Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. function la_add_custom_metabox() {
  2. add_meta_box(
  3. 'la_meta',
  4. __( 'Dados de Cadastro' ),
  5. 'la_meta_callback',
  6. 'cota',
  7. 'normal',
  8. 'core'
  9. );
  10. }
  11. add_action( 'add_meta_boxes', 'la_add_custom_metabox' );
  12.  
  13. function la_meta_callback(){
  14.  
  15. wp_nonce_field( basename( __FILE__ ), 'la_cotas_nonce' );
  16. $la_stored_meta = get_post_meta( $post->ID ); ?>
  17.  
  18. <div>
  19.  
  20. <div class="meta-row">
  21. <div class="meta-th">
  22. <label for="credito" class="dwwp-row-title"><?php _e( 'Crédito', 'la-cotas' ); ?></label>
  23. </div>
  24. <div class="meta-td">
  25. <input type="text" class="dwwp-row-content" name="credito" id="credito" value="<?php if ( ! empty ( $la_stored_meta['credito'] ) ) { echo esc_attr( $la_stored_meta['credito'][0] ); } ?>"/>
  26. </div>
  27. </div>
  28. </div>
  29.  
  30. function la_meta_save( $post_id ) {
  31. // Checks save status
  32. $is_autosave = wp_is_post_autosave( $post_id );
  33. $is_revision = wp_is_post_revision( $post_id );
  34. $is_valid_nonce = ( isset( $_POST[ 'la_cotas_nonce' ] ) && wp_verify_nonce( $_POST[ 'la_cotas_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
  35.  
  36. // Exits script depending on save status
  37. if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
  38. return;
  39. }
  40.  
  41.  
  42. if ( isset( $_POST[ 'credito' ] ) ) {
  43. update_post_meta( $post_id, 'credito', sanitize_text_field( $_POST[ 'credito' ] ) );
  44. }
  45.  
  46. }
  47.  
  48. add_action( 'save_post', 'la_meta_save' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement