identifier = $identifier; add_action( 'admin_enqueue_scripts', [$this, 'enqueue_assets'],999 ); } /** * Enqueue admin scripts and pass localized data * * @since 1.0.0 * * @return void */ public function enqueue_assets() { $admin_script_handler = Helpers::get_config_data( $this->identifier,'admin_script_handler' ); $plugin_slug = Helpers::get_config_data( $this->identifier,'plugin_slug' ); $general_prefix = Helpers::get_config_data( $this->identifier,'general_prefix' ); wp_localize_script( $admin_script_handler, $general_prefix . '_ens_data', [ // Must stay the 'wp_rest' action: this value is sent as the // X-WP-Nonce header, and WordPress core rejects the whole request // with rest_cookie_invalid_nonce if that header is anything else. 'nonce' => wp_create_nonce( 'wp_rest' ), 'api_version' => 'v1', 'plugin_slug' => $plugin_slug, 'base_url' => site_url(), 'triggers' => apply_filters( 'ens_'.$this->identifier.'_available_actions', [] ) ] ); } }