Advanced Tax Query

$args = array(
'post_type' => 'actions',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
//'relation' => 'AND',
array(
'taxonomy' => 'actions_difficulty_levels',
'field' => 'slug',
'terms' => array($term)
),
array(
'taxonomy' => 'actions_tags',
'field' => 'slug',
'terms' => array('rebate'),
//'operator' => 'NOT IN'
)
)
);
$actions = get_posts($args);

Create a Role

$nl_roles = new NLRoles();

class NLRoles{

public function __construct(){
add_action('init',array(&$this,'init'));
}

public function init(){
add_role('nl_document_user',__('Document User'),
array(
'read' => true, // true allows this capability
//'edit_posts' => true,
//'delete_posts' => false, // Use false to explicitly deny
)
);

}
}

Meta Box Datepicker

public function meta_box_1($post){
// Enqueue Datepicker + jQuery UI CSS
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_style('jquery-ui-style','http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/smoothness/jquery-ui.css',true);

//This is where the normal meta box stuff goes. Nonce, get_post_meta, etc

?>
<script type="text/javascript">jQuery(document).ready(function(){ jQuery('#presentation_date').datepicker({dateFormat : 'mm/dd/yy'}); });</script>
<?php
}

Password Protected Directory

# .htaccess file in the directory you want to protect, the first line prevents wordpress 404 page:

ErrorDocument 401 default
AuthUserFile /home/sitename/.htpasswds/.htpasswd
AuthType Basic
AuthName "Restricted Area"
Require valid-user

SSL Switcher

<?php
//Define to activate system
define('TER_SSL','https'); //'https' for a mostly secure site, 'http' for mostly unsecured

function ter_ssl_meta_box(){
global $post;
$disabled_post_types = array('attachment','revision','nav_menu_item','post');
if(in_array(get_post_type($post),$disabled_post_types )) return;
if(TER_SSL == 'https') $checkbox_text = 'Not Secured';
else $checkbox_text = 'Secured';
echo '<div class="misc-pub-section misc-pub-section-last">';
wp_nonce_field(plugin_basename(__FILE__),'ter_ssl_nonce');
$ter_ssl_meta = get_post_meta($post->ID,'_ter_ssl_meta',true);
if($ter_ssl_meta) $checked = ' checked="checked"';
echo '<input type="checkbox" name="ter_ssl_meta" id="ter-ssl-meta" value="checked"' . $checked . '> ' . $checkbox_text;
echo '</div>';
}
if(TER_SSL) add_action('post_submitbox_misc_actions','ter_ssl_meta_box');

function ter_ssl_save_meta_box($post_id){
if(!isset($_POST['post_type'])) return $post_id;
$disabled_post_types = array('attachment','revision','nav_menu_item');
if(in_array($_POST['post_type'],$disabled_post_types)) return $post_id;
if(!wp_verify_nonce($_POST['ter_ssl_nonce'],plugin_basename(__FILE__))) return $post_id;
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
if(!current_user_can('edit_post',$post_id)) return $post_id;
if($_POST['ter_ssl_meta'] == 'checked') update_post_meta( $post_id, '_ter_ssl_meta', $_POST['ter_ssl_meta'] );
else delete_post_meta( $post_id, '_ter_ssl_meta');
}
if(TER_SSL) add_action('save_post','ter_ssl_save_meta_box');

function ter_ssl_template_redirect(){
//Add funciton call to top of header.php, or use a wordpress action
if(!TER_SSL) return;
global $post;
$ter_ssl_meta = get_post_meta($post->ID,'_ter_ssl_meta',true);
if(!$ter_ssl_meta) return;
if(TER_SSL == 'https' && $_SERVER['HTTPS'] == 'on'){ wp_redirect('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],301); exit; }
elseif(TER_SSL == 'http' && $_SERVER['HTTPS'] != 'on'){ wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],301); exit; }
}

