This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); |
Questions, comments, or suggestion for improvement? Leave a comment on the GitHub Gist page.