'inherit', 'value' => 1500, ); } public function register_meta() { $args = array( 'show_in_rest' => array( 'schema' => array( 'type' => 'object', 'properties' => array( 'type' => array( 'type' => 'string', ), 'value' => array( 'type' => 'number', ), ), ), ), 'single' => true, 'type' => 'object', 'default' => self::get_default_value(), 'auth_callback' => '__return_true', ); foreach ( array( 'post', 'page' ) as $post_type ) { register_post_meta( $post_type, self::META_NAME, $args ); } } public static function is_valid_meta_value( $meta_value ) { if ( ! isset( $meta_value['type'] ) || ! in_array( $meta_value['type'], array( 'inherit', 'custom', 'unset' ), true ) ) { return false; } if ( ! isset( $meta_value['value'] ) || ! is_numeric( $meta_value['value'] ) ) { return false; } return true; } public function register_block_editor_setting( $editor_settings ) { $editor_settings['styles'][] = array( 'css' => 'body{' . PostMetaServices::map_array_to_css( self::get_css_array() ) . '}', 'author' => 'brandy', 'type' => 'post_container_layout', ); return $editor_settings; } public static function get_css_array() { $current_post_id = brandy_get_current_page_id(); if ( empty( $current_post_id ) ) { return array(); } $container_max_width = self::get_value( $current_post_id ); $styles = array(); if ( isset( $container_max_width['type'] ) && 'custom' === $container_max_width['type'] ) { $styles['--theme-container-max-width'] = ( empty( $container_max_width['value'] ) ? 'unset' : ( $container_max_width['value'] . 'px' ) ); } if ( isset( $container_max_width['type'] ) && 'unset' === $container_max_width['type'] ) { $styles['--theme-container-max-width'] = '100%'; } return $styles; } }