function ter_ssl_content_filter($content){
if(isset($_SERVER['HTTPS'])) $content = ereg_replace('http://' . $_SERVER['SERVER_NAME'],'https://' . $_SERVER['SERVER_NAME'],$content);
return $content;
}
if(TER_SSL) add_filter('the_content','ter_ssl_content_filter');

?>

jQuery click to open menus

<script type="text/javascript">
jQuery(document).ready(function(){
frCurrentOpenMenuId = false;
jQuery('#mobile-nav a[href="#"]').click(function(event){
var parent = jQuery(this).parent().attr('id');
if(frCurrentOpenMenuId == parent){
jQuery('#' + parent).removeClass('submenu-open');
frCurrentOpenMenuId = false;
}
else{
jQuery('.menu-item-has-children').removeClass('submenu-open');
jQuery('#' + parent).addClass('submenu-open');
frCurrentOpenMenuId = parent;
event.preventDefault();
event.stopPropagation();
}
});
jQuery(document).click(function(){ jQuery('.menu-item-has-children').removeClass('submenu-open'); frCurrentOpenMenuId = false; });
});
</script>

Meta box for custom sidebar

function ter_create_page_meta_box(){ new TerPageMetaBox(); }

if(is_admin()){
add_action('load-post.php','ter_create_page_meta_box');
add_action('load-post-new.php','ter_create_page_meta_box');
}

class TerPageMetaBox{
public function __construct(){
add_action('add_meta_boxes',array($this,'add_meta_box'));
add_action('save_post',array($this,'save'));
}

public function add_meta_box($post_type){
$post_types = array('page','locations','services','resources');
if(in_array($post_type,$post_types)) add_meta_box('ter_page_meta_box',__('Custom Sidebar HTML','terra'),array($this,'render_meta_box_content'),$post_type,'advanced','high');
}

public function save($post_id){
$post_types = array('page','locations','services','resources');
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if(!in_array($_POST['post_type'],$post_types)) return $post_id;
if(!wp_verify_nonce($_POST['ter_custom_sidebar'],plugin_basename(__FILE__))) return $post_id;
if(!current_user_can('edit_post',$post_id)) return $post_id;
update_post_meta($post_id,'ter_custom_sidebar_html',$_POST['ter_custom_sidebar_html']);
}

public function render_meta_box_content($post){
wp_nonce_field(plugin_basename(__FILE__),'ter_custom_sidebar');
echo '<label>Sidebar HTML:</label><br>';
echo '<textarea style="width:90%" name="ter_custom_sidebar_html">' . esc_attr(get_post_meta($post->ID,'ter_custom_sidebar_html',1)) . '</textarea>';
}
}

Add meta box to attachment

<?php

$hypbi_attachment_meta = new HypbiAttachmentMeta();

class HypbiAttachmentMeta{
public function __construct(){
add_filter('attachment_fields_to_edit',array($this,'add_image_meta_field'),null,2);
add_filter('attachment_fields_to_save',array($this,'save_image_meta_field'),null,2);
}
public function add_image_meta_field($form_fields,$post){
$form_fields['hypbi_option_code'] = array(
'label' => __('Build It Option Code'),
'value' => get_post_meta($post->ID,'_hypbi_option_code', true),
'helps' => __('Comma separated option code. For multiple options separate with pipe |'),
);
return $form_fields;
}
public function save_image_meta_field($post,$attachment){
if(isset($attachment['hypbi_option_code'])) update_post_meta($post['ID'],'_hypbi_option_code',$attachment['hypbi_option_code']);
return $post;
}
}

?>

No Index https, redirect https to http

RewriteEngine on

RewriteCond %{HTTPS} ^on$
RewriteCond %{REQUEST_URI} ^/robots.txt$
RewriteRule ^(.*)$ /robots-ssl.txt [L]

#this page has to be on https
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} ^/ssl.php$ [NC]
RewriteRule ^(.*)$ https://mydomain.com/$1 [L,R=301]

#all other pages have to be on http
RewriteCond %{SERVER_PORT} ^443$ [OR]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/ssl.php$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]