Skip to content

Instantly share code, notes, and snippets.

🇬🇧
Looking for new contracts / freelance from August 1st

Jonny Harris spacedmonkey

🇬🇧
Looking for new contracts / freelance from August 1st
Block or report user

Report or block spacedmonkey

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@spacedmonkey
spacedmonkey / test.php
Created May 23, 2019
Add gutenberg blocks to WordPress API as json.
View test.php
<?php
add_action( 'rest_api_init', function () {
$types = get_post_types(
[
'show_in_rest' => true,
],
'names'
);
View gist:89dc01a3e043a9e39aff9a27ded6bac1
Changes to 5.1
Multisite
https://core.trac.wordpress.org/ticket/37923
https://core.trac.wordpress.org/ticket/40364
https://core.trac.wordpress.org/ticket/44368
https://core.trac.wordpress.org/ticket/41333
https://core.trac.wordpress.org/ticket/40647
View gist:817c7b7fcdc483913a39f02218a96f9d
function get_site_id_of_user( $user_id, $all = false ) {
global $wpdb;
$user_id = (int) $user_id;
// Logged out users can't have sites
if ( empty( $user_id ) ) {
return array();
}
$keys = get_user_meta( $user_id );
if ( empty( $keys ) ) {
@spacedmonkey
spacedmonkey / Functions
Last active May 3, 2019
Starts of a feature plugin for global user roles.
View Functions
Create table
Remove Table
Activate
Uninstall
@spacedmonkey
spacedmonkey / gist:6d0b395df4664040df9095fdd54a1562
Last active Jul 11, 2018
Change the admin theme depending on enviroments in WordPress
View gist:6d0b395df4664040df9095fdd54a1562
<?php
add_filter( 'get_user_metadata', function ( $value, $object_id, $meta_key, $single ) {
if ( 'admin_color' !== $meta_key || ! $single ) {
return $value;
}
if ( ! defined( 'WPCOM_IS_VIP_ENV' ) ) {
return $value;
}
switch ( WPCOM_IS_VIP_ENV ) {
case 'develop':
View gist:ef0254e9dca9505d257dfe746989bd28
public function migrate1( $args, $assoc_args ) {
global $wpdb;
$user_list = $wpdb->get_col( "SELECT ID FROM $wpdb->users;" );
// Number of users returned by query
$found_users = count( $user_list );
// Generate progess bar
$progress = new \cli\progress\Bar( 'Progress', $found_users );
@spacedmonkey
spacedmonkey / s3.php
Last active Jan 22, 2018
Using Digital Ocean spaces with S3 Uploads plugin
View s3.php
add_filter( 's3_uploads_s3_client_params', function ( $params ) {
if ( defined( 'S3_UPLOADS_ENDPOINT' ) ) {
$params['endpoint'] = S3_UPLOADS_ENDPOINT;
}
return $params;
}, 5, 1 );
@spacedmonkey
spacedmonkey / gist:be74fb8160d5746f43614774db4d877b
Created Dec 24, 2017
Using S3 Uploads with digital ocean spaces
View gist:be74fb8160d5746f43614774db4d877b
add_filter('s3_uploads_s3_client_params', function($params){
$params['endpoint'] = 'https://ams3.digitaloceanspaces.com';
return $params;
}, 10, 1);
View sunrise.php
<?php
/**
* Force cookie constants to be local domain / path
* after multisite is loaded.
*/
add_action(
'ms_loaded', function () {
$site = get_site();
View gist:0edaa7e31e11f957c2fb16bf4d11c97a
$properties = array( 'blogname', 'siteurl', 'post_count', 'home' );
foreach ( $properties as $property ) {
add_action("add_option_".$property,"add_option_site_meta" 99, 2);
add_action("delete_option_".$property,"delete_option_site_meta" 99, 1);
add_action("update_option_".$property,"update_option_site_meta" 99, 3);
}
function delete_option_site_meta( $option ){
delete_site_meta(get_current_blog_id(), $option);
}
You can’t perform that action at this time.