Skip to content

Instantly share code, notes, and snippets.

View wpscholar's full-sized avatar
😀
Happy

Micah Wood wpscholar

😀
Happy
View GitHub Profile
@wpscholar
wpscholar / remote-media-loader.php
Last active April 5, 2022 08:57
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';
<?php
wp_list_comments( apply_filters( 'stellar_comment_args', array(
'style' => 'div',
'type' => 'all',
'avatar_size' => 50,
) ) );
paginate_comments_links();
@wpscholar
wpscholar / create-admin-user.php
Last active January 30, 2025 17:31
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 );
@wpscholar
wpscholar / jenkins.sh
Last active August 29, 2015 14:13
Create a Jenkins box
#!/bin/bash
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | apt-key add - sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
apt-get update -y
apt-get install jenkins -y
service jenkins start
@wpscholar
wpscholar / stellar-places-example.js
Created September 23, 2014 12:39
Example of how to access the Google map and mapBounds variables in Stellar Places
var map = jQuery('.stellar-places-map-canvas').data('map');
var mapBounds = jQuery('.stellar-places-map-canvas').data('mapBounds');
@wpscholar
wpscholar / query-var-alias.php
Created September 11, 2014 14:17
Create an alias for a query var
<?php
/**
* Class Query_Var_Alias
*/
class Query_Var_Alias {
/**
* Query var being aliased
*
@wpscholar
wpscholar / query-arg-alias.php
Created September 11, 2014 14:16
Create an alias for a query argument
<?php
/**
* Class Query_Arg_Alias
*/
class Query_Arg_Alias {
/**
* Query var
*
@wpscholar
wpscholar / sanitize-option.php
Last active August 29, 2015 14:05
Sanitize option example
<?php
add_filter(
"sanitize_option_{$option_name}",
function ( $option_value, $option_name ) {
return filter_var( $option_value, FILTER_VALIDATE_BOOLEAN );
},
10,
2
);
@wpscholar
wpscholar / trust-wordpress.php
Created August 13, 2014 01:54
WordPress functions properly escape, but must be used in the proper context.
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?>
</a>
@wpscholar
wpscholar / verify-nonce.php
Created August 13, 2014 01:43
Verify nonce example
<?php
if ( wp_verify_nonce( $_POST['nonce'], 'update_email' ) && is_email( $_POST['email'] ) ) {
update_post_meta( get_the_ID(), 'email', sanitize_email( $_POST['email'] ) );
}