Support Forum
Support › MB Settings Page › MB Settings
I thought I would try using the new MB Settings Extension in my plugin, but it does not seem to want to work..I am sure I am doing something wrong.
I have the mb-settings-page folder in my root directory (along with the meta-box folder) and am trying to load it via this function
function fp_add_meta() {
if( !class_exists( 'RW_Meta_Box' ) ) {
include( plugin_dir_path( __FILE__ ) . 'meta-box/meta-box.php');
}
if( !class_exists( 'MB_Settings_Page' ) ) {
include( plugin_dir_path( __FILE__ ) . 'mb-settings-page/mb-settings-page.php');
}
}
add_action( 'init', 'fp_add_meta' );
The meta-box is loading fine, as the metaboxes are working in my CPT, however I have the following function to create the settings page, but cannot see it in my admin panel at all
function bl_plugin_page( $settings_pages )
{
$settings_pages[] = array(
'id' => 'bl-settings',
'menu_title' => __( 'BeaverLodge Options', 'textdomain' ),
'icon_url' => 'dashicons-admin-generic',
);
return $settings_pages;
}
add_filter( 'mb_settings_pages', 'bl_plugin_page' );
Ok, I installed the settings page as per a normal plugin and it failed so it is loading in my plugin, so my fp_add_meta()
function is working.
That means my bl_plugin_page
function is not.
I tried the example code (which by the way is wrong)
add_filter( 'mb_settings_pages', 'prefix_settings_pages' );
function prefix_settings_pages( $settings_pages )
{
$settings_pages[] = array(
'id' => 'my-options',
'option_name' => 'my_options',
'menu_title' => __( 'Options', 'textdomain' ),
'icon_url' => 'dashicons-images-alt',
'submenu_title' => __( 'Settings', 'textdomain' ), // Note this
);
$settings_pages[] = array(
'id' => 'my-options-im',
'option_name' => 'my_options',
'menu_title' => __( 'Import', 'textdomain' ),
'parent' => 'my-options', // Note this
);
$settings_pages[] = array(
'id' => 'my-options-ex',
'option_name' => 'my_options',
'menu_title' => __( 'Export', 'textdomain' ),
'parent' => 'my-options',
);
return $settings_pages;
} ); // why does this end in );?
And still no joy, so clearly something must be wrong??
Hi carassius,
Can you try replacing init
by plugins_loaded
. init
is too late for the settings page extension.
i still cannot get this to work
Anyone able to help me get this thing to work? Hello?
Let me revisit this with you
I have my bl-settings.php file in the root directory of my plugin
I also have the mb-settings-page folder in my plugins root directory
This is how I am trying to call them
// Settings
function fp_add_meta_settings() {
if( !class_exists( 'MB_Settings_Page' ) ) {
include( plugin_dir_path( __FILE__ ) . 'mb-settings-page/mb-settings-page.php');
}
}
add_action( 'plugins_loaded', 'fp_add_meta_settings' );
include( dirname( __FILE__ ) . '/bl-settings.php');
In my bl-settings.php i am trying to load my settings page as a sub-directory for the Plugins page, so i have the following code
function bl_settings_pages( $settings_pages ) {
$settings_pages[] = array(
'id' => 'bl-options',
'option_name' => 'bl_options',
'parent' => 'plugins.php',
'submenu_title' => __( 'BeaverLodge HQ', 'fl-builder' ),
);
return $settings_pages;
}
add_filter( 'mb_settings_pages', 'bl_settings_pages' );
function bl_options_meta_boxes( $meta_boxes )
{
$meta_boxes[] = array(
'id' => 'fotoplugins',
'title' => __( 'Fotoplugins Settings', 'fl-builder' ),
'settings_pages' => 'bl-options',
'fields' => array(
array(
'name' => __( 'Disable Gallery CPT', 'fl-builder' ),
'id' => 'gallery_cpt',
'type' => 'select',
'syd' => 'no',
'options' => array(
'no' => 'No',
'yes' => 'Yes',
),
),
),
);
return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'bl_options_meta_boxes' );
I am getting really frustrated getting this to work, someone help please
Sorry for the delay. I'm replicating the problem on my localhost now.
I've just checked the code and here is what I did:
1. This is how I structure a "test" plugin:
2. This is the code in the test.php
file (similar to your 1st file):
<?php
/**
* Plugin Name: Test
* Plugin URI: https://metabox.io
* Description: Test
* Version: 0.0.1
* Author: Rilwis
* Author URI: http://www.deluxeblogtips.com
*/
// Load meta box and settings page extension
include plugin_dir_path( __FILE__ ) . 'meta-box/meta-box.php';
include plugin_dir_path( __FILE__ ) . 'mb-settings-page/mb-settings-page.php';
// Load configuration
include plugin_dir_path( __FILE__ ) . 'bl-settings.php';
3. This is the content of the settings file:
<?php
function bl_settings_pages( $settings_pages )
{
$settings_pages[] = array(
'id' => 'bl-options',
'option_name' => 'bl_options',
'parent' => 'plugins.php',
'menu_title' => 'Test',
'submenu_title' => __( 'BeaverLodge HQ', 'fl-builder' ),
);
return $settings_pages;
}
add_filter( 'mb_settings_pages', 'bl_settings_pages' );
function bl_options_meta_boxes( $meta_boxes )
{
$meta_boxes[] = array(
'id' => 'fotoplugins',
'title' => __( 'Fotoplugins Settings', 'fl-builder' ),
'settings_pages' => 'bl-options',
'fields' => array(
array(
'name' => __( 'Disable Gallery CPT', 'fl-builder' ),
'id' => 'gallery_cpt',
'type' => 'select',
'syd' => 'no',
'options' => array(
'no' => 'No',
'yes' => 'Yes',
),
),
),
);
return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'bl_options_meta_boxes' );
Note:menu_title in the settings file, so the menu appears in HTML but not visible cause it doesn't have a text.
4. This is the result: