HEX
Server: LiteSpeed
System: Linux cde2.duelhost.dk 4.18.0-553.34.1.lve.el8.x86_64 #1 SMP Thu Jan 9 16:30:32 UTC 2025 x86_64
User: dtptviut (1121)
PHP: 8.0.30
Disabled: exec,system,passthru,shell_exec,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/dtptviut/domains/financo.dk/private_html/wp-content/plugins/internal-links/helper/post.php
<?php

namespace ILJ\Helper;

use ILJ\Core\IndexBuilder;
use ILJ\Core\Options;
use ILJ\Core\Options\OptionInterface;
use ILJ\Database\Keywords;

/**
 * Post toolset
 *
 * Methods for handling POST requests
 *
 * @package ILJ\Helper
 *
 * @since 1.1.3
 */
class Post {
	public static function option_actions() {
		if (!check_admin_referer(Options::KEY) || !current_user_can('manage_options')) {
			return false;
		}

		$url = wp_get_referer();

		if (!$url) {
			$url = admin_url();
		}

		if (filter_has_var(INPUT_POST, 'ilj-reset-options') && filter_has_var(INPUT_POST, 'section') && filter_has_var(INPUT_POST, 'action') && isset($_POST['action']) && Options::KEY === $_POST['action']) {
			self::resetOptionsAction();
		}

		if (filter_has_var(INPUT_POST, 'ilj-reset-keywords')) {
			self::reset_all_keywords();
		}

		wp_safe_redirect(esc_url_raw($url));
		exit;
	}
	/**
	 * Handles the process of resetting options from a given section to default.
	 *
	 * @since  1.1.3
	 * @return bool
	 */
	public static function resetOptionsAction() {
		// phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce verification is handled in the caller method.
		$section = isset($_POST['section']) ? Options::getSection(sanitize_text_field(wp_unslash($_POST['section']))) : array();

		if ($section) {
			foreach ($section['options'] as $option) {
				if (!$option instanceof OptionInterface) {
					continue;
				}

				delete_option($option::getKey());
			}
		}

		Options::setOptionsDefault();

		do_action(IndexBuilder::ILJ_INITIATE_BATCH_REBUILD);
	}

	/**
	 * Handles the process of deleting all keywords set in ILJ.
	 *
	 * @since  2.1.2
	 * @return bool
	 */
	public static function reset_all_keywords() {
		Keywords::reset_all_keywords();
		Cleanup::initiate_cleanup();
	}
}