Completed
Branch master (24c3eb)
by
unknown
34:49 queued 28:57
created
core/services/admin/AdminListTableFilters.php 2 patches
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -12,74 +12,74 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class AdminListTableFilters
14 14
 {
15
-    /**
16
-     * @var RequestInterface
17
-     */
18
-    protected RequestInterface $request;
19
-
20
-    protected string $search_term;
21
-
22
-    protected ?string $orderby;
23
-
24
-    protected ?string $order;
25
-
26
-    protected ?string $detached;
27
-
28
-    protected ?string $post_mime_type;
29
-
30
-
31
-    public function __construct(RequestInterface $request)
32
-    {
33
-        $this->request = $request;
34
-        // add_action('admin_enqueue_scripts', [$this, 'loadScriptsStyles']);
35
-    }
36
-
37
-
38
-    public function loadScriptsStyles()
39
-    {
40
-        wp_enqueue_script(EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN);
41
-    }
42
-
43
-
44
-    /**
45
-     * Sets the parameters from request
46
-     *
47
-     * @return void
48
-     */
49
-    private function setRequestParams(): void
50
-    {
51
-        $this->search_term    = $this->request->getRequestParam('s', '');
52
-        $this->orderby        = $this->request->getRequestParam('orderby');
53
-        $this->order          = $this->request->getRequestParam('order');
54
-        $this->post_mime_type = $this->request->getRequestParam('post_mime_type');
55
-        $this->detached       = $this->request->getRequestParam('detached');
56
-    }
57
-
58
-
59
-    /**
60
-     * Displays the search box with reset button
61
-     *
62
-     * @param string $text     The 'submit' button label.
63
-     * @param string $input_id ID attribute value for the search input field.
64
-     * @param string $url      Reset URL
65
-     * @return void
66
-     */
67
-    public function searchBox(string $text, string $input_id, string $url): void
68
-    {
69
-        $this->setRequestParams();
70
-        if (! empty($this->orderby)) {
71
-            echo '<input type="hidden" name="orderby" value="' . esc_attr($this->orderby) . '" />';
72
-        }
73
-        if (! empty($this->order)) {
74
-            echo '<input type="hidden" name="order" value="' . esc_attr($this->order) . '" />';
75
-        }
76
-        if (! empty($this->post_mime_type)) {
77
-            echo '<input type="hidden" name="post_mime_type" value="' . esc_attr($this->post_mime_type) . '" />';
78
-        }
79
-        if (! empty($this->detached)) {
80
-            echo '<input type="hidden" name="detached" value="' . esc_attr($this->detached) . '" />';
81
-        }
82
-        ?>
15
+	/**
16
+	 * @var RequestInterface
17
+	 */
18
+	protected RequestInterface $request;
19
+
20
+	protected string $search_term;
21
+
22
+	protected ?string $orderby;
23
+
24
+	protected ?string $order;
25
+
26
+	protected ?string $detached;
27
+
28
+	protected ?string $post_mime_type;
29
+
30
+
31
+	public function __construct(RequestInterface $request)
32
+	{
33
+		$this->request = $request;
34
+		// add_action('admin_enqueue_scripts', [$this, 'loadScriptsStyles']);
35
+	}
36
+
37
+
38
+	public function loadScriptsStyles()
39
+	{
40
+		wp_enqueue_script(EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN);
41
+	}
42
+
43
+
44
+	/**
45
+	 * Sets the parameters from request
46
+	 *
47
+	 * @return void
48
+	 */
49
+	private function setRequestParams(): void
50
+	{
51
+		$this->search_term    = $this->request->getRequestParam('s', '');
52
+		$this->orderby        = $this->request->getRequestParam('orderby');
53
+		$this->order          = $this->request->getRequestParam('order');
54
+		$this->post_mime_type = $this->request->getRequestParam('post_mime_type');
55
+		$this->detached       = $this->request->getRequestParam('detached');
56
+	}
57
+
58
+
59
+	/**
60
+	 * Displays the search box with reset button
61
+	 *
62
+	 * @param string $text     The 'submit' button label.
63
+	 * @param string $input_id ID attribute value for the search input field.
64
+	 * @param string $url      Reset URL
65
+	 * @return void
66
+	 */
67
+	public function searchBox(string $text, string $input_id, string $url): void
68
+	{
69
+		$this->setRequestParams();
70
+		if (! empty($this->orderby)) {
71
+			echo '<input type="hidden" name="orderby" value="' . esc_attr($this->orderby) . '" />';
72
+		}
73
+		if (! empty($this->order)) {
74
+			echo '<input type="hidden" name="order" value="' . esc_attr($this->order) . '" />';
75
+		}
76
+		if (! empty($this->post_mime_type)) {
77
+			echo '<input type="hidden" name="post_mime_type" value="' . esc_attr($this->post_mime_type) . '" />';
78
+		}
79
+		if (! empty($this->detached)) {
80
+			echo '<input type="hidden" name="detached" value="' . esc_attr($this->detached) . '" />';
81
+		}
82
+		?>
83 83
         <p class="search-box">
84 84
             <label class="screen-reader-text" for="<?php echo esc_attr($input_id); ?>"><?php echo $text; ?>:</label>
85 85
             <input type="search"
@@ -94,36 +94,36 @@  discard block
 block discarded – undo
94 94
             </button>
95 95
             <?php // submit_button($text, '', '', false, ['id' => 'search-submit']); ?>
96 96
             <?php
97
-            if (! empty($this->search_term)) {
98
-                echo wp_kses($this->generateResetButton($url), AllowedTags::getAllowedTags());
99
-            }
100
-            ?>
97
+			if (! empty($this->search_term)) {
98
+				echo wp_kses($this->generateResetButton($url), AllowedTags::getAllowedTags());
99
+			}
100
+			?>
101 101
         </p>
102 102
         <?php
103
-    }
104
-
105
-
106
-    /**
107
-     * filters
108
-     * This receives the filters array from children _get_table_filters() and assembles the string including the filter
109
-     * button.
110
-     *
111
-     * @param string[] $filters
112
-     * @param string   $url Reset URL
113
-     * @return void  echos html showing filters
114
-     */
115
-    public function filters(array $filters, string $url): void
116
-    {
117
-        $use_filters = $this->request->getRequestParam('use_filters', false, DataType::BOOL);
118
-        $use_filters = $use_filters ? 'yes' : 'no';
119
-
120
-        $filters_html = '';
121
-        foreach ($filters as $filter) {
122
-            $filters_html .= wp_kses($filter, AllowedTags::getWithFormTags());
123
-        }
124
-        $filter_submit_btn_text = esc_html__('Filter', 'event_espresso');
125
-
126
-        echo "
103
+	}
104
+
105
+
106
+	/**
107
+	 * filters
108
+	 * This receives the filters array from children _get_table_filters() and assembles the string including the filter
109
+	 * button.
110
+	 *
111
+	 * @param string[] $filters
112
+	 * @param string   $url Reset URL
113
+	 * @return void  echos html showing filters
114
+	 */
115
+	public function filters(array $filters, string $url): void
116
+	{
117
+		$use_filters = $this->request->getRequestParam('use_filters', false, DataType::BOOL);
118
+		$use_filters = $use_filters ? 'yes' : 'no';
119
+
120
+		$filters_html = '';
121
+		foreach ($filters as $filter) {
122
+			$filters_html .= wp_kses($filter, AllowedTags::getWithFormTags());
123
+		}
124
+		$filter_submit_btn_text = esc_html__('Filter', 'event_espresso');
125
+
126
+		echo "
127 127
         <div id='ee-list-table-filters-dv' class='ee-list-table-filters actions alignleft'>
128 128
            $filters_html
129 129
             <span class='ee-list-table-filters__submit-buttons'>
@@ -146,20 +146,20 @@  discard block
 block discarded – undo
146 146
             <span class='ee-list-table-filters-toggle-text'>" . esc_html__('show filters', 'event_espresso') . "</span>
147 147
         </button>
148 148
         ";
149
-    }
149
+	}
150 150
 
151 151
 
152
-    /**
153
-     * @param string $url Reset URL
154
-     * @return string
155
-     */
156
-    private function generateResetButton(string $url): string
157
-    {
158
-        return '<a class="ee-aria-tooltip button button--icon-only"
152
+	/**
153
+	 * @param string $url Reset URL
154
+	 * @return string
155
+	 */
156
+	private function generateResetButton(string $url): string
157
+	{
158
+		return '<a class="ee-aria-tooltip button button--icon-only"
159 159
             href="' . esc_url_raw($url) . '"
160 160
             aria-label="' . esc_attr__('Reset Filters', 'event_espresso') . '"
161 161
         >
162 162
             <span class="dashicons dashicons-update"></span>
163 163
         </a>';
164
-    }
164
+	}
165 165
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -67,17 +67,17 @@  discard block
 block discarded – undo
67 67
     public function searchBox(string $text, string $input_id, string $url): void
68 68
     {
69 69
         $this->setRequestParams();
70
-        if (! empty($this->orderby)) {
71
-            echo '<input type="hidden" name="orderby" value="' . esc_attr($this->orderby) . '" />';
70
+        if ( ! empty($this->orderby)) {
71
+            echo '<input type="hidden" name="orderby" value="'.esc_attr($this->orderby).'" />';
72 72
         }
73
-        if (! empty($this->order)) {
74
-            echo '<input type="hidden" name="order" value="' . esc_attr($this->order) . '" />';
73
+        if ( ! empty($this->order)) {
74
+            echo '<input type="hidden" name="order" value="'.esc_attr($this->order).'" />';
75 75
         }
76
-        if (! empty($this->post_mime_type)) {
77
-            echo '<input type="hidden" name="post_mime_type" value="' . esc_attr($this->post_mime_type) . '" />';
76
+        if ( ! empty($this->post_mime_type)) {
77
+            echo '<input type="hidden" name="post_mime_type" value="'.esc_attr($this->post_mime_type).'" />';
78 78
         }
79
-        if (! empty($this->detached)) {
80
-            echo '<input type="hidden" name="detached" value="' . esc_attr($this->detached) . '" />';
79
+        if ( ! empty($this->detached)) {
80
+            echo '<input type="hidden" name="detached" value="'.esc_attr($this->detached).'" />';
81 81
         }
82 82
         ?>
83 83
         <p class="search-box">
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
             </button>
95 95
             <?php // submit_button($text, '', '', false, ['id' => 'search-submit']); ?>
96 96
             <?php
97
-            if (! empty($this->search_term)) {
97
+            if ( ! empty($this->search_term)) {
98 98
                 echo wp_kses($this->generateResetButton($url), AllowedTags::getAllowedTags());
99 99
             }
100 100
             ?>
@@ -133,17 +133,17 @@  discard block
 block discarded – undo
133 133
                        value='$filter_submit_btn_text'
134 134
                 />
135 135
                 <input type='hidden' id='ee-list-table-use-filters' name='use_filters' value='$use_filters' />
136
-                " . wp_kses($this->generateResetButton($url), AllowedTags::getAllowedTags()) . "
136
+                ".wp_kses($this->generateResetButton($url), AllowedTags::getAllowedTags())."
137 137
             </span>
138 138
         </div>
139 139
         <button id='ee-list-table-filters-toggle'
140 140
             class='button button--secondary button--small'
141 141
             data-target='ee-list-table-filters'
142
-            data-hide-text='" . esc_html__('hide filters', 'event_espresso') . "'
143
-            data-show-text='" . esc_html__('show filters', 'event_espresso') . "'
142
+            data-hide-text='" . esc_html__('hide filters', 'event_espresso')."'
143
+            data-show-text='" . esc_html__('show filters', 'event_espresso')."'
144 144
         >
145 145
             <span class='dashicons dashicons-filter'></span>
146
-            <span class='ee-list-table-filters-toggle-text'>" . esc_html__('show filters', 'event_espresso') . "</span>
146
+            <span class='ee-list-table-filters-toggle-text'>" . esc_html__('show filters', 'event_espresso')."</span>
147 147
         </button>
148 148
         ";
149 149
     }
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
     private function generateResetButton(string $url): string
157 157
     {
158 158
         return '<a class="ee-aria-tooltip button button--icon-only"
159
-            href="' . esc_url_raw($url) . '"
160
-            aria-label="' . esc_attr__('Reset Filters', 'event_espresso') . '"
159
+            href="' . esc_url_raw($url).'"
160
+            aria-label="' . esc_attr__('Reset Filters', 'event_espresso').'"
161 161
         >
162 162
             <span class="dashicons dashicons-update"></span>
163 163
         </a>';
Please login to merge, or discard this patch.
core/services/licensing/AddonLicense.php 1 patch
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -17,102 +17,102 @@
 block discarded – undo
17 17
  */
18 18
 class AddonLicense
19 19
 {
20
-    /**
21
-     * add-on names indexed by plugin slug.
22
-     * Duplicates are because the plugin slugs used in the license data
23
-     * sometimes differ from those used in the register add-on API
24
-     *
25
-     * @var array|string[]
26
-     */
27
-    private static array $addon_names = [
28
-        // Add-ons
29
-        'eea-affiliate-wp'                          => 'AffiliateWP Integration',
30
-        'eea-attendee-mover'                        => 'Attendee Mover',
31
-        'eea-automated-upcoming-event-notification' => 'Automatic Event Notifications',
32
-        'espresso-barcode-scanner'                  => 'Barcode Scanner',
33
-        'espresso_calendar'                         => 'Calendar',
34
-        'eea-event-app-customization'               => 'Event Mobile App Customization',
35
-        'espresso-grid-template'                    => 'Events List Grid Template',
36
-        'espresso-events-table-template'            => 'Events List Table Template',
37
-        'eea-importer'                              => 'Importer',
38
-        'espresso_importer'                         => 'Importer',
39
-        'espresso-infusionsoft'                     => 'Keap Integration',
40
-        'ee4-mailchimp'                             => 'MailChimp Integration',
41
-        'eea-multi-event-registration'              => 'Event Cart',
42
-        'eea-people-addon'                          => 'People Manager',
43
-        'eea-promotions'                            => 'Promotion and Discount Codes',
44
-        'eea-recurring-events-manager'              => 'Recurring Events',
45
-        'eea-events-social-sharing'                 => 'Social Sharing',
46
-        'eea-ticketing'                             => 'Scannable Tickets',
47
-        'eea-utf8-variation'                        => 'Font Pack for DOMPDF',
48
-        'eea-wait-lists'                            => 'Wait List Manager',
49
-        'eea-wpuser-integration'                    => 'WordPress User Integration',
50
-        'eea-payment-methods-pro'                   => 'Payment Methods Manager',
51
-        // Payment Methods
52
-        'eea-authnet-accept'                        => 'Authorize.net Accept Integration',
53
-        'eea-aim-echeck'                            => 'Authorize.net eCheck Integration',
54
-        'eea-braintree-gateway'                     => 'Braintree Integration',
55
-        'eea-chase-orbital'                         => 'Chase Paymentech Orbital Integration',
56
-        'eea-cybersource-gateway'                   => 'CyberSource Integration',
57
-        'eea-payeezy'                               => 'First Data Payeezy Integration',
58
-        'eea-flexible-payment-method'               => 'Flexible Payment Method',
59
-        'eea-ipay88-gateway'                        => 'iPay88 Integration',
60
-        'eea-migs-payment-method'                   => 'Mastercard Gateway Integration',
61
-        'eea-ideal-mollie-gateway'                  => 'Mollie Integration',
62
-        'eea-payflow-pro-gateway'                   => 'Payflow Pro Integration',
63
-        'eea-paypal-smart-buttons'                  => 'PayPal Smart Buttons Integration',
64
-        'eea-quickbooks-gateway'                    => 'QuickBooks Payment Gateway Integration',
65
-        'eea-sage-pay-gateway'                      => 'Opayo Integration',
66
-        'eea-square-gateway'                        => 'Square Integration',
67
-        'eea-stripe-gateway'                        => 'Stripe Integration',
68
-        'espresso-transfirst'                       => 'TSYS TransFirst Integration',
69
-        'eea-vanco-payment-method'                  => 'Vanco Integration',
70
-    ];
20
+	/**
21
+	 * add-on names indexed by plugin slug.
22
+	 * Duplicates are because the plugin slugs used in the license data
23
+	 * sometimes differ from those used in the register add-on API
24
+	 *
25
+	 * @var array|string[]
26
+	 */
27
+	private static array $addon_names = [
28
+		// Add-ons
29
+		'eea-affiliate-wp'                          => 'AffiliateWP Integration',
30
+		'eea-attendee-mover'                        => 'Attendee Mover',
31
+		'eea-automated-upcoming-event-notification' => 'Automatic Event Notifications',
32
+		'espresso-barcode-scanner'                  => 'Barcode Scanner',
33
+		'espresso_calendar'                         => 'Calendar',
34
+		'eea-event-app-customization'               => 'Event Mobile App Customization',
35
+		'espresso-grid-template'                    => 'Events List Grid Template',
36
+		'espresso-events-table-template'            => 'Events List Table Template',
37
+		'eea-importer'                              => 'Importer',
38
+		'espresso_importer'                         => 'Importer',
39
+		'espresso-infusionsoft'                     => 'Keap Integration',
40
+		'ee4-mailchimp'                             => 'MailChimp Integration',
41
+		'eea-multi-event-registration'              => 'Event Cart',
42
+		'eea-people-addon'                          => 'People Manager',
43
+		'eea-promotions'                            => 'Promotion and Discount Codes',
44
+		'eea-recurring-events-manager'              => 'Recurring Events',
45
+		'eea-events-social-sharing'                 => 'Social Sharing',
46
+		'eea-ticketing'                             => 'Scannable Tickets',
47
+		'eea-utf8-variation'                        => 'Font Pack for DOMPDF',
48
+		'eea-wait-lists'                            => 'Wait List Manager',
49
+		'eea-wpuser-integration'                    => 'WordPress User Integration',
50
+		'eea-payment-methods-pro'                   => 'Payment Methods Manager',
51
+		// Payment Methods
52
+		'eea-authnet-accept'                        => 'Authorize.net Accept Integration',
53
+		'eea-aim-echeck'                            => 'Authorize.net eCheck Integration',
54
+		'eea-braintree-gateway'                     => 'Braintree Integration',
55
+		'eea-chase-orbital'                         => 'Chase Paymentech Orbital Integration',
56
+		'eea-cybersource-gateway'                   => 'CyberSource Integration',
57
+		'eea-payeezy'                               => 'First Data Payeezy Integration',
58
+		'eea-flexible-payment-method'               => 'Flexible Payment Method',
59
+		'eea-ipay88-gateway'                        => 'iPay88 Integration',
60
+		'eea-migs-payment-method'                   => 'Mastercard Gateway Integration',
61
+		'eea-ideal-mollie-gateway'                  => 'Mollie Integration',
62
+		'eea-payflow-pro-gateway'                   => 'Payflow Pro Integration',
63
+		'eea-paypal-smart-buttons'                  => 'PayPal Smart Buttons Integration',
64
+		'eea-quickbooks-gateway'                    => 'QuickBooks Payment Gateway Integration',
65
+		'eea-sage-pay-gateway'                      => 'Opayo Integration',
66
+		'eea-square-gateway'                        => 'Square Integration',
67
+		'eea-stripe-gateway'                        => 'Stripe Integration',
68
+		'espresso-transfirst'                       => 'TSYS TransFirst Integration',
69
+		'eea-vanco-payment-method'                  => 'Vanco Integration',
70
+	];
71 71
 
72 72
 
73
-    public static function register(string $addon_name, array $license_data)
74
-    {
75
-        if (! $addon_name || ! $license_data) {
76
-            return;
77
-        }
78
-        // also bail if the feature flag is not enabled
79
-        $feature = LoaderFactory::getShared(FeatureFlags::class);
80
-        if (! $feature->allowed('use_edd_plugin_licensing')) {
81
-            return;
82
-        }
83
-        // Get the plugin name.
84
-        $plugin_name = $license_data['plugin_name'] ?? AddonLicense::derivePluginNameFromMainFile($license_data);
85
-        // Bail if we still don't have a plugin name.
86
-        if (empty($plugin_name)) {
87
-            return;
88
-        }
89
-        // ensure defaults are set
90
-        $license_data += [
91
-            'beta'             => false,
92
-            'main_file_path'   => $license_data['main_file_path'] ?? '',
93
-            'min_core_version' => $license_data['min_core_version'] ?? '',
94
-            'plugin_id'        => $license_data['plugin_id'] ?? 0,
95
-            'plugin_name'      => $plugin_name,
96
-            'plugin_slug'      => $license_data['plugin_slug'] ?? '',
97
-            'version'          => $license_data['version'],
98
-            'wp_override'      => false,
99
-        ];
73
+	public static function register(string $addon_name, array $license_data)
74
+	{
75
+		if (! $addon_name || ! $license_data) {
76
+			return;
77
+		}
78
+		// also bail if the feature flag is not enabled
79
+		$feature = LoaderFactory::getShared(FeatureFlags::class);
80
+		if (! $feature->allowed('use_edd_plugin_licensing')) {
81
+			return;
82
+		}
83
+		// Get the plugin name.
84
+		$plugin_name = $license_data['plugin_name'] ?? AddonLicense::derivePluginNameFromMainFile($license_data);
85
+		// Bail if we still don't have a plugin name.
86
+		if (empty($plugin_name)) {
87
+			return;
88
+		}
89
+		// ensure defaults are set
90
+		$license_data += [
91
+			'beta'             => false,
92
+			'main_file_path'   => $license_data['main_file_path'] ?? '',
93
+			'min_core_version' => $license_data['min_core_version'] ?? '',
94
+			'plugin_id'        => $license_data['plugin_id'] ?? 0,
95
+			'plugin_name'      => $plugin_name,
96
+			'plugin_slug'      => $license_data['plugin_slug'] ?? '',
97
+			'version'          => $license_data['version'],
98
+			'wp_override'      => false,
99
+		];
100 100
 
101
-        new PluginLicense(
102
-            $license_data['main_file_path'] ?? '',
103
-            $license_data['plugin_id'] ?? 0,
104
-            $license_data['plugin_name'] ?? '',
105
-            $license_data['plugin_slug'] ?? '',
106
-            $license_data['version'] ?? '',
107
-            $license_data['beta'] ?? '',
108
-            $license_data['wp_override'] ?? '',
109
-            $license_data['min_core_version'] ?? ''
110
-        );
111
-    }
101
+		new PluginLicense(
102
+			$license_data['main_file_path'] ?? '',
103
+			$license_data['plugin_id'] ?? 0,
104
+			$license_data['plugin_name'] ?? '',
105
+			$license_data['plugin_slug'] ?? '',
106
+			$license_data['version'] ?? '',
107
+			$license_data['beta'] ?? '',
108
+			$license_data['wp_override'] ?? '',
109
+			$license_data['min_core_version'] ?? ''
110
+		);
111
+	}
112 112
 
113 113
 
114
-    private static function derivePluginNameFromMainFile(array $license_data): string
115
-    {
116
-        return AddonLicense::$addon_names[ wp_basename($license_data['main_file_path'], '.php') ] ?? '';
117
-    }
114
+	private static function derivePluginNameFromMainFile(array $license_data): string
115
+	{
116
+		return AddonLicense::$addon_names[ wp_basename($license_data['main_file_path'], '.php') ] ?? '';
117
+	}
118 118
 }
Please login to merge, or discard this patch.
core/services/licensing/SamplePlugin.php 2 patches
Indentation   +296 added lines, -296 removed lines patch added patch discarded remove patch
@@ -28,8 +28,8 @@  discard block
 block discarded – undo
28 28
 define('EDD_SAMPLE_PLUGIN_LICENSE_PAGE', 'pluginname-license');
29 29
 
30 30
 if (! class_exists('EDD_SL_Plugin_Updater')) {
31
-    // load our custom updater
32
-    include dirname(__FILE__) . '/EDD_SL_Plugin_Updater.php';
31
+	// load our custom updater
32
+	include dirname(__FILE__) . '/EDD_SL_Plugin_Updater.php';
33 33
 }
34 34
 
35 35
 /**
@@ -39,27 +39,27 @@  discard block
 block discarded – undo
39 39
 function edd_sl_sample_plugin_updater()
40 40
 {
41 41
 
42
-    // To support auto-updates, this needs to run during the wp_version_check cron job for privileged users.
43
-    $doing_cron = defined('DOING_CRON') && DOING_CRON;
44
-    if (! current_user_can('manage_options') && ! $doing_cron) {
45
-        return;
46
-    }
47
-
48
-    // retrieve our license key from the DB
49
-    $license_key = trim(get_option('edd_sample_license_key'));
50
-
51
-    // setup the updater
52
-    $edd_updater = new EDD_SL_Plugin_Updater(
53
-        EDD_SAMPLE_STORE_URL,
54
-        __FILE__,
55
-        array(
56
-            'version' => '1.0',                    // current version number
57
-            'license' => $license_key,             // license key (used get_option above to retrieve from DB)
58
-            'item_id' => EDD_SAMPLE_ITEM_ID,       // ID of the product
59
-            'author'  => 'Easy Digital Downloads', // author of this plugin
60
-            'beta'    => false,
61
-        )
62
-    );
42
+	// To support auto-updates, this needs to run during the wp_version_check cron job for privileged users.
43
+	$doing_cron = defined('DOING_CRON') && DOING_CRON;
44
+	if (! current_user_can('manage_options') && ! $doing_cron) {
45
+		return;
46
+	}
47
+
48
+	// retrieve our license key from the DB
49
+	$license_key = trim(get_option('edd_sample_license_key'));
50
+
51
+	// setup the updater
52
+	$edd_updater = new EDD_SL_Plugin_Updater(
53
+		EDD_SAMPLE_STORE_URL,
54
+		__FILE__,
55
+		array(
56
+			'version' => '1.0',                    // current version number
57
+			'license' => $license_key,             // license key (used get_option above to retrieve from DB)
58
+			'item_id' => EDD_SAMPLE_ITEM_ID,       // ID of the product
59
+			'author'  => 'Easy Digital Downloads', // author of this plugin
60
+			'beta'    => false,
61
+		)
62
+	);
63 63
 }
64 64
 add_action('init', 'edd_sl_sample_plugin_updater');
65 65
 
@@ -77,41 +77,41 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function edd_sample_license_menu()
79 79
 {
80
-    add_plugins_page(
81
-        __('Plugin License'),
82
-        __('Plugin License'),
83
-        'manage_options',
84
-        EDD_SAMPLE_PLUGIN_LICENSE_PAGE,
85
-        'edd_sample_license_page'
86
-    );
80
+	add_plugins_page(
81
+		__('Plugin License'),
82
+		__('Plugin License'),
83
+		'manage_options',
84
+		EDD_SAMPLE_PLUGIN_LICENSE_PAGE,
85
+		'edd_sample_license_page'
86
+	);
87 87
 }
88 88
 add_action('admin_menu', 'edd_sample_license_menu');
89 89
 
90 90
 function edd_sample_license_page()
91 91
 {
92
-    add_settings_section(
93
-        'edd_sample_license',
94
-        __('Plugin License'),
95
-        'edd_sample_license_key_settings_section',
96
-        EDD_SAMPLE_PLUGIN_LICENSE_PAGE
97
-    );
98
-    add_settings_field(
99
-        'edd_sample_license_key',
100
-        '<label for="edd_sample_license_key">' . __('License Key') . '</label>',
101
-        'edd_sample_license_key_settings_field',
102
-        EDD_SAMPLE_PLUGIN_LICENSE_PAGE,
103
-        'edd_sample_license',
104
-    );
105
-    ?>
92
+	add_settings_section(
93
+		'edd_sample_license',
94
+		__('Plugin License'),
95
+		'edd_sample_license_key_settings_section',
96
+		EDD_SAMPLE_PLUGIN_LICENSE_PAGE
97
+	);
98
+	add_settings_field(
99
+		'edd_sample_license_key',
100
+		'<label for="edd_sample_license_key">' . __('License Key') . '</label>',
101
+		'edd_sample_license_key_settings_field',
102
+		EDD_SAMPLE_PLUGIN_LICENSE_PAGE,
103
+		'edd_sample_license',
104
+	);
105
+	?>
106 106
     <div class="wrap">
107 107
         <h2><?php esc_html_e('Plugin License Options'); ?></h2>
108 108
         <form method="post" action="options.php">
109 109
 
110 110
             <?php
111
-            do_settings_sections(EDD_SAMPLE_PLUGIN_LICENSE_PAGE);
112
-            settings_fields('edd_sample_license');
113
-            submit_button();
114
-            ?>
111
+			do_settings_sections(EDD_SAMPLE_PLUGIN_LICENSE_PAGE);
112
+			settings_fields('edd_sample_license');
113
+			submit_button();
114
+			?>
115 115
 
116 116
         </form>
117 117
     <?php
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
  */
125 125
 function edd_sample_license_key_settings_section()
126 126
 {
127
-    esc_html_e('This is where you enter your license key.');
127
+	esc_html_e('This is where you enter your license key.');
128 128
 }
129 129
 
130 130
 /**
@@ -134,28 +134,28 @@  discard block
 block discarded – undo
134 134
  */
135 135
 function edd_sample_license_key_settings_field()
136 136
 {
137
-    $license = get_option('edd_sample_license_key');
138
-    $status  = get_option('edd_sample_license_status');
137
+	$license = get_option('edd_sample_license_key');
138
+	$status  = get_option('edd_sample_license_status');
139 139
 
140
-    ?>
140
+	?>
141 141
     <p class="description"><?php esc_html_e('Enter your license key.'); ?></p>
142 142
     <?php
143
-    printf(
144
-        '<input type="text" class="regular-text" id="edd_sample_license_key" name="edd_sample_license_key" value="%s" />',
145
-        esc_attr($license)
146
-    );
147
-    $button = array(
148
-        'name'  => 'edd_license_deactivate',
149
-        'label' => __('Deactivate License'),
150
-    );
151
-    if ('valid' !== $status) {
152
-        $button = array(
153
-            'name'  => 'edd_license_activate',
154
-            'label' => __('Activate License'),
155
-        );
156
-    }
157
-    wp_nonce_field('edd_sample_nonce', 'edd_sample_nonce');
158
-    ?>
143
+	printf(
144
+		'<input type="text" class="regular-text" id="edd_sample_license_key" name="edd_sample_license_key" value="%s" />',
145
+		esc_attr($license)
146
+	);
147
+	$button = array(
148
+		'name'  => 'edd_license_deactivate',
149
+		'label' => __('Deactivate License'),
150
+	);
151
+	if ('valid' !== $status) {
152
+		$button = array(
153
+			'name'  => 'edd_license_activate',
154
+			'label' => __('Activate License'),
155
+		);
156
+	}
157
+	wp_nonce_field('edd_sample_nonce', 'edd_sample_nonce');
158
+	?>
159 159
     <input type="submit" class="button-secondary" name="<?php echo esc_attr($button['name']); ?>" value="<?php echo esc_attr($button['label']); ?>"/>
160 160
     <?php
161 161
 }
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
  */
168 168
 function edd_sample_register_option()
169 169
 {
170
-    register_setting('edd_sample_license', 'edd_sample_license_key', 'edd_sanitize_license');
170
+	register_setting('edd_sample_license', 'edd_sample_license_key', 'edd_sanitize_license');
171 171
 }
172 172
 add_action('admin_init', 'edd_sample_register_option');
173 173
 
@@ -179,12 +179,12 @@  discard block
 block discarded – undo
179 179
  */
180 180
 function edd_sanitize_license($new)
181 181
 {
182
-    $old = get_option('edd_sample_license_key');
183
-    if ($old && $old !== $new) {
184
-        delete_option('edd_sample_license_status'); // new license has been entered, so must reactivate
185
-    }
182
+	$old = get_option('edd_sample_license_key');
183
+	if ($old && $old !== $new) {
184
+		delete_option('edd_sample_license_status'); // new license has been entered, so must reactivate
185
+	}
186 186
 
187
-    return sanitize_text_field($new);
187
+	return sanitize_text_field($new);
188 188
 }
189 189
 
190 190
 /**
@@ -195,117 +195,117 @@  discard block
 block discarded – undo
195 195
 function edd_sample_activate_license()
196 196
 {
197 197
 
198
-    // listen for our activate button to be clicked
199
-    if (! isset($_POST['edd_license_activate'])) {
200
-        return;
201
-    }
202
-
203
-    // run a quick security check
204
-    if (! check_admin_referer('edd_sample_nonce', 'edd_sample_nonce')) {
205
-        return; // get out if we didn't click the Activate button
206
-    }
207
-
208
-    // retrieve the license from the database
209
-    $license = trim(get_option('edd_sample_license_key'));
210
-    if (! $license) {
211
-        $license = ! empty($_POST['edd_sample_license_key']) ? sanitize_text_field($_POST['edd_sample_license_key']) : '';
212
-    }
213
-    if (! $license) {
214
-        return;
215
-    }
216
-
217
-    // data to send in our API request
218
-    $api_params = array(
219
-        'edd_action'  => 'activate_license',
220
-        'license'     => $license,
221
-        'item_id'     => EDD_SAMPLE_ITEM_ID,
222
-        'item_name'   => rawurlencode(EDD_SAMPLE_ITEM_NAME), // the name of our product in EDD
223
-        'url'         => home_url(),
224
-        'environment' => function_exists('wp_get_environment_type') ? wp_get_environment_type() : 'production',
225
-    );
226
-
227
-    // Call the custom API.
228
-    $response = wp_remote_post(
229
-        EDD_SAMPLE_STORE_URL,
230
-        array(
231
-            'timeout'   => 15,
232
-            'sslverify' => false,
233
-            'body'      => $api_params,
234
-        )
235
-    );
236
-
237
-        // make sure the response came back okay
238
-    if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
239
-        if (is_wp_error($response)) {
240
-            $message = $response->get_error_message();
241
-        } else {
242
-            $message = __('An error occurred, please try again.');
243
-        }
244
-    } else {
245
-        $license_data = json_decode(wp_remote_retrieve_body($response));
246
-
247
-        if (false === $license_data->success) {
248
-            switch ($license_data->error) {
249
-                case 'expired':
250
-                    $message = sprintf(
251
-                        /* translators: the license key expiration date */
252
-                        __('Your license key expired on %s.', 'edd-sample-plugin'),
253
-                        date_i18n(get_option('date_format'), strtotime($license_data->expires, current_time('timestamp')))
254
-                    );
255
-                    break;
256
-
257
-                case 'disabled':
258
-                case 'revoked':
259
-                    $message = __('Your license key has been disabled.', 'edd-sample-plugin');
260
-                    break;
261
-
262
-                case 'missing':
263
-                    $message = __('Invalid license.', 'edd-sample-plugin');
264
-                    break;
265
-
266
-                case 'invalid':
267
-                case 'site_inactive':
268
-                    $message = __('Your license is not active for this URL.', 'edd-sample-plugin');
269
-                    break;
270
-
271
-                case 'item_name_mismatch':
272
-                    /* translators: the plugin name */
273
-                    $message = sprintf(__('This appears to be an invalid license key for %s.', 'edd-sample-plugin'), EDD_SAMPLE_ITEM_NAME);
274
-                    break;
275
-
276
-                case 'no_activations_left':
277
-                    $message = __('Your license key has reached its activation limit.', 'edd-sample-plugin');
278
-                    break;
279
-
280
-                default:
281
-                    $message = __('An error occurred, please try again.', 'edd-sample-plugin');
282
-                    break;
283
-            }
284
-        }
285
-    }
286
-
287
-        // Check if anything passed on a message constituting a failure
288
-    if (! empty($message)) {
289
-        $redirect = add_query_arg(
290
-            array(
291
-                'page'          => EDD_SAMPLE_PLUGIN_LICENSE_PAGE,
292
-                'sl_activation' => 'false',
293
-                'message'       => rawurlencode($message),
294
-            ),
295
-            admin_url('plugins.php')
296
-        );
297
-
298
-        wp_safe_redirect($redirect);
299
-        exit();
300
-    }
301
-
302
-    // $license_data->license will be either "valid" or "invalid"
303
-    if ('valid' === $license_data->license) {
304
-        update_option('edd_sample_license_key', $license);
305
-    }
306
-    update_option('edd_sample_license_status', $license_data->license);
307
-    wp_safe_redirect(admin_url('plugins.php?page=' . EDD_SAMPLE_PLUGIN_LICENSE_PAGE));
308
-    exit();
198
+	// listen for our activate button to be clicked
199
+	if (! isset($_POST['edd_license_activate'])) {
200
+		return;
201
+	}
202
+
203
+	// run a quick security check
204
+	if (! check_admin_referer('edd_sample_nonce', 'edd_sample_nonce')) {
205
+		return; // get out if we didn't click the Activate button
206
+	}
207
+
208
+	// retrieve the license from the database
209
+	$license = trim(get_option('edd_sample_license_key'));
210
+	if (! $license) {
211
+		$license = ! empty($_POST['edd_sample_license_key']) ? sanitize_text_field($_POST['edd_sample_license_key']) : '';
212
+	}
213
+	if (! $license) {
214
+		return;
215
+	}
216
+
217
+	// data to send in our API request
218
+	$api_params = array(
219
+		'edd_action'  => 'activate_license',
220
+		'license'     => $license,
221
+		'item_id'     => EDD_SAMPLE_ITEM_ID,
222
+		'item_name'   => rawurlencode(EDD_SAMPLE_ITEM_NAME), // the name of our product in EDD
223
+		'url'         => home_url(),
224
+		'environment' => function_exists('wp_get_environment_type') ? wp_get_environment_type() : 'production',
225
+	);
226
+
227
+	// Call the custom API.
228
+	$response = wp_remote_post(
229
+		EDD_SAMPLE_STORE_URL,
230
+		array(
231
+			'timeout'   => 15,
232
+			'sslverify' => false,
233
+			'body'      => $api_params,
234
+		)
235
+	);
236
+
237
+		// make sure the response came back okay
238
+	if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
239
+		if (is_wp_error($response)) {
240
+			$message = $response->get_error_message();
241
+		} else {
242
+			$message = __('An error occurred, please try again.');
243
+		}
244
+	} else {
245
+		$license_data = json_decode(wp_remote_retrieve_body($response));
246
+
247
+		if (false === $license_data->success) {
248
+			switch ($license_data->error) {
249
+				case 'expired':
250
+					$message = sprintf(
251
+						/* translators: the license key expiration date */
252
+						__('Your license key expired on %s.', 'edd-sample-plugin'),
253
+						date_i18n(get_option('date_format'), strtotime($license_data->expires, current_time('timestamp')))
254
+					);
255
+					break;
256
+
257
+				case 'disabled':
258
+				case 'revoked':
259
+					$message = __('Your license key has been disabled.', 'edd-sample-plugin');
260
+					break;
261
+
262
+				case 'missing':
263
+					$message = __('Invalid license.', 'edd-sample-plugin');
264
+					break;
265
+
266
+				case 'invalid':
267
+				case 'site_inactive':
268
+					$message = __('Your license is not active for this URL.', 'edd-sample-plugin');
269
+					break;
270
+
271
+				case 'item_name_mismatch':
272
+					/* translators: the plugin name */
273
+					$message = sprintf(__('This appears to be an invalid license key for %s.', 'edd-sample-plugin'), EDD_SAMPLE_ITEM_NAME);
274
+					break;
275
+
276
+				case 'no_activations_left':
277
+					$message = __('Your license key has reached its activation limit.', 'edd-sample-plugin');
278
+					break;
279
+
280
+				default:
281
+					$message = __('An error occurred, please try again.', 'edd-sample-plugin');
282
+					break;
283
+			}
284
+		}
285
+	}
286
+
287
+		// Check if anything passed on a message constituting a failure
288
+	if (! empty($message)) {
289
+		$redirect = add_query_arg(
290
+			array(
291
+				'page'          => EDD_SAMPLE_PLUGIN_LICENSE_PAGE,
292
+				'sl_activation' => 'false',
293
+				'message'       => rawurlencode($message),
294
+			),
295
+			admin_url('plugins.php')
296
+		);
297
+
298
+		wp_safe_redirect($redirect);
299
+		exit();
300
+	}
301
+
302
+	// $license_data->license will be either "valid" or "invalid"
303
+	if ('valid' === $license_data->license) {
304
+		update_option('edd_sample_license_key', $license);
305
+	}
306
+	update_option('edd_sample_license_status', $license_data->license);
307
+	wp_safe_redirect(admin_url('plugins.php?page=' . EDD_SAMPLE_PLUGIN_LICENSE_PAGE));
308
+	exit();
309 309
 }
310 310
 add_action('admin_init', 'edd_sample_activate_license');
311 311
 
@@ -318,68 +318,68 @@  discard block
 block discarded – undo
318 318
 function edd_sample_deactivate_license()
319 319
 {
320 320
 
321
-    // listen for our activate button to be clicked
322
-    if (isset($_POST['edd_license_deactivate'])) {
323
-        // run a quick security check
324
-        if (! check_admin_referer('edd_sample_nonce', 'edd_sample_nonce')) {
325
-            return; // get out if we didn't click the Activate button
326
-        }
327
-
328
-        // retrieve the license from the database
329
-        $license = trim(get_option('edd_sample_license_key'));
330
-
331
-        // data to send in our API request
332
-        $api_params = array(
333
-            'edd_action'  => 'deactivate_license',
334
-            'license'     => $license,
335
-            'item_id'     => EDD_SAMPLE_ITEM_ID,
336
-            'item_name'   => rawurlencode(EDD_SAMPLE_ITEM_NAME), // the name of our product in EDD
337
-            'url'         => home_url(),
338
-            'environment' => function_exists('wp_get_environment_type') ? wp_get_environment_type() : 'production',
339
-        );
340
-
341
-        // Call the custom API.
342
-        $response = wp_remote_post(
343
-            EDD_SAMPLE_STORE_URL,
344
-            array(
345
-                'timeout'   => 15,
346
-                'sslverify' => false,
347
-                'body'      => $api_params,
348
-            )
349
-        );
350
-
351
-        // make sure the response came back okay
352
-        if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
353
-            if (is_wp_error($response)) {
354
-                $message = $response->get_error_message();
355
-            } else {
356
-                $message = __('An error occurred, please try again.');
357
-            }
358
-
359
-            $redirect = add_query_arg(
360
-                array(
361
-                    'page'          => EDD_SAMPLE_PLUGIN_LICENSE_PAGE,
362
-                    'sl_activation' => 'false',
363
-                    'message'       => rawurlencode($message),
364
-                ),
365
-                admin_url('plugins.php')
366
-            );
367
-
368
-            wp_safe_redirect($redirect);
369
-            exit();
370
-        }
371
-
372
-        // decode the license data
373
-        $license_data = json_decode(wp_remote_retrieve_body($response));
374
-
375
-        // $license_data->license will be either "deactivated" or "failed"
376
-        if ('deactivated' === $license_data->license) {
377
-            delete_option('edd_sample_license_status');
378
-        }
379
-
380
-        wp_safe_redirect(admin_url('plugins.php?page=' . EDD_SAMPLE_PLUGIN_LICENSE_PAGE));
381
-        exit();
382
-    }
321
+	// listen for our activate button to be clicked
322
+	if (isset($_POST['edd_license_deactivate'])) {
323
+		// run a quick security check
324
+		if (! check_admin_referer('edd_sample_nonce', 'edd_sample_nonce')) {
325
+			return; // get out if we didn't click the Activate button
326
+		}
327
+
328
+		// retrieve the license from the database
329
+		$license = trim(get_option('edd_sample_license_key'));
330
+
331
+		// data to send in our API request
332
+		$api_params = array(
333
+			'edd_action'  => 'deactivate_license',
334
+			'license'     => $license,
335
+			'item_id'     => EDD_SAMPLE_ITEM_ID,
336
+			'item_name'   => rawurlencode(EDD_SAMPLE_ITEM_NAME), // the name of our product in EDD
337
+			'url'         => home_url(),
338
+			'environment' => function_exists('wp_get_environment_type') ? wp_get_environment_type() : 'production',
339
+		);
340
+
341
+		// Call the custom API.
342
+		$response = wp_remote_post(
343
+			EDD_SAMPLE_STORE_URL,
344
+			array(
345
+				'timeout'   => 15,
346
+				'sslverify' => false,
347
+				'body'      => $api_params,
348
+			)
349
+		);
350
+
351
+		// make sure the response came back okay
352
+		if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
353
+			if (is_wp_error($response)) {
354
+				$message = $response->get_error_message();
355
+			} else {
356
+				$message = __('An error occurred, please try again.');
357
+			}
358
+
359
+			$redirect = add_query_arg(
360
+				array(
361
+					'page'          => EDD_SAMPLE_PLUGIN_LICENSE_PAGE,
362
+					'sl_activation' => 'false',
363
+					'message'       => rawurlencode($message),
364
+				),
365
+				admin_url('plugins.php')
366
+			);
367
+
368
+			wp_safe_redirect($redirect);
369
+			exit();
370
+		}
371
+
372
+		// decode the license data
373
+		$license_data = json_decode(wp_remote_retrieve_body($response));
374
+
375
+		// $license_data->license will be either "deactivated" or "failed"
376
+		if ('deactivated' === $license_data->license) {
377
+			delete_option('edd_sample_license_status');
378
+		}
379
+
380
+		wp_safe_redirect(admin_url('plugins.php?page=' . EDD_SAMPLE_PLUGIN_LICENSE_PAGE));
381
+		exit();
382
+	}
383 383
 }
384 384
 add_action('admin_init', 'edd_sample_deactivate_license');
385 385
 
@@ -393,42 +393,42 @@  discard block
 block discarded – undo
393 393
 function edd_sample_check_license()
394 394
 {
395 395
 
396
-    $license = trim(get_option('edd_sample_license_key'));
397
-
398
-    $api_params = array(
399
-        'edd_action'  => 'check_license',
400
-        'license'     => $license,
401
-        'item_id'     => EDD_SAMPLE_ITEM_ID,
402
-        'item_name'   => rawurlencode(EDD_SAMPLE_ITEM_NAME),
403
-        'url'         => home_url(),
404
-        'environment' => function_exists('wp_get_environment_type') ? wp_get_environment_type() : 'production',
405
-    );
406
-
407
-    // Call the custom API.
408
-    $response = wp_remote_post(
409
-        EDD_SAMPLE_STORE_URL,
410
-        array(
411
-            'timeout'   => 15,
412
-            'sslverify' => false,
413
-            'body'      => $api_params,
414
-        )
415
-    );
416
-
417
-    if (is_wp_error($response)) {
418
-        return false;
419
-    }
420
-
421
-    $license_data = json_decode(wp_remote_retrieve_body($response));
422
-
423
-    if ('valid' === $license_data->license) {
424
-        echo 'valid';
425
-        exit;
426
-        // this license is still valid
427
-    } else {
428
-        echo 'invalid';
429
-        exit;
430
-        // this license is no longer valid
431
-    }
396
+	$license = trim(get_option('edd_sample_license_key'));
397
+
398
+	$api_params = array(
399
+		'edd_action'  => 'check_license',
400
+		'license'     => $license,
401
+		'item_id'     => EDD_SAMPLE_ITEM_ID,
402
+		'item_name'   => rawurlencode(EDD_SAMPLE_ITEM_NAME),
403
+		'url'         => home_url(),
404
+		'environment' => function_exists('wp_get_environment_type') ? wp_get_environment_type() : 'production',
405
+	);
406
+
407
+	// Call the custom API.
408
+	$response = wp_remote_post(
409
+		EDD_SAMPLE_STORE_URL,
410
+		array(
411
+			'timeout'   => 15,
412
+			'sslverify' => false,
413
+			'body'      => $api_params,
414
+		)
415
+	);
416
+
417
+	if (is_wp_error($response)) {
418
+		return false;
419
+	}
420
+
421
+	$license_data = json_decode(wp_remote_retrieve_body($response));
422
+
423
+	if ('valid' === $license_data->license) {
424
+		echo 'valid';
425
+		exit;
426
+		// this license is still valid
427
+	} else {
428
+		echo 'invalid';
429
+		exit;
430
+		// this license is no longer valid
431
+	}
432 432
 }
