This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_pre_user_query( $query ) { | |
$where = get_posts_by_author_sql( 'post' ) . " AND MONTH(post_date) = " . date( 'm', strtotime( '-1 month' ) ); | |
$query->query_from = str_replace( get_posts_by_author_sql( 'post' ), $where, $query->query_from ); | |
$query->query_where .= " AND post_count > 0 "; | |
$query->query_limit .= " LIMIT 5 "; | |
} | |
function my_magic_loop() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Dirty, easy to miss a ' or " or . | |
echo '<a href="' . get_permalink() . '" class="link">' . get_the_title() . '</a>'; | |
// Clean, easier to read | |
printf( '<a href="%s" class="link">%s</a>', get_permalink(), get_the_title() ); | |
// Almost as clean, and more secure, maybe a little paranoic :) | |
printf( '<a href="%s" class="link">%s</a>', esc_url( get_permalink() ), esc_html( get_the_title() ) ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Moved to: https://github.com/kovshenin/escape-ngg | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This script will rewrite the date column in a PayPal CSV | |
export from m/d/y to Y-m-d format. | |
Usage: | |
# python fix-paypal-csv-dates.py input_file.csv > output_file.csv | |
""" | |
import csv, sys | |
from time import strptime, strftime | |
filename = sys.argv[1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Shortcodes | |
add_shortcode( 'my', function() { return 'my'; } ); | |
add_shortcode( 'my-shortcode', function() { return 'my-shortcode'; } ); | |
add_shortcode( 'my_shortcode', function() { return 'my_shortcode'; } ); | |
/** | |
* Results: | |
* | |
* [my] - my |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$content = ''; | |
$shortcodes = array( 'one', 'two', 'three', 'four' ); | |
foreach ( $shortcodes as $shortcode ) { | |
add_shortcode( $shortcode, function() use ( $shortcode ) { return $shortcode; } ); | |
$content .= sprintf( ' Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. [%s]', $shortcode ); | |
} | |
$content = str_repeat( $content, 10 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Register Some Post Types | |
*/ | |
add_action( 'init', 'my_register_post_types' ); | |
function my_register_post_types() { | |
register_post_type( 'cpt-1', array( | |
'label' => 'Image', | |
'public' => true, | |
'show_in_menu' => true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Featured Image Size in Metabox | |
* Description: Adds 123x456 to the metabox title in featured image. | |
*/ | |
add_action( 'do_meta_boxes', 'my_do_meta_boxes' ); | |
function my_do_meta_boxes( $post_type ) { | |
global $wp_meta_boxes; | |
if ( ! current_theme_supports( 'post-thumbnails', $post_type ) || ! post_type_supports( $post_type, 'thumbnail' ) ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Hide posts from category on home page | |
*/ | |
add_action( 'pre_get_posts', 'my_pre_get_posts' ); | |
function my_pre_get_posts( $query ) { | |
// Category IDs to exclude | |
$exclude_categories = array( 1, 2, 3 ); | |
if ( $query->is_home() ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$a = 15; | |
add_filter( 'my_filter', function() use ( $a ) { | |
return "I'm a filter and here's a: $a"; | |
} ); | |
$s = apply_filters( 'my_filter', '' ); | |
echo $s; |