Rest_Store_Settings::get_response( $request )


Source

File: includes/libs/rest-api/endpoints/plugin/rest-store-settings.class.php

	public function get_response( \WP_REST_Request $request ) {
		$options = $this->process_options(
			Plugin::instance()->get_options_obj()->get_defaults(),
			Plugin::instance()->get_options_obj()->get_options(),
			$request->get_params()
		);
		// Update the options
		Plugin::instance()->get_options_obj()->update_options( $options );

		$player_options = $this->process_options(
			Plugin::instance()->get_embed_options_obj()->get_defaults(),
			Plugin::instance()->get_embed_options_obj()->get_options(),
			$request->get_params()
		);
		// Update the player embed options
		Plugin::instance()->get_embed_options_obj()->update_options( $player_options );

		// Refresh the options.
		$options = Plugin::instance()->get_options_obj()->get_options(true);

		$settings_page_url = sprintf(
			'edit.php?post_type=%s&page=%s',
			Plugin::instance()->get_cpt()->get_post_type(),
			'cvm_settings'
		);

		$oauth = new Vimeo_Oauth(
			$options['vimeo_consumer_key'],
			$options['vimeo_secret_key'],
			$options['oauth_token'],
			admin_url( $settings_page_url )
		);

		$success = false;
		$message = '';

		if( !empty( $options['vimeo_consumer_key'] ) && !empty( $options['vimeo_secret_key'] ) ){
			if( empty( $options['oauth_token'] ) || ( isset( $options['oauth_secret'] ) && empty( $options['oauth_secret'] ) ) ){
				$token = $oauth->get_unauth_token();

				if( !is_wp_error( $token ) ){
					$options['oauth_token'] = $token;
					$success = true;
					$message = __( 'Your Vimeo keys are successfully installed. You can now query public videos on Vimeo and import them as WordPress posts.', 'codeflavors-vimeo-video-post-lite' );
				}else{
					$options['vimeo_consumer_key'] = '';
					$options['vimeo_secret_key'] = '';
					$options['oauth_token'] = '';
					$message = $token->get_error_message();
				}

				Plugin::instance()->get_options_obj()->update_options( $options );
			}
		}else{
			$message = __( 'In order to be able to query Vimeo you must enter your Vimeo OAuth client and secret key.', 'codeflavors-vimeo-video-post-lite' );
		}

		wp_send_json([
			'success' => $success,
			'message' => $message
		]);
	}

Start your video site now!

Manage and coordinate your Vimeo channels, albums or videos with your WordPress website. Perfect fit for membership, portfolio, online courses or any type of video collection.

Get Vimeotheque PRO!