WP_REST_Global_Styles_Controller::prepare_item_for_database() – Prepares a single global styles config for update.

You appear to be a bot. Output may be restricted

Description

Prepares a single global styles config for update.

Usage

$stdClass = WP_REST_Global_Styles_Controller::prepare_item_for_database( $request );

Parameters

$request
( WP_REST_Request ) required – Request object.

Returns

stdClass Changes to pass to wp_update_post.

Source

File name: wordpress/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php
Lines:

1 to 43 of 43
  protected function prepare_item_for_database( $request ) {
    $changes     = new stdClass();
    $changes->ID = $request['id'];

    $post            = get_post( $request['id'] );
    $existing_config = array();
    if ( $post ) {
      $existing_config     = json_decode( $post->post_content, true );
      $json_decoding_error = json_last_error();
      if ( JSON_ERROR_NONE !== $json_decoding_error || ! isset( $existing_config['isGlobalStylesUserThemeJSON'] ) ||
        ! $existing_config['isGlobalStylesUserThemeJSON'] ) {
        $existing_config = array();
      }
    }

    if ( isset( $request['styles'] ) || isset( $request['settings'] ) ) {
      $config = array();
      if ( isset( $request['styles'] ) ) {
        $config['styles'] = $request['styles'];
      } elseif ( isset( $existing_config['styles'] ) ) {
        $config['styles'] = $existing_config['styles'];
      }
      if ( isset( $request['settings'] ) ) {
        $config['settings'] = $request['settings'];
      } elseif ( isset( $existing_config['settings'] ) ) {
        $config['settings'] = $existing_config['settings'];
      }
      $config['isGlobalStylesUserThemeJSON'] = true;
      $config['version']                     = WP_Theme_JSON::LATEST_SCHEMA;
      $changes->post_content                 = wp_json_encode( $config );
    }

    // Post title.
    if ( isset( $request['title'] ) ) {
      if ( is_string( $request['title'] ) ) {
        $changes->post_title = $request['title'];
      } elseif ( ! empty( $request['title']['raw'] ) ) {
        $changes->post_title = $request['title']['raw'];
      }
    }

    return $changes;
  }
 

 View on GitHub View on Trac