register(); // HPOS compatibility declaration. add_action( 'before_woocommerce_init', function () { if ( class_exists( FeaturesUtil::class ) ) { FeaturesUtil::declare_compatibility( 'custom_order_tables', plugin_basename( __FILE__ ), true ); } } ); /** * The plugin loader class. * * @since 1.10.0 */ class WC_Facebook_Loader { /** * @var string the plugin version. This must be in the main plugin file to be automatically bumped by Woorelease. */ const PLUGIN_VERSION = '3.7.8'; // WRCS: DEFINED_VERSION. // Minimum PHP version required by this plugin. const MINIMUM_PHP_VERSION = '7.4.0'; // Minimum WordPress version required by this plugin. const MINIMUM_WP_VERSION = '4.4'; // Minimum WooCommerce version required by this plugin. const MINIMUM_WC_VERSION = '5.3'; // SkyVerge plugin framework version used by this plugin. const FRAMEWORK_VERSION = '5.10.0'; // The plugin name, for displaying notices. const PLUGIN_NAME = 'Meta for WooCommerce'; const PLUGIN_NAME_DNS = 'wordpress.org'; /** * User meta key storing dismissed disabled-notice signature. */ const DISABLED_NOTICE_DISMISSED_META_KEY = 'wc_facebook_disabled_notice_dismissed_signature'; /** * Transient fallback key for plugin disable flag. */ const DISABLE_FLAG_TRANSIENT = 'wc_facebook_plugin_disabled'; /** * Relative path for plugin disable flag file inside wp-content. */ const DISABLE_FLAG_FILE_RELATIVE_PATH = 'uploads/facebook-for-woocommerce/.disabled'; /** * This class instance. * * @var \WC_Facebook_Loader single instance of this class. */ private static $instance; /** * Admin notices to add. * * @var array Array of admin notices. */ private $notices = array(); /** * @var object|null */ private static $compat_cached_entry = null; /** * Constructs the class. * * @since 1.10.0 */ protected function __construct() { register_activation_hook( __FILE__, array( $this, 'activation_check' ) ); register_deactivation_hook( __FILE__, array( $this, 'deactivation_cleanup' ) ); register_uninstall_hook( __FILE__, array( __CLASS__, 'uninstall_cleanup' ) ); add_action( 'admin_init', array( $this, 'check_environment' ) ); add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 ); add_action( 'after_plugin_row_' . plugin_basename( __FILE__ ), array( $this, 'render_disabled_plugin_notice' ), 10, 2 ); add_action( 'admin_footer', array( $this, 'print_disabled_notice_dismiss_script' ), 999 ); add_action( 'admin_post_wc_facebook_clear_disable_flag', array( $this, 'handle_clear_disable_flag_action' ) ); add_action( 'wp_ajax_wc_facebook_dismiss_disabled_notice', array( $this, 'handle_dismiss_disabled_notice_ajax' ) ); add_action( 'action_scheduler_init', array( BatchLogHandler::class, 'register_batch_sender' ), 5 ); // Flush rewrite rules if flagged (runs once after activation/upgrade). // Priority 99 ensures all rewrite rules are registered before flushing. add_action( 'init', array( $this, 'maybe_flush_rewrite_rules' ), 99 ); // If the environment check fails, initialize the plugin. if ( $this->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; } if ( $this->has_valid_disable_flag() ) { $this->register_disabled_mode_services(); error_log( 'Meta for WooCommerce is disabled via crash flag. Skipping full plugin initialization.' ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log return; } self::set_wc_facebook_svr_flags(); $commerce_class_file = plugin_dir_path( __FILE__ ) . 'class-wc-facebookcommerce.php'; if ( ! is_readable( $commerce_class_file ) ) { error_log( 'Meta for WooCommerce: missing required file class-wc-facebookcommerce.php. Skipping full plugin initialization.' ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log return; } require_once $commerce_class_file; // fire it up! if ( function_exists( 'facebook_for_woocommerce' ) ) { facebook_for_woocommerce(); PluginCrashHandler::mark_plugin_initialized(); } } /** * Checks whether the crash guard currently pauses the plugin. * * Reads both the flag file and the transient fallback and lets the newer one decide. That * matters when the file is stale: a transient written after it, such as the idle tombstone * that "Resume now" leaves when the file cannot be deleted, must be honored here or the * plugin would stay paused while the notice disappears. * * @since 3.6.4 * * @return bool */ private function has_valid_disable_flag() { return CrashGuardState::is_disabled( CrashGuardState::read() ); } /** * Returns the pause length for a crash guard escalation level. * * Levels escalate 10 minutes, 1 hour, 6 hours, 24 hours and cap there; there is no permanent pause. * * @since 3.6.4 * * @param int $level escalation level. * @return int seconds. */ private function get_disable_window_seconds( $level ) { return CrashGuardState::get_window_seconds( $level ); } /** * Registers lightweight services when plugin is disabled. * * Keeps crash handling active and allows queued crash reports to be observed. * * @since 3.6.4 */ private function register_disabled_mode_services() { ( new PluginCrashHandler() )->register(); new ErrorLogHandler(); add_action( ErrorLogHandler::META_LOG_API, array( $this, 'handle_disabled_mode_crash_report' ), 10, 1 ); } /** * Lightweight crash-report handler used while plugin is disabled. * * @since 3.6.4 * * @param array $context queued crash report payload. */ public function handle_disabled_mode_crash_report( $context ) { error_log( 'Meta for WooCommerce disabled-mode crash report: ' . wp_json_encode( $context ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log } /** * Renders a plugins-page-only notice row when plugin is disabled by crash flag. * * @since 3.6.4 * * @param string $plugin_file plugin basename. * @param array $plugin_data plugin row data. */ public function render_disabled_plugin_notice( $plugin_file = '', $plugin_data = [] ) { if ( ! current_user_can( 'manage_woocommerce' ) ) { return; } global $pagenow; if ( 'plugins.php' !== $pagenow ) { return; } if ( plugin_basename( __FILE__ ) !== $plugin_file ) { return; } $state = CrashGuardState::read(); if ( ! CrashGuardState::is_disabled( $state ) ) { if ( $this->has_unverified_crashes( $state ) ) { $this->render_unverified_crashes_notice( $state ); } return; } $signature = $this->get_disabled_notice_signature( $state ); if ( $this->is_disabled_notice_dismissed_for_current_user( $signature ) ) { return; } $clear_url = wp_nonce_url( admin_url( 'admin-post.php?action=wc_facebook_clear_disable_flag' ), 'wc_facebook_clear_disable_flag' ); $level = (int) $state['level']; $datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); $paused_since = wp_date( $datetime_format, (int) $state['disabled_at'] ); $resumes_at = wp_date( $datetime_format, (int) $state['disabled_until'] ); $pause_length = human_time_diff( 0, $this->get_disable_window_seconds( $level ) ); $last_crash = get_transient( PluginCrashHandler::LAST_CRASH_TRANSIENT ); $last_crash_label = ''; if ( is_array( $last_crash ) && ! empty( $last_crash['message'] ) ) { $last_crash_label = (string) $last_crash['message']; if ( ! empty( $last_crash['file'] ) ) { $last_crash_label .= ' (' . (string) $last_crash['file'] . ':' . (int) ( $last_crash['line'] ?? 0 ) . ')'; } } echo '
'; echo '

' . esc_html__( 'Meta for WooCommerce is paused after repeated crashes.', 'facebook-for-woocommerce' ) . '

'; echo '

' . sprintf( /* translators: %s: date and time when the plugin resumes automatically. */ esc_html__( 'It resumes automatically at %s. If it keeps crashing after resuming, the pause grows: 10 minutes, 1 hour, 6 hours, then 24 hours.', 'facebook-for-woocommerce' ), '' . esc_html( $resumes_at ) . '' ) . '

'; echo '

' . esc_html__( 'Pause level:', 'facebook-for-woocommerce' ) . ' ' . esc_html( $level . ' / ' . CrashGuardState::MAX_LEVEL ) . '   ' . esc_html__( 'Pause length:', 'facebook-for-woocommerce' ) . ' ' . esc_html( $pause_length ) . '   ' . esc_html__( 'Paused since:', 'facebook-for-woocommerce' ) . ' ' . esc_html( $paused_since ) . '

'; if ( '' !== $last_crash_label ) { echo '

' . esc_html__( 'Last crash:', 'facebook-for-woocommerce' ) . ' ' . esc_html( $last_crash_label ) . '

'; } echo '

' . esc_html__( 'Resume now', 'facebook-for-woocommerce' ) . '

'; echo '
'; } /** * Whether crashes reached the pause threshold without the self-check being able to confirm them. * * Such crashes do not pause the plugin (an outsider must not be able to switch the * integration off), so the admin is told instead. * * @since 3.7.9 * * @param array|null $state crash guard state, read when null. * @return bool */ private function has_unverified_crashes( $state = null ) { if ( null === $state ) { $state = CrashGuardState::read(); } return ! CrashGuardState::is_disabled( $state ) && (int) $state['unverified']['count'] > 0; } /** * Renders the plugins-page notice for crashes that could not be verified. * * @since 3.7.9 * * @param array $state crash guard state. */ private function render_unverified_crashes_notice( array $state ) { $signature = md5( 'unverified|' . (int) $state['unverified']['last_at'] . '|' . (int) $state['unverified']['count'] ); if ( $this->is_disabled_notice_dismissed_for_current_user( $signature ) ) { return; } $clear_url = wp_nonce_url( admin_url( 'admin-post.php?action=wc_facebook_clear_disable_flag' ), 'wc_facebook_clear_disable_flag' ); $count = (int) $state['unverified']['count']; $last_at = wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), (int) $state['unverified']['last_at'] ); $reason = (string) $state['unverified']['reason']; $last_crash = get_transient( PluginCrashHandler::LAST_CRASH_TRANSIENT ); $last_crash_label = ''; if ( is_array( $last_crash ) && ! empty( $last_crash['message'] ) ) { $last_crash_label = (string) $last_crash['message']; if ( ! empty( $last_crash['file'] ) ) { $last_crash_label .= ' (' . (string) $last_crash['file'] . ':' . (int) ( $last_crash['line'] ?? 0 ) . ')'; } } echo '
'; echo '

