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
import {
doAction,
applyFilters,
addAction,
addFilter,
doingAction,
doingFilter,
didAction,
didFilter,
hasAction,
wp.api.init({
'versionString': '/custom/v1/'
}
).done( function( mySchema ) {
// mySchema contains your namespace models/collections
...
} );
@adamsilverstein
adamsilverstein / blocksinpost.json
Last active September 8, 2017 17:57
Blocks in post
// 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"
@adamsilverstein
adamsilverstein / demo-post.json
Created January 2, 2018 19:26
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"
},
@adamsilverstein
adamsilverstein / workaround.php
Created February 2, 2018 16:00
Meta Revision timing workaround
// 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 );
@adamsilverstein
adamsilverstein / gist:4bfc76454656046b24f18b292da895f7
Created November 21, 2018 21:23
shorten wordpress heartbeat
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 / nonce.php
Created November 21, 2018 21:28
shorten nonce lifetimes
add_filter( 'nonce_life', function () { return 25; } );
for i in {1..100}
do
wp site create --slug=site-$i
done
╰─$ ./vendor/bin/phpcs src/*.php src/**/*.php --standard=WordPress --sniffs=WordPress.WP.I18n --report=summary
PHP CODE SNIFFER REPORT SUMMARY
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FILE ERRORS WARNINGS
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
develop.wordpress/src/wp-login.php 1 0
develop.wordpress/src/wp-admin/admin-footer.php 1 0
develop.wordpress/src/wp-admin/admin.php 1 0
develop.wordpress/src/wp-admi
╰─$ ./vendor/bin/phpcs src/*.php src/**/*.php --standard=WordPress --sniffs=WordPress.WP.I18n
FILE: develop.wordpress/src/wp-login.php
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
434 | ERROR | A gettext call containing placeholders was found, but was not accompanied by a "translators:" comment on the line above to clarify the meaning of the placeholders.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------