Skip to content

Instantly share code, notes, and snippets.

<!-- 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);
}
@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 / 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 / custom_table_hooks.php
Last active August 29, 2015 14:13
Add this to UCM in includes/plugin_custom_table_hooks/custom_table_hooks.php
<?php
class module_custom_table_hooks extends module_base{
public function init(){
hook_add('table_process_data','module_custom_table_hooks::hook_table_process_data');
}
public static function hook_table_process_data($callback, $table_manager){
@dtbaker
dtbaker / custom_dashboard_widgets.php
Created January 20, 2015 23:46
This is an example of how to add widgets to the UCM dashboard
<?php
// upload this file to includes/plugin_custom_dashboard_widgets/custom_dashboard_widgets.php
class module_custom_dashboard_widgets extends module_base{
public static function can_i($actions,$name=false,$category=false,$module=false){
if(!$module)$module=__CLASS__;
return parent::can_i($actions,$name,$category,$module);
}
@dtbaker
dtbaker / custom_table_hooks.php
Last active January 2, 2016 22:53
Modify columns from the UCM table output (i.e. remove columns from Customer table)
<?php
// This example removes the "Customer" and "Group" and "Staff" columns from the main customer page.
// It also adds some new columns to the "Customer" and "Job" listing tables.
// Upload this file to includes/plugin_custom_table_hooks/custom_table_hooks.php in the UCM folder
class module_custom_table_hooks extends module_base{
public function init(){