Skip to content

Instantly share code, notes, and snippets.

diff --git a/WordPress-Dropins/wp-stack-cdn.php b/WordPress-Dropins/wp-stack-cdn.php
index 4099276..070ace8 100644
--- a/WordPress-Dropins/wp-stack-cdn.php
+++ b/WordPress-Dropins/wp-stack-cdn.php
@@ -54,11 +54,11 @@ class WP_Stack_CDN_Plugin extends WP_Stack_Plugin {
$preg_path = preg_quote( $path, '#' );
// Targeted replace just on uploads URLs
- return preg_replace( "#=([\"'])(https?://{$domain})?$preg_path/((?:(?!\\1]).)+)\.(" . implode( '|', $this->extensions ) . ")(\?((?:(?!\\1).)+))?\\1#", '=$1http://' . $this->cdn_domain . $path . '/$3.$4$5$1', $content );
+ return preg_replace( "#=([\"'])(https?://{$domain})?$preg_path/((?:(?!\\1]).)+)\.(" . implode( '|', $this->extensions ) . ")(\?((?:(?!\\1).)+))?\\1#", '=$1//' . $this->cdn_domain . $path . '/$3.$4$5$1', $content );
@tollmanz
tollmanz / make-info.php
Created June 24, 2014 17:50
Getting info from .org repo
<?php
function ttf_get_make_stats() {
// Make remote request to WP.org
$response = wp_remote_post(
'http://api.wordpress.org/themes/info/1.0/',
array(
'body' => array(
'action' => 'theme_information',
'request' => serialize( (object) array(
@tollmanz
tollmanz / wordpress-exporter-unlimited-execution-time.php
Created November 13, 2011 19:58
Increase WordPress Exporter Script Execution Time
// Run function only when the export is initiated
add_action( 'export_wp', 'zdt_unlimited_script_time' );
/**
* Sets script execution time to unlimited.
*
* @return void
*/
function zdt_unlimited_script_time() {
set_time_limit( 0 );
@tollmanz
tollmanz / gist:1968124
Created March 3, 2012 20:46
Get Expired Transient
/**
* Used in front end requests to get the latest Tweet.
*
* @return bool|string
*/
function get_latest_tweet() {
// Attempt to get the transient
if ( $tweet = get_transient( 'my_latest_tweet' ) ) {
return $tweet;
@tollmanz
tollmanz / front-end-display.php
Created March 6, 2012 04:46
Pinterest image functions
<?php if ( $image = zdt_get_social_image( $post ) ) : ?>
<div class="pin_share">
<a href="http://pinterest.com/pin/create/button/?url=<?php echo urlencode( esc_url( get_the_permalink( get_the_ID() ) ); ?>&media=<?php echo urlencode( esc_url( $image ) ); ?>&description=<?php echo urlencode( esc_html( get_the_excerpt( get_the_ID() ) ); ?>" class="pin-it-button" count-layout="none">Pin It</a>
</div>
<?php endif; ?>
@tollmanz
tollmanz / gist:1986992
Created March 6, 2012 15:52
Happy AJAX on .com
/**
* Generates a domain-mapping safe URL on WordPress.com
* Core's ajaxurl uses admin_url() which returns *.wordpress.com which doesn't work for the front-end on domain-mapped sites.
* This works around that and generates the correct URL based on context.
*/
function admin_ajax_url( $path = '' ) {
if ( is_admin() )
$url = admin_url( 'admin-ajax.php' );
else
$url = home_url( 'wp-admin/admin-ajax.php' );
@tollmanz
tollmanz / memcached-vals.php
Created March 12, 2012 18:13
Return values for memcache in WordPress
<?php
add_action( 'init', 'test' );
function test() {
// Returns bool( false )
set_transient( 'test-trans-false', false, 5 );
get_transient( 'test-trans-false' );
// Return bool( false )
set_transient( 'test-trans-true', true, 5 );
get_transient( 'test-trans-true' );
@tollmanz
tollmanz / gist:2209983
Created March 26, 2012 21:43
Add enctype to post form
<?php
function zt_add_enctype {
echo ' enctype="multipart/form-data"';
}
add_action( 'post_edit_form_tag', 'zt_add_enctype' );
@tollmanz
tollmanz / you-lock-it-up.php
Created April 10, 2012 05:26
A locking technique for high concurrency situations in WordPress
<?php
function test_race() {
if ( wp_cache_get( 'lock' ) )
return false;
wp_cache_add( 'lock', 1 );
$key = time();
wp_cache_add( $key, 0 );
@tollmanz
tollmanz / no-you-lock-it-up.php
Created April 10, 2012 15:50
Another locking technique that should only allow one execution per hour
<?php
function test_race() {
$key = date( 'YdmH', time() );
wp_cache_add( $key, 0 );
if ( 1 !== wp_cache_incr( $key ) )
return false;
// Do the things
}