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:1918689
Created February 26, 2012 19:58
Turn a spiderable list of links into a dropdown + a go button with jQuery
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
// Inspiration partly from: http://stackoverflow.com/questions/1897129
jQuery(document).ready(function($) {
$('ul.dropdown').each(function(){
var list = $(this);
var select = $(document.createElement('select'))
.attr('id',$(this).attr('id'))
@jdevalk
jdevalk / links.php
Created March 28, 2012 17:33
Link template
@jdevalk
jdevalk / gist:2426489
Created April 20, 2012 06:11
Search query
SELECT c.Content, c.Title, c.ID, c.CTID, c.RID, r.Sitename,
CASE WHEN c.Title LIKE '%conversion%' THEN 1 ELSE 0 END AS titlematch,
CASE WHEN c.Content LIKE '%conversion%' THEN 1 ELSE 0 END AS contentmatch,
MATCH (c.Title, c.Content) AGAINST ('conversion') AS relevance
FROM Chapters c LEFT JOIN Reviews r
ON c.RID = r.ID
WHERE MATCH(c.Title, c.Content) AGAINST ('conversion' IN BOOLEAN MODE)
HAVING relevance > 0
ORDER BY titlematch DESC, contentmatch DESC, relevance DESC
LIMIT 50
@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 / 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 / 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
*/