Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. /**
  2. * Adds a meta box to the post editing screen
  3. */
  4. function gwrrest_custom_meta() {
  5. $post_types = array ( 'supplier' );
  6. foreach( $post_types as $post_type ) {
  7. add_meta_box(
  8. 'gwrrest_meta',
  9. __( 'Restaurant Options', 'gwrrest-textdomain' ),
  10. 'gwrrest_meta_callback',
  11. $post_type,
  12. 'normal',
  13. 'high'
  14. );
  15. }
  16. }
  17. add_action( 'add_meta_boxes', 'gwrrest_custom_meta' );
  18.  
  19. /**
  20. * Outputs the content of the meta box
  21. */
  22. function gwrrest_meta_callback( $post ) {
  23. wp_nonce_field( basename( __FILE__ ), 'gwrrest_nonce' );
  24. $gwrrest_stored_meta = get_post_meta( $post->ID );
  25. ?>
  26.  
  27. <?php _e( 'Is this a restaurant? ', 'gwrrest-textdomain' )?>
  28. </span>
  29. <div class="gwrrest-row-content">
  30. <label for="restaurant-options">
  31. <input type="checkbox" name="restaurant-options" id="restaurant-options" value="yes" <?php if ( isset ( $gwrrest_stored_meta['restaurant-options'] ) ) checked( $gwrrest_stored_meta['restaurant-options'][0], 'yes' ); ?> />
  32. <?php _e( 'Check to add a specials section to the restaurant pages', 'gwrrest-textdomain' )?>
  33. </label>
  34. </div>
  35. </p>
  36. <p>
  37. <label for="specials-textarea" class="prfx-row-title"><?php _e( 'Enter Specials Content Here', 'prfx-textdomain' )?></label>
  38. <textarea name="specials-textarea" id="specials-textarea"><?php if ( isset ( $prfx_stored_meta['specials-textarea'] ) ) echo $prfx_stored_meta['specials-textarea'][0]; ?></textarea>
  39. </p>
  40. <?php
  41. }
  42.  
  43. /**
  44. * Saves the custom meta input
  45. */
  46. function gwrrest_meta_save( $post_id ) {
  47. // Checks save status
  48. $is_autosave = wp_is_post_autosave( $post_id );
  49. $is_revision = wp_is_post_revision( $post_id );
  50. $is_valid_nonce = ( isset( $_POST[ 'gwrrest_nonce' ] ) && wp_verify_nonce( $_POST[ 'gwrrest_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
  51.  
  52. // Exits script depending on save status
  53. if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
  54. return;
  55. }
  56.  
  57. // Checks for input and saves
  58. if ( isset( $_POST['restaurant-options'] ) && $_POST['restaurant-options'] ) {
  59. add_post_meta( $post_id, 'restaurant-options', 'yes', true );
  60. } else {
  61. delete_post_meta( $post_id, 'restaurant-options' );
  62. }
  63.  
  64. // Checks for input and saves if needed
  65. if( isset( $_POST[ 'specials-textarea' ] ) ) {
  66. update_post_meta( $post_id, 'specials-textarea', $_POST[ 'specials-textarea' ] );
  67. } else {
  68. delete_post_meta( $post_id, 'specials-textarea' );
  69. }
  70. }
  71. add_action( 'save_post', 'gwrrest_meta_save' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement