Skip to content

Instantly share code, notes, and snippets.

@RupW
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RupW/e85750191cd3c240855b to your computer and use it in GitHub Desktop.
Save RupW/e85750191cd3c240855b to your computer and use it in GitHub Desktop.
WordPress theme snippet to warn if no permalink structure configured
<?php
/**
* "We strongly recommend a permalink structure" admin site notice
*
* from http://wordpress.stackexchange.com/a/157071/3276
*/
if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
/* Admin-site only code */
/**
* If we don't have a permalink structure configured, and if the user has
* permission to configure one, display a warning at the top of the admin
* site. (We can't yet test which screen we're on.)
*/
if ( ( '' == get_option( 'permalink_structure' ) ) &&
current_user_can( 'manage_options' ) ) {
/**
* If we're not already on the permalink configuration page, display a
* warning recommending the administrator configure one.
*/
function wpse_157069_permalink_warning() {
$screen = get_current_screen();
if ( ! isset( $screen ) || ( 'options-permalink' != $screen->id ) ) {
echo '<div id="permalink_warning" class="error">';
echo '<p>' . sprintf(
__( 'We strongly recommend adding a %s to your site when using WPSE AwesomeTheme.' ),
sprintf( '<a href="%s">%s</a>', esc_url( admin_url( 'options-permalink.php' ) ),
__( 'permalink structure' ) ) ) . '</p>';
echo '</div>';
}
}
add_action( 'admin_footer', 'wpse_157069_permalink_warning' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment