Skip to content

Instantly share code, notes, and snippets.

@BronsonQuick
BronsonQuick / gist:8fc49236e57d94abf7cc
Created May 4, 2015 06:03
Delete 1000 WCCommerce Completed orders at a time via WP-CLI
wp post list --field=ID --post_type=shop_order --post_status='wc-completed' --posts_per_page=1000 | xargs wp post delete --force
@BronsonQuick
BronsonQuick / wordcamp_brisbane_jetpack_SCSS.scss
Created June 5, 2015 06:19
WordCamp Brisbane JetPack SCSS for Pascal
/*
Welcome to Custom CSS!
CSS (Cascading Style Sheets) is a kind of code that tells the browser how
to render a web page. You may delete these comments and get started with
your customizations.
By default, your stylesheet will be loaded after the theme stylesheets,
which means that your rules can take precedence and override the theme CSS
rules. Just write here what you want to change, you don't need to copy all
@BronsonQuick
BronsonQuick / basic_testimonials_custom_post_type.php
Created March 4, 2012 06:34
A basic Testimonials Custom Post Type for WordPress
<?php add_action( 'init', 'sennza_register_cpt_testimonial' );
function sennza_register_cpt_testimonial() {
$args = array(
'public' => true,
'query_var' => 'testimonial',
'rewrite' => array(
'slug' => 'testimonials',
'with_front' => false
),
@BronsonQuick
BronsonQuick / meta_boxes_for_testimonials_cpt.php
Created March 4, 2012 06:40
Add meta boxes to the Testimonials WordPress CPT
<?php /**
* Adds a custom meta box to the Testimonials editor page for collecting
* Testimonial meta.
* Refer to: https://gist.github.com/1971046 for the Custom Post Type Setup
*
* @since 1.0
*/
function sennza_add_meta_boxes() {
add_meta_box( 'sennza_testimonials_meta_box', __( 'Testimonial Details' ), 'sennza_testimonials_meta_box', 'testimonial', 'side', 'core' );
}
@BronsonQuick
BronsonQuick / random_testimonial_widget.php
Created March 4, 2012 06:46
A WordPress widget to generate random Testimonials from the Testimonials Custom Post Type
<?php if( ! class_exists( 'Testimonials_Widget' ) ) :
/**
* Create a widget to display a random testimonial post.
* Refer to https://gist.github.com/1971046 and https://gist.github.com/1971054 for the Custom Post Type and Meta Box Setup
*
* @since 1.0
*/
class Testimonials_Widget extends WP_Widget {
function Testimonials_Widget() {
@BronsonQuick
BronsonQuick / add_categories_to_pages.php
Created March 4, 2012 07:06
Add Categories to Pages in WordPress
<?php /*
* In some weird occasions Pages need to have Categories like Posts in WordPress.
*/
add_action( 'init', 'sennza_add_page_cats' );
function sennza_add_page_cats()
{
register_taxonomy_for_object_type( 'category', 'page' );
}
?>
@BronsonQuick
BronsonQuick / cromwell-downloads-widget.php
Created March 4, 2012 07:34
A WordPress widget to display all attachments to a post/page of a certain type
<?php
/*
* A WordPress widget that displays all PDF's attached to the current post
* You can adapt this widget to extract other file types by altering the 'post_mime_type' => 'application/pdf'
* argument refer to: http://en.wikipedia.org/wiki/Internet_media_type#List_of_common_media_types for mime types
*/
class Sennza_PDF_Download_Widget extends WP_Widget
{
/** constructor */
@BronsonQuick
BronsonQuick / add_hr_to_tinymce.php
Created March 4, 2012 07:40
Add the horizontal rule <hr> button back to the TinyMCE editor in WordPress
<?php /*
* Add the horizontal rule button back to the WordPress TinyMCE editor
*/
function sennza_hr_button($buttons) {
$buttons[] = 'hr';
return $buttons;
}
add_filter( 'mce_buttons', 'sennza_hr_button' ); ?>
@BronsonQuick
BronsonQuick / add_superscript_to_tinymce.php
Created March 4, 2012 07:15
Add back the Superscript button in the TinyMCE editor in WordPress
<?php
/* Add back the superscript TinyMCE button in WordPress */
function sennza_add_more_buttons( $buttons )
{
$buttons[] = 'sup';
return $buttons;
}
add_filter( 'mce_buttons_3', 'sennza_add_more_buttons' );
?>
@BronsonQuick
BronsonQuick / enhanced_excerpt.php
Created March 4, 2012 07:24
Extract the_content in WordPress but only bring back links and <strong> tags
<?php /*
* Sometimes you will might want something like the_excerpt but still want <strong> tags. Add this function and call it
* inside your theme template file e.g. sennza_enhanced_excerpt();
*/
function sennza_enhanced_excerpt( $content ) {
$content = strip_shortcodes( $content );
$content = str_replace( ']]>', ']]&gt;', $content );
$content = preg_replace( '/<img[^>]+./','',$content );
$content = preg_replace( '%<div.+?</div>%is', '', $content );
$content = preg_replace( '%<object.+?</object>%is', '', $content );