Created
May 23, 2012 22:53
-
-
Save pedroelsner/2778335 to your computer and use it in GitHub Desktop.
#5 - Plugin WordPress - Hello Word
This file contains hidden or 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 | |
/** | |
* Função que grava as opções do plugin | |
* | |
* @param int $post_id | |
* @return int | |
*/ | |
function hello_world_save_postdata( $post_id ) { | |
if ( ! wp_verify_nonce( $_POST['hello_world_nonce'], plugin_basename(__FILE__) ) ) { | |
return $post_id; | |
} | |
// Verifica se o usuário pode editar post ou página | |
if ( 'page' == $_POST['post_type'] && ! current_user_can( 'edit_page', $post_id ) ) { | |
return $post_id; | |
} elseif ( ! current_user_can( 'edit_post', $post_id ) ) { | |
return $post_id; | |
} | |
// Se opt_mostrar_mensagem foi selecionado atualiza tabela | |
if ( ! empty( $_POST['hello_world_opt_mostrar_mensagem'] ) ) { | |
update_post_meta( $post_id, 'hello_world_opt_mostrar_mensagem', '1' ); | |
} else { | |
delete_post_meta( $post_id, 'hello_world_opt_mostrar_mensagem' ); | |
} | |
return true; | |
} | |
// Cria hook necessário | |
add_action( 'save_post', 'hello_world_save_postdata' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment