Skip to content

Commit

Permalink
PHP Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
officiallygod committed Nov 18, 2022
1 parent 2d37959 commit e99fedd
Showing 1 changed file with 39 additions and 43 deletions.
82 changes: 39 additions & 43 deletions includes/RestApi/Themes/ThemeVariationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,45 @@ public function register_routes() {
$this->rest_base . $this->rest_extended_base,
array(
array(
'methods' => \WP_REST_Server::READABLE,
'args' => $this->get_pattern_args(),
'callback' => array( $this, 'get_theme_variations' ),
'methods' => \WP_REST_Server::READABLE,
'args' => $this->get_pattern_args(),
'callback' => array( $this, 'get_theme_variations' ),
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ),
),
array(
'methods' => \WP_REST_Server::EDITABLE,
'args' => $this->set_pattern_args(),
'callback' => array($this, 'set_theme_variation'),
'permission_callback' => array(Permissions::class, 'rest_is_authorized_admin'),
'methods' => \WP_REST_Server::EDITABLE,
'args' => $this->set_pattern_args(),
'callback' => array( $this, 'set_theme_variation' ),
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ),
),
)
);
}

public function get_pattern_args()
{
public function get_pattern_args() {
// These variable return the orginal numerous variations if true
// Else sends the recently saved theme settings in db
return array(
'variations' => array(
'type' => 'boolean',
'default' => false,
)
);
}

public function set_pattern_args()
{
return array(
'variations' => array(
'type' => 'boolean',
'default' => false,
),
);
}

public function set_pattern_args() {
// This is the latest modified Global Style to be saved in the db
return array(
'title' => array(
'type' => 'string',
'required' => true,
),
'settings' => array(
'type' => 'array',
'required' => true,
)
);
}
return array(
'title' => array(
'type' => 'string',
'required' => true,
),
'settings' => array(
'type' => 'array',
'required' => true,
),
);
}

/**
* Retrieves the active themes variations.
Expand All @@ -89,20 +87,19 @@ public function set_pattern_args()
*/
public function get_theme_variations( \WP_REST_Request $request ) {

$default = $request->get_param('variations');
$default = $request->get_param( 'variations' );

// If there exists an old Custom Theme then return that
if( 'false' === $default && false !== \get_option(Options::get_option_name('theme_settings')) )
{
if ( 'false' === $default && false !== \get_option( Options::get_option_name( 'theme_settings' ) ) ) {
return array(
\get_option(Options::get_option_name('theme_settings'))
\get_option( Options::get_option_name( 'theme_settings' ) ),
);
}

$active_variation = \WP_Theme_JSON_Resolver::get_merged_data( 'theme' )->get_raw_data();
$active_variation_global_style = array(
'id' => 0,
'title' => 'Default',
'title' => 'Default',
'version' => $active_variation['version'],
'settings' => $active_variation['settings'],
'styles' => $active_variation['styles'],
Expand All @@ -119,16 +116,15 @@ public function get_theme_variations( \WP_REST_Request $request ) {
*
* @return \WP_REST_Response|\WP_Error
*/
public function set_theme_variation(\WP_REST_Request $request)
{
public function set_theme_variation( \WP_REST_Request $request ) {
// The theme data with the new Colors and Fonts
$theme_data = json_decode($request->get_body(), true);
if($theme_data){
$theme_data = json_decode( $request->get_body(), true );

if ( $theme_data ) {

// Save the new Theme style into the db
\update_option(Options::get_option_name('theme_settings'), $theme_data);
\update_option( Options::get_option_name( 'theme_settings' ), $theme_data );

return new \WP_REST_Response(
$theme_data,
200
Expand Down

0 comments on commit e99fedd

Please sign in to comment.