Rest_Store_Settings
Source
File: includes/libs/rest-api/endpoints/plugin/rest-store-settings.class.php
018 | class Rest_Store_Settings |
019 | extends Rest_Controller_Abstract |
020 | implements Rest_Controller_Interface { |
022 | public function __construct(){ |
023 | parent::set_namespace( 'vimeotheque/v1' ); |
024 | parent::set_rest_base( '/plugin/settings' ); |
025 | $this ->register_routes(); |
031 | public function get_response( \WP_REST_Request $request ) { |
032 | $options = $this ->process_options( |
033 | Plugin::instance()->get_options_obj()->get_defaults(), |
034 | Plugin::instance()->get_options_obj()->get_options(), |
035 | $request ->get_params() |
038 | Plugin::instance()->get_options_obj()->update_options( $options ); |
040 | $player_options = $this ->process_options( |
041 | Plugin::instance()->get_embed_options_obj()->get_defaults(), |
042 | Plugin::instance()->get_embed_options_obj()->get_options(), |
043 | $request ->get_params() |
046 | Plugin::instance()->get_embed_options_obj()->update_options( $player_options ); |
049 | $options = Plugin::instance()->get_options_obj()->get_options(true); |
051 | $settings_page_url = sprintf( |
052 | 'edit.php?post_type=%s&page=%s' , |
053 | Plugin::instance()->get_cpt()->get_post_type(), |
057 | $oauth = new Vimeo_Oauth( |
058 | $options [ 'vimeo_consumer_key' ], |
059 | $options [ 'vimeo_secret_key' ], |
060 | $options [ 'oauth_token' ], |
061 | admin_url( $settings_page_url ) |
067 | if ( ! empty ( $options [ 'vimeo_consumer_key' ] ) && ! empty ( $options [ 'vimeo_secret_key' ] ) ){ |
068 | if ( empty ( $options [ 'oauth_token' ] ) || ( isset( $options [ 'oauth_secret' ] ) && empty ( $options [ 'oauth_secret' ] ) ) ){ |
069 | $token = $oauth ->get_unauth_token(); |
071 | if ( !is_wp_error( $token ) ){ |
072 | $options [ 'oauth_token' ] = $token ; |
074 | $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' ); |
076 | $options [ 'vimeo_consumer_key' ] = '' ; |
077 | $options [ 'vimeo_secret_key' ] = '' ; |
078 | $options [ 'oauth_token' ] = '' ; |
079 | $message = $token ->get_error_message(); |
082 | Plugin::instance()->get_options_obj()->update_options( $options ); |
085 | $message = __( 'In order to be able to query Vimeo you must enter your Vimeo OAuth client and secret key.' , 'codeflavors-vimeo-video-post-lite' ); |
089 | 'success' => $success , |
090 | 'message' => $message |
103 | private function process_options( $defaults , $options , $new_options ){ |
104 | foreach ( $defaults as $index => $value ) { |
105 | if ( isset( $new_options [ $index ] ) ){ |
106 | switch ( gettype ( $value ) ){ |
108 | $options [ $index ] = (bool) $new_options [ $index ]; |
111 | $options [ $index ] = (int) $new_options [ $index ]; |
114 | $options [ $index ] = trim( (string) $new_options [ $index ] ); |
126 | public function register_routes() { |
128 | parent::get_namespace(), |
129 | parent::get_rest_base(), |
131 | 'methods' => \WP_REST_Server::CREATABLE, |
132 | 'callback' => [ $this , 'get_response' ], |
133 | 'permission_callback' => function (){ |
134 | return current_user_can( 'manage_options' ); |
Expand full source code
Collapse full source code