From 841c06a5d13b133d2cc547b11f2498c23b3c2b16 Mon Sep 17 00:00:00 2001 From: Richard Luck Date: Wed, 15 Jul 2015 18:03:22 -0700 Subject: [PATCH] allowing the navbar to be displayed on pages and home --- CHANGELOG.md | 4 ++ includes/classes/SmartNavbar.class.php | 81 ++++++++++++++++++++++---- readme.txt | 10 +++- smart-navbar.php | 4 +- 4 files changed, 82 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adbf3ed..054374d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ###Changelog +#### 0.1.0 +* Added ability to display smart-navbar on Pages and Home page. +* Cleaned up a bunch of the code. + #### 0.0.4 * Fixed bug with enqueing of admin stylesheet diff --git a/includes/classes/SmartNavbar.class.php b/includes/classes/SmartNavbar.class.php index a8ed512..7b1f142 100644 --- a/includes/classes/SmartNavbar.class.php +++ b/includes/classes/SmartNavbar.class.php @@ -25,10 +25,12 @@ class SmartNavbar { var $page_shortcode = '__SMARTNAVBAR_FAVORITES_LIST_GOES_HERE__'; var $page_permalink = null; var $page_title = 'Bookmarks and Favorites'; + var $defaults = array('on_page' => true,'on_home' => false); public function __construct() { // initialize the dates $this->options = get_option($this->opt_key); + $this->check_plugin_version(); } public function __destruct() { @@ -78,15 +80,28 @@ public function ajax_handler() { wp_die('Error','Unable to save change',400); } } + public function update_options($form) { + $this->log("In update options!!"); + $message = null; + if(isset($_POST['save_settings'])) { + $this->log("we have the post"); + check_admin_referer(SNB_ADMIN_PAGE_NONCE); + if (isset($_POST['snb_opt'])) { + $message = 'Your updates have been saved.'; + $opts = $_POST['snb_opt']; + $this->options[options] = $opts; + update_option($this->opt_key,$this->options); + } + return $message; + } + } public function configuration_screen() { if (is_user_logged_in() && is_admin() ){ $page_link = get_permalink($this->options[post_id]); - // $message = $this->update_options($_POST); - // $opts = get_option(SNB_PLUGIN_OPTTIONS); - // $posts = $this->get_post_meta(); - // $existing = array(); - + $message = $this->update_options($_POST); + $opts = $this->options[options]; + $this->log(sprintf("OPTIONS: %s",print_r($opts,1))); if ($message) { printf('

%s

',$message); } elseif ($this->error) { // reload the form post in this form @@ -132,7 +147,7 @@ public function configuration_screen() { $this->sidebar_link('Home','https://wordpress.org/plugins//','Plugin Homepage'); $this->sidebar_link('Suggestion','https://wordpress.org/support/plugin/','Suggestions'); $this->sidebar_link('Contact','mailto:wordpress@loudlever.com','Contact Us'); - $this->sidebar_link('More','https://wordpress.org/plugins/search.php?q=loudlever','More Plugins by Us'); + $this->sidebar_link('More','https://wordpress.org/plugins/tags/loudlever','More Plugins by Us'); $this->html_box_footer(true); ?> @@ -141,14 +156,33 @@ public function configuration_screen() {
- html_box_header('snb_default_asins',__('Overview',$this->i18n),true); ?>

Readers will be able to view their Bookmarks and Favorites on the page: page_title; ?>

Feel free the options[post_id]); ?> if you wish. Just remember to keep the following shortcode in the page:

[page_shortcode; ?>].

+ html_box_footer(true); ?> + +
+ + html_box_header('snb_default_asins',__('Settings',$this->i18n),true); ?> +

By default, the nav bar will only display on POSTs. Check below where you would also like it to display.

+

+ + /> + +

+

+ + /> + + +

