A library that adds a WPFactory menu on WordPress dashboard.
Installation via Composer. Instructions to setup the composer.json
.
- Add these objects to the
repositories
array:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/wpcodefactory/wpfactory-admin-menu"
}
]
- Require the library and its dependencies:
"require": {
"wpfactory/wpfactory-admin-menu": "*"
}
- Use
preferred-install
parameter set asdist
onconfig
.
"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
replace
node to yourcomposer.json
pro 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'
.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.