diff --git a/CHANGELOG.md b/CHANGELOG.md index 6826512..f9a5876 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Notice Manager Changelog +## 0.19 + +### Added +- Add 'Distraction Free' option. + ## 0.18 ### Minor diff --git a/composer.json b/composer.json index 0b61873..df9bc5c 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "require":{ "abuyoyo/screen-meta-links": "~0.11", - "abuyoyo/plugincore": "~0.23", - "abuyoyo/adminmenupage": "~0.21" + "abuyoyo/plugincore": "~0.26", + "abuyoyo/adminmenupage": "~0.25" } } \ No newline at end of file diff --git a/composer.lock b/composer.lock index 1698ab5..d6510b9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,24 +4,24 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c7eb351b97392f663e147702dbc845b9", + "content-hash": "d8561fb20f4729b2675b8aeef402b4aa", "packages": [ { "name": "abuyoyo/adminmenupage", - "version": "0.21", + "version": "0.25", "source": { "type": "git", "url": "https://github.com/abuyoyo/AdminMenuPage.git", - "reference": "d05a9e9977d7e7c4ba3c913993493fefba4359d6" + "reference": "487d262aec77a9a3ce04fa762e9048f30d22f123" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/abuyoyo/AdminMenuPage/zipball/d05a9e9977d7e7c4ba3c913993493fefba4359d6", - "reference": "d05a9e9977d7e7c4ba3c913993493fefba4359d6", + "url": "https://api.github.com/repos/abuyoyo/AdminMenuPage/zipball/487d262aec77a9a3ce04fa762e9048f30d22f123", + "reference": "487d262aec77a9a3ce04fa762e9048f30d22f123", "shasum": "" }, "suggest": { - "abuyoyo/plugincore": "~0.18", + "abuyoyo/plugincore": "~0.26", "cmb2/cmb2": "~2.9" }, "type": "library", @@ -40,26 +40,26 @@ "description": "WordPress admin menu page helper class", "support": { "issues": "https://github.com/abuyoyo/AdminMenuPage/issues", - "source": "https://github.com/abuyoyo/AdminMenuPage/tree/0.21" + "source": "https://github.com/abuyoyo/AdminMenuPage/tree/0.25" }, - "time": "2022-08-06T13:42:37+00:00" + "time": "2023-06-09T00:00:00+00:00" }, { "name": "abuyoyo/plugincore", - "version": "0.23", + "version": "0.26", "source": { "type": "git", "url": "https://github.com/abuyoyo/PluginCore.git", - "reference": "0a5809d6722a2abf0bdaf23f73bd3875b00fd2a4" + "reference": "77f7d5451bdff4bda6c9766847b215bdeaca96d6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/abuyoyo/PluginCore/zipball/0a5809d6722a2abf0bdaf23f73bd3875b00fd2a4", - "reference": "0a5809d6722a2abf0bdaf23f73bd3875b00fd2a4", + "url": "https://api.github.com/repos/abuyoyo/PluginCore/zipball/77f7d5451bdff4bda6c9766847b215bdeaca96d6", + "reference": "77f7d5451bdff4bda6c9766847b215bdeaca96d6", "shasum": "" }, "suggest": { - "abuyoyo/adminmenupage": "~0.20", + "abuyoyo/adminmenupage": "~0.25", "yahnis-elsts/plugin-update-checker": "~4.12" }, "type": "library", @@ -75,9 +75,9 @@ "description": "WordPress plugin core helper class", "support": { "issues": "https://github.com/abuyoyo/PluginCore/issues", - "source": "https://github.com/abuyoyo/PluginCore/tree/0.23" + "source": "https://github.com/abuyoyo/PluginCore/tree/0.26" }, - "time": "2022-08-06T00:00:00+00:00" + "time": "2022-06-09T00:00:00+00:00" }, { "name": "abuyoyo/screen-meta-links", diff --git a/js/notice_manager_panel.js b/js/notice_manager_panel.js index d0fecee..d2eee9d 100644 --- a/js/notice_manager_panel.js +++ b/js/notice_manager_panel.js @@ -3,58 +3,58 @@ * */ var NoticeManager = (function ($, document) { - let options = window.notice_manager_options; + let options = window.notice_manager_options let selectors_notice = [ "div.notice", "div.updated", - ]; + ] let selectors_warning = [ "div.notice-warning", "div.update-nag", - ]; + ] let selectors_error = [ "div.error", "div.notice-error", - ]; + ] - let selectors_all = selectors_notice.concat(selectors_warning, selectors_error); + let selectors_all = selectors_notice.concat(selectors_warning, selectors_error) // wait function used with autoCollapse let wait = function (ms) { - var dfd = $.Deferred(); - setTimeout(dfd.resolve, ms); //callback, timeout till callback - return dfd.promise(); - }; + var dfd = $.Deferred() + setTimeout(dfd.resolve, ms) //callback, timeout till callback + return dfd.promise() + } - let notices; + let notices - let button; - let panel; - let haveClosed; // set to true on first close/collect - let dismissNoticesButton; + let button + let panel + let haveClosed // set to true on first close/collect + let dismissNoticesButton // bootstrap // some of these need to run BEFORE document.ready - don't know why really - button = $("#meta-link-notices"); - panel = $("#meta-link-notices-wrap"); - haveClosed = false; - dismissNoticesButton = $("#meta-link-notices-wrap button.notice-dismiss"); + button = $("#meta-link-notices") + panel = $("#meta-link-notices-wrap") + haveClosed = false + dismissNoticesButton = $("#meta-link-notices-wrap button.notice-dismiss") dismissNoticesButton.on("click", () => { - screenMeta.close(panel, button); + screenMeta.close(panel, button) if (! haveClosed){ - NoticeManager.collectNotices(); + NoticeManager.collectNotices() } - NoticeManager.addCounter(); - }); + NoticeManager.addCounter() + }) //original wp focus on click function button.on("focus.scroll-into-view", (e) => { - if (e.target.scrollIntoView) e.target.scrollIntoView(false); - }); + if (e.target.scrollIntoView) e.target.scrollIntoView(false) + }) // scroll page to top when closing notice panel // function used to work with $(this) @@ -63,57 +63,57 @@ var NoticeManager = (function ($, document) { button.on("click", (e) => { if ($(e.target).hasClass("screen-meta-active")) { if (haveClosed) { - NoticeManager.addCounter(); + NoticeManager.addCounter() } - // $(window).scrollTop(true); + // $(window).scrollTop(true) } else { - NoticeManager.removeCounter(); + NoticeManager.removeCounter() // wait (500).then(function(){ //still jumpy sometimes - but scrolls to correct position 400 ~ 600 - // $(window).scrollTop(true); - // }); + // $(window).scrollTop(true) + // }) } - }); + }) /** * document.on.ready */ $(() => { - console.log("NoticeManager.on.ready"); - console.log("options"); - console.log(options); + console.log("NoticeManager.on.ready") + console.log("options") + console.log(options) // bootstrap notices // get all notices that are not explicitly marked as `.inline` or `.below-h2` // we add .update-nag.inline for WordPress Update notice notices = $( selectors_all.join(', ') ) .not(".inline, .below-h2") - .add("div.update-nag"); + .add("div.update-nag") /** * Remove panel if there are no notices on this page */ if (options.screen_panel) { - NoticeManager.maybeRemoveNoticesPanel(); + NoticeManager.maybeRemoveNoticesPanel() } if (options.screen_panel && options.auto_collect) { - NoticeManager.collectNotices(); + NoticeManager.collectNotices() } else { if (options.above_title) { - NoticeManager.moveAboveTitle(); + NoticeManager.moveAboveTitle() } } /** * auto-open notices panel */ - if (button.length) { - panel.toggle(); - button.addClass("screen-meta-active"); - screenMeta.open(panel, button); + if (button.length && ! options.distraction_free) { + panel.toggle() + button.addClass("screen-meta-active") + screenMeta.open(panel, button) } /** @@ -121,20 +121,25 @@ var NoticeManager = (function ($, document) { * only auto-close if we have collected notices previously * only auto-close if no error messages */ - if (options.auto_collapse) { + if (options.auto_collapse && ! options.distraction_free) { wait(4000).then(() => { if (haveClosed && NoticeManager.getNoticesTopPriority() != 'error') { - screenMeta.close(panel, button); - NoticeManager.addCounter(); + screenMeta.close(panel, button) + NoticeManager.addCounter() } - }); + }) } - }); // end document.on.ready + + if (options.distraction_free) { + NoticeManager.addCounterWhenClosed() + } + + }) // end document.on.ready // prevent jumpy scrollRestoration on reload page // fixed below on 'beforeunload' // if (history.scrollRestoration) { - // history.scrollRestoration = 'manual'; + // history.scrollRestoration = 'manual' //} /** * Set history.scrollTop to prevent jump on page refresh when scrollRestoration = auto @@ -144,18 +149,31 @@ var NoticeManager = (function ($, document) { { scrollTop: document.body.scrollTop }, document.title, document.location.pathname - ); - }); + ) + }) return { getNotices: () => notices, getNoticesTopPriority: () => { if (notices.filter(":visible").filter(selectors_error.join(", ")).length) - return 'error'; + return 'error' if (notices.filter(":visible").filter(selectors_warning.join(", ")).length) - return 'warning'; - return 'notice'; + return 'warning' + return 'notice' + }, + + /** + * .filter(":visible") unreliable when closed + * + * @returns {string} top priority + */ + getNoticesTopPriorityWhenClosed: () => { + if (notices.filter(selectors_error.join(", ")).length) + return 'error' + if (notices.filter(selectors_warning.join(", ")).length) + return 'warning' + return 'notice' }, /** @@ -163,10 +181,10 @@ var NoticeManager = (function ($, document) { * Remove dismiss-notices button. */ collectNotices: () => { - notices.appendTo(".notice_container").eq(0); - $(".notice_container").removeClass("empty"); // .empty removes padding + notices.appendTo(".notice_container").eq(0) + $(".notice_container").removeClass("empty") // .empty removes padding - haveClosed = true; // initial collection has occurred. + haveClosed = true // initial collection has occurred. /** * When dismissible notices are dismissed, check if any notices are left on page. @@ -178,10 +196,10 @@ var NoticeManager = (function ($, document) { () => { notices = panel .find(selectors_all.join(", ")) - .filter(":visible"); - NoticeManager.maybeRemoveNoticesPanel(); + .filter(":visible") + NoticeManager.maybeRemoveNoticesPanel() } - ); + ) }, addCounter: () => { @@ -190,12 +208,25 @@ var NoticeManager = (function ($, document) { $("").text(notices.filter(":visible").length).attr({ class: "plugin-count", }).addClass(NoticeManager.getNoticesTopPriority()) - ); + ) + } + }, + + /** + * cannot rely on filter(:visible) + */ + addCounterWhenClosed: () => { + if (!button.children('.plugin-count').length){ + button.append( + $("").text(notices.length).attr({ + class: "plugin-count", + }).addClass(NoticeManager.getNoticesTopPriorityWhenClosed()) + ) } }, removeCounter: () => { - button.children(".plugin-count").remove(); + button.children(".plugin-count").remove() }, /** @@ -204,13 +235,13 @@ var NoticeManager = (function ($, document) { */ maybeRemoveNoticesPanel: () => { if (!notices.length) { - screenMeta.close(panel, button); + screenMeta.close(panel, button) - $("#meta-link-notices-link-wrap").detach(); - $("#meta-link-notices-wrap").detach(); + $("#meta-link-notices-link-wrap").detach() + $("#meta-link-notices-wrap").detach() if (!$("#screen-meta-links").children().length) - $("#screen-meta-links").detach(); + $("#screen-meta-links").detach() } }, @@ -220,7 +251,7 @@ var NoticeManager = (function ($, document) { * I HATE it when WordPress moves notices below title. */ moveAboveTitle: () => { - notices.insertBefore(".wrap:first"); + notices.insertBefore(".wrap:first") }, - }; + } }(jQuery,document) ) \ No newline at end of file diff --git a/notice-manager.php b/notice-manager.php index e078923..61b5531 100644 --- a/notice-manager.php +++ b/notice-manager.php @@ -2,7 +2,7 @@ /** * Plugin Name: Notice Manager * Description: Manage notices on WordPress admin pages. Adds 'Notices' screen-meta-link. - * Version: 0.18 + * Version: 0.19 * Author: abuyoyo * Author URI: https://github.com/abuyoyo/ * Plugin URI: https://github.com/abuyoyo/notice-manager @@ -12,7 +12,8 @@ defined( 'ABSPATH' ) || die( 'No soup for you!' ); use WPHelper\PluginCore; -require_once 'vendor/autoload.php'; +if ( file_exists( 'vendor/autoload.php' ) ) + require_once 'vendor/autoload.php'; /** * Bootstrap plugin and admin page (Tools > Notice Manager) @@ -29,7 +30,7 @@ new PluginCore( 'admin_page' => [ 'parent' => 'options', 'render' => 'settings-page', // built-in settings page - 'plugin_info' => true, + // 'plugin_info' => true, // disable on public repo 'settings' => [ 'option_name' => 'notice_manager', // option_name used in wp_options table 'sections' => [ @@ -62,6 +63,12 @@ new PluginCore( 'type' => 'checkbox', 'description' => 'If auto-collect is enabled - Notices panel will stay open for a few seconds on page load, and then close automatically. Panel will not auto-collapse if it contains `error` level notices.', ], + [ + 'id' => 'distraction_free', + 'title' => 'Distraction Free', + 'type' => 'checkbox', + 'description' => 'Notice Panel is closed on page load. Requires auto_collect.' + ], ] ] ] diff --git a/vendor/abuyoyo/adminmenupage/CHANGELOG.md b/vendor/abuyoyo/adminmenupage/CHANGELOG.md index 4d24a7c..4f1cecc 100644 --- a/vendor/abuyoyo/adminmenupage/CHANGELOG.md +++ b/vendor/abuyoyo/adminmenupage/CHANGELOG.md @@ -1,6 +1,54 @@ # Changelog WPHelper\AdminMenuPage +## 0.25 +Release date: Jun 9 2023 + +### Added +- Non-CMB2 pages can be added to CMB2 tab groups. New options `tab_group` and `tab_title` + +### Changed +- New method `render_plugin_info_meta_box`. Deprecate `render_plugin_info_box`. +- Plugin info meta box rendered using `WPHelper\MetaBox`. + +### Fixed +- Fix several PHP undefined variable warnings. + +### Internal +- Setting pages/wrap temlate uses WordPress Core `do_meta_boxes` to render `side` meta boxes div. +- Add variables to `AdminPage::options()` array. +- Multiple code refactoring and template restructuring. + +## 0.24 +Release date: Jan 28 2023 + +### Fixed +- Fix plugin info meta box when no PluginCore is available. +- Fix PHP deprecated notice. + +## 0.23 +Release date: Jan 15 2023 + +### Added +- Add action hook `wphelper/plugin_info_meta_box/{$slug}` to modify and render plugin info meta box. +- Add support for `textarea` input field in SettingsPage. +- Add `sanitize_callback` option - allow plugins to supply their own sanitize function. +- Add `render` to fields - allow plugins to supply their own render callback for fields. +- Add `placeholder` to fields - allow plugins to supply placeholder values for fields. + +### Fixed +- Fix default value handling for fields. + +### Internal +- Rename `tpl/` template parts. +- Minor changes and fixes. + +## 0.22 +Release date: Jan 1 2023 + +### Fixed +- Fix error when `plugin_info = true` but `plugin_core` is not set. + ## 0.21 ### Fixed @@ -9,7 +57,7 @@ WPHelper\AdminMenuPage ## 0.20 ### Added -- Add SettingsPage section option `desciption-container`. Accepts `card` div, `notice`, `notice-info` and `none`. +- Add SettingsPage section option `description-container`. Accepts `card` div, `notice`, `notice-info` and `none`. - Sanitize SettingsPage text, url and email fields. ## 0.19 @@ -19,7 +67,7 @@ WPHelper\AdminMenuPage - CMB2_OptionsPage supports all admin menu top-level slugs. ### Fixed -- Fixed PHP fatal error: cannot redeclare function `wph_extra_plugin_headers()`. +- Fix PHP fatal error: cannot redeclare function `wph_extra_plugin_headers()`. ### Changed - If CMB2 plugin is not activated - show missing plugin card on `cmb2` and `cmb2-tabs` pages. diff --git a/vendor/abuyoyo/adminmenupage/README.md b/vendor/abuyoyo/adminmenupage/README.md index 80508f0..ffce297 100644 --- a/vendor/abuyoyo/adminmenupage/README.md +++ b/vendor/abuyoyo/adminmenupage/README.md @@ -19,7 +19,7 @@ require __DIR__ . '/vendor/autoload.php'; WPHelper\AdminMenuPage uses [PSR-4](https://www.php-fig.org/psr/psr-4/) to autoload. -OR +OR Install as WordPress plugin and activate. @@ -40,14 +40,13 @@ $args = [ 'icon_url' => $icon_url; // optional - icon url passed to add_menu_page/add_submenu_page 'position' => 4; // optional - passed to add_menu_page 'scripts' => [ // optional - script parameters passed to enqueue_scripts. Will only enqueue scripts on admin page - [ 'script_handle', 'js/myscript.js', ['jquery'], false, true ], + [ 'script_handle', 'js/my_script.js', ['jquery'], false, true ], [ 'another_script', 'js/my_other_script.js', ['jquery', 'script_handle'], false, true ] ]; ]; // Register the admin menu page. $admin_menu_page = new AdminPage( $args ); -$admin_menu_page->setup(); // That's it. We're done. // This function can be called from anywhere. No need to wrap in any hook. diff --git a/vendor/abuyoyo/adminmenupage/composer.json b/vendor/abuyoyo/adminmenupage/composer.json index 63cdd5e..bfe3a87 100644 --- a/vendor/abuyoyo/adminmenupage/composer.json +++ b/vendor/abuyoyo/adminmenupage/composer.json @@ -2,10 +2,11 @@ "name": "abuyoyo/adminmenupage", "description": "WordPress admin menu page helper class", "type": "library", - "version": "0.21", + "version": "0.25", + "time": "2023-06-09", "license": "BSD-3-Clause", "suggest": { - "abuyoyo/plugincore": "~0.18", + "abuyoyo/plugincore": "~0.26", "cmb2/cmb2": "~2.9" }, "autoload": { diff --git a/vendor/abuyoyo/adminmenupage/src/AdminMenuPage.php b/vendor/abuyoyo/adminmenupage/src/AdminMenuPage.php index 5fff7fc..4be3b61 100644 --- a/vendor/abuyoyo/adminmenupage/src/AdminMenuPage.php +++ b/vendor/abuyoyo/adminmenupage/src/AdminMenuPage.php @@ -3,7 +3,7 @@ namespace WPHelper; defined( 'ABSPATH' ) || die( 'No soup for you!' ); -if ( ! class_exists( 'WPHelper\AdminMenuPage' ) ): +if ( ! class_exists( AdminMenuPage::class ) ): /** * AdminMenuPage * diff --git a/vendor/abuyoyo/adminmenupage/src/AdminPage.php b/vendor/abuyoyo/adminmenupage/src/AdminPage.php index 4bcb7dd..da03b09 100644 --- a/vendor/abuyoyo/adminmenupage/src/AdminPage.php +++ b/vendor/abuyoyo/adminmenupage/src/AdminPage.php @@ -1,13 +1,15 @@ plugin_core ) ) $this->plugin_core( $options->plugin_core ); - if ( isset( $options->title ) ) - $this->title( $options->title ); + $this->title( $options->title ?? null ); /** * @todo move this to bootstrap() */ if ( ! isset( $options->menu_title ) ) - $options->menu_title = $options->title; + $options->menu_title = $this->title; if ( isset( $options->menu_title ) ) $this->menu_title( $options->menu_title ); @@ -193,8 +222,7 @@ class AdminPage if ( isset( $options->capability ) ) $this->capability( $options->capability ); - if ( isset( $options->slug ) ) - $this->slug( $options->slug ); + $this->slug( $options->slug ?? null ); if ( isset( $options->plugin_info ) ){ // before render() $this->plugin_info( $options->plugin_info ); @@ -204,21 +232,24 @@ class AdminPage $this->wrap( $options->wrap ); } - if ( isset( $options->render ) ) // dev - $this->render( $options->render ); - - if ( isset( $options->render_cb ) ) // dev - deprecate? + if ( isset( $options->render_cb ) ) $this->render_cb( $options->render_cb ); - if ( isset( $options->render_tpl ) ) // dev - deprecate? + if ( isset( $options->render_tpl ) ) // before render() $this->render_tpl( $options->render_tpl ); + // This runs last so we can have 'settings-page' with custom render_tpl + if ( isset( $options->render ) ) + $this->render( $options->render ); + + if (true) $this->render(); // render anyway - will use default tpl if render is empty if (true) $this->wrap(); // set wrap anyway - will set to 'none' if empty + if ( isset( $options->parent ) ) $this->parent( $options->parent ); @@ -228,6 +259,11 @@ class AdminPage if ( isset( $options->position ) ) $this->position( $options->position ); + if ( isset( $options->tab_group ) ){ + $this->tab_group( $options->tab_group ); + $this->tab_title( $options->tab_title ?? $options->submenu_title ?? $options->menu_title ); + } + if ( isset( $options->scripts ) ) $this->scripts( $options->scripts ); @@ -253,8 +289,8 @@ class AdminPage * * @access private */ - private function title( $title ) { - $this->title = $title; + private function title( $title=null ) { + $this->title = $title ?? ( isset( $this->plugin_core ) ? $this->plugin_core->title() : __METHOD__ ); } /** @@ -284,7 +320,19 @@ class AdminPage * @access private */ private function slug( $slug ) { - $this->slug = $slug; + + $this->slug = $slug // if not empty + ?: $this->settings['option_key'] // if isset option_key + ?? ( + isset( $this->plugin_core ) + ? ( + method_exists( PluginCore::class, 'token' ) + ? $this->plugin_core->token() // PluginCore ~0.25 + : str_replace('-','_', strtolower( $this->plugin_core->slug() ) ) // PluginCore <= 0.24 + ) + : 'slug' . time() // unique slug + ); + } /** @@ -316,7 +364,6 @@ class AdminPage $this->icon_url = $icon_url; } - /** * Setter - position * WordPress admin menu param @@ -327,6 +374,44 @@ class AdminPage $this->position = $position; } + /** + * Setter - tab_group + * CMB2 Tab Group - used by regular 'wrap' pages as well. + * + * @access private + */ + private function tab_group( $tab_group ) { + $this->tab_group = $tab_group; + + add_filter( 'cmb2_tab_group_tabs', [ $this, 'add_to_tab_group' ], 10, 2 ); + add_action( 'cmb2_admin_init', function(){ + /** + * When deactivating CMB2 and reactivating - got this fatal error: + * + * Fatal error: Uncaught Error: Argument 1 passed to CMB2_Options_Hookup::__construct() + * must be an instance of CMB2, bool given, + * called in \wp-content\plugins\cgv\inc\CGV.php on line 56 + * in \wp-content\plugins\cmb2\includes\CMB2_Options_Hookup.php on line 39 + * + * Validate cmb2_get_metabox did not return false. + */ + if ( $cmb = cmb2_get_metabox( $this->parent ) ){ + $hookup = new CMB2_Options_Hookup( $cmb, $this->slug ); + add_action ( 'wphelper/adminpage/tab_nav', [ $hookup, 'options_page_tab_nav_output' ] ); + } + }); + } + + /** + * Setter - tab_title + * CMB2 Tab Title - only set if tab_group. + * + * @access private + */ + private function tab_title( $tab_title ) { + $this->tab_title = $tab_title; + } + /** * Setter - render * Sets render cb or tpl @@ -340,34 +425,30 @@ class AdminPage */ private function render( $render=null ) { if ( 'settings-page' == $render ) { - $this->render_tpl( __DIR__ . '/tpl/settings-form.php' ); + $this->render_tpl( __DIR__ . '/tpl/form-basic.php' ); $this->render = $this->render ?? $render; // 'settings-page' } else if ( 'cmb2' == $render || 'cmb2-tabs' == $render ) { // validate if ( ! defined( 'CMB2_LOADED' ) ){ - $this->render_tpl( __DIR__ . '/tpl/cmb2-unavailable.php' ); + $this->render_tpl( __DIR__ . '/tpl/wrap-cmb2-unavailable.php' ); $this->render = $this->render ?? 'render_tpl'; } else { - $this->delegate_hookup = true; - - if ( ! empty( $this->plugin_core ) || ! empty( $this->plugin_info ) ){ - $this->render_tpl( __DIR__ . '/tpl/cmb2_options_page-plugin_info.php' ); - } else { - $this->render_tpl( __DIR__ . '/tpl/cmb2_options_page.php' ); - } - + /** + * Render templates managed and included by CMB2_OptionsPage + * @see CMB2_OptionsPage::options_page_output() + */ $this->render = $this->render ?? $render; // 'cmb2' || 'cmb2-tabs' } } else if( is_callable( $render ) ) { $this->render_cb( $render ); $this->render = $this->render ?? 'render_cb'; - } else if ( is_readable( $render ) ) { + } else if ( is_readable( $render ?? '' ) ) { $this->render_tpl( $render ); $this->render = $this->render ?? 'render_tpl'; } else { - $this->render_tpl( __DIR__ . '/tpl/default.php' ); + $this->render_tpl( __DIR__ . '/tpl/wrap-default.php' ); $this->render = $this->render ?? 'render_tpl'; } } @@ -465,11 +546,23 @@ class AdminPage if( is_callable( $plugin_info ) ) $this->plugin_info = $plugin_info; - // if true-y value passed and PluginCore class exists - set to true - else if (!empty($plugin_info) && class_exists('WPHelper\PluginCore')) + // if true-y value passed and plugin_core isset + else if ( ! empty( $plugin_info ) && ! empty( $this->plugin_core ) ) $this->plugin_info = true; } + /** + * Add to tab group + * + * @hook cmb2_tab_group_tabs + */ + public function add_to_tab_group( $tabs, $tab_group ){ + if ( $tab_group == $this->tab_group ){ + $tabs[ $this->slug ] = $this->tab_title; + } + return $tabs; + } + /** * Setter - scripts * Scripts to enqueue on admin page @@ -501,7 +594,7 @@ class AdminPage } function plugin_core($plugin_core){ - if ( is_a( $plugin_core, 'WPHelper\PluginCore') ){ + if ( $plugin_core instanceof PluginCore ){ $this->plugin_core = $plugin_core; } } @@ -525,13 +618,18 @@ class AdminPage 'capability' => $this->capability, 'slug' => $this->slug, 'parent' => $this->parent, + 'hook_suffix' => $this->hook_suffix, 'icon_url' => $this->icon_url, 'position' => $this->position, 'render' => $this->render, // render_cb | render_tpl | settings-page | cmb2 | cmb2-tabs 'render_cb' => $this->render_cb, 'render_tpl' => $this->render_tpl, 'settings' => $this->settings, + 'wrap' => $this->wrap, + 'tab_group' => $this->tab_group, + 'tab_title' => $this->tab_title, 'plugin_core' => $this->plugin_core, + 'plugin_info' => $this->plugin_info, ]; return $options; @@ -570,37 +668,30 @@ class AdminPage if ( ! $this->capability ) $this->capability = 'manage_options'; - if ( $this->render == 'settings-page' ){ + add_action( "wphelper/adminpage/plugin_info_box/{$this->slug}" , [ $this , 'render_plugin_info_meta_box' ] ); - $this->settings_page = new SettingsPage($this); - $this->settings_page->setup(); + /** + * @todo Perhaps this can hook on admin_init - right after admin_menu has finished + * @todo CMB2 options-page does not return page_hook/hook_suffix - MUST validate + */ + add_action ( 'admin_init' , [ $this , '_bootstrap_admin_page' ] ); - } + if ( in_array( $this->render, [ 'cmb2', 'cmb2-tabs' ] ) ){ - add_action( "wphelper/adminpage/plugin_info_box/{$this->slug}" , [ $this , 'render_plugin_info_box' ] ); - - // if ( $this->delegate_hookup ){ - if ( 'cmb2' == $this->render || 'cmb2-tabs' == $this->render ){ - - if ( isset( $this->settings['options_type'] ) && $this->settings['options_type'] == 'multi' ) { - $this->cmb2_page = new CMB2_OptionsPage_Multi( $this ); - } else { - $this->cmb2_page = new CMB2_OptionsPage( $this ); - } - - /** - * @todo Perhaps this can hook on admin_init - right after admin_menu has finished - * @todo CMB2 options-page does not return page_hook/hook_suffix - MUST validate - */ - add_action ( 'admin_menu' , [ $this , '_bootstrap_admin_page' ], 12 ); + $this->cmb2_page = $this->settings['options_type'] ?? '' == 'multi' + ? new CMB2_OptionsPage_Multi( $this ) + : new CMB2_OptionsPage( $this ); // skip add_menu_page return; } - // if ( ! $this->delegate_hookup ){ + if ( $this->render == 'settings-page' ){ + $this->settings_page = new SettingsPage($this); + } + add_action ( 'admin_menu' , [ $this , 'add_menu_page' ], 11 ); - add_action ( 'admin_menu' , [ $this , '_bootstrap_admin_page' ], 12 ); + add_action ( 'admin_menu' , [ $this , 'add_plugin_info_meta_box' ], 11 ); } @@ -644,6 +735,21 @@ class AdminPage ); break; } + } + + /** + * + */ + public function add_plugin_info_meta_box() { + $metabox_args = [ + 'id' => $this->slug . '_plugin_info_meta_box', // id is unique (in case a plugin uses $this->slug) + 'title' => 'Plugin Info', + 'context' => 'side', + 'screens' => [ $this->get_hook_suffix() ], + // 'template', + 'render' => [ $this , 'render_plugin_info_meta_box_inside' ], + ]; + ( new MetaBox($metabox_args) )->add(); } @@ -653,14 +759,6 @@ class AdminPage */ public function validate_page_hook(){ - /** - * hack! - * This is ad hoc validation - should do this earlier - */ - if ( empty( $this->slug ) ){ - $this->slug = $this->settings['option_key']; - } - if ( empty( $this->hook_suffix ) ){ $this->hook_suffix = get_plugin_page_hookname( $this->slug, $this->parent ); } @@ -678,14 +776,9 @@ class AdminPage * * @hook admin_menu priority 12 * @access private - * - * @todo move this function to admin_init - after admin_menu has finished */ public function _bootstrap_admin_page(){ - /** - * @todo perhaps run this on 'admin_init' - */ $this->validate_page_hook(); add_action ( 'load-' . $this->hook_suffix , [ $this , '_admin_page_setup' ] ); @@ -854,19 +947,21 @@ class AdminPage */ public function render_admin_page() { - // @todo if render callback supplied - add shortcircuit hook here - // execute render callback and return early + // if wrap - 1. We collect output buffer if ( 'none' != $this->wrap ){ ob_start(); } + //---------------------------[The McGuffin]---------------------------------// if ( isset( $this->render_cb ) && is_callable( $this->render_cb ) ) { call_user_func( $this->render_cb ); } else if ( isset( $this->render_tpl ) && is_readable( $this->render_tpl ) ) { include $this->render_tpl; } + //---------------------------[The McGuffin]---------------------------------// + // if wrap - 2. include chosen wrap template if ( 'none' != $this->wrap ){ $ob_content = ob_get_clean(); @@ -885,7 +980,21 @@ class AdminPage } /** - * Render plugin info metabox + * + * @see render_plugin_info_meta_box() + * @deprecated + */ + public function render_plugin_info_box(){ + + _doing_it_wrong( __METHOD__, 'Deprecated. Use render_plugin_info_meta_box() instead.', '0.26' ); + + $this->render_plugin_info_meta_box(); + } + + + + /** + * Render plugin info meta-box * * Call user-provided callable. * Or else attempt to create PluginInfoMetaBox class from $this->plugin_core and call its render function. @@ -895,17 +1004,55 @@ class AdminPage * @todo See if this function should be public API or only run on action hook * @todo deprecate public use - use wphelper/adminpage/plugin_info_box/{$this->slug} instead */ - public function render_plugin_info_box(){ + public function render_plugin_info_meta_box(){ if ( isset( $this->plugin_info ) && is_callable( $this->plugin_info ) ) { call_user_func( $this->plugin_info ); } else { - if ( ! empty( $this->plugin_core ) && empty( $this->plugin_info_meta_box ) ){ - $this->plugin_info_meta_box = new PluginInfoMetaBox( $this->plugin_core ); + + if (!$this->bootstrap_plugin_info_meta_box()){ + return; } - $this->plugin_info_meta_box->plugin_info_box(); + + /** + * Allow plugins to modify plugin info meta box + * + * @since 0.23 + */ + do_action( "wphelper/plugin_info_meta_box/{$this->plugin_core->slug()}" ); + } + } + + /** + * + */ + public function render_plugin_info_meta_box_inside(){ + if ( isset( $this->plugin_info ) && is_callable( $this->plugin_info ) ) { + call_user_func( $this->plugin_info ); + } else { + + if (!$this->bootstrap_plugin_info_meta_box()){ + return; + } + + do_action( "wphelper/plugin_info_meta_box/inside/{$this->plugin_core->slug()}" ); + } + } + + /** + * Bootstrap PluginInfoMetaBox + */ + private function bootstrap_plugin_info_meta_box() { + if ( empty( $this->plugin_info_meta_box ) && ! empty( $this->plugin_core ) ){ + $this->plugin_info_meta_box = new PluginInfoMetaBox( $this->plugin_core ); } + // If no plugin_info_meta_box - return false + if ( empty( $this->plugin_info_meta_box ) ) { + return false; + } + + return true; } } endif; \ No newline at end of file diff --git a/vendor/abuyoyo/adminmenupage/src/CMB2_OptionsPage.php b/vendor/abuyoyo/adminmenupage/src/CMB2_OptionsPage.php index 2601922..bd79663 100644 --- a/vendor/abuyoyo/adminmenupage/src/CMB2_OptionsPage.php +++ b/vendor/abuyoyo/adminmenupage/src/CMB2_OptionsPage.php @@ -4,9 +4,9 @@ namespace WPHelper; defined( 'ABSPATH' ) || die( 'No soup for you!' ); use CMB2; -use CMB2_Options_Hook; +use CMB2_Options_Hookup; -if ( ! class_exists( 'WPHelper\CMB2_OptionsPage' ) ): +if ( ! class_exists( CMB2_OptionsPage::class ) ): /** * CMB2_OptionsPage * @@ -26,11 +26,21 @@ class CMB2_OptionsPage{ */ public $admin_page; + /** + * @var array $fields + */ + protected $fields; + /** * @var CMB2 $cmb */ private $cmb; + /** + * @var array $cmb2_options + */ + protected $cmb2_options; + /** * @param AdminPage $admin_page */ @@ -48,6 +58,8 @@ class CMB2_OptionsPage{ $settings['option_key'] ??= ( $settings['option_name'] ?? ( $settings['id'] ?? $admin_options['slug'] ) ); $settings['title'] ??= $admin_options['title']; $settings['menu_title'] ??= $admin_options['menu_title']; + // @todo Only if cmb2-tabs + $settings['tab_title'] ??= $admin_options['tab_title'] ?? $settings['submenu_title'] ?? $settings['menu_title']; $settings['parent_slug'] ??= $admin_options['parent']; $settings['position'] ??= $admin_options['position']; $settings['icon_url'] ??= $admin_options['icon_url']; @@ -63,7 +75,8 @@ class CMB2_OptionsPage{ /** * CMB2 only accepts url slug * - * @todo export parent_slug convertion to dedicated method + * @todo export parent_slug conversion to dedicated method + * @todo perhaps move this to AdminPage::parent() method */ switch ( $settings['parent_slug'] ) { case 'dashboard': @@ -116,11 +129,11 @@ class CMB2_OptionsPage{ $settings['tab_title'] ??= $settings['menu_title']; } + $this->fields = $settings['fields'] ?? []; + /** + * @todo revisit this - might not need to unset fields + */ if ( isset( $settings['fields'] ) ){ - $this->fields = $settings['fields']; - /** - * @todo revisit this - might not need to unset fields - */ unset( $settings['fields'] ); } @@ -198,12 +211,20 @@ class CMB2_OptionsPage{ /** * Display options-page output. To override, set 'display_cb' box property. * - * @param CMB2_Options_Hook $hookup - instance of Options Page Hookup class (caller of this function) + * @param CMB2_Options_Hookup $hookup - instance of Options Page Hookup class (caller of this function) * - * @see CMB2_Options_Hook + * @see CMB2_Options_Hookup */ public function options_page_output( $hookup ) { - include $this->admin_page->get_render_tpl(); + + $options = $this->admin_page->options(); + + if ( ! empty( $options['plugin_core'] ) || ! empty( $options['plugin_info'] ) ){ + include __DIR__ . '/tpl/wrap-cmb2-sidebar.php'; + } else { + include __DIR__ . '/tpl/wrap-cmb2-simple.php'; + } + } diff --git a/vendor/abuyoyo/adminmenupage/src/CMB2_OptionsPage_Multi.php b/vendor/abuyoyo/adminmenupage/src/CMB2_OptionsPage_Multi.php index 919c60b..f323e8e 100644 --- a/vendor/abuyoyo/adminmenupage/src/CMB2_OptionsPage_Multi.php +++ b/vendor/abuyoyo/adminmenupage/src/CMB2_OptionsPage_Multi.php @@ -3,9 +3,13 @@ namespace WPHelper; defined( 'ABSPATH' ) || die( 'No soup for you!' ); -include_once __DIR__ . '/CMB2_Override_Meta.php'; +if ( ! class_exists( CMB2_OptionsPage_Multi::class ) ): + +// Require dependency CMB2_Override_Meta +if ( ! trait_exists( CMB2_Override_Meta::class ) ) { + require_once __DIR__ . '/CMB2_Override_Meta.php'; +} -if ( ! class_exists( 'WPHelper\CMB2_OptionsPage_Multi' ) ): /** * CMB2_OptionsPage - MULTI * diff --git a/vendor/abuyoyo/adminmenupage/src/CMB2_Override_Meta.php b/vendor/abuyoyo/adminmenupage/src/CMB2_Override_Meta.php index 4074e23..abff69e 100644 --- a/vendor/abuyoyo/adminmenupage/src/CMB2_Override_Meta.php +++ b/vendor/abuyoyo/adminmenupage/src/CMB2_Override_Meta.php @@ -3,7 +3,7 @@ namespace WPHelper; defined( 'ABSPATH' ) || die( 'No soup for you!' ); -if ( ! trait_exists('CMB2_Override_Meta') ): +if ( ! trait_exists( CMB2_Override_Meta::class ) ): /** * CMB2 Options page override meta * diff --git a/vendor/abuyoyo/adminmenupage/src/PluginInfoMetaBox.php b/vendor/abuyoyo/adminmenupage/src/PluginInfoMetaBox.php index ce5ad09..952deb9 100644 --- a/vendor/abuyoyo/adminmenupage/src/PluginInfoMetaBox.php +++ b/vendor/abuyoyo/adminmenupage/src/PluginInfoMetaBox.php @@ -2,27 +2,72 @@ namespace WPHelper; use DateTime; -use function get_plugin_data; -if ( ! class_exists( 'WPHelper\PluginInfoMetaBox' ) ): +if ( ! class_exists( PluginInfoMetaBox::class ) ): /** * Plugin Info Metabox * * Get instance of PluginCore * Render default plugin info box template. + * + * @since 0.14 */ class PluginInfoMetaBox{ private $tpl = '/tpl/plugin_info_meta_box.php'; + private $tpl_inside = '/tpl/plugin_info_meta_box-inside.php'; + /** * @var PluginCore */ - private $plugin_core; + public $plugin_core; function __construct( PluginCore $plugin_core ) { $this->plugin_core = $plugin_core; + + /** + * Allow plugins to render or modify plugin info box + * + * Call: do_action('wphelper/plugin_info_meta_box/{$slug}') + * action used in AdminPage::render_plugin_info_meta_box() + * + * @since 0.23 + */ + add_action( "wphelper/plugin_info_meta_box/{$this->plugin_core->slug()}", [ $this, 'plugin_info_box' ] ); + + add_action( "wphelper/plugin_info_meta_box/inside/{$this->plugin_core->slug()}", [ $this, 'inside' ] ); + } + + /** + * Setup args used in template. + * + * @todo move 'repo' setup to method from template + */ + function setup_template_args() { + + $plugin_data = $this->plugin_core->plugin_data(); + + + $last_update = $plugin_data['Last Update'] ?: $plugin_data['Release Date']; + $last_update = DateTime::createFromFormat('Y_m_d', $last_update); + + if ($last_update) { + $diff = (int) abs( time() - $last_update->format('U') ); + + if ( $diff < (DAY_IN_SECONDS) ){ + $update_message = 'Today'; + }elseif ($diff < (2 * DAY_IN_SECONDS)){ + $update_message = 'Yesterday'; + }else{ + $update_message = human_time_diff($last_update->format('U')) . ' ago'; + } + } else { + $update_message = ''; + } + return compact('plugin_data','update_message'); + } /** @@ -33,33 +78,25 @@ class PluginInfoMetaBox{ * @since iac_engine 1.1.0 * @since iac_engine 1.2.0 plugin_info_box now a function * @since iac_engine 1.3.0 use 'Last Update' header + * @since 0.14 PluginInfoMetaBox::plugin_info_box() + * + * @todo rename method render() */ function plugin_info_box(){ - - $plugin_data = get_plugin_data( $this->plugin_core->file() , false ); // false = no markup (i think) - - - $last_update = $plugin_data['Last Update'] ?: $plugin_data['Release Date']; - $last_update = DateTime::createFromFormat('Y_m_d', $last_update); - - // $last_update = new DateTime('now'); - // $last_update->add(new DateInterval('P1D')); - // $last_update->add(new DateInterval('P2D')); - if ($last_update): - $diff = (int) abs( time() - $last_update->format('U') ); - - if ( $diff < (DAY_IN_SECONDS) ){ - $update_message = 'Today'; - }elseif ($diff < (2 * DAY_IN_SECONDS)){ - $update_message = 'Yesterday'; - }else{ - $update_message = human_time_diff($last_update->format('U')) . ' ago'; - } - else: - $update_message = ''; - endif; - + $args = $this->setup_template_args(); + extract($args); include __DIR__ . $this->tpl; } + + + /** + * Only print meta-box .inside + * No header. + */ + function inside(){ + $args = $this->setup_template_args(); + extract($args); + include __DIR__ . $this->tpl_inside; + } } endif; \ No newline at end of file diff --git a/vendor/abuyoyo/adminmenupage/src/SettingsPage.php b/vendor/abuyoyo/adminmenupage/src/SettingsPage.php index 1606aa0..b5686d4 100644 --- a/vendor/abuyoyo/adminmenupage/src/SettingsPage.php +++ b/vendor/abuyoyo/adminmenupage/src/SettingsPage.php @@ -9,7 +9,7 @@ use function add_settings_field; use function checked; use function get_option; -if ( ! class_exists( 'WPHelper\SettingsPage' ) ): +if ( ! class_exists( SettingsPage::class ) ): /** * SettingsPage * @@ -64,6 +64,13 @@ class SettingsPage{ */ public $fields = []; + /** + * Sanitize Callback + * + * @var Callable $sanitize_callback + */ + public $sanitize_callback; + /** * Constructor. * @@ -89,18 +96,20 @@ class SettingsPage{ $this->option_group = $settings['option_group'] ?? $this->page . '_option_group'; - foreach ( $settings['sections'] as $section ) { + $this->sanitize_callback = $settings['sanitize_callback'] ?? null; + + // PHP Warning: foreach() argument must be of type array|object + foreach ( $settings['sections'] ?? [] as $section ) { // extract fields foreach ( $section['fields'] as $field ){ $field['section_id'] = $section['id']; // create back-reference in field to section. ( @see add_settings_field() ) + $field['name'] = $this->option_name . '[' . $field['id'] . ']'; $this->fields[] = $field; } unset( $section['fields'] ); $this->sections[] = $section; // save without fields } - } - function setup() { add_action( 'admin_init', [ $this, 'register_settings' ] ); } @@ -108,7 +117,7 @@ class SettingsPage{ register_setting( $this->option_group, // $option_group - A settings group name. Must exist prior to the register_setting call. This must match the group name in settings_fields() $this->option_name, // $option_name - The name of an option to sanitize and save. - [ $this,'sanitize_settings' ] // $sanitize_callback - A callback function that sanitizes the option's value. (see also: built-in php callbacks) + $this->sanitize_callback ?? [ $this,'sanitize_settings' ] // callback ?? fallback // $sanitize_callback - A callback function that sanitizes the option's value. (see also: built-in php callbacks) ); foreach ( $this->sections as $section ){ @@ -125,7 +134,7 @@ class SettingsPage{ add_settings_field( $field['id'], $field['title'], - [ $this, "print_{$field['type']}" ], + $field['render'] ?? [ $this, "print_{$field['type']}" ], $this->page, // can built-in pages: (general, reading, writing, ...) $field['section_id'], $field //send setting array as $args for print function @@ -135,8 +144,8 @@ class SettingsPage{ } /** - * Print text input field - * Support field type 'text' + * Print checkbox input field + * Support field type 'checkbox' * * @since 0.11 */ @@ -147,10 +156,11 @@ class SettingsPage{ $input_tag = sprintf( '', + + %3$s + ', $id, - $this->option_name, + $name, $description, checked( ( $options[$id] ?? false ), '1', false) ); @@ -176,10 +186,11 @@ class SettingsPage{ $options = get_option( $this->option_name ); $input_tag = sprintf( - '', + '', $id, - $this->option_name, - $default + $name, + $options[$id] ?: $default ?? '', + $placeholder ?? '' ); if ( ! empty( $description ) ) { @@ -211,10 +222,11 @@ class SettingsPage{ $options = get_option( $this->option_name ); $input_tag = sprintf( - '', + '', $id, - $this->option_name, - $default + $name, + $options[$id] ?: $default ?? '', + $placeholder ?? '' ); if ( ! empty( $description ) ) { @@ -246,10 +258,11 @@ class SettingsPage{ $options = get_option( $this->option_name ); $input_tag = sprintf( - '', + '', $id, - $this->option_name, - $default + $name, + $options[$id] ?: $default ?? '', + $placeholder ?? '' ); if ( ! empty( $description ) ) { @@ -269,6 +282,42 @@ class SettingsPage{ } + /** + * Print email input field + * Support field type 'email' + * + * @since 0.23 + */ + function print_textarea( $field ){ + extract($field); + + $options = get_option( $this->option_name ); + + $textarea = sprintf( + '', + $id, + $name, + $options[$id] ?: $default ?? '', + $placeholder ?? '' + ); + + if ( ! empty( $description ) ) { + $textarea .= sprintf( + '

%2$s

', + $id, + $description + ); + } + + /** + * Allow plugins to directly manipulate field HTML + */ + $textarea = apply_filters( 'wphelper/settings_page/textarea', $textarea, $field, $this->option_name, $options ); + + echo $textarea; + + } + /** * Sanitizes entire $options array. */ @@ -276,17 +325,18 @@ class SettingsPage{ $new_options = []; foreach( $options as $id => $option ) { - $field = reset( + $field = current( array_filter( $this->fields, fn($item) => $item['id'] == $id ) ); - switch ( $field['type'] ){ + switch ( $field['type'] ) { case 'checkbox': $new_options[$id] = $option == 1 ? 1 : 0; break; case 'text': + case 'textarea': $new_options[$id] = sanitize_text_field( $option ); break; case 'email': diff --git a/vendor/abuyoyo/adminmenupage/src/tpl/cmb2_options_page.php b/vendor/abuyoyo/adminmenupage/src/tpl/cmb2_options_page.php deleted file mode 100644 index f803a81..0000000 --- a/vendor/abuyoyo/adminmenupage/src/tpl/cmb2_options_page.php +++ /dev/null @@ -1,13 +0,0 @@ - -
- - - -
\ No newline at end of file diff --git a/vendor/abuyoyo/adminmenupage/src/tpl/settings-form.php b/vendor/abuyoyo/adminmenupage/src/tpl/form-basic.php similarity index 100% rename from vendor/abuyoyo/adminmenupage/src/tpl/settings-form.php rename to vendor/abuyoyo/adminmenupage/src/tpl/form-basic.php diff --git a/vendor/abuyoyo/adminmenupage/src/tpl/cmb-form.php b/vendor/abuyoyo/adminmenupage/src/tpl/form-cmb2.php similarity index 100% rename from vendor/abuyoyo/adminmenupage/src/tpl/cmb-form.php rename to vendor/abuyoyo/adminmenupage/src/tpl/form-cmb2.php diff --git a/vendor/abuyoyo/adminmenupage/src/tpl/plugin_info_meta_box-inside.php b/vendor/abuyoyo/adminmenupage/src/tpl/plugin_info_meta_box-inside.php new file mode 100644 index 0000000..fe18e6c --- /dev/null +++ b/vendor/abuyoyo/adminmenupage/src/tpl/plugin_info_meta_box-inside.php @@ -0,0 +1,27 @@ + +

