Refactored code to add filters on plugins_loaded
This commit is contained in:
parent
b5b60c93b7
commit
c7fc4a9521
|
@ -22,6 +22,7 @@ class WC_Admin {
|
|||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'plugins_loaded', array( $this, 'preload_helper' ) );
|
||||
add_action( 'init', array( $this, 'includes' ) );
|
||||
add_action( 'current_screen', array( $this, 'conditional_includes' ) );
|
||||
add_action( 'admin_init', array( $this, 'buffer' ), 1 );
|
||||
|
@ -86,6 +87,13 @@ class WC_Admin {
|
|||
include_once dirname( __FILE__ ) . '/helper/class-wc-helper.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Preloads functionality part of the Helper to be loaded on the `plugins_loaded` hook
|
||||
*/
|
||||
public function preload_helper() {
|
||||
include_once dirname( __FILE__ ) . '/helper/class-wc-helper-file-headers.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Include admin files conditionally.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
/**
|
||||
* WooCommerce Admin
|
||||
*
|
||||
* @class WC_Admin
|
||||
* @author WooThemes
|
||||
* @category Admin
|
||||
* @package WooCommerce/Admin
|
||||
* @version 3.5.2
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* WC_Helper_File_Headers Class
|
||||
*
|
||||
* Adds some filters to be able to parse the `Woo` header from locally
|
||||
* installed Woo plugins and themes
|
||||
*/
|
||||
class WC_Helper_File_Headers {
|
||||
|
||||
/**
|
||||
* Load functions adds the `extra_headers` filter on the `extra_plugin_headers`
|
||||
* and `extra_theme_headers` hooks.
|
||||
*/
|
||||
public static function load() {
|
||||
add_filter( 'extra_plugin_headers', array( __CLASS__, 'extra_headers' ) );
|
||||
add_filter( 'extra_theme_headers', array( __CLASS__, 'extra_headers' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional theme style.css and plugin file headers.
|
||||
*
|
||||
* Format: Woo: product_id:file_id
|
||||
*/
|
||||
public static function extra_headers( $headers ) {
|
||||
$headers[] = 'Woo';
|
||||
return $headers;
|
||||
}
|
||||
}
|
||||
|
||||
WC_Helper_File_Headers::load();
|
|
@ -32,20 +32,6 @@ class WC_Helper {
|
|||
add_action( 'current_screen', array( __CLASS__, 'current_screen' ) );
|
||||
add_action( 'woocommerce_helper_output', array( __CLASS__, 'render_helper_output' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_enqueue_scripts' ) );
|
||||
add_filter( 'extra_plugin_headers', array( __CLASS__, 'extra_headers' ) );
|
||||
add_filter( 'extra_theme_headers', array( __CLASS__, 'extra_headers' ) );
|
||||
|
||||
/**
|
||||
* Clean the plugins cache since self::extra_headers() adds an additional plugin header
|
||||
* which needs to be parsed for detecting locally installed Woo plugins
|
||||
*/
|
||||
wp_clean_plugins_cache();
|
||||
|
||||
/**
|
||||
* Clean the themes cache since self::extra_headers() adds an additional theme header
|
||||
* which needs to be parsed for detecting locally installed Woo themes
|
||||
*/
|
||||
wp_clean_themes_cache();
|
||||
|
||||
// Attempt to toggle subscription state upon plugin activation/deactivation
|
||||
add_action( 'activated_plugin', array( __CLASS__, 'activated_plugin' ) );
|
||||
|
@ -1020,16 +1006,6 @@ class WC_Helper {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional theme style.css and plugin file headers.
|
||||
*
|
||||
* Format: Woo: product_id:file_id
|
||||
*/
|
||||
public static function extra_headers( $headers ) {
|
||||
$headers[] = 'Woo';
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a list of locally installed Woo extensions.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue