Skip to content

Instantly share code, notes, and snippets.

@mindctrl
mindctrl / enqueue-react-devtools-script.php
Last active May 23, 2022 14:28
Using React Dev Tools (react-devtools) with WordPress and Safari
<?php
// This loads the react-devtools script in wp-admin when using Safari.
add_action( 'admin_enqueue_scripts', function() {
if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'Safari' ) !== false ) {
?>
<script src="http://localhost:8097"></script>
<?php
}
} );
@mindctrl
mindctrl / setup-phpunit.sh
Created January 29, 2019 15:48 — forked from keesiemeijer/setup-phpunit.sh
Setup PHPUnit for use in the Local by Flywheel app
#!/usr/bin/env bash
# ===============================================================================
# Script to install PHPUnit in the Local by Flywheel Mac app
# These packages are installed
#
# PHPUnit, git, subversion, composer, curl and wget
#
# The $WP_CORE_DIR and $WP_TESTS_DIR environment variables are added to the ~/.bashrc file
#
function simple_plugin_updater( $update_plugins, $transient_name ) {
$plugin = json_decode(
json_encode(
array(
'new_version' => 89,
'stable_version' => 89,
'name' => 'My Fake Plugin',
'slug' => 'my-fake-plugin.php',
'url' => 'https://myfakeplugin.com',
@mindctrl
mindctrl / commercial-client.php
Created November 7, 2018 00:09 — forked from pento/commercial-client.php
Sample Commercial Plugin update server and client
<?php
/*
* Plugin Name: Commercial Client
* Plugin URI: http://pento.net/
* Description: A sample client plugin for showing updates for non-WordPress.org plugins
* Author: pento
* Version: 0.1
* Author URI: http://pento.net/
* License: GPL2+
*/
<?php
/**
* Iterates over results of a query, split into many queries via LIMIT and OFFSET
*/
class QueryIterator implements Iterator {
var $limit = 500;
var $query = '';
var $global_index = 0;
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>Subscriptions - freek@spatie.be</title>
</head>
<body>
<outline text="PHP" title="PHP">
<outline htmlUrl="http://mattallan.org" title="mattallan.org" xmlUrl="http://mattallan.org/feed.xml" type="rss" text="mattallan.org"/>
<outline title="asked.io" xmlUrl="https://asked.io/rss" type="rss" text="asked.io"/>
<outline htmlUrl="https://ocramius.github.io/" title="ocramius.github.io" xmlUrl="https://ocramius.github.io/atom.xml" type="rss" text="ocramius.github.io"/>
@mindctrl
mindctrl / rcp-custom-post-restriction-messages.php
Created October 1, 2016 03:00
Custom post / page restriction messages in Restrict Content Pro
/**
* This plugin adds support for custom restriction messages per post.
* If a custom message exists, it is used in place of the ones defined
* in the RCP settings under Restrict > Settings > General.
*/
/**
* Displays the custom message metabox on the post edit screen.
*/
function jp_rcp_post_level_restriction_message_metabox() {
@mindctrl
mindctrl / plugin.php
Created September 10, 2016 17:21 — forked from logoscreative/plugin.php
Friendlier, Safer WordPress Admin Areas
<?php
/**
* "Friendlier, Safer WordPress Admin Areas"
* Presented by Cliff Seal at WordCamp Atlanta 2015 and Asheville 2016
* Slides: http://www.slideshare.net/cliffseal/wp-admin
*
* Plugin Name: A Better Admin Experience
* Plugin URI: http://evermoresites.com
* Description: Cleans up and sanitizes the WordPress admin area
* Version: 1.0
@mindctrl
mindctrl / wp_human_time_diff.php
Created May 7, 2016 13:53 — forked from BinaryMoon/wp_human_time_diff.php
Human Time Difference Function for WordPress
<?php
/**
* Display the post time in a human readable format
*
* @return string
*/
function carmack_human_time_diff() {
$post_time = get_the_time( 'U' );
$time_now = date( 'U' );
@mindctrl
mindctrl / gist:c7d27f504ed0eb281dc5
Created January 14, 2016 04:35 — forked from ericandrewlewis/gist:95239573dc97c0e86714
Setting up a WordPress site on AWS

Setting up a WordPress site on AWS

This tutorial walks through setting up AWS infrastructure for WordPress, starting at creating an AWS account. We'll manually provision a single EC2 instance (i.e an AWS virtual machine) to run WordPress using Nginx, PHP-FPM, and MySQL.

This tutorial assumes you're relatively comfortable on the command line and editing system configuration files. It is intended for folks who want a high-level of control and understanding of their infrastructure. It will take about half an hour if you don't Google away at some point.

If you experience any difficulties or have any feedback, leave a comment. 🐬

Coming soon: I'll write another tutorial on a high availability setup for WordPress on AWS, including load-balancing multiple application servers in an auto-scaling group and utilizing RDS.