Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // add custom meta box "Product Description" for post type "Product"
- add_action( 'add_meta_boxes', 'aim_product_description' );
- function aim_product_description() {
- add_meta_box(
- 'product_des',
- 'Product Description',
- 'aim_p_des_output_func',
- 'product',
- 'normal'
- );
- }
- function aim_p_des_output_func( $post ){
- wp_nonce_field( basename( __FILE__ ), 'aim_p_des_nonce' );
- $apd_meta_stored = get_post_meta( $post->ID );
- ?>
- <p>
- <label for="file_size" style="width: 60px;display:inline-block;">File Size</label>
- <input type="text" id="file_size" class="regular-text" name="_filesize"
- value="<?php if ( ! empty( $apd_meta_stored['_filesize'] ) ) {
- echo esc_attr ( $apd_meta_stored['_filesize'][0] );
- }?>" >
- </p>
- <p>
- <label for="file_type" style="width: 60px;display:inline-block;">File Type</label>
- <input type="text" id="file_type" class="regular-text" name="_filetype"
- value="<?php if ( ! empty( $apd_meta_stored['_filetype'] ) ) {
- echo esc_attr ( $apd_meta_stored['_filetype'][0] );
- }?>" >
- </p>
- <p>
- <label for="file_url" style="width: 60px;display:inline-block;">File Url</label>
- <input type="text" id="file_url" class="regular-text" name="_fileurl"
- value="<?php if ( ! empty( $apd_meta_stored['_fileurl'] ) ) {
- echo esc_attr ( $apd_meta_stored['_fileurl'][0] );
- }?>" >
- </p>
- <?php
- }
- function apd_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['aim_p_des_nonce'] ) && wp_verify_nonce( $_POST['aim_p_des_nonce'], basename( __FILE__ ) ) ) ? 'true' : 'false';
- // Exits script depending on save status
- if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
- return;
- }
- if ( isset( $_POST['_filesize'] ) ) {
- update_post_meta( $post_id, '_filesize', sanitize_text_field( $_POST['_filesize'] ) );
- }
- if ( isset( $_POST['_filetype'] ) ) {
- update_post_meta( $post_id, '_filetype', sanitize_text_field( $_POST['_filetype'] ) );
- }
- if ( isset( $_POST['_fileurl'] ) ) {
- update_post_meta( $post_id, '_fileurl', sanitize_text_field( $_POST['_fileurl'] ) );
- }
- }
- add_action( 'save_post', 'apd_meta_save' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement