Skip to content

Commit

Permalink
linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ramyakrishnai committed Apr 10, 2024
1 parent 07e5e03 commit c79cad7
Showing 1 changed file with 121 additions and 102 deletions.
223 changes: 121 additions & 102 deletions includes/ECommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,47 +94,46 @@ public function __construct( Container $container ) {
add_action( 'before_woocommerce_init', array( $this, 'custom_payment_gateways_order' ) );
add_action( 'before_woocommerce_init', array( $this, 'dismiss_woo_payments_cta' ) );
add_action( 'load-toplevel_page_' . $container->plugin()->id, array( $this, 'disable_creative_mail_banner' ) );
add_action( 'activated_plugin', array( $this, 'detect_plugin_activation' ), 10, 1 );

$brandNameValue = $container->plugin()->brand;
$this->set_wpnav_collapse_setting($brandNameValue);

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'));
};

// Handle WonderCart Integrations
if ( is_plugin_active( 'wonder-cart/init.php' ) ) {
$wonder_cart = new WonderCart( $container );
$wonder_cart->init();
}

CaptiveFlow::init();
WooCommerceBacklink::init( $container );
register_meta(
'post',
'nf_dc_page',
array(
'type' => 'string',
'description' => 'Reference to page category',
'show_in_rest' => true,
'single' => true,
)
);
add_filter( 'newfold-runtime', array( $this, 'add_to_runtime' ) );
$this->add_filters(
array( 'postbox_classes_page_wpseo_meta', 'postbox_classes_post_wpseo_meta', 'postbox_classes_product_wpseo_meta' ),
function ( $classes ) {
$classes[] = 'closed';
return $classes;
}
);
add_action( 'activated_plugin', array( $this, 'detect_plugin_activation' ), 10, 1 );

$brandNameValue = $container->plugin()->brand;
$this->set_wpnav_collapse_setting( $brandNameValue );

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' ) );
}

// Handle WonderCart Integrations
if ( is_plugin_active( 'wonder-cart/init.php' ) ) {
$wonder_cart = new WonderCart( $container );
$wonder_cart->init();
}

CaptiveFlow::init();
WooCommerceBacklink::init( $container );
register_meta(
'post',
'nf_dc_page',
array(
'type' => 'string',
'description' => 'Reference to page category',
'show_in_rest' => true,
'single' => true,
)
);
add_filter( 'newfold-runtime', array( $this, 'add_to_runtime' ) );
$this->add_filters(
array( 'postbox_classes_page_wpseo_meta', 'postbox_classes_post_wpseo_meta', 'postbox_classes_product_wpseo_meta' ),
function ( $classes ) {
$classes[] = 'closed';
return $classes;
}
);

// Handle WonderCart Integrations
if ( is_plugin_active( 'wonder-cart/init.php' ) ) {
Expand Down Expand Up @@ -167,10 +166,10 @@ function ( $classes ) {
/**
* Add multiple filters to a closure
*
* @param $tags
* @param $function_to_add
* @param int $priority
* @param int $accepted_args
* @param string|array $tags The filter name or array of filter names
* @param callable $function_to_add The closure to add to the filter
* @param int|array $priority The priority at which the closure should be added
* @param int|array $accepted_args The number of arguments the closure accepts
*
* @return bool true
*/
Expand All @@ -179,22 +178,26 @@ public static function add_filters( $tags, $function_to_add, $priority = 10, $ac
if ( ! is_array( $tags ) ) {
$tags = array( $tags );
}
// For each filter name
// For each filter name
foreach ( $tags as $index => $tag ) {
add_filter( $tag, $function_to_add, (int) ( is_array( $priority ) ? $priority[ $index ] : $priority ), (int) ( is_array( $accepted_args ) ? $accepted_args[ $index ] : $accepted_args ) );
}

return true;
}
}

/**
* Set the wpnav_collapse setting
*
* @param string $brandNameValue The brand name value
*/
public static function set_wpnav_collapse_setting( $brandNameValue ) {

public static function set_wpnav_collapse_setting($brandNameValue) {

$expiration_time = time() + (10 * 365 * 24 * 60 * 60);
setcookie('nfdbrandname', $brandNameValue, $expiration_time, '/');

wp_enqueue_script( 'nfd_wpnavbar_setting', NFD_ECOMMERCE_PLUGIN_URL . 'vendor/newfold-labs/wp-module-ecommerce/includes/wpnavbar.js', array('jquery'), '1.0', true);

}
$expiration_time = time() + ( 10 * 365 * 24 * 60 * 60 );
setcookie( 'nfdbrandname', $brandNameValue, $expiration_time, '/' );

wp_enqueue_script( 'nfd_wpnavbar_setting', NFD_ECOMMERCE_PLUGIN_URL . 'vendor/newfold-labs/wp-module-ecommerce/includes/wpnavbar.js', array( 'jquery' ), '1.0', true );
}

/**
* Loads the textdomain for the module. This applies only to PHP strings.
Expand All @@ -208,10 +211,20 @@ public static function load_php_textdomain() {
);
}

/**
* Update the experience level
*/
public static function load_experience_level() {
update_option( 'onboarding_experience_level', FlowService::get_experience_level() );
}

/**
* Add values to the runtime object.
*
* @param array $sdk The runtime object.
*
* @return array
*/
public function add_to_runtime( $sdk ) {
$values = array(
'brand_settings' => Brands::get_config( $this->container ),
Expand All @@ -223,6 +236,9 @@ public function add_to_runtime( $sdk ) {
return array_merge( $sdk, array( 'ecommerce' => $values ) );
}

/**
* Redirect to the dashboard after WooCommerce activation.
*/
public function maybe_do_dash_redirect() {
$show_dash = get_option( 'nfd_show_dash_after_woo_activation', false );
if ( $show_dash && ! wp_doing_ajax() ) {
Expand Down Expand Up @@ -319,38 +335,43 @@ public function register_settings() {
}
}

/**
* Load the textdomains for the module.
*/
public function register_textdomains() {
$MODULE_LANG_DIR = $this->container->plugin()->dir . 'vendor/newfold-labs/wp-module-ecommerce/languages';
\load_script_textdomain( 'nfd-ecommerce-dependency', 'wp-module-ecommerce', $MODULE_LANG_DIR );
$current_language = get_locale();
\load_textdomain( 'wp-module-ecommerce', $MODULE_LANG_DIR . '/wp-module-ecommerce-' . $current_language . '.mo' );
}

/**
* Load WP dependencies into the page.
*/
public function register_assets() {
$asset_file = NFD_ECOMMERCE_BUILD_DIR . 'index.asset.php';
if ( file_exists( $asset_file ) ) {
$asset = require $asset_file;
\wp_register_script(
'nfd-ecommerce-dependency',
NFD_ECOMMERCE_PLUGIN_URL,
array_merge( $asset['dependencies'], array() ),
$asset['version']
);
I18nService::load_js_translations(
'wp-module-ecommerce',
'nfd-ecommerce-dependency',
NFD_ECOMMERCE_DIR . '/languages'
);
\wp_enqueue_script( 'nfd-ecommerce-dependency' );
\wp_enqueue_script( 'nfd_wpnavbar_setting' );
}
}
/**
* Load WP dependencies into the page.
*/
public function register_assets() {
$asset_file = NFD_ECOMMERCE_BUILD_DIR . 'index.asset.php';
if ( file_exists( $asset_file ) ) {
$asset = require $asset_file;
\wp_register_script(
'nfd-ecommerce-dependency',
NFD_ECOMMERCE_PLUGIN_URL,
array_merge( $asset['dependencies'], array() ),
$asset['version']
);
I18nService::load_js_translations(
'wp-module-ecommerce',
'nfd-ecommerce-dependency',
NFD_ECOMMERCE_DIR . '/languages'
);
\wp_enqueue_script( 'nfd-ecommerce-dependency' );
\wp_enqueue_script( 'nfd_wpnavbar_setting' );
}
}

/**
* Remove Add coupon field on cart page
*
* @param boolean $enabled The enabled status of the coupon field.
*/
public function disable_coupon_field_on_cart( $enabled ) {
if ( is_cart() ) {
Expand All @@ -373,39 +394,27 @@ public function hide_banner_notice_on_cart() {
<?php
}
}

/**
* Hide the WooCommerce set up task list
*/
public function hide_woocommerce_set_up() {
$hidden_list = get_option( 'woocommerce_task_list_hidden_lists', array() );
if ( ! in_array( 'setup', $hidden_list ) ) {
if ( ! in_array( 'setup', $hidden_list, true ) ) {
$woocommerce_list = array_merge(
get_option( 'woocommerce_task_list_hidden_lists', array() ),
array(
'setup',
)
);
// $woocommerce_list = array("setup");
update_option( 'woocommerce_task_list_hidden_lists', $woocommerce_list );
}
}

/**
* Update the heading and checkbox text
*/
public function update_text( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Billing details':
$translated_text = __( 'Shipping details', 'wp-module-ecommerce' );
break;
case 'Ship to a different address?':
$translated_text = __( 'Bill to a different address?', 'wp-module-ecommerce' );
break;
}
return $translated_text;
}

/**
* Add promotion (Promote) under WooCommerce Marketing tab
*/
function custom_add_promotion_menu_item( $menu_items ) {
public function custom_add_promotion_menu_item() {
add_submenu_page(
'woocommerce-marketing',
'Promotion product Page',
Expand All @@ -420,21 +429,23 @@ function custom_add_promotion_menu_item( $menu_items ) {
/**
* Add a Promotion button under Add New product tab
*/
function custom_product_general_options() {
public function custom_product_general_options() {
global $post;
$redirect_url = admin_url( 'admin.php?page=' . $this->container->plugin()->id . '#/store/sales_discounts' );
wp_enqueue_style( 'Create_a_Promotion', NFD_ECOMMERCE_PLUGIN_URL . 'vendor/newfold-labs/wp-module-ecommerce/includes/Promotions.css', array(), '1.0', 'all' );
echo '<div class="options_group">
<p class="form-field custom-button-field">
<a id="Create_a_Promotion" href="' . $redirect_url . '" class="promotion">' . __( 'Create a Promotion', 'wp-module-ecommerce' ) . '</a>
<a id="Create_a_Promotion" href="' . esc_url( $redirect_url ) . '" class="promotion">' . __( 'Create a Promotion', 'wp-module-ecommerce' ) . '</a>
</p>
</div>';
}

/**
* Add a Custom tab (Prmotions tab) button added below Advance tab
*
* @param array $tabs The tabs.
*/
function custom_product_write_panel_tabs( $tabs ) {
public function custom_product_write_panel_tabs( $tabs ) {
$tabs['custom_tab'] = array(
'label' => __( 'Promotions', 'wp-module-ecommerce' ),
'target' => 'promotion_product_data',
Expand All @@ -447,7 +458,7 @@ function custom_product_write_panel_tabs( $tabs ) {
/**
* Content on click of a Custom tab (Promotions tab) button added below Advance tab
*/
function promotion_product_data() {
public function promotion_product_data() {
$redirect_url = 'admin.php?page=' . $this->container->plugin()->id . '#/store/sales_discounts';
global $post;
echo '<div id="promotion_product_data" class="panel woocommerce_options_panel hidden"></div>';
Expand All @@ -472,16 +483,19 @@ function promotion_product_data() {
}

/**
* change icon for a Custom tab (Promotions tab) button added below Advance tab
* Change icon for a Custom tab (Promotions tab) button added below Advance tab
*/
function action_admin_head() {
public function action_admin_head() {
echo '<style>
#woocommerce-product-data ul.wc-tabs li.custom_tab_options a::before {
content: "\f323";
}
</style>';
}

/**
* Change the order of payment gateways
*/
public function custom_payment_gateways_order() {
$array_data = array(
'pre_install_woocommerce_payments_promotion' => 2,
Expand All @@ -491,13 +505,19 @@ public function custom_payment_gateways_order() {
update_option( 'woocommerce_gateway_order', $array_data );
}

/**
* Dismisses the WooCommerce Payments CTA
*/
public function dismiss_woo_payments_cta() {
$is_dismissed = get_option( 'wcpay_welcome_page_incentives_dismissed' );
if ( ! is_array( $is_dismissed ) || empty( $is_dismissed ) ) {
update_option( 'wcpay_welcome_page_incentives_dismissed', array( 'wcpay-promo-2023-action-discount' ) );
}
}

/**
* Disables the creative mail banner
*/
public function disable_creative_mail_banner() {
$is_dismissed = get_option( 'ce4wp_ignore_review_notice' );
if ( ! is_array( $is_dismissed ) || empty( $is_dismissed ) ) {
Expand All @@ -509,7 +529,6 @@ public function disable_creative_mail_banner() {
* Activates yith payment plugins (Paypal, Stripe) when woocommerce is activated
*
* @param string $plugin Path to the plugin file relative
* @param bool $network_activation enable the plugin for all sites
*
* @return void
*/
Expand Down

0 comments on commit c79cad7

Please sign in to comment.