433 433
 
434 434
 /**
@@ -436,22 +436,22 @@  discard block
 block discarded – undo
436 436
  */
437 437
 function edd_sample_admin_notices()
438 438
 {
439
-    if (isset($_GET['sl_activation']) && ! empty($_GET['message'])) {
440
-        switch ($_GET['sl_activation']) {
441
-            case 'false':
442
-                $message = urldecode($_GET['message']);
443
-                ?>
439
+	if (isset($_GET['sl_activation']) && ! empty($_GET['message'])) {
440
+		switch ($_GET['sl_activation']) {
441
+			case 'false':
442
+				$message = urldecode($_GET['message']);
443
+				?>
444 444
                 <div class="error">
445 445
                     <p><?php echo wp_kses_post($message); ?></p>
446 446
                 </div>
447 447
                 <?php
448
-                break;
449
-
450
-            case 'true':
451
-            default:
452
-                // Developers can put a custom success message here for when activation is successful if they way.
453
-                break;
454
-        }
455
-    }
448
+				break;
449
+
450
+			case 'true':
451
+			default:
452
+				// Developers can put a custom success message here for when activation is successful if they way.
453
+				break;
454
+		}
455
+	}
456 456
 }
457 457
 add_action('admin_notices', 'edd_sample_admin_notices');
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
 // the name of the settings page for the license input to be displayed
