$type ) { add_meta_box( 'theme-settings', esc_html__( 'Theme Settings', 'photomania' ), 'photomania_render_theme_settings_metabox', $type ); } } endif; add_action( 'add_meta_boxes', 'photomania_add_theme_meta_box' ); if ( ! function_exists( 'photomania_render_theme_settings_metabox' ) ) : /** * Render theme settings meta box. * * @since 1.0.0 * * @param WP_Post $post The current post. * @param array $metabox Metabox arguments. */ function photomania_render_theme_settings_metabox( $post, $metabox ) { $post_id = $post->ID; // Meta box nonce for verification. wp_nonce_field( basename( __FILE__ ), 'photomania_theme_settings_meta_box_nonce' ); // Fetch values of current post meta. $values = get_post_meta( $post_id, 'photomania_theme_settings', true ); $photomania_theme_settings_post_layout = isset( $values['post_layout'] ) ? esc_attr( $values['post_layout'] ) : ''; $photomania_theme_settings_single_image = isset( $values['single_image'] ) ? esc_attr( $values['single_image'] ) : ''; ?>
array( 'type' => 'select', ), 'single_image' => array( 'type' => 'select', ), ); $sanitized_values = array(); foreach ( $raw_value as $mk => $mv ) { if ( isset( $meta_fields[ $mk ]['type'] ) ) { switch ( $meta_fields[ $mk ]['type'] ) { case 'select': $sanitized_values[ $mk ] = sanitize_key( $mv ); break; case 'checkbox': $sanitized_values[ $mk ] = absint( $mv ) > 0 ? 1 : 0; break; default: $sanitized_values[ $mk ] = sanitize_text_field( $mv ); break; } } // End if. } update_post_meta( $post_id, 'photomania_theme_settings', $sanitized_values ); } } // End if theme settings. } endif; add_action( 'save_post', 'photomania_save_theme_settings_meta', 10, 2 );