Expand theme prefix and clean up file structure

This commit is contained in:
Brian Miyaji
2014-01-07 17:44:33 +11:00
parent 66c1639e7e
commit 0dd53482b6
40 changed files with 1838 additions and 1851 deletions

View File

@@ -0,0 +1,6 @@
<?php
function sportspress_admin_enqueue_scripts() {
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'sportspress-admin', SPORTSPRESS_PLUGIN_URL .'/assets/js/admin.js', array( 'jquery' ), time(), true );
}
add_action( 'admin_enqueue_scripts', 'sportspress_admin_enqueue_scripts' );

View File

@@ -0,0 +1,10 @@
<?php
function sportspress_admin_head() {
global $typenow;
if ( in_array( $typenow, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_statistic' ) ) ):
sportspress_highlight_admin_menu();
endif;
}
add_action( 'admin_head-edit.php', 'sportspress_admin_head', 10, 2 );
add_action( 'admin_head-post.php', 'sportspress_admin_head', 10, 2 );

View File

@@ -0,0 +1,162 @@
<?php
function sportspress_admin_init() {
$installed = get_option( 'sportspress_installed', false );
// Define roles and capabilities
if ( ! $installed ):
$role = get_role( 'administrator' );
// Events
$role->add_cap( 'edit_sp_event' );
$role->add_cap( 'edit_sp_events' );
$role->add_cap( 'edit_others_sp_events' );
$role->add_cap( 'delete_sp_event' );
$role->add_cap( 'publish_sp_events' );
$role->add_cap( 'read_sp_events' );
$role->add_cap( 'read_private_sp_events' );
// Teams
$role->add_cap( 'edit_sp_team' );
$role->add_cap( 'edit_sp_teams' );
$role->add_cap( 'edit_others_sp_teams' );
$role->add_cap( 'delete_sp_team' );
$role->add_cap( 'publish_sp_teams' );
$role->add_cap( 'read_sp_teams' );
$role->add_cap( 'read_private_sp_teams' );
// League Tables
$role->add_cap( 'edit_sp_table' );
$role->add_cap( 'edit_sp_tables' );
$role->add_cap( 'edit_others_sp_tables' );
$role->add_cap( 'delete_sp_table' );
$role->add_cap( 'publish_sp_tables' );
$role->add_cap( 'read_sp_tables' );
$role->add_cap( 'read_private_sp_tables' );
// Players
$role->add_cap( 'edit_sp_player' );
$role->add_cap( 'edit_sp_players' );
$role->add_cap( 'edit_others_sp_players' );
$role->add_cap( 'delete_sp_player' );
$role->add_cap( 'publish_sp_players' );
$role->add_cap( 'read_sp_players' );
$role->add_cap( 'read_private_sp_players' );
// Player Lists
$role->add_cap( 'edit_sp_list' );
$role->add_cap( 'edit_sp_lists' );
$role->add_cap( 'edit_others_sp_lists' );
$role->add_cap( 'delete_sp_list' );
$role->add_cap( 'publish_sp_lists' );
$role->add_cap( 'read_sp_lists' );
$role->add_cap( 'read_private_sp_lists' );
// Staff
$role->add_cap( 'edit_sp_staff' );
$role->add_cap( 'edit_sp_staffs' );
$role->add_cap( 'edit_others_sp_staffs' );
$role->add_cap( 'delete_sp_staff' );
$role->add_cap( 'publish_sp_staffs' );
$role->add_cap( 'read_sp_staffs' );
$role->add_cap( 'read_private_sp_staffs' );
// Settings
$role->add_cap( 'read_sp_configs' );
$role->add_cap( 'read_private_sp_configs' );
$role->add_cap( 'edit_sp_config' );
$role->add_cap( 'edit_sp_configs' );
$role->add_cap( 'edit_published_sp_configs' );
$role->add_cap( 'edit_private_sp_configs' );
$role->add_cap( 'edit_others_sp_configs' );
$role->add_cap( 'delete_sp_config' );
$role->add_cap( 'delete_published_sp_configs' );
$role->add_cap( 'delete_private_sp_configs' );
$role->add_cap( 'delete_others_sp_configs' );
$role->add_cap( 'publish_sp_configs' );
// Team Manager
remove_role( 'sp_team_manager' );
add_role(
'sp_team_manager',
__( 'Team Manager', 'sportspress' ),
array(
'read' => true,
'edit_posts' => true,
'delete_posts' => true,
'read_sp_players' => true,
'edit_sp_players' => true,
'edit_others_sp_players' => true,
'delete_sp_player' => true,
'publish_sp_players' => true,
'read_sp_staffs' => true,
'edit_sp_staffs' => true,
'edit_others_sp_staffs' => true,
'delete_sp_staff' => true,
'publish_sp_staffs' => true
)
);
// Staff
remove_role( 'sp_staff' );
add_role(
'sp_staff',
__( 'Staff', 'sportspress' ),
array(
'read' => true,
'edit_posts' => true,
'delete_posts' => true,
'read_sp_staffs' => true,
'edit_sp_staffs' => true,
'delete_sp_staff' => true
)
);
// Player
remove_role( 'sp_player' );
add_role(
'sp_player',
__( 'Player', 'sportspress' ),
array(
'read' => true,
'edit_posts' => true,
'delete_posts' => true,
'read_sp_players' => true,
'edit_sp_players' => true,
'delete_sp_player' => true
)
);
update_option( 'sportspress_installed', 1 );
endif;
// Load admin styles
wp_register_style( 'sportspress-admin', SPORTSPRESS_PLUGIN_URL . 'assets/css/admin.css', array(), '1.0' );
wp_enqueue_style( 'sportspress-admin');
// Add settings sections
register_setting(
'sportspress_general',
'sportspress',
'sportspress_validate'
);
add_settings_section(
'general',
'',
'',
'sportspress_general'
);
add_settings_field(
'sport',
__( 'Sport', 'sportspress' ),
'sportspress_sport_callback',
'sportspress_general',
'general'
);
}
add_action( 'admin_init', 'sportspress_admin_init', 1 );

View File

@@ -1,5 +1,13 @@
<?php
function sp_admin_menu( $position ) {
function sportspress_admin_menu( $position ) {
add_options_page(
__( 'SportsPress', 'sportspress' ),
__( 'SportsPress', 'sportspress' ),
'manage_options',
'sportspress',
'sportspress_settings'
);
if ( ! current_user_can( 'manage_options' ) )
return;
@@ -28,4 +36,4 @@ function sp_admin_menu( $position ) {
// Remove "Seasons" link under Staff
unset( $submenu['edit.php?post_type=sp_staff'][15] );
}
add_action( 'admin_menu', 'sp_admin_menu' );
add_action( 'admin_menu', 'sportspress_admin_menu' );

View File

@@ -0,0 +1,5 @@
<?php
function sportspress_after_setup_theme() {
add_theme_support( 'post-thumbnails' );
}
add_action( 'after_setup_theme', 'sportspress_after_setup_theme' );

View File

@@ -1,5 +0,0 @@
<?php
function sp_after_theme_setup() {
add_theme_support( 'post-thumbnails' );
}
add_action( 'after_theme_setup', 'sp_after_theme_setup' );

View File

@@ -0,0 +1,4 @@
<?php
function sp_manage_posts_columns() {
sportspress_highlight_admin_menu();
}

View File

@@ -1,5 +1,5 @@
<?php
function sp_manage_posts_custom_column( $column, $post_id ) {
function sportspress_manage_posts_custom_column( $column, $post_id ) {
global $post;
switch ( $column ):
case 'sp_logo':
@@ -16,7 +16,7 @@ function sp_manage_posts_custom_column( $column, $post_id ) {
foreach( $teams as $team_id ):
if ( ! $team_id ) continue;
$team = get_post( $team_id );
$outcome_slug = sp_array_value( sp_array_value( $results, $team_id, null ), 'outcome', null );
$outcome_slug = sportspress_array_value( sportspress_array_value( $results, $team_id, null ), 'outcome', null );
$args=array(
'name' => $outcome_slug,
@@ -32,7 +32,7 @@ function sp_manage_posts_custom_column( $column, $post_id ) {
foreach( $teams as $team_id ):
if ( ! $team_id ) continue;
$team = get_post( $team_id );
$outcome_slug = sp_array_value( sp_array_value( $results, $team_id, null ), 'outcome', null );
$outcome_slug = sportspress_array_value( sportspress_array_value( $results, $team_id, null ), 'outcome', null );
$args=array(
'name' => $outcome_slug,
@@ -51,19 +51,19 @@ function sp_manage_posts_custom_column( $column, $post_id ) {
endif;
break;
case 'sp_equation':
echo sp_get_post_equation( $post_id );
echo sportspress_get_post_equation( $post_id );
break;
case 'sp_order':
echo sp_get_post_order( $post_id );
echo sportspress_get_post_order( $post_id );
break;
case 'sp_key':
echo $post->post_name;
break;
case 'sp_format':
echo sp_get_post_format( $post_id );
echo sportspress_get_post_format( $post_id );
break;
case 'sp_player':
echo sp_the_posts( $post_id, 'sp_player' );
echo sportspress_the_posts( $post_id, 'sp_player' );
break;
case 'sp_event':
echo get_post_meta ( $post_id, 'sp_event' ) ? sizeof( get_post_meta ( $post_id, 'sp_event' ) ) : '—';
@@ -82,5 +82,5 @@ function sp_manage_posts_custom_column( $column, $post_id ) {
break;
endswitch;
}
add_action( 'manage_posts_custom_column', 'sp_manage_posts_custom_column', 10, 2 );
add_action( 'manage_pages_custom_column', 'sp_manage_posts_custom_column', 10, 2 );
add_action( 'manage_posts_custom_column', 'sportspress_manage_posts_custom_column', 10, 2 );
add_action( 'manage_pages_custom_column', 'sportspress_manage_posts_custom_column', 10, 2 );

View File

@@ -1,6 +1,6 @@
<?php
function sp_plugins_loaded() {
load_plugin_textdomain ( 'sportspress', false, dirname( SPORTSPRESS_PLUGIN_BASENAME ) . '/i18n/languages/' );
function sportspress_plugins_loaded() {
load_plugin_textdomain ( 'sportspress', false, dirname( SPORTSPRESS_PLUGIN_BASENAME ) . '/languages/' );
add_image_size( 'sp_icon', 32, 32, false );
}
add_action( 'plugins_loaded', 'sp_plugins_loaded' );
add_action( 'plugins_loaded', 'sportspress_plugins_loaded' );

View File

@@ -1,5 +1,5 @@
<?php
function sp_post_thumbnail_html( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
function sportspress_post_thumbnail_html( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
if( empty ( $html ) && in_array( get_post_type( $post_id ), array( 'sp_team', 'sp_tournament' ) ) ) {
$parents = get_post_ancestors( $post_id );
foreach ( $parents as $parent ) {
@@ -11,4 +11,4 @@ function sp_post_thumbnail_html( $html, $post_id, $post_thumbnail_id, $size, $at
}
return $html;
}
add_filter( 'post_thumbnail_html', 'sp_post_thumbnail_html', 10, 5 );
add_filter( 'post_thumbnail_html', 'sportspress_post_thumbnail_html', 10, 5 );

View File

@@ -1,6 +1,6 @@
<?php
function sp_restrict_manage_posts() {
sp_highlight_admin_menu();
function sportspress_restrict_manage_posts() {
sportspress_highlight_admin_menu();
global $typenow, $wp_query;
if ( in_array( $typenow, array( 'sp_event', 'sp_player', 'sp_staff', 'sp_table', 'sp_list' ) ) ):
$selected = isset( $_REQUEST['sp_team'] ) ? $_REQUEST['sp_team'] : null;
@@ -20,7 +20,7 @@ function sp_restrict_manage_posts() {
'name' => 'sp_position',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
sportspress_dropdown_taxonomies( $args );
endif;
if ( in_array( $typenow, array( 'sp_team', 'sp_event', 'sp_player', 'sp_staff', 'sp_table', 'sp_list' ) ) ):
$selected = isset( $_REQUEST['sp_season'] ) ? $_REQUEST['sp_season'] : null;
@@ -30,7 +30,7 @@ function sp_restrict_manage_posts() {
'name' => 'sp_season',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
sportspress_dropdown_taxonomies( $args );
endif;
}
add_action( 'restrict_manage_posts', 'sp_restrict_manage_posts' );
add_action( 'restrict_manage_posts', 'sportspress_restrict_manage_posts' );

View File

@@ -1,5 +1,5 @@
<?php
function sp_save_post( $post_id ) {
function sportspress_save_post( $post_id ) {
global $post, $typenow;
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id;
if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id;
@@ -8,129 +8,129 @@ function sp_save_post( $post_id ) {
case ( 'sp_team' ):
// Update columns
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
update_post_meta( $post_id, 'sp_columns', sportspress_array_value( $_POST, 'sp_columns', array() ) );
break;
case ( 'sp_event' ):
// Get results
$results = (array)sp_array_value( $_POST, 'sp_results', array() );
$results = (array)sportspress_array_value( $_POST, 'sp_results', array() );
// Update results
update_post_meta( $post_id, 'sp_results', $results );
// Update player statistics
update_post_meta( $post_id, 'sp_players', sp_array_value( $_POST, 'sp_players', array() ) );
update_post_meta( $post_id, 'sp_players', sportspress_array_value( $_POST, 'sp_players', array() ) );
// Update team array
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
sportspress_update_post_meta_recursive( $post_id, 'sp_team', sportspress_array_value( $_POST, 'sp_team', array() ) );
// Update player array
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) );
sportspress_update_post_meta_recursive( $post_id, 'sp_player', sportspress_array_value( $_POST, 'sp_player', array() ) );
// Update staff array
sp_update_post_meta_recursive( $post_id, 'sp_staff', sp_array_value( $_POST, 'sp_staff', array() ) );
sportspress_update_post_meta_recursive( $post_id, 'sp_staff', sportspress_array_value( $_POST, 'sp_staff', array() ) );
break;
case ( 'sp_column' ):
// Update format as string
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'integer' ) );
update_post_meta( $post_id, 'sp_format', sportspress_array_value( $_POST, 'sp_format', 'integer' ) );
// Update precision as integer
update_post_meta( $post_id, 'sp_precision', (int) sp_array_value( $_POST, 'sp_precision', 1 ) );
update_post_meta( $post_id, 'sp_precision', (int) sportspress_array_value( $_POST, 'sp_precision', 1 ) );
// Update equation as string
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
update_post_meta( $post_id, 'sp_equation', implode( ' ', sportspress_array_value( $_POST, 'sp_equation', array() ) ) );
// Update sort order as string
update_post_meta( $post_id, 'sp_priority', sp_array_value( $_POST, 'sp_priority', '0' ) );
update_post_meta( $post_id, 'sp_priority', sportspress_array_value( $_POST, 'sp_priority', '0' ) );
// Update sort order as string
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', 'DESC' ) );
update_post_meta( $post_id, 'sp_order', sportspress_array_value( $_POST, 'sp_order', 'DESC' ) );
break;
case ( 'sp_statistic' ):
// Update format as string
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'integer' ) );
update_post_meta( $post_id, 'sp_format', sportspress_array_value( $_POST, 'sp_format', 'integer' ) );
// Update precision as integer
update_post_meta( $post_id, 'sp_precision', (int) sp_array_value( $_POST, 'sp_precision', 1 ) );
update_post_meta( $post_id, 'sp_precision', (int) sportspress_array_value( $_POST, 'sp_precision', 1 ) );
// Update equation as string
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
update_post_meta( $post_id, 'sp_equation', implode( ' ', sportspress_array_value( $_POST, 'sp_equation', array() ) ) );
// Update sort order as string
update_post_meta( $post_id, 'sp_priority', sp_array_value( $_POST, 'sp_priority', '0' ) );
update_post_meta( $post_id, 'sp_priority', sportspress_array_value( $_POST, 'sp_priority', '0' ) );
// Update sort order as string
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', 'DESC' ) );
update_post_meta( $post_id, 'sp_order', sportspress_array_value( $_POST, 'sp_order', 'DESC' ) );
break;
case ( 'sp_result' ):
// Update format as string
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'integer' ) );
update_post_meta( $post_id, 'sp_format', sportspress_array_value( $_POST, 'sp_format', 'integer' ) );
break;
case ( 'sp_player' ):
// Update player statistics
update_post_meta( $post_id, 'sp_statistics', sp_array_value( $_POST, 'sp_statistics', array() ) );
update_post_meta( $post_id, 'sp_statistics', sportspress_array_value( $_POST, 'sp_statistics', array() ) );
// Update team array
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
sportspress_update_post_meta_recursive( $post_id, 'sp_team', sportspress_array_value( $_POST, 'sp_team', array() ) );
// Update player number
update_post_meta( $post_id, 'sp_number', sp_array_value( $_POST, 'sp_number', '' ) );
update_post_meta( $post_id, 'sp_number', sportspress_array_value( $_POST, 'sp_number', '' ) );
// Update player details array
update_post_meta( $post_id, 'sp_details', sp_array_value( $_POST, 'sp_details', array() ) );
update_post_meta( $post_id, 'sp_details', sportspress_array_value( $_POST, 'sp_details', array() ) );
break;
case ( 'sp_staff' ):
// Update team array
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
sportspress_update_post_meta_recursive( $post_id, 'sp_team', sportspress_array_value( $_POST, 'sp_team', array() ) );
break;
case ( 'sp_table' ):
// Update teams array
update_post_meta( $post_id, 'sp_teams', sp_array_value( $_POST, 'sp_teams', array() ) );
update_post_meta( $post_id, 'sp_teams', sportspress_array_value( $_POST, 'sp_teams', array() ) );
// Update season taxonomy
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
// Update team array
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
sportspress_update_post_meta_recursive( $post_id, 'sp_team', sportspress_array_value( $_POST, 'sp_team', array() ) );
break;
case ( 'sp_list' ):
// Update players array
update_post_meta( $post_id, 'sp_players', sp_array_value( $_POST, 'sp_players', array() ) );
update_post_meta( $post_id, 'sp_players', sportspress_array_value( $_POST, 'sp_players', array() ) );
// Update team array
update_post_meta( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
update_post_meta( $post_id, 'sp_team', sportspress_array_value( $_POST, 'sp_team', array() ) );
// Update season taxonomy
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
//Update player array
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) );
sportspress_update_post_meta_recursive( $post_id, 'sp_player', sportspress_array_value( $_POST, 'sp_player', array() ) );
break;
endswitch;
}
add_action( 'save_post', 'sp_save_post' );
add_action( 'save_post', 'sportspress_save_post' );