is_environment_compatible() ) { add_action( 'plugins_loaded', array( $this, 'init_plugin' ) ); } if ( ! self::is_wp_com() ) { add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'compat_capture_entry' ), 11 ); add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'compat_verify_entry' ), PHP_INT_MAX ); } } /** * Cloning instances is forbidden due to singleton pattern. * * @since 1.10.0 */ public function __clone() { wc_doing_it_wrong( __FUNCTION__, sprintf( 'You cannot clone instances of %s.', get_class( $this ) ), '1.10.0' ); } /** * Unserializing instances is forbidden due to singleton pattern. * * @since 1.10.0 */ public function __wakeup() { wc_doing_it_wrong( __FUNCTION__, sprintf( 'You cannot unserialize instances of %s.', get_class( $this ) ), '1.10.0' ); } /** * Initializes the plugin. * * @since 1.10.0 */ public function init_plugin() { if ( ! Checker::instance()->is_compatible( __FILE__, self::PLUGIN_VERSION ) ) { return; } self::set_wc_facebook_svr_flags(); require_once plugin_dir_path( __FILE__ ) . 'class-wc-facebookcommerce.php'; // fire it up! if ( function_exists( 'facebook_for_woocommerce' ) ) { facebook_for_woocommerce(); } } /** * Gets the framework version in namespace form. * * @since 1.10.0 * * @return string */ public function get_framework_version_namespace() { return 'v' . str_replace( '.', '_', $this->get_framework_version() ); } /** * Gets the framework version used by this plugin. * * @since 1.10.0 * * @return string */ public function get_framework_version() { return self::FRAMEWORK_VERSION; } /** * Checks the server environment and other factors and deactivates plugins as necessary. * * Based on http://wptavern.com/how-to-prevent-wordpress-plugins-from-activating-on-sites-with-incompatible-hosting-environments * * @internal * * @since 1.10.0 */ public function activation_check() { if ( ! $this->is_environment_compatible() ) { $this->deactivate_plugin(); wp_die( esc_html( self::PLUGIN_NAME . ' could not be activated. ' . $this->get_environment_message() ) ); } // Flag that rewrite rules need to be flushed on next init. update_option( 'facebook_for_woocommerce_flush_rewrite_rules', 'yes' ); } /** * Handles plugin deactivation cleanup. * * Flushes rewrite rules to remove custom endpoints like /fbcollection/. * * @internal * * @since 3.5.0 */ public function deactivation_cleanup() { flush_rewrite_rules(); delete_option( 'facebook_for_woocommerce_rewrite_version' ); self::$compat_cached_entry = null; } /** * Flush rewrite rules if the flag is set. * * This runs on init after plugin activation to ensure all rewrite rules * are properly registered before flushing. * * @internal * * @since 3.5.0 */ public function maybe_flush_rewrite_rules() { $stored_version = get_option( 'facebook_for_woocommerce_rewrite_version' ); // Flush if activation flag is set OR if plugin version has changed (plugin upgrade). $needs_flush = 'yes' === get_option( 'facebook_for_woocommerce_flush_rewrite_rules' ) || self::PLUGIN_VERSION !== $stored_version; if ( $needs_flush ) { flush_rewrite_rules(); delete_option( 'facebook_for_woocommerce_flush_rewrite_rules' ); update_option( 'facebook_for_woocommerce_rewrite_version', self::PLUGIN_VERSION ); } } /** * Checks the environment on loading WordPress, just in case the environment changes after activation. * * @internal * * @since 1.10.0 */ public function check_environment() { if ( ! $this->is_environment_compatible() && is_plugin_active( plugin_basename( __FILE__ ) ) ) { $this->deactivate_plugin(); $this->add_admin_notice( 'bad_environment', 'error', self::PLUGIN_NAME . ' has been deactivated. ' . $this->get_environment_message() ); } } /** * Deactivates the plugin. * * @internal * * @since 1.10.0 */ protected function deactivate_plugin() { deactivate_plugins( plugin_basename( __FILE__ ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['activate'] ) ) { unset( $_GET['activate'] ); } } /** * Adds an admin notice to be displayed. * * @since 1.10.0 * * @param string $slug The slug for the notice. * @param string $class The css class for the notice. * @param string $message The notice message. */ // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.classFound private function add_admin_notice( $slug, $class, $message ) { $this->notices[ $slug ] = array( 'class' => $class, 'message' => $message, ); } /** * Displays any admin notices added with \WC_Facebook_Loader::add_admin_notice() * * @internal * * @since 1.10.0 */ public function admin_notices() { foreach ( (array) $this->notices as $notice_key => $notice ) { ?>
array( 'href' => array(), ), 'strong' => array(), ) ); ?>