Skip to content

Instantly share code, notes, and snippets.

View jimboobrien's full-sized avatar

Jimobrien jimboobrien

View GitHub Profile
@jimboobrien
jimboobrien / custom-page-templates.php
Created September 20, 2017 23:15 — forked from wpscholar/custom-page-templates.php
Load custom page templates from within a plugin
<?php
/**
* Class Custom_Page_Templates
*/
class Custom_Page_Templates {
/**
* Storage for all custom template paths
*
@jimboobrien
jimboobrien / create-admin-user.php
Created September 20, 2017 22:44 — forked from wpscholar/create-admin-user.php
Create a new admin user in WordPress via code. Drop this file in the mu-plugins directory and update the variables, then load a page in WordPress to create the user. Remove the file when done.
<?php
add_action( 'init', function () {
$username = 'admin';
$password = 'password';
$email_address = '[email protected]';
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );
@jimboobrien
jimboobrien / remote-media-loader.php
Created September 20, 2017 22:44 — forked from wpscholar/remote-media-loader.php
Load media from a remote site so you don't have to download the uploads directory.
<?php
/**
* Loads media from a remote site when on a local dev environment.
* Eliminates the need to download the uploads directory from the remote site for testing purposes.
*/
if ( 'mydomain.dev' === $_SERVER['HTTP_HOST'] ):
add_filter( 'upload_dir', function ( $uploads ) {
$uploads['baseurl'] = 'http://mydomain.com/wp-content/uploads';
@jimboobrien
jimboobrien / cookies.js
Created September 20, 2017 22:42 — forked from wpscholar/cookies.js
Functions for setting, getting and deleting cookies via JavaScript
/**
* Set a cookie
*
* @param {string} cookieName
* @param {string} cookieValue
* @param {object} cookieOptions (expires, domain, path)
*/
function setCookie(cookieName, cookieValue, cookieOptions) {
cookieOptions = cookieOptions || {};
if (cookieValue) {
<?php
/**
* Ensure that a specific plugin is never updated. This works by removing the
* plugin from the list of available updates.
*/
add_filter( 'http_request_args', function ( $response, $url ) {
if ( 0 === strpos( $url, 'https://api.wordpress.org/plugins/update-check' ) ) {
$basename = plugin_basename( __FILE__ );
<?php
/**
* Ensure that a specific theme is never updated. This works by removing the
* theme from the list of available updates.
*/
add_filter( 'http_request_args', function ( $response, $url ) {
if ( 0 === strpos( $url, 'https://api.wordpress.org/themes/update-check' ) ) {
$themes = json_decode( $response['body']['themes'] );
<?php
/**
* Drop this code into your main plugin file to hide plugin deactivation from the WordPress admin.
*/
add_filter( 'plugin_action_links', function ( $actions, $plugin_file ) {
if ( plugin_basename( __FILE__ ) === $plugin_file ) {
unset( $actions['deactivate'] );
}
@jimboobrien
jimboobrien / array-insert-after.php
Created September 20, 2017 22:41 — forked from wpscholar/array-insert-after.php
Insert a value or key/value pair after a specific key in an array. If key doesn't exist, value is appended to the end of the array.
<?php
/**
* Insert a value or key/value pair after a specific key in an array. If key doesn't exist, value is appended
* to the end of the array.
*
* @param array $array
* @param string $key
* @param array $new
*
@jimboobrien
jimboobrien / array-insert-before.php
Created September 20, 2017 22:41 — forked from wpscholar/array-insert-before.php
Insert a value or key/value pair before a specific key in an array. If key doesn't exist, value is prepended to the beginning of the array.
<?php
/**
* Insert a value or key/value pair before a specific key in an array. If key doesn't exist, value is prepended
* to the beginning of the array.
*
* @param array $array
* @param string $key
* @param array $new
*