Skip to content

Instantly share code, notes, and snippets.

@pommiegranit
Created February 27, 2014 00:07
Show Gist options
  • Save pommiegranit/9241565 to your computer and use it in GitHub Desktop.
Save pommiegranit/9241565 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Sidr - Side Menus
* Plugin URI: http://wpmu.org
* Description: Adds the Sidr plugin to WordPress. Sidr is a jQuery plugin written by Alberto Valero http://www.berriart.com/sidr/
* Version: 1.0
* Author: Chris Knowles
* Author URI: http://wpmu.org
* License: GPL2
*/
/*
* Add the necessary styles and javascript files
*/
function sidr_scripts_styles(){
/*
* Adds JavaScript for handling the navigation menu hide-and-show behavior.
*/
wp_enqueue_script( 'sidr' , plugins_url() . '/sidr/js/jquery.sidr.min.js', array('jquery'), '1.0', true );
/*
* Loads stylesheet.
*/
wp_enqueue_style( 'sidr-style', plugins_url() . '/sidr/stylesheets/jquery.sidr.dark.css');
}
/*
* If the sidebars have widgets (are active) then add them to the bottom of the HTML and output javascript to 'sidr' them
*/
function sidr_footer() {
if ( is_active_sidebar( 'sidr-left' ) ) :
echo ' <div id="sidr-left" class="sidebar-container sidr" role="complementary">
<div class="widget-area">';
dynamic_sidebar( 'sidr-left' );
echo ' </div><!-- .widget-area -->
</div><!-- #sidr-left -->
<script language="javascript">
(function($) {
$(document).ready(function(){
// hook up the left side menu
$("#sidr-left-link").sidr({
name: "sidr-left",
side: "left"
});
});
// just to make sure that not visible so that sidr works
$("#sidr-left").css("display","none");
})(jQuery);
</script>';
endif;
if ( is_active_sidebar( 'sidr-right' ) ) :
echo ' <div id="sidr-right" class="sidebar-container sidr" role="complementary">
<div class="widget-area">';
dynamic_sidebar( 'sidr-right' );
echo ' </div><!-- .widget-area -->
</div><!-- #sidr-right -->
<script language="javascript">
(function($) {
$(document).ready(function(){
// hook up the right side menu
$("#sidr-right-link").sidr({
name: "sidr-right",
side: "right"
});
});
// just to make sure that not visible so that sidr works!
$("#sidr-right").css("display","none");
})(jQuery);
</script>';
endif;
}
/*
* Add a sidr specific menu
*/
function sidr_setup() {
// This theme uses wp_nav_menu() in one location.
register_nav_menu( 'sidr-menu', __( 'Sidr Menu' ) );
}
/*
* Create 2 new sidebars, one for the left and one for the right
*/
function sidr_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidr Left Sidebar' ),
'id' => 'sidr-left',
'description' => __( 'Left-hand Side Menu' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __( 'Sidr Right Sidebar' ),
'id' => 'sidr-right',
'description' => __( 'Right-hand Side Menu' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
add_action( 'wp_enqueue_scripts', 'sidr_scripts_styles' );
add_action( 'wp_footer' , 'sidr_footer' );
add_action( 'after_setup_theme', 'sidr_setup' );
add_action( 'widgets_init' , 'sidr_widgets_init' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment