Skip to content

Commit

Permalink
Merge branch 'update/ecommerce-version-1.3.44' of https://github.com/…
Browse files Browse the repository at this point in the history
…newfold-labs/wp-module-ecommerce into update/ecommerce-version-1.3.44
  • Loading branch information
ramyakrishnai committed Sep 18, 2024
2 parents 270b9d5 + ee15615 commit 63bcc01
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions includes/ECommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ class ECommerce {
* @param Container $container Container loaded from the brand plugin.
*/
public function __construct( Container $container ) {
$capability = new SiteCapabilities();
$hasYithExtended = $capability->get( 'hasYithExtended' );
$canAccessGlobalCTB = $capability->get( 'canAccessGlobalCTB' );

$this->container = $container;
// Module functionality goes here
Expand Down Expand Up @@ -110,14 +107,7 @@ public function __construct( Container $container ) {
add_action( 'admin_enqueue_scripts', array( $this, 'set_wpnav_collapse_setting' ) );
add_action('admin_footer', array( $this, 'remove_woocommerce_ssl_notice' ), 20);

if ( ( $container->plugin()->id === 'bluehost' && ( $canAccessGlobalCTB || $hasYithExtended ) ) || ( $container->plugin()->id === 'hostgator' && $hasYithExtended ) ) {
add_filter( 'admin_menu', array( $this, 'custom_add_promotion_menu_item' ) );
add_action( 'woocommerce_product_options_general_product_data', array( $this, 'custom_product_general_options' ) );
add_action( 'woocommerce_product_options_related', array( $this, 'custom_product_general_options' ) );
add_action( 'woocommerce_product_data_tabs', array( $this, 'custom_product_write_panel_tabs' ) );
add_action( 'woocommerce_product_data_panels', array( $this, 'promotion_product_data' ) );
add_action( 'admin_head', array( $this, 'action_admin_head' ) );
}
add_action( 'admin_init', array( $this, 'admin_init_conditional_on_capabilities' ) );

// Handle WonderCart Integrations
if ( is_plugin_active( 'wonder-cart/init.php' ) ) {
Expand Down Expand Up @@ -621,6 +611,40 @@ public function remove_woocommerce_ssl_notice() {
}
}

/**
* Add actions and filters that are conditionally added depending on the Site's capabilities.
*
* Running the capabilities check after `admin_init` with `is_admin()` `true` ensures no HTTP requests are made
* for frontend page loads.
*
* `admin_init` runs in `wp-admin/admin.php:175`, `wp-admin/admin-ajax.php:45`, and `wp-admin/admin-post:30`.
* Each of the hooks in this function are UI (HTML) related, so only need to run inside `is_admin()`.
*
* @hooked admin_init
*/
public function admin_init_conditional_on_capabilities() {

if ( ! is_admin() ) {
return;
}

$capability = new SiteCapabilities();
$hasYithExtended = $capability->get( 'hasYithExtended' );
$canAccessGlobalCTB = $capability->get( 'canAccessGlobalCTB' );

if (
( $this->container->plugin()->id === 'bluehost' && ( $canAccessGlobalCTB || $hasYithExtended ) )
|| ( $this->container->plugin()->id === 'hostgator' && $hasYithExtended )
) {
add_filter( 'admin_menu', array( $this, 'custom_add_promotion_menu_item' ) );
add_action( 'woocommerce_product_options_general_product_data', array( $this, 'custom_product_general_options' ) );
add_action( 'woocommerce_product_options_related', array( $this, 'custom_product_general_options' ) );
add_action( 'woocommerce_product_data_tabs', array( $this, 'custom_product_write_panel_tabs' ) );
add_action( 'woocommerce_product_data_panels', array( $this, 'promotion_product_data' ) );
add_action( 'admin_head', array( $this, 'action_admin_head' ) );
}
}

/**
* Add custom column header for post/page/product screen
*
Expand Down

0 comments on commit 63bcc01

Please sign in to comment.