Created
August 20, 2016 11:16
-
-
Save timwhitlock/379c20d395bfe69965cc84563eb0eb13 to your computer and use it in GitHub Desktop.
Example of adding an unregistered MU plugin to Loco Translate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* MU plugins inside directories are not returned in `get_mu_plugins`. | |
* This filter modifies the array obtained from Wordpress when Loco grabs it. | |
* | |
* Note that this filter only runs once per script execution, because the value is cached. | |
* Define the function *before* Loco Translate plugin is even included by WP. | |
*/ | |
function add_unregistered_plugins_to_loco( array $plugins ){ | |
// we know the plugin by this handle, even if WordPress doesn't | |
$handle = 'foo-bar/foo-bar.php'; | |
// fetch the plugin's meta data from the would-be plugin file | |
$data = get_plugin_data( trailingslashit(WPMU_PLUGIN_DIR).$handle ); | |
// extra requirement of Loco - $handle must be resolvable to full path | |
$data['basedir'] = WPMU_PLUGIN_DIR; | |
// add to array and return back to Loco Translate | |
$plugins[$handle] = $data; | |
return $plugins; | |
} | |
add_filter('loco_plugins_data', 'add_unregistered_plugins_to_loco', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment