Skip to content

@bueltge /wpse46583_save.php
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Check for right WordPress page template on save_post hook
<?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
Something went wrong with that request. Please try again.