remove_menu("comments"); }); } public static function maintenance_mode() { // Maintenance mode if .maintenance file exists in root redirect until login if (get_option('hithto_maintenance_mode', 0) == 1) { // if url is not wp-login.php and not wp-admin redirect to maintenance page if (!in_array($GLOBALS['pagenow'], ['wp-login.php', 'wp-register.php']) && !is_user_logged_in() && !is_admin()) { // load custom maintenance page include(HITHTO_DIR . '/views/maintenance.php'); exit; } } } public static function enable_cookie_consent() { if (get_option('cookie_consent', 0) == 1) { CookieService::register(); } } public static function enable_calendar() { if (get_option('hithto_calendar', 0) == 1) { \Toolkit\models\CalendarEvent::register(); \Toolkit\utils\CalendarService::register(); CalendarAdminService::register(); } } public static function templates_directory() { // Hook into the template_include filter add_filter('template_include', function ($template) { $views_path = HITHTO_THEME_VIEWS_PATH; $custom_template = $template; $types = []; if (is_singular()) { $types[] = 'singular-' . get_query_var('post_type'); } if (is_tax()) { $types[] = 'taxonomy-' . get_query_var('taxonomy'); } if (is_category()) { $types[] = 'category-' . get_query_var('cat'); } if (is_tag()) { $types[] = 'tag-' . get_query_var('tag'); } if (is_search()) { $types[] = 'search'; } if (is_404()) { $types[] = '404'; } if (is_home()) { $types[] = 'home'; } if (is_front_page()) { $types[] = 'front-page'; } if (is_page()) { if (is_page_template()) { $types[] = 'template-' . str_replace('.php', '', get_page_template_slug()); } else { $types[] = 'page-' . get_post_field('post_name'); $types[] = 'page-' . get_the_ID(); $types[] = 'page'; } } if (is_single()) { $types[] = 'single-' . get_query_var('post_type'); $types[] = 'single-' . get_post_field('post_name'); $types[] = 'single-' . get_the_ID(); $types[] = 'single'; } if (is_post_type_archive()) { $types[] = 'archive-' . self::pluralize(get_query_var('post_type')); $types[] = 'archive-' . get_query_var('post_type'); $types[] = 'archive'; } foreach ($types as $type) { if (file_exists($views_path . '/' . $type . '.php')) { $custom_template = $views_path . '/' . $type . '.php'; break; } } return $custom_template; }); } public static function pluralize($word, $count = 2) { // Simple pluralization: assumes 'y' -> 'ies', and adds 's' or 'es' if ($count === 1) { return $word; } else { $lastLetter = strtolower($word[strlen($word) - 1]); switch ($lastLetter) { case 'y': // Words that end in 'y' with a consonant before it, 'y' -> 'ies' if (preg_match('/[bcdfghjklmnpqrstvwxyz]y$/i', $word)) { return substr($word, 0, -1) . 'ies'; } // If the 'y' is preceded by a vowel, simply add 's' return $word . 's'; case 's': case 'x': case 'z': case 'o': // Most words ending in 's', 'x', 'z', or 'o' add 'es' return $word . 'es'; case 'h': if (preg_match('/(ch|sh)$/i', $word)) { // Words ending in 'ch' or 'sh' add 'es' return $word . 'es'; } return $word . 's'; default: return $word . 's'; } } } public static function admin_menu() { add_action('admin_init', function () { register_setting('wordpress-toolkit-plugin', 'hithto_menu_settings', [ 'sanitize_callback' => function ( $value ) { if ( ! is_array( $value ) ) { return []; } return array_map( 'absint', $value ); }, ]); register_setting('wordpress-toolkit-plugin', 'hithto_maintenance_mode', [ 'sanitize_callback' => 'absint' ]); register_setting('wordpress-toolkit-plugin', 'cookie_consent', [ 'sanitize_callback' => 'absint' ]); register_setting('wordpress-toolkit-plugin', 'hithto_disable_comments', [ 'sanitize_callback' => 'absint' ]); register_setting('wordpress-toolkit-plugin', 'hithto_file_size', [ 'sanitize_callback' => 'absint' ]); register_setting('wordpress-toolkit-plugin', 'hithto_limit_upload_size', [ 'sanitize_callback' => 'absint' ]); register_setting('wordpress-toolkit-plugin', 'hithto_allow_svg_upload', [ 'sanitize_callback' => 'absint' ]); }); add_action('admin_menu', function () { add_menu_page( 'Toolkit', 'Toolkit', 'edit_theme_options', 'wordpress-toolkit-plugin', [self::class, 'display_toolkit_page'], 'dashicons-hi', 65 ); // Add a submenu for settings add_submenu_page( 'wordpress-toolkit-plugin', // Parent menu slug 'Hide menu items', // Page title 'Hide menu items', // Menu title 'edit_theme_options', 'toolkit-hide-menu-items', // Menu slug [self::class, 'display_settings_page'] // Callback function to display the settings page ); }); } public static function upload_limit() { // Upload limit for media library, only when enabled in the Toolkit settings (off by default) if (get_option('hithto_limit_upload_size', 0) != 1) { return; } add_filter("upload_size_limit", function ($_size) { return (int) get_option('hithto_file_size', 5 * 1024 * 1024); }, 20 ); } public static function add_theme_support() { add_theme_support('post-thumbnails'); add_theme_support( 'title-tag' ); } public static function add_action() { add_action("admin_menu", function () { $options = get_option("hithto_menu_settings", []); $menu_items = [ 'edit-comments.php' => 'Comments', 'themes.php' => 'Appearance', 'plugins.php' => 'Plugins', 'users.php' => 'Users', 'tools.php' => 'Tools', 'options-general.php' => 'Settings', 'index.php' => 'Dashboard', 'upload.php' => 'Media', 'edit.php?post_type=page' => 'Pages', 'edit.php' => 'Posts', 'toolkit-calendar' => 'Calendar', ]; foreach ($menu_items as $menu_slug => $menu_label) { if (isset($options[$menu_slug]) && $options[$menu_slug] == 1) { remove_menu_page($menu_slug); } } }, 999); // set admin footer add_action("admin_init", function () { add_filter( "admin_footer_text", function () { $footer_name = get_option( 'toolkit_admin_footer_name', '' ); $footer_url = get_option( 'toolkit_admin_footer_url', '' ); if ( $footer_name ) { if ( $footer_url ) { echo 'Powered by ' . esc_html( $footer_name ) . ''; } else { echo 'Powered by ' . esc_html( $footer_name ); } } }, 11 ); add_editor_style("assets/css/editor.css"); }); // add thumbnails support add_action("after_setup_theme", function () { add_theme_support("title-tag"); add_theme_support("post-thumbnails"); add_theme_support("responsive-embeds"); add_theme_support("title-tag"); if (class_exists('WooCommerce')) { add_theme_support("woocommerce"); } }); // disable all actions related to emojis add_action("init", function () { remove_action("admin_print_styles", "print_emoji_styles"); remove_action("wp_head", "print_emoji_detection_script", 7); remove_action("admin_print_scripts", "print_emoji_detection_script"); remove_action("wp_print_styles", "print_emoji_styles"); remove_filter("wp_mail", "wp_staticize_emoji_for_email"); remove_filter("the_content_feed", "wp_staticize_emoji"); remove_filter("comment_text_rss", "wp_staticize_emoji"); add_filter("emoji_svg_url", "__return_false"); }); } public static function add_filter() { // Allow SVG uploads, only when enabled in the Toolkit settings (off by default) if (get_option('hithto_allow_svg_upload', 0) == 1) { add_filter("upload_mimes", function ($mimes) { $mimes["svg"] = "image/svg+xml"; return $mimes; }); } // updraft ignore dev files and folders add_filter( "updraftplus_exclude_directory", function ($filter, $directory) { $excludes = [".git", ".vscode", "node_modules", "src"]; foreach ($excludes as $exclude) { if (strpos($directory, "wp-content/themes/" . $exclude)) { return true; } } return $filter; }, 10, 2 ); add_filter( "updraftplus_exclude_file", function ($filter, $file) { $excludes = [ ".editorconfig", ".gitignore", ".tool-versions", "config.example.json", "config.json", "package.json", "package-lock.json", "readme.md", "webpack.mix.js", ]; foreach ($excludes as $exclude) { if (strpos($file, "wp-content/themes/" . $exclude)) { return true; } } return $filter; }, 10, 2 ); // remove WordPress version add_filter("the_generator", function () { return ""; }); add_filter("style_loader_src", function ($src) { if (strpos($src, "ver=" . get_bloginfo("version"))) { $src = remove_query_arg("ver", $src); } $src = str_replace("ver=", "", $src); return $src; }); add_filter("script_loader_src", function ($src) { if (strpos($src, "ver=" . get_bloginfo("version"))) { $src = remove_query_arg("ver", $src); } $src = str_replace("ver=", "", $src); return $src; }); } public static function remove_action() { remove_action("wp_head", "rsd_link"); remove_action("wp_head", "wlwmanifest_link"); } public static function display_settings_page() { $post_data = wp_unslash($_POST); // Define the menu items to be managed $menu_items = [ 'edit-comments.php' => 'Comments', 'themes.php' => 'Appearance', 'plugins.php' => 'Plugins', 'users.php' => 'Users', 'tools.php' => 'Tools', 'options-general.php' => 'Settings', 'index.php' => 'Dashboard', 'upload.php' => 'Media', 'edit.php?post_type=page' => 'Pages', 'edit.php' => 'Posts', 'toolkit-calendar' => 'Calendar', ]; // Check if the form was submitted if (isset($post_data['submit'])) { if (!isset($post_data['hithto_menu_settings_nonce']) || !wp_verify_nonce(sanitize_text_field($post_data['hithto_menu_settings_nonce']), 'hithto_menu_settings_action')) { print 'Sorry, your nonce did not verify.'; exit; } else { // Save the user's choices to options $options = []; foreach ($menu_items as $menu_slug => $menu_label) { // Replace underscores with dots to match the form keys $post_key = str_replace('.', '_', $menu_slug); // Check if the option exists in the POST data before accessing it $options[$menu_slug] = isset($post_data[$post_key]) ? 1 : 0; } update_option('hithto_menu_settings', $options); } } // Retrieve the saved options $options = get_option('hithto_menu_settings', []); // Output the settings form ?>

Toolkit Settings

$menu_label) { ?>
>

= $min_size_bytes && $file_size_bytes <= $max_size_bytes) { $options['file_size'] = $file_size_bytes; update_option('hithto_file_size', $options['file_size']); } } ?>

