Skip to content

Instantly share code, notes, and snippets.

@jessepearson
jessepearson / woocommerce-notices.scss
Last active August 29, 2015 14:06
WooCommerce Notice CSS Classes
.woocommerce-info {
border-top: 3px solid #5b95a4;
&:before {
background-color: #5b95a4;
}
}
.woocommerce-message {
border-top: 3px solid #6b9e56;
<?php
// func to sort the columns
add_action( 'pre_get_posts', 'floorplan_order_columns', 9999 );
function floorplan_order_columns( $query ) {
// if we're not in the admin, or if it isn't the custom post type, exit
if( ! is_admin() || $query->get( 'post_type' ) !== 'floorplan' )
return;
// get the orderby, if it is not set, leave it blank
<?php
switch( $orderby ) {
case 'fp_sf_tot':
$query->set( 'meta_key', 'fp_sf_tot' );
$query->set( 'orderby', 'meta_value_num' );
break;
case 'fp_pdf':
$query->set( 'meta_key', 'fp_pdf' );
$query->set( 'orderby', 'meta_value' );
@jessepearson
jessepearson / get-page-by-template.php
Created October 13, 2014 16:51
Getting a WordPress page by its template
<?php
// get our portfolio page
$args = array(
'post_type' => 'page',
'posts_per_page' => 1,
'meta_key' => '_wp_page_template',
'meta_value' => 'template-galleries.php'
);
$portfolio_page = get_posts( $args );
@jessepearson
jessepearson / admin-custom.js
Created October 15, 2014 15:40
Turn WordPress editor resizing on and off based on page template
jQuery( document ).ready( function( $ ) {
// our variables
var page_template = $( '#page_template' ), // Page - page template select box
main_editor_container = $( '#postdivrich' ), // All - main editor
editor_expand_toggle = $( '#editor-expand-toggle' ); // All - the checkbox to turn autoresizing of the editor on and off.
// function that flips the switch to turn the auto resize of the MCE editor on and off
// basically, it gets it to reinitialize itself once we've shown it after hiding it, fixing layout issues
function expand_toggle(){
if( editor_expand_toggle.prop( 'checked' ) ) {
@jessepearson
jessepearson / wordpress_widget_api_example_1.php
Last active August 29, 2015 14:13
Example from WordPress Codex for the Widget API
<?php
/**
* Register widget with WordPress.
*/
function __construct() {
parent::__construct(
'foo_widget', // Base ID
__( 'Widget Title', 'text_domain' ), // Name
array( 'description' => __( 'A Foo Widget', 'text_domain' ), ) // Args
);
@jessepearson
jessepearson / wordpress_widget_api_example_2.php
Created January 8, 2015 17:52
Example from WordPress Codex for the Widget API with CSS classes
<?php
/**
* Register widget with WordPress.
*/
function __construct() {
parent::__construct(
'foo_widget', // Base ID
__( 'Widget Title', 'text_domain' ), // Name
array(
'classname' => 'YOUR WIDGET CLASSES',
@jessepearson
jessepearson / line-177-widgets.js
Created January 13, 2015 00:46
Line 177 from wp-admin/js/widgets.js
$( document ).trigger( 'widget-added', [ $widget ] );
@jessepearson
jessepearson / admin-media-uploader-init.js
Created January 13, 2015 00:49
Using WordPress jQuery widget added callback
// if a widget is added, then initialize the media_uploader in that widget
$( document ).on( 'widget-added', function( event, target ) {
init_media_uploader( target );
} );
@jessepearson
jessepearson / add-nav-parent-count.php
Created March 4, 2015 17:13
Functions to add a parent count to WordPress nav menus. This is useful if you need to change nav element size based on the number of parent/top level elements.
<?php
/**
* Gets the count of the parent items in a nav menu based upon the id specified.
*
* @param string $nav_id The id of the nav item to get the parent count for.
* @return bool|int False on fail, or the count of how many parent items there are.
* @uses wp_get_nav_menu_items
*/
function count_nav_parent_items( $nav_id = null ) {