__( 'Choose image', 'shariff' ) ); wp_localize_script( 'shariff_mediaupload', 'shariff_media', $translation_array ); wp_enqueue_script( 'shariff_mediaupload' ); // Make sure the form request comes from WordPress. wp_nonce_field( basename( __FILE__ ), 'shariff_metabox_nonce' ); // Retrieve the current metabox disable value. $shariff_metabox_disable = get_post_meta( get_the_ID(), 'shariff_metabox_disable', true ); // Disable checkbox. echo '

' . esc_html__( 'Disable Shariff', 'shariff' ) . '
'; echo ''; echo '

'; // Retrieve the current metabox add before and after values. $shariff_metabox_before = get_post_meta( get_the_ID(), 'shariff_metabox_before', true ); $shariff_metabox_after = get_post_meta( get_the_ID(), 'shariff_metabox_after', true ); // Add Shariff checkboxes. echo '

' . esc_html__( 'Add Shariff', 'shariff' ) . '
'; // Before checkbox. echo ''; echo '
'; // After checkbox. echo ''; echo '

'; // Retrieve the current metabox media value (pinterest image). $shariff_metabox_media = get_post_meta( get_the_ID(), 'shariff_metabox_media', true ); // Metabox shortcode. echo '

' . esc_html__( 'Pinterest Image', 'shariff' ) . '

'; echo '

'; // Retrieve the current metabox shortcode value. $shariff_metabox = get_post_meta( get_the_ID(), 'shariff_metabox', true ); // Metabox shortcode. echo '

' . esc_html__( 'Shortcode', 'shariff' ) . '

'; echo '

'; // Retrieve the current metabox ignore widget value. $shariff_metabox_ignore_widget = get_post_meta( get_the_ID(), 'shariff_metabox_ignore_widget', true ); // Disable checkbox. echo '

' . esc_html__( 'Ignore Widgets', 'shariff' ) . '
'; echo ''; echo '

'; } /** * Save meta data. * * @param integer $post_id ID of the current post. * @param WP_Post $post Current post. */ function shariff3uu_save_metabox_data( $post_id, $post ) { // Check nonce and if shariff_metabox is set. if ( isset( $_REQUEST['shariff_metabox_nonce'] ) && wp_verify_nonce( sanitize_key( $_REQUEST['shariff_metabox_nonce'] ), basename( __FILE__ ) ) ) { // Check if we are not autosaving or previewing (revision), else we are good to go and can save our meta box data. $post_type_object = get_post_type_object( $post->post_type ); if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || wp_is_post_revision( $post ) || ( is_multisite() && ms_is_switched() ) || ! current_user_can( $post_type_object->cap->edit_post, $post_id ) ) { return; } else { // Save meta box disable. if ( isset( $_POST['shariff_metabox_disable'] ) && 'on' === $_POST['shariff_metabox_disable'] ) { update_post_meta( $post_id, 'shariff_metabox_disable', 1 ); } else { delete_post_meta( $post_id, 'shariff_metabox_disable', 1 ); } // Save meta box add before value. if ( isset( $_POST['shariff_metabox_before'] ) && 'on' === $_POST['shariff_metabox_before'] ) { update_post_meta( $post_id, 'shariff_metabox_before', 1 ); } else { delete_post_meta( $post_id, 'shariff_metabox_before', 1 ); } // Save meta box add after value. if ( isset( $_POST['shariff_metabox_after'] ) && 'on' === $_POST['shariff_metabox_after'] ) { update_post_meta( $post_id, 'shariff_metabox_after', 1 ); } else { delete_post_meta( $post_id, 'shariff_metabox_after', 1 ); } // Save meta box media. if ( isset( $_POST['shariff_metabox_media'] ) && ! empty( $_POST['shariff_metabox_media'] ) ) { update_post_meta( $post_id, 'shariff_metabox_media', esc_url_raw( wp_unslash( $_POST['shariff_metabox_media'] ) ) ); } else { delete_post_meta( $post_id, 'shariff_metabox_media' ); } // Save meta box shortcode. if ( isset( $_POST['shariff_metabox'] ) && ! empty( $_POST['shariff_metabox'] ) ) { update_post_meta( $post_id, 'shariff_metabox', wp_kses( wp_unslash( $_POST['shariff_metabox'] ), $GLOBALS['allowed_tags'] ) ); } else { delete_post_meta( $post_id, 'shariff_metabox' ); } // Save meta box ignore widgets. if ( isset( $_POST['shariff_metabox_ignore_widget'] ) && 'on' === $_POST['shariff_metabox_ignore_widget'] ) { update_post_meta( $post_id, 'shariff_metabox_ignore_widget', 1 ); } else { delete_post_meta( $post_id, 'shariff_metabox_ignore_widget', 1 ); } } } } add_action( 'save_post', 'shariff3uu_save_metabox_data', 10, 2 );