admin menu with stats/config info
admin menu with stats/config info

--- a/redis-page-views.php
+++ b/redis-page-views.php
@@ -41,6 +41,10 @@
 
         if (function_exists('add_action')) {
             add_action('init', array($this, 'init'));
+            if (is_admin()) {
+                add_action('admin_menu', array($this, 'add_menu_item'));
+                $this->currentTab = isset($_GET['tab']) ? $_GET['tab'] : 'stats';
+            }
         }
     }
 
@@ -67,6 +71,92 @@
             wp_add_inline_script($this->plugin, "var _rpv = {id: " . $post_id . ", url: '" . plugins_url('/pageview.php', __FILE__) . "'};");
         }
     }
+
+    public function add_menu_item()
+    {
+        add_menu_page(__('Redis Page Views', $this->plugin), __('Redis Page Views', $this->plugin), 'manage_options', $this->plugin . '-plugin', array($this, 'settings_page'), plugins_url() . '/' . $this->plugin . '/icon.png', 100);
+    }
+
+    public function settings_page()
+    {
+    ?>
+        <div class="wrap">
+        <h1><?=__('Redis Page Views', $this->plugin)?></h1>
+
+        <h2 class="nav-tab-wrapper">
+            <a class="nav-tab <?php if($this->currentTab == 'stats'): ?>nav-tab-active<?php endif; ?>" href="<?php echo admin_url() ?>index.php?page=<?=$this->plugin?>-plugin&amp;tab=stats"><?=__('Statistics', $this->plugin)?></a>
+            <a class="nav-tab <?php if($this->currentTab == 'posts-views'): ?>nav-tab-active<?php endif; ?>" href="<?php echo admin_url() ?>index.php?page=<?=$this->plugin?>-plugin&amp;tab=posts-views"><?=__('Posts views', $this->plugin)?></a>
+            <a class="nav-tab <?php if($this->currentTab == 'conf'): ?>nav-tab-active<?php endif; ?>" href="<?php echo admin_url() ?>index.php?page=<?=$this->plugin?>-plugin&amp;tab=conf"><?=__('Configuration info', $this->plugin)?></a>
+        </h2>
+
+        <?php if($this->currentTab == 'stats'): ?>
+            <h2><?= __('Statistics', $this->plugin) ?></h2>
+
+            <div class="wrap">
+                <table class="wp-list-table widefat fixed striped">
+                    <thead>
+                        <tr>
+                            <td class="manage-column"><strong>Key</strong></td>
+                            <td class="manage-column"><strong>Value</strong></td>
+                            <!--td class="manage-column"><strong>Description</strong></td-->
+                        </tr>
+                    </thead>
+                    <tbody>
+                    <?php $this->connect_redis(); ?>
+                    <?php foreach($data = $this->redis->info() as $key => $value): ?>
+                        <tr>
+                            <td><?=$key?></td>
+                            <td><?=$value?></td>
+                            <!--td></td-->
+                        </tr>
+                    <?php endforeach; ?>
+                    </tbody>
+                </table>
+            </div>
+        <?php elseif($this->currentTab == 'conf'): ?>
+            <h2><?= __('Configuration info', $this->plugin) ?></h2>
+
+            <div class="wrap">
+                <table class="wp-list-table widefat fixed striped">
+                    <tbody>
+                        <tr>
+                            <td>
+                                <?php
+                                    echo sprintf('<h4>' . __('You can override in wp-config.php redis default connection data' . '</h4>', $this->plugin));
+                                ?>
+                                <textarea cols="100" rows="5"><?php
+                                    echo __("DEFINE('RPV_POST_META_KEY', 'redis_pageviews_count');", $this->plugin); echo "\r\n";
+                                    echo __("DEFINE('RPV_REDIS_HOST', '127.0.0.1');", $this->plugin); echo "\r\n";
+                                    echo __("DEFINE('RPV_REDIS_PORT', 6379);", $this->plugin); echo "\r\n";
+                                    echo __("DEFINE('RPV_REDIS_PASS', '');", $this->plugin); echo "\r\n";
+                                    echo __("DEFINE('RPV_REDIS_PREFIX', 'redis-page-views'); // use custom prefix on all keys", $this->plugin);
+                                ?></textarea>
+                                <br /><br />
+                                <?php
+                                    echo __("You can use get_post_meta(\$post_id, RPV_POST_META_KEY, true); to get the post views");
+                                ?>
+                            </td>
+                        </tr>
+                    </tbody>
+                </table>
+            </div>
+        <?php elseif($this->currentTab == 'posts'): ?>
+            <h2><?= __('Posts views in memory', $this->plugin) ?></h2>
+
+            <div class="wrap">
+                <table class="wp-list-table widefat fixed striped">
+                    <tbody>
+                        <tr>
+                            <td>
+                            </td>
+                        </tr>
+                    </tbody>
+                </table>
+            </div>
+        <?php endif; ?>
+        </div>
+    <?php
+    }
 }
 
 $redisPageViews = new Redis_Page_Views();

file:a/wp-cli.php -> file:b/wp-cli.php
--- a/wp-cli.php
+++ b/wp-cli.php
@@ -17,7 +17,7 @@
     }
 
     /**
-     * Adds the views
+     * Adds the views to database using add_post_meta / update_post_meta
      *
      * ## EXAMPLES
      *
@@ -45,7 +45,7 @@
     }
 
     /**
-     * Delete all data from Redis
+     * Remove all keys from all databases.
      *
      * ## EXAMPLES
      *
@@ -56,7 +56,7 @@
     public function flush()
     {
         $this->rpv->connect_redis();
-        $this->rpv->redis->flushAll();
+        $this->rpv->redis->flushDb();
 
         WP_CLI::success('Redis cache flushed.');
     }

comments