Skip to content

Instantly share code, notes, and snippets.

View adamsilverstein's full-sized avatar
💭
Working remotely, as usual

Adam Silverstein adamsilverstein

💭
Working remotely, as usual
View GitHub Profile
@adamsilverstein
adamsilverstein / deprecated_warning_disabler.php
Last active December 10, 2015 15:31
Disabled deprecated warnings in WordPress.
<?php
add_filter( 'deprecated_constructor_trigger_error', '__return_false' );
add_filter( 'deprecated_function_trigger_error', '__return_false' );
add_filter( 'deprecated_file_trigger_error', '__return_false' );
@adamsilverstein
adamsilverstein / gocat.js
Last active January 6, 2016 05:33
Create a post with categories
// Create a new post
var post = new wp.api.models.Posts({ title:'new test' } );
post.save();
// Get a collection of the post's categories
var postCategories = post.getCategories();
// The new post has an single Category: Uncategorized
postCategories.at( 0 ).get('name');
// response -> "Uncategorized"
jQuery( document ).on( 'click', 'div.attachment-preview', function( e ) {
console.log( 'Image clicked', e );
// Do ajax stuff here...
} );
var callbackFunction = function( e ) {
console.log( 'Image clicked', e );
// Do ajax stuff here...
};
wp.media.view.Attachment.prototype.on( 'click', callbackFunction );
$host = parse_url( strtolower( site_url() ) , PHP_URL_HOST );
if ( strpos( $host, 'domain.com' ) ) {
$site_matches = true;
}
<?php
function use_floor_for_human_time_diff( $since, $diff, $from, $to ) {
if ( empty( $to ) ) {
$to = time();
}
$diff = (int) abs( $to - $from );
if ( $diff < HOUR_IN_SECONDS ) {
$mins = floor( $diff / MINUTE_IN_SECONDS );
In some environments it’s necessary to hop through 1 or even 2
gateways to reach the hosts.
In order to make this a little easier and also allow easy scp file
transfers here is a little guide for setting up ssh access.
Add the following to your ~/.ssh/config file
Host *
TCPKeepAlive yes
For reference, here's how I'm doing it now:
```
add_filter( 'oembed_request_post_id', function( $post_id, $url ) {
if( is_my_gallery_page() ) {
add_filter( 'post_embed_url', function( $embed_url ) use ($url) {
remove_filter( current_filter(), __FUNCTION__ );
$url = explode("?",$url);
$embed_url = $embed_url."?".$url[1];
return $embed_url;
/**
* A filter dropdown for month/dates.
*/
wp.media.view.CategoryFilter = wp.media.view.AttachmentFilters.extend({
id: 'media-attachment-date-filters',
createFilters: function() {
var filters = {};
var categories = ['one', 'two', 'three'];
_.each( categories || {}, function( value, index ) {
filters[ index ] = {
// Show 10 posts in the quick draft list.
wp.hooks.addFilter(
'dashboard_recent_drafts_fetch_args',
function( $args ) {
$args['per_page'] = 10;
return $args;
}
);