+ html_box_footer(true); ?> + +
@@ -170,7 +204,14 @@ public function configuration_screen_help($contextual_help, $screen_id, $screen) } public function header_bar( &$wp_query) { global $wp_the_query,$post; - if ( ( $wp_query === $wp_the_query ) && !is_admin() && !is_feed() && !is_robots() && !is_trackback() && !is_home() && !is_page()) { + $opts = $this->options[options]; + // $this->log(sprintf("showing header bar\n home ops: %s\nis home %s\n front page %s", $opts[on_home], is_home(),is_front_page())); + // will never show here + if (is_admin() || is_feed() || is_robots() || is_trackback()) { return; } + // Don't show here if toggled off + if (is_home() && !$opts[on_home]) { return; } + if (is_page() && !$opts[on_page]) { return; } + if ( $wp_query === $wp_the_query ) { $this->log(sprintf("post => %s",print_r($post,1))); $author = get_the_author_meta('display_name',$post->post_author); $author_link = sprintf("%s",get_author_posts_url($post->post_author),$author ); @@ -353,7 +394,8 @@ private function init_install_options() { 'install_date' => null, 'upgrade_date' => null ), - 'post_id' => null + 'post_id' => null, + 'options' => $this->defaults ); return; } @@ -407,7 +449,18 @@ private function log($msg) { } // http://codex.wordpress.org/Creating_Tables_with_Plugins private function upgrade_plugin($opts) { - // No updates yet. + $ver = $this->get_version_as_int($this->options['plugin']['version_current']); + $this->log("in upgrade_plugin(): Version = $ver"); + if ($ver < 10) { + // we don't have the defaults + $this->options[options] = $this->defaults; + } + $this->options[plugin][version_last] = $this->options[plugin][version_current]; + $this->options[plugin][version_current] = SNB_PLUGIN_VERSION; + $this->options[plugin][upgrade_date] = Date('Y-m-d'); + $this->log(sprintf("upgrading plugin with opts %s",print_r($this->options,1))); + update_option($this->opt_key,$this->options); + return; } // Update the user's action in the database. @@ -473,6 +526,10 @@ private function delete_bookmarks_page() { } return; } + private function get_version_as_int($str) { + $var = intval(preg_replace("/[^0-9 ]/", '', $str)); + return $var; + } } diff --git a/readme.txt b/readme.txt index 26cdaca..fb90775 100644 --- a/readme.txt +++ b/readme.txt @@ -1,10 +1,10 @@ === Smart-Navbar === Contributors: loudlever Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Y8SL68GN5J2PL -Tags: navigation, bookmark, favorite +Tags: navigation, bookmark, favorite, loudlever Requires at least: 3.5 -Tested up to: 4.1.0 -Stable tag: 0.0.4 +Tested up to: 4.2.2 +Stable tag: 0.1.0 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -35,6 +35,10 @@ This plugin give you a simple way to allow your readers to bookmark or favorite == Changelog == += 0.1.0 = +* Added ability to display smart-navbar on Pages and Home page. +* Cleaned up a bunch of the code. + = 0.0.4 = * Fixed bug with enqueing of admin stylesheet diff --git a/smart-navbar.php b/smart-navbar.php index 04f651e..5f39e63 100644 --- a/smart-navbar.php +++ b/smart-navbar.php @@ -5,7 +5,7 @@ Description: Give readers the ability to favorite and bookmark POSTs with this simply styled navigation bar. Author: Loudlever Author URI: http://www.loudlever.com -Version: 0.0.4 +Version: 0.1.0 Copyright 2014-2015 Loudlever (wordpress@loudlever.com) @@ -43,7 +43,7 @@ OPTION SETTINGS --------------------------------------------------------------------------------- */ -define('SNB_PLUGIN_VERSION', '0.0.1'); +define('SNB_PLUGIN_VERSION', '0.1.0'); define('SNB_INCLUDE_URL', plugins_url('includes',__FILE__)); define('SNB_ADMIN_PAGE','smart-navbar'); define('SNB_ADMIN_PAGE_NONCE','_snb-save-options');