Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Created October 27, 2013 16:31
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredatch/7184603 to your computer and use it in GitHub Desktop.
Save jaredatch/7184603 to your computer and use it in GitHub Desktop.
A few tricks to use for your local installs
<?php
/*------------------------------------------------------------------------------
The functions below are executed if the install is declared to be a
development environment.
The following constants should be set in the install's wp-config.php:
SITE_DEV - [true/false]
SITE_PROD_URL - primary root URL of the production site
------------------------------------------------------------------------------*/
/**
* Filter post/page content via the_content
*
* The links inside the content point to the production site. The filter
* below replaces those links with the URL to the production site to make
* testing easier. Only the_content is filtered, production URLs inside
* menus, widgets, etc will remain unchanged.
*
* SITE_DEV and SITE_PROD_URL need to be defined in the wp-config.php.
*
* @since 1.0.0
* @param string $content
* @return string
*/
function ja_dev_site_url_filter( $content ) {
if ( defined( 'SITE_DEV' ) && defined( 'SITE_PROD_URL' ) && SITE_DEV == true )
$content = str_replace( SITE_PROD_URL, get_bloginfo( 'url' ), $content );
return $content;
}
add_filter( 'the_content', 'ja_dev_site_url_filter' );
/**
* Display a notice on the development site and include a link to production
*
* @since 1.0.0
*/
function ja_dev_site_notice() {
if ( defined( 'SITE_DEV' ) && SITE_DEV == true ) {
echo '<div id="development-site-notice">';
echo get_bloginfo( 'name' ) . ' development site';
if ( defined( 'SITE_PROD_URL' ) ) {
$url = str_replace( get_bloginfo( 'url' ), SITE_PROD_URL, get_permalink() );
echo ' - <a href="' . $url . '">view this page</a> on production';
}
echo '</div>';
}
}
add_action( 'wp_footer', 'ja_dev_site_notice' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment