CMB2 – place inside options page created by ‘add_options_page’
-
How to place my CMB2 fields inside options page created by ‘add_options_page’ (wordpress native function) ? https://scrnli.com/DN9ksKz3kurjP6
Do I need more more advanced PHP (custom PHP class) than usual CMB2 parameter like custom ‘show_on_cb’ ?
Let’s presume ‘show_on_cb’ will do the trick…
First, as I mentioned, I created the options page by native WordPress function ‘add_options_page’ :
function pd_theme_settings_function() { add_options_page( 'Tytu?', '_Ustawienia_Motywu_', 'manage_options', 'ustawienia_motywu', 'theme_settings' ); } add_action('admin_menu', 'pd_theme_settings_function');
…and I want CMB2 fields inside of it…
….so here is my attempt to use ‘cmb2_show_on’ filter :
function show_only_if_screen_id_equals_settings_page_ustawienia_motywu($display) { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : (object) array( 'id' => null ); // Only show on our screen. if ( 'settings_page_ustawienia_motywu' !== $screen->id ) { return; } return $display; } add_filter( 'cmb2_show_on', 'show_only_if_screen_id_equals_settings_page_ustawienia_motywu', 10, 2 );
….and then I used it inside new_cmb2_box like so:
$cmb = new_cmb2_box( array( 'id' => 'backlink_offer', 'title' => 'fdsa', 'object_types' => array( 'options-page', ), // Post type 'show_on_cb' => 'show_only_if_screen_id_equals_settings_page_ustawienia_motywu', 'capability' => 'manage_options', 'context' => 'normal', 'priority' => 'low', 'show_names' => true, // Show field names on the left ) );
….nope….it does not work
So I tried to utilize ‘Prefix_Add_CMB2_To_Settings_Page’ class form snipets library, namely:
I tried to utilize ‘Prefix_Add_CMB2_To_Settings_Page’ class form snipets library…changing the $screen parameter to ‘settings_page_ustawienia_motywu’
….and then executing the function
myprefix_cmb2_on_settings();
But still no success…
Any ideas how to make it work ?
- This topic was modified 3 years, 1 month ago by .
- This topic was modified 3 years, 1 month ago by .
- This topic was modified 3 years, 1 month ago by .
- This topic was modified 3 years, 1 month ago by .
- This topic was modified 3 years, 1 month ago by .
- This topic was modified 3 years, 1 month ago by .
- This topic was modified 3 years, 1 month ago by .
- The topic ‘CMB2 – place inside options page created by ‘add_options_page’’ is closed to new replies.