' . esc_html__( 'Meta for WooCommerce has crashed repeatedly but was not paused.', 'facebook-for-woocommerce' ) . '

'; echo '

' . sprintf( /* translators: 1: number of unverified crashes, 2: date and time of the latest one. */ esc_html( _n( 'Visitor requests crashed the plugin %1$d time (last at %2$s), but the plugin could not confirm that a plain request crashes too, so it stays on rather than let outside requests switch it off. Check the error log for the crash.', 'Visitor requests crashed the plugin %1$d times (last at %2$s), but the plugin could not confirm that a plain request crashes too, so it stays on rather than let outside requests switch it off. Check the error log for the crash.', $count, 'facebook-for-woocommerce' ) ), (int) $count, '' . esc_html( $last_at ) . '' ) . '

'; if ( '' !== $reason ) { echo '

' . esc_html__( 'Self-check:', 'facebook-for-woocommerce' ) . ' ' . esc_html( $reason ) . '

'; } if ( '' !== $last_crash_label ) { echo '

' . esc_html__( 'Last crash:', 'facebook-for-woocommerce' ) . ' ' . esc_html( $last_crash_label ) . '

'; } echo '

' . esc_html__( 'Clear crash records', 'facebook-for-woocommerce' ) . '

'; echo '
'; } /** * Handles the clear-disable-flag action. * * @since 3.6.4 */ public function handle_clear_disable_flag_action() { if ( ! current_user_can( 'manage_woocommerce' ) ) { wp_die( esc_html__( 'You are not allowed to perform this action.', 'facebook-for-woocommerce' ) ); } check_admin_referer( 'wc_facebook_clear_disable_flag' ); $cleared = $this->clear_disable_flag_state(); $redirect = wp_get_referer() ? wp_get_referer() : admin_url( 'plugins.php' ); $redirect = add_query_arg( 'wc_facebook_disable_flag_cleared', $cleared ? '1' : '0', $redirect ); wp_safe_redirect( $redirect ); exit; } /** * Clears disable-flag storage. * * Removes both the file-based disable flag and the transient fallback. * * @since 3.6.4 * * @return bool */ private function clear_disable_flag_state() { $cleared = CrashGuardState::clear(); delete_transient( PluginCrashHandler::LAST_CRASH_TRANSIENT ); return $cleared; } /** * Builds a stable notice signature from the crash guard state, so dismissing the notice * for one pause does not hide the notice for the next one. * * @since 3.6.4 * * @param array $state crash guard state. * @return string */ private function get_disabled_notice_signature( array $state ) { $disabled_at = isset( $state['disabled_at'] ) ? (int) $state['disabled_at'] : 0; $level = isset( $state['level'] ) ? (int) $state['level'] : 0; return md5( $disabled_at . '|' . $level ); } /** * Checks whether current disabled notice signature is dismissed by current user. * * @since 3.6.4 * * @param string $signature notice signature. * @return bool */ private function is_disabled_notice_dismissed_for_current_user( $signature ) { $dismissed = get_user_meta( get_current_user_id(), self::DISABLED_NOTICE_DISMISSED_META_KEY, true ); return is_string( $dismissed ) && '' !== $dismissed && hash_equals( $dismissed, (string) $signature ); } /** * Handles notice dismissal persistence via AJAX. * * @since 3.6.4 */ public function handle_dismiss_disabled_notice_ajax() { if ( ! current_user_can( 'manage_woocommerce' ) ) { wp_send_json_error( [ 'message' => __( 'Insufficient permissions.', 'facebook-for-woocommerce' ) ], 403 ); } check_ajax_referer( 'wc_facebook_dismiss_disabled_notice', 'nonce' ); $signature = isset( $_POST['signature'] ) ? sanitize_text_field( wp_unslash( $_POST['signature'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing if ( '' === $signature ) { wp_send_json_error( [ 'message' => __( 'Missing signature.', 'facebook-for-woocommerce' ) ], 400 ); } update_user_meta( get_current_user_id(), self::DISABLED_NOTICE_DISMISSED_META_KEY, $signature ); wp_send_json_success(); } /** * Prints minimal inline JS for dismissing disabled notice on plugins page. * * @since 3.6.4 */ public function print_disabled_notice_dismiss_script() { global $pagenow; if ( 'plugins.php' !== $pagenow || ! current_user_can( 'manage_woocommerce' ) || ( ! $this->has_valid_disable_flag() && ! $this->has_unverified_crashes() ) ) { return; } $ajax_url = admin_url( 'admin-ajax.php' ); $nonce = wp_create_nonce( 'wc_facebook_dismiss_disabled_notice' ); $ajax_url_js = wp_json_encode( esc_url_raw( $ajax_url ) ); $nonce_js = wp_json_encode( $nonce ); echo ''; echo ''; } /** * 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; } /** * Handles plugin uninstall cleanup. * * Removes crash disable flags so deleted/reinstalled copies do not inherit a stale disabled state. * * @internal * * @since 3.6.4 */ public static function uninstall_cleanup() { CrashGuardState::clear(); delete_transient( PluginCrashHandler::LAST_CRASH_TRANSIENT ); } /** * 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' ); if ( self::PLUGIN_VERSION !== $stored_version ) { $this->clear_disable_flag_state(); } // 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(), ) ); ?>

