'; foreach ( $errors as $error ) { echo '
' . wp_kses_post( $error ) . '
'; } echo ''; // Clear delete_option( 'flash_toolkit_meta_box_errors' ); } } /** * Add SI Meta boxes. */ public function add_meta_boxes() { // Portfolio add_meta_box( 'flash-toolkit-portfolio-data', __( 'Portfolio Data', 'flash-toolkit' ), 'FT_Meta_Box_Portfolio_Data::output', 'portfolio', 'normal', 'high' ); // Page Header if ( is_flash_pro_active() ) { add_meta_box( 'flash-toolkit-pageheader-data', __( 'Page Options', 'flash-toolkit' ), 'FT_Meta_Box_Pageoptions_Data::output', 'page', 'normal', 'high' ); } // Layouts foreach ( flash_toolkit_get_layout_supported_screens() as $post_type ) { if ( post_type_exists( $post_type ) && is_flash_pro_active() ) { $post_type_object = get_post_type_object( $post_type ); add_meta_box( 'flash-toolkit-layout-data', sprintf( __( '%s Layout', 'flash-toolkit' ), $post_type_object->labels->singular_name ), 'FT_Meta_Box_Layout_Data::output', $post_type, 'side', 'default' ); } } } /** * Remove bloat. */ public function remove_meta_boxes() { global $post; if ( is_flash_pro_active() ) { remove_meta_box( 'page-layout', 'post', 'side' ); remove_meta_box( 'page-layout', 'page', 'side' ); remove_meta_box( 'header-transparency', 'page', 'side' ); } if ( 'portfolio' === $post->post_type && 0 === count( get_page_templates( $post ) ) ) { remove_meta_box( 'pageparentdiv', 'portfolio', 'side' ); } } /** * Check if we're saving, the trigger an action based on the post type. * @param int $post_id * @param object $post */ public function save_meta_boxes( $post_id, $post ) { // $post_id and $post are required if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { return; } // Don't save meta boxes for revisions or autosaves if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { return; } // Check the nonce if ( empty( $_POST['flash_toolkit_meta_nonce'] ) || ! wp_verify_nonce( $_POST['flash_toolkit_meta_nonce'], 'flash_toolkit_save_data' ) ) { return; } // Check the post being saved == the $post_id to prevent triggering this call for other save_post events if ( empty( $_POST['post_ID'] ) || $_POST['post_ID'] != $post_id ) { return; } // Check user has permission to edit if ( ! current_user_can( 'edit_post', $post_id ) ) { return; } // We need this save event to run once to avoid potential endless loops. This would have been perfect: self::$saved_meta_boxes = true; // Check the post type if ( in_array( $post->post_type, array( 'portfolio' ) ) ) { do_action( 'flash_toolkit_process_' . $post->post_type . '_meta', $post_id, $post ); } // Trigger action $process_actions = array( 'layout', 'page' ); foreach ( $process_actions as $process_action ) { do_action( 'flash_toolkit_process_' . $process_action . '_meta', $post_id, $post ); } } } new FT_Admin_Meta_Boxes();