Skip to content

Instantly share code, notes, and snippets.

@dtbaker
dtbaker / gist:da02576c021646cd97d7
Created January 7, 2015 01:23
boutique_line shortcode
<?php
/**
* Class dtbaker_Shortcode_Line
* handles the creation of [boutique_line] 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.
* Author: dtbaker@gmail.com
* Copyright 2014
@dtbaker
dtbaker / query.php
Last active August 29, 2015 14:09
Hacky caching with PHP
$key = $_SERVER['REMOTE_ADDR'] . serialize($_REQUEST);
if(strlen($key) < 500){ // help prevent flooding.
$key = md5($key);
// global so we can find it in the shutdown function
$GLOBALS['wordpress_temp_file'] = dirname(__FILE__).'/cache/wp_'.basename($key);
if(is_file($GLOBALS['wordpress_temp_file']) && filemtime($GLOBALS['wordpress_temp_file']) > (time() - 3600)){
$data = unserialize(file_get_contents($GLOBALS['wordpress_temp_file']));
echo $data['content'];
exit;
}
@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);
}
@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
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 / 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);
<!-- 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 / 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: dtbaker@gmail.com
* Copyright 2014
*/
@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 / 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