A library that adds a WPFactory menu on WordPress dashboard.
Installation via Composer. Instructions to setup the composer.json.
- Add these objects to the
repositoriesarray:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/wpcodefactory/wpfactory-admin-menu"
}
]- Require the library and its dependencies:
"require": {
"wpfactory/wpfactory-admin-menu": "*"
}- Use
preferred-installparameter set asdistonconfig.
"config": {
"preferred-install": "dist"
}- If you're loading it on the pro version of a plugin, you're probably loading it on the free version already, so to avoid that, add the
replacenode to yourcomposer.jsonpro version.
"replace": {
"wpfactory/wpfactory-admin-menu": "*"
}Full Example:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/wpcodefactory/wpfactory-admin-menu"
}
],
"require": {
"wpfactory/wpfactory-admin-menu": "*"
},
"config": {
"preferred-install": "dist"
}
}-
Create/Put the composer.json on the root folder.
-
Then initialize the library with
\WPFactory\WPFactory_Admin_Menu\WPFactory_Admin_Menu::get_instance()from within the main plugin class. Probably the best place is inside the hookplugins_loaded. If the main class is already being loaded with that hook, you can simply load the library in the class constructor. Try to remember to only run it inside ais_admin()check.
Note
Most probably, you won't even need to initialize it because it should have been initialized already by some other library.
Example:
add_action( 'plugins_loaded', function(){
$main_plugin_class = new Main_Plugin_Class();
} );class Main_Plugin_Class(){
function __construct() {
if ( is_admin() ) {
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
\WPFactory\WPFactory_Admin_Menu\WPFactory_Admin_Menu::get_instance();
}
}
}Adds WooCommerce Settings tab as a WPFactory submenu item.
Parameters:
wc_settings_tab_id(string) - The WooCommerce tab id from the settings page. Ex: From a settings tab such aswp-admin/admin.php?page=wc-settings&tab=alg_wc_cost_of_goods, the id would bealg_wc_cost_of_goods.menu_title(string) - The submenu item label displayed on WPFactory menu.page_title(string) - The title displayed above the new settings page. Default value:'WPFactory plugins settings'.plugin_icon(array) - Sets the plugin icon. Default value:Array().-
url(string) - The plugin icon URL. Default value:''.
-
style(string) - The plugin icon inline style. Use it to fine tune the icon if necessary. Default value:''. Example:margin-top:-5px;
-
width(string) - The plugin icon width. Default value:''.
-
height(string) - The plugin icon height. Default value:36.
-
wporg_plugin_slug(string) - The plugin slug from wp.org. Default value:''.
-
get_url_method(string) - Get URL method. Default value:manual.
-
-
- If set as
manual, it will require theurlparameter.
- If set as
-
-
-
- If set as
wporg_plugins_apiit will require thewporg_plugin_slugso it can get the url automatically.
- If set as
-
capability(string) - Capability string used onadd_submenu_page(). Default value:'class_exists( 'WooCommerce' ) ? 'manage_woocommerce' : 'manage_options'.position(int) - Position used onadd_submenu_page(). Default value:30.
Example:
if ( is_admin() ) {
$wpf_admin_menu = \WPFactory\WPFactory_Admin_Menu\WPFactory_Admin_Menu::get_instance();
if ( method_exists( $wpf_admin_menu, 'move_wc_settings_tab_to_wpfactory_menu' ) ) {
$wpf_admin_menu->move_wc_settings_tab_to_wpfactory_menu( array(
'wc_settings_tab_id' => 'alg_wc_cost_of_goods',
'menu_title' => 'Cost of Goods',
) );
}
}Note
It's a good idea to check if the method exists with method_exists( $wpf_admin_menu, 'move_wc_settings_tab_to_wpfactory_menu' ) to make sure it will be compatible with previous versions.