input = new Input(); add_action('init', function () { $this->handleInputDataForCreatePage(); $this->noticeAfterCreatePages(); $this->noticeAfterUpdatePage(); $this->noticeAfterDeletePages(); $this->deletePages(); Flash::destroy(); }); SubpageWhatsNew::register(); add_action('admin_menu', function () { $this->setPages(); }); add_action('wp_ajax_notUsedExistingMenuTitles', function () { SubpageImportExport::verifyAjaxRequest(); wp_send_json(Data::notUsedExistingMenuTitles()); }); add_action('wp_ajax_aopSettingsForExport', function () { SubpageImportExport::verifyAjaxRequest(); $data = Collection::make(Data::getAllRowsFromPluginTable())->map(function ($item) { $item = clone $item; $item->page_value = PageRepository::decode($item->page_value); return $item; }); wp_send_json($data); }); add_action('admin_post_' . SubpageImportExport::EXPORT_ACTION, function () { SubpageImportExport::handleExport(); }); } private function setPages() { add_menu_page( MenuPage::PAGE_TITLE, // Short enough for one line in the admin menu ("Admin Options Pages" takes two). __('Options Pages', 'admin-options-pages'), MenuPage::CAPABILITY, SubpageMaster::SLUG, '', MenuPage::ICON_URL, MenuPage::POSITION ); // Master Page add_submenu_page( SubpageMaster::SLUG, SubpageMaster::PAGE_TITLE, __('All Options Pages', 'admin-options-pages'), MenuPage::CAPABILITY, SubpageMaster::SLUG, function () { SubpageMaster::view(); } ); // Create Page add_submenu_page( SubpageMaster::SLUG, SubpageCreate::PAGE_TITLE, __('Add new', 'admin-options-pages'), MenuPage::CAPABILITY, SubpageCreate::SLUG, function () { $this->checkOptionAopStandardWpAdminMenu(); SubpageCreate::view(); } ); // Edit Page $editHook = add_submenu_page( SubpageEdit::SLUG, SubpageEdit::PAGE_TITLE, __('edit Page', 'admin-options-pages'), MenuPage::CAPABILITY, SubpageEdit::SLUG, function () { $this->checkOptionAopStandardWpAdminMenu(); $this->input->prepareDataForPages(new Validation()); SubpageEdit::view(); } ); if ($editHook) { add_action('load-' . $editHook, [SubpageEdit::class, 'load']); } // What's new: not in the menu (its parent is itself, like the edit page); the notice after an update links here. add_submenu_page( SubpageWhatsNew::SLUG, __("What's new in Admin Options Pages 1.0", 'admin-options-pages'), __("What's new", 'admin-options-pages'), MenuPage::CAPABILITY, SubpageWhatsNew::SLUG, function () { SubpageWhatsNew::view(); } ); // Settings Page add_submenu_page( SubpageMaster::SLUG, SubpageSettings::PAGE_TITLE, __('Settings', 'admin-options-pages'), MenuPage::CAPABILITY, SubpageSettings::SLUG, function () { SubpageSettings::view(); } ); // Import/Export Page add_submenu_page( SubpageMaster::SLUG, SubpageSettings::PAGE_TITLE, __('Import / Export', 'admin-options-pages'), MenuPage::CAPABILITY, SubpageImportExport::SLUG, function () { SubpageImportExport::view(); } ); } private function deletePages() { Data::deleteRowFromSpecificId(); } private function handleInputDataForCreatePage() { if (!SubpageCreate::isCurrentPage()) { return; } if (!isset($_POST['existing_menu']) && !isset($_POST['menu'])) { return; } $this->input->prepareDataForPages(new Validation()); } private function noticeAfterCreatePages() { if (!SubpageEdit::isCurrentPage()) { return; } if (!Flash::get('pages_saved')) { return; } add_action('admin_notices', function () { Notice::succes(__('Saved.', 'admin-options-pages'), true); }); } /** * The editor saves through REST and reloads; the "Updated." notice comes from the flash data of that request. */ private function noticeAfterUpdatePage() { if (!SubpageEdit::isCurrentPage() || !Flash::get('pages_updated')) { return; } add_action('admin_notices', function () { Notice::succes(__('Updated.', 'admin-options-pages'), true); }); } private function noticeAfterDeletePages() { if (!SubpageMaster::isCurrentPage()) { return; } if (!Flash::get('pages_deleted')) { return; } add_action('admin_notices', function () { $message = Flash::get('pages_deleted_multiple') ? __('Pages deleted.', 'admin-options-pages') : __('Page deleted.', 'admin-options-pages'); Notice::succes($message, true); }); } private function checkOptionAopStandardWpAdminMenu() { if (!get_option(Plugin::PREFIX_ . 'admin_menu_list')) { add_option(Plugin::PREFIX_ . 'admin_menu_list', $GLOBALS['menu'], '', 'no'); } update_option(Plugin::PREFIX_ . 'admin_menu_list', $GLOBALS['menu'], 'no'); } }