Created
August 1, 2012 13:30
-
-
Save bueltge/3226847 to your computer and use it in GitHub Desktop.
Check for right WordPress page template on save_post hook
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 | |
/** | |
* Plugin Name: Template Check | |
* Plugin URI: http://wordpress.stackexchange.com/questions/60451/check-for-page-template-on-save-post-hook/ | |
* Description: | |
* Author: Frank Bültge | |
* Author URI: http://bueltge.de | |
* License: GPLv3 | |
*/ | |
add_action( 'save_post','wpse46583_save', 10, 2 ); | |
function wpse46583_save( $post_id, $post ) { | |
// verify this is not an auto save routine. | |
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) | |
return; | |
// You should check nonces and permissions here | |
if ( ! current_user_can( 'edit_page', $post_id ) ) | |
return; | |
// only for debugging, get an list of all templates for pages | |
var_dump( get_page_templates() ); | |
if ( esc_attr( $_REQUEST['page_template'] ) !== 'page-contact.php' ) { | |
// No page template assigned - do something here. | |
wp_die( 'wrong template' ); | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment