Skip to content

Instantly share code, notes, and snippets.

Adam Silverstein adamsilverstein

View GitHub Profile
View create-multiple-sites.sh
for i in {1..100}
do
wp site create --slug=site-$i
done
@adamsilverstein
adamsilverstein / nonce.php
Created Nov 21, 2018
shorten nonce lifetimes
View nonce.php
add_filter( 'nonce_life', function () { return 25; } );
View gist:4bfc76454656046b24f18b292da895f7
function wp_heartbeat_settings_3242( $settings ) {
$settings['interval'] = 15; //Anything between 15-120
return $settings;
}
add_filter( 'heartbeat_settings', 'wp_heartbeat_settings_3242' );
@adamsilverstein
adamsilverstein / workaround.php
Created Feb 2, 2018
Meta Revision timing workaround
View workaround.php
// do not save revision on post_updated since the meta fields are not saved yet.
remove_action( 'post_updated', 'wp_save_post_revision', 10 );
// readd wp_save_post_revision on save_post if needed.
add_action( 'post_updated', 'save_post_revision_on_save_post', 10 );
function save_post_revision_on_save_post() {
$mycustomfieldsplugin_save_post_priority = 10;
// wp_save_post_revision has to be executed after the plugin saves its meta fields (higher priority on save_post hook).
add_action( 'save_post', 'wp_save_post_revision', $mycustomfieldsplugin_save_post_priority + 1, 1 );
View demo-post.json
// 20180102142527
// http://developwordpress.localhost/wp-json/wp/v2/posts/336
{
"id": 336,
"date": "2018-01-02T14:24:26",
"date_gmt": "2018-01-02T19:24:26",
"guid": {
"rendered": "http://developwordpress.localhost/?p=336"
},
View blocksinpost.json
// 20170908135703
// http://developwordpress.localhost/wp-json/wp/v2/posts/40018
{
"content": {
"id": 40018,
"date": "2017-09-04T19:21:42",
"date_gmt": "2017-09-04T19:21:42",
"guid": {
"rendered": "http://developwordpress.localhost/?p=40018"
View wp-api-init-w-namespace.js
wp.api.init({
'versionString': '/custom/v1/'
}
).done( function( mySchema ) {
// mySchema contains your namespace models/collections
...
} );
View hooks.js
import {
doAction,
applyFilters,
addAction,
addFilter,
doingAction,
doingFilter,
didAction,
didFilter,
hasAction,
View demo-hook-1.js
// Show 10 posts in the quick draft list.
wp.hooks.addFilter(
'dashboard_recent_drafts_fetch_args',
function( $args ) {
$args['per_page'] = 10;
return $args;
}
);
View add-filter-to-media-grid.js
/**
* 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 ] = {
You can’t perform that action at this time.