Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonny Harris spacedmonkey

View GitHub Profile
View gist:d8d0a822d05d716fcfd1656caa909c97
$post_type_taxonomies = array();
$term_ids = array();
$prime_post_terms = array();
foreach ( $posts as $post ) {
if ( ! ( $post instanceof WP_Post ) ) {
continue;
}
if ( ! isset( $post_type_taxonomies[ $post->post_type ] ) ) {
$post_type_taxonomies[ $post->post_type ] = get_object_taxonomies( $post->post_type );
@spacedmonkey
spacedmonkey / hasVideoGotAudio.js
Created Aug 15, 2021
Detect if video has audio, using javascript
View hasVideoGotAudio.js
function hasAudio(video) {
return (
video.mozHasAudio ||
Boolean(video.webkitAudioDecodedByteCount) ||
Boolean(video.audioTracks?.length)
);
}
function hasVideoGotAudio(src) {
const video = document.createElement('video');
video.muted = true;
View gist:5d080de3711c6964f2d9c92108102523
add_filter( 'get_image_tag', function( $html, $id, $alt, $title, $align, $size ){
$original_url = $this->get_original_url( $id );
if ( ! $original_url ) {
return $html;
}
list( $img_src, $width, $height ) = image_downsize( $id, $size );
$hwstring = image_hwstring( $width, $height );
$html = '<img src="' . $img_src . '" alt="' . esc_attr( $alt ) . '" ' . $title . $hwstring . 'class="' . $class . '" />';
@spacedmonkey
spacedmonkey / Function.txt
Last active Feb 17, 2020
WordPress core private Functions and Classes.
View Function.txt
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
View gist:37c77d59692d6dcb9ef61463fa59cd95
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 / gist:d9a3c066c63dff41470a2dedd2d8734d
Created Oct 18, 2019
Get all posts for all post types in javascript.
View gist:d9a3c066c63dff41470a2dedd2d8734d
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);
});
}
} );
@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