+

+ + Version:
+ + + Author: + +
+ +
+ + + + Repo: + $plugin_core->slug(); ?> +
+ + + Last Updated: + +

\ No newline at end of file diff --git a/vendor/abuyoyo/adminmenupage/src/tpl/plugin_info_meta_box.php b/vendor/abuyoyo/adminmenupage/src/tpl/plugin_info_meta_box.php index 028ca03..27d7870 100644 --- a/vendor/abuyoyo/adminmenupage/src/tpl/plugin_info_meta_box.php +++ b/vendor/abuyoyo/adminmenupage/src/tpl/plugin_info_meta_box.php @@ -3,25 +3,10 @@ * Plugin Info Metabox */ ?> -
-

Plugin Info

+

Plugin Info

-

-

- Version:
- Author:
- GitHub:
- Last Updated: -

+
\ No newline at end of file diff --git a/vendor/abuyoyo/adminmenupage/src/tpl/sidebar-add-meta-boxes.php b/vendor/abuyoyo/adminmenupage/src/tpl/sidebar-add-meta-boxes.php new file mode 100644 index 0000000..5174c1e --- /dev/null +++ b/vendor/abuyoyo/adminmenupage/src/tpl/sidebar-add-meta-boxes.php @@ -0,0 +1,41 @@ + + +get_hook_suffix(), 'side' ); + +/** + * Remove 'Featured Image' meta-box added by core. + * + * @see register_and_do_post_meta_boxes() (wp-admin/includes/meta-boxes.php) + * @todo Investigate why $thumbnail_support returns true for our pages. + */ +remove_meta_box( 'postimagediv', $this->get_hook_suffix(), 'side' ); + +/** + * Render meta-boxes + * + * Renders div.meta-box-sortables + */ +do_meta_boxes( $this->get_hook_suffix(), 'side', null ); diff --git a/vendor/abuyoyo/adminmenupage/src/tpl/tab-nav.php b/vendor/abuyoyo/adminmenupage/src/tpl/tab-nav-cmb2.php similarity index 86% rename from vendor/abuyoyo/adminmenupage/src/tpl/tab-nav.php rename to vendor/abuyoyo/adminmenupage/src/tpl/tab-nav-cmb2.php index 0d41046..f2681f9 100644 --- a/vendor/abuyoyo/adminmenupage/src/tpl/tab-nav.php +++ b/vendor/abuyoyo/adminmenupage/src/tpl/tab-nav-cmb2.php @@ -4,7 +4,7 @@ * * Print tabs navigation row. * - * @var CMB2_Options_Hook $hookup + * @var CMB2_Options_Hookup $hookup */ if ( ! isset( $hookup ) ){ return; diff --git a/vendor/abuyoyo/adminmenupage/src/tpl/tab-nav-simple.php b/vendor/abuyoyo/adminmenupage/src/tpl/tab-nav-simple.php new file mode 100644 index 0000000..af7c4b3 --- /dev/null +++ b/vendor/abuyoyo/adminmenupage/src/tpl/tab-nav-simple.php @@ -0,0 +1,5 @@ +cmb->prop( 'title' ) ) { echo '

' . wp_kses_post( $this->cmb->prop( 'title' ) ) . '

'; diff --git a/vendor/abuyoyo/adminmenupage/src/tpl/cmb2_options_page-plugin_info.php b/vendor/abuyoyo/adminmenupage/src/tpl/wrap-cmb2-sidebar.php similarity index 85% rename from vendor/abuyoyo/adminmenupage/src/tpl/cmb2_options_page-plugin_info.php rename to vendor/abuyoyo/adminmenupage/src/tpl/wrap-cmb2-sidebar.php index 35d5074..d7d4347 100644 --- a/vendor/abuyoyo/adminmenupage/src/tpl/cmb2_options_page-plugin_info.php +++ b/vendor/abuyoyo/adminmenupage/src/tpl/wrap-cmb2-sidebar.php @@ -2,8 +2,8 @@ /** * Template for CMB2 Options Page * - * @var WPHelper\CMB2_Options_Page $this - * @var CMB2_Options_Hook $hookup + * @var WPHelper\CMB2_OptionsPage $this + * @var CMB2_Options_Hookup $hookup */ ?>
- - + +
@@ -26,7 +26,7 @@
- +
diff --git a/vendor/abuyoyo/adminmenupage/src/tpl/wrap-cmb2-simple.php b/vendor/abuyoyo/adminmenupage/src/tpl/wrap-cmb2-simple.php new file mode 100644 index 0000000..e6672f6 --- /dev/null +++ b/vendor/abuyoyo/adminmenupage/src/tpl/wrap-cmb2-simple.php @@ -0,0 +1,13 @@ + +
+ + + +
\ No newline at end of file diff --git a/vendor/abuyoyo/adminmenupage/src/tpl/cmb2-unavailable.php b/vendor/abuyoyo/adminmenupage/src/tpl/wrap-cmb2-unavailable.php similarity index 100% rename from vendor/abuyoyo/adminmenupage/src/tpl/cmb2-unavailable.php rename to vendor/abuyoyo/adminmenupage/src/tpl/wrap-cmb2-unavailable.php diff --git a/vendor/abuyoyo/adminmenupage/src/tpl/default.php b/vendor/abuyoyo/adminmenupage/src/tpl/wrap-default.php similarity index 84% rename from vendor/abuyoyo/adminmenupage/src/tpl/default.php rename to vendor/abuyoyo/adminmenupage/src/tpl/wrap-default.php index 9131945..56badc6 100644 --- a/vendor/abuyoyo/adminmenupage/src/tpl/default.php +++ b/vendor/abuyoyo/adminmenupage/src/tpl/wrap-default.php @@ -1,3 +1,10 @@ +

diff --git a/vendor/abuyoyo/adminmenupage/src/tpl/wrap-sidebar.php b/vendor/abuyoyo/adminmenupage/src/tpl/wrap-sidebar.php index caa493b..37e1675 100644 --- a/vendor/abuyoyo/adminmenupage/src/tpl/wrap-sidebar.php +++ b/vendor/abuyoyo/adminmenupage/src/tpl/wrap-sidebar.php @@ -3,12 +3,12 @@ * Template for CMB2 Options Page * * @var string $ob_content - Render template or callback - * @var AdminPage $this + * @var WPHelper\AdminPage $this */ ?>

- +
@@ -21,9 +21,7 @@
-
- get_slug()}"); ?> -
+
diff --git a/vendor/abuyoyo/adminmenupage/src/tpl/wrap-simple.php b/vendor/abuyoyo/adminmenupage/src/tpl/wrap-simple.php index cfdf6b7..9eeb918 100644 --- a/vendor/abuyoyo/adminmenupage/src/tpl/wrap-simple.php +++ b/vendor/abuyoyo/adminmenupage/src/tpl/wrap-simple.php @@ -1,10 +1,12 @@

