Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Adds a meta box to the post editing screen
- */
- function gwrrest_custom_meta() {
- $post_types = array ( 'supplier' );
- foreach( $post_types as $post_type ) {
- add_meta_box(
- 'gwrrest_meta',
- __( 'Restaurant Options', 'gwrrest-textdomain' ),
- 'gwrrest_meta_callback',
- $post_type,
- 'normal',
- 'high'
- );
- }
- }
- add_action( 'add_meta_boxes', 'gwrrest_custom_meta' );
- /**
- * Outputs the content of the meta box
- */
- function gwrrest_meta_callback( $post ) {
- wp_nonce_field( basename( __FILE__ ), 'gwrrest_nonce' );
- $gwrrest_stored_meta = get_post_meta( $post->ID );
- ?>
- <?php _e( 'Is this a restaurant? ', 'gwrrest-textdomain' )?>
- </span>
- <div class="gwrrest-row-content">
- <label for="restaurant-options">
- <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' ); ?> />
- <?php _e( 'Check to add a specials section to the restaurant pages', 'gwrrest-textdomain' )?>
- </label>
- </div>
- </p>
- <p>
- <label for="specials-textarea" class="prfx-row-title"><?php _e( 'Enter Specials Content Here', 'prfx-textdomain' )?></label>
- <textarea name="specials-textarea" id="specials-textarea"><?php if ( isset ( $prfx_stored_meta['specials-textarea'] ) ) echo $prfx_stored_meta['specials-textarea'][0]; ?></textarea>
- </p>
- <?php
- }
- /**
- * Saves the custom meta input
- */
- function gwrrest_meta_save( $post_id ) {
- // Checks save status
- $is_autosave = wp_is_post_autosave( $post_id );
- $is_revision = wp_is_post_revision( $post_id );
- $is_valid_nonce = ( isset( $_POST[ 'gwrrest_nonce' ] ) && wp_verify_nonce( $_POST[ 'gwrrest_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
- // Exits script depending on save status
- if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
- return;
- }
- // Checks for input and saves
- if ( isset( $_POST['restaurant-options'] ) && $_POST['restaurant-options'] ) {
- add_post_meta( $post_id, 'restaurant-options', 'yes', true );
- } else {
- delete_post_meta( $post_id, 'restaurant-options' );
- }
- // Checks for input and saves if needed
- if( isset( $_POST[ 'specials-textarea' ] ) ) {
- update_post_meta( $post_id, 'specials-textarea', $_POST[ 'specials-textarea' ] );
- } else {
- delete_post_meta( $post_id, 'specials-textarea' );
- }
- }
- add_action( 'save_post', 'gwrrest_meta_save' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement