Skip to content

Instantly share code, notes, and snippets.

$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
<!-- put this file in your theme folder -->
<div id="googlemap<?php echo $map_id; ?>" class="googlemap" style="height:<?php echo $height; ?>px;"></div>
<div class="clear"></div>
<?php if ( $enlarge_button ) { ?>
<div class="map_buttons">
<a href="http://maps.google.com/maps?q=<?php echo htmlspecialchars( urlencode( $address ) ); ?>"
target="_blank"><?php _e( 'Enlarge Map', 'boutique' ); ?></a>
</div>
@dtbaker
dtbaker / functions.php
Created October 27, 2014 06:08
Hack for WordPress RTL bracket fix
function dtbaker_rtl_bracket_hack($content){
if(is_rtl()){
$content = preg_replace('#<p>([^<]+)\)\s*</p>#','<p>$1)&#x200E;</p>',$content);
$content = preg_replace('#<p>\s*\(([^<]+)</p>#','<p>&#x200E;($1</p>',$content);
}
return $content;
}
add_filter('the_content','dtbaker_rtl_bracket_hack',100,1);
@dtbaker
dtbaker / functions.php
Last active August 29, 2015 14:08
WordPress RTL bracket hack fix using JavaScript
function dtbaker_rtl_bracket_js_hack() {
?>
<script type="text/javascript">
(function($){
$('p:contains(")")').each(function(){
$(this).html($(this).html().replace(/\)(\s*)$/,')&#x200E;\1').replace(/^(\s*)\(/,'\1&#x200E;('));
});
})(jQuery);
</script>
<?php
@dtbaker
dtbaker / style.less
Created October 30, 2014 08:27
simple less mixin
@highdpi: ~"((-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx))";
.double_background(@url){
background: ~"@{url}";
@media @highdpi {
background: ~`@{url}.replace(/images\//g, 'images/2x/')`;
}
}
#your_element{
@dtbaker
dtbaker / functions.php
Last active August 29, 2015 14:08
Show WordPress post count per tag
add_filter ( 'wp_tag_cloud', 'tag_cloud_count' );
function tag_cloud_count( $return ) {
return preg_replace('#(<a[^>]+\')(\d+)( topics?\'[^>]*>)([^<]*)<#imsU','$1$2$3$4 ($2)<',$return);
}