Plugin ArchitectureHooks UsageAdmin Enqueue Scripts

The admin_enqueue_scripts Hook in WPFTS

The admin_enqueue_scripts hook is a standard WordPress hook used to enqueue scripts and styles in the WordPress admin panel. WPFTS utilizes this hook to enqueue necessary scripts and styles on its settings pages and post editing pages.

What WPFTS Does When admin_enqueue_scripts is Called:

  1. Determining the Current Page: The plugin determines the current admin page using the get_current_screen() function.

  2. Enqueuing Scripts and Styles on Settings Pages: If the current page is a WPFTS settings page ($wpfts_core->is_wpfts_settings_page), the plugin enqueues core styles and scripts required for the settings interface, including Bootstrap, jQuery UI, Font Awesome, Select2, and Ace editor. It also sets the is_welcome_message flag and enqueues scripts for working with meta boxes (postbox) and pointers (wp-pointer).

  3. Enqueuing Scripts on Post Editing Pages: On post editing pages, WPFTS enqueues scripts necessary for displaying indexing status.

  4. Enqueuing Scripts and Styles for Add-ons: The wpfts_admin_scripts action is called, which add-ons can use to enqueue their own scripts and styles.

Important Functions Involved in admin_enqueue_scripts Handling:

  • get_current_screen()

  • wp_enqueue_style()

  • wp_enqueue_script()

  • WPFTS_Core::set_is_settings_page()

  • WPFTS_Core::set_option()

  • WPFTS_Core::FeatureDetector()

  • do_action('wpfts_admin_scripts')

How to Use This in Add-on Development:

Add-on developers can use the wpfts_admin_scripts action to enqueue their scripts and styles on WPFTS settings pages. This ensures your scripts and styles are only loaded when needed, preventing slowdowns on other admin pages.

Additional Notes:

  • WPFTS uses versioning for scripts and styles to avoid caching issues.

  • The plugin enqueues different scripts and styles depending on the current admin page, optimizing performance.