Instantly share code, notes, and snippets.

🤖
building things

Chuck Reynolds chuckreynolds

View GitHub Profile
View wordpress-get-child-page-ids.php
<?php
// basic idea here is a common function to pass a parent page ID
// and get back an array of it and its child page IDs only
function getChildPageIDs( $id ) {
$child_pages = get_pages('child_of='.$id);
$ids_to_remove = array($id); // we want to remove parent id too
foreach($child_pages as $child) {
array_push($ids_to_remove,$child->ID); // for every child add the id into array
}
View remove-jquery-migrate-wordpress.php
<?php
/**
* Remove jQuery Migrate script
*/
function ryno_remove_jquery_migrate( $scripts ) {
if ( isset( $scripts->registered['jquery'] ) ) {
$script = $scripts->registered['jquery'];
if ( $script->deps ) { // Check whether the script has any dependencies
$script->deps = array_diff( $script->deps, array( 'jquery-migrate' ) );
View fetch-dadjoke-api.php
<?php
$url = 'https://icanhazdadjoke.com/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept:text/plain']);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
View json-discord-embeds-twitch.json
{
"username":"twitch.tv/{{ChannelName}} [via RynoBot]",
"content":"@everyone {{ChannelName}} just went LIVE on Twitch! See you in chat! clintusHYPE",
"embeds":[
{
"title":"{{ChannelUrl}}",
"url":"{{ChannelUrl}}",
"color":6570404,
"thumbnail":{
"url":"https://static-cdn.jtvnw.net/jtv_user_pictures/b26daa03-975b-4a5d-9dea-a7fe9505a63f-profile_image-300x300.png"
View shopify-products-json-async-await.html
<html>
<head>
<style>
.wrapper {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 220px));
grid-gap: 20px;
}
.box {
background-color: #ebebeb;
View affiliate-links.md
View gist:3509561dda65df35075f87fb7adc629e
Verifying that "chuckreynolds.id" is my Blockstack ID. https://onename.com/chuckreynolds
View sample-wordpress-options-cache.php
<?php
function get_twitter_followers() {
$ttl = 2 * HOUR_IN_SECONDS;
$cache = get_option( 'my_twitter_followers' );
if ( empty( $cache['timeout'] ) || $cache['timeout'] < time() ) {
$followers = wp_remote_get( ... );
$cache = array(
'count' => $followers,
View ngrok-to-local-vagrant.sh
./ngrok http -host-header=rewrite localsitename.app:80
View gist:c28d0957300b6b540dc295190ddfc1cb
// Disable users REST API endpoints
add_action( 'rest_endpoints', function( $endpoints) {
foreach ( $endpoints as $endpoint => $args ){
if( false !== strpos( '/wp/v2/users', $endpoint ) ){
unset( $endpoints[ $endpoint ] );
}
}
return $endpoints;
});