Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function demo_settings_page()
- {
- add_settings_section("section", "Настройки страниц:", null, "demo");
- add_settings_field("demo-checkbox", "Закрытить внутр. страницы", "pages_404", "demo", "section");
- register_setting("section", "demo-checkbox");
- }
- function pages_404()
- {
- ?>
- <!-- Here we are comparing stored value with 1. Stored value is 1 if user checks the checkbox otherwise empty string. -->
- <input type="checkbox" name="demo-checkbox" value="1" <?php checked(1, get_option('demo-checkbox'), true); ?> />
- <?php
- }
- add_action("admin_init", "demo_settings_page");
- function custom_settings()
- {
- ?>
- <div class="wrap">
- <h1>Дополнительные настройки</h1>
- <form method="post" action="options.php">
- <?php
- settings_fields("section");
- do_settings_sections("demo");
- submit_button();
- ?>
- </form>
- </div>
- <?php
- }
- function menu_item()
- {
- add_submenu_page("options-general.php", "Дополнительно", "Дополнительно", "manage_options", "custom-settigs", "custom_settings");
- }
- add_action("admin_menu", "menu_item");
- $option_404 = get_option('demo-checkbox');
- if(isset($option_404) && $option_404 == 1)
- {
- add_action('template_redirect', 'test_redirect');
- function test_redirect()
- {
- global $page, $wp_query;
- if(!is_front_page())
- {
- $wp_query->set_404();
- wp_redirect( '/', 404 );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement