options_page = add_options_page( FacebookPluginConfig::ADMIN_PAGE_TITLE, FacebookPluginConfig::ADMIN_MENU_TITLE, FacebookPluginConfig::ADMIN_CAPABILITY, FacebookPluginConfig::ADMIN_MENU_SLUG, array( $this, 'add_fbe_box' ) ); \add_option( FacebookPluginConfig::CAPI_INTEGRATION_STATUS, FacebookPluginConfig::CAPI_INTEGRATION_STATUS_DEFAULT ); \add_option( FacebookPluginConfig::CAPI_INTEGRATION_EVENTS_FILTER, FacebookPluginConfig::CAPI_INTEGRATION_EVENTS_FILTER_DEFAULT ); } /** * Renders the Facebook Business Extension box on the settings page. * * This function checks if the current user has the necessary capabilities * to access the page. If not, it terminates the script * with an error message. * If the user has the required permissions, it displays any previous pixel * ID message and the FBE browser settings, and enqueues the * necessary script * for the page. * * @return void */ public function add_fbe_box() { if ( ! current_user_can( FacebookPluginConfig::ADMIN_CAPABILITY ) ) { wp_die( esc_html__( 'You do not have permissions to access this page', 'official-facebook-pixel' ) ); } echo $this->get_fbe_browser_settings(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped wp_enqueue_script( 'fbe_allinone_script' ); } /** * Generates and returns the browser settings HTML and JavaScript * for the Facebook Business Extension. * * This function constructs and outputs a set of HTML elements and * JavaScript code necessary for configuring * the Facebook Business Extension in the browser. It includes sections * for advanced configuration, ads creation, * and ads insights, as well as functionality for testing * conversion API events. * * The function dynamically generates JSON-encoded configuration * data and embeds it into the HTML via * data attributes, allowing for the interactive configuration * of various Facebook Business Extension features. * * It also enqueues the necessary scripts and styles for * rendering the settings page and handles * inline script parameters for AJAX communication * and configuration management. * * @return string The HTML and JavaScript code for the * Facebook Business Extension browser settings. */ private function get_fbe_browser_settings() { ob_start(); $fbe_extras = wp_json_encode( array( 'business_config' => array( 'business' => array( 'name' => 'Solutions_Engineering_Team', ), ), 'setup' => array( 'external_business_id' => FacebookWordpressOptions::get_external_business_id(), 'timezone' => 'America/Los_Angeles', 'currency' => 'USD', 'business_vertical' => 'ECOMMERCE', 'channel' => 'DEFAULT', ), 'repeat' => false, ) ); ?>
Meta Advanced Configuration

Enable checkbox to filter PageView events from sending.

When turned on, PII will be cached for non logged in users.

Conversion API Tests

Plugin Connected to Meta Events Manager

Meta Events Manager is a tool that enables you to view and manage your event data. In Events Manager, you can set up, monitor and troubleshoot issues with your integrations, such as the Conversions API and Meta pixel.

Visit the Meta Events Manager to view the events being tracked.

'; ?>
?

To obtain the Test Event Code, visit the Test Event section in the Events Manager.

Advanced | Edit Event Data Click here to load default payload

Event Log

Code/Message Event Type Status

No events logged yet.

Ads Creation

Ads Insights

admin_url( 'admin-ajax.php' ), 'send_capi_event_nonce' => wp_create_nonce( 'send_capi_event_nonce' ), 'pixelId' => FacebookWordpressOptions::get_pixel_id(), 'setSaveSettingsRoute' => $this->get_fbe_save_settings_ajax_route(), 'externalBusinessId' => esc_html( FacebookWordpressOptions::get_external_business_id() ), 'deleteConfigKeys' => $this->get_delete_fbe_settings_ajax_route(), 'installed' => FacebookWordpressOptions::get_is_fbe_installed(), 'systemUserName' => esc_html( FacebookWordpressOptions::get_external_business_id() ), 'pixelString' => esc_html( FacebookWordpressOptions::get_pixel_id() ), 'piiCachingStatus' => FacebookWordpressOptions::get_capi_pii_caching_status(), 'fbAdvConfTop' => FacebookPluginConfig::CAPI_INTEGRATION_DIV_TOP, 'capiIntegrationPageViewFiltered' => wp_json_encode( FacebookWordpressOptions::get_capi_integration_page_view_filtered() ), 'capiPiiCachingStatusSaveUrl' => $this->get_capi_pii_caching_status_save_url(), 'capiPiiCachingStatusActionName' => FacebookPluginConfig::SAVE_CAPI_PII_CACHING_STATUS_ACTION_NAME, 'capiPiiCachingStatusUpdateError' => FacebookPluginConfig::CAPI_PII_CACHING_STATUS_UPDATE_ERROR, 'capiIntegrationEventsFilterSaveUrl' => $this->get_capi_integration_events_filter_save_url(), 'capiIntegrationEventsFilterActionName' => FacebookPluginConfig::SAVE_CAPI_INTEGRATION_EVENTS_FILTER_ACTION_NAME, 'capiIntegrationEventsFilterUpdateError' => FacebookPluginConfig::CAPI_INTEGRATION_EVENTS_FILTER_UPDATE_ERROR, ) ) . '; var hasAccessToken = ' . wp_json_encode( $has_access_token ) . '; if (!hasAccessToken) { jQuery("#fb-adv-conf").attr("data-access-token", "false"); }', 'before' ); return $initial_script; } /** * Generates the AJAX route URL for saving FBE settings. * * This function creates a nonce for the AJAX action to ensure * security and constructs a URL for the admin-ajax.php endpoint * with the required query arguments, including the action name and nonce. * * @return string The URL with query arguments for the AJAX action. */ public function get_fbe_save_settings_ajax_route() { $nonce_value = wp_create_nonce( FacebookPluginConfig::SAVE_FBE_SETTINGS_ACTION_NAME ); $simple_url = admin_url( 'admin-ajax.php' ); $args = array( 'action' => FacebookPluginConfig::SAVE_FBE_SETTINGS_ACTION_NAME, '_wpnonce' => $nonce_value, ); return add_query_arg( $args, $simple_url ); } /** * Generates the AJAX route URL for saving CAPE integration status. * * This function creates a nonce for the AJAX action to ensure * security and constructs a URL for the admin-ajax.php endpoint * with the required query arguments, including the action name and nonce. * * @return string The URL with query arguments for the AJAX action. */ public function get_capi_integration_status_save_url() { $nonce_value = wp_create_nonce( FacebookPluginConfig::SAVE_CAPI_INTEGRATION_STATUS_ACTION_NAME ); $simple_url = admin_url( 'admin-ajax.php' ); $args = array( 'action' => FacebookPluginConfig::SAVE_CAPI_INTEGRATION_STATUS_ACTION_NAME, '_wpnonce' => $nonce_value, ); return add_query_arg( $args, $simple_url ); } /** * Generates the AJAX route URL for saving CAPE events filter. * * This function creates a nonce for the AJAX action to ensure * security and constructs a URL for the admin-ajax.php endpoint * with the required query arguments, including the action name and nonce. * * @return string The URL with query arguments for the AJAX action. */ public function get_capi_integration_events_filter_save_url() { $nonce_value = wp_create_nonce( FacebookPluginConfig::SAVE_CAPI_INTEGRATION_EVENTS_FILTER_ACTION_NAME ); $simple_url = admin_url( 'admin-ajax.php' ); $args = array( 'action' => FacebookPluginConfig::SAVE_CAPI_INTEGRATION_EVENTS_FILTER_ACTION_NAME, '_wpnonce' => $nonce_value, ); return add_query_arg( $args, $simple_url ); } /** * Generates the AJAX route URL for saving CAPI PII caching status. * * This function creates a nonce for the AJAX action to ensure * security and constructs a URL for the admin-ajax.php endpoint * with the required query arguments, including the action name and nonce. * * @return string The URL with query arguments for the AJAX action. */ public function get_capi_pii_caching_status_save_url() { $nonce_value = wp_create_nonce( FacebookPluginConfig::SAVE_CAPI_PII_CACHING_STATUS_ACTION_NAME ); $simple_url = admin_url( 'admin-ajax.php' ); $args = array( 'action' => FacebookPluginConfig::SAVE_CAPI_PII_CACHING_STATUS_ACTION_NAME, '_wpnonce' => $nonce_value, ); return add_query_arg( $args, $simple_url ); } /** * Generates the AJAX route URL for deleting FBE settings. * * This function creates a nonce for the AJAX action to ensure * security and constructs a URL for the admin-ajax.php endpoint * with the required query arguments, including the action name and nonce. * * @return string The URL with query arguments for the AJAX action. */ public function get_delete_fbe_settings_ajax_route() { $nonce_value = wp_create_nonce( FacebookPluginConfig::DELETE_FBE_SETTINGS_ACTION_NAME ); $simple_url = admin_url( 'admin-ajax.php' ); $args = array( 'action' => FacebookPluginConfig::DELETE_FBE_SETTINGS_ACTION_NAME, '_wpnonce' => $nonce_value, ); return add_query_arg( $args, $simple_url ); } /** * Adds a settings link to the plugin action links. * * This function appends a "Settings" link to the given * array of plugin action links. * The link directs the user to the Facebook Business * Extension settings page. * * @param array $links An array of existing plugin action links. * @return array The modified array of plugin action * links with the settings link added. */ public function add_settings_link( $links ) { $settings = array( 'settings' => sprintf( '%s', admin_url( 'options-general.php?page=' . FacebookPluginConfig::ADMIN_MENU_SLUG ), 'Settings' ), ); return array_merge( $settings, $links ); } /** * Registers admin notices for the Facebook Business Extension. * * This function determines whether the Facebook Business * Extension is installed * and whether the user has dismissed the notice. If the * extension is not installed * and the user has not dismissed the notice, it * registers the 'fbe_not_installed_notice' * function to display the notice. If the extension is * installed and the user has not * dismissed the review notice, it registers the * 'plugin_review_notice' function to * display the review notice. */ public function register_notices() { $is_fbe_installed = FacebookWordpressOptions::get_is_fbe_installed(); $current_screen_id = get_current_screen()->id; if ( current_user_can( FacebookPluginConfig::ADMIN_CAPABILITY ) && in_array( $current_screen_id, array( 'dashboard', 'plugins' ), true ) ) { if ( $this->should_show_wpcom_update_notice() ) { add_action( 'admin_notices', array( $this, 'wpcom_update_notice' ) ); } if ( '0' == $is_fbe_installed && ! get_user_meta( // phpcs:ignore Universal.Operators.StrictComparisons get_current_user_id(), FacebookPluginConfig::ADMIN_IGNORE_FBE_NOT_INSTALLED_NOTICE, true ) ) { add_action( 'admin_notices', array( $this, 'fbe_not_installed_notice' ) ); } if ( '1' == $is_fbe_installed && ! get_user_meta( // phpcs:ignore Universal.Operators.StrictComparisons get_current_user_id(), FacebookPluginConfig::ADMIN_IGNORE_PLUGIN_REVIEW_NOTICE, true ) ) { add_action( 'admin_notices', array( $this, 'plugin_review_notice' ) ); } } } /** * Returns a customized message for the Facebook Business * Extension not installed notice. * * This function determines if a valid pixel ID and access * token are set. If both are set, it * suggests using the plugin to manage the connection to Meta. * If only the pixel ID is set, it * highlights the Conversions API feature. If neither is set, * it suggests completing the setup * steps. * * @return string The customized message. */ public function get_customized_fbe_not_installed_notice() { $valid_pixel_id = ! empty( FacebookWordpressOptions::get_pixel_id() ); $valid_access_token = ! empty( FacebookWordPressOptions::get_access_token() ); $message = ''; $plugin_name_tag = sprintf( '%s', FacebookPluginConfig::PLUGIN_NAME ); if ( $valid_pixel_id ) { if ( $valid_access_token ) { $message = sprintf( 'Easily manage your connection to Meta with %s.', $plugin_name_tag ); } else { $message = sprintf( '%s gives you access to the Conversions API.', $plugin_name_tag ); } } else { $message = sprintf( '%s is almost ready.', $plugin_name_tag ); } return $message . ' To complete your configuration, ' . 'follow the setup steps.'; } /** * Determines whether the WordPress.com update notice should be shown. * * @return bool Whether the WordPress.com update notice should be shown. */ public function should_show_wpcom_update_notice() { if ( 1 !== (int) get_option( 'is_wordpress_com_hosted' ) ) { return false; } return ! get_user_meta( get_current_user_id(), FacebookPluginConfig::ADMIN_IGNORE_WPCOM_UPDATE_NOTICE, true ); } /** * Returns the WordPress.com update notice message. * * @return string The WordPress.com update notice message. */ public function get_wpcom_update_notice_message() { $plugin_url = 'https://wordpress.org/plugins/' . FacebookPluginConfig::TEXT_DOMAIN . '/'; return sprintf( /* translators: %s: WordPress.org plugin page URL */ __( 'After April 30th, 2026, Meta Pixel for WordPress will no longer receive automatic updates on WordPress.com-hosted websites. Download the latest version from WordPress.org and install it manually via PluginsAdd New PluginUpload Plugin to ensure you receive future updates.', 'official-facebook-pixel' ), esc_url( $plugin_url ) ); } /** * Displays a WordPress admin notice with a dismiss button. * * This function generates an HTML notice with the * specified content and type, * which can be dismissed by the user. It constructs a URL for the settings * page and includes a button to dismiss the notice. * * @param string $notice The content of the notice, * with a placeholder for the settings URL. * @param array $dismiss_config Configuration for * the dismissal URL query arguments. * @param string $notice_type The type of notice * to display (e.g., 'warning', 'info'). */ public function set_notice( $notice, $dismiss_config, $notice_type ) { $url = admin_url( 'options-general.php?page=' . FacebookPluginConfig::ADMIN_MENU_SLUG ); $link = sprintf( $notice, esc_url( $url ) ); printf( '

%s

', esc_html( $notice_type ), wp_kses_post( $link ), esc_url( add_query_arg( $dismiss_config, '' ) ), esc_html__( 'Dismiss this notice.', 'official-facebook-pixel' ) ); } /** * Displays a notice asking the user to leave a review for the plugin. * * If the user has not dismissed the review notice, this function generates * an HTML notice with a link to the plugin's * review page and a dismiss button. * * @since 3.0.0 */ public function plugin_review_notice() { $message = sprintf( /* translators: %1$s: Plugin name, %2$s: Review page URL */ __( 'Let us know what you think about %1$s. Leave a review on this page.', 'official-facebook-pixel' ), FacebookPluginConfig::PLUGIN_NAME, FacebookPluginConfig::PLUGIN_REVIEW_PAGE ); $this->set_notice( $message, FacebookPluginConfig::ADMIN_DISMISS_PLUGIN_REVIEW_NOTICE, 'info' ); } /** * Displays a notice about WordPress.com automatic updates ending. * * @return void */ public function wpcom_update_notice() { $this->set_notice( $this->get_wpcom_update_notice_message(), FacebookPluginConfig::ADMIN_DISMISS_WPCOM_UPDATE_NOTICE, 'warning' ); } /** * Displays a notice indicating that the Facebook * Business Extension is not installed. * * This function retrieves a customized message for the * Facebook Business Extension not installed notice * and uses it to generate an HTML admin notice. * The notice is dismissible and marked as a warning type. * * @since 3.0.0 */ public function fbe_not_installed_notice() { $message = $this->get_customized_fbe_not_installed_notice(); $this->set_notice( $message, FacebookPluginConfig::ADMIN_DISMISS_FBE_NOT_INSTALLED_NOTICE, 'warning' ); } /** * Handles dismissals of admin notices. * * This function checks for the presence of * query arguments that indicate a notice * should be dismissed. If such an argument * is present, it updates the corresponding * user meta value to true, indicating that * the notice should no longer be shown. * * @since 3.0.0 */ public function dismiss_notices() { $user_id = get_current_user_id(); if ( isset( $_GET[ FacebookPluginConfig::ADMIN_DISMISS_FBE_NOT_INSTALLED_NOTICE ] // phpcs:ignore WordPress.Security.NonceVerification.Recommended ) ) { update_user_meta( $user_id, FacebookPluginConfig::ADMIN_IGNORE_FBE_NOT_INSTALLED_NOTICE, true ); } if ( isset( $_GET[ FacebookPluginConfig::ADMIN_DISMISS_PLUGIN_REVIEW_NOTICE ] // phpcs:ignore WordPress.Security.NonceVerification.Recommended ) ) { update_user_meta( $user_id, FacebookPluginConfig::ADMIN_IGNORE_PLUGIN_REVIEW_NOTICE, true ); } if ( isset( $_GET[ FacebookPluginConfig::ADMIN_DISMISS_WPCOM_UPDATE_NOTICE ] // phpcs:ignore WordPress.Security.NonceVerification.Recommended ) ) { update_user_meta( $user_id, FacebookPluginConfig::ADMIN_IGNORE_WPCOM_UPDATE_NOTICE, true ); } } }