Fix bugs, use plural post slugs, move actions and filters into hooks folder
This commit is contained in:
9
admin/hooks/admin-enqueue-scripts.php
Normal file
9
admin/hooks/admin-enqueue-scripts.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
function sportspress_admin_enqueue_scripts() {
|
||||
wp_register_style( 'sportspress-admin', SPORTSPRESS_PLUGIN_URL . 'assets/css/admin.css', array(), time() );
|
||||
wp_enqueue_style( 'sportspress-admin');
|
||||
|
||||
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' );
|
||||
10
admin/hooks/admin-head.php
Normal file
10
admin/hooks/admin-head.php
Normal 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 );
|
||||
130
admin/hooks/admin-init.php
Normal file
130
admin/hooks/admin-init.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
function sportspress_admin_init() {
|
||||
|
||||
$installed = get_option( 'sportspress_installed', false );
|
||||
|
||||
// General settings
|
||||
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'
|
||||
);
|
||||
|
||||
// Event Settings
|
||||
register_setting(
|
||||
'sportspress_events',
|
||||
'sportspress',
|
||||
'sportspress_validate'
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'events',
|
||||
'',
|
||||
'',
|
||||
'sportspress_events'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'sport',
|
||||
__( 'Sport', 'sportspress' ),
|
||||
'sportspress_sport_callback',
|
||||
'sportspress_events',
|
||||
'events'
|
||||
);
|
||||
|
||||
}
|
||||
add_action( 'admin_init', 'sportspress_admin_init', 1 );
|
||||
|
||||
|
||||
|
||||
function sportspress_validate( $input ) {
|
||||
|
||||
$options = get_option( 'sportspress' );
|
||||
|
||||
// Do nothing if sport is the same as currently selected
|
||||
if ( sportspress_array_value( $options, 'sport', null ) == sportspress_array_value( $input, 'sport', null ) )
|
||||
|
||||
return $input;
|
||||
|
||||
// Get sports presets
|
||||
global $sportspress_sports;
|
||||
|
||||
// Get array of post types to insert
|
||||
$post_groups = sportspress_array_value( sportspress_array_value( $sportspress_sports, sportspress_array_value( $input, 'sport', null ), array() ), 'posts', array() );
|
||||
|
||||
// Loop through each post type
|
||||
foreach( $post_groups as $post_type => $posts ):
|
||||
|
||||
$args = array(
|
||||
'post_type' => $post_type,
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => 'sp_preset',
|
||||
'value' => 1
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Delete posts
|
||||
$old_posts = get_posts( $args );
|
||||
|
||||
foreach( $old_posts as $post ):
|
||||
wp_delete_post( $post->ID, true);
|
||||
endforeach;
|
||||
|
||||
// Add posts
|
||||
foreach( $posts as $index => $post ):
|
||||
|
||||
// Make sure post doesn't overlap
|
||||
if ( ! get_page_by_path( $post['post_name'], OBJECT, $post_type ) ):
|
||||
|
||||
// Translate post title
|
||||
$post['post_title'] = __( $post['post_title'], 'sportspress' );
|
||||
|
||||
// Set post type
|
||||
$post['post_type'] = $post_type;
|
||||
|
||||
// Increment menu order by 2 and publish post
|
||||
$post['menu_order'] = $index * 2 + 2;
|
||||
$post['post_status'] = 'publish';
|
||||
$id = wp_insert_post( $post );
|
||||
|
||||
// Flag as preset
|
||||
update_post_meta( $id, 'sp_preset', 1 );
|
||||
|
||||
// Update meta
|
||||
if ( array_key_exists( 'meta', $post ) ):
|
||||
|
||||
foreach ( $post['meta'] as $key => $value ):
|
||||
|
||||
update_post_meta( $id, $key, $value );
|
||||
|
||||
endforeach;
|
||||
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
||||
endforeach;
|
||||
|
||||
endforeach;
|
||||
|
||||
return $input;
|
||||
}
|
||||
39
admin/hooks/admin-menu.php
Normal file
39
admin/hooks/admin-menu.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
function sportspress_admin_menu( $position ) {
|
||||
add_options_page(
|
||||
__( 'SportsPress', 'sportspress' ),
|
||||
__( 'SportsPress', 'sportspress' ),
|
||||
'manage_options',
|
||||
'sportspress',
|
||||
'sportspress_settings'
|
||||
);
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) )
|
||||
return;
|
||||
|
||||
global $menu, $submenu;
|
||||
|
||||
// Find where our placeholder is in the menu
|
||||
foreach( $menu as $key => $data ) {
|
||||
if ( is_array( $data ) && array_key_exists( 2, $data ) && $data[2] == 'edit.php?post_type=sp_separator' )
|
||||
$position = $key;
|
||||
}
|
||||
|
||||
// Swap our placeholder post type with a menu separator
|
||||
if ( $position ):
|
||||
$menu[ $position ] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' );
|
||||
endif;
|
||||
|
||||
// Remove "Add Configuration" link under SportsPress
|
||||
unset( $submenu['edit.php?post_type=sp_config'][10] );
|
||||
|
||||
// Remove "Seasons" link under Events
|
||||
unset( $submenu['edit.php?post_type=sp_event'][15] );
|
||||
|
||||
// Remove "Seasons" link under Players
|
||||
unset( $submenu['edit.php?post_type=sp_player'][15] );
|
||||
|
||||
// Remove "Seasons" link under Staff
|
||||
unset( $submenu['edit.php?post_type=sp_staff'][15] );
|
||||
}
|
||||
add_action( 'admin_menu', 'sportspress_admin_menu' );
|
||||
26
admin/hooks/admin-post-thumbnail-html.php
Normal file
26
admin/hooks/admin-post-thumbnail-html.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
function sportspress_admin_post_thumbnail_html( $translated_text, $post_id ) {
|
||||
$texts = array(
|
||||
'sp_team' => array(
|
||||
'Set featured image' => 'Select Logo',
|
||||
'Remove featured image' => 'Remove Logo',
|
||||
),
|
||||
'sp_player' => array(
|
||||
'Set featured image' => 'Select Photo',
|
||||
'Remove featured image' => 'Remove Photo',
|
||||
),
|
||||
'sp_staff' => array(
|
||||
'Set featured image' => 'Select Photo',
|
||||
'Remove featured image' => 'Remove Photo',
|
||||
),
|
||||
);
|
||||
|
||||
$typenow = get_post_type( $post_id );
|
||||
if ( is_admin() && array_key_exists( $typenow, $texts ) ):
|
||||
foreach ( $texts[ $typenow ] as $key => $value ):
|
||||
$translated_text = str_replace( __( $key ), __( $value, 'sportspress' ), $translated_text );
|
||||
endforeach;
|
||||
endif;
|
||||
return $translated_text;
|
||||
}
|
||||
add_filter( 'admin_post_thumbnail_html', 'sportspress_admin_post_thumbnail_html', 10, 2 );
|
||||
5
admin/hooks/after-setup-theme.php
Normal file
5
admin/hooks/after-setup-theme.php
Normal 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' );
|
||||
43
admin/hooks/gettext.php
Normal file
43
admin/hooks/gettext.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
function sportspress_gettext( $translated_text, $untranslated_text, $domain ) {
|
||||
global $typenow;
|
||||
|
||||
$texts = array(
|
||||
'sp_team' => array(
|
||||
'Enter title here' => 'Team',
|
||||
'Set featured image' => 'Select Logo',
|
||||
'Set Featured Image' => 'Select Logo',
|
||||
'Remove featured image' => 'Remove Logo',
|
||||
),
|
||||
'sp_event' => array(
|
||||
'Enter title here' => '(no title)',
|
||||
'Scheduled for: <b>%1$s</b>' => 'Kick-off: <b>%1$s</b>',
|
||||
'Published on: <b>%1$s</b>' => 'Kick-off: <b>%1$s</b>',
|
||||
'Publish <b>immediately</b>' => 'Kick-off: <b>%1$s</b>',
|
||||
),
|
||||
'sp_player' => array(
|
||||
'Enter title here' => 'Name',
|
||||
'Set featured image' => 'Select Photo',
|
||||
'Set Featured Image' => 'Select Photo',
|
||||
'Remove featured image' => 'Remove Photo',
|
||||
'Scheduled for: <b>%1$s</b>' => 'Joined: <b>%1$s</b>',
|
||||
'Published on: <b>%1$s</b>' => 'Joined: <b>%1$s</b>',
|
||||
'Publish <b>immediately</b>' => 'Joined: <b>%1$s</b>',
|
||||
),
|
||||
'sp_staff' => array(
|
||||
'Enter title here' => 'Name',
|
||||
'Set featured image' => 'Select Photo',
|
||||
'Set Featured Image' => 'Select Photo',
|
||||
'Remove featured image' => 'Remove Photo',
|
||||
'Scheduled for: <b>%1$s</b>' => 'Joined: <b>%1$s</b>',
|
||||
'Published on: <b>%1$s</b>' => 'Joined: <b>%1$s</b>',
|
||||
'Publish <b>immediately</b>' => 'Joined: <b>%1$s</b>',
|
||||
),
|
||||
);
|
||||
|
||||
if ( is_admin() && array_key_exists( $typenow, $texts ) && array_key_exists( $untranslated_text, $texts[ $typenow ] ) )
|
||||
return __( $texts[ $typenow ][ $untranslated_text ], 'sportspress' );
|
||||
else
|
||||
return $translated_text;
|
||||
}
|
||||
add_filter( 'gettext', 'sportspress_gettext', 20, 3 );
|
||||
92
admin/hooks/manage-posts-custom-column.php
Normal file
92
admin/hooks/manage-posts-custom-column.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
function sportspress_manage_posts_custom_column( $column, $post_id ) {
|
||||
global $post;
|
||||
switch ( $column ):
|
||||
case 'sp_logo':
|
||||
edit_post_link( get_the_post_thumbnail( $post_id, 'sp_icon' ), '', '', $post_id );
|
||||
break;
|
||||
case 'sp_position':
|
||||
echo get_the_terms ( $post_id, 'sp_position' ) ? the_terms( $post_id, 'sp_position' ) : '—';
|
||||
break;
|
||||
case 'sp_team':
|
||||
$post_type = get_post_type( $post );
|
||||
$teams = get_post_meta ( $post_id, 'sp_team', false );
|
||||
if ( $post_type == 'sp_event' ):
|
||||
$results = get_post_meta( $post_id, 'sp_results', true );
|
||||
foreach( $teams as $team_id ):
|
||||
if ( ! $team_id ) continue;
|
||||
$team = get_post( $team_id );
|
||||
$outcome_slug = sportspress_array_value( sportspress_array_value( $results, $team_id, null ), 'outcome', null );
|
||||
|
||||
if ( $outcome_slug && $outcome_slug != '-1' ):
|
||||
$args=array(
|
||||
'name' => $outcome_slug,
|
||||
'post_type' => 'sp_outcome',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => 1
|
||||
);
|
||||
$outcomes = get_posts( $args );
|
||||
|
||||
echo $team->post_title . ( $outcomes ? ' — ' . $outcomes[0]->post_title : '' ) . '<br>';
|
||||
else:
|
||||
echo $team->post_title . '<br>';
|
||||
endif;
|
||||
endforeach;
|
||||
elseif ( $post_type == 'sp_player' ):
|
||||
$results = get_post_meta( $post_id, 'sp_results', true );
|
||||
foreach( $teams as $team_id ):
|
||||
if ( ! $team_id ) continue;
|
||||
$team = get_post( $team_id );
|
||||
$outcome_slug = sportspress_array_value( sportspress_array_value( $results, $team_id, null ), 'outcome', null );
|
||||
echo $team->post_title . '<br>';
|
||||
endforeach;
|
||||
else:
|
||||
foreach( $teams as $team_id ):
|
||||
$team = get_post( $team_id );
|
||||
echo $team->post_title . '<br>';
|
||||
endforeach;
|
||||
endif;
|
||||
break;
|
||||
case 'sp_equation':
|
||||
echo sportspress_get_post_equation( $post_id );
|
||||
break;
|
||||
case 'sp_order':
|
||||
echo sportspress_get_post_order( $post_id );
|
||||
break;
|
||||
case 'sp_key':
|
||||
echo $post->post_name;
|
||||
break;
|
||||
case 'sp_format':
|
||||
echo sportspress_get_post_format( $post_id );
|
||||
break;
|
||||
case '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' ) ) : '—';
|
||||
break;
|
||||
case 'sp_season':
|
||||
echo get_the_terms ( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : '—';
|
||||
break;
|
||||
case 'sp_sponsor':
|
||||
echo get_the_terms ( $post_id, 'sp_sponsor' ) ? the_terms( $post_id, 'sp_sponsor' ) : '—';
|
||||
break;
|
||||
case 'sp_kickoff':
|
||||
if ( $post->post_status == 'future' ):
|
||||
_e( 'Scheduled', 'sportspress' );
|
||||
elseif( $post->post_status == 'publish' ):
|
||||
_e( 'Played', 'sportspress' );
|
||||
elseif( $post->post_status == 'draft' ):
|
||||
_e( 'Draft', 'sportspress' );
|
||||
else:
|
||||
_e( 'Pending Review', 'sportspress' );
|
||||
endif;
|
||||
echo '<br />' . date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) );
|
||||
break;
|
||||
case 'sp_address':
|
||||
echo get_post_meta( $post_id, 'sp_address', true ) ? get_post_meta( $post_id, 'sp_address', true ) : '—';
|
||||
break;
|
||||
endswitch;
|
||||
}
|
||||
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 );
|
||||
9
admin/hooks/plugin-action-links.php
Normal file
9
admin/hooks/plugin-action-links.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
function sportspress_plugin_action_links( $links ) {
|
||||
$settings_link = '<a href="options-general.php?page=sportspress">' . __( 'Settings', 'sportspress' ) . '</a>';
|
||||
array_unshift( $links, $settings_link );
|
||||
return $links;
|
||||
}
|
||||
|
||||
$plugin = SPORTSPRESS_PLUGIN_BASENAME;
|
||||
add_filter( "plugin_action_links_$plugin", 'sportspress_plugin_action_links' );
|
||||
6
admin/hooks/plugins-loaded.php
Normal file
6
admin/hooks/plugins-loaded.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
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', 'sportspress_plugins_loaded' );
|
||||
14
admin/hooks/post-thumbnail-html.php
Normal file
14
admin/hooks/post-thumbnail-html.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
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 ) {
|
||||
if( has_post_thumbnail( $parent ) ) {
|
||||
$html = get_the_post_thumbnail( $parent, $size, $attr );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
add_filter( 'post_thumbnail_html', 'sportspress_post_thumbnail_html', 10, 5 );
|
||||
15
admin/hooks/pre-get-posts.php
Normal file
15
admin/hooks/pre-get-posts.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
function sportspress_pre_get_posts( $wp_query ) {
|
||||
if ( is_admin() ):
|
||||
$post_type = $wp_query->query['post_type'];
|
||||
|
||||
if ( in_array( $post_type, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_statistic' ) ) ):
|
||||
$wp_query->set( 'orderby', 'menu_order' );
|
||||
$wp_query->set( 'order', 'ASC' );
|
||||
elseif ( $post_type == 'sp_event' ):
|
||||
$wp_query->set( 'orderby', 'post_date' );
|
||||
$wp_query->set( 'order', 'ASC' );
|
||||
endif;
|
||||
endif;
|
||||
}
|
||||
add_filter('pre_get_posts', 'sportspress_pre_get_posts');
|
||||
141
admin/hooks/register-activation-hook.php
Normal file
141
admin/hooks/register-activation-hook.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
function sportspress_activation_hook() {
|
||||
|
||||
$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
|
||||
)
|
||||
);
|
||||
|
||||
// Flush rewrite rules
|
||||
sportspress_event_post_init();
|
||||
sportspress_result_post_init();
|
||||
sportspress_outcome_post_init();
|
||||
sportspress_column_post_init();
|
||||
sportspress_statistic_post_init();
|
||||
sportspress_team_post_init();
|
||||
sportspress_table_post_init();
|
||||
sportspress_player_post_init();
|
||||
sportspress_list_post_init();
|
||||
sportspress_staff_post_init();
|
||||
sportspress_position_term_init();
|
||||
sportspress_season_term_init();
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
register_activation_hook( SPORTSPRESS_PLUGIN_FILE, 'sportspress_activation_hook' );
|
||||
36
admin/hooks/restrict-manage-posts.php
Normal file
36
admin/hooks/restrict-manage-posts.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
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;
|
||||
$args = array(
|
||||
'show_option_none' => sprintf( __( 'All %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
|
||||
'post_type' => 'sp_team',
|
||||
'name' => 'sp_team',
|
||||
'selected' => $selected
|
||||
);
|
||||
// wp_dropdown_pages( $args );
|
||||
endif;
|
||||
if ( in_array( $typenow, array( 'sp_player' ) ) ):
|
||||
$selected = isset( $_REQUEST['sp_position'] ) ? $_REQUEST['sp_position'] : null;
|
||||
$args = array(
|
||||
'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Positions', 'sportspress' ) ),
|
||||
'taxonomy' => 'sp_position',
|
||||
'name' => 'sp_position',
|
||||
'selected' => $selected
|
||||
);
|
||||
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;
|
||||
$args = array(
|
||||
'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Seasons', 'sportspress' ) ),
|
||||
'taxonomy' => 'sp_season',
|
||||
'name' => 'sp_season',
|
||||
'selected' => $selected
|
||||
);
|
||||
sportspress_dropdown_taxonomies( $args );
|
||||
endif;
|
||||
}
|
||||
add_action( 'restrict_manage_posts', 'sportspress_restrict_manage_posts' );
|
||||
25
admin/hooks/sanitize-title.php
Normal file
25
admin/hooks/sanitize-title.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
function sportspress_sanitize_title( $title ) {
|
||||
|
||||
if ( isset( $_POST ) && array_key_exists( 'post_type', $_POST ) && in_array( $_POST['post_type'], array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_statistic' ) ) ):
|
||||
|
||||
$key = $_POST['sp_key'];
|
||||
|
||||
if ( ! $key ) $key = $_POST['post_title'];
|
||||
|
||||
$title = sportspress_get_eos_safe_slug( $key, sportspress_array_value( $_POST, 'ID', 'var' ) );
|
||||
|
||||
elseif ( isset( $_POST ) && array_key_exists( 'post_type', $_POST ) && $_POST['post_type'] == 'sp_event' ):
|
||||
|
||||
// Auto slug generation
|
||||
if ( $_POST['post_title'] == '' && ( $_POST['post_name'] == '' || is_int( $_POST['post_name'] ) ) ):
|
||||
|
||||
$title = '';
|
||||
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
||||
return $title;
|
||||
}
|
||||
add_filter( 'sanitize_title', 'sportspress_sanitize_title' );
|
||||
133
admin/hooks/save-post.php
Normal file
133
admin/hooks/save-post.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
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;
|
||||
if ( !isset( $_POST['sportspress_nonce'] ) || ! wp_verify_nonce( $_POST['sportspress_nonce'], SPORTSPRESS_PLUGIN_BASENAME ) ) return $post_id;
|
||||
switch ( $_POST['post_type'] ):
|
||||
case ( 'sp_team' ):
|
||||
|
||||
// Update columns
|
||||
update_post_meta( $post_id, 'sp_columns', sportspress_array_value( $_POST, 'sp_columns', array() ) );
|
||||
|
||||
break;
|
||||
|
||||
case ( 'sp_event' ):
|
||||
|
||||
// Get results
|
||||
$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', sportspress_array_value( $_POST, 'sp_players', array() ) );
|
||||
|
||||
// Update team array
|
||||
sportspress_update_post_meta_recursive( $post_id, 'sp_team', sportspress_array_value( $_POST, 'sp_team', array() ) );
|
||||
|
||||
// Update player array
|
||||
sportspress_update_post_meta_recursive( $post_id, 'sp_player', sportspress_array_value( $_POST, 'sp_player', array() ) );
|
||||
|
||||
// Update 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', sportspress_array_value( $_POST, 'sp_format', 'integer' ) );
|
||||
|
||||
// Update precision as integer
|
||||
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( ' ', sportspress_array_value( $_POST, 'sp_equation', array() ) ) );
|
||||
|
||||
// Update sort order as string
|
||||
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', sportspress_array_value( $_POST, 'sp_order', 'DESC' ) );
|
||||
|
||||
break;
|
||||
|
||||
case ( 'sp_statistic' ):
|
||||
|
||||
// Update format as string
|
||||
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) sportspress_array_value( $_POST, 'sp_precision', 1 ) );
|
||||
|
||||
// Update sort order as string
|
||||
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', sportspress_array_value( $_POST, 'sp_order', 'DESC' ) );
|
||||
|
||||
break;
|
||||
|
||||
case ( 'sp_result' ):
|
||||
|
||||
// Update format as string
|
||||
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', sportspress_array_value( $_POST, 'sp_statistics', array() ) );
|
||||
|
||||
// Update 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', sportspress_array_value( $_POST, 'sp_number', '' ) );
|
||||
|
||||
// Update player metrics array
|
||||
update_post_meta( $post_id, 'sp_metrics', sportspress_array_value( $_POST, 'sp_metrics', array() ) );
|
||||
|
||||
break;
|
||||
|
||||
case ( 'sp_staff' ):
|
||||
|
||||
// Update 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', sportspress_array_value( $_POST, 'sp_teams', array() ) );
|
||||
|
||||
// Update season taxonomy
|
||||
wp_set_post_terms( $post_id, sportspress_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
|
||||
|
||||
// Update 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', sportspress_array_value( $_POST, 'sp_players', array() ) );
|
||||
|
||||
// Update 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, sportspress_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
|
||||
|
||||
//Update player array
|
||||
sportspress_update_post_meta_recursive( $post_id, 'sp_player', sportspress_array_value( $_POST, 'sp_player', array() ) );
|
||||
|
||||
break;
|
||||
|
||||
endswitch;
|
||||
}
|
||||
add_action( 'save_post', 'sportspress_save_post' );
|
||||
24
admin/hooks/the-content.php
Normal file
24
admin/hooks/the-content.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
function sportspress_the_content( $content ) {
|
||||
if ( is_singular( 'sp_team' ) && in_the_loop() ):
|
||||
|
||||
elseif ( is_singular( 'sp_table' ) && in_the_loop() ):
|
||||
|
||||
global $post;
|
||||
|
||||
// Display league table
|
||||
$content .= sportspress_league_table( $post->ID );
|
||||
|
||||
elseif ( is_singular( 'sp_list' ) && in_the_loop() ):
|
||||
|
||||
global $post;
|
||||
|
||||
// Display player list
|
||||
$content .= sportspress_player_list( $post->ID );
|
||||
|
||||
endif;
|
||||
|
||||
return $content;
|
||||
}
|
||||
add_filter( 'the_content', 'sportspress_the_content' );
|
||||
add_filter( 'get_the_content', 'sportspress_the_content' );
|
||||
12
admin/hooks/wp-enqueue-scripts.php
Normal file
12
admin/hooks/wp-enqueue-scripts.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
function sportspress_enqueue_scripts() {
|
||||
// Styles
|
||||
wp_register_style( 'sportspress', SPORTSPRESS_PLUGIN_URL . 'assets/css/sportspress.css', array(), time() );
|
||||
wp_enqueue_style( 'sportspress');
|
||||
|
||||
// Scripts
|
||||
wp_enqueue_script( 'jquery' );
|
||||
wp_enqueue_script( 'jquery-datatables', SPORTSPRESS_PLUGIN_URL .'/assets/js/jquery.dataTables.min.js', array( 'jquery' ), '1.9.4', true );
|
||||
wp_enqueue_script( 'sportspress', SPORTSPRESS_PLUGIN_URL .'/assets/js/sportspress.js', array( 'jquery' ), time(), true );
|
||||
}
|
||||
add_action( 'wp_enqueue_scripts', 'sportspress_enqueue_scripts' );
|
||||
19
admin/hooks/wp-insert-post-data.php
Normal file
19
admin/hooks/wp-insert-post-data.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
function sportspress_insert_post_data( $data, $postarr ) {
|
||||
|
||||
if( $data['post_type'] == 'sp_event' && $data['post_title'] == '' ):
|
||||
|
||||
$teams = (array)$postarr['sp_team'];
|
||||
|
||||
$team_names = array();
|
||||
foreach( $teams as $team ):
|
||||
$team_names[] = get_the_title( $team );
|
||||
endforeach;
|
||||
|
||||
$data['post_title'] = implode( ' ' . __( 'vs', 'sportspress' ) . ' ', $team_names );
|
||||
|
||||
endif;
|
||||
|
||||
return $data;
|
||||
}
|
||||
add_filter( 'wp_insert_post_data' , 'sportspress_insert_post_data' , '99', 2 );
|
||||
Reference in New Issue
Block a user