-
Notifications
You must be signed in to change notification settings - Fork 9
PluginTools
Daniel M. Hendricks edited this page Oct 2, 2017
·
4 revisions
A class for retrieving data and performing various tasks on plugins.
Currently, the class doesn't accept any arguments. This will change as new features are added. This is an initial version and it will be improved.
use WordPress_ToolKit\PluginTools;
$plugin_obj = new PluginTools( __DIR__ );
Returns path/url information and the meta data of the current plugin.
$plugin_data = $plugin_obj->get_current_plugin_data();
print_r( $plugin_data );
Returns a ConfigRegistry object with plugin data.
WordPress_ToolKit\ConfigRegistry Object
(
[config:protected] => Array
(
[slug] => my-wordpress-plugin
[path] => /app/public/wp-content/plugins/my-wordpress-plugin/
[url] => https://local.dev/wp-content/plugins/my-wordpress-plugin/
[id] => my-wordpress-plugin/plugin.php
[file] => plugin.php
[meta] => Array
(
[Name] => My WordPress Plugin
[PluginURI] => https://mydomain.com/plugin/
[Version] => 1.2.0
[Description] => A simple plugin to do great things
[Author] => <a href="https://www.danhendricks.com">Daniel M. Hendricks</a>
[AuthorURI] => https://www.danhendricks.com
[TextDomain] => mywpplugin
[DomainPath] => languages
[Network] =>
[Title] => <a href="https://mydomain.com/plugin/">My WordPress Plugin</a>
[AuthorName] => Daniel M. Hendricks
)
)
)
See the output above for available data.
To retrieve the plugin path:
echo $plugin_data->get( 'path' );
To retrieve the plugin name:
echo $plugin_data->get( 'meta/Name' );
This method allows you to hide one or more plugins from WP Admin > Settings (excluding multisite network admin).
To hide a single plugin:
$plugin_obj->hide_plugins( 'akismet/akismet.php' );
To hide the current plugin (using the data from get_current_plugin_data():
$plugin_data = $plugin_obj->get_current_plugin_data();
$plugin_obj->hide_plugins( $plugin_data->get( 'id' ) );
To hide multiple plugins, pass an array:
$plugin_obj->hide_plugins( [ 'akismet/akismet.php', 'disqus-comment-system/disqus.php' ] );