Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
manzurahammed committed Apr 30, 2024
1 parent a2324fe commit f56b72b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ function ( $product ) {
);

if ( WC_Helper::is_site_connected() ) {
$settings[ 'wccomHelper' ][ 'subscription_expired_notice' ] = PluginsHelper::get_expired_subscription_notice( false );
$settings[ 'wccomHelper' ][ 'subscription_expiring_notice' ] = PluginsHelper::get_expiring_subscription_notice( false );
$settings['wccomHelper']['subscription_expired_notice'] = PluginsHelper::get_expired_subscription_notice( false );
$settings['wccomHelper']['subscription_expiring_notice'] = PluginsHelper::get_expiring_subscription_notice( false );
}

return $settings;
Expand Down
55 changes: 24 additions & 31 deletions plugins/woocommerce/src/Admin/PluginsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ class PluginsHelper {
/**
* The URL for the WooCommerce subscription page.
*/
const WOO_SUBSCRIPTION_PAGE_URL = 'https://woocommerce.com/my-account/my-subscriptions/';
const WOO_SUBSCRIPTION_PAGE_URL = 'https://woocommerce.com/my-account/my-subscriptions/';

/**
* Meta key for dismissing expired subscription notices.
*/
const DISMISS_EXPIRED_SUBS_NOTICE = 'woo_subscription_expired_notice_dismiss';
const DISMISS_EXPIRED_SUBS_NOTICE = 'woo_subscription_expired_notice_dismiss';

/**
* Meta key for dismissing expiring subscription notices
Expand Down Expand Up @@ -627,7 +627,7 @@ public static function maybe_enqueue_scripts_for_connect_notice() {
}

/**
* Show notice about to expired subscription on WC settings page
* Show notice about to expired subscription on WC settings page.
*
* @return void
*/
Expand All @@ -651,7 +651,7 @@ public static function maybe_show_expired_subscriptions_notice() {
}

/**
* Show notice about to expiring subscription on WC settings page
* Show notice about to expiring subscription on WC settings page.
*
* @return void
*/
Expand Down Expand Up @@ -705,7 +705,7 @@ function ( $sub ) use ( $product_id ) {
);

$message_key = sprintf( '%s_manage', $has_multiple_subs_for_product ? 'multiple' : 'single' );
$price = $subscription[ 'product_price' ] ?? '';
$price = $subscription['product_price'] ?? '';
$expiry_date = date_i18n( 'F jS', $subscription['expires'] );

if ( isset( $messages[ $message_key ] ) ) {
Expand All @@ -729,16 +729,16 @@ function ( $sub ) use ( $product_id ) {
*/
public static function get_expiring_subscription_notice( $allowed_link = true ) {
if ( ! WC_Helper::is_site_connected() ) {
return [];
return array();
}

if ( !self::$can_show_expiring_subs_notice ) {
return [];
return array();
}

$is_notice_dismiss = get_user_meta( get_current_user_id(), self::DISMISS_EXPIRING_SUBS_NOTICE, true );
if ( !empty( $is_notice_dismiss ) ) {
return [];
if ( ! empty( $is_notice_dismiss ) ) {
return array();
}

$subscriptions = WC_Helper::get_subscriptions();
Expand All @@ -750,7 +750,7 @@ function ( $sub ) {
);

if ( ! $expiring_subscriptions ) {
return [];
return array();
}

$total_expiring_subscriptions = count( $expiring_subscriptions );
Expand All @@ -769,27 +769,27 @@ function ( $sub ) {
]
);

return [
return array(
'description' => $allowed_link ? $message : preg_replace( '#<a.*?>(.*?)</a>#i', '\1', $message ),
'button_text' => __( 'Enable auto-renewal', 'woocommerce' ),
'button_link' => self::WOO_SUBSCRIPTION_PAGE_URL
];
);
}

/**
* Get formatted notice information for expired subscription.
*
* @param boolean $allowed_link whether the notice description should include a link
* @return array notice information
* @param boolean $allowed_link whether the notice description should include a link.
* @return array notice information.
*/
public static function get_expired_subscription_notice( $allowed_link = true ) {
if ( ! WC_Helper::is_site_connected() ) {
return [];
return array();
}

$is_notice_dismiss = get_user_meta( get_current_user_id(), self::DISMISS_EXPIRED_SUBS_NOTICE, true );
if ( !empty( $is_notice_dismiss ) ) {
return [];
return array();
}

$subscriptions = WC_Helper::get_subscriptions();
Expand All @@ -801,7 +801,7 @@ function ( $sub ) {
);

if ( !$expired_subscriptions ) {
return [];
return array();
}

$total_expired_subscriptions = count( $expired_subscriptions );
Expand All @@ -821,11 +821,11 @@ function ( $sub ) {
],
);

return [
return array(
'description' => $allowed_link ? $message : preg_replace( '#<a.*?>(.*?)</a>#i', '\1', $message ),
'button_text' => __( 'Renew', 'woocommerce' ),
'button_link' => self::WOO_SUBSCRIPTION_PAGE_URL
];
);
}

/**
Expand Down Expand Up @@ -853,7 +853,7 @@ public static function woo_subscriptions_notice_dismiss_api() {
array(
'methods' => 'POST',
'callback' => array( static::class, 'dismiss_woo_subscription_notice' ),
'permission_callback' => array( static::class, 'user_permissions_check' ),
'permission_callback' => array( static::class, 'get_permission' ),
),
)
);
Expand Down Expand Up @@ -884,18 +884,11 @@ public static function dismiss_woo_subscription_notice( $request ) {
}

/**
* Check user has the necessary permissions to perform this action
* Check user has the necessary permissions to perform this action.
*
* @return bool|\WP_Error
* @return bool
*/
public static function user_permissions_check() {
if ( !current_user_can( 'manage_woocommerce' ) ) {
return new \WP_Error(
'invalid_permission_to_disimiss_button',
esc_html__( 'you are not allowed to perform this action', 'woocommerce' ),
array( 'status' => rest_authorization_required_code() )
);
}
return true;
public static function get_permission(): bool {
return current_user_can('manage_woocommerce');
}
}

0 comments on commit f56b72b

Please sign in to comment.