rozanchetta

Wordpress - Metabox

Sep 5th, 2011
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.29 KB | None | 0 0
  1. //METABOXES
  2. // Metabox das informações de projetos
  3. add_action('add_meta_boxes', 'portfolio_custom_boxes');
  4. function portfolio_custom_boxes() {add_meta_box('info-projetos', 'Informações do Projeto', 'rpt_info_projeto', 'post', 'side', 'high');}
  5. function rpt_info_projeto() {
  6. global $post;
  7. echo '<input type="hidden" name="infoprojetometa_noncename" id="infoprojetometa_noncename" value="' .
  8. wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
  9. $projeto = get_post_meta($post->ID, '_projeto', true);
  10. $anocriacao  = get_post_meta($post->ID, '_anocriacao', true);
  11. $role  = get_post_meta($post->ID, '_role', true);
  12. $urlcliente = get_post_meta($post->ID, '_urlcliente', true);
  13. $urlfacebook = get_post_meta($post->ID, '_urlfacebook', true);
  14. echo '<p>Tipo de Projeto:</p>';
  15. echo '<input type="text" name="_projeto" value="' . $projeto  . '" class="widefat" />';
  16. echo '<p>Digite o Ano de Criação do Projeto</p>';
  17. echo '<input type="text" name="_anocriacao" value="' . $anocriacao  . '" class="widefat" />';
  18. echo '<p>Tarefas Executadas</p>';
  19. echo '<input type="textarea" name="_role" value="' . $role  . '" class="widefat" />';
  20. echo '<p>Digite a Url do Cliente</p>';
  21. echo '<input type="text" name="_urlcliente" value="' . $urlcliente  . '" class="widefat" />';
  22. echo '<p>Digite a Url da Fan Page do Facebook</p>';
  23. echo '<input type="text" name="_urlfacebook" value="' . $urlfacebook  . '" class="widefat" />';
  24. }
  25. function rpt_save_infoprojeto_meta($post_id, $post) {
  26. if ( !wp_verify_nonce( $_POST['infoprojetometa_noncename'], plugin_basename(__FILE__) )) { return $post->ID; }
  27. if ( !current_user_can( 'edit_post', $post->ID )) return $post->ID;
  28. $infoprojeto_meta['_projeto'] = $_POST['_projeto'];
  29. $infoprojeto_meta['_anocriacao'] = $_POST['_anocriacao'];
  30. $infoprojeto_meta['_role'] = $_POST['_role'];
  31. $infoprojeto_meta['_urlcliente'] = $_POST['_urlcliente'];
  32. $infoprojeto_meta['_urlfacebook'] = $_POST['_urlfacebook'];
  33. foreach ($infoprojeto_meta as $key => $value) {
  34. if( $post->post_type == 'revision' ) return;
  35. $value = implode(',', (array)$value);
  36. if(get_post_meta($post->ID, $key, FALSE)) {
  37. update_post_meta($post->ID, $key, $value);
  38. } else {
  39. add_post_meta($post->ID, $key, $value);
  40. }
  41. if(!$value) delete_post_meta($post->ID, $key);
  42. }
  43. }
  44. add_action('save_post', 'rpt_save_infoprojeto_meta', 1, 2);
Advertisement
Add Comment
Please, Sign In to add comment