28 28
 define('EDD_SAMPLE_PLUGIN_LICENSE_PAGE', 'pluginname-license');
29 29
 
30
-if (! class_exists('EDD_SL_Plugin_Updater')) {
30
+if ( ! class_exists('EDD_SL_Plugin_Updater')) {
31 31
     // load our custom updater
32
-    include dirname(__FILE__) . '/EDD_SL_Plugin_Updater.php';
32
+    include dirname(__FILE__).'/EDD_SL_Plugin_Updater.php';
33 33
 }
34 34
 
35 35
 /**
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 
42 42
     // To support auto-updates, this needs to run during the wp_version_check cron job for privileged users.
43 43
     $doing_cron = defined('DOING_CRON') && DOING_CRON;
44
-    if (! current_user_can('manage_options') && ! $doing_cron) {
44
+    if ( ! current_user_can('manage_options') && ! $doing_cron) {
45 45
         return;
46 46
     }
47 47
 
@@ -53,9 +53,9 @@  discard block
 block discarded – undo
53 53
         EDD_SAMPLE_STORE_URL,
54 54
         __FILE__,
55 55
         array(
56
-            'version' => '1.0',                    // current version number
57
-            'license' => $license_key,             // license key (used get_option above to retrieve from DB)
58
-            'item_id' => EDD_SAMPLE_ITEM_ID,       // ID of the product
56
+            'version' => '1.0', // current version number
57
+            'license' => $license_key, // license key (used get_option above to retrieve from DB)
58
+            'item_id' => EDD_SAMPLE_ITEM_ID, // ID of the product
59 59
             'author'  => 'Easy Digital Downloads', // author of this plugin
60 60
             'beta'    => false,
61 61
         )
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
     );
98 98
     add_settings_field(
99 99
         'edd_sample_license_key',
100
-        '<label for="edd_sample_license_key">' . __('License Key') . '</label>',
100
+        '<label for="edd_sample_license_key">'.__('License Key').'</label>',
101 101
         'edd_sample_license_key_settings_field',
102 102
         EDD_SAMPLE_PLUGIN_LICENSE_PAGE,
103 103
         'edd_sample_license',
@@ -196,21 +196,21 @@  discard block
 block discarded – undo
196 196
 {
197 197
 
198 198
     // listen for our activate button to be clicked
199
-    if (! isset($_POST['edd_license_activate'])) {
199
+    if ( ! isset($_POST['edd_license_activate'])) {
200 200
         return;
201 201
     }
202 202
 
203 203
     // run a quick security check
204
-    if (! check_admin_referer('edd_sample_nonce', 'edd_sample_nonce')) {
204
+    if ( ! check_admin_referer('edd_sample_nonce', 'edd_sample_nonce')) {
205 205
         return; // get out if we didn't click the Activate button
206 206
     }
207 207
 
208 208
     // retrieve the license from the database
209 209
     $license = trim(get_option('edd_sample_license_key'));
210
-    if (! $license) {
210
+    if ( ! $license) {
211 211
         $license = ! empty($_POST['edd_sample_license_key']) ? sanitize_text_field($_POST['edd_sample_license_key']) : '';
212 212
     }
213
-    if (! $license) {
213
+    if ( ! $license) {
214 214
         return;
215 215
     }
216 216
 
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
     }
286 286
 
287 287
         // Check if anything passed on a message constituting a failure
288
-    if (! empty($message)) {
288
+    if ( ! empty($message)) {
289 289
         $redirect = add_query_arg(
290 290
             array(
291 291
                 'page'          => EDD_SAMPLE_PLUGIN_LICENSE_PAGE,
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
         update_option('edd_sample_license_key', $license);
305 305
     }
306 306
     update_option('edd_sample_license_status', $license_data->license);
307
-    wp_safe_redirect(admin_url('plugins.php?page=' . EDD_SAMPLE_PLUGIN_LICENSE_PAGE));
307
+    wp_safe_redirect(admin_url('plugins.php?page='.EDD_SAMPLE_PLUGIN_LICENSE_PAGE));
308 308
     exit();
309 309
 }
310 310
 add_action('admin_init', 'edd_sample_activate_license');
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
     // listen for our activate button to be clicked
322 322
     if (isset($_POST['edd_license_deactivate'])) {
323 323
         // run a quick security check
324
-        if (! check_admin_referer('edd_sample_nonce', 'edd_sample_nonce')) {
324
+        if ( ! check_admin_referer('edd_sample_nonce', 'edd_sample_nonce')) {
325 325
             return; // get out if we didn't click the Activate button
326 326
         }
327 327
 
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
             delete_option('edd_sample_license_status');
378 378
         }
379 379
 
380
-        wp_safe_redirect(admin_url('plugins.php?page=' . EDD_SAMPLE_PLUGIN_LICENSE_PAGE));
380
+        wp_safe_redirect(admin_url('plugins.php?page='.EDD_SAMPLE_PLUGIN_LICENSE_PAGE));
381 381
         exit();
382 382
     }
383 383
 }
Please login to merge, or discard this patch.
core/services/licensing/PluginLicenseCollection.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -6,21 +6,21 @@
 block discarded – undo
6 6
 
7 7
 class PluginLicenseCollection extends Collection
8 8
 {
9
-    const COLLECTION_NAME = 'plugin licenses';
9
+	const COLLECTION_NAME = 'plugin licenses';
10 10
 
11 11
 
12
-    public function __construct()
13
-    {
14
-        parent::__construct(PluginLicense::class, PluginLicenseCollection::COLLECTION_NAME);
15
-        add_action('init', [$this, 'loadPluginLicenses'], 99);
16
-    }
12
+	public function __construct()
13
+	{
14
+		parent::__construct(PluginLicense::class, PluginLicenseCollection::COLLECTION_NAME);
15
+		add_action('init', [$this, 'loadPluginLicenses'], 99);
16
+	}
17 17
 
18 18
 
19
-    public function loadPluginLicenses()
20
-    {
21
-        do_action(
22
-            'AHEE__EventEspresso_core_services_licensing_PluginLicenseCollection__loadPluginLicenses',
23
-            $this
24
-        );
25
-    }
19
+	public function loadPluginLicenses()
20
+	{
21
+		do_action(
22
+			'AHEE__EventEspresso_core_services_licensing_PluginLicenseCollection__loadPluginLicenses',
23
+			$this
24
+		);
25
+	}
26 26
 }
Please login to merge, or discard this patch.
core/services/helpers/DebugDisplay.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -4,34 +4,34 @@
 block discarded – undo
4 4
 
5 5
 trait DebugDisplay
6 6
 {
7
-    /**
8
-     * used for controlling how much data is displayed when debugging
9
-     * threshold is set to 0 by default, but can be set to 1, 2, 3, or 4
10
-     * where higher numbers display more data
11
-     *
12
-     * @var int
13
-     */
14
-    private int $threshold = 0;
7
+	/**
8
+	 * used for controlling how much data is displayed when debugging
9
+	 * threshold is set to 0 by default, but can be set to 1, 2, 3, or 4
10
+	 * where higher numbers display more data
11
+	 *
12
+	 * @var int
13
+	 */
14
+	private int $threshold = 0;
15 15
 
16
-    private array $levels = [
17
-        0 => 'none',
18
-        1 => 'low',
19
-        2 => 'medium',
20
-        3 => 'high',
21
-        4 => 'all'
22
-    ];
16
+	private array $levels = [
17
+		0 => 'none',
18
+		1 => 'low',
19
+		2 => 'medium',
20
+		3 => 'high',
21
+		4 => 'all'
22
+	];
23 23
 
24 24
 
25
-    public function initializeDebugDisplay(int $threshold = 0, ?array $levels = null)
26
-    {
27
-        $this->threshold = defined('WP_DEBUG') && WP_DEBUG ? $threshold : 0;
28
-        $this->levels = $levels ?: $this->levels;
29
-    }
25
+	public function initializeDebugDisplay(int $threshold = 0, ?array $levels = null)
26
+	{
27
+		$this->threshold = defined('WP_DEBUG') && WP_DEBUG ? $threshold : 0;
28
+		$this->levels = $levels ?: $this->levels;
29
+	}
30 30
 
31
-    public function debugLog(string $text, int $level = 1)
32
-    {
33
-        if ($this->threshold && $this->threshold >= $level) {
34
-            error_log($text);
35
-        }
36
-    }
31
+	public function debugLog(string $text, int $level = 1)
32
+	{
33
+		if ($this->threshold && $this->threshold >= $level) {
34
+			error_log($text);
35
+		}
36
+	}
37 37
 }
Please login to merge, or discard this patch.
core/services/helpers/WordPressHooks.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -4,35 +4,35 @@
 block discarded – undo
4 4
 
5 5
 class WordPressHooks
6 6
 {
7
-    /**
8
-     * returns an array of names for all classes that have methods registered as callbacks for the given action or
9
-     * filter hook
10
-     *
11
-     * @param string $hook
12
-     * @return array
13
-     */
14
-    public static function getClassNamesForAllCallbacksOnHook(string $hook): array
15
-    {
16
-        global $wp_filter;
17
-        $class_names = [];
18
-        // are any callbacks registered for this hook ?
19
-        if (isset($wp_filter[ $hook ])) {
20
-            // loop thru all of the callbacks attached to the deprecated hookpoint
21
-            foreach ($wp_filter[ $hook ] as $priority) {
22
-                foreach ($priority as $callback) {
23
-                    // is the callback a non-static class method ?
24
-                    if (isset($callback['function']) && is_array($callback['function'])) {
25
-                        if (isset($callback['function'][0]) && is_object($callback['function'][0])) {
26
-                            $class_names[] = get_class($callback['function'][0]);
27
-                        }
28
-                        // test for static method
29
-                    } elseif (strpos($callback['function'], '::') !== false) {
30
-                        $class         = explode('::', $callback['function']);
31
-                        $class_names[] = $class[0];
32
-                    }
33
-                }
34
-            }
35
-        }
36
-        return $class_names;
37
-    }
7
+	/**
8
+	 * returns an array of names for all classes that have methods registered as callbacks for the given action or
9
+	 * filter hook
10
+	 *
11
+	 * @param string $hook
12
+	 * @return array
13
+	 */
14
+	public static function getClassNamesForAllCallbacksOnHook(string $hook): array
15
+	{
16
+		global $wp_filter;
17
+		$class_names = [];
18
+		// are any callbacks registered for this hook ?
19
+		if (isset($wp_filter[ $hook ])) {
20
+			// loop thru all of the callbacks attached to the deprecated hookpoint
21
+			foreach ($wp_filter[ $hook ] as $priority) {
22
+				foreach ($priority as $callback) {
23
+					// is the callback a non-static class method ?
24
+					if (isset($callback['function']) && is_array($callback['function'])) {
25
+						if (isset($callback['function'][0]) && is_object($callback['function'][0])) {
26
+							$class_names[] = get_class($callback['function'][0]);
27
+						}
28
+						// test for static method
29
+					} elseif (strpos($callback['function'], '::') !== false) {
30
+						$class         = explode('::', $callback['function']);
31
+						$class_names[] = $class[0];
32
+					}
33
+				}
34
+			}
35
+		}
36
+		return $class_names;
37
+	}
38 38
 }
Please login to merge, or discard this patch.
core/services/request/RequestStack.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -14,47 +14,47 @@
 block discarded – undo
14 14
  */
15 15
 class RequestStack
