wpfts_admin_scripts (Action)

The wpfts_admin_scripts hook in WP Fast Total Search is called to enqueue JavaScript and CSS files on the plugin’s settings pages in the WordPress admin panel. This allows developers to add their own scripts and styles needed for their extensions, only on WPFTS settings pages, avoiding unnecessary resource loading on other admin pages.

When to Use

  • Adding scripts necessary for the operation of your extension’s JavaScript components (e.g., for interactive control elements on the settings page).
  • Adding styles needed to style your settings page or interface elements of your extension.

Arguments

  • The wpfts_admin_scripts hook does not accept any arguments.

Return Value

  • The wpfts_admin_scripts hook should not return any value.

Example

/**
* Enqueues script and styles for the addon admin panel.
*/
add_action('wpfts_admin_scripts', 'my_addon_admin_scripts');
function my_addon_admin_scripts() {
    // Get the screen object.
    $screen = get_current_screen();
 
    // Check if we are on the WPFTS or addon settings page.
    if ( $screen && strpos( $screen->id, 'wpfts-options' ) !== false ) { //wp_enqueue_scripts
        // Enqueue the script.
		wp_enqueue_script( 'my_awesome_script', plugins_url( 'my_awesome_script.js', __FILE__ ), array(), '1.0', true );
		
        // Enqueue the styles.
		wp_enqueue_style( 'my_plugin_styles', plugin_dir_url( __FILE__ ) . 'my_awesome_script.css' );   
    }
 
}

Important Notes

  • Use the wp_enqueue_script() and wp_enqueue_style() functions to enqueue scripts and styles. This ensures correct script dependencies and avoids conflicts.
  • Specify dependencies for your scripts in the $deps argument of the wp_enqueue_script() function to guarantee they are loaded in the correct order.
  • Use the $ver argument to specify the version of scripts and styles. This helps avoid caching problems.
  • Note that the example code includes a check to ensure that scripts and styles are enqueued only on WPFTS settings pages to optimize the performance of the admin panel.

The wpfts_admin_scripts hook allows you to easily add the necessary resources to WPFTS settings pages, ensuring the correct operation of your extensions.