Move admin functions
This commit is contained in:
@@ -34,7 +34,7 @@ add_action( 'admin_print_styles', 'sportspress_admin_notices_styles' );
|
||||
* @return void
|
||||
*/
|
||||
function sportspress_admin_install_notices() {
|
||||
// include( dirname( SP_PLUGIN_FILE ) . '/admin/includes/notice-install.php' );
|
||||
// include( dirname( SP_PLUGIN_FILE ) . '/includes/admin/views/notice-install.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,5 +44,5 @@ function sportspress_admin_install_notices() {
|
||||
* @return void
|
||||
*/
|
||||
function sportspress_theme_check_notice() {
|
||||
// include( dirname( SP_PLUGIN_FILE ) . '/admin/includes/notice-theme-support.php' );
|
||||
// include( dirname( SP_PLUGIN_FILE ) . '/includes/admin/views/notice-theme-support.php' );
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
function sportspress_event_importer() {
|
||||
require_once ABSPATH . 'wp-admin/includes/import.php';
|
||||
|
||||
if ( ! class_exists( 'WP_Importer' ) ) {
|
||||
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
|
||||
if ( file_exists( $class_wp_importer ) )
|
||||
require $class_wp_importer;
|
||||
}
|
||||
|
||||
// includes
|
||||
require dirname( SP_PLUGIN_FILE ) . '/admin/tools/event-importer.php';
|
||||
|
||||
// Dispatch
|
||||
$importer = new SP_Event_Importer();
|
||||
$importer->dispatch();
|
||||
}
|
||||
|
||||
function sportspress_team_importer() {
|
||||
require_once ABSPATH . 'wp-admin/includes/import.php';
|
||||
|
||||
if ( ! class_exists( 'WP_Importer' ) ) {
|
||||
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
|
||||
if ( file_exists( $class_wp_importer ) )
|
||||
require $class_wp_importer;
|
||||
}
|
||||
|
||||
// includes
|
||||
require dirname( SP_PLUGIN_FILE ) . '/admin/tools/team-importer.php';
|
||||
|
||||
// Dispatch
|
||||
$importer = new SP_Team_Importer();
|
||||
$importer->dispatch();
|
||||
}
|
||||
|
||||
function sportspress_player_importer() {
|
||||
require_once ABSPATH . 'wp-admin/includes/import.php';
|
||||
|
||||
if ( ! class_exists( 'WP_Importer' ) ) {
|
||||
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
|
||||
if ( file_exists( $class_wp_importer ) )
|
||||
require $class_wp_importer;
|
||||
}
|
||||
|
||||
// includes
|
||||
require dirname( SP_PLUGIN_FILE ) . '/admin/tools/player-importer.php';
|
||||
|
||||
// Dispatch
|
||||
$importer = new SP_Player_Importer();
|
||||
$importer->dispatch();
|
||||
}
|
||||
|
||||
function sportspress_register_importers() {
|
||||
register_importer( 'sportspress_event_csv', __( 'SportsPress Events (CSV)', 'sportspress' ), __( 'Import <strong>events</strong> from a csv file.', 'sportspress'), 'sportspress_event_importer' );
|
||||
register_importer( 'sportspress_team_csv', __( 'SportsPress Teams (CSV)', 'sportspress' ), __( 'Import <strong>teams</strong> from a csv file.', 'sportspress'), 'sportspress_team_importer' );
|
||||
register_importer( 'sportspress_player_csv', __( 'SportsPress Players (CSV)', 'sportspress' ), __( 'Import <strong>players</strong> from a csv file.', 'sportspress'), 'sportspress_player_importer' );
|
||||
}
|
||||
add_action( 'admin_init', 'sportspress_register_importers' );
|
||||
102
includes/admin/class-sp-admin-importers.php
Normal file
102
includes/admin/class-sp-admin-importers.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* Setup importers for SP data.
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Admin_Importers' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Admin_Importers Class
|
||||
*/
|
||||
class SP_Admin_Importers {
|
||||
|
||||
/**
|
||||
* Hook in tabs.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'admin_init', array( $this, 'register_importers' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add menu items
|
||||
*/
|
||||
public function register_importers() {
|
||||
register_importer( 'sportspress_event_csv', __( 'SportsPress Events (CSV)', 'sportspress' ), __( 'Import <strong>events</strong> from a csv file.', 'sportspress'), array( $this, 'events_importer' ) );
|
||||
register_importer( 'sportspress_team_csv', __( 'SportsPress Teams (CSV)', 'sportspress' ), __( 'Import <strong>teams</strong> from a csv file.', 'sportspress'), array( $this, 'teams_importer' ) );
|
||||
register_importer( 'sportspress_player_csv', __( 'SportsPress Players (CSV)', 'sportspress' ), __( 'Import <strong>players</strong> from a csv file.', 'sportspress'), array( $this, 'players_importer' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add menu item
|
||||
*/
|
||||
public function events_importer() {
|
||||
// Load Importer API
|
||||
require_once ABSPATH . 'wp-admin/includes/import.php';
|
||||
|
||||
if ( ! class_exists( 'WP_Importer' ) ) {
|
||||
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
|
||||
if ( file_exists( $class_wp_importer ) )
|
||||
require $class_wp_importer;
|
||||
}
|
||||
|
||||
// Includes
|
||||
require 'importers/class-sp-event-importer.php';
|
||||
|
||||
// Dispatch
|
||||
$importer = new SP_Event_Importer();
|
||||
$importer->dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add menu item
|
||||
*/
|
||||
public function teams_importer() {
|
||||
// Load Importer API
|
||||
require_once ABSPATH . 'wp-admin/includes/import.php';
|
||||
|
||||
if ( ! class_exists( 'WP_Importer' ) ) {
|
||||
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
|
||||
if ( file_exists( $class_wp_importer ) )
|
||||
require $class_wp_importer;
|
||||
}
|
||||
|
||||
// Includes
|
||||
require 'importers/class-sp-team-importer.php';
|
||||
|
||||
// Dispatch
|
||||
$importer = new SP_Team_Importer();
|
||||
$importer->dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add menu item
|
||||
*/
|
||||
public function players_importer() {
|
||||
// Load Importer API
|
||||
require_once ABSPATH . 'wp-admin/includes/import.php';
|
||||
|
||||
if ( ! class_exists( 'WP_Importer' ) ) {
|
||||
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
|
||||
if ( file_exists( $class_wp_importer ) )
|
||||
require $class_wp_importer;
|
||||
}
|
||||
|
||||
// Includes
|
||||
require 'importers/class-sp-player-importer.php';
|
||||
|
||||
// Dispatch
|
||||
$importer = new SP_Player_Importer();
|
||||
$importer->dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Admin_Importers();
|
||||
97
includes/admin/class-sp-admin.php
Normal file
97
includes/admin/class-sp-admin.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* SportsPress Admin.
|
||||
*
|
||||
* @class SP_Admin
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
class SP_Admin {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'init', array( $this, 'includes' ) );
|
||||
add_action( 'current_screen', array( $this, 'conditonal_includes' ) );
|
||||
add_action( 'admin_init', array( $this, 'prevent_admin_access' ) );
|
||||
// add_action( 'admin_init', array( $this, 'preview_emails' ) );
|
||||
// add_action( 'admin_footer', 'wc_print_js', 25 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Include any classes we need within admin.
|
||||
*/
|
||||
public function includes() {
|
||||
// Functions
|
||||
// include_once( 'wc-admin-functions.php' );
|
||||
// include_once( 'wc-meta-box-functions.php' );
|
||||
|
||||
// Classes
|
||||
// include_once( 'class-wc-admin-post-types.php' );
|
||||
// include_once( 'class-wc-admin-taxonomies.php' );
|
||||
|
||||
// Classes we only need if the ajax is not-ajax
|
||||
if ( ! is_ajax() ) {
|
||||
// include( 'class-wc-admin-menus.php' );
|
||||
// include( 'class-wc-admin-welcome.php' );
|
||||
// include( 'class-wc-admin-notices.php' );
|
||||
// include( 'class-wc-admin-assets.php' );
|
||||
// include( 'class-wc-admin-permalink-settings.php' );
|
||||
// include( 'class-wc-admin-editor.php' );
|
||||
|
||||
// Help
|
||||
// if ( apply_filters( 'sportspress_enable_admin_help_tab', true ) )
|
||||
// include( 'class-wc-admin-help.php' );
|
||||
}
|
||||
|
||||
// Importers
|
||||
if ( defined( 'WP_LOAD_IMPORTERS' ) )
|
||||
include( 'class-sp-admin-importers.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Include admin files conditionally
|
||||
*/
|
||||
public function conditonal_includes() {
|
||||
$screen = get_current_screen();
|
||||
|
||||
switch ( $screen->id ) {
|
||||
case 'dashboard' :
|
||||
include( 'class-sp-admin-dashboard.php' );
|
||||
break;
|
||||
case 'users' :
|
||||
case 'user' :
|
||||
case 'profile' :
|
||||
case 'user-edit' :
|
||||
include( 'class-sp-admin-profile.php' );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent any user who cannot 'edit_posts' (subscribers, customers etc) from accessing admin
|
||||
*/
|
||||
public function prevent_admin_access() {
|
||||
$prevent_access = false;
|
||||
|
||||
if ( 'yes' == get_option( 'sportspress_lock_down_admin' ) && ! is_ajax() && ! ( current_user_can( 'edit_posts' ) || current_user_can( 'manage_sportspress' ) ) && basename( $_SERVER["SCRIPT_FILENAME"] ) !== 'admin-post.php' ) {
|
||||
$prevent_access = true;
|
||||
}
|
||||
|
||||
$prevent_access = apply_filters( 'sportspress_prevent_admin_access', $prevent_access );
|
||||
|
||||
if ( $prevent_access ) {
|
||||
wp_safe_redirect( get_permalink( sp_get_page_id( 'myaccount' ) ) );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new SP_Admin();
|
||||
26
includes/sp-conditional-functions.php
Normal file
26
includes/sp-conditional-functions.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Conditional Functions
|
||||
*
|
||||
* Functions for determining the current query/page.
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Core
|
||||
* @package SportsPress/Functions
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! function_exists( 'is_ajax' ) ) {
|
||||
|
||||
/**
|
||||
* is_ajax - Returns true when the page is loaded via ajax.
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function is_ajax() {
|
||||
return defined( 'DOING_AJAX' );
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,10 @@
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
// Include core functions
|
||||
include( 'sp-conditional-functions.php' );
|
||||
include( 'sp-deprecated-functions.php' );
|
||||
|
||||
/**
|
||||
* Get templates passing attributes and including the file.
|
||||
*
|
||||
|
||||
@@ -1 +1,13 @@
|
||||
sp-template-functions.php
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Template
|
||||
*
|
||||
* Functions for the templating system.
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Core
|
||||
* @package SportsPress/Functions
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
@@ -173,7 +173,6 @@ final class SportsPress {
|
||||
|
||||
// Functions
|
||||
include_once( 'includes/sp-core-functions.php' );
|
||||
include_once( 'includes/sp-deprecated-functions.php' );
|
||||
|
||||
// Options
|
||||
include_once( 'admin/settings/settings.php' );
|
||||
@@ -201,6 +200,14 @@ final class SportsPress {
|
||||
include_once( 'admin/post-types/staff.php' );
|
||||
//include_once( 'admin/post-types/directory.php' );
|
||||
|
||||
if ( is_admin() ) {
|
||||
include_once( 'includes/admin/class-sp-admin.php' );
|
||||
}
|
||||
|
||||
if ( defined( 'DOING_AJAX' ) ) {
|
||||
$this->ajax_includes();
|
||||
}
|
||||
|
||||
if ( ! is_admin() ) {
|
||||
$this->frontend_includes();
|
||||
}
|
||||
@@ -211,9 +218,6 @@ final class SportsPress {
|
||||
// Terms
|
||||
include_once( 'admin/terms/venue.php' );
|
||||
|
||||
// Tools
|
||||
include_once( 'admin/tools/importers.php' );
|
||||
|
||||
// Typical request actions
|
||||
include_once( 'admin/hooks/plugins-loaded.php' );
|
||||
include_once( 'admin/hooks/wp-enqueue-scripts.php' );
|
||||
@@ -251,6 +255,13 @@ final class SportsPress {
|
||||
include_once( 'admin/hooks/register-activation-hook.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Include required ajax files.
|
||||
*/
|
||||
public function ajax_includes() {
|
||||
include_once( 'includes/class-sp-ajax.php' ); // Ajax functions for admin and the front-end
|
||||
}
|
||||
|
||||
/**
|
||||
* Include required frontend files.
|
||||
*/
|
||||
@@ -262,6 +273,7 @@ final class SportsPress {
|
||||
* Function used to Init SportsPress Template Functions - This makes them pluggable by plugins and themes.
|
||||
*/
|
||||
public function include_template_functions() {
|
||||
include_once( 'includes/sp-template-functions.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user