Core Integration
Hook Architecture
The UditAkhouri/wordpress library is designed to integrate seamlessly with the WordPress lifecycle. It utilizes the standard Plugin API (Actions and Filters) to allow users to modify behavior without touching the core source code.
Action Hooks
These hooks allow you to execute custom code at specific points in the library's execution flow.
| Hook Name | Description | Parameters |
| :--- | :--- | :--- |
| ua_wp_before_init | Fires immediately before the library components are initialized. | None |
| ua_wp_after_setup | Fires after all modules have been loaded and configured. | (array) $active_modules |
| ua_wp_dispatch_event | Triggered when a library-specific event is dispatched. | (string) $event_name, (mixed) $data |
Example: Running code after setup
add_action('ua_wp_after_setup', function($modules) {
if (in_array('mvp_core', $modules)) {
// Perform logic specific to the MVP module
}
});
Filter Hooks
Filters allow you to intercept and modify data used by the library before it is processed or saved to the database.
| Filter Name | Purpose | Expected Return |
| :--- | :--- | :--- |
| ua_wp_config_defaults | Modify the default configuration array for the library. | array |
| ua_wp_query_args | Filter the arguments passed to internal WP_Query instances. | array |
| ua_wp_template_path | Change the directory where the library looks for custom templates. | string |
Example: Modifying global configuration
add_filter('ua_wp_config_defaults', function($defaults) {
$defaults['enable_mvp_mode'] = true;
$defaults['cache_ttl'] = 3600;
return $defaults;
});
Accessing Global Objects
To maintain compatibility with WordPress standards while providing modern functionality, the library exposes a primary singleton instance.
The Global Instance
The main functionality is accessible via the UA_WP() helper function or the $ua_wordpress global object.
// Recommended: Use the helper function
$plugin = UA_WP();
// Access specific sub-components
$plugin->get_module('analytics')->track_event('mvp_contribution');
REST API Integration
The library automatically extends the WordPress REST API to expose MVP-related data. By default, these endpoints are registered under the ua/v1 namespace.
Registering Custom Fields
You can use the library's internal registration wrapper to expose metadata to the REST response:
/**
* Registers a meta field to the WP REST API via the library's interface.
*
* @param string $object_type The WP object type (post, user, etc.)
* @param string $meta_key The key of the meta data.
* @param array $args Standard WP register_rest_field arguments.
*/
UA_WP()->api->register_meta_extension($object_type, $meta_key, $args);
Database & WPDB
For custom table interactions, the library utilizes the $wpdb global object. All custom tables created by this project are prefixed with the standard WordPress table prefix.
Internal Role Note: While the library manages its own schema updates internally, you can retrieve table names via:
$table_name = UA_WP()->db->get_table_name('mvp_logs');
// Returns: wp_ua_mvp_logs (depending on your prefix)
Shortcode Integration
The library provides a registry for UI components that can be called via standard WordPress Shortcodes.
Usage:
[ua_mvp_display component="contribution_chart" limit="5"]
Customizing Output:
To modify the HTML output of library-provided shortcodes, use the ua_wp_shortcode_output filter:
add_filter('ua_wp_shortcode_output', function($output, $tag, $attr) {
if ($tag === 'ua_mvp_display') {
return '<div class="custom-wrapper">' . $output . '</div>';
}
return $output;
}, 10, 3);