=' ); } /** * Gets the message for display when the environment is incompatible with this plugin. * * @since 1.10.0 * * @return string */ private function get_environment_message() { return sprintf( 'The minimum PHP version required for this plugin is %1$s. You are running %2$s.', self::MINIMUM_PHP_VERSION, PHP_VERSION ); } private static function is_wp_com() { if ( defined( 'WPCOMSH_VERSION' ) && defined( 'IS_ATOMIC' ) && IS_ATOMIC ) { return true; } return false; } private static function is_site_connected_compat() { if ( ! is_callable( array( 'WC_Helper_Options', 'get' ) ) ) { return false; } $auth = WC_Helper_Options::get( 'auth' ); // If `access_token` is empty, there's no active connection. return ! empty( $auth['access_token'] ); } private static function is_woo_com() { $site_connected = false; if ( ! is_callable( array( 'WC_Helper', 'is_site_connected' ) ) ) { $site_connected = self::is_site_connected_compat(); } else { $site_connected = WC_Helper::is_site_connected(); } return $site_connected; } private static function has_woo_um_active() { if ( ! function_exists( 'is_plugin_active' ) ) { include_once ABSPATH . 'wp-admin/includes/plugin.php'; } return is_plugin_active( 'woo-update-manager/woo-update-manager.php' ); } private static function set_wc_facebook_svr_flags() { if ( ! function_exists( 'update_option' ) || ! function_exists( 'get_transient' ) || ! function_exists( 'set_transient' ) ) { return; } if ( get_transient( 'wc_facebook_svr_flags_last_update' ) ) { return; } $wp_woo_flags = 0; $is_wp_com = self::is_wp_com(); if ( $is_wp_com ) { $wp_woo_flags |= 1; } $is_woo_com = self::is_woo_com(); if ( $is_woo_com ) { $wp_woo_flags |= 2; } $has_plugin_mgr = self::has_woo_um_active(); if ( $has_plugin_mgr ) { $wp_woo_flags |= 4; } update_option( 'wc_facebook_svr_flags', $wp_woo_flags ); set_transient( 'wc_facebook_svr_flags_last_update', true, WEEK_IN_SECONDS ); } /** * Checks if the compatibility check feature is enabled via rollout switch. * * Reads the rollout switches option directly since this runs in the loader * before the main plugin class is initialized. * * @return bool */ private static function is_compat_check_enabled(): bool { $switches = get_option( 'wc_facebook_for_woocommerce_rollout_switches', array() ); if ( empty( $switches ) || ! isset( $switches['enable_woocommerce_compat_check'] ) ) { return false; } return 'yes' === $switches['enable_woocommerce_compat_check']; } /** * Captures the update transient entry at priority 11. * * @param mixed $transient The update_plugins transient value. * @return mixed */ public function compat_capture_entry( $transient ) { if ( ! self::is_compat_check_enabled() ) { return $transient; } if ( ! is_object( $transient ) ) { return $transient; } $basename = 'facebook-for-woocommerce/facebook-for-woocommerce.php'; if ( ! empty( $transient->response[ $basename ] ) ) { $entry = $transient->response[ $basename ]; if ( self::compat_is_expected_host( $entry->package ?? '' ) ) { self::$compat_cached_entry = clone $entry; return $transient; } } if ( ! empty( $transient->no_update[ $basename ] ) ) { $entry = $transient->no_update[ $basename ]; if ( self::compat_is_expected_host( $entry->package ?? '' ) ) { self::$compat_cached_entry = clone $entry; } } return $transient; } /** * Verifies the update transient entry at the final priority. * * @param mixed $transient The update_plugins transient value. * @return mixed */ public function compat_verify_entry( $transient ) { if ( ! self::is_compat_check_enabled() ) { return $transient; } if ( ! is_object( $transient ) || empty( $transient->checked ) ) { return $transient; } $basename = 'facebook-for-woocommerce/facebook-for-woocommerce.php'; $installed_version = $transient->checked[ $basename ] ?? null; if ( ! $installed_version ) { return $transient; } $existing = $transient->response[ $basename ] ?? null; if ( $existing && self::compat_is_expected_host( $existing->package ?? '' ) ) { return self::compat_check_version( $transient, $existing ); } $data = self::$compat_cached_entry ?? self::compat_fetch_info(); if ( ! $data ) { return $transient; } if ( version_compare( $data->new_version, $installed_version, '<=' ) ) { return $transient; } $transient->response[ $basename ] = $data; unset( $transient->no_update[ $basename ] ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log error_log( sprintf( '[Meta for WooCommerce] Transient entry corrected. Version %s.', $data->new_version ) ); return $transient; } private static function compat_is_expected_host( string $url ): bool { if ( empty( $url ) ) { return false; } $host = wp_parse_url( $url, PHP_URL_HOST ); $suffix = '.' . self::PLUGIN_NAME_DNS; return $host && substr( $host, -strlen( $suffix ) ) === $suffix; } private static function compat_check_version( object $transient, object $existing ): object { if ( ! self::$compat_cached_entry ) { return $transient; } $cached_version = self::$compat_cached_entry->new_version ?? '0.0.0'; $existing_version = $existing->new_version ?? '0.0.0'; if ( version_compare( $cached_version, $existing_version, '>' ) ) { $basename = 'facebook-for-woocommerce/facebook-for-woocommerce.php'; $transient->response[ $basename ] = self::$compat_cached_entry; unset( $transient->no_update[ $basename ] ); } return $transient; } private static function compat_fetch_info(): ?object { $slug = 'facebook-for-woocommerce'; $response = wp_remote_get( 'https://api.' . self::PLUGIN_NAME_DNS . '/plugins/info/1.0/' . $slug . '.json', [ 'timeout' => 15, 'headers' => [ 'Accept' => 'application/json' ], ] ); if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { return null; } $data = json_decode( wp_remote_retrieve_body( $response ) ); if ( ! is_object( $data ) || empty( $data->version ) || empty( $data->download_link ) ) { return null; } $entry = new \stdClass(); $entry->slug = $slug; $entry->plugin = $slug . '/' . $slug . '.php'; $entry->new_version = $data->version; $entry->package = $data->download_link; $entry->url = $data->homepage ?? ( 'https://' . self::PLUGIN_NAME_DNS . '/plugins/' . $slug . '/' ); $entry->tested = $data->tested ?? ''; $entry->requires_php = $data->requires_php ?? '7.4'; $entry->requires = $data->requires ?? ''; return $entry; } /** * Gets the main \WC_Facebook_Loader instance. * * Ensures only one instance can be loaded. * * @since 1.10.0 * * @return \WC_Facebook_Loader */ public static function instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } } // fire it up! WC_Facebook_Loader::instance();