您可以通过测试以下各项来检查用户是否将其保留为默认设置,即未选择永久链接方案get_option( \'permalink_structure\' )
为空。
我认为仅仅为他们更改用户的选项是不礼貌的,尤其是因为他们需要更新自己的。htaccess或同等产品才真正起作用。下面是一个快速示例,可以将主题的管理函数放入标题中以发出警告:
if ( \'\' == get_option( \'permalink_structure\' ) ) {
function wpse157069_permalink_warning() {
echo \'<div id="permalink_warning" class="error">\';
echo \'<p>We strongly recommend adding a <a href="\' . esc_url( admin_url( \'options-permalink.php\' ) ) . \'">permalink structure</a> to your site when using WPSE AwesomeTheme.</p>\';
echo \'</div>\';
}
add_action( \'admin_footer\', \'wpse157069_permalink_warning\' );
}
形成更完整的溶液(也
as a gist) 具有本地化功能,仅在适当时显示:
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\' );
}
}