Skip to content

Instantly share code, notes, and snippets.

View mckernanin's full-sized avatar

Kevin McKernan mckernanin

View GitHub Profile
@mckernanin
mckernanin / nginx.conf
Last active November 17, 2023 09:27
Example nginx config to get WordPress uploads from remote if they don't exist locally
# save space, and grab uploads from the live site
location /wp-content/uploads/ {
if (!-e $request_filename){
rewrite ^/wp-content/uploads/(.*) http://yourlivesite.com/wp-content/uploads/$1 redirect;
}
}
@mckernanin
mckernanin / social.php
Created March 30, 2016 21:24
Social Sharing PHP
<div class="social-sharing-shortcode">
<ul class="social_icons_container">
<li class="social_facebook">
<a href="http://www.facebook.com/sharer.php?u=<?php echo urlencode( get_the_permalink() ); ?>" class="social-sharing" rel="nofollow" data-social_name="facebook" data-post_id="<?php the_id(); ?>">
<i class="social_icon social_icon_facebook"></i>
<div class="social_networkname">Facebook</div>
</a>
</li>
<?php
@mckernanin
mckernanin / social.html
Created March 30, 2016 22:14
Static Social Icons
<div class="social-sharing-shortcode">
<ul class="social_icons_container">
<li class="social_facebook">
<a href="http://www.facebook.com/sharer.php?u=<?php echo urlencode( get_the_permalink() ); ?>" class="social-sharing" rel="nofollow" data-social_name="facebook" data-post_id="<?php the_id(); ?>">
<i class="social_icon social_icon_facebook"></i>
<div class="social_networkname">Facebook</div>
</a>
</li>
<?php
@mckernanin
mckernanin / functions.php
Last active March 8, 2017 19:40
Add new admin via functions.php
<?php
/**
* Function to insert an administrator login into a WordPress site.
* Login and email have to be unique, the function doesn't update existing accounts.
* Function should be placed in functions.php of the active theme.
*/
function insert_admin(){
$login = ''; // username goes here.
$passw = ''; // password goes here, will be hashed on creation.
@mckernanin
mckernanin / functions.php
Last active August 6, 2016 18:45
WordPress Admin AJAX Example
<?php
add_action('wp_ajax_action_name', 'callback_function');
add_action('wp_ajax_nopriv_action_name', 'callback_function');
function callback_function() {
echo 'stuff to return';
die();
}
@mckernanin
mckernanin / functions.php
Created August 6, 2016 18:20
REST API Endpoint Example
<?php
add_action( 'rest_api_init', 'spe_register_api_hooks' );
function spe_register_api_hooks() {
$namespace = 'simple-posts/v1';
register_rest_route( $namespace, '/list-posts/', array(
'methods' => 'GET',
'callback' => 'spe_get_posts',
) );
}
function spe_get_posts() {
@mckernanin
mckernanin / functions.php
Created August 16, 2016 13:51
Quickly replace the text in Divi's footer
<?php
function mck_replace_footer_text( $text ){
if ( 'Designed by %1$s | Powered by %2$s' === $text ) {
$text = '&copy; ' . date('Y') . ' ' . get_bloginfo( 'name' ) . '. All rights reserved.';
}
return $text;
}
add_filter( 'gettext', 'mck_replace_footer_text' );
@mckernanin
mckernanin / gist:c29950a9a977ff6dcfc96875f3ca50d4
Created February 21, 2017 18:23
Remote uploads function
<?php
define( 'LIVE_URL', 'http://yoursite.com')
// add_action('init', 'my_replace_image_urls' );
function my_replace_image_urls() {
$site_url = get_site_url();
if ( false !== strpos( $site_url, '.dev' ) ){
add_filter( 'wp_get_attachment_url', 'replace_dev_url', 10, 2 );
add_filter( 'wp_calculate_image_srcset', 'replace_dev_url_srcset', 10, 2 );
}
}
@mckernanin
mckernanin / keybase.md
Created March 31, 2017 23:44
keybase.md

Keybase proof

I hereby claim:

  • I am mckernanin on github.
  • I am mckernanin (https://keybase.io/mckernanin) on keybase.
  • I have a public key ASAjPR8hCkehQd_Pyfw7zl00aQMLUe5lHeuBj7A_8JqC-Ao

To claim this, I am signing this object:

<?php
/**
* CMB2 Theme Options
* @version 0.1.0
*/
class RTC_Admin {
/**
* Option key, and option page slug
* @var string