Changeset 2670796
- Timestamp:
- 02/01/2022 06:17:39 PM (4 years ago)
- Location:
- shutterstock
- Files:
-
- 8 edited
- 1 copied
-
tags/1.3.9 (copied) (copied from shutterstock/trunk)
-
tags/1.3.9/README.txt (modified) (2 diffs)
-
tags/1.3.9/admin/class-shutterstock-admin.php (modified) (6 diffs)
-
tags/1.3.9/includes/class-shutterstock.php (modified) (1 diff)
-
tags/1.3.9/shutterstock.php (modified) (2 diffs)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/admin/class-shutterstock-admin.php (modified) (6 diffs)
-
trunk/includes/class-shutterstock.php (modified) (1 diff)
-
trunk/shutterstock.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shutterstock/tags/1.3.9/README.txt
r2661410 r2670796 3 3 Tags: shutterstock, stock photography, images, editorial images, licensing, media library, stock 4 4 Requires at least: 5.5 5 Tested up to: 5. 86 Stable tag: 1.3. 85 Tested up to: 5.9 6 Stable tag: 1.3.9 7 7 Requires PHP: 7.1 8 8 License: MIT … … 112 112 113 113 == Changelog == 114 = 1.3.9 = 115 * Update to support Wordpress 5.9 116 114 117 = 1.3.8 = 115 118 * * Bug fixes related to PHP warnings -
shutterstock/tags/1.3.9/admin/class-shutterstock-admin.php
r2466651 r2670796 21 21 * @author Shutterstock <api@shutterstock.com> 22 22 */ 23 class Shutterstock_Admin { 24 25 /** 26 * The ID of this plugin. 27 * 28 * @since 1.0.0 29 * @access private 30 * @var string $shutterstock The ID of this plugin. 31 */ 32 private $shutterstock; 33 34 /** 35 * The version of this plugin. 36 * 37 * @since 1.0.0 38 * @access private 39 * @var string $version The current version of this plugin. 40 */ 41 private $version; 42 43 private $shutterstock_options; 44 45 /** 46 * Initialize the class and set its properties. 47 * 48 * @since 1.0.0 49 * @param string $shutterstock The name of this plugin. 50 * @param string $version The version of this plugin. 51 */ 52 public function __construct( $shutterstock, $version, $shutterstock_ui ) { 53 54 $this->shutterstock = $shutterstock; 55 $this->version = $version; 56 $this->shutterstock_ui = $shutterstock_ui; 57 } 58 59 /** 60 * Register the stylesheets for the admin area. 61 * 62 * @since 1.0.0 63 */ 64 public function enqueue_styles() { 65 66 /** 67 * This function is provided for demonstration purposes only. 68 * 69 * An instance of this class should be passed to the run() function 70 * defined in Shutterstock_Loader as all of the hooks are defined 71 * in that particular class. 72 * 73 * The Shutterstock_Loader will then create the relationship 74 * between the defined hooks and the functions defined in this 75 * class. 76 */ 77 wp_enqueue_style( $this->shutterstock, plugin_dir_url( __FILE__ ) . 'css/shutterstock-admin.css', array(), $this->version, 'all' ); 78 79 } 80 81 /** 82 * Register the JavaScript for the admin area. 83 * 84 * @since 1.0.0 85 */ 86 public function enqueue_scripts($hook) { 87 88 /** 89 * This function is provided for demonstration purposes only. 90 * 91 * An instance of this class should be passed to the run() function 92 * defined in Shutterstock_Loader as all of the hooks are defined 93 * in that particular class. 94 * 95 * The Shutterstock_Loader will then create the relationship 96 * between the defined hooks and the functions defined in this 97 * class. 98 */ 99 100 wp_enqueue_script( $this->shutterstock, plugin_dir_url( __FILE__ ) . 'js/shutterstock-admin.js', array( 'jquery' ), $this->version, false ); 101 102 if ('media_page_shutterstock_media_page' === $hook) { 103 $this->load_scripts_for_media_page(); 104 } 105 } 106 107 public function load_scripts_for_media_page() { 108 wp_register_style('shutterstock-media-page-shutterstock-ui-css', $this->shutterstock_ui['css']); 109 wp_enqueue_style( 'shutterstock-media-page-shutterstock-ui-css'); 110 wp_register_script('shutterstock-media-page-shuttestock-ui-js', $this->shutterstock_ui['js']); 111 wp_enqueue_script( 'shutterstock-media-page-shuttestock-ui-js'); 112 113 $dir = dirname( __FILE__ ); 114 115 $script_asset_path = "$dir/shutterstock-media-page/index.asset.php"; 116 117 if ( ! file_exists( $script_asset_path ) ) { 118 throw new Error( 119 'You need to run `npm start:shutterstock:mediapage` or `npm run build:shutterstock:mediapage` for the "shutterstock/public/shutterstock-block" block first.' 120 ); 121 } 122 123 124 // Registering the shutterstock-media-page script 125 $index_js = 'shutterstock-media-page/index.js'; 126 $script_asset = require(dirname( __FILE__ ) . '/shutterstock-media-page/index.asset.php' ); 127 128 // Registering the shutterstock-media-page styles 129 $index_css = 'shutterstock-media-page/index.css'; 130 131 wp_register_style('shutterstock-media-page-styles', plugins_url( $index_css, __FILE__ )); 132 133 wp_register_script( 134 'shutterstock-media-page', 135 plugins_url( $index_js, __FILE__ ), 136 $script_asset['dependencies'], 137 $script_asset['version'] 138 ); 139 140 $loaded = wp_set_script_translations( 'shutterstock-media-page', 'shutterstock', plugin_dir_path(__DIR__) . 'languages/'); 141 142 wp_enqueue_script('shutterstock-media-page'); 143 wp_enqueue_style( 'shutterstock-media-page-styles'); 144 145 $shutterstock_helper = new Shutterstock_Helper($this->shutterstock, $this->version); 146 $shutterstock_js_object = $shutterstock_helper->get_shutterstock_js_object(); 147 148 wp_localize_script('shutterstock-media-page-shuttestock-ui-js', 'shutterstock', $shutterstock_js_object ); 149 } 150 151 public function add_admin_settings_page() { 152 add_options_page( 153 'Shutterstock', // page_title 154 'Shutterstock', // menu_title 155 'manage_options', // capability 156 "{$this->shutterstock}_options_page", // menu_slug 157 array( $this, 'create_admin_settings_page') // function 158 ); 159 160 add_submenu_page( 161 'upload.php', 162 'Shutterstock', 163 'Shutterstock', 164 'upload_files', 165 'shutterstock_media_page', 166 array($this, 'create_media_page') 167 ); 168 } 169 170 public function create_media_page() { 171 include( plugin_dir_path( __FILE__ ) . "partials/{$this->shutterstock}-media-shutterstock.php"); 172 } 173 174 public function add_network_admin_settings_page() { 175 add_submenu_page( 176 'settings.php', // Parent element 177 'Shutterstock', // Text in browser title bar 178 'Shutterstock', // Text to be displayed in the menu. 179 'manage_network_options', // Capability 180 "{$this->shutterstock}_network_options_page", // Page slug, will be displayed in URL 181 array( $this, 'create_network_admin_settings_page' ) // Callback function which displays the page 182 ); 183 184 $this->network_settings_init(); 185 } 186 187 public function create_network_admin_settings_page() { 188 $this->shutterstock_options = $this->get_site_option(); 189 190 include( plugin_dir_path( __FILE__ ) . "partials/{$this->shutterstock}-admin-network-settings-page.php" ); 191 } 192 193 public function create_admin_settings_page() { 194 $this->shutterstock_options = $this->get_option(); 195 include( plugin_dir_path( __FILE__ ) . "partials/{$this->shutterstock}-admin-settings-page.php"); 196 } 197 198 /** 199 * Register settings for network admins for section of shutterstock settings page 200 * 201 * @since 1.0.0 202 */ 203 public function network_settings_init() { 204 register_setting( 205 'shutterstock_network_option_group', 206 'shutterstock_option_name', 207 array($this, 'sanitize_fields') 208 ); 209 210 add_settings_section( 211 'shutterstock_setting_section', // id 212 '', // title 213 array( $this, 'shutterstock_section_info' ), // callback 214 'shutterstock_network_options_page' // page 215 ); 216 217 $this->register_fields("shutterstock_network_options_page"); 218 } 219 220 221 /** 222 * Register settings for admin_init action 223 * 224 * @since 1.0.0 225 */ 226 public function settings_init() { 227 register_setting( 228 'shutterstock_option_group', // option_group 229 'shutterstock_option_name', // option_name 230 array( $this, 'sanitize_fields' ) // sanitize_callback 231 ); 232 233 add_settings_section( 234 'shutterstock_setting_section', // id 235 '', // title 236 array( $this, 'shutterstock_section_info' ), // callback 237 'shutterstock-admin' // page 238 ); 239 240 $this->register_fields('shutterstock-admin'); 241 } 242 243 /** 244 * Register fields for section of shutterstock settings page 245 * 246 * @since 1.0.0 247 */ 248 public function register_fields($page) { 249 add_settings_field( 250 'api_key', // id 251 __('wordpress:text_api_key', 'shutterstock'), // title 252 array( $this, 'field_text' ), // callback 253 $page, // page 254 'shutterstock_setting_section', // section 255 array( 256 'id' => 'api_key', 257 'description' => __('wordpress:text_api_key_description', 'shutterstock'), 258 ) 259 ); 23 class Shutterstock_Admin 24 { 25 26 /** 27 * The ID of this plugin. 28 * 29 * @since 1.0.0 30 * @access private 31 * @var string $shutterstock The ID of this plugin. 32 */ 33 private $shutterstock; 34 35 /** 36 * The version of this plugin. 37 * 38 * @since 1.0.0 39 * @access private 40 * @var string $version The current version of this plugin. 41 */ 42 private $version; 43 44 private $shutterstock_options; 45 46 /** 47 * Initialize the class and set its properties. 48 * 49 * @param string $shutterstock The name of this plugin. 50 * @param string $version The version of this plugin. 51 * @since 1.0.0 52 */ 53 public function __construct($shutterstock, $version, $shutterstock_ui) 54 { 55 56 $this->shutterstock = $shutterstock; 57 $this->version = $version; 58 $this->shutterstock_ui = $shutterstock_ui; 59 } 60 61 /** 62 * Register the stylesheets for the admin area. 63 * 64 * @since 1.0.0 65 */ 66 public function enqueue_styles() 67 { 68 69 /** 70 * This function is provided for demonstration purposes only. 71 * 72 * An instance of this class should be passed to the run() function 73 * defined in Shutterstock_Loader as all of the hooks are defined 74 * in that particular class. 75 * 76 * The Shutterstock_Loader will then create the relationship 77 * between the defined hooks and the functions defined in this 78 * class. 79 */ 80 wp_enqueue_style($this->shutterstock, plugin_dir_url(__FILE__) . 'css/shutterstock-admin.css', array(), $this->version, 'all'); 81 82 } 83 84 /** 85 * Register the JavaScript for the admin area. 86 * 87 * @since 1.0.0 88 */ 89 public function enqueue_scripts($hook) 90 { 91 92 /** 93 * This function is provided for demonstration purposes only. 94 * 95 * An instance of this class should be passed to the run() function 96 * defined in Shutterstock_Loader as all of the hooks are defined 97 * in that particular class. 98 * 99 * The Shutterstock_Loader will then create the relationship 100 * between the defined hooks and the functions defined in this 101 * class. 102 */ 103 104 wp_enqueue_script($this->shutterstock, plugin_dir_url(__FILE__) . 'js/shutterstock-admin.js', array('jquery'), $this->version, false); 105 106 if ('media_page_shutterstock_media_page' === $hook) { 107 $this->load_scripts_for_media_page(); 108 } 109 } 110 111 public function load_scripts_for_media_page() 112 { 113 wp_register_style('shutterstock-media-page-shutterstock-ui-css', $this->shutterstock_ui['css']); 114 wp_enqueue_style('shutterstock-media-page-shutterstock-ui-css'); 115 wp_register_script('shutterstock-media-page-shuttestock-ui-js', $this->shutterstock_ui['js']); 116 wp_enqueue_script('shutterstock-media-page-shuttestock-ui-js'); 117 118 $dir = dirname(__FILE__); 119 120 $script_asset_path = "$dir/shutterstock-media-page/index.asset.php"; 121 122 if (!file_exists($script_asset_path)) { 123 throw new Error( 124 'You need to run `npm start:shutterstock:mediapage` or `npm run build:shutterstock:mediapage` for the "shutterstock/public/shutterstock-block" block first.' 125 ); 126 } 127 128 129 // Registering the shutterstock-media-page script 130 $index_js = 'shutterstock-media-page/index.js'; 131 $script_asset = require(dirname(__FILE__) . '/shutterstock-media-page/index.asset.php'); 132 133 // Registering the shutterstock-media-page styles 134 $index_css = 'shutterstock-media-page/index.css'; 135 136 wp_register_style('shutterstock-media-page-styles', plugins_url($index_css, __FILE__)); 137 138 wp_register_script( 139 'shutterstock-media-page', 140 plugins_url($index_js, __FILE__), 141 $script_asset['dependencies'], 142 $script_asset['version'] 143 ); 144 145 $loaded = wp_set_script_translations('shutterstock-media-page', 'shutterstock', plugin_dir_path(__DIR__) . 'languages/'); 146 147 wp_enqueue_script('shutterstock-media-page'); 148 wp_enqueue_style('shutterstock-media-page-styles'); 149 150 $shutterstock_helper = new Shutterstock_Helper($this->shutterstock, $this->version); 151 $shutterstock_js_object = $shutterstock_helper->get_shutterstock_js_object(); 152 153 wp_localize_script('shutterstock-media-page-shuttestock-ui-js', 'shutterstock', $shutterstock_js_object); 154 } 155 156 public function add_admin_settings_page() 157 { 158 add_options_page( 159 'Shutterstock', // page_title 160 'Shutterstock', // menu_title 161 'manage_options', // capability 162 "{$this->shutterstock}_options_page", // menu_slug 163 array($this, 'create_admin_settings_page') // function 164 ); 165 166 add_submenu_page( 167 'upload.php', 168 'Shutterstock', 169 'Shutterstock', 170 'upload_files', 171 'shutterstock_media_page', 172 array($this, 'create_media_page') 173 ); 174 } 175 176 public function create_media_page() 177 { 178 include(plugin_dir_path(__FILE__) . "partials/{$this->shutterstock}-media-shutterstock.php"); 179 } 180 181 public function add_network_admin_settings_page() 182 { 183 add_submenu_page( 184 'settings.php', // Parent element 185 'Shutterstock', // Text in browser title bar 186 'Shutterstock', // Text to be displayed in the menu. 187 'manage_network_options', // Capability 188 "{$this->shutterstock}_network_options_page", // Page slug, will be displayed in URL 189 array($this, 'create_network_admin_settings_page') // Callback function which displays the page 190 ); 191 192 $this->network_settings_init(); 193 } 194 195 public function create_network_admin_settings_page() 196 { 197 $this->shutterstock_options = $this->get_site_option(); 198 199 include(plugin_dir_path(__FILE__) . "partials/{$this->shutterstock}-admin-network-settings-page.php"); 200 } 201 202 public function create_admin_settings_page() 203 { 204 $this->shutterstock_options = $this->get_option(); 205 include(plugin_dir_path(__FILE__) . "partials/{$this->shutterstock}-admin-settings-page.php"); 206 } 207 208 /** 209 * Register settings for network admins for section of shutterstock settings page 210 * 211 * @since 1.0.0 212 */ 213 public function network_settings_init() 214 { 215 register_setting( 216 'shutterstock_network_option_group', 217 'shutterstock_option_name', 218 array($this, 'sanitize_fields') 219 ); 220 221 add_settings_section( 222 'shutterstock_setting_section', // id 223 '', // title 224 array($this, 'shutterstock_section_info'), // callback 225 'shutterstock_network_options_page' // page 226 ); 227 228 $this->register_fields("shutterstock_network_options_page"); 229 } 230 231 232 /** 233 * Register settings for admin_init action 234 * 235 * @since 1.0.0 236 */ 237 public function settings_init() 238 { 239 register_setting( 240 'shutterstock_option_group', // option_group 241 'shutterstock_option_name', // option_name 242 array($this, 'sanitize_fields') // sanitize_callback 243 ); 244 245 add_settings_section( 246 'shutterstock_setting_section', // id 247 '', // title 248 array($this, 'shutterstock_section_info'), // callback 249 'shutterstock-admin' // page 250 ); 251 252 $this->register_fields('shutterstock-admin'); 253 } 254 255 /** 256 * Register fields for section of shutterstock settings page 257 * 258 * @since 1.0.0 259 */ 260 public function register_fields($page) 261 { 262 add_settings_field( 263 'api_key', // id 264 __('wordpress:text_api_key', 'shutterstock'), // title 265 array($this, 'field_text'), // callback 266 $page, // page 267 'shutterstock_setting_section', // section 268 array( 269 'id' => 'api_key', 270 'description' => __('wordpress:text_api_key_description', 'shutterstock'), 271 ) 272 ); 260 273 261 274 add_settings_field( 262 275 'api_secret', // id 263 276 __('wordpress:text_api_secret', 'shutterstock'), // title 264 array( $this, 'field_text'), // callback277 array($this, 'field_text'), // callback 265 278 $page, // page 266 279 'shutterstock_setting_section', // section … … 271 284 ); 272 285 273 $nonce = wp_create_nonce('generate-token'); 274 275 $network_admin = is_network_admin(); 276 277 $redirect_uri = $network_admin ? 278 network_admin_url('edit.php?action=shutterstock_network_generate_access_token&_wpnonce='.$nonce) : 279 admin_url('admin.php?action=shutterstock_generate_access_token&_wpnonce='.$nonce); 280 281 $post_location = $network_admin ? 282 'edit.php?action=shutterstock_network_update_options' : 283 'options.php'; 286 $nonce = wp_create_nonce('generate-token'); 287 288 $network_admin = is_network_admin(); 289 290 $redirect_uri = $network_admin ? 291 network_admin_url('edit.php?action=shutterstock_network_generate_access_token&_wpnonce=' . $nonce) : 292 admin_url('admin.php?action=shutterstock_generate_access_token&_wpnonce=' . $nonce); 293 294 // network settings page: 295 // network/settings.php?page=shutterstock_network_options_page 296 297 $post_location = $network_admin ? 298 'edit.php?action=shutterstock_network_update_options' : 299 'options.php'; 284 300 285 301 286 302 $redirect_query_params = http_build_query(array( 287 303 'state' => gmdate(DATE_ATOM), 288 'redirect_uri' => $redirect_uri,304 'redirect_uri' => $redirect_uri, 289 305 'client_id' => 'CLIENT_ID', 290 306 'scope' => 'licenses.create licenses.view purchases.view user.view' … … 311 327 'postLocation' => $post_location, 312 328 'has_value_button_text' => __('wordpress:text_logout', 'shutterstock'), 313 'no_value_button_text' => __('wordpress:text_log_in_with_shutterstock', 'shutterstock'),314 'description' => __('wordpress:text_app_token_description', 'shutterstock'),329 'no_value_button_text' => __('wordpress:text_log_in_with_shutterstock', 'shutterstock'), 330 'description' => __('wordpress:text_app_token_description', 'shutterstock'), 315 331 ], 316 332 ) 317 333 ); 318 334 319 add_settings_field( 320 'editorial_country', // id 321 __('wordpress:text_editorial_country', 'shutterstock'), // title 322 array( $this, 'field_text' ), // callback 323 $page, // page 324 'shutterstock_setting_section', // section 325 array( 326 'id' => 'editorial_country', 327 'description' => __('wordpress:text_editorial_country_description', 'shutterstock'), 328 ) 329 ); 330 331 add_settings_field( 332 'user_settings', // id 333 __('wordpress:text_user_settings', 'shutterstock'), // title 334 array( $this, 'field_user_settings' ), // callback 335 $page, // page 336 'shutterstock_setting_section', // section 337 array( 338 'id' => 'user_settings', 339 'description' => __('wordpress:text_user_settings_description', 'shutterstock'), 340 ) 341 ); 342 343 } 344 345 public function sanitize_fields($input) { 346 $sanitary_values = array(); 347 if ( isset( $input['api_key'] ) ) { 348 $sanitary_values['api_key'] = sanitize_text_field( $input['api_key'] ); 349 } 350 351 if ( isset( $input['api_secret'] ) ) { 352 $sanitary_values['api_secret'] = sanitize_text_field( $input['api_secret'] ); 353 } 354 355 if ( isset( $input['editorial_country'] ) ) { 356 $sanitary_values['editorial_country'] = sanitize_text_field( $input['editorial_country'] ); 357 } 358 359 if ( isset( $input['app_token'] ) ) { 360 $sanitary_values['app_token'] = esc_textarea( $input['app_token'] ); 361 } 362 363 if (isset( $input['user_settings'])) { 364 $sanitary_values['user_settings'] = $input['user_settings']; 365 $sanitary_values['user_settings'] = array(); 366 367 if ( is_array( $input['user_settings'] ) ) { 368 foreach($input['user_settings'] as $user_type => $user_capabilities) { 369 $sanitary_values['user_settings'][$user_type] = array_map( 'sanitize_text_field', wp_unslash( $user_capabilities) ); 370 } 371 } 372 } 373 374 return $sanitary_values; 375 } 376 377 public function shutterstock_section_info() { 378 379 } 380 381 /** 382 * Creates a text field 383 * 384 * @param array $args The arguments for the field 385 * @return string The HTML field 386 */ 387 public function field_text( $args ) { 388 $defaults = []; 389 $defaults['class'] = 'regular-text'; 390 $defaults['description'] = ''; 391 $defaults['label'] = ''; 392 $defaults['name'] = "{$this->shutterstock}_option_name[{$args['id']}]"; 393 $defaults['placeholder'] = ''; 394 $defaults['type'] = 'text'; 395 $defaults['value'] = ''; 396 397 $atts = wp_parse_args( $args, $defaults ); 398 if ( ! empty( $this->shutterstock_options[$atts['id']] ) ) { 399 400 $atts['value'] = $this->shutterstock_options[$atts['id']]; 401 402 } 403 404 include( plugin_dir_path( __FILE__ ) . "partials/{$this->shutterstock}-admin-field-text.php" ); 405 406 } 407 408 /** 409 * Creates a textarea field 410 * 411 * @param array $args The arguments for the field 412 * @return string The HTML field 413 */ 414 public function field_textarea( $args ) { 415 $defaults = []; 416 $defaults['class'] = ''; 417 $defaults['cols'] = 100; 418 $defaults['context'] = ''; 419 $defaults['description'] = ''; 420 $defaults['label'] = ''; 421 $defaults['name'] = "{$this->shutterstock}_option_name[{$args['id']}]"; 422 $defaults['rows'] = 6; 423 $defaults['value'] = ''; 424 425 $atts = wp_parse_args( $args, $defaults ); 426 427 if ( ! empty( $this->shutterstock_options[$atts['id']] ) ) { 428 429 $atts['value'] = $this->shutterstock_options[$atts['id']]; 430 431 } 432 433 include( plugin_dir_path( __FILE__ ) . "partials/{$this->shutterstock}-admin-field-textarea.php" ); 434 435 } 335 add_settings_field( 336 'editorial_country', // id 337 __('wordpress:text_editorial_country', 'shutterstock'), // title 338 array($this, 'field_text'), // callback 339 $page, // page 340 'shutterstock_setting_section', // section 341 array( 342 'id' => 'editorial_country', 343 'description' => __('wordpress:text_editorial_country_description', 'shutterstock'), 344 ) 345 ); 346 347 add_settings_field( 348 'user_settings', // id 349 __('wordpress:text_user_settings', 'shutterstock'), // title 350 array($this, 'field_user_settings'), // callback 351 $page, // page 352 'shutterstock_setting_section', // section 353 array( 354 'id' => 'user_settings', 355 'description' => __('wordpress:text_user_settings_description', 'shutterstock'), 356 ) 357 ); 358 359 } 360 361 public function sanitize_fields($input) 362 { 363 $sanitary_values = array(); 364 if (isset($input['api_key'])) { 365 $sanitary_values['api_key'] = sanitize_text_field($input['api_key']); 366 } 367 368 if (isset($input['api_secret'])) { 369 $sanitary_values['api_secret'] = sanitize_text_field($input['api_secret']); 370 } 371 372 if (isset($input['editorial_country'])) { 373 $sanitary_values['editorial_country'] = sanitize_text_field($input['editorial_country']); 374 } 375 376 if (isset($input['app_token'])) { 377 $sanitary_values['app_token'] = esc_textarea($input['app_token']); 378 } 379 380 if (isset($input['user_settings'])) { 381 $sanitary_values['user_settings'] = $input['user_settings']; 382 $sanitary_values['user_settings'] = array(); 383 384 if (is_array($input['user_settings'])) { 385 foreach ($input['user_settings'] as $user_type => $user_capabilities) { 386 $sanitary_values['user_settings'][$user_type] = array_map('sanitize_text_field', wp_unslash($user_capabilities)); 387 } 388 } 389 } 390 391 return $sanitary_values; 392 } 393 394 public function shutterstock_section_info() 395 { 396 397 } 398 399 /** 400 * Creates a text field 401 * 402 * @param array $args The arguments for the field 403 * @return string The HTML field 404 */ 405 public function field_text($args) 406 { 407 $defaults = []; 408 $defaults['class'] = 'regular-text'; 409 $defaults['description'] = ''; 410 $defaults['label'] = ''; 411 $defaults['name'] = "{$this->shutterstock}_option_name[{$args['id']}]"; 412 $defaults['placeholder'] = ''; 413 $defaults['type'] = 'text'; 414 $defaults['value'] = ''; 415 416 $atts = wp_parse_args($args, $defaults); 417 if (!empty($this->shutterstock_options[$atts['id']])) { 418 419 $atts['value'] = $this->shutterstock_options[$atts['id']]; 420 421 } 422 423 include(plugin_dir_path(__FILE__) . "partials/{$this->shutterstock}-admin-field-text.php"); 424 425 } 426 427 /** 428 * Creates a textarea field 429 * 430 * @param array $args The arguments for the field 431 * @return string The HTML field 432 */ 433 public function field_textarea($args) 434 { 435 $defaults = []; 436 $defaults['class'] = ''; 437 $defaults['cols'] = 100; 438 $defaults['context'] = ''; 439 $defaults['description'] = ''; 440 $defaults['label'] = ''; 441 $defaults['name'] = "{$this->shutterstock}_option_name[{$args['id']}]"; 442 $defaults['rows'] = 6; 443 $defaults['value'] = ''; 444 445 $atts = wp_parse_args($args, $defaults); 446 447 if (!empty($this->shutterstock_options[$atts['id']])) { 448 449 $atts['value'] = $this->shutterstock_options[$atts['id']]; 450 451 } 452 453 include(plugin_dir_path(__FILE__) . "partials/{$this->shutterstock}-admin-field-textarea.php"); 454 455 } 436 456 437 457 /** 438 458 * Creates a button field 439 459 * 440 * @param array $args The arguments for the field 441 * @return string The HTML field 442 */ 443 public function field_button( $args ) { 460 * @param array $args The arguments for the field 461 * @return string The HTML field 462 */ 463 public function field_button($args) 464 { 444 465 445 466 $defaults = []; 446 $defaults['context'] = '';447 $defaults['value'] = '';448 $defaults['name'] = "{$this->shutterstock}_option_name[{$args['id']}]";449 450 $atts = wp_parse_args( $args, $defaults);451 452 if ( ! empty( $this->shutterstock_options[$atts['id']] )) {467 $defaults['context'] = ''; 468 $defaults['value'] = ''; 469 $defaults['name'] = "{$this->shutterstock}_option_name[{$args['id']}]"; 470 471 $atts = wp_parse_args($args, $defaults); 472 473 if (!empty($this->shutterstock_options[$atts['id']])) { 453 474 454 475 $atts['value'] = $this->shutterstock_options[$atts['id']]; … … 456 477 } 457 478 458 include( plugin_dir_path( __FILE__ ) . "partials/{$this->shutterstock}-admin-field-shutterstock-login-button.php" ); 459 460 } 461 462 public function field_user_settings($args) { 463 $wp_roles = wp_roles(); 464 $role_names = $wp_roles->role_names; 465 $atts = []; 466 $atts['role_names'] = $role_names; 467 $atts['description'] = $args['description']; 468 469 if (isset($this->shutterstock_options[$args['id']])) { 470 $atts['user_settings'] = $this->shutterstock_options[$args['id']]; 471 } 472 473 include( plugin_dir_path( __FILE__ ) . "partials/{$this->shutterstock}-admin-field-user-settings.php" ); 474 475 } 476 477 /** 478 * This function here is hooked up to a special action and necessary to process 479 * the saving of the options. This is the big difference with a normal options 480 * page. 481 */ 482 public function shutterstock_network_update_options() { 483 // Make sure we are posting from our options page. There's a little surprise 484 // here, on the options page we used the 'shutterstock_network_option_group' 485 // slug when calling 'settings_fields' but we must add the '-options' postfix 486 // when we check the referer. 487 check_admin_referer( 'shutterstock_network_option_group-options' ); // Nonce security check 488 489 // This is the list of registered options. 490 global $new_whitelist_options; 491 492 $options = $new_whitelist_options['shutterstock_network_option_group']; 493 494 // Go through the posted data and save only our options. 495 foreach ($options as $option) { 496 if (isset($_POST[$option])) { 497 $api_key = isset( $_POST[$option]['api_key'] ) ? sanitize_text_field($_POST[$option]['api_key']) : ''; 498 $api_secret = isset( $_POST[$option]['api_secret'] ) ? sanitize_text_field($_POST[$option]['api_secret']) : ''; 499 $app_token = isset( $_POST[$option]['app_token'] ) ? sanitize_textarea_field($_POST[$option]['app_token']) : ''; 500 $editorial_country = isset( $_POST[$option]['editorial_country'] ) ? sanitize_text_field($_POST[$option]['editorial_country']) : ''; 501 $user_settings = []; 502 503 if (isset($_POST[$option]['user_settings'])) { 504 $wp_roles = wp_roles(); 505 $role_names = $wp_roles->role_names; 506 $roles_slugs = array_keys($role_names); 507 508 foreach($roles_slugs as $role_slug) { 509 if (isset($_POST[$option]['user_settings'][$role_slug])) { 510 $user_settings[$role_slug] = array_map( 'sanitize_text_field', wp_unslash( $_POST[$option]['user_settings'][$role_slug] ) ); 511 } 512 } 513 } 514 515 update_site_option($option, array( 516 'api_key' => $api_key, 517 'api_secret' => $api_secret, 518 'app_token' => $app_token, 519 'user_settings' => $user_settings, 520 'editorial_country' => $editorial_country, 521 )); 522 } 523 } 524 525 $wp_nonce = wp_create_nonce('shutterstock-network-settings-updated'); 526 // At last we redirect back to our options page. 527 wp_redirect(add_query_arg(array('page' => 'shutterstock_network_options_page', 528 'updated' => $wp_nonce, ), network_admin_url('settings.php'))); 529 exit; 530 } 531 532 public function shutterstock_generate_access_token() { 533 $nonce = isset($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']): ''; 534 535 if (!wp_verify_nonce( $nonce, 'generate-token')) { 536 die( esc_html_e('Security error.') ); 537 } else { 538 $code = isset($_REQUEST['code']) ? sanitize_text_field($_REQUEST['code']) : ''; 539 540 if ($code) { 541 $option = is_network_admin() ? $this->get_site_option() : $this->get_option(); 542 $token = $this->post_token($code, $option['api_key'], $option['api_secret']); 543 544 $option['app_token'] = $token; 545 546 if (is_network_admin()) { 547 update_site_option("{$this->shutterstock}_option_name", $option); 548 $wp_nonce = wp_create_nonce('shutterstock-network-settings-updated'); 549 // At last we redirect back to our options page. 550 wp_redirect(add_query_arg(array('page' => 'shutterstock_network_options_page', 551 'updated' => $wp_nonce, ), network_admin_url('settings.php'))); 552 exit; 553 } else { 554 update_option("{$this->shutterstock}_option_name", $option); 555 $wp_nonce = wp_create_nonce('shutterstock-setting-updated'); 556 // At last we redirect back to our options page. 557 wp_redirect(add_query_arg(array('page' => 'shutterstock_options_page', 558 'updated' => $wp_nonce, ), admin_url('options-general.php'))); 559 exit; 560 } 561 } 562 } 563 } 564 565 private function get_option() { 566 return get_option("{$this->shutterstock}_option_name"); 567 } 568 569 private function get_site_option() { 570 return get_site_option("{$this->shutterstock}_option_name"); 571 } 572 573 private function post_token($code, $key, $secret) { 479 include(plugin_dir_path(__FILE__) . "partials/{$this->shutterstock}-admin-field-shutterstock-login-button.php"); 480 481 } 482 483 public function field_user_settings($args) 484 { 485 $wp_roles = wp_roles(); 486 $role_names = $wp_roles->role_names; 487 $atts = []; 488 $atts['role_names'] = $role_names; 489 $atts['description'] = $args['description']; 490 491 if (isset($this->shutterstock_options[$args['id']])) { 492 $atts['user_settings'] = $this->shutterstock_options[$args['id']]; 493 } 494 495 include(plugin_dir_path(__FILE__) . "partials/{$this->shutterstock}-admin-field-user-settings.php"); 496 497 } 498 499 /** 500 * This function here is hooked up to a special action and necessary to process 501 * the saving of the options. This is the big difference with a normal options 502 * page. 503 */ 504 public function shutterstock_network_update_options() 505 { 506 // Make sure we are posting from our options page. There's a little surprise 507 // here, on the options page we used the 'shutterstock_network_option_group' 508 // slug when calling 'settings_fields' but we must add the '-options' postfix 509 // when we check the referer. 510 check_admin_referer('shutterstock_network_option_group-options'); // Nonce security check 511 512 // This is the list of registered options. 513 global $new_whitelist_options; 514 515 $options = $new_whitelist_options['shutterstock_network_option_group']; 516 517 // Go through the posted data and save only our options. 518 foreach ($options as $option) { 519 if (isset($_POST[$option])) { 520 $api_key = isset($_POST[$option]['api_key']) ? sanitize_text_field($_POST[$option]['api_key']) : ''; 521 $api_secret = isset($_POST[$option]['api_secret']) ? sanitize_text_field($_POST[$option]['api_secret']) : ''; 522 $app_token = isset($_POST[$option]['app_token']) ? sanitize_textarea_field($_POST[$option]['app_token']) : ''; 523 $editorial_country = isset($_POST[$option]['editorial_country']) ? sanitize_text_field($_POST[$option]['editorial_country']) : ''; 524 $user_settings = []; 525 526 if (isset($_POST[$option]['user_settings'])) { 527 $wp_roles = wp_roles(); 528 $role_names = $wp_roles->role_names; 529 $roles_slugs = array_keys($role_names); 530 531 foreach ($roles_slugs as $role_slug) { 532 if (isset($_POST[$option]['user_settings'][$role_slug])) { 533 $user_settings[$role_slug] = array_map('sanitize_text_field', wp_unslash($_POST[$option]['user_settings'][$role_slug])); 534 } 535 } 536 } 537 538 update_site_option($option, array( 539 'api_key' => $api_key, 540 'api_secret' => $api_secret, 541 'app_token' => $app_token, 542 'user_settings' => $user_settings, 543 'editorial_country' => $editorial_country, 544 )); 545 } 546 } 547 548 $wp_nonce = wp_create_nonce('shutterstock-network-settings-updated'); 549 // At last we redirect back to our options page. 550 wp_redirect(add_query_arg(array('page' => 'shutterstock_network_options_page', 551 'updated' => $wp_nonce,), network_admin_url('settings.php'))); 552 exit; 553 } 554 555 public function shutterstock_generate_access_token() 556 { 557 $nonce = isset($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; 558 559 if (!wp_verify_nonce($nonce, 'generate-token')) { 560 die(esc_html_e('Security error.')); 561 } else { 562 $code = isset($_REQUEST['code']) ? sanitize_text_field($_REQUEST['code']) : ''; 563 564 if ($code) { 565 $option = is_network_admin() ? $this->get_site_option() : $this->get_option(); 566 $token = $this->post_token($code, $option['api_key'], $option['api_secret']); 567 568 $option['app_token'] = $token; 569 570 if (is_network_admin()) { 571 update_site_option("{$this->shutterstock}_option_name", $option); 572 $wp_nonce = wp_create_nonce('shutterstock-network-settings-updated'); 573 // At last we redirect back to our options page. 574 wp_redirect(add_query_arg(array('page' => 'shutterstock_network_options_page', 575 'updated' => $wp_nonce,), network_admin_url('settings.php'))); 576 exit; 577 } else { 578 update_option("{$this->shutterstock}_option_name", $option); 579 $wp_nonce = wp_create_nonce('shutterstock-setting-updated'); 580 // At last we redirect back to our options page. 581 wp_redirect(add_query_arg(array('page' => 'shutterstock_options_page', 582 'updated' => $wp_nonce,), admin_url('options-general.php'))); 583 exit; 584 } 585 } 586 } 587 } 588 589 private function get_option() 590 { 591 return get_option("{$this->shutterstock}_option_name"); 592 } 593 594 private function get_site_option() 595 { 596 return get_site_option("{$this->shutterstock}_option_name"); 597 } 598 599 private function post_token($code, $key, $secret) 600 { 574 601 $token_url = 'https://api.shutterstock.com/v2/oauth/access_token'; 575 602 … … 584 611 'headers' => [ 585 612 'Content-Type' => 'application/json', 586 'x-shutterstock-application' => 'Wordpress/' . $this->version,613 'x-shutterstock-application' => 'Wordpress/' . $this->version, 587 614 ], 588 615 'body' => wp_json_encode($body), … … 596 623 597 624 return $decoded_body['access_token']; 598 }625 } 599 626 } -
shutterstock/tags/1.3.9/includes/class-shutterstock.php
r2661410 r2670796 71 71 $this->version = SHUTTERSTOCK_VERSION; 72 72 } else { 73 $this->version = '1.3. 8';73 $this->version = '1.3.9'; 74 74 } 75 75 $this->shutterstock = 'shutterstock'; -
shutterstock/tags/1.3.9/shutterstock.php
r2661410 r2670796 16 16 * Plugin Name: Shutterstock 17 17 * Description: Access exceptional, royalty-free content straight from WordPress. 18 * Version: 1.3. 818 * Version: 1.3.9 19 19 * Author: Shutterstock 20 20 * License: MIT … … 34 34 * Rename this for your plugin and update it as you release new versions. 35 35 */ 36 define( 'SHUTTERSTOCK_VERSION', '1.3. 8' );36 define( 'SHUTTERSTOCK_VERSION', '1.3.9' ); 37 37 38 38 /** -
shutterstock/trunk/README.txt
r2661410 r2670796 3 3 Tags: shutterstock, stock photography, images, editorial images, licensing, media library, stock 4 4 Requires at least: 5.5 5 Tested up to: 5. 86 Stable tag: 1.3. 85 Tested up to: 5.9 6 Stable tag: 1.3.9 7 7 Requires PHP: 7.1 8 8 License: MIT … … 112 112 113 113 == Changelog == 114 = 1.3.9 = 115 * Update to support Wordpress 5.9 116 114 117 = 1.3.8 = 115 118 * * Bug fixes related to PHP warnings -
shutterstock/trunk/admin/class-shutterstock-admin.php
r2466651 r2670796 21 21 * @author Shutterstock <api@shutterstock.com> 22 22 */ 23 class Shutterstock_Admin { 24 25 /** 26 * The ID of this plugin. 27 * 28 * @since 1.0.0 29 * @access private 30 * @var string $shutterstock The ID of this plugin. 31 */ 32 private $shutterstock; 33 34 /** 35 * The version of this plugin. 36 * 37 * @since 1.0.0 38 * @access private 39 * @var string $version The current version of this plugin. 40 */ 41 private $version; 42 43 private $shutterstock_options; 44 45 /** 46 * Initialize the class and set its properties. 47 * 48 * @since 1.0.0 49 * @param string $shutterstock The name of this plugin. 50 * @param string $version The version of this plugin. 51 */ 52 public function __construct( $shutterstock, $version, $shutterstock_ui ) { 53 54 $this->shutterstock = $shutterstock; 55 $this->version = $version; 56 $this->shutterstock_ui = $shutterstock_ui; 57 } 58 59 /** 60 * Register the stylesheets for the admin area. 61 * 62 * @since 1.0.0 63 */ 64 public function enqueue_styles() { 65 66 /** 67 * This function is provided for demonstration purposes only. 68 * 69 * An instance of this class should be passed to the run() function 70 * defined in Shutterstock_Loader as all of the hooks are defined 71 * in that particular class. 72 * 73 * The Shutterstock_Loader will then create the relationship 74 * between the defined hooks and the functions defined in this 75 * class. 76 */ 77 wp_enqueue_style( $this->shutterstock, plugin_dir_url( __FILE__ ) . 'css/shutterstock-admin.css', array(), $this->version, 'all' ); 78 79 } 80 81 /** 82 * Register the JavaScript for the admin area. 83 * 84 * @since 1.0.0 85 */ 86 public function enqueue_scripts($hook) { 87 88 /** 89 * This function is provided for demonstration purposes only. 90 * 91 * An instance of this class should be passed to the run() function 92 * defined in Shutterstock_Loader as all of the hooks are defined 93 * in that particular class. 94 * 95 * The Shutterstock_Loader will then create the relationship 96 * between the defined hooks and the functions defined in this 97 * class. 98 */ 99 100 wp_enqueue_script( $this->shutterstock, plugin_dir_url( __FILE__ ) . 'js/shutterstock-admin.js', array( 'jquery' ), $this->version, false ); 101 102 if ('media_page_shutterstock_media_page' === $hook) { 103 $this->load_scripts_for_media_page(); 104 } 105 } 106 107 public function load_scripts_for_media_page() { 108 wp_register_style('shutterstock-media-page-shutterstock-ui-css', $this->shutterstock_ui['css']); 109 wp_enqueue_style( 'shutterstock-media-page-shutterstock-ui-css'); 110 wp_register_script('shutterstock-media-page-shuttestock-ui-js', $this->shutterstock_ui['js']); 111 wp_enqueue_script( 'shutterstock-media-page-shuttestock-ui-js'); 112 113 $dir = dirname( __FILE__ ); 114 115 $script_asset_path = "$dir/shutterstock-media-page/index.asset.php"; 116 117 if ( ! file_exists( $script_asset_path ) ) { 118 throw new Error( 119 'You need to run `npm start:shutterstock:mediapage` or `npm run build:shutterstock:mediapage` for the "shutterstock/public/shutterstock-block" block first.' 120 ); 121 } 122 123 124 // Registering the shutterstock-media-page script 125 $index_js = 'shutterstock-media-page/index.js'; 126 $script_asset = require(dirname( __FILE__ ) . '/shutterstock-media-page/index.asset.php' ); 127 128 // Registering the shutterstock-media-page styles 129 $index_css = 'shutterstock-media-page/index.css'; 130 131 wp_register_style('shutterstock-media-page-styles', plugins_url( $index_css, __FILE__ )); 132 133 wp_register_script( 134 'shutterstock-media-page', 135 plugins_url( $index_js, __FILE__ ), 136 $script_asset['dependencies'], 137 $script_asset['version'] 138 ); 139 140 $loaded = wp_set_script_translations( 'shutterstock-media-page', 'shutterstock', plugin_dir_path(__DIR__) . 'languages/'); 141 142 wp_enqueue_script('shutterstock-media-page'); 143 wp_enqueue_style( 'shutterstock-media-page-styles'); 144 145 $shutterstock_helper = new Shutterstock_Helper($this->shutterstock, $this->version); 146 $shutterstock_js_object = $shutterstock_helper->get_shutterstock_js_object(); 147 148 wp_localize_script('shutterstock-media-page-shuttestock-ui-js', 'shutterstock', $shutterstock_js_object ); 149 } 150 151 public function add_admin_settings_page() { 152 add_options_page( 153 'Shutterstock', // page_title 154 'Shutterstock', // menu_title 155 'manage_options', // capability 156 "{$this->shutterstock}_options_page", // menu_slug 157 array( $this, 'create_admin_settings_page') // function 158 ); 159 160 add_submenu_page( 161 'upload.php', 162 'Shutterstock', 163 'Shutterstock', 164 'upload_files', 165 'shutterstock_media_page', 166 array($this, 'create_media_page') 167 ); 168 } 169 170 public function create_media_page() { 171 include( plugin_dir_path( __FILE__ ) . "partials/{$this->shutterstock}-media-shutterstock.php"); 172 } 173 174 public function add_network_admin_settings_page() { 175 add_submenu_page( 176 'settings.php', // Parent element 177 'Shutterstock', // Text in browser title bar 178 'Shutterstock', // Text to be displayed in the menu. 179 'manage_network_options', // Capability 180 "{$this->shutterstock}_network_options_page", // Page slug, will be displayed in URL 181 array( $this, 'create_network_admin_settings_page' ) // Callback function which displays the page 182 ); 183 184 $this->network_settings_init(); 185 } 186 187 public function create_network_admin_settings_page() { 188 $this->shutterstock_options = $this->get_site_option(); 189 190 include( plugin_dir_path( __FILE__ ) . "partials/{$this->shutterstock}-admin-network-settings-page.php" ); 191 } 192 193 public function create_admin_settings_page() { 194 $this->shutterstock_options = $this->get_option(); 195 include( plugin_dir_path( __FILE__ ) . "partials/{$this->shutterstock}-admin-settings-page.php"); 196 } 197 198 /** 199 * Register settings for network admins for section of shutterstock settings page 200 * 201 * @since 1.0.0 202 */ 203 public function network_settings_init() { 204 register_setting( 205 'shutterstock_network_option_group', 206 'shutterstock_option_name', 207 array($this, 'sanitize_fields') 208 ); 209 210 add_settings_section( 211 'shutterstock_setting_section', // id 212 '', // title 213 array( $this, 'shutterstock_section_info' ), // callback 214 'shutterstock_network_options_page' // page 215 ); 216 217 $this->register_fields("shutterstock_network_options_page"); 218 } 219 220 221 /** 222 * Register settings for admin_init action 223 * 224 * @since 1.0.0 225 */ 226 public function settings_init() { 227 register_setting( 228 'shutterstock_option_group', // option_group 229 'shutterstock_option_name', // option_name 230 array( $this, 'sanitize_fields' ) // sanitize_callback 231 ); 232 233 add_settings_section( 234 'shutterstock_setting_section', // id 235 '', // title 236 array( $this, 'shutterstock_section_info' ), // callback 237 'shutterstock-admin' // page 238 ); 239 240 $this->register_fields('shutterstock-admin'); 241 } 242 243 /** 244 * Register fields for section of shutterstock settings page 245 * 246 * @since 1.0.0 247 */ 248 public function register_fields($page) { 249 add_settings_field( 250 'api_key', // id 251 __('wordpress:text_api_key', 'shutterstock'), // title 252 array( $this, 'field_text' ), // callback 253 $page, // page 254 'shutterstock_setting_section', // section 255 array( 256 'id' => 'api_key', 257 'description' => __('wordpress:text_api_key_description', 'shutterstock'), 258 ) 259 ); 23 class Shutterstock_Admin 24 { 25 26 /** 27 * The ID of this plugin. 28 * 29 * @since 1.0.0 30 * @access private 31 * @var string $shutterstock The ID of this plugin. 32 */ 33 private $shutterstock; 34 35 /** 36 * The version of this plugin. 37 * 38 * @since 1.0.0 39 * @access private 40 * @var string $version The current version of this plugin. 41 */ 42 private $version; 43 44 private $shutterstock_options; 45 46 /** 47 * Initialize the class and set its properties. 48 * 49 * @param string $shutterstock The name of this plugin. 50 * @param string $version The version of this plugin. 51 * @since 1.0.0 52 */ 53 public function __construct($shutterstock, $version, $shutterstock_ui) 54 { 55 56 $this->shutterstock = $shutterstock; 57 $this->version = $version; 58 $this->shutterstock_ui = $shutterstock_ui; 59 } 60 61 /** 62 * Register the stylesheets for the admin area. 63 * 64 * @since 1.0.0 65 */ 66 public function enqueue_styles() 67 { 68 69 /** 70 * This function is provided for demonstration purposes only. 71 * 72 * An instance of this class should be passed to the run() function 73 * defined in Shutterstock_Loader as all of the hooks are defined 74 * in that particular class. 75 * 76 * The Shutterstock_Loader will then create the relationship 77 * between the defined hooks and the functions defined in this 78 * class. 79 */ 80 wp_enqueue_style($this->shutterstock, plugin_dir_url(__FILE__) . 'css/shutterstock-admin.css', array(), $this->version, 'all'); 81 82 } 83 84 /** 85 * Register the JavaScript for the admin area. 86 * 87 * @since 1.0.0 88 */ 89 public function enqueue_scripts($hook) 90 { 91 92 /** 93 * This function is provided for demonstration purposes only. 94 * 95 * An instance of this class should be passed to the run() function 96 * defined in Shutterstock_Loader as all of the hooks are defined 97 * in that particular class. 98 * 99 * The Shutterstock_Loader will then create the relationship 100 * between the defined hooks and the functions defined in this 101 * class. 102 */ 103 104 wp_enqueue_script($this->shutterstock, plugin_dir_url(__FILE__) . 'js/shutterstock-admin.js', array('jquery'), $this->version, false); 105 106 if ('media_page_shutterstock_media_page' === $hook) { 107 $this->load_scripts_for_media_page(); 108 } 109 } 110 111 public function load_scripts_for_media_page() 112 { 113 wp_register_style('shutterstock-media-page-shutterstock-ui-css', $this->shutterstock_ui['css']); 114 wp_enqueue_style('shutterstock-media-page-shutterstock-ui-css'); 115 wp_register_script('shutterstock-media-page-shuttestock-ui-js', $this->shutterstock_ui['js']); 116 wp_enqueue_script('shutterstock-media-page-shuttestock-ui-js'); 117 118 $dir = dirname(__FILE__); 119 120 $script_asset_path = "$dir/shutterstock-media-page/index.asset.php"; 121 122 if (!file_exists($script_asset_path)) { 123 throw new Error( 124 'You need to run `npm start:shutterstock:mediapage` or `npm run build:shutterstock:mediapage` for the "shutterstock/public/shutterstock-block" block first.' 125 ); 126 } 127 128 129 // Registering the shutterstock-media-page script 130 $index_js = 'shutterstock-media-page/index.js'; 131 $script_asset = require(dirname(__FILE__) . '/shutterstock-media-page/index.asset.php'); 132 133 // Registering the shutterstock-media-page styles 134 $index_css = 'shutterstock-media-page/index.css'; 135 136 wp_register_style('shutterstock-media-page-styles', plugins_url($index_css, __FILE__)); 137 138 wp_register_script( 139 'shutterstock-media-page', 140 plugins_url($index_js, __FILE__), 141 $script_asset['dependencies'], 142 $script_asset['version'] 143 ); 144 145 $loaded = wp_set_script_translations('shutterstock-media-page', 'shutterstock', plugin_dir_path(__DIR__) . 'languages/'); 146 147 wp_enqueue_script('shutterstock-media-page'); 148 wp_enqueue_style('shutterstock-media-page-styles'); 149 150 $shutterstock_helper = new Shutterstock_Helper($this->shutterstock, $this->version); 151 $shutterstock_js_object = $shutterstock_helper->get_shutterstock_js_object(); 152 153 wp_localize_script('shutterstock-media-page-shuttestock-ui-js', 'shutterstock', $shutterstock_js_object); 154 } 155 156 public function add_admin_settings_page() 157 { 158 add_options_page( 159 'Shutterstock', // page_title 160 'Shutterstock', // menu_title 161 'manage_options', // capability 162 "{$this->shutterstock}_options_page", // menu_slug 163 array($this, 'create_admin_settings_page') // function 164 ); 165 166 add_submenu_page( 167 'upload.php', 168 'Shutterstock', 169 'Shutterstock', 170 'upload_files', 171 'shutterstock_media_page', 172 array($this, 'create_media_page') 173 ); 174 } 175 176 public function create_media_page() 177 { 178 include(plugin_dir_path(__FILE__) . "partials/{$this->shutterstock}-media-shutterstock.php"); 179 } 180 181 public function add_network_admin_settings_page() 182 { 183 add_submenu_page( 184 'settings.php', // Parent element 185 'Shutterstock', // Text in browser title bar 186 'Shutterstock', // Text to be displayed in the menu. 187 'manage_network_options', // Capability 188 "{$this->shutterstock}_network_options_page", // Page slug, will be displayed in URL 189 array($this, 'create_network_admin_settings_page') // Callback function which displays the page 190 ); 191 192 $this->network_settings_init(); 193 } 194 195 public function create_network_admin_settings_page() 196 { 197 $this->shutterstock_options = $this->get_site_option(); 198 199 include(plugin_dir_path(__FILE__) . "partials/{$this->shutterstock}-admin-network-settings-page.php"); 200 } 201 202 public function create_admin_settings_page() 203 { 204 $this->shutterstock_options = $this->get_option(); 205 include(plugin_dir_path(__FILE__) . "partials/{$this->shutterstock}-admin-settings-page.php"); 206 } 207 208 /** 209 * Register settings for network admins for section of shutterstock settings page 210 * 211 * @since 1.0.0 212 */ 213 public function network_settings_init() 214 { 215 register_setting( 216 'shutterstock_network_option_group', 217 'shutterstock_option_name', 218 array($this, 'sanitize_fields') 219 ); 220 221 add_settings_section( 222 'shutterstock_setting_section', // id 223 '', // title 224 array($this, 'shutterstock_section_info'), // callback 225 'shutterstock_network_options_page' // page 226 ); 227 228 $this->register_fields("shutterstock_network_options_page"); 229 } 230 231 232 /** 233 * Register settings for admin_init action 234 * 235 * @since 1.0.0 236 */ 237 public function settings_init() 238 { 239 register_setting( 240 'shutterstock_option_group', // option_group 241 'shutterstock_option_name', // option_name 242 array($this, 'sanitize_fields') // sanitize_callback 243 ); 244 245 add_settings_section( 246 'shutterstock_setting_section', // id 247 '', // title 248 array($this, 'shutterstock_section_info'), // callback 249 'shutterstock-admin' // page 250 ); 251 252 $this->register_fields('shutterstock-admin'); 253 } 254 255 /** 256 * Register fields for section of shutterstock settings page 257 * 258 * @since 1.0.0 259 */ 260 public function register_fields($page) 261 { 262 add_settings_field( 263 'api_key', // id 264 __('wordpress:text_api_key', 'shutterstock'), // title 265 array($this, 'field_text'), // callback 266 $page, // page 267 'shutterstock_setting_section', // section 268 array( 269 'id' => 'api_key', 270 'description' => __('wordpress:text_api_key_description', 'shutterstock'), 271 ) 272 ); 260 273 261 274 add_settings_field( 262 275 'api_secret', // id 263 276 __('wordpress:text_api_secret', 'shutterstock'), // title 264 array( $this, 'field_text'), // callback277 array($this, 'field_text'), // callback 265 278 $page, // page 266 279 'shutterstock_setting_section', // section … … 271 284 ); 272 285 273 $nonce = wp_create_nonce('generate-token'); 274 275 $network_admin = is_network_admin(); 276 277 $redirect_uri = $network_admin ? 278 network_admin_url('edit.php?action=shutterstock_network_generate_access_token&_wpnonce='.$nonce) : 279 admin_url('admin.php?action=shutterstock_generate_access_token&_wpnonce='.$nonce); 280 281 $post_location = $network_admin ? 282 'edit.php?action=shutterstock_network_update_options' : 283 'options.php'; 286 $nonce = wp_create_nonce('generate-token'); 287 288 $network_admin = is_network_admin(); 289 290 $redirect_uri = $network_admin ? 291 network_admin_url('edit.php?action=shutterstock_network_generate_access_token&_wpnonce=' . $nonce) : 292 admin_url('admin.php?action=shutterstock_generate_access_token&_wpnonce=' . $nonce); 293 294 // network settings page: 295 // network/settings.php?page=shutterstock_network_options_page 296 297 $post_location = $network_admin ? 298 'edit.php?action=shutterstock_network_update_options' : 299 'options.php'; 284 300 285 301 286 302 $redirect_query_params = http_build_query(array( 287 303 'state' => gmdate(DATE_ATOM), 288 'redirect_uri' => $redirect_uri,304 'redirect_uri' => $redirect_uri, 289 305 'client_id' => 'CLIENT_ID', 290 306 'scope' => 'licenses.create licenses.view purchases.view user.view' … … 311 327 'postLocation' => $post_location, 312 328 'has_value_button_text' => __('wordpress:text_logout', 'shutterstock'), 313 'no_value_button_text' => __('wordpress:text_log_in_with_shutterstock', 'shutterstock'),314 'description' => __('wordpress:text_app_token_description', 'shutterstock'),329 'no_value_button_text' => __('wordpress:text_log_in_with_shutterstock', 'shutterstock'), 330 'description' => __('wordpress:text_app_token_description', 'shutterstock'), 315 331 ], 316 332 ) 317 333 ); 318 334 319 add_settings_field( 320 'editorial_country', // id 321 __('wordpress:text_editorial_country', 'shutterstock'), // title 322 array( $this, 'field_text' ), // callback 323 $page, // page 324 'shutterstock_setting_section', // section 325 array( 326 'id' => 'editorial_country', 327 'description' => __('wordpress:text_editorial_country_description', 'shutterstock'), 328 ) 329 ); 330 331 add_settings_field( 332 'user_settings', // id 333 __('wordpress:text_user_settings', 'shutterstock'), // title 334 array( $this, 'field_user_settings' ), // callback 335 $page, // page 336 'shutterstock_setting_section', // section 337 array( 338 'id' => 'user_settings', 339 'description' => __('wordpress:text_user_settings_description', 'shutterstock'), 340 ) 341 ); 342 343 } 344 345 public function sanitize_fields($input) { 346 $sanitary_values = array(); 347 if ( isset( $input['api_key'] ) ) { 348 $sanitary_values['api_key'] = sanitize_text_field( $input['api_key'] ); 349 } 350 351 if ( isset( $input['api_secret'] ) ) { 352 $sanitary_values['api_secret'] = sanitize_text_field( $input['api_secret'] ); 353 } 354 355 if ( isset( $input['editorial_country'] ) ) { 356 $sanitary_values['editorial_country'] = sanitize_text_field( $input['editorial_country'] ); 357 } 358 359 if ( isset( $input['app_token'] ) ) { 360 $sanitary_values['app_token'] = esc_textarea( $input['app_token'] ); 361 } 362 363 if (isset( $input['user_settings'])) { 364 $sanitary_values['user_settings'] = $input['user_settings']; 365 $sanitary_values['user_settings'] = array(); 366 367 if ( is_array( $input['user_settings'] ) ) { 368 foreach($input['user_settings'] as $user_type => $user_capabilities) { 369 $sanitary_values['user_settings'][$user_type] = array_map( 'sanitize_text_field', wp_unslash( $user_capabilities) ); 370 } 371 } 372 } 373 374 return $sanitary_values; 375 } 376 377 public function shutterstock_section_info() { 378 379 } 380 381 /** 382 * Creates a text field 383 * 384 * @param array $args The arguments for the field 385 * @return string The HTML field 386 */ 387 public function field_text( $args ) { 388 $defaults = []; 389 $defaults['class'] = 'regular-text'; 390 $defaults['description'] = ''; 391 $defaults['label'] = ''; 392 $defaults['name'] = "{$this->shutterstock}_option_name[{$args['id']}]"; 393 $defaults['placeholder'] = ''; 394 $defaults['type'] = 'text'; 395 $defaults['value'] = ''; 396 397 $atts = wp_parse_args( $args, $defaults ); 398 if ( ! empty( $this->shutterstock_options[$atts['id']] ) ) { 399 400 $atts['value'] = $this->shutterstock_options[$atts['id']]; 401 402 } 403 404 include( plugin_dir_path( __FILE__ ) . "partials/{$this->shutterstock}-admin-field-text.php" ); 405 406 } 407 408 /** 409 * Creates a textarea field 410 * 411 * @param array $args The arguments for the field 412 * @return string The HTML field 413 */ 414 public function field_textarea( $args ) { 415 $defaults = []; 416 $defaults['class'] = ''; 417 $defaults['cols'] = 100; 418 $defaults['context'] = ''; 419 $defaults['description'] = ''; 420 $defaults['label'] = ''; 421 $defaults['name'] = "{$this->shutterstock}_option_name[{$args['id']}]"; 422 $defaults['rows'] = 6; 423 $defaults['value'] = ''; 424 425 $atts = wp_parse_args( $args, $defaults ); 426 427 if ( ! empty( $this->shutterstock_options[$atts['id']] ) ) { 428 429 $atts['value'] = $this->shutterstock_options[$atts['id']]; 430 431 } 432 433 include( plugin_dir_path( __FILE__ ) . "partials/{$this->shutterstock}-admin-field-textarea.php" ); 434 435 } 335 add_settings_field( 336 'editorial_country', // id 337 __('wordpress:text_editorial_country', 'shutterstock'), // title 338 array($this, 'field_text'), // callback 339 $page, // page 340 'shutterstock_setting_section', // section 341 array( 342 'id' => 'editorial_country', 343 'description' => __('wordpress:text_editorial_country_description', 'shutterstock'), 344 ) 345 ); 346 347 add_settings_field( 348 'user_settings', // id 349 __('wordpress:text_user_settings', 'shutterstock'), // title 350 array($this, 'field_user_settings'), // callback 351 $page, // page 352 'shutterstock_setting_section', // section 353 array( 354 'id' => 'user_settings', 355 'description' => __('wordpress:text_user_settings_description', 'shutterstock'), 356 ) 357 ); 358 359 } 360 361 public function sanitize_fields($input) 362 { 363 $sanitary_values = array(); 364 if (isset($input['api_key'])) { 365 $sanitary_values['api_key'] = sanitize_text_field($input['api_key']); 366 } 367 368 if (isset($input['api_secret'])) { 369 $sanitary_values['api_secret'] = sanitize_text_field($input['api_secret']); 370 } 371 372 if (isset($input['editorial_country'])) { 373 $sanitary_values['editorial_country'] = sanitize_text_field($input['editorial_country']); 374 } 375 376 if (isset($input['app_token'])) { 377 $sanitary_values['app_token'] = esc_textarea($input['app_token']); 378 } 379 380 if (isset($input['user_settings'])) { 381 $sanitary_values['user_settings'] = $input['user_settings']; 382 $sanitary_values['user_settings'] = array(); 383 384 if (is_array($input['user_settings'])) { 385 foreach ($input['user_settings'] as $user_type => $user_capabilities) { 386 $sanitary_values['user_settings'][$user_type] = array_map('sanitize_text_field', wp_unslash($user_capabilities)); 387 } 388 } 389 } 390 391 return $sanitary_values; 392 } 393 394 public function shutterstock_section_info() 395 { 396 397 } 398 399 /** 400 * Creates a text field 401 * 402 * @param array $args The arguments for the field 403 * @return string The HTML field 404 */ 405 public function field_text($args) 406 { 407 $defaults = []; 408 $defaults['class'] = 'regular-text'; 409 $defaults['description'] = ''; 410 $defaults['label'] = ''; 411 $defaults['name'] = "{$this->shutterstock}_option_name[{$args['id']}]"; 412 $defaults['placeholder'] = ''; 413 $defaults['type'] = 'text'; 414 $defaults['value'] = ''; 415 416 $atts = wp_parse_args($args, $defaults); 417 if (!empty($this->shutterstock_options[$atts['id']])) { 418 419 $atts['value'] = $this->shutterstock_options[$atts['id']]; 420 421 } 422 423 include(plugin_dir_path(__FILE__) . "partials/{$this->shutterstock}-admin-field-text.php"); 424 425 } 426 427 /** 428 * Creates a textarea field 429 * 430 * @param array $args The arguments for the field 431 * @return string The HTML field 432 */ 433 public function field_textarea($args) 434 { 435 $defaults = []; 436 $defaults['class'] = ''; 437 $defaults['cols'] = 100; 438 $defaults['context'] = ''; 439 $defaults['description'] = ''; 440 $defaults['label'] = ''; 441 $defaults['name'] = "{$this->shutterstock}_option_name[{$args['id']}]"; 442 $defaults['rows'] = 6; 443 $defaults['value'] = ''; 444 445 $atts = wp_parse_args($args, $defaults); 446 447 if (!empty($this->shutterstock_options[$atts['id']])) { 448 449 $atts['value'] = $this->shutterstock_options[$atts['id']]; 450 451 } 452 453 include(plugin_dir_path(__FILE__) . "partials/{$this->shutterstock}-admin-field-textarea.php"); 454 455 } 436 456 437 457 /** 438 458 * Creates a button field 439 459 * 440 * @param array $args The arguments for the field 441 * @return string The HTML field 442 */ 443 public function field_button( $args ) { 460 * @param array $args The arguments for the field 461 * @return string The HTML field 462 */ 463 public function field_button($args) 464 { 444 465 445 466 $defaults = []; 446 $defaults['context'] = '';447 $defaults['value'] = '';448 $defaults['name'] = "{$this->shutterstock}_option_name[{$args['id']}]";449 450 $atts = wp_parse_args( $args, $defaults);451 452 if ( ! empty( $this->shutterstock_options[$atts['id']] )) {467 $defaults['context'] = ''; 468 $defaults['value'] = ''; 469 $defaults['name'] = "{$this->shutterstock}_option_name[{$args['id']}]"; 470 471 $atts = wp_parse_args($args, $defaults); 472 473 if (!empty($this->shutterstock_options[$atts['id']])) { 453 474 454 475 $atts['value'] = $this->shutterstock_options[$atts['id']]; … … 456 477 } 457 478 458 include( plugin_dir_path( __FILE__ ) . "partials/{$this->shutterstock}-admin-field-shutterstock-login-button.php" ); 459 460 } 461 462 public function field_user_settings($args) { 463 $wp_roles = wp_roles(); 464 $role_names = $wp_roles->role_names; 465 $atts = []; 466 $atts['role_names'] = $role_names; 467 $atts['description'] = $args['description']; 468 469 if (isset($this->shutterstock_options[$args['id']])) { 470 $atts['user_settings'] = $this->shutterstock_options[$args['id']]; 471 } 472 473 include( plugin_dir_path( __FILE__ ) . "partials/{$this->shutterstock}-admin-field-user-settings.php" ); 474 475 } 476 477 /** 478 * This function here is hooked up to a special action and necessary to process 479 * the saving of the options. This is the big difference with a normal options 480 * page. 481 */ 482 public function shutterstock_network_update_options() { 483 // Make sure we are posting from our options page. There's a little surprise 484 // here, on the options page we used the 'shutterstock_network_option_group' 485 // slug when calling 'settings_fields' but we must add the '-options' postfix 486 // when we check the referer. 487 check_admin_referer( 'shutterstock_network_option_group-options' ); // Nonce security check 488 489 // This is the list of registered options. 490 global $new_whitelist_options; 491 492 $options = $new_whitelist_options['shutterstock_network_option_group']; 493 494 // Go through the posted data and save only our options. 495 foreach ($options as $option) { 496 if (isset($_POST[$option])) { 497 $api_key = isset( $_POST[$option]['api_key'] ) ? sanitize_text_field($_POST[$option]['api_key']) : ''; 498 $api_secret = isset( $_POST[$option]['api_secret'] ) ? sanitize_text_field($_POST[$option]['api_secret']) : ''; 499 $app_token = isset( $_POST[$option]['app_token'] ) ? sanitize_textarea_field($_POST[$option]['app_token']) : ''; 500 $editorial_country = isset( $_POST[$option]['editorial_country'] ) ? sanitize_text_field($_POST[$option]['editorial_country']) : ''; 501 $user_settings = []; 502 503 if (isset($_POST[$option]['user_settings'])) { 504 $wp_roles = wp_roles(); 505 $role_names = $wp_roles->role_names; 506 $roles_slugs = array_keys($role_names); 507 508 foreach($roles_slugs as $role_slug) { 509 if (isset($_POST[$option]['user_settings'][$role_slug])) { 510 $user_settings[$role_slug] = array_map( 'sanitize_text_field', wp_unslash( $_POST[$option]['user_settings'][$role_slug] ) ); 511 } 512 } 513 } 514 515 update_site_option($option, array( 516 'api_key' => $api_key, 517 'api_secret' => $api_secret, 518 'app_token' => $app_token, 519 'user_settings' => $user_settings, 520 'editorial_country' => $editorial_country, 521 )); 522 } 523 } 524 525 $wp_nonce = wp_create_nonce('shutterstock-network-settings-updated'); 526 // At last we redirect back to our options page. 527 wp_redirect(add_query_arg(array('page' => 'shutterstock_network_options_page', 528 'updated' => $wp_nonce, ), network_admin_url('settings.php'))); 529 exit; 530 } 531 532 public function shutterstock_generate_access_token() { 533 $nonce = isset($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']): ''; 534 535 if (!wp_verify_nonce( $nonce, 'generate-token')) { 536 die( esc_html_e('Security error.') ); 537 } else { 538 $code = isset($_REQUEST['code']) ? sanitize_text_field($_REQUEST['code']) : ''; 539 540 if ($code) { 541 $option = is_network_admin() ? $this->get_site_option() : $this->get_option(); 542 $token = $this->post_token($code, $option['api_key'], $option['api_secret']); 543 544 $option['app_token'] = $token; 545 546 if (is_network_admin()) { 547 update_site_option("{$this->shutterstock}_option_name", $option); 548 $wp_nonce = wp_create_nonce('shutterstock-network-settings-updated'); 549 // At last we redirect back to our options page. 550 wp_redirect(add_query_arg(array('page' => 'shutterstock_network_options_page', 551 'updated' => $wp_nonce, ), network_admin_url('settings.php'))); 552 exit; 553 } else { 554 update_option("{$this->shutterstock}_option_name", $option); 555 $wp_nonce = wp_create_nonce('shutterstock-setting-updated'); 556 // At last we redirect back to our options page. 557 wp_redirect(add_query_arg(array('page' => 'shutterstock_options_page', 558 'updated' => $wp_nonce, ), admin_url('options-general.php'))); 559 exit; 560 } 561 } 562 } 563 } 564 565 private function get_option() { 566 return get_option("{$this->shutterstock}_option_name"); 567 } 568 569 private function get_site_option() { 570 return get_site_option("{$this->shutterstock}_option_name"); 571 } 572 573 private function post_token($code, $key, $secret) { 479 include(plugin_dir_path(__FILE__) . "partials/{$this->shutterstock}-admin-field-shutterstock-login-button.php"); 480 481 } 482 483 public function field_user_settings($args) 484 { 485 $wp_roles = wp_roles(); 486 $role_names = $wp_roles->role_names; 487 $atts = []; 488 $atts['role_names'] = $role_names; 489 $atts['description'] = $args['description']; 490 491 if (isset($this->shutterstock_options[$args['id']])) { 492 $atts['user_settings'] = $this->shutterstock_options[$args['id']]; 493 } 494 495 include(plugin_dir_path(__FILE__) . "partials/{$this->shutterstock}-admin-field-user-settings.php"); 496 497 } 498 499 /** 500 * This function here is hooked up to a special action and necessary to process 501 * the saving of the options. This is the big difference with a normal options 502 * page. 503 */ 504 public function shutterstock_network_update_options() 505 { 506 // Make sure we are posting from our options page. There's a little surprise 507 // here, on the options page we used the 'shutterstock_network_option_group' 508 // slug when calling 'settings_fields' but we must add the '-options' postfix 509 // when we check the referer. 510 check_admin_referer('shutterstock_network_option_group-options'); // Nonce security check 511 512 // This is the list of registered options. 513 global $new_whitelist_options; 514 515 $options = $new_whitelist_options['shutterstock_network_option_group']; 516 517 // Go through the posted data and save only our options. 518 foreach ($options as $option) { 519 if (isset($_POST[$option])) { 520 $api_key = isset($_POST[$option]['api_key']) ? sanitize_text_field($_POST[$option]['api_key']) : ''; 521 $api_secret = isset($_POST[$option]['api_secret']) ? sanitize_text_field($_POST[$option]['api_secret']) : ''; 522 $app_token = isset($_POST[$option]['app_token']) ? sanitize_textarea_field($_POST[$option]['app_token']) : ''; 523 $editorial_country = isset($_POST[$option]['editorial_country']) ? sanitize_text_field($_POST[$option]['editorial_country']) : ''; 524 $user_settings = []; 525 526 if (isset($_POST[$option]['user_settings'])) { 527 $wp_roles = wp_roles(); 528 $role_names = $wp_roles->role_names; 529 $roles_slugs = array_keys($role_names); 530 531 foreach ($roles_slugs as $role_slug) { 532 if (isset($_POST[$option]['user_settings'][$role_slug])) { 533 $user_settings[$role_slug] = array_map('sanitize_text_field', wp_unslash($_POST[$option]['user_settings'][$role_slug])); 534 } 535 } 536 } 537 538 update_site_option($option, array( 539 'api_key' => $api_key, 540 'api_secret' => $api_secret, 541 'app_token' => $app_token, 542 'user_settings' => $user_settings, 543 'editorial_country' => $editorial_country, 544 )); 545 } 546 } 547 548 $wp_nonce = wp_create_nonce('shutterstock-network-settings-updated'); 549 // At last we redirect back to our options page. 550 wp_redirect(add_query_arg(array('page' => 'shutterstock_network_options_page', 551 'updated' => $wp_nonce,), network_admin_url('settings.php'))); 552 exit; 553 } 554 555 public function shutterstock_generate_access_token() 556 { 557 $nonce = isset($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; 558 559 if (!wp_verify_nonce($nonce, 'generate-token')) { 560 die(esc_html_e('Security error.')); 561 } else { 562 $code = isset($_REQUEST['code']) ? sanitize_text_field($_REQUEST['code']) : ''; 563 564 if ($code) { 565 $option = is_network_admin() ? $this->get_site_option() : $this->get_option(); 566 $token = $this->post_token($code, $option['api_key'], $option['api_secret']); 567 568 $option['app_token'] = $token; 569 570 if (is_network_admin()) { 571 update_site_option("{$this->shutterstock}_option_name", $option); 572 $wp_nonce = wp_create_nonce('shutterstock-network-settings-updated'); 573 // At last we redirect back to our options page. 574 wp_redirect(add_query_arg(array('page' => 'shutterstock_network_options_page', 575 'updated' => $wp_nonce,), network_admin_url('settings.php'))); 576 exit; 577 } else { 578 update_option("{$this->shutterstock}_option_name", $option); 579 $wp_nonce = wp_create_nonce('shutterstock-setting-updated'); 580 // At last we redirect back to our options page. 581 wp_redirect(add_query_arg(array('page' => 'shutterstock_options_page', 582 'updated' => $wp_nonce,), admin_url('options-general.php'))); 583 exit; 584 } 585 } 586 } 587 } 588 589 private function get_option() 590 { 591 return get_option("{$this->shutterstock}_option_name"); 592 } 593 594 private function get_site_option() 595 { 596 return get_site_option("{$this->shutterstock}_option_name"); 597 } 598 599 private function post_token($code, $key, $secret) 600 { 574 601 $token_url = 'https://api.shutterstock.com/v2/oauth/access_token'; 575 602 … … 584 611 'headers' => [ 585 612 'Content-Type' => 'application/json', 586 'x-shutterstock-application' => 'Wordpress/' . $this->version,613 'x-shutterstock-application' => 'Wordpress/' . $this->version, 587 614 ], 588 615 'body' => wp_json_encode($body), … … 596 623 597 624 return $decoded_body['access_token']; 598 }625 } 599 626 } -
shutterstock/trunk/includes/class-shutterstock.php
r2661410 r2670796 71 71 $this->version = SHUTTERSTOCK_VERSION; 72 72 } else { 73 $this->version = '1.3. 8';73 $this->version = '1.3.9'; 74 74 } 75 75 $this->shutterstock = 'shutterstock'; -
shutterstock/trunk/shutterstock.php
r2661410 r2670796 16 16 * Plugin Name: Shutterstock 17 17 * Description: Access exceptional, royalty-free content straight from WordPress. 18 * Version: 1.3. 818 * Version: 1.3.9 19 19 * Author: Shutterstock 20 20 * License: MIT … … 34 34 * Rename this for your plugin and update it as you release new versions. 35 35 */ 36 define( 'SHUTTERSTOCK_VERSION', '1.3. 8' );36 define( 'SHUTTERSTOCK_VERSION', '1.3.9' ); 37 37 38 38 /**
Note: See TracChangeset
for help on using the changeset viewer.