balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class-redux-themecheck.php (5756B)


      1 <?php
      2 /**
      3  * Redux Themecheck Class
      4  *
      5  * @class Redux_Core
      6  * @version 3.5.0
      7  * @package Redux Framework/Classes
      8  */
      9 
     10 defined( 'ABSPATH' ) || exit;
     11 
     12 // Don't duplicate me!
     13 if ( ! class_exists( 'Redux_ThemeCheck', false ) ) {
     14 
     15 	/**
     16 	 * Class Redux_ThemeCheck
     17 	 */
     18 	class Redux_ThemeCheck {
     19 
     20 		/**
     21 		 * Plugin version, used for cache-busting of style and script file references.
     22 		 *
     23 		 * @since   1.0.0
     24 		 * @var     string
     25 		 */
     26 		protected $version = '1.0.0';
     27 
     28 		/**
     29 		 * Instance of this class.
     30 		 *
     31 		 * @since    1.0.0
     32 		 * @var      object
     33 		 */
     34 		protected static $instance = null;
     35 
     36 		/**
     37 		 * Instance of the Redux class.
     38 		 *
     39 		 * @since    1.0.0
     40 		 * @var      object
     41 		 */
     42 		protected static $redux = null;
     43 
     44 		/**
     45 		 * Details of the embedded Redux class.
     46 		 *
     47 		 * @since    1.0.0
     48 		 * @var      object
     49 		 */
     50 		protected static $redux_details = null;
     51 
     52 		/**
     53 		 * Slug for various elements.
     54 		 *
     55 		 * @since   1.0.0
     56 		 * @var     string
     57 		 */
     58 		protected $slug = 'redux_themecheck';
     59 
     60 		/**
     61 		 * Initialize the plugin by setting localization, filters, and administration functions.
     62 		 *
     63 		 * @since     1.0.0
     64 		 */
     65 		private function __construct() {
     66 			if ( ! class_exists( 'ThemeCheckMain' ) ) {
     67 				return;
     68 			}
     69 
     70 			// Load admin style sheet and JavaScript.
     71 			add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
     72 			add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
     73 
     74 			add_action( 'themecheck_checks_loaded', array( $this, 'disable_checks' ) );
     75 			add_action( 'themecheck_checks_loaded', array( $this, 'add_checks' ) );
     76 		}
     77 
     78 		/**
     79 		 * Return an instance of this class.
     80 		 *
     81 		 * @since     1.0.0
     82 		 * @return    object    A single instance of this class.
     83 		 */
     84 		public static function get_instance() {
     85 
     86 			// If the single instance hasn't been set, set it now.
     87 			if ( null === self::$instance ) {
     88 				self::$instance = new self();
     89 			}
     90 
     91 			return self::$instance;
     92 		}
     93 
     94 		/**
     95 		 * Return an instance of this class.
     96 		 *
     97 		 * @since     1.0.0
     98 		 * @return    object    A single instance of this class.
     99 		 */
    100 		public static function get_redux_instance() {
    101 
    102 			// If the single instance hasn't been set, set it now.
    103 			if ( null === self::$redux && Redux_Core::$as_plugin ) {
    104 				self::$redux = new ReduxFramework();
    105 				self::$redux->init();
    106 			}
    107 
    108 			return self::$redux;
    109 		}
    110 
    111 		/**
    112 		 * Return the Redux path info, if had.
    113 		 *
    114 		 * @param array $php_files Array of files to check.
    115 		 *
    116 		 * @return    object    A single instance of this class.
    117 		 *@since     1.0.0
    118 		 */
    119 		public static function get_redux_details( array $php_files = array() ) {
    120 			if ( null === self::$redux_details ) {
    121 				foreach ( $php_files as $php_key => $phpfile ) {
    122 
    123 					// phpcs:ignore Generic.Strings.UnnecessaryStringConcat
    124 					if ( false !== strpos( $phpfile, 'class' . ' ReduxFramework {' ) ) {
    125 						self::$redux_details               = array(
    126 							'filename' => Redux_Core::strtolower( basename( $php_key ) ),
    127 							'path'     => $php_key,
    128 						);
    129 						self::$redux_details['dir']        = str_replace( basename( $php_key ), '', $php_key );
    130 						self::$redux_details['parent_dir'] = str_replace( basename( self::$redux_details['dir'] ) . '/', '', self::$redux_details['dir'] );
    131 					}
    132 				}
    133 			}
    134 			if ( null === self::$redux_details ) {
    135 				self::$redux_details = false;
    136 			}
    137 
    138 			return self::$redux_details;
    139 		}
    140 
    141 		/**
    142 		 * Disable Theme-Check checks that aren't relevant for ThemeForest themes
    143 		 *
    144 		 * @since    1.0.0
    145 		 */
    146 		public function disable_checks() {
    147 			global $themechecks;
    148 
    149 			/** $checks_to_disable = array(
    150 			 *    'IncludeCheck',
    151 			 *    'I18NCheck',
    152 			 *    'AdminMenu',
    153 			 *    'Bad_Checks',
    154 			 *    'MalwareCheck',
    155 			 *    'Theme_Support',
    156 			 *    'CustomCheck',
    157 			 *    'EditorStyleCheck',
    158 			 *    'IframeCheck',
    159 			 * );
    160 			 * foreach ( $themechecks as $keyindex => $check ) {
    161 			 *    if ( $check instanceof themecheck ) {
    162 			 *        $check_class = get_class( $check );
    163 			 *        if ( in_array( $check_class, $checks_to_disable ) ) {
    164 			 *            unset( $themechecks[$keyindex] );
    165 			 *        }
    166 			 *    }
    167 			 * }
    168 			 */
    169 		}
    170 
    171 		/**
    172 		 * Disable Theme-Check checks that aren't relevant for ThemeForest themes
    173 		 *
    174 		 * @since    1.0.0
    175 		 */
    176 		public function add_checks() {
    177 			global $themechecks;
    178 
    179 			// load all the checks in the checks directory.
    180 			$dir = 'checks';
    181 			foreach ( glob( dirname( __FILE__ ) . '/' . $dir . '/*.php' ) as $file ) {
    182 				require_once $file;
    183 			}
    184 		}
    185 
    186 		/**
    187 		 * Register and enqueue admin-specific style sheet.
    188 		 *
    189 		 * @since     1.0.1
    190 		 */
    191 		public function enqueue_admin_styles() {
    192 			$screen = get_current_screen();
    193 			if ( 'appearance_page_themecheck' === $screen->id ) {
    194 				wp_enqueue_style( $this->slug . '-admin-styles', Redux_Core::$url . 'inc/themecheck/css/admin.css', array(), $this->version );
    195 			}
    196 		}
    197 
    198 		/**
    199 		 * Register and enqueue admin-specific JavaScript.
    200 		 *
    201 		 * @since     1.0.1
    202 		 */
    203 		public function enqueue_admin_scripts() {
    204 
    205 			$screen = get_current_screen();
    206 
    207 			if ( 'appearance_page_themecheck' === $screen->id ) {
    208 				wp_enqueue_script(
    209 					$this->slug . '-admin-script',
    210 					Redux_Core::$url . 'inc/themecheck/js/admin' . Redux_Functions::is_min() . '.js',
    211 					array( 'jquery' ),
    212 					$this->version,
    213 					true
    214 				);
    215 
    216 				if ( ! isset( $_POST['themename'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
    217 
    218 					$intro  = '<h2>Redux Theme-Check</h2>';
    219 					$intro .= '<p>Extra checks for Redux to ensure you\'re ready for marketplace submission to marketplaces.</p>';
    220 
    221 					$redux_check_intro['text'] = $intro;
    222 
    223 					wp_localize_script( $this->slug . '-admin-script', 'redux_check_intro', $redux_check_intro );
    224 				}
    225 			}
    226 		}
    227 	}
    228 
    229 	Redux_ThemeCheck::get_instance();
    230 }