예제 #1
0
 function network_options_action()
 {
     $allowed_referers = array(self::NETWORK_SETTINGS_PAGE_SLUG, self::DEFAULT_SETTINGS_PAGE_SLUG);
     if (!isset($_GET['action']) || !in_array($_GET['action'], $allowed_referers)) {
         return;
     }
     $options = isset($_POST['option_page']) ? explode(',', stripslashes($_POST['option_page'])) : null;
     if ($options) {
         foreach ($options as $option) {
             $option = trim($option);
             $value = null;
             $sections = MainWP_WP_Stream_Settings::get_fields();
             foreach ($sections as $section_name => $section) {
                 foreach ($section['fields'] as $field_idx => $field) {
                     $option_key = $section_name . '_' . $field['name'];
                     if (isset($_POST[$option][$option_key])) {
                         $value[$option_key] = $_POST[$option][$option_key];
                     } else {
                         $value[$option_key] = false;
                     }
                 }
             }
             if (!is_array($value)) {
                 $value = trim($value);
             }
             update_site_option($option, $value);
         }
     }
     if (!count(get_settings_errors())) {
         add_settings_error('general', 'settings_updated', __('Settings saved.', 'default'), 'updated');
     }
     set_transient('settings_errors', get_settings_errors(), 30);
     $go_back = add_query_arg('settings-updated', 'true', wp_get_referer());
     wp_redirect($go_back);
     exit;
 }
예제 #2
0
    public static function render_page()
    {
        $option_key = MainWP_WP_Stream_Settings::$option_key;
        $form_action = apply_filters('mainwp_wp_stream_settings_form_action', admin_url('options.php'));
        $page_title = apply_filters('mainwp_wp_stream_settings_form_title', get_admin_page_title());
        $page_description = apply_filters('mainwp_wp_stream_settings_form_description', '');
        $sections = MainWP_WP_Stream_Settings::get_fields();
        $active_tab = mainwp_wp_stream_filter_input(INPUT_GET, 'tab');
        ?>
		<div class="wrap">

			<h2><?php 
        echo esc_html($page_title);
        ?>
</h2>

			<?php 
        if (!empty($page_description)) {
            ?>
				<p><?php 
            echo esc_html($page_description);
            ?>
</p>
			<?php 
        }
        ?>

			<?php 
        settings_errors();
        ?>

			<?php 
        if (count($sections) > 1) {
            ?>
				<h2 class="nav-tab-wrapper">
					<?php 
            $i = 0;
            ?>
					<?php 
            foreach ($sections as $section => $data) {
                ?>
						<?php 
                $i++;
                ?>
						<?php 
                $is_active = 1 === $i && !$active_tab || $active_tab === $section;
                ?>
						<a href="<?php 
                echo esc_url(add_query_arg('tab', $section));
                ?>
" class="nav-tab<?php 
                if ($is_active) {
                    echo esc_attr(' nav-tab-active');
                }
                ?>
">
							<?php 
                echo esc_html($data['title']);
                ?>
						</a>
					<?php 
            }
            ?>
				</h2>
			<?php 
        }
        ?>

			<div class="nav-tab-content" id="tab-content-settings">
				<br/><br/>
				<div class="postbox">
					<div class="inside">

				<form method="post" action="<?php 
        echo esc_attr($form_action);
        ?>
" enctype="multipart/form-data">
		<?php 
        $i = 0;
        foreach ($sections as $section => $data) {
            $i++;
            $is_active = 1 === $i && !$active_tab || $active_tab === $section;
            if ($is_active) {
                settings_fields($option_key);
                do_settings_sections($option_key);
            }
        }
        submit_button();
        ?>
				</form>

			</div>
		</div>
			</div>
		</div>
	<?php 
    }