Skip to content

Instantly share code, notes, and snippets.

View spacedmonkey's full-sized avatar
🖐️
Open for work

Jonny Harris spacedmonkey

🖐️
Open for work
View GitHub Profile
@spacedmonkey
spacedmonkey / s3.php
Last active November 6, 2024 15:19
Using Digital Ocean spaces with S3 Uploads plugin
add_filter( 's3_uploads_s3_client_params', function ( $params ) {
if ( defined( 'S3_UPLOADS_ENDPOINT' ) ) {
$params['endpoint'] = S3_UPLOADS_ENDPOINT;
}
return $params;
}, 5, 1 );
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 / gist:6d0b395df4664040df9095fdd54a1562
Last active July 11, 2018 17:10
Change the admin theme depending on enviroments in WordPress
<?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':
@spacedmonkey
spacedmonkey / Functions
Last active May 3, 2019 18:05
Starts of a feature plugin for global user roles.
Create table
Remove Table
Activate
Uninstall
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 ) ) {
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
@spacedmonkey
spacedmonkey / test.php
Created May 23, 2019 14:18
Add gutenberg blocks to WordPress API as json.
<?php
add_action( 'rest_api_init', function () {
$types = get_post_types(
[
'show_in_rest' => true,
],
'names'
);
@spacedmonkey
spacedmonkey / gist:d9a3c066c63dff41470a2dedd2d8734d
Created October 18, 2019 22:43
Get all posts for all post types in javascript.
wp.apiFetch( { path: '/wp/v2/types' } ).then( ( post_types ) => {
for ( let post_type in post_types ){
let {rest_base} = post_types[post_type];
wp.apiFetch( { path: '/wp/v2/' + rest_base } ).then( ( posts ) => {
console.log(posts);
});
}
} );
public function get_item_permissions_check( $request ) {
$post = $this->get_post( $request['id'] );
if ( is_wp_error( $post ) ) {
return $post;
}
if ( $post && ! $this->check_update_permission( $post ) ) {
return false;
}
return parent::get_item_permissions_check( $request );
@spacedmonkey
spacedmonkey / Function.txt
Last active February 17, 2020 11:58
WordPress core private Functions and Classes.
Functions
startElement
endElement
_wp_menu_output
_add_themes_utility_last
_wp_ajax_delete_comment_response
_wp_ajax_add_hierarchical_term
wp_link_manager_disabled_message
_wp_credits_add_profile_link