Admin notice to configure sport
This commit is contained in:
138
includes/admin/class-sp-admin-notices.php
Normal file
138
includes/admin/class-sp-admin-notices.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* Display notices in admin.
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.7
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Admin_Notices' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Admin_Notices Class
|
||||
*/
|
||||
class SP_Admin_Notices {
|
||||
|
||||
/**
|
||||
* Hook in tabs.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'switch_theme', array( $this, 'reset_admin_notices' ) );
|
||||
add_action( 'sportspress_updated', array( $this, 'reset_admin_notices' ) );
|
||||
add_action( 'admin_print_styles', array( $this, 'add_notices' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset notices for themes when switched or a new version of SP is installed
|
||||
*/
|
||||
public function reset_admin_notices() {
|
||||
update_option( 'sportspress_admin_notices', array( 'template_files', 'theme_support' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add notices + styles if needed.
|
||||
*/
|
||||
public function add_notices() {
|
||||
if ( get_option( '_sp_needs_config' ) == 1 ) {
|
||||
wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) );
|
||||
add_action( 'admin_notices', array( $this, 'install_notice' ) );
|
||||
}
|
||||
|
||||
$notices = get_option( 'sportspress_admin_notices', array() );
|
||||
|
||||
if ( isset( $_GET['skip_install_sportspress'] ) ):
|
||||
update_option( '_sp_needs_config', $_GET['_sp_needs_config'] ? 0 : 1 );
|
||||
endif;
|
||||
|
||||
if ( ! empty( $_GET['hide_theme_support_notice'] ) ) {
|
||||
$notices = array_diff( $notices, array( 'theme_support' ) );
|
||||
update_option( 'sportspress_admin_notices', $notices );
|
||||
}
|
||||
|
||||
if ( ! empty( $_GET['hide_template_files_notice'] ) ) {
|
||||
$notices = array_diff( $notices, array( 'template_files' ) );
|
||||
update_option( 'sportspress_admin_notices', $notices );
|
||||
}
|
||||
|
||||
if ( in_array( 'theme_support', $notices ) && ! current_theme_supports( 'sportspress' ) ) {
|
||||
$template = get_option( 'template' );
|
||||
|
||||
if ( ! in_array( $template, array( 'twentyfourteen', 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten' ) ) ) {
|
||||
wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) );
|
||||
add_action( 'admin_notices', array( $this, 'theme_check_notice' ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( in_array( 'template_files', $notices ) ) {
|
||||
wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) );
|
||||
// add_action( 'admin_notices', array( $this, 'template_file_check_notice' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the install notices
|
||||
*/
|
||||
public function install_notice() {
|
||||
$screen = get_current_screen();
|
||||
|
||||
// If we have just installed, show a message with the install pages button
|
||||
if ( get_option( '_sp_needs_config' ) == 1 && $screen->id != 'settings_page_sportspress' ) {
|
||||
include( 'views/html-notice-install.php' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the Theme Check notice
|
||||
*/
|
||||
public function theme_check_notice() {
|
||||
// include( 'views/html-notice-theme-support.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a notice highlighting bad template files
|
||||
*/
|
||||
public function template_file_check_notice() {
|
||||
if ( isset( $_GET['page'] ) && 'sp-status' == $_GET['page'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$status = include( 'class-sp-admin-status.php' );
|
||||
$core_templates = $status->scan_template_files( SP()->plugin_path() . '/templates' );
|
||||
$outdated = false;
|
||||
|
||||
foreach ( $core_templates as $file ) {
|
||||
$theme_file = false;
|
||||
if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
|
||||
$theme_file = get_stylesheet_directory() . '/' . $file;
|
||||
} elseif ( file_exists( get_stylesheet_directory() . '/sportspress/' . $file ) ) {
|
||||
$theme_file = get_stylesheet_directory() . '/sportspress/' . $file;
|
||||
} elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
|
||||
$theme_file = get_template_directory() . '/' . $file;
|
||||
} elseif( file_exists( get_template_directory() . '/sportspress/' . $file ) ) {
|
||||
$theme_file = get_template_directory() . '/sportspress/' . $file;
|
||||
}
|
||||
|
||||
if ( $theme_file ) {
|
||||
$core_version = $status->get_file_version( SP()->plugin_path() . '/templates/' . $file );
|
||||
$theme_version = $status->get_file_version( $theme_file );
|
||||
|
||||
if ( $core_version && $theme_version && version_compare( $theme_version, $core_version, '<' ) ) {
|
||||
$outdated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $outdated ) {
|
||||
include( 'views/html-notice-template-check.php' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Admin_Notices();
|
||||
Reference in New Issue
Block a user