Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php //
- //Price list meta boxes
- add_action( 'add_meta_boxes', 'cd_meta_box_add' );
- function cd_meta_box_add() {add_meta_box( 'price-list-id', 'Price List', 'cd_meta_box_cb', 'post', 'normal', 'high' );}
- function cd_meta_box_cb()
- {
- // $post is already set, and contains an object: the WordPress post
- global $post;
- $values = get_post_custom( $post->ID );
- //
- $plheading = isset( $values['price_list_heading'] ) ? esc_attr( $values['price_list_heading'][0] ) : '';
- $plcategory1 = isset( $values['price_list_category1'] ) ? esc_attr( $values['price_list_category1'][0] ) : '';
- $plcategoryitems1 = isset( $values['price_list_items_category1'] ) ? esc_attr( $values['price_list_items_category1'][0] ) : '';
- $plcategory2 = isset( $values['price_list_category2'] ) ? esc_attr( $values['price_list_category2'][0] ) : '';
- $plcategoryitems2 = isset( $values['price_list_items_category2'] ) ? esc_attr( $values['price_list_items_category2'][0] ) : '';
- $plcategory3 = isset( $values['price_list_category3'] ) ? esc_attr( $values['price_list_category3'][0] ) : '';
- $plcategoryitems3 = isset( $values['price_list_items_category3'] ) ? esc_attr( $values['price_list_items_category3'][0] ) : '';
- // We'll use this nonce field later on when saving.
- wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
- ?>
- <p>
- <label for="price_list_heading">Price list heading:</label>
- <input type="text" name="price_list_heading" id="price_list_heading" value="<?php echo $plheading; ?>" />
- *Deleting this value disables price list in sidebar front-end
- </p>
- <p>
- <label for="price_list_category1">Category1 Title:</label>
- <input type="text" name="price_list_category1" id="price_list_category1" value="<?php echo $plcategory1; ?>" />
- <textarea style="width: 100%;" rows="3" name="price_list_items_category1" id="price_list_items_category1"><?php echo $plcategoryitems1; ?></textarea>
- <span style="display: block; font-weight: bold; text-align: right;">Example: Rhine Riesling1|0,75 l|9,50 €</span>
- </p>
- <p>
- <label for="price_list_category2">Category2 Title:</label>
- <input type="text" name="price_list_category2" id="price_list_category2" value="<?php echo $plcategory2; ?>" />
- <textarea style="width: 100%;" rows="3" name="price_list_items_category2" id="price_list_items_category2"><?php echo $plcategoryitems2; ?></textarea>
- <span style="display: block; font-weight: bold; text-align: right;">Example: Rhine Riesling1|0,75 l|9,50 €</span>
- </p>
- <p>
- <label for="price_list_category3">Category3 Title:</label>
- <input type="text" name="price_list_category3" id="price_list_category3" value="<?php echo $plcategory3; ?>" />
- <textarea style="width: 100%;" rows="3" name="price_list_items_category3" id="price_list_items_category3"><?php echo $plcategoryitems3; ?></textarea>
- <span style="display: block; font-weight: bold; text-align: right;">Example: Rhine Riesling1|0,75 l|9,50 €</span>
- </p>
- <?php
- }
- //Saving price list
- add_action( 'save_post', 'cd_meta_box_save' );
- function cd_meta_box_save( $post_id )
- {
- // Bail if we're doing an auto save
- if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
- // if our nonce isn't there, or we can't verify it, bail
- if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
- // if our current user can't edit this post, bail
- if( !current_user_can( 'edit_post' ) ) return;
- // Make sure your data is set before trying to save it
- if( isset( $_POST['price_list_heading'] ) )
- update_post_meta( $post_id, 'price_list_heading', esc_attr( $_POST['price_list_heading'] ) );
- //
- if( isset( $_POST['price_list_category1'] ) )
- update_post_meta( $post_id, 'price_list_category1', esc_attr( $_POST['price_list_category1'] ) );
- if( isset( $_POST['price_list_items_category1'] ) )
- update_post_meta( $post_id, 'price_list_items_category1', esc_attr( $_POST['price_list_items_category1'] ) );
- //
- if( isset( $_POST['price_list_category2'] ) )
- update_post_meta( $post_id, 'price_list_category2', esc_attr( $_POST['price_list_category2'] ) );
- if( isset( $_POST['price_list_items_category2'] ) )
- update_post_meta( $post_id, 'price_list_items_category2', esc_attr( $_POST['price_list_items_category2'] ) );
- //
- if( isset( $_POST['price_list_category3'] ) )
- update_post_meta( $post_id, 'price_list_category3', esc_attr( $_POST['price_list_category3'] ) );
- if( isset( $_POST['price_list_items_category3'] ) )
- update_post_meta( $post_id, 'price_list_items_category3', esc_attr( $_POST['price_list_items_category3'] ) );
- }
- //Listing details features and services meta checkboxes
- add_action( 'add_meta_boxes', 'cd_meta_checklist_add' );
- function cd_meta_checklist_add() {add_meta_box( 'checklist-id', 'Listing Icons', 'cd_meta_checklist_cb', 'post', 'normal', 'high' );}
- function cd_meta_checklist_cb()
- {
- global $post;
- $values = get_post_custom( $post->ID );
- //check of checkbox should be active or not
- $pricelistline = explode(",", get_post_meta($post->ID, 'meta_features_checklist', true));
- // We'll use this nonce field later on when saving.
- wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
- ?>
- <p>
- <label for="meta_box_check_bar">bar</label>
- <input type="checkbox" id="meta_box_check_bar" name="meta_box_check_bar" value="bar" <?php if ($pricelistline[0]) {echo "checked";} ?> />
- </p>
- <p>
- <label for="meta_box_check_parking">parking</label>
- <input type="checkbox" id="meta_box_check_parking" name="meta_box_check_parking" value="parking" <?php if ($pricelistline[1]) {echo "checked";} ?> />
- </p>
- <p>
- <label for="meta_box_check_accessible-for-disabled">accessible-for-disabled</label>
- <input type="checkbox" id="meta_box_check_accessible-for-disabled" name="meta_box_check_accessible-for-disabled" value="accessible-for-disabled" <?php if ($pricelistline[2]) {echo "checked";} ?> />
- </p>
- <p>
- <label for="meta_box_check_air-conditioning">air-conditioning</label>
- <input type="checkbox" id="meta_box_check_air-conditioning" name="meta_box_check_air-conditioning" value="air-conditioning" <?php if ($pricelistline[3]) {echo "checked";} ?> />
- </p>
- <p>
- <label for="meta_box_check_frigo-bar">frigo-bar </label>
- <input type="checkbox" id="meta_box_check_frigo-bar" name="meta_box_check_frigo-bar" value="frigo-bar" <?php if ($pricelistline[4]) {echo "checked";} ?> />
- </p>
- <p>
- <label for="meta_box_check_pets">pets</label>
- <input type="checkbox" id="meta_box_check_pets" name="meta_box_check_pets" value="pets" <?php if ($pricelistline[5]) {echo "checked";} ?> />
- </p>
- <p>
- <label for="meta_box_check_phone">phone</label>
- <input type="checkbox" id="meta_box_check_phone" name="meta_box_check_phone" value="phone" <?php if ($pricelistline[6]) {echo "checked";} ?> />
- </p>
- <p>
- <label for="meta_box_check_tv">tv</label>
- <input type="checkbox" id="meta_box_check_tv" name="meta_box_check_tv" value="tv" <?php if ($pricelistline[7]) {echo "checked";} ?> />
- </p>
- <p>
- <label for="meta_box_check_local-dishes">local-dishes</label>
- <input type="checkbox" id="meta_box_check_local-dishes" name="meta_box_check_local-dishes" value="local-dishes" <?php if ($pricelistline[8]) {echo "checked";} ?> />
- </p>
- <?php }
- //Saving checkbox states
- add_action( 'save_post', 'cd_meta_checkbox_save' );
- function cd_meta_checkbox_save( $post_id )
- {
- // Bail if we're doing an auto save
- if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
- // if our nonce isn't there, or we can't verify it, bail
- if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
- // if our current user can't edit this post, bail
- if( !current_user_can( 'edit_post' ) ) return;
- //grabing all checkbox values and combining them
- /* make an array for all used checkbox */
- $used_checkboxes = array();
- /* make an array whit all options */
- $avaible_checkboxes = explode(',', "bar,parking,accessible-for-disabled,air-conditioning,frigo-bar,pets,phone,tv,local-dishes");
- /* loop troguht all avaible checkboxes */
- foreach($avaible_checkboxes as $current_key)
- {
- /* check if the checkbox was sent */
- if(isset($_POST["meta_box_check_{$current_key}"]))
- {
- /* if sent, add key to list */
- $used_checkboxes[$current_key] = $current_key;
- }
- else
- {
- /* if not sent, add empty value to list */
- $used_checkboxes[$current_key] = '';
- }
- }
- /* convert list to csv */
- $used_checkboxes_csv = implode(',', $used_checkboxes);
- //saving to DB
- if( isset( $used_checkboxes_csv ) )
- update_post_meta( $post_id, 'meta_features_checklist', esc_attr( $used_checkboxes_csv ) );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement