This file contains 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 | |
/** | |
* Return posts with maximum age of one year. | |
* | |
* Usage: | |
* add_filter( 'posts_where', 'wp_query_filter_max_one_year_old' ); | |
* $my_query = new WP_Query( array( ... ) ); | |
* remove_filter( 'posts_where', 'wp_query_filter_max_one_year_old' ); | |
* | |
* @param string $where |
This file contains 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 | |
$age_filter = function ( $where = '' ) use ( $options ) { | |
$where .= " AND post_date > '" . date( 'Y-m-d', strtotime( '-' . $options[ 'max_post_age' ] ) ) . "'"; | |
return $where; | |
}; | |
add_filter( 'posts_where', $age_filter ); | |
$query = new WP_Query( $args ); | |
remove_filter( 'posts_where', $age_filter ); |
This file contains 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 | |
/** | |
* Return posts with maximum age of one year. | |
* | |
* Usage: | |
* add_filter( 'posts_where', 'wp_query_filter_max_one_year_old' ); | |
* $my_query = new WP_Query( array( ... ) ); | |
* remove_filter( 'posts_where', 'wp_query_filter_max_one_year_old' ); | |
* | |
* @param string $where |
This file contains 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 | |
/** | |
* My Plugin | |
* | |
* @uses add_filter() for 'the_content': make love not content | |
* @uses add_filter() for 'get_the_excerpt': clearly announce all excerpts | |
*/ | |
class my_plugin | |
{ | |
function __construct() { |
This file contains 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 | |
register_activation_hook( __FILE__, 'add_last_activity_for_all_users' ); | |
function add_last_activity_for_all_users() { | |
global $wpdb; | |
$sql = $wpdb->prepare( " | |
SELECT | |
u.ID | |
FROM | |
$wpdb->users AS u |
This file contains 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 | |
/** | |
* Return array containing all capabilities that user has access to. | |
* If he is an admin, the list will contain all available capability IDs. | |
* | |
* @param $user_id integer | |
* @return array | |
*/ | |
function dtpr_get_all_user_capabilities( $user_id ) { | |
global $wpdb; |
This file contains 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
jQuery(function($) { | |
// configure | |
var comment_input = $( '#commentform textarea' ); | |
var submit_button = $( '#commentform .form-submit' ); | |
var comment_limit_chars = 1000; | |
// stop editing here | |
// display how many characters are left | |
$( '<div class="comment_limit_info"><span>' + comment_limit_chars + '</span> characters left</div>' ).insertAfter( comment_input ); | |
This file contains 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 | |
// Alternative 1 | |
function my_postbox_fun() { | |
# code... | |
} | |
postbox( 'My Awesome Postbox', 'my_postbox_fun' ); | |
// Alternative 2 | |
class my_example_class | |
{ |
This file contains 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
ericteubert: ~/Sites/wordpress-single | |
➜ ack widget_text | |
wp-admin/includes/schema.php | |
307: 'widget_text' => array(), | |
wp-content/plugins/ikonum/class/class.custom-field-template.php | |
101: add_filter('widget_text', 'do_shortcode'); | |
wp-includes/default-widgets.php | |
371: $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML')); |
This file contains 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 | |
class content_parser { | |
public function __construct() { | |
// apply parser to all posts | |
add_filter( 'the_content', array( __CLASS__, 'parse' ) ); | |
} | |
public static function parse( $text ) { | |
global $post; |