16 16
 {
17
-    protected RequestDecoratorInterface $request_stack_app;
18
-
19
-    protected RequestInterface $request;
20
-
21
-    protected RequestStackCoreAppInterface $core_app;
22
-
23
-    protected ResponseInterface $response;
24
-
25
-
26
-    /**
27
-     * @param RequestDecoratorInterface    $request_stack_app
28
-     * @param RequestStackCoreAppInterface $core_app
29
-     */
30
-    public function __construct(RequestDecoratorInterface $request_stack_app, RequestStackCoreAppInterface $core_app)
31
-    {
32
-        $this->request_stack_app = $request_stack_app;
33
-        $this->core_app          = $core_app;
34
-    }
35
-
36
-
37
-    /**
38
-     * @param RequestInterface  $request
39
-     * @param ResponseInterface $response
40
-     * @return ResponseInterface
41
-     */
42
-    public function handleRequest(RequestInterface $request, ResponseInterface $response): ResponseInterface
43
-    {
44
-        $this->request  = $request;
45
-        $this->response = $response;
46
-        return $this->request_stack_app->handleRequest($request, $response);
47
-    }
48
-
49
-
50
-    /**
51
-     * handle_response
52
-     * executes the handle_response() method on the RequestStackCoreAppInterface object
53
-     * after the request stack has been fully processed
54
-     */
55
-    public function handleResponse()
56
-    {
57
-        $this->core_app->handleResponse($this->request, $this->response);
58
-    }
17
+	protected RequestDecoratorInterface $request_stack_app;
18
+
19
+	protected RequestInterface $request;
20
+
21
+	protected RequestStackCoreAppInterface $core_app;
22
+
23
+	protected ResponseInterface $response;
24
+
25
+
26
+	/**
27
+	 * @param RequestDecoratorInterface    $request_stack_app
28
+	 * @param RequestStackCoreAppInterface $core_app
29
+	 */
30
+	public function __construct(RequestDecoratorInterface $request_stack_app, RequestStackCoreAppInterface $core_app)
31
+	{
32
+		$this->request_stack_app = $request_stack_app;
33
+		$this->core_app          = $core_app;
34
+	}
35
+
36
+
37
+	/**
38
+	 * @param RequestInterface  $request
39
+	 * @param ResponseInterface $response
40
+	 * @return ResponseInterface
41
+	 */
42
+	public function handleRequest(RequestInterface $request, ResponseInterface $response): ResponseInterface
43
+	{
44
+		$this->request  = $request;
45
+		$this->response = $response;
46
+		return $this->request_stack_app->handleRequest($request, $response);
47
+	}
48
+
49
+
50
+	/**
51
+	 * handle_response
52
+	 * executes the handle_response() method on the RequestStackCoreAppInterface object
53
+	 * after the request stack has been fully processed
54
+	 */
55
+	public function handleResponse()
56
+	{
57
+		$this->core_app->handleResponse($this->request, $this->response);
58
+	}
59 59
 }
60 60
 // Location: RequestStack.php
Please login to merge, or discard this patch.
core/services/request/CurrentPage.php 2 patches
Indentation   +295 added lines, -295 removed lines patch added patch discarded remove patch
@@ -22,299 +22,299 @@
 block discarded – undo
22 22
  */
23 23
 class CurrentPage
