PluginProbe ʕ •ᴥ•ʔ
WooCommerce Square / 5.3.2
WooCommerce Square v5.3.2
5.4.2 5.4.1 5.4.0 trunk 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.7.0 2.8.0 2.9.0 2.9.1 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.2.0 3.3.0 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.7.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 4.0.0 4.1.0 4.2.0 4.2.1 4.2.2 4.2.3 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.9.0 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 4.9.8 4.9.9 5.0.0 5.0.1 5.1.0 5.1.1 5.1.2 5.2.0 5.3.0 5.3.1 5.3.2 5.3.3
woocommerce-square / includes / Framework / Plugin.php
woocommerce-square / includes / Framework Last commit date
Addresses 3 years ago Api 1 year ago Compatibility 2 years ago PaymentGateway 3 months ago Utilities 1 year ago Admin_Message_Handler.php 3 years ago Admin_Notice_Handler.php 3 months ago Lifecycle.php 2 years ago Plugin.php 11 months ago Plugin_Compatibility.php 2 years ago Plugin_Dependencies.php 1 year ago Square_Helper.php 8 months ago
Plugin.php
821 lines
1 <?php
2 /**
3 * WooCommerce Plugin Framework
4 *
5 * This source file is subject to the GNU General Public License v3.0
6 * that is bundled with this package in the file license.txt.
7 * It is also available through the world-wide-web at this URL:
8 * http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later
9 * If you did not receive a copy of the license and are unable to
10 * obtain it through the world-wide-web, please send an email
11 * to license@skyverge.com so we can send you a copy immediately.
12 *
13 * @since 3.0.0
14 * @author WooCommerce / SkyVerge
15 * @copyright Copyright (c) 2013-2019, SkyVerge, Inc.
16 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later
17 *
18 * Modified by WooCommerce on 15 December 2021.
19 */
20
21 namespace WooCommerce\Square\Framework;
22
23 defined( 'ABSPATH' ) || exit;
24
25 /**
26 * # WooCommerce Plugin Framework
27 *
28 * This framework class provides a base level of configurable and overrideable
29 * functionality and features suitable for the implementation of a WooCommerce
30 * plugin. This class handles all the "non-feature" support tasks such
31 * as verifying dependencies are met, loading the text domain, etc.
32 */
33 abstract class Plugin {
34
35 /** @var object single instance of plugin */
36 protected static $instance;
37
38 /** @var string plugin id */
39 private $id;
40
41 /** @var string version number */
42 private $version;
43
44 /** @var string plugin path without trailing slash */
45 private $plugin_path;
46
47 /** @var string plugin uri */
48 private $plugin_url;
49
50 /** @var \WC_Logger instance */
51 private $logger;
52
53 /** @var Admin_Message_Handler instance */
54 private $message_handler;
55
56 /** @var string the plugin text domain */
57 private $text_domain;
58
59 /** @var Plugin_Dependencies dependency handler instance */
60 private $dependency_handler;
61
62 /** @var Plugin\Lifecycle lifecycle handler instance */
63 protected $lifecycle_handler;
64
65 /** @var REST_API REST API handler instance */
66 protected $rest_api_handler;
67
68 /** @var Admin\Setup_Wizard handler instance */
69 protected $setup_wizard_handler;
70
71 /** @var Admin_Notice_Handler the admin notice handler class */
72 private $admin_notice_handler;
73
74
75 /**
76 * Initialize the plugin.
77 *
78 * Child plugin classes may add their own optional arguments.
79 *
80 * @since 3.0.0
81 *
82 * @param string $id plugin id
83 * @param string $version plugin version number
84 * @param array $args {
85 * optional plugin arguments
86 *
87 * @type string $text_domain the plugin textdomain, used to set up translations
88 * @type array $dependencies {
89 * PHP extension, function, and settings dependencies
90 *
91 * @type array $php_extensions PHP extension dependencies
92 * @type array $php_functions PHP function dependencies
93 * @type array $php_settings PHP settings dependencies
94 * }
95 * }
96 */
97 public function __construct( $id, $version, $args = array() ) {
98
99 // required params
100 $this->id = $id;
101 $this->version = $version;
102
103 $args = wp_parse_args(
104 $args,
105 array(
106 'text_domain' => '',
107 'dependencies' => array(),
108 )
109 );
110
111 $this->text_domain = $args['text_domain'];
112
113 // includes that are required to be available at all times
114 $this->includes();
115
116 // initialize the dependencies manager
117 $this->init_dependencies( $args['dependencies'] );
118
119 // build the admin message handler instance
120 $this->init_admin_message_handler();
121
122 // build the admin notice handler instance
123 $this->init_admin_notice_handler();
124
125 // build the lifecycle handler instance
126 $this->init_lifecycle_handler();
127
128 // add the action & filter hooks
129 $this->add_hooks();
130 }
131
132
133 /** Init methods **********************************************************/
134
135
136 /**
137 * Initializes the plugin dependency handler.
138 *
139 * @since 3.0.0
140 *
141 * @param array $dependencies {
142 * PHP extension, function, and settings dependencies
143 *
144 * @type array $php_extensions PHP extension dependencies
145 * @type array $php_functions PHP function dependencies
146 * @type array $php_settings PHP settings dependencies
147 * }
148 */
149 protected function init_dependencies( $dependencies ) {
150
151 $this->dependency_handler = new Plugin_Dependencies( $this, $dependencies );
152 }
153
154
155 /**
156 * Builds the admin message handler instance.
157 *
158 * Plugins can override this with their own handler.
159 *
160 * @since 3.0.0
161 */
162 protected function init_admin_message_handler() {
163
164 $this->message_handler = new Admin_Message_Handler( 'square' );
165 }
166
167
168 /**
169 * Builds the admin notice handler instance.
170 *
171 * Plugins can override this with their own handler.
172 *
173 * @since 3.0.0
174 */
175 protected function init_admin_notice_handler() {
176
177 $this->admin_notice_handler = new Admin_Notice_Handler( $this );
178 }
179
180 /**
181 * Builds the lifecycle handler instance.
182 *
183 * Plugins can override this with their own handler to perform install and
184 * upgrade routines.
185 *
186 * @since 3.0.0
187 */
188 protected function init_lifecycle_handler() {
189
190 $this->lifecycle_handler = new Lifecycle( $this );
191 }
192
193 /**
194 * Adds the action & filter hooks.
195 *
196 * @since 3.0.0
197 */
198 private function add_hooks() {
199
200 // initialize the plugin
201 add_action( 'plugins_loaded', array( $this, 'init_plugin' ), 15 );
202
203 // initialize the plugin admin
204 add_action( 'admin_init', array( $this, 'init_admin' ), 0 );
205 add_action( 'admin_footer', array( $this, 'add_delayed_admin_notices' ) );
206
207 // add a 'Configure' link to the plugin action links
208 add_filter( 'plugin_action_links_' . plugin_basename( $this->get_plugin_file() ), array( $this, 'plugin_action_links' ) );
209
210 // automatically log HTTP requests from Base
211 $this->add_api_request_logging();
212
213 // add any PHP incompatibilities to the system status report
214 add_filter( 'woocommerce_system_status_environment_rows', array( $this, 'add_system_status_php_information' ) );
215 }
216
217
218 /**
219 * Cloning instances is forbidden due to singleton pattern.
220 *
221 * @since 3.0.0
222 */
223 public function __clone() {
224 /* translators: Placeholders: %s - plugin name */
225 _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'You cannot clone instances of %s.', 'woocommerce-square' ), esc_html( $this->get_plugin_name() ) ), '3.1.0' );
226 }
227
228
229 /**
230 * Unserializing instances is forbidden due to singleton pattern.
231 *
232 * @since 3.0.0
233 */
234 public function __wakeup() {
235 /* translators: Placeholders: %s - plugin name */
236 _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'You cannot unserialize instances of %s.', 'woocommerce-square' ), esc_html( $this->get_plugin_name() ) ), '3.1.0' );
237 }
238
239 /**
240 * Include any critical files which must be available as early as possible,
241 *
242 * @since 3.0.0
243 */
244 private function includes() {
245
246 $framework_path = $this->get_framework_path();
247
248 // addresses
249 require_once $framework_path . '/Addresses/Address.php';
250 require_once $framework_path . '/Addresses/Customer_Address.php';
251
252 // common utility methods
253 require_once $framework_path . '/Square_Helper.php';
254
255 // backwards compatibility for older WC versions
256 require_once $framework_path . '/Plugin_Compatibility.php';
257 require_once $framework_path . '/Compatibility/Data_Compatibility.php';
258 require_once $framework_path . '/Compatibility/Order_Compatibility.php';
259
260 // generic API base
261 require_once $framework_path . '/Api/Base.php';
262 require_once $framework_path . '/Api/API_Request.php';
263 require_once $framework_path . '/Api/API_Response.php';
264
265 // JSON API base
266 require_once $framework_path . '/Api/API_JSON_Request.php';
267 require_once $framework_path . '/Api/API_JSON_Response.php';
268
269 // Handlers
270 require_once $framework_path . '/Plugin_Dependencies.php';
271 require_once $framework_path . '/Admin_Message_Handler.php';
272 require_once $framework_path . '/Admin_Notice_Handler.php';
273 require_once $framework_path . '/Lifecycle.php';
274 }
275
276 /**
277 * Returns true if on the admin plugin settings page, if any
278 *
279 * @since 3.0.0
280 * @return boolean true if on the admin plugin settings page
281 */
282 public function is_plugin_settings() {
283 // optional method, not all plugins *have* a settings page
284 return false;
285 }
286
287 /**
288 * Return the plugin action links. This will only be called if the plugin
289 * is active.
290 *
291 * @since 3.0.0
292 * @param array $actions associative array of action names to anchor tags
293 * @return array associative array of plugin action links
294 */
295 public function plugin_action_links( $actions ) {
296
297 $custom_actions = array();
298
299 // settings url(s)
300 if ( $this->get_square_onboarding_link() && wc_square()->get_dependency_handler()->meets_php_dependencies() ) {
301 $custom_actions['setup-wizard'] = $this->get_square_onboarding_link();
302 }
303
304 // documentation url if any
305 if ( $this->get_documentation_url() ) {
306 /* translators: Docs as in Documentation */
307 $custom_actions['docs'] = sprintf( '<a href="%s" target="_blank">%s</a>', $this->get_documentation_url(), esc_html__( 'Docs', 'woocommerce-square' ) );
308 }
309
310 // support url if any
311 if ( $this->get_support_url() ) {
312 $custom_actions['support'] = sprintf( '<a href="%s">%s</a>', $this->get_support_url(), esc_html_x( 'Support', 'noun', 'woocommerce-square' ) );
313 }
314
315 // review url if any
316 if ( $this->get_reviews_url() ) {
317 $custom_actions['review'] = sprintf( '<a href="%s">%s</a>', $this->get_reviews_url(), esc_html_x( 'Review', 'verb', 'woocommerce-square' ) );
318 }
319
320 // add the links to the front of the actions list
321 return array_merge( $custom_actions, $actions );
322 }
323
324 /**
325 * Automatically log API requests/responses when using Base
326 *
327 * @since 3.0.0
328 * @see Base::broadcast_request()
329 */
330 public function add_api_request_logging() {
331
332 if ( ! has_action( 'wc_square_api_request_performed' ) ) {
333 add_action( 'wc_square_api_request_performed', array( $this, 'log_api_request' ), 10, 2 );
334 }
335 }
336
337
338 /**
339 * Log API requests/responses
340 *
341 * @since 3.0.0
342 * @param array $request request data, see Base::broadcast_request() for format
343 * @param array $response response data
344 * @param string|null $log_id log to write data to
345 */
346 public function log_api_request( $request, $response, $log_id = null ) {
347
348 $this->log( sprintf( "Request\n %s", $this->get_api_log_message( $request ) ), $log_id );
349
350 if ( ! empty( $response ) ) {
351 $this->log( sprintf( "Response\n %s", $this->get_api_log_message( $response ) ), $log_id );
352 }
353 }
354
355
356 /**
357 * Transform the API request/response data into a string suitable for logging
358 *
359 * @since 3.0.0
360 * @param array $data
361 * @return string
362 */
363 public function get_api_log_message( $data ) {
364
365 $messages = array();
366
367 $messages[] = isset( $data['uri'] ) && $data['uri'] ? 'Request' : 'Response';
368
369 foreach ( (array) $data as $key => $value ) {
370 // print_r here is necessary to dump request / response data for logging purposes.
371 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
372 $messages[] = trim( sprintf( '%s: %s', $key, is_array( $value ) || ( is_object( $value ) && 'stdClass' === get_class( $value ) ) ? print_r( (array) $value, true ) : $value ) );
373 }
374
375 return implode( "\n", $messages ) . "\n";
376 }
377
378
379 /**
380 * Adds any PHP incompatibilities to the system status report.
381 *
382 * @since 3.0.0
383 *
384 * @param array $rows WooCommerce system status rows
385 * @return array
386 */
387 public function add_system_status_php_information( $rows ) {
388
389 foreach ( $this->get_dependency_handler()->get_incompatible_php_settings() as $setting => $values ) {
390
391 if ( isset( $values['type'] ) && 'min' === $values['type'] ) {
392
393 // if this setting already has a higher minimum from another plugin, skip it
394 if ( isset( $rows[ $setting ]['expected'] ) && $values['expected'] < $rows[ $setting ]['expected'] ) {
395 continue;
396 }
397
398 /* translators: Placeholders: %1$s = Current PHP setting value, %2$s = Minimum required PHP setting value */
399 $note = __( '%1$s - A minimum of %2$s is required.', 'woocommerce-square' );
400
401 } else {
402
403 // if this requirement is already listed, skip it
404 if ( isset( $rows[ $setting ] ) ) {
405 continue;
406 }
407
408 /* translators: Placeholders: %1$s = Current PHP setting value set as, %2$s = Minimum required PHP setting value */
409 $note = __( 'Set as %1$s - %2$s is required.', 'woocommerce-square' );
410 }
411
412 $note = sprintf( $note, esc_html( $values['actual'] ), esc_html( $values['expected'] ) );
413
414 $rows[ $setting ] = array(
415 'name' => $setting,
416 'note' => $note,
417 'success' => false,
418 'expected' => $values['expected'], // WC doesn't use this, but it's useful for us
419 );
420 }
421
422 return $rows;
423 }
424
425
426 /**
427 * Saves errors or messages to WooCommerce Log (woocommerce/logs/plugin-id-xxx.txt)
428 *
429 * @since 3.0.0
430 * @param string $message error or message to save to log
431 * @param string $log_id optional log id to segment the files by, defaults to plugin id
432 */
433 public function log( $message, $log_id = null ) {
434
435 if ( is_null( $log_id ) ) {
436 $log_id = 'square';
437 }
438
439 if ( ! is_object( $this->logger ) ) {
440 $this->logger = new \WC_Logger();
441 }
442
443 $this->logger->add( $log_id, $message );
444 }
445
446 /**
447 * Gets the main plugin file.
448 *
449 * @since 3.0.0
450 *
451 * @return string
452 */
453 public function get_plugin_file() {
454
455 $slug = dirname( plugin_basename( $this->get_file() ) );
456
457 return trailingslashit( $slug ) . $slug . '.php';
458 }
459
460
461 /**
462 * The implementation for this abstract method should simply be:
463 *
464 * return __FILE__;
465 *
466 * @since 3.0.0
467 * @return string the full path and filename of the plugin file
468 */
469 abstract protected function get_file();
470
471
472 /**
473 * Returns the plugin id
474 *
475 * @since 3.0.0
476 * @return string plugin id
477 */
478 public function get_id() {
479 return $this->id;
480 }
481
482
483 /**
484 * Returns the plugin id with dashes in place of underscores, and
485 * appropriate for use in frontend element names, classes and ids
486 *
487 * @since 3.0.0
488 * @return string plugin id with dashes in place of underscores
489 */
490 public function get_id_dasherized() {
491 return str_replace( '_', '-', 'square' );
492 }
493
494
495 /**
496 * Returns the plugin full name including "WooCommerce", ie
497 * "WooCommerce X". This method is defined abstract for localization purposes
498 *
499 * @since 3.0.0
500 * @return string plugin name
501 */
502 abstract public function get_plugin_name();
503
504 /**
505 * Gets the dependency handler.
506 *
507 * @since 3.0.0
508 *
509 * @return Plugin_Dependencies
510 */
511 public function get_dependency_handler() {
512
513 return $this->dependency_handler;
514 }
515
516
517 /**
518 * Gets the lifecycle handler instance.
519 *
520 * @since 3.0.0
521 *
522 * @return Plugin\Lifecycle
523 */
524 public function get_lifecycle_handler() {
525
526 return $this->lifecycle_handler;
527 }
528
529 /**
530 * Gets the admin message handler.
531 *
532 * @since 3.0.0
533 *
534 * @return Admin_Message_Handler
535 */
536 public function get_message_handler() {
537
538 return $this->message_handler;
539 }
540
541
542 /**
543 * Gets the admin notice handler instance.
544 *
545 * @since 3.0.0
546 *
547 * @return Admin_Notice_Handler
548 */
549 public function get_admin_notice_handler() {
550
551 return $this->admin_notice_handler;
552 }
553
554
555 /**
556 * Returns the plugin version name. Defaults to wc_{plugin id}_version
557 *
558 * @since 3.0.0
559 * @return string the plugin version name
560 */
561 public function get_plugin_version_name() {
562
563 return 'wc_square_version';
564 }
565
566
567 /**
568 * Returns the current version of the plugin
569 *
570 * @since 3.0.0
571 * @return string plugin version
572 */
573 public function get_version() {
574 return $this->version;
575 }
576
577
578 /**
579 * Returns the "Configure" plugin action link to go directly to the plugin
580 * settings page (if any)
581 *
582 * @since 3.0.0
583 * @see Plugin::get_settings_url()
584 * @param string $plugin_id optional plugin identifier. Note that this can be a
585 * sub-identifier for plugins with multiple parallel settings pages
586 * (ie a gateway that supports credit cards)
587 * @return string plugin configure link
588 */
589 public function get_settings_link( $plugin_id = null ) {
590
591 $settings_url = $this->get_settings_url( $plugin_id );
592
593 if ( $settings_url ) {
594 return sprintf( '<a href="%s">%s</a>', esc_url( $settings_url ), esc_html__( 'Configure', 'woocommerce-square' ) );
595 }
596
597 // no settings
598 return '';
599 }
600
601 /**
602 * Returns the "Configure" plugin action link to go directly to the plugin
603 * settings page (if any)
604 *
605 * @since 4.7.0
606 * @see Plugin::get_settings_url()
607 * @param string $step optional step identifier.
608 *
609 * @return string plugin configure link
610 */
611 public function get_square_onboarding_link( $step = '' ) {
612
613 $square_onboarding_url = $this->get_square_onboarding_url( $step );
614
615 if ( $square_onboarding_url ) {
616 return sprintf( '<a href="%s">%s</a>', esc_url( $square_onboarding_url ), esc_html__( 'Setup Wizard', 'woocommerce-square' ) );
617 }
618
619 // no settings
620 return '';
621 }
622
623
624 /**
625 * Gets the plugin configuration URL
626 *
627 * @since 4.7.0
628 * @see Plugin::get_settings_link()
629 * @return string plugin settings URL
630 */
631 public function get_square_onboarding_url() {
632
633 // stub method
634 return '';
635 }
636
637 /**
638 * Gets the plugin configuration URL
639 *
640 * @since 3.0.0
641 * @see Plugin::get_settings_link()
642 * @param string $plugin_id optional plugin identifier. Note that this can be a
643 * sub-identifier for plugins with multiple parallel settings pages
644 * (ie a gateway that supports credit cards)
645 * @return string plugin settings URL
646 */
647 public function get_settings_url( $plugin_id = null ) {
648
649 // stub method
650 return '';
651 }
652
653 /**
654 * Returns the admin configuration url for the admin general configuration page
655 *
656 * @since 3.0.0
657 * @return string admin configuration url for the admin general configuration page
658 */
659 public function get_general_configuration_url() {
660
661 return admin_url( 'admin.php?page=wc-settings&tab=general' );
662 }
663
664
665 /**
666 * Gets the plugin documentation url, used for the 'Docs' plugin action
667 *
668 * @since 3.0.0
669 * @return string documentation URL
670 */
671 public function get_documentation_url() {
672
673 return null;
674 }
675
676
677 /**
678 * Gets the support URL, used for the 'Support' plugin action link
679 *
680 * @since 3.0.0
681 * @return string support url
682 */
683 public function get_support_url() {
684
685 return null;
686 }
687
688
689 /**
690 * Gets the plugin sales page URL.
691 *
692 * @since 3.0.0
693 *
694 * @return string
695 */
696 public function get_sales_page_url() {
697
698 return '';
699 }
700
701
702 /**
703 * Gets the plugin reviews page URL.
704 *
705 * Used for the 'Reviews' plugin action and review prompts.
706 *
707 * @since 3.0.0
708 *
709 * @return string
710 */
711 public function get_reviews_url() {
712
713 return $this->get_sales_page_url() ? $this->get_sales_page_url() . '#comments' : '';
714 }
715
716
717 /**
718 * Returns the plugin's path without a trailing slash, i.e.
719 * /path/to/wp-content/plugins/plugin-directory
720 *
721 * @since 3.0.0
722 * @return string the plugin path
723 */
724 public function get_plugin_path() {
725
726 if ( $this->plugin_path ) {
727 return $this->plugin_path;
728 }
729
730 return $this->plugin_path = untrailingslashit( plugin_dir_path( $this->get_file() ) );
731 }
732
733
734 /**
735 * Returns the plugin's url without a trailing slash, i.e.
736 *
737 * @since 3.0.0
738 * @return string the plugin URL
739 */
740 public function get_plugin_url() {
741
742 if ( $this->plugin_url ) {
743 return $this->plugin_url;
744 }
745
746 return $this->plugin_url = untrailingslashit( plugins_url( '/', $this->get_file() ) );
747 }
748
749 /**
750 * Returns the loaded framework __FILE__
751 *
752 * @since 3.0.0
753 * @return string
754 */
755 public function get_framework_file() {
756
757 return __FILE__;
758 }
759
760
761 /**
762 * Returns the loaded framework path, without trailing slash. Ths is the highest
763 * version framework that was loaded by the bootstrap.
764 *
765 * @since 3.0.0
766 * @return string
767 */
768 public function get_framework_path() {
769
770 return untrailingslashit( plugin_dir_path( $this->get_framework_file() ) );
771 }
772
773 /**
774 * Returns the loaded framework assets URL without a trailing slash
775 *
776 * @since 3.0.0
777 * @return string
778 */
779 public function get_framework_assets_url() {
780
781 return untrailingslashit( plugins_url( '/assets', $this->get_framework_file() ) );
782 }
783
784
785 /**
786 * Helper function to determine whether a plugin is active
787 *
788 * @since 3.0.0
789 * @param string $plugin_name plugin name, as the plugin-filename.php
790 * @return boolean true if the named plugin is installed and active
791 */
792 public function is_plugin_active( $plugin_name ) {
793
794 $active_plugins = (array) get_option( 'active_plugins', array() );
795
796 if ( is_multisite() ) {
797 $active_plugins = array_merge( $active_plugins, array_keys( get_site_option( 'active_sitewide_plugins', array() ) ) );
798 }
799
800 $plugin_filenames = array();
801
802 foreach ( $active_plugins as $plugin ) {
803
804 if ( Square_Helper::str_exists( $plugin, '/' ) ) {
805
806 // normal plugin name (plugin-dir/plugin-filename.php)
807 list( , $filename ) = explode( '/', $plugin );
808
809 } else {
810
811 // no directory, just plugin file
812 $filename = $plugin;
813 }
814
815 $plugin_filenames[] = $filename;
816 }
817
818 return in_array( $plugin_name, $plugin_filenames, true );
819 }
820 }
821