Skip to content

Instantly share code, notes, and snippets.

@wpsmith
wpsmith / display-posts-deactivate.php
Last active August 29, 2015 13:56
PHP: Extends Display Posts Shortcode to add a 'not_in' attribute for 'post__not_in' in WP_Query.
<?php
add_action( 'update_option_active_sitewide_plugins', 'dpse_deactivate_self', 10, 2 );
add_action( 'update_option_active_plugins', 'dpse_deactivate_self', 10, 2 );
/**
* Deactivate ourself if Addthis is deactivated.
*/
function dpse_deactivate_self( $plugin, $network_deactivating ) {
if ( !is_plugin_active( 'addthis/addthis_social_widget.php' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ), true );
@wpsmith
wpsmith / httpd-new.conf
Created March 3, 2014 04:32
CONF: Default Port for Apache
Listen 0.0.0.0:8080
#Listen [::]:80
#Listen 80
@wpsmith
wpsmith / php-file-uploads.ini
Last active August 29, 2015 13:56
INI: php.ini Resource Limits
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;
; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads=On
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
<?php
// Change /*CUSTOMIZE_THIS*/ to a unique name (two places). Go ahead, make it long.
// Like, your initials, and your full plugin name.
// e.g. MTJ_Some_Awesome_Plugin_Controller
/*CUSTOMIZE_THIS*/_Controller::init();
class /*CUSTOMIZE_THIS*/_Controller {
function init() {
@wpsmith
wpsmith / us-phone-format.php
Created March 16, 2014 19:09
PHP: Format US Phone Number to always be the same.
<?php
$formatted_phone = preg_replace( '~.*(\d{3})[^\d]*(\d{3})[^\d]*(\d{4}).*~', '($1) $2-$3', $unformatted_number );
$formatted_phone = preg_replace( '~.*(\d{3})[^\d]*(\d{3})[^\d]*(\d{4}).*~', '$1.$2.$3', $unformatted_number );
$formatted_phone = preg_replace( '~.*(\d{3})[^\d]*(\d{3})[^\d]*(\d{4}).*~', '$1-$2-$3', $unformatted_number );
@wpsmith
wpsmith / remove-soliloquy-metabox-post-types.php
Created April 7, 2014 18:02
PHP: Remove Soliloquy Metaboxes
<?php
add_filter( 'soliloquy_skipped_posttypes', 'myprefix_soliloquy_skipped_posttypes' );
/**
* Remove Soliloquy Metabox from posts, etc..
* @param array $post_types Array of skipped post types.
* @return array $post_types Modified array of skipped post types.
*/
function myprefix_soliloquy_skipped_posttypes( $post_types ) {
$post_types['post'];
@wpsmith
wpsmith / gist:10028234
Last active August 29, 2015 13:58
HTML: HTML for Soliloquy HTML Slides to Appear in Thumbnails
HTML Slide Code:
`<a rel="soliloquybox{SOLILOQUYID}" href="http://domain.com/path/to/full-image.jpg" data-thumbnail="http://domain.com/path/to/thumbnail-image.jpg"><img src="http://domain.com/path/to/full-image.jpg" alt="HTML Slide"/></a>`
@wpsmith
wpsmith / update-thumbnails.php
Created April 7, 2014 21:02
PHP: Update Thumbnails default number to 5.
<?php
// Load the WordPress Environment
define( 'WP_DEBUG', true ); /* uncomment for debug mode */
require('./wp-load.php');
foreach( get_posts( array( 'post_type' => 'soliloquy', ) ) as $post ) {
$data = get_post_meta( $post->ID, '_sol_slider_data', true );
$data['config']['thumbnails_num'] = 5;
update_post_meta( $post->ID, '_sol_slider_data', $data );
@wpsmith
wpsmith / p2p-install.php
Created April 9, 2014 19:43
PHP: How to Allow Posts to Posts to Install on New Blog/Site Creation with Users being Editors
<?php
add_action( 'wpmu_new_blog', 'ap_install_p2p', 5, 6 );
/**
* Create P2P table on site creation regardless of admin presence.
*
* @see P2P_Tools_Page::maybe_install()
*
* @author Ryan Imel <ryan@wpcandy.com>
* @author Travis Smith <t@wpsmith.com>
@wpsmith
wpsmith / p2p-install.php
Created April 9, 2014 19:46
PHP: How to Allow Posts to Posts to Install on New Blog/Site Creation with Users being Editors
<?php
add_action( 'wpmu_new_blog', 'wps_install_p2p', 5, 6 );
/**
* Create P2P table on site creation regardless of admin presence.
*
* @see P2P_Tools_Page::maybe_install()
* @author Travis Smith <wpsmith.net>
*
* @param int $blog_id Blog ID.