コード例 #1
0
    /**
     * Runs the Admin Page and outputs the HTML
     *
     * @return void
     */
    public static function admin()
    {
        // Make sure that this Plugin Loads before the others.
        if ($active_plugins = get_option('active_plugins')) {
            $plugin_path = plugin_basename(__FILE__);
            if (!empty($active_plugins[0]) && $active_plugins[0] !== $plugin_path) {
                $plugin_count = count($active_plugins);
                $out = array_splice($active_plugins, array_search($plugin_path, $active_plugins), 1);
                array_splice($active_plugins, 0, 0, $out);
                if (count($active_plugins) === $plugin_count && $active_plugins[0] === $plugin_path) {
                    update_option('active_plugins', $active_plugins);
                }
            }
        }
        // Get Settings
        self::get_settings(true);
        // Save Settings if POST
        $response = GRAV_TESTER_PLUGIN_SETTINGS::save_settings();
        if ($response['error']) {
            $error = 'Error saving Settings. Please try again.';
        } else {
            if ($response['success']) {
                $success = 'Settings saved successfully.';
            }
        }
        ?>

		<div class="wrap">
			<header>
				<h1>Gravitate Automated Tester</h1>
			</header>
			<main>
				<h4>Version <?php 
        echo self::$version;
        ?>
</h4>

				<?php 
        if (!empty($error)) {
            ?>
<div class="error"><p><?php 
            echo $error;
            ?>
</p></div><?php 
        }
        ?>
				<?php 
        if (!empty($success)) {
            ?>
<div class="updated"><p><?php 
            echo $success;
            ?>
</p></div><?php 
        }
        ?>
			</main>
		<br>

		<div class="gravitate-redirects-page-links">
			<a href="<?php 
        echo self::$page;
        ?>
&section=run_tests" class="<?php 
        echo self::get_current_tab($_GET['section'], 'run_tests');
        ?>
">Run Tests</a> &nbsp; | &nbsp;
			<a href="<?php 
        echo self::$page;
        ?>
&section=settings" class="<?php 
        echo self::get_current_tab($_GET['section'], 'settings');
        ?>
">Settings</a> &nbsp; | &nbsp;
			<a href="<?php 
        echo self::$page;
        ?>
&section=developers" class="<?php 
        echo self::get_current_tab($_GET['section'], 'developers');
        ?>
">Developers</a>
		</div>


		<br style="clear:both;">
		<br>

		<?php 
        $section = !empty($_GET['section']) ? $_GET['section'] : 'run_tests';
        switch ($section) {
            case 'run_tests':
                self::run_tests();
                break;
            case 'developers':
                self::developers();
                break;
            default:
            case 'settings':
                self::form();
                break;
        }
        ?>
		</div>
		<?php 
    }