24 24
 {
25
-    private EE_CPT_Strategy $cpt_strategy;
26
-
27
-    private bool $initialized;
28
-
29
-    private ?bool $is_espresso_page = null;
30
-
31
-    private int $post_id          = 0;
32
-
33
-    private string $post_name        = '';
34
-
35
-    private array $post_type        = [];
36
-
37
-    private RequestInterface $request;
38
-
39
-
40
-    /**
41
-     * CurrentPage constructor.
42
-     *
43
-     * @param EE_CPT_Strategy  $cpt_strategy
44
-     * @param RequestInterface $request
45
-     */
46
-    public function __construct(EE_CPT_Strategy $cpt_strategy, RequestInterface $request)
47
-    {
48
-        $this->cpt_strategy = $cpt_strategy;
49
-        $this->request      = $request;
50
-        $this->initialized  = is_admin();
51
-        // analyse the incoming WP request
52
-        add_action('parse_request', [$this, 'parseQueryVars'], 2);
53
-    }
54
-
55
-
56
-    /**
57
-     * @param WP|null $WP
58
-     * @return void
59
-     */
60
-    public function parseQueryVars(WP $WP = null)
61
-    {
62
-        if ($this->initialized) {
63
-            return;
64
-        }
65
-        // if somebody forgot to provide us with WP, that's ok because its global
66
-        if (! $WP instanceof WP) {
67
-            global $WP;
68
-        }
69
-        $this->post_id   = $this->getPostId($WP);
70
-        $this->post_name = $this->getPostName($WP);
71
-        $this->post_type = $this->getPostType($WP);
72
-        // true or false ? is this page being used by EE ?
73
-        $this->setEspressoPage();
74
-        remove_action('parse_request', [$this, 'parseQueryVars'], 2);
75
-        $this->initialized = true;
76
-    }
77
-
78
-
79
-    /**
80
-     * Just a helper method for getting the url for the displayed page.
81
-     *
82
-     * @param WP|null $WP
83
-     * @return string
84
-     */
85
-    public function getPermalink(WP $WP = null): string
86
-    {
87
-        $post_id = $this->post_id ?: $this->getPostId($WP);
88
-        if ($post_id) {
89
-            return get_permalink($post_id);
90
-        }
91
-        if (! $WP instanceof WP) {
92
-            global $WP;
93
-        }
94
-        if ($WP instanceof WP && $WP->request) {
95
-            return site_url($WP->request);
96
-        }
97
-        return esc_url_raw(site_url($_SERVER['REQUEST_URI']));
98
-    }
99
-
100
-
101
-    /**
102
-     * @return array
103
-     */
104
-    public function espressoPostType(): array
105
-    {
106
-        return array_filter(
107
-            $this->post_type,
108
-            function ($post_type) {
109
-                return strpos($post_type, 'espresso_') === 0;
110
-            }
111
-        );
112
-    }
113
-
114
-
115
-    /**
116
-     * pokes and prods the WP object query_vars in an attempt to shake out a page/post ID
117
-     *
118
-     * @param WP|null $WP $WP
119
-     * @return int
120
-     */
121
-    private function getPostId(WP $WP = null): ?int
122
-    {
123
-        $post_id = 0;
124
-        if ($WP instanceof WP) {
125
-            // look for the post ID in the aptly named 'p' query var
126
-            if (isset($WP->query_vars['p'])) {
127
-                $post_id = $WP->query_vars['p'];
128
-            }
129
-            // not a post? what about a page?
130
-            if (! $post_id && isset($WP->query_vars['page_id'])) {
131
-                $post_id = $WP->query_vars['page_id'];
132
-            }
133
-            // ok... maybe pretty permalinks are off and the ID is set in the raw request...
134
-            // but hasn't been processed yet ie: this method is being called too early :\
135
-            if (! $post_id && $WP->request !== null && is_numeric(basename($WP->request))) {
136
-                $post_id = basename($WP->request);
137
-            }
138
-        }
139
-        // none of the above? ok what about an explicit "post_id" URL parameter?
140
-        if (! $post_id && $this->request->requestParamIsSet('post_id')) {
141
-            $post_id = $this->request->getRequestParam('post_id', 0, DataType::INT);
142
-        }
143
-        return (int) $post_id;
144
-    }
145
-
146
-
147
-    /**
148
-     * similar to getPostId() above but attempts to obtain the "name" for the current page/post
149
-     *
150
-     * @param WP|null $WP $WP
151
-     * @return string|null
152
-     */
153
-    private function getPostName(WP $WP = null): ?string
154
-    {
155
-        global $wpdb;
156
-        $post_name = '';
157
-        if ($WP instanceof WP) {
158
-            // if this is a post, then is the post name set?
159
-            if (isset($WP->query_vars['name']) && ! empty($WP->query_vars['name'])) {
160
-                $post_name = is_array($WP->query_vars['name']) ? $WP->query_vars['name'][0] : $WP->query_vars['name'];
161
-            }
162
-            // what about the page name?
163
-            if (! $post_name && isset($WP->query_vars['pagename']) && ! empty($WP->query_vars['pagename'])) {
164
-                $post_name = is_array($WP->query_vars['pagename']) ? $WP->query_vars['pagename'][0]
165
-                    : $WP->query_vars['pagename'];
166
-            }
167
-            // this stinks but let's run a query to try and get the post name from the URL
168
-            // (assuming pretty permalinks are on)
169
-            if (! $post_name && ! empty($WP->request)) {
170
-                $possible_post_name = basename($WP->request);
171
-                if (! is_numeric($possible_post_name)) {
172
-                    $SQL                = "SELECT ID from $wpdb->posts";
173
-                    $SQL                .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')";
174
-                    $SQL                .= ' AND post_name=%s';
175
-                    $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name));
176
-                    if ($possible_post_name) {
177
-                        $post_name = $possible_post_name;
178
-                    }
179
-                }
180
-            }
181
-        }
182
-        // ug... ok... nothing yet... but do we have a post ID?
183
-        // if so then... sigh... run a query to get the post name :\
184
-        if (! $post_name && $this->post_id) {
185
-            $SQL                = "SELECT post_name from $wpdb->posts";
186
-            $SQL                .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')";
187
-            $SQL                .= ' AND ID=%d';
188
-            $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->post_id));
189
-            if ($possible_post_name) {
190
-                $post_name = $possible_post_name;
191
-            }
192
-        }
193
-        // still nothing? ok what about an explicit 'post_name' URL parameter?
194
-        if (! $post_name && $this->request->requestParamIsSet('post_name')) {
195
-            $post_name = $this->request->getRequestParam('post_name');
196
-        }
197
-        return $post_name;
198
-    }
199
-
200
-
201
-    /**
202
-     * also similar to getPostId() and getPostName() above but not as insane
203
-     *
204
-     * @param WP|null $WP $WP
205
-     * @return array
206
-     */
207
-    private function getPostType(WP $WP = null): array
208
-    {
209
-        $post_types = [];
210
-        if ($WP instanceof WP) {
211
-            $post_types = isset($WP->query_vars['post_type'])
212
-                ? (array) $WP->query_vars['post_type']
213
-                : [];
214
-        }
215
-        if (empty($post_types) && $this->request->requestParamIsSet('post_type')) {
216
-            $post_types = $this->request->getRequestParam('post_type', [], DataType::STRING, true);
217
-        }
218
-        return (array) $post_types;
219
-    }
220
-
221
-
222
-    /**
223
-     * if TRUE, then the current page is somehow utilizing EE logic
224
-     *
225
-     * @return bool
226
-     */
227
-    public function isEspressoPage(): bool
228
-    {
229
-        if ($this->is_espresso_page === null) {
230
-            $this->setEspressoPage();
231
-        }
232
-        return $this->is_espresso_page;
233
-    }
234
-
235
-
236
-    /**
237
-     * @return int
238
-     */
239
-    public function postId(): int
240
-    {
241
-        return $this->post_id;
242
-    }
243
-
244
-
245
-    /**
246
-     * @return string|null
247
-     */
248
-    public function postName(): ?string
249
-    {
250
-        return $this->post_name;
251
-    }
252
-
253
-
254
-    /**
255
-     * @return array
256
-     */
257
-    public function postType(): array
258
-    {
259
-        return $this->post_type;
260
-    }
261
-
262
-
263
-    /**
264
-     * for manually indicating the current page will utilize EE logic
265
-     *
266
-     * @param bool|int|string|null $value
267
-     * @return void
268
-     */
269
-    public function setEspressoPage($value = null)
270
-    {
271
-        $this->is_espresso_page = $value !== null
272
-            ? filter_var($value, FILTER_VALIDATE_BOOLEAN)
273
-            : $this->testForEspressoPage();
274
-    }
275
-
276
-
277
-    /**
278
-     * attempts to determine if the current page/post is an EE related page/post
279
-     * because it utilizes one of our CPT taxonomies, endpoints, or post types
280
-     *
281
-     * @return bool
282
-     */
283
-    private function testForEspressoPage(): bool
284
-    {
285
-        // in case it has already been set
286
-        if ($this->is_espresso_page) {
287
-            return true;
288
-        }
289
-        global $WP;
290
-        $espresso_CPT_taxonomies = $this->cpt_strategy->get_CPT_taxonomies();
291
-        if (is_array($espresso_CPT_taxonomies)) {
292
-            foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) {
293
-                if (isset($WP->query_vars, $WP->query_vars[ $espresso_CPT_taxonomy ])) {
294
-                    return true;
295
-                }
296
-            }
297
-        }
298
-        // load espresso CPT endpoints
299
-        $espresso_CPT_endpoints  = $this->cpt_strategy->get_CPT_endpoints();
300
-        $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
301
-        foreach ($this->post_type as $post_type) {
302
-            // was a post name passed ?
303
-            if (isset($post_type_CPT_endpoints[ $post_type ])) {
304
-                // kk we know this is an espresso page, but is it a specific post ?
305
-                if (! $this->post_name) {
306
-                    $espresso_post_type = $this->request->getRequestParam('post_type');
307
-                    // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
308
-                    // this essentially sets the post_name to "events" (or whatever EE CPT)
309
-                    $post_name = $post_type_CPT_endpoints[ $espresso_post_type ] ?? '';
310
-                    // if the post type matches one of ours then set the post name to the endpoint
311
-                    if ($post_name) {
312
-                        $this->post_name = $post_name;
313
-                    }
314
-                }
315
-                return true;
316
-            }
317
-        }
318
-        return false;
319
-    }
25
+	private EE_CPT_Strategy $cpt_strategy;
26
+
27
+	private bool $initialized;
28
+
29
+	private ?bool $is_espresso_page = null;
30
+
31
+	private int $post_id          = 0;
32
+
33
+	private string $post_name        = '';
34
+
35
+	private array $post_type        = [];
36
+
37
+	private RequestInterface $request;
38
+
39
+
40
+	/**
41
+	 * CurrentPage constructor.
42
+	 *
43
+	 * @param EE_CPT_Strategy  $cpt_strategy
44
+	 * @param RequestInterface $request
45
+	 */
46
+	public function __construct(EE_CPT_Strategy $cpt_strategy, RequestInterface $request)
47
+	{
48
+		$this->cpt_strategy = $cpt_strategy;
49
+		$this->request      = $request;
50
+		$this->initialized  = is_admin();
51
+		// analyse the incoming WP request
52
+		add_action('parse_request', [$this, 'parseQueryVars'], 2);
53
+	}
54
+
55
+
56
+	/**
57
+	 * @param WP|null $WP
58
+	 * @return void
59
+	 */
60
+	public function parseQueryVars(WP $WP = null)
61
+	{
62
+		if ($this->initialized) {
63
+			return;
64
+		}
65
+		// if somebody forgot to provide us with WP, that's ok because its global
66
+		if (! $WP instanceof WP) {
67
+			global $WP;
68
+		}
69
+		$this->post_id   = $this->getPostId($WP);
70
+		$this->post_name = $this->getPostName($WP);
71
+		$this->post_type = $this->getPostType($WP);
72
+		// true or false ? is this page being used by EE ?
73
+		$this->setEspressoPage();
74
+		remove_action('parse_request', [$this, 'parseQueryVars'], 2);
75
+		$this->initialized = true;
76
+	}
77
+
78
+
79
+	/**
80
+	 * Just a helper method for getting the url for the displayed page.
81
+	 *
82
+	 * @param WP|null $WP
83
+	 * @return string
84
+	 */
85
+	public function getPermalink(WP $WP = null): string
86
+	{
87
+		$post_id = $this->post_id ?: $this->getPostId($WP);
88
+		if ($post_id) {
89
+			return get_permalink($post_id);
90
+		}
91
+		if (! $WP instanceof WP) {
92
+			global $WP;
93
+		}
94
+		if ($WP instanceof WP && $WP->request) {
95
+			return site_url($WP->request);
96
+		}
97
+		return esc_url_raw(site_url($_SERVER['REQUEST_URI']));
98
+	}
99
+
100
+
101
+	/**
102
+	 * @return array
103
+	 */
104
+	public function espressoPostType(): array
105
+	{
106
+		return array_filter(
107
+			$this->post_type,
108
+			function ($post_type) {
109
+				return strpos($post_type, 'espresso_') === 0;
110
+			}
111
+		);
112
+	}
113
+
114
+
115
+	/**
116
+	 * pokes and prods the WP object query_vars in an attempt to shake out a page/post ID
117
+	 *
118
+	 * @param WP|null $WP $WP
119
+	 * @return int
120
+	 */
121
+	private function getPostId(WP $WP = null): ?int
122
+	{
123
+		$post_id = 0;
124
+		if ($WP instanceof WP) {
125
+			// look for the post ID in the aptly named 'p' query var
126
+			if (isset($WP->query_vars['p'])) {
127
+				$post_id = $WP->query_vars['p'];
128
+			}
129
+			// not a post? what about a page?
130
+			if (! $post_id && isset($WP->query_vars['page_id'])) {
131
+				$post_id = $WP->query_vars['page_id'];
132
+			}
133
+			// ok... maybe pretty permalinks are off and the ID is set in the raw request...
134
+			// but hasn't been processed yet ie: this method is being called too early :\
135
+			if (! $post_id && $WP->request !== null && is_numeric(basename($WP->request))) {
136
+				$post_id = basename($WP->request);
137
+			}
138
+		}
139
+		// none of the above? ok what about an explicit "post_id" URL parameter?
140
+		if (! $post_id && $this->request->requestParamIsSet('post_id')) {
141
+			$post_id = $this->request->getRequestParam('post_id', 0, DataType::INT);
142
+		}
143
+		return (int) $post_id;
144
+	}
145
+
146
+
147
+	/**
148
+	 * similar to getPostId() above but attempts to obtain the "name" for the current page/post
149
+	 *
150
+	 * @param WP|null $WP $WP
151
+	 * @return string|null
152
+	 */
153
+	private function getPostName(WP $WP = null): ?string
154
+	{
155
+		global $wpdb;
156
+		$post_name = '';
157
+		if ($WP instanceof WP) {
158
+			// if this is a post, then is the post name set?
159
+			if (isset($WP->query_vars['name']) && ! empty($WP->query_vars['name'])) {
160
+				$post_name = is_array($WP->query_vars['name']) ? $WP->query_vars['name'][0] : $WP->query_vars['name'];
161
+			}
162
+			// what about the page name?
163
+			if (! $post_name && isset($WP->query_vars['pagename']) && ! empty($WP->query_vars['pagename'])) {
164
+				$post_name = is_array($WP->query_vars['pagename']) ? $WP->query_vars['pagename'][0]
165
+					: $WP->query_vars['pagename'];
166
+			}
167
+			// this stinks but let's run a query to try and get the post name from the URL
168
+			// (assuming pretty permalinks are on)
169
+			if (! $post_name && ! empty($WP->request)) {
170
+				$possible_post_name = basename($WP->request);
171
+				if (! is_numeric($possible_post_name)) {
172
+					$SQL                = "SELECT ID from $wpdb->posts";
173
+					$SQL                .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')";
174
+					$SQL                .= ' AND post_name=%s';
175
+					$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name));
176
+					if ($possible_post_name) {
177
+						$post_name = $possible_post_name;
178
+					}
179
+				}
180
+			}
181
+		}
182
+		// ug... ok... nothing yet... but do we have a post ID?
183
+		// if so then... sigh... run a query to get the post name :\
184
+		if (! $post_name && $this->post_id) {
185
+			$SQL                = "SELECT post_name from $wpdb->posts";
186
+			$SQL                .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')";
187
+			$SQL                .= ' AND ID=%d';
188
+			$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->post_id));
189
+			if ($possible_post_name) {
190
+				$post_name = $possible_post_name;
191
+			}
192
+		}
193
+		// still nothing? ok what about an explicit 'post_name' URL parameter?
194
+		if (! $post_name && $this->request->requestParamIsSet('post_name')) {
195
+			$post_name = $this->request->getRequestParam('post_name');
196
+		}
197
+		return $post_name;
198
+	}
199
+
200
+
201
+	/**
202
+	 * also similar to getPostId() and getPostName() above but not as insane
203
+	 *
204
+	 * @param WP|null $WP $WP
205
+	 * @return array
206
+	 */
207
+	private function getPostType(WP $WP = null): array
208
+	{
209
+		$post_types = [];
210
+		if ($WP instanceof WP) {
211
+			$post_types = isset($WP->query_vars['post_type'])
212
+				? (array) $WP->query_vars['post_type']
213
+				: [];
214
+		}
215
+		if (empty($post_types) && $this->request->requestParamIsSet('post_type')) {
216
+			$post_types = $this->request->getRequestParam('post_type', [], DataType::STRING, true);
217
+		}
218
+		return (array) $post_types;
219
+	}
220
+
221
+
222
+	/**
223
+	 * if TRUE, then the current page is somehow utilizing EE logic
224
+	 *
225
+	 * @return bool
226
+	 */
227
+	public function isEspressoPage(): bool
228
+	{
229
+		if ($this->is_espresso_page === null) {
230
+			$this->setEspressoPage();
231
+		}
232
+		return $this->is_espresso_page;
233
+	}
234
+
235
+
236
+	/**
237
+	 * @return int
238
+	 */
239
+	public function postId(): int
240
+	{
241
+		return $this->post_id;
242
+	}
243
+
244
+
245
+	/**
246
+	 * @return string|null
247
+	 */
248
+	public function postName(): ?string
249
+	{
250
+		return $this->post_name;
251
+	}
252
+
253
+
254
+	/**
255
+	 * @return array
256
+	 */
257
+	public function postType(): array
258
+	{
259
+		return $this->post_type;
260
+	}
261
+
262
+
263
+	/**
264
+	 * for manually indicating the current page will utilize EE logic
265
+	 *
266
+	 * @param bool|int|string|null $value
267
+	 * @return void
268
+	 */
269
+	public function setEspressoPage($value = null)
270
+	{
271
+		$this->is_espresso_page = $value !== null
272
+			? filter_var($value, FILTER_VALIDATE_BOOLEAN)
273
+			: $this->testForEspressoPage();
274
+	}
275
+
276
+
277
+	/**
278
+	 * attempts to determine if the current page/post is an EE related page/post
279
+	 * because it utilizes one of our CPT taxonomies, endpoints, or post types
280
+	 *
281
+	 * @return bool
282
+	 */
283
+	private function testForEspressoPage(): bool
284
+	{
285
+		// in case it has already been set
286
+		if ($this->is_espresso_page) {
287
+			return true;
288
+		}
289
+		global $WP;
290
+		$espresso_CPT_taxonomies = $this->cpt_strategy->get_CPT_taxonomies();
291
+		if (is_array($espresso_CPT_taxonomies)) {
292
+			foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) {
293
+				if (isset($WP->query_vars, $WP->query_vars[ $espresso_CPT_taxonomy ])) {
294
+					return true;
295
+				}
296
+			}
297
+		}
298
+		// load espresso CPT endpoints
299
+		$espresso_CPT_endpoints  = $this->cpt_strategy->get_CPT_endpoints();
300
+		$post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
301
+		foreach ($this->post_type as $post_type) {
302
+			// was a post name passed ?
303
+			if (isset($post_type_CPT_endpoints[ $post_type ])) {
304
+				// kk we know this is an espresso page, but is it a specific post ?
305
+				if (! $this->post_name) {
306
+					$espresso_post_type = $this->request->getRequestParam('post_type');
307
+					// there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
308
+					// this essentially sets the post_name to "events" (or whatever EE CPT)
309
+					$post_name = $post_type_CPT_endpoints[ $espresso_post_type ] ?? '';
310
+					// if the post type matches one of ours then set the post name to the endpoint
311
+					if ($post_name) {
312
+						$this->post_name = $post_name;
313
+					}
314
+				}
315
+				return true;
316
+			}
317
+		}
318
+		return false;
319
+	}
320 320
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -28,11 +28,11 @@  discard block
 block discarded – undo
28 28
 
29 29
     private ?bool $is_espresso_page = null;
30 30
 
31
-    private int $post_id          = 0;
31
+    private int $post_id = 0;
32 32
 
33
-    private string $post_name        = '';
33
+    private string $post_name = '';
34 34
 
35
-    private array $post_type        = [];
35
+    private array $post_type = [];
36 36
 
37 37
     private RequestInterface $request;
38 38
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
             return;
64 64
         }
65 65
         // if somebody forgot to provide us with WP, that's ok because its global
66
-        if (! $WP instanceof WP) {
66
+        if ( ! $WP instanceof WP) {
67 67
             global $WP;
68 68
         }
69 69
         $this->post_id   = $this->getPostId($WP);
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
         if ($post_id) {
89 89
             return get_permalink($post_id);
90 90
         }
91
-        if (! $WP instanceof WP) {
91
+        if ( ! $WP instanceof WP) {
92 92
             global $WP;
93 93
         }
94 94
         if ($WP instanceof WP && $WP->request) {
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
     {
106 106
         return array_filter(
107 107
             $this->post_type,
108
-            function ($post_type) {
108
+            function($post_type) {
109 109
                 return strpos($post_type, 'espresso_') === 0;
110 110
             }
111 111
         );
@@ -127,17 +127,17 @@  discard block
 block discarded – undo
127 127
                 $post_id = $WP->query_vars['p'];
128 128
             }
129 129
             // not a post? what about a page?
130
-            if (! $post_id && isset($WP->query_vars['page_id'])) {
130
+            if ( ! $post_id && isset($WP->query_vars['page_id'])) {
131 131
                 $post_id = $WP->query_vars['page_id'];
132 132
             }
133 133
             // ok... maybe pretty permalinks are off and the ID is set in the raw request...
134 134
             // but hasn't been processed yet ie: this method is being called too early :\
135
-            if (! $post_id && $WP->request !== null && is_numeric(basename($WP->request))) {
135
+            if ( ! $post_id && $WP->request !== null && is_numeric(basename($WP->request))) {
136 136
                 $post_id = basename($WP->request);
137 137
             }
138 138
         }
139 139
         // none of the above? ok what about an explicit "post_id" URL parameter?
140
-        if (! $post_id && $this->request->requestParamIsSet('post_id')) {
140
+        if ( ! $post_id && $this->request->requestParamIsSet('post_id')) {
141 141
             $post_id = $this->request->getRequestParam('post_id', 0, DataType::INT);
142 142
         }
143 143
         return (int) $post_id;
@@ -160,15 +160,15 @@  discard block
 block discarded – undo
160 160
                 $post_name = is_array($WP->query_vars['name']) ? $WP->query_vars['name'][0] : $WP->query_vars['name'];
161 161
             }
162 162
             // what about the page name?
163
-            if (! $post_name && isset($WP->query_vars['pagename']) && ! empty($WP->query_vars['pagename'])) {
163
+            if ( ! $post_name && isset($WP->query_vars['pagename']) && ! empty($WP->query_vars['pagename'])) {
164 164
                 $post_name = is_array($WP->query_vars['pagename']) ? $WP->query_vars['pagename'][0]
165 165
                     : $WP->query_vars['pagename'];
166 166
             }
167 167
             // this stinks but let's run a query to try and get the post name from the URL
168 168
             // (assuming pretty permalinks are on)
169
-            if (! $post_name && ! empty($WP->request)) {
169
+            if ( ! $post_name && ! empty($WP->request)) {
170 170
                 $possible_post_name = basename($WP->request);
171
-                if (! is_numeric($possible_post_name)) {
171
+                if ( ! is_numeric($possible_post_name)) {
172 172
                     $SQL                = "SELECT ID from $wpdb->posts";
173 173
                     $SQL                .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')";
174 174
                     $SQL                .= ' AND post_name=%s';
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
         }
182 182
         // ug... ok... nothing yet... but do we have a post ID?
183 183
         // if so then... sigh... run a query to get the post name :\
184
-        if (! $post_name && $this->post_id) {
184
+        if ( ! $post_name && $this->post_id) {
185 185
             $SQL                = "SELECT post_name from $wpdb->posts";
186 186
             $SQL                .= " WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash')";
187 187
             $SQL                .= ' AND ID=%d';
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
             }
192 192
         }
193 193
         // still nothing? ok what about an explicit 'post_name' URL parameter?
194
-        if (! $post_name && $this->request->requestParamIsSet('post_name')) {
194
+        if ( ! $post_name && $this->request->requestParamIsSet('post_name')) {
195 195
             $post_name = $this->request->getRequestParam('post_name');
196 196
         }
197 197
         return $post_name;
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
         $espresso_CPT_taxonomies = $this->cpt_strategy->get_CPT_taxonomies();
291 291
         if (is_array($espresso_CPT_taxonomies)) {
292 292
             foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) {
293
-                if (isset($WP->query_vars, $WP->query_vars[ $espresso_CPT_taxonomy ])) {
293
+                if (isset($WP->query_vars, $WP->query_vars[$espresso_CPT_taxonomy])) {
294 294
                     return true;
295 295
                 }
296 296
             }
@@ -300,13 +300,13 @@  discard block
 block discarded – undo
300 300
         $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
301 301
         foreach ($this->post_type as $post_type) {
302 302
             // was a post name passed ?
303
-            if (isset($post_type_CPT_endpoints[ $post_type ])) {
303
+            if (isset($post_type_CPT_endpoints[$post_type])) {
304 304
                 // kk we know this is an espresso page, but is it a specific post ?
305
-                if (! $this->post_name) {
305
+                if ( ! $this->post_name) {
306 306
                     $espresso_post_type = $this->request->getRequestParam('post_type');
307 307
                     // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
308 308
                     // this essentially sets the post_name to "events" (or whatever EE CPT)
309
-                    $post_name = $post_type_CPT_endpoints[ $espresso_post_type ] ?? '';
309
+                    $post_name = $post_type_CPT_endpoints[$espresso_post_type] ?? '';
310 310
                     // if the post type matches one of ours then set the post name to the endpoint
311 311
                     if ($post_name) {
312 312
                         $this->post_name = $post_name;
Please login to merge, or discard this patch.
core/services/request/Response.php 2 patches
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -14,139 +14,139 @@
 block discarded – undo
14 14
  */
15 15
 class Response implements ResponseInterface, ReservedInstanceInterface
16 16
 {
17
-    protected bool $deactivate_plugin = false;
18
-
19
-    protected array $notice            = [];
20
-
21
-    /**
22
-     * rendered output to be returned to WP
23
-     */
24
-    protected array $output             = [];
25
-
26
-    protected array $request_headers    = [];
27
-
28
-    protected bool $request_terminated = false;
29
-
30
-
31
-    /**
32
-     * EE_Response constructor.
33
-     */
34
-    public function __construct()
35
-    {
36
-        $this->terminateRequest(false);
37
-    }
38
-
39
-
40
-    /**
41
-     * @param $key
42
-     * @param $value
43
-     * @return    void
44
-     */
45
-    public function setNotice($key, $value)
46
-    {
47
-        $this->notice[ $key ] = $value;
48
-    }
49
-
50
-
51
-    /**
52
-     * @param $key
53
-     * @return    mixed
54
-     */
55
-    public function getNotice($key)
56
-    {
57
-        return $this->notice[ $key ] ?? null;
58
-    }
59
-
60
-
61
-    /**
62
-     * @return array
63
-     */
64
-    public function getNotices(): array
65
-    {
66
-        return $this->notice;
67
-    }
68
-
69
-
70
-    /**
71
-     * @param string $string
72
-     * @param bool   $append
73
-     */
74
-    public function addOutput(string $string, bool $append = true)
75
-    {
76
-        if ($append) {
77
-            $this->output[] = $string;
78
-            return;
79
-        }
80
-        array_unshift($this->output, $string);
81
-    }
82
-
83
-
84
-    /**
85
-     * @param bool   $as_string
86
-     * @param string $separator
87
-     * @return array|string
88
-     */
89
-    public function getOutput(bool $as_string = true, string $separator = PHP_EOL)
90
-    {
91
-        return $as_string
92
-            ? implode($separator, $this->output)
93
-            : $this->output;
94
-    }
95
-
96
-
97
-    /**
98
-     * @return boolean
99
-     */
100
-    public function requestTerminated(): bool
101
-    {
102
-        return $this->request_terminated;
103
-    }
104
-
105
-
106
-    /**
107
-     * @param bool|int|string|null $request_terminated
108
-     */
109
-    public function terminateRequest($request_terminated = true)
110
-    {
111
-        $this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN);
112
-    }
113
-
114
-
115
-    /**
116
-     * @return boolean
117
-     */
118
-    public function pluginDeactivated(): bool
119
-    {
120
-        return $this->deactivate_plugin;
121
-    }
122
-
123
-
124
-    /**
125
-     * sets $deactivate_plugin to true
126
-     */
127
-    public function deactivatePlugin()
128
-    {
129
-        $this->deactivate_plugin = true;
130
-    }
131
-
132
-
133
-    /**
134
-     * @return array
135
-     * @since 5.0.0.p
136
-     */
137
-    public function requestHeaders(): array
138
-    {
139
-        return $this->request_headers;
140
-    }
141
-
142
-
143
-    /**
144
-     * @param string $request_header
145
-     * @return void
146
-     * @since 5.0.0.p
147
-     */
148
-    public function setRequestHeader(string $request_header): void
149
-    {
150
-        $this->request_headers[] = $request_header;
151
-    }
17
+	protected bool $deactivate_plugin = false;
18
+
19
+	protected array $notice            = [];
20
+
21
+	/**
22
+	 * rendered output to be returned to WP
23
+	 */
24
+	protected array $output             = [];
25
+
26
+	protected array $request_headers    = [];
27
+
28
+	protected bool $request_terminated = false;
29
+
30
+
31
+	/**
32
+	 * EE_Response constructor.
33
+	 */
34
+	public function __construct()
35
+	{
36
+		$this->terminateRequest(false);
37
+	}
38
+
39
+
40
+	/**
41
+	 * @param $key
42
+	 * @param $value
43
+	 * @return    void
44
+	 */
45
+	public function setNotice($key, $value)
46
+	{
47
+		$this->notice[ $key ] = $value;
48
+	}
49
+
50
+
51
+	/**
52
+	 * @param $key
53
+	 * @return    mixed
54
+	 */
55
+	public function getNotice($key)
56
+	{
57
+		return $this->notice[ $key ] ?? null;
58
+	}
59
+
60
+
61
+	/**
62
+	 * @return array
63
+	 */
64
+	public function getNotices(): array
65
+	{
66
+		return $this->notice;
67
+	}
68
+
69
+
70
+	/**
71
+	 * @param string $string
72
+	 * @param bool   $append
73
+	 */
74
+	public function addOutput(string $string, bool $append = true)
75
+	{
76
+		if ($append) {
77
+			$this->output[] = $string;
78
+			return;
79
+		}
80
+		array_unshift($this->output, $string);
81
+	}
82
+
83
+
84
+	/**
85
+	 * @param bool   $as_string
86
+	 * @param string $separator
87
+	 * @return array|string
88
+	 */
89
+	public function getOutput(bool $as_string = true, string $separator = PHP_EOL)
90
+	{
91
+		return $as_string
92
+			? implode($separator, $this->output)
93
+			: $this->output;
94
+	}
95
+
96
+
97
+	/**
98
+	 * @return boolean
99
+	 */
100
+	public function requestTerminated(): bool
101
+	{
102
+		return $this->request_terminated;
103
+	}
104
+
105
+
106
+	/**
107
+	 * @param bool|int|string|null $request_terminated
108
+	 */
109
+	public function terminateRequest($request_terminated = true)
110
+	{
111
+		$this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN);
112
+	}
113
+
114
+
115
+	/**
116
+	 * @return boolean
117
+	 */
118
+	public function pluginDeactivated(): bool
119
+	{
120
+		return $this->deactivate_plugin;
121
+	}
122
+
123
+
124
+	/**
125
+	 * sets $deactivate_plugin to true
126
+	 */
127
+	public function deactivatePlugin()
128
+	{
129
+		$this->deactivate_plugin = true;
130
+	}
131
+
132
+
133
+	/**
134
+	 * @return array
135
+	 * @since 5.0.0.p
136
+	 */
137
+	public function requestHeaders(): array
138
+	{
139
+		return $this->request_headers;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @param string $request_header
145
+	 * @return void
146
+	 * @since 5.0.0.p
147
+	 */
148
+	public function setRequestHeader(string $request_header): void
149
+	{
150
+		$this->request_headers[] = $request_header;
151
+	}
152 152
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 {
17 17
     protected bool $deactivate_plugin = false;
18 18
 
19
-    protected array $notice            = [];
19
+    protected array $notice = [];
20 20
 
21 21
     /**
22 22
      * rendered output to be returned to WP
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      */
45 45
     public function setNotice($key, $value)
46 46
     {
47
-        $this->notice[ $key ] = $value;
47
+        $this->notice[$key] = $value;
48 48
     }
49 49
 
50 50
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public function getNotice($key)
56 56
     {
57
-        return $this->notice[ $key ] ?? null;
57
+        return $this->notice[$key] ?? null;
58 58
     }
59 59
 
60 60
 
Please login to merge, or discard this patch.