Skip to content

Instantly share code, notes, and snippets.

@pedroelsner
Created May 23, 2012 22:53
Show Gist options
  • Save pedroelsner/2778335 to your computer and use it in GitHub Desktop.
Save pedroelsner/2778335 to your computer and use it in GitHub Desktop.
#5 - Plugin WordPress - Hello Word
<?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