Skip to content

Instantly share code, notes, and snippets.

View jdevalk's full-sized avatar
😀

Joost de Valk jdevalk

😀
View GitHub Profile
@jdevalk
jdevalk / gist:2692707
Created May 14, 2012 08:29
rewrite fix
Index: wp-includes/rewrite.php
===================================================================
--- wp-includes/rewrite.php (revision 20781)
+++ wp-includes/rewrite.php (working copy)
@@ -1927,19 +1927,42 @@
}
/**
+ * Schedules a flush of the rewrite rules.
+ *
<?php
// catch some weird locales served out by WP.
$locales = array(
'ar'=> 'ar_ar',
'ca'=> 'ca_es',
'en'=> 'en_us',
'el'=> 'el_gr',
'et'=> 'et_ee',
'fi'=> 'fi_fi',
'ja'=> 'ja_jp',
@jdevalk
jdevalk / changelog-1.2.md
Created May 28, 2012 19:53
Changelog for WP SEO 1.2

If you want to help test, you can download the development version from here, or directly from here. If you find issues, please file them here.

= 1.2 (development version) =

Major improvements: all sorts of fixes to suggest and keyword check functionality which now should allow for non-ascii stuff, like Greek, Arabic, but even "weird" chars in western-European languages.

  • Bugs fixed:
    • ereg_replace != preg_replace ; in other words: alt and title tags for images in xml sitemap fixed.
    • Image size for OpenGraph now defaults to medium for thumbnail image.
    • Selecting a Facebook App as the admin of your site now actually works.
@jdevalk
jdevalk / fix-dupe-title-alts.php
Created June 15, 2012 13:22
If title attribute == alt attribute, strip title attribute.
<?php
if ( preg_match_all( '/<img [^>]+>/', $post->post_content, $matches ) ) {
$content_changed = false;
foreach ( $matches[0] as $img ) {
preg_match( '/title=("|\')([^"\']+)("|\') /', $img, $title_match );
preg_match( '/alt=("|\')([^"\']+)("|\') /', $img, $alt_match );
if ( isset($title_match[2]) && isset($alt_match[2]) && $title_match[2] == $alt_match[2] ) {
$post->post_content = str_replace( $title_match[0], '', $post->post_content );
@jdevalk
jdevalk / non-ssl-redirect.php
Created June 20, 2012 18:14
WordPress code to redirect non-admin and non-login pages to http when opened over https
<?php
// If we're not on an admin or login page, make sure we're not on https.
if ( !is_admin() && strpos($_SERVER['REQUEST_URI'], 'login.php') === false && $_SERVER['HTTPS'] == 'on' ) {
wp_redirect( "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], 301 );
}
@jdevalk
jdevalk / regex.php
Created July 2, 2012 18:41
Regex to match meta description in content
<?php
preg_match_all( '#<meta (name|content)="(.*)" (name|content)="(.*)"(\s+)?/?>#i', $content, $matches, PREG_SET_ORDER );
preg_match_all( "#<meta (name|content)='(.*)' (name|content)='(.*)'(\s+)?/?>#i", $content, $matches2, PREG_SET_ORDER );
@jdevalk
jdevalk / presstrends.php
Created August 15, 2012 19:37
Improved PressTrends tracking
<?php
/**
* PressTrends tracking
*/
function presstrends_plugin() {
// PressTrends Account API Key
$api_key = 'n6svrrn650hyckud8ghhs1o497hcm0g1o3s5';
$auth = 'dhs4fy3nhnx5x0y6gkdfwt7fz2wprguqk';
@jdevalk
jdevalk / nofollow-orangevalley.php
Created October 2, 2012 20:09
Nofollow all links to OrangeValley.
<?php
function orangevalley_link_nofollow( $content ) {
$content = preg_replace('#<a href=(\'|")http://www.orangevalley\.(nl|com)/(\'|")#', '<a rel="nofollow" href="http://www.orangevalley.com/"', $content );
return $content;
}
add_filter('the_content','orangevalley_link_nofollow');
@jdevalk
jdevalk / edd_get_purchase_id_by_key.php
Created October 27, 2012 21:16
Retrieve the purchase ID based on the purchase key
<?php
/**
* Retrieve the purchase ID based on the purchase key
*
* @access public
* @since 1.2.3
*
* @param string $key the purchase key to search for
* @return int $order_id
*/
@jdevalk
jdevalk / video-filter.php
Created November 28, 2012 08:54
Filter the video array of the Video SEO plugin to include duration from a custom field
<?php
/**
* Filter the vid array to include duration.
*
* @param array $vid The video array as determined by the indexation process
*
* @return array
*/
function filter_jwplayer_duration( $vid ) {