Skip to content

Instantly share code, notes, and snippets.

@dtbaker
dtbaker / dtbaker.wiki-mode.php
Created April 4, 2013 04:39
Register wiki custom post type
public function register_custom_post_type() {
$labels = array(
'name' => 'Wiki Pages',
'singular_name' => 'Wiki Page',
'menu_name' => 'Wiki Pages',
'parent_item_colon' => 'Parent Wiki Page:',
'all_items' => 'All Wiki Pages',
'view_item' => 'View Wiki Page',
'add_new_item' => 'Add New Wiki Page',
'add_new' => 'New Wiki Page',
@dtbaker
dtbaker / dtbaker.wiki-mode.php
Created April 4, 2013 15:41
hacking WordPress to support nested custom post types.
<?php
// get_page_by_path called in query.php 2119 !
//remove_action('template_redirect', 'redirect_canonical');
@dtbaker
dtbaker / australia_post.php
Last active December 16, 2015 04:29
working out if a product fits within the max dimensions for a "letter" delivery
// work out if we're doing a letter or parcel delivery
// Letter max is 26cm x 36cm x 2cm / 0.5kg
// everything larger will be parcel.
$max_dimensions = array(2,26,36);
if($calculate_product['weight']<=0.5){
$product_dimensions = array($calculate_product['length'],$calculate_product['width'],$calculate_product['height']);
sort($product_dimensions);
$is_letter = (
$product_dimensions[0]<=$max_dimensions[0] &&
$product_dimensions[1]<=$max_dimensions[1] &&
@dtbaker
dtbaker / plugin.php
Created July 2, 2013 02:35
Hack WordPress to perform an inter-table comparison using 'meta_query'
add_shortcode('bbp-unread-topic-index','dtbaker_bbq_unread_topics');
function dtbaker_bbq_unread_topics(){
if(is_user_logged_in()){
$result = '';
// filter the bbPress query args that are run when [bbp-topic-index] is executed.
add_filter('bbp_after_has_topics_parse_args','unread_bbp_after_has_topics_parse_args',3,1);
// adjust the generated 'where' SQL to perform a table comparison
add_filter('get_meta_sql','dtbaker_get_meta_sql',3,6);
// run the built in bbpress shortcode which does everything nicely
$possibleTemplates = array(
plugin_dir_path( __FILE__ ).'/template_file_name.php', // default template
TEMPLATEPATH.'/my_plugin_name/template_file_name.php', // user can override default with this template
STYLESHEETPATH.'/my_plugin_name/template_file_name.php', // or user can override default with this template
);
$tempalteToUse = false;
foreach($possibleTemplates as $possibleTemplate){
if(is_readable($possibleTemplate)){
$tempalteToUse = $possibleTemplate;
}
@dtbaker
dtbaker / widget_sample.php
Created August 12, 2014 04:41
Sample PHP for AdminLTE UCM Dashboard Widget
<?php
// this sample widget will show how many jobs were started in the last 7 days:
if(class_exists('module_job',false) && module_job::can_i('view','Jobs')){
$jobs = module_job::get_jobs(array(
'date_start_after'=>date('Y-m-d',strtotime('-7 days'))
),array('columns'=>'u.job_id'));
ob_start();
// icons from http://ionicons.com/
?>
@dtbaker
dtbaker / gist:acd15e542d98bff68034
Created August 26, 2014 04:16
Get WordPress posts incremently to save on PHP memory usage
// memory friendly alternative to get_posts( array( 'posts_per_page' => '-1' ) );
$product_page = 1;
$product_per_page = 10;
$product_query = new WP_Query( array(
'posts_per_page' => $product_per_page,
'paged' => $product_page,
'post_type' => array( 'product', 'product_variation' ),
) );
$product_ids = array();
@dtbaker
dtbaker / dtbaker.shortcode.php
Created September 30, 2014 01:23
Custom WordPress MCE View and shortcode editor
<?php
/**
* Class dtbaker_Shortcode_Banner
* handles the creation of [boutique_banner] shortcode
* adds a button in MCE editor allowing easy creation of shortcode
* creates a wordpress view representing this shortcode in the editor
* edit/delete button on wp view as well makes for easy shortcode managements.
*
* separate css is in style.content.css - this is loaded in frontend and also backend with add_editor_style
@dtbaker
dtbaker / signup.php
Created October 6, 2014 05:20
proxy PHP script for handling UCM customer signups
<?php
// upload this signup.php form to your website then change the UCM form action="" to this signup.php file (e.g. <form action="http://yourwebsite.com/signup.php"> )
// CHANGE THIS URL TO YOUR UCM SIGNUP URL
$url = "http://yourwebsite.com/ucm/ext.php?m=customer&h=public_signup";
$ch = curl_init($url);
// put your code here that does any local processing with form submit data
@dtbaker
dtbaker / google_map.php
Last active June 25, 2016 00:17
Easy Google Map WordPress Shortcode + Google Map Widget + MCE View + MCE Button
<?php
/**
* Class dtbaker_Widget_Google_Map and dtbaker_Shortcode_Google_Map
* Easily create a Google Map on any WordPress post/page (with an insert map button).
* Easily create a Google Map in any Widget Area.
* Author: [email protected]
* Copyright 2014
*/