Files
2024_WORDPRESS_PLUGIN_fbpatch/menu/menu_content.php
2024-07-17 15:30:32 +02:00

105 lines
2.0 KiB
PHP

<?php
namespace FBPATCH;
/*
* it means someone outside wp is accessing the file, in this case kill it.
*/
if (!defined('ABSPATH')) {
die('You can not access this file!');
}
/*
* the construction of the admin menu page
*
*/
function plugin_content() {
$patches = Fbpatch::get_patches();
$nonce = Fbpatch::NONCE;
$admin_post_patches = Fbpatch::ADMIN_POST_PATCH_CHOICE;
ob_start();
include(Fbpatch::root_path() . '/html/menu.html');
$html = ob_get_clean();
echo $html;
}
/*
* use this hook 'admin_post_{$action}' to receive a form post
* https://developer.wordpress.org/reference/hooks/admin_post_action/
*
* add the url to the action atrtibute of form, and the value of the action in an hidden input
* <form method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>">
* <input type="hidden" name="action" value="<?php echo $admin_post_patches; ?>">
*
*/
function patches_choice() {
$nonce = Fbpatch::NONCE;
if (!isset($_POST[$nonce['_name']])) {
\FBPATCH\redirect_menu_referer($_POST);
exit;
}
if (!wp_verify_nonce($_POST[$nonce['_name']], $nonce['_action'])) {
\FBPATCH\redirect_menu_referer($_POST);
exit;
}
/*
*
*
[24-Mar-2024 12:24:08 UTC] -> _POST {
"action":"add_patches",
"nonce_name":"7eeb560dc0",
"_wp_http_referer":"\/wp-admin\/admin.php?page=fbpatch-plugin",
"hide_show":"on"
}
*/
$pathes_on = array();
foreach($_POST as $key => $value) {
if ($value !== 'on') {
continue;
}
$pathes_on[] = $key;
}
Fbpatch::set_patches($pathes_on);
\FBPATCH\redirect_menu_referer($_POST);
}
add_action('admin_post_'.Fbpatch::ADMIN_POST_PATCH_CHOICE, __NAMESPACE__.'\patches_choice');
function redirect_menu_referer($post) {
if (!isset($post)) {
wp_redirect(admin_url(), 301);
exit;
}
if (is_null($post)) {
wp_redirect(admin_url(), 301);
exit;
}
if (empty($post)) {
wp_redirect(admin_url(), 301);
exit;
}
if (!isset($post['_wp_http_referer'])) {
wp_redirect(admin_url(), 301);
exit;
}
wp_redirect(home_url($post['_wp_http_referer']), 301);
exit;
}
?>