- +
\ No newline at end of file diff --git a/vendor/abuyoyo/plugincore/CHANGELOG.md b/vendor/abuyoyo/plugincore/CHANGELOG.md index 5d0d976..249e5c0 100644 --- a/vendor/abuyoyo/plugincore/CHANGELOG.md +++ b/vendor/abuyoyo/plugincore/CHANGELOG.md @@ -1,5 +1,23 @@ # WPHelper\PluginCore Changelog +## 0.26 +Release Date: Jun 9, 2023 + +### Fixed +- Fix passing PluginCore instance to AdminPage constructor in `admin_page()` method. + +## 0.25 +Release Date: Feb 3, 2023 + +### Added +- Property `token` and method `token`. Lowercase underscore token to be used as variable name. + +## 0.24 +Release Date: Jan 13, 2023 + +### Added +- Static `get_by_file` method. Get PluginCore instance by plugin filename. + ## 0.23 Release Date: Aug 8, 2022 diff --git a/vendor/abuyoyo/plugincore/PluginCore.php b/vendor/abuyoyo/plugincore/PluginCore.php index b60e654..5013873 100644 --- a/vendor/abuyoyo/plugincore/PluginCore.php +++ b/vendor/abuyoyo/plugincore/PluginCore.php @@ -1,24 +1,25 @@ $core->file() == $filename + ) + ) ?: null; + } + + /** + * Constructor + * + * @since 0.1 + * @since 0.2 Accept filename as first param and options array as optional param + */ function __construct( $plugin_file, $options = null ) { $this->plugin_file( $plugin_file ); @@ -141,6 +176,8 @@ class PluginCore { $this->const( $options->const ?? null ); // fallback: generate const from slug + $this->token( $options->token ?? null ); // fallback: generate token from slug + if ( isset( $options->activate_cb ) ) $this->activate_cb( $options->activate_cb ); @@ -177,6 +214,9 @@ class PluginCore { * Register activation, deactivation, uninstall, upgrade hooks. * Init PUC update checker. * + * @since 0.1 setup() + * @since 0.21 bootstrap() + * * @todo set plugin_dir_path, plugin_basename as accessible public variables (available thru methods atm) */ private function bootstrap() { @@ -216,6 +256,11 @@ class PluginCore { } } + /** + * Register activation/deactivation/uninstall/upgrade hooks + * + * @since 0.5 + */ private function register_hooks() { if ( ! empty( $this->activate_cb ) ) // && is_callable() ? @@ -236,6 +281,8 @@ class PluginCore { * Plugin title. * If none provided - plugin header Title will be used. * + * @since 0.1 + * * @param string|null $title * @return string $this->title */ @@ -246,6 +293,8 @@ class PluginCore { /** * Wrapper function for $this->title() * + * @since 0.6 + * * @deprecated */ public function name( $title = null ) { @@ -258,6 +307,8 @@ class PluginCore { * Plugin slug. * If none provided - plugin file basename will be used * + * @since 0.1 + * * @param string|null $slug * @return string $this->slug */ @@ -269,6 +320,8 @@ class PluginCore { * Setter - plugin_file (also Getter - kinda) * Plugin file fully qualified path. * + * @since 0.1 + * * @param string $plugin_file - Path to plugin file * @return string $this->plugin_file */ @@ -281,6 +334,8 @@ class PluginCore { * Might have to rethink this * used by test-plugin update_checker * + * @since 0.7 + * * @todo revisit this */ public function file() { @@ -290,9 +345,11 @@ class PluginCore { /** * Getter/Setter - plugin data array + * + * @since 0.14 */ public function plugin_data() { - return $this->plugin_data ??= get_plugin_data( $this->plugin_file, false); + return $this->plugin_data ??= get_plugin_data( $this->plugin_file, false ); // false = no markup (i think) } /** @@ -300,6 +357,8 @@ class PluginCore { * Prefix of plugin specific defines (PLUGIN_NAME_PATH etc.) * If not provided - plugin slug will be uppercase. * + * @since 0.4 + * * @param string|null $const (string should be uppercase) * @return string $this->const */ @@ -307,8 +366,23 @@ class PluginCore { return $this->const ??= $const ?: str_replace( '-', '_' , strtoupper( $this->slug() ) ); } + /** + * Getter/Setter - token + * Create a single-token slug (convert to underscore + lowercase). + * + * @since 0.25 + * + * @param string|null $token (string will be normalized) + * @return string $this->token + */ + public function token( $token = null ) { + return $this->token ??= str_replace( '-', '_' , strtolower( $token ?: $this->slug() ) ); + } + /** * Getter/setter + * + * @since 0.6 */ public function path() { return $this->path ??= plugin_dir_path( $this->plugin_file ); @@ -316,6 +390,8 @@ class PluginCore { /** * Getter/Setter + * + * @since 0.6 */ public function url() { return $this->url ??= plugin_dir_url( $this->plugin_file ); @@ -323,6 +399,8 @@ class PluginCore { /** * Getter/Setter + * + * @since 0.12 */ public function plugin_basename() { return $this->plugin_basename ??= plugin_basename( $this->plugin_file ); @@ -333,6 +411,8 @@ class PluginCore { * Callback runs on 'register_activation_hook' * PluginCore does not validate. Authors must ensure valid callback. * + * @since 0.4 + * * @param callable $activate_cb - Activation callback * * @access private @@ -346,6 +426,8 @@ class PluginCore { * Callback runs on 'register_deactivation_hook' * PluginCore does not validate. Authors must ensure valid callback. * + * @since 0.4 + * * @param callable $deactivate_cb - Deactivation callback. * * @access private @@ -359,6 +441,8 @@ class PluginCore { * Callback runs on 'register_uninstall_hook' * PluginCore does not validate. Authors must ensure valid callback. * + * @since 0.4 + * * @param callable $uninstall_cb - Uninstall callback. * * @access private @@ -375,6 +459,8 @@ class PluginCore { * * PluginCore does not validate. Authors must ensure valid callback. * + * @since 0.11 + * * @param callable $upgrade_cb - Upgrade callback. * * @access private @@ -407,26 +493,27 @@ class PluginCore { /** * Getter/Setter - AdminPage * - * Construct AdminPage instance for plugin. + * Construct AdminPage instance for plugin. + * + * @since 0.14 + * @since 0.17 - Pass instance of PluginCore to AdminPage (~0.14) * * @param array $admin_page - AdminPage settings array - * * @return AdminPage */ public function admin_page( $admin_page ) { - if ( ! class_exists( 'WPHelper\AdminPage' ) ) + if ( ! class_exists( AdminPage::class ) ) return; - // validate - $admin_page['slug'] ??= $this->slug(); - $admin_page['title'] ??= $this->title(); - - $this->admin_page = new AdminPage( $admin_page ); - - // validate for older versions of AdminPage - if ( method_exists( $this->admin_page, 'plugin_core' ) ) { - $this->admin_page->plugin_core( $this ); // back-reference + if ( ! isset( $this->admin_page ) ){ + + // validate + $admin_page['slug'] ??= $this->slug(); + $admin_page['title'] ??= $this->title(); + $admin_page['plugin_core'] ??= $this; + + $this->admin_page = new AdminPage( $admin_page ); } return $this->admin_page; @@ -435,13 +522,15 @@ class PluginCore { /** * Setter * - * Setup info used by Puc_v4_Factory + * Setup info used by PucFactory * * set $update_checker (bool) * set $update_repo_uri (string) * set $update_auth (optional) * set $update_branch (optional) * + * @since 0.9 + * * @param bool|string|array $update_checker */ private function update_checker( $update_checker ) { @@ -490,14 +579,17 @@ class PluginCore { /** * Init Puc update checker instance * - * @uses Puc_v4_Factory::buildUpdateChecker + * @since 0.9 init_update_checker() + * @since 0.21 build_update_checker() + * + * @uses PucFactory::buildUpdateChecker */ private function build_update_checker() { - - if ( ! class_exists('Puc_v4_Factory') ) + + if ( ! class_exists( PucFactory::class ) ) return; - $update_checker = Puc_v4_Factory::buildUpdateChecker( + $update_checker = PucFactory::buildUpdateChecker( $this->update_repo_uri, $this->plugin_file, $this->slug() // using slug() @@ -520,6 +612,8 @@ class PluginCore { * This function called on upgrader_process_complete * sanity-checks if our plugin was upgraded * if so - calls upgrade_cb provided by our plugin + * + * @since 0.12 */ public function upgrade_cb_wrapper( $upgrader_object, $options ) { if( diff --git a/vendor/abuyoyo/plugincore/composer.json b/vendor/abuyoyo/plugincore/composer.json index e8a6f6c..f1c5d17 100644 --- a/vendor/abuyoyo/plugincore/composer.json +++ b/vendor/abuyoyo/plugincore/composer.json @@ -2,12 +2,12 @@ "name": "abuyoyo/plugincore", "description": "WordPress plugin core helper class", "type": "library", - "version": "0.23", - "time": "2022-08-06", + "version": "0.26", + "time": "2022-06-09", "license": "BSD-3-Clause", "suggest": { "yahnis-elsts/plugin-update-checker": "~4.12", - "abuyoyo/adminmenupage": "~0.20" + "abuyoyo/adminmenupage": "~0.25" }, "autoload": { "psr-4": { diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 8ebd664..130eea7 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -2,26 +2,26 @@ "packages": [ { "name": "abuyoyo/adminmenupage", - "version": "0.21", - "version_normalized": "0.21.0.0", + "version": "0.25", + "version_normalized": "0.25.0.0", "source": { "type": "git", "url": "https://github.com/abuyoyo/AdminMenuPage.git", - "reference": "d05a9e9977d7e7c4ba3c913993493fefba4359d6" + "reference": "487d262aec77a9a3ce04fa762e9048f30d22f123" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/abuyoyo/AdminMenuPage/zipball/d05a9e9977d7e7c4ba3c913993493fefba4359d6", - "reference": "d05a9e9977d7e7c4ba3c913993493fefba4359d6", + "url": "https://api.github.com/repos/abuyoyo/AdminMenuPage/zipball/487d262aec77a9a3ce04fa762e9048f30d22f123", + "reference": "487d262aec77a9a3ce04fa762e9048f30d22f123", "shasum": "" }, "suggest": { - "abuyoyo/plugincore": "~0.18", + "abuyoyo/plugincore": "~0.26", "cmb2/cmb2": "~2.9" }, - "time": "2022-08-06T13:42:37+00:00", + "time": "2023-06-09T00:00:00+00:00", "type": "library", - "installation-source": "dist", + "installation-source": "source", "autoload": { "files": [ "wph_admin_page.php" @@ -37,30 +37,30 @@ "description": "WordPress admin menu page helper class", "support": { "issues": "https://github.com/abuyoyo/AdminMenuPage/issues", - "source": "https://github.com/abuyoyo/AdminMenuPage/tree/0.21" + "source": "https://github.com/abuyoyo/AdminMenuPage/tree/0.25" }, "install-path": "../abuyoyo/adminmenupage" }, { "name": "abuyoyo/plugincore", - "version": "0.23", - "version_normalized": "0.23.0.0", + "version": "0.26", + "version_normalized": "0.26.0.0", "source": { "type": "git", "url": "https://github.com/abuyoyo/PluginCore.git", - "reference": "0a5809d6722a2abf0bdaf23f73bd3875b00fd2a4" + "reference": "77f7d5451bdff4bda6c9766847b215bdeaca96d6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/abuyoyo/PluginCore/zipball/0a5809d6722a2abf0bdaf23f73bd3875b00fd2a4", - "reference": "0a5809d6722a2abf0bdaf23f73bd3875b00fd2a4", + "url": "https://api.github.com/repos/abuyoyo/PluginCore/zipball/77f7d5451bdff4bda6c9766847b215bdeaca96d6", + "reference": "77f7d5451bdff4bda6c9766847b215bdeaca96d6", "shasum": "" }, "suggest": { - "abuyoyo/adminmenupage": "~0.20", + "abuyoyo/adminmenupage": "~0.25", "yahnis-elsts/plugin-update-checker": "~4.12" }, - "time": "2022-08-06T00:00:00+00:00", + "time": "2022-06-09T00:00:00+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -75,7 +75,7 @@ "description": "WordPress plugin core helper class", "support": { "issues": "https://github.com/abuyoyo/PluginCore/issues", - "source": "https://github.com/abuyoyo/PluginCore/tree/0.23" + "source": "https://github.com/abuyoyo/PluginCore/tree/0.26" }, "install-path": "../abuyoyo/plugincore" }, diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index b8e356d..6aad20e 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -11,12 +11,12 @@ ), 'versions' => array( 'abuyoyo/adminmenupage' => array( - 'pretty_version' => '0.21', - 'version' => '0.21.0.0', + 'pretty_version' => '0.25', + 'version' => '0.25.0.0', 'type' => 'library', 'install_path' => __DIR__ . '/../abuyoyo/adminmenupage', 'aliases' => array(), - 'reference' => 'd05a9e9977d7e7c4ba3c913993493fefba4359d6', + 'reference' => '487d262aec77a9a3ce04fa762e9048f30d22f123', 'dev_requirement' => false, ), 'abuyoyo/notice-manager' => array( @@ -29,12 +29,12 @@ 'dev_requirement' => false, ), 'abuyoyo/plugincore' => array( - 'pretty_version' => '0.23', - 'version' => '0.23.0.0', + 'pretty_version' => '0.26', + 'version' => '0.26.0.0', 'type' => 'library', 'install_path' => __DIR__ . '/../abuyoyo/plugincore', 'aliases' => array(), - 'reference' => '0a5809d6722a2abf0bdaf23f73bd3875b00fd2a4', + 'reference' => '77f7d5451bdff4bda6c9766847b215bdeaca96d6', 'dev_requirement' => false, ), 'abuyoyo/screen-meta-links' => array(