Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Allow non-CMB2 pages to be added to tab-groups #1407

Closed
abuyoyo opened this issue Feb 15, 2021 · 7 comments
Closed

Feature request: Allow non-CMB2 pages to be added to tab-groups #1407

abuyoyo opened this issue Feb 15, 2021 · 7 comments

Comments

@abuyoyo
Copy link

abuyoyo commented Feb 15, 2021

Allow non-CMB2 pages to be added to options-page tab-groups.

  1. A filter hook inside get_tab_group_tabs() could facilitate this
    $tabs = apply_filters( 'cmb2/tab_group', $tabs, $tab_group );

  2. Additionally it would be nice if CMB2 would also provide a method to print out these tabs on the non-CMB2 pages. Even with the filter hook, the non-CMB2 page has to render its own tabs, replicating and slightly modifying code from get_tab_group_tabs() and options_page_output().

The second part would require a more involved solution. Separating the tab-printing logic from options_page_output() and making it available statically/globally to other plugins.
And there are probably other considerations to be thought through. So perhaps item 2 can be considered separately from the filter hook.

@tw2113
Copy link
Contributor

tw2113 commented Feb 15, 2021

Not shooting this down, but curious about the usecase for this. It feels like you're trying to mix CMB2-created options pages and non-CMB2 options pages in both directions.

@abuyoyo
Copy link
Author

abuyoyo commented Feb 15, 2021

I have a plugin that has multiple (3) admin-pages that I created with CMB2 using a tab-group. One being a top-level menu item. The other 2 being sub-menu items of the first. All three have their own tab - appearing on the admin pages.
I also have another admin page of that plugin that is not created with CMB2 (and has no reason to be converted to CMB2 - a WP_List_Table page).

Adding the non-CMB2 page as a sub-menu item to the main CMB2 pages menu hierarchy is easy using wp-core's native API ( just pass the parent slug to add_submenu_page ).
Adding it to the tabs-group is not as easy.

It feels like you're trying to mix CMB2-created options pages and non-CMB2 options pages in both directions.

I am trying to integrate CMB2 pages more seamlessly into my plugins, my wp installation and workflow. yes.

@tw2113
Copy link
Contributor

tw2113 commented Feb 16, 2021

@jtsternberg what do you think about this?

@jtsternberg
Copy link
Member

Ok, 'tis done. I copied the example settings page in the WP developer docs to the snippet library, and hooked in the CMB2 tabs using the new hookup method:
https://github.com/CMB2/CMB2-Snippet-Library/blob/7fddffa332a9a2811bcd6b374734b2662cf9f722/options-and-settings-pages/non-cmb2-options-page.php#L138-L146

And used the new filter to register the additional tab:
https://github.com/CMB2/CMB2-Snippet-Library/blob/7fddffa332a9a2811bcd6b374734b2662cf9f722/options-and-settings-pages/non-cmb2-options-page.php#L162-L170

@abuyoyo
Copy link
Author

abuyoyo commented Feb 19, 2021

Just tested the new filter hook and function - and everything works great.
Thanks :)

@tw2113
Copy link
Contributor

tw2113 commented Feb 19, 2021

Awesome possum :D

@fabianpimminger
Copy link

This is cool. Thanks!

lipemat added a commit to lipemat/CMB2 that referenced this issue Mar 30, 2021
* upstream/develop:
  Clean up and add props for CMB2#1413
  Sanitize URLs with HTTPS
  Add develop suffix to init class
  Add am-cli-tools
  Update changelong and version numbers and readmes, and prepare release
  Set default priority to 10 for options pages. Fixes CMB2#1410
  build field-cache key manually to remove unnecessary |'s
  Better generated array key for cached fields, fixes issue where wrong field is found. Fixes CMB2#1405
  Add to list of valid image types from get_allowed_mime_types(). Fixes CMB2#1223
  Move tab markup output to separate method, options_page_tab_nav_output. Fixes CMB2#1407
  Add cmb2_tab_group_tabs filter for adding arbitrary menu page urls to the cmb2 tabs. See CMB2#1407
  Update since tag, and add props for CMB2#1340
  Limit use of italic, including removing from field descriptions. Fixes CMB2#1404
  Add props for CMB2#1400
  move $args in deprecated_param method for 7.4
  Add develop suffix to init class
  Prepare release and changelog for 2.8.0
  Fix tests since WP_Error signature changed
  move $args in deprecated_param method for 7.4
  Use the already-existing get_priority method. Re CMB2#1380 and CMB2#1398
  Use existing "priority" field param. Fixes CMB2#1380. Closes CMB2#1398
  Add admin_menu_hook_priority box property for options boxes. Fixes CMB2#1380. Closes CMB2#1398
  Make field_can first param required to address php 8 "Required parameter follows optional parameter". Fixes CMB2#1396
  Update includes/types/CMB2_Type_Colorpicker.php
  Update includes/types/CMB2_Type_Colorpicker.php
  Update includes/CMB2_Utils.php
  Prevent array to string conversion
  Update includes/types/CMB2_Type_Colorpicker.php
  Update includes/types/CMB2_Type_Colorpicker.php
  Update includes/types/CMB2_Type_Colorpicker.php
  Update includes/types/CMB2_Type_Colorpicker.php
  Update includes/types/CMB2_Type_Colorpicker.php
  Update includes/types/CMB2_Type_Colorpicker.php
  Added sanitize_color() function and remove PHP warnings suppresions
  Fixes PHP warnings on repeatable ColorPicker with an array as default
abuyoyo added a commit to abuyoyo/AdminMenuPage that referenced this issue Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants