Skip to content

Instantly share code, notes, and snippets.

@mgmartel
mgmartel / add-image-editor-size.php
Created January 20, 2014 19:09
In WordPress, when you edit images using the Image Editor, only core sizes are saved, and not any of your custom sizes (including post-thumbnail!). If you register image sizes using the functions in this Gist, images edited in the Image Editor will be saved in all image sizes.
<?php
/**
* If you register image sizes using the function below, images
* edited in the Image Editor will be saved in all image sizes.
*
* @see https://core.trac.wordpress.org/ticket/19889
*/
if ( !function_exists( 'add_image_editor_size') ) :
@mgmartel
mgmartel / TimberRedux.php
Last active December 30, 2015 17:49
Use Redux Framework with Timber (and, optionally, WPML).
<?php
/**
* Use Redux Framework with Timber
*
* Use this class like you would Redux Framework. All options are automatically
* made available in your Timber template context (by default as 'options').
*
* Extra optional arguments in the $args array:
* - 'timber_context' (string) Name of the variable in template context.
@mgmartel
mgmartel / duplicate-p2p.php
Created December 7, 2013 16:27
Duplicate WP-Posts-to-Posts (https://github.com/scribu/wp-posts-to-posts/) connections when duplicating a post using Duplicate Post (http://wordpress.org/plugins/duplicate-post/) or the WooCommerce product duplicator.
<?php
add_action( 'dp_duplicate_page', 'dp_duplicate_p2p', 10, 2 );
add_action( 'dp_duplicate_post', 'dp_duplicate_p2p', 10, 2 );
// For Duplicate Product support in WooCommerce:
//add_action( 'woocommerce_duplicate_product', 'dp_duplicate_p2p', 10, 2 );
function dp_duplicate_p2p( $new_post_id, $old_post ) {
global $wpdb;
@mgmartel
mgmartel / bp-message-attachment-secure.php
Created February 14, 2013 20:17
Secures attachments for messages in BuddyPress when using the BuddyPress Message Attachment plugin, by only service the file to users that are part of the thread the file is attached to.
<?php
/**
* This gist secures attachments for messages in BuddyPress when
* using the BuddyPress Message Attachment plugin, by only serving
* the file to users that are part of the thread the file is attached
* to.
*
* =Usage=
* Add the functions in this file to your theme's functions.php or
* wherever you want it. Then add the following rewrite rule to your
@mgmartel
mgmartel / bp-sort-members-by-last-name.php
Last active December 11, 2023 03:23
Sort BuddyPress users by last name in the members directory. Updated for BP 1.7.
<?php
// Sort BuddyPress users by last name
//
// Use this Gist to sort members alphabetically by last name in the
// members directory. Follow the instructions below and drop the code
// in your functions.php or your functions plugin.
//
// Updated to work with BP 1.7. See earlier revisions of this gist for
// earlier versions of BP.
@mgmartel
mgmartel / wp-tiles-menu.php
Last active December 10, 2015 15:28
Use WP Tiles as a site menu, by automatically adding pages on fixed locations in your website. Drop in your functions.php or functions plugin. It only shows pages with the meta value 'tile-position', which is their fixed position in the tiles.
<?php
add_filter( 'wp-tiles-data', 'fixed_page_tiles', 10, 4 );
function fixed_page_tiles( $data, $posts, $colors, $tiles_obj ) {
$pages = get_pages();
foreach ( $pages as $page ) {
$position = get_post_meta( $page->ID, 'tile-position', true );
if ( empty ( $position ) || ! is_numeric ( $position ) )
continue;