input = new Input();
add_action('init', [$this, 'handleInputDataForCreatePage']);
add_action('init', [$this, 'noticeAfterCreatePages']);
add_action('init', [$this, 'noticeAfterDeletePages']);
add_action('init', [$this, 'updateOptionNamesAfterFirstSave']);
add_action('init', [$this, 'updateOptionNamesAfterDeletePages']);
// add_action('init', [$this, 'noticeAfterDeletePagesOnBulkAction']);
add_action('init', [$this, 'sessionsDestroyed']);
add_action('init', [$this, 'deletePages']);
add_action('admin_menu', [$this, 'setPages']);
}
public function setPages()
{
add_menu_page(
MenuPage::PAGE_TITLE,
MenuPage::MENU_TITLE,
MenuPage::CAPABILITY,
SubpageMaster::SLUG,
'',
MenuPage::ICON_URL,
MenuPage::POSITION
);
// Master Page
add_submenu_page(
SubpageMaster::SLUG,
SubpageMaster::PAGE_TITLE,
SubpageMaster::MENU_TITLE,
MenuPage::CAPABILITY,
SubpageMaster::SLUG,
[$this, 'masterPageDisplay']
);
// Create Page
add_submenu_page(
SubpageMaster::SLUG,
SubpageCreate::PAGE_TITLE,
SubpageCreate::MENU_TITLE,
MenuPage::CAPABILITY,
SubpageCreate::SLUG,
[$this, 'createPageDisplay']
);
// Edit Page
add_submenu_page(
null,
SubpageEdit::PAGE_TITLE,
SubpageEdit::MENU_TITLE,
MenuPage::CAPABILITY,
SubpageEdit::SLUG,
[$this, 'editPageDisplay']
);
}
public function masterPageDisplay()
{
$listTable = new ListTable();
printf('
', Plugin::PREFIX . 'root');
$listTable->prepare_items();
printf(
'
%s
',
SubpageMaster::PAGE_TITLE
);
printf(
'
%s',
SubpageCreate::url(),
__('Add New')
);
print('');
printf(
'
');
print('
');
print('
');
}
public function editPageDisplay()
{
$this->input->prepareDataForPages();
printf('', Plugin::PREFIX . 'root');
vprintf(
'
',
SubpageEdit::wpNonceFieldArray()
);
print('
');
print('
');
}
public function createPageDisplay()
{
$this->checkOptionAopStandardWpAdminMenu();
printf('', Plugin::PREFIX . 'root');
vprintf(
'
',
SubpageCreate::wpNonceFieldArray()
);
print('
');
}
public function deletePages()
{
Data::deleteRowFromSpecificId();
}
public function handleInputDataForCreatePage()
{
if (!isset($_REQUEST['page'])) {
return;
}
if ($_REQUEST['page'] !== SubpageCreate::SLUG) {
return;
}
if (!isset($_REQUEST['existing_menu']) && !isset($_REQUEST['menu'])) {
return;
}
$this->input->prepareDataForPages();
}
public function noticeAfterCreatePages()
{
if (!isset($_REQUEST['page'])) {
return;
}
if ($_REQUEST['page'] !== SubpageEdit::SLUG) {
return;
}
session_start();
if (!isset($_SESSION['aop_pages_saved'])) {
return;
}
add_action('admin_notices', function () {
Notice::succes(__('Saved.'), true);
});
}
public function updateOptionNamesAfterFirstSave()
{
if (!isset($_REQUEST['page'])) {
return;
}
if ($_REQUEST['page'] !== SubpageEdit::SLUG) {
return;
}
if (!isset($_SESSION['aop_request_on_save'])) {
return;
}
update_option(Plugin::PREFIX_ . 'option_names', Data::getAllCreatedOptionNamesAfterSave()->all());
$optionsNames = Data::getFieldsfromId($_REQUEST['optionpage'])
->whereIn('field_name', get_option(Plugin::PREFIX_ . 'option_names'));
$optionsNames->filter(function ($item) {
return isset($item['default_value']) && isset($item['field_name']);
})->map(function ($item) {
add_option($item['field_name'], $item['default_value']);
});
}
public function noticeAfterDeletePages()
{
if (!isset($_REQUEST['page'])) {
return;
}
if ($_REQUEST['page'] !== SubpageMaster::SLUG) {
return;
}
session_start();
if (!isset($_SESSION['aop_pages_deleted'])) {
return;
}
$session = $_SESSION;
add_action('admin_notices', function () use ($session) {
$message = $session['aop_pages_deleted_multiple'] ? __('Pages deleted.') : __('Page deleted.');
Notice::succes($message, true);
});
}
public function noticeAfterDeletePagesOnBulkAction()
{
if (!isset($_REQUEST['page'])) {
return;
}
if ($_REQUEST['page'] !== SubpageMaster::SLUG) {
return;
}
session_start();
if (!isset($_SESSION)) {
return;
}
vardumper($_SESSION);
if ('delete' !== $this->current_action() || !isset($_REQUEST['optionpage']) || !isset($_REQUEST['_wpnonce'])) {
return;
}
list($nonce, $ids) = [$_REQUEST['_wpnonce'], $_REQUEST['optionpage']];
if (!wp_verify_nonce($nonce, 'bulk-optionpages')) {
return;
}
// $ids = Collection::make($ids);
// $ids->map(function ($id) {
// return Data::getOptionNamesFromSettingPagesById($id)->all();
// })->flatten(1)->map(function ($optionName) {
// return delete_option($optionName);
// });
// $ids->map(function ($id) {
// return DB::deleteRowById($id);
// });
// if (!isset($_SESSION['aop_pages_deleted'])) {
// return;
// }
// $session = $_SESSION;
add_action('admin_notices', function () {
Notice::succes(__('Deleted.'), true);
});
}
public function updateOptionNamesAfterDeletePages()
{
if (!isset($_SESSION['aop_pages_deleted'])) {
return;
}
update_option(Plugin::PREFIX_ . 'option_names', Data::getAllCreatedOptionNames()->all());
}
public function sessionsDestroyed()
{
if (!isset($_SESSION)) {
return;
}
session_destroy();
$_SESSION = [];
}
public function checkOptionAopStandardWpAdminMenu()
{
if (!get_option(Plugin::PREFIX_ . 'admin_menu_list')) {
add_option(Plugin::PREFIX_ . 'admin_menu_list', $GLOBALS['menu']);
}
update_option(Plugin::PREFIX_ . 'admin_menu_list', $GLOBALS['menu']);
}
public function current_action()
{
if (isset($_REQUEST['filter_action']) && !empty($_REQUEST['filter_action'])) {
return false;
}
if (isset($_REQUEST['action']) && -1 != $_REQUEST['action']) {
return $_REQUEST['action'];
}
if (isset($_REQUEST['action2']) && -1 != $_REQUEST['action2']) {
return $_REQUEST['action2'];
}
return false;
}
// public function helpTabDisplay()
// {
// global $current_screen;
// return Collection::make([
// 'toplevel_page_wp_options_master',
// 'admin_page_wp_options_edit',
// 'options-pages_page_wp_options_create'
// ])->filter(function ($id) use ($current_screen) {
// return $current_screen->id === $id;
// })->map(function ($id) use ($current_screen) {
// $current_screen->set_help_sidebar(
// '
// More info:
// Documentatie over het gebruik van Thema\'s
// '
// );
// $current_screen->add_help_tab([
// 'id' => 1,
// 'title' => 'Documentation',
// 'callback' => function ($screen, $tab) {
// if ($screen->id !== 'toplevel_page_wp_options_master') {
// print('
// Documentation:
// Some Lorem ipsum.
// ');
// }
// }
// // 'callback' => $callback //optional function to callback
// ]);
// $current_screen->add_help_tab([
// 'id' => 2,
// 'title' => 'FAQ',
// 'callback' => function ($screen, $tab) {
// if ($screen->id !== 'toplevel_page_wp_options_master') {
// print('
// FAQ:
// Searching for the faq?
// ');
// }
// }
// ]);
// });
// }
}