PluginProbe
Tiered Pricing Table for WooCommerce / 8.0.2
Tiered Pricing Table for WooCommerce v8.0.2
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
tier-pricing-table / src / Addons / GlobalTieredPricing / CPT / Actions / ReactivateAction.php

ReactivateAction.php in Tiered Pricing Table for WooCommerce 8.0.2, at src/Addons/GlobalTieredPricing/CPT/Actions/ReactivateAction.php

72 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\GlobalTieredPricing\CPT\Actions;
2
3 use TierPricingTable\Addons\GlobalTieredPricing\CPT\GlobalTieredPricingCPT;
4 use TierPricingTable\Core\AdminNotifier;
5 use TierPricingTable\Core\ServiceContainerTrait;
6 use TierPricingTable\Addons\GlobalTieredPricing\GlobalPricingRule;
7 use WP_Post;
8
9 class ReactivateAction {
10
11 const ACTION = 'tpt_reactivate_global_rule';
12
13 use ServiceContainerTrait;
14
15 public function __construct() {
16
17 add_action( 'admin_post_' . self::ACTION, array( $this, 'handle' ) );
18
19 add_filter( 'post_row_actions', function ( $actions, WP_Post $post ) {
20
21 if ( GlobalTieredPricingCPT::SLUG !== $post->post_type ) {
22 return $actions;
23 }
24
25 $rule = GlobalPricingRule::build( $post->ID );
26
27 if ( $rule->isSuspended() ) {
28 $actions['reactivate'] = sprintf( '<a href="%s">%s</a>', $this->getRunLink( $post->ID ), $this->getName() );
29 }
30
31 return $actions;
32 }, 10, 2 );
33 }
34
35 public function getName(): string {
36 return __( 'Reactivate', 'tier-pricing-table' );
37 }
38
39 public function handle(): bool {
40 $nonce = isset( $_GET['_wpnonce'] ) ? sanitize_text_field( $_GET['_wpnonce'] ) : false;
41
42 if ( wp_verify_nonce( $nonce, self::ACTION ) ) {
43 $ruleId = isset( $_GET['rule_id'] ) ? intval( $_GET['rule_id'] ) : false;
44
45 if ( $ruleId ) {
46 $rule = GlobalPricingRule::build( $ruleId );
47
48 if ( false !== get_post_status( $ruleId ) ) {
49
50 $rule->reactivate();
51 $rule->save();
52
53 $this->getContainer()->getAdminNotifier()->flash( __( 'The rule reactivated successfully.', 'tier-pricing-table
54 ' ), AdminNotifier::SUCCESS, true );
55 }
56 }
57
58 } else {
59 wp_die( 'You\'re not allowed to run this action' );
60 }
61
62 return wp_safe_redirect( wp_get_referer() );
63 }
64
65 public function getRunLink( $id ): string {
66 return add_query_arg( array(
67 'rule_id' => $id,
68 'action' => self::ACTION,
69 ), wp_nonce_url( admin_url( 'admin-post.php' ), self::ACTION ) );
70 }
71 }
72