The plugins_loaded
Hook in WPFTS
The plugins_loaded
hook is a standard WordPress hook that fires after all plugins have been loaded. WPFTS uses this hook to load the plugin’s text domain, enabling translation of the plugin’s interface into different languages. WPFTS also initializes its core classes and functions on this hook, if the plugin core is already loaded.
What WPFTS does when plugins_loaded
is called:
-
Loading the text domain: Calls the
wpfts_load_plugin_textdomain()
function to load the plugin’s translation file. This allows using the__()
function for translating interface strings. -
Initializing the plugin core (if available): Checks if the global variable
$wpfts_core
exists and is an instance of theWPFTS_Core
class. If so, it means the plugin core has already been loaded and initialized (e.g., throughwpfts_init_addons
), and the following actions are performed on this hook:- Calling the
WPFTS_Core::set_hooks()
method to register hooks related to search. - Registering AJAX handlers for autocomplete (
wpfts_autocomplete_proc
). - Registering AJAX handlers for forced indexing (
WPFTS_Core::ajax_force_index()
). - Adding the
safe_style_css
filter for supporting specific CSS. - Adding a handler for
post_submitbox_misc_actions
to display the indexing status. - Enqueuing admin scripts and styles if the request is from the admin panel (
wpfts_admin_menu
,wpfts_plugin_links
,wpfts_enqueues
). - Registering AJAX handlers for internal plugin functions (
wpftsi_ping
,wpftsi_set_pause
,wpftsi_hide_notification
,wpftsi_se_style_preview
,wpftsi_se_style_reset
,wpftsi_try_updatedb
). - Registering AJAX handlers for administrator actions (
wpftsi_submit_testpost
,wpftsi_submit_testsearch
,wpftsi_submit_rebuild
,wpftsi_smartform
,wpftsi_submit_upgradeindex
,wpftsi_add_user_irule
). - Calling
$wpfts_core->FeatureDetector();
to detect WordPress environment specifics (e.g., to display notifications about insufficient memory limits). - Executing the
wpfts_init_addons
action to initialize add-ons.
- Calling the
Important functions involved in handling plugins_loaded
:
wpfts_load_plugin_textdomain()
WPFTS_Core::set_hooks()
WPFTS_Core::set_is_settings_page()
(used inwpfts_enqueues
)add_action()
for registering AJAX handlersadd_filter()
for registering filtersdo_action('wpfts_init_addons')
How to use this in add-on development:
Add-on developers can use this hook to initialize their add-ons after all plugins have been loaded. This ensures that all necessary WordPress functions and classes are available. For integration with WPFTS, it is recommended to use the wpfts_init_addons
action, which is called on the same hook.
Additional notes:
Loading the text domain on the plugins_loaded
hook is standard practice for WordPress plugins, allowing for translation of the plugin’s interface into different languages. WPFTS follows this practice. It’s important to note that while much of the plugin’s logic is initialized on the plugins_loaded
hook, the plugin itself begins much earlier, on the init
hook, where the WPFTS_Core
class instance is created.