Merge pull request #21669 from woocommerce/fix/helper-not-able-to-detect-local-woo-plugin

Add File Headers filter at 'plugins_loaded' hook so that WooCommerce Helper can detect all locally installed Woo plugins
This commit is contained in:
Claudiu Lodromanean 2018-12-11 11:08:49 -08:00 committed by GitHub
commit b70fed6868
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 12 deletions

View File

@ -22,6 +22,7 @@ class WC_Admin {
* Constructor.
*/
public function __construct() {
add_action( 'plugins_loaded', array( $this, 'preload_helper' ), 9 );
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 some functionality 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.
*/

View File

@ -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();

View File

@ -32,8 +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' ) );
// Attempt to toggle subscription state upon plugin activation/deactivation
add_action( 'activated_plugin', array( __CLASS__, 'activated_plugin' ) );
@ -1008,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.
*/