Toolkit

Theme details

Name:

URL:

Directory:


Maintenance mode

Comments


SVG uploads

File size

get_template_directory_uri() . '/assets/images/logo.svg', * 'background' => '#f5f5f5', * 'button_color' => '#e63946', * 'button_hover' => '#c1121f', * ]); */ public static function customize_login(array $options = []): void { add_action('login_enqueue_scripts', function () use ($options): void { $css = ''; if (!empty($options['logo'])) { $logo = esc_url($options['logo']); $css .= ".login h1 a { background-image: url('{$logo}') !important; background-size: contain; background-repeat: no-repeat; background-position: center; width: 100%; }"; } if (!empty($options['background'])) { $bg = esc_attr($options['background']); $css .= "body.login { background-color: {$bg}; }"; } if (!empty($options['button_color'])) { $color = esc_attr($options['button_color']); $hover = esc_attr($options['button_hover'] ?? $options['button_color']); $css .= "body.login .button-primary, #wp-submit { background: {$color}; border-color: {$color}; box-shadow: none; }"; $css .= "body.login .button-primary:hover, body.login .button-primary:focus, #wp-submit:hover, #wp-submit:focus { background: {$hover}; border-color: {$hover}; box-shadow: none; }"; } if ($css) { wp_add_inline_style('login', $css); } }); if (!empty($options['logo'])) { add_filter('login_headerurl', fn() => home_url('/')); } } }