Skip to content

Commit

Permalink
allowing the navbar to be displayed on pages and home
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Luck committed Jul 16, 2015
1 parent 133659e commit 841c06a
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
81 changes: 69 additions & 12 deletions includes/classes/SmartNavbar.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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('<div id="message" class="updated fade"><p>%s</p></div>',$message);
} elseif ($this->error) { // reload the form post in this form
Expand Down Expand Up @@ -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:[email protected]','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);
?>
</div>
Expand All @@ -141,14 +156,33 @@ public function configuration_screen() {
<div class="has-sidebar sm-padded">
<div id="post-body-content" class="has-sidebar-content">
<div class="meta-box-sortabless">
<?php
if(function_exists('wp_nonce_field')){ wp_nonce_field(SNB_ADMIN_PAGE_NONCE); }
?>
<!-- Default Settings -->
<?php $this->html_box_header('snb_default_asins',__('Overview',$this->i18n),true); ?>
<p>Readers will be able to view their Bookmarks and Favorites on the page: <a href='<?php echo $page_link; ?>'><?php echo $this->page_title; ?></a></p>
<p>Feel free the <?php echo edit_post_link('modify the page','','',$this->options[post_id]); ?> if you wish. Just remember to keep the following shortcode in the page:</p>
<p><code>[<?php echo $this->page_shortcode; ?>]</code>.</p>
<?php $this->html_box_footer(true); ?>

<form method="post" action="admin.php?page=<?php echo SNB_ADMIN_PAGE; ?>">
<?php
if(function_exists('wp_nonce_field')){ wp_nonce_field(SNB_ADMIN_PAGE_NONCE); }
?>
<?php $this->html_box_header('snb_default_asins',__('Settings',$this->i18n),true); ?>
<p>By default, the nav bar will only display on POSTs. Check below where you would also like it to display.</p>
<p>
<input type='hidden' name="snb_opt[on_page]" value='0'/>
<input type="checkbox" name="snb_opt[on_page]" id="snb_on_page" class='amznpp_input' value="1" <?php if ($opts[on_page] == 1) { echo 'checked'; } ?> />
<label class='snb_label' for='snb_on_page'>Display on Pages?</label>
</p>
<p>
<input type='hidden' name="snb_opt[on_home]" value='0'/>
<input type="checkbox" name="snb_opt[on_home]" id="snb_on_home" class='amznpp_input' value="1" <?php if ($opts[on_home] == 1) { echo 'checked'; } ?> />
<label class='snb_label' for='snb_on_home'>Display on Home?</label>
<input type="hidden" name="save_settings" value="1" />
</p>
<?php $this->html_box_footer(true); ?>
<input type="submit" class="button-primary" name="save_button" value="<?php _e('Update Settings', $this->i18n); ?>" />
</form>
</div>
</div>
</div>
Expand All @@ -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("<a href='%s'>%s</a>",get_author_posts_url($post->post_author),$author );
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}


}
Expand Down
10 changes: 7 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions smart-navbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([email protected])
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 841c06a

Please sign in to comment.