| @@ -80,9 +80,9 @@ | ||
| 80 | 80 | if ( is_admin() ) { |
| 81 | 81 | return $tag; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - $scripts = array( 'google-jsapi-new', 'google-jsapi-old', 'visualizer-render-google-lib', 'visualizer-render-google' ); | |
| 84 | + $scripts = array( 'google-jsapi', 'visualizer-render-google-lib', 'visualizer-render-google' ); | |
| 85 | 85 | |
| 86 | 86 | foreach ( $scripts as $async ) { |
| 87 | 87 | if ( $async === $handle ) { |
| 88 | 88 | $tag = str_replace( ' src', ' defer="defer" src', $tag ); |
| @@ -107,9 +107,26 @@ | ||
| 107 | 107 | register_rest_route( |
| 108 | 108 | 'visualizer/v' . VISUALIZER_REST_VERSION, |
| 109 | 109 | '/action/(?P<chart>\d+)/(?P<type>.+)/', |
| 110 | 110 | array( |
| 111 | - 'methods' => array( 'GET', 'POST' ), | |
| 111 | + 'methods' => 'GET', | |
| 112 | + 'args' => array( | |
| 113 | + 'chart' => array( | |
| 114 | + 'required' => true, | |
| 115 | + 'sanitize_callback' => function( $param ) { | |
| 116 | + return is_numeric( $param ) ? $param : null; | |
| 117 | + }, | |
| 118 | + ), | |
| 119 | + 'type' => array( | |
| 120 | + 'required' => true, | |
| 121 | + 'type' => 'string', | |
| 122 | + 'enum' => array_keys( $this->get_actions() ), | |
| 123 | + ), | |
| 124 | + ), | |
| 125 | + 'permission_callback' => function ( WP_REST_Request $request ) { | |
| 126 | + $chart_id = filter_var( sanitize_text_field( $request->get_param( 'chart' ), FILTER_VALIDATE_INT ) ); | |
| 127 | + return ! empty( $chart_id ) && apply_filters( 'visualizer_pro_show_chart', true, $chart_id ); | |
| 128 | + }, | |
| 112 | 129 | 'callback' => array( $this, 'perform_action' ), |
| 113 | 130 | ) |
| 114 | 131 | ); |
| 115 | 132 | } |
| @@ -218,9 +235,8 @@ | ||
| 218 | 235 | * @access public |
| 219 | 236 | */ |
| 220 | 237 | public function enqueueScripts() { |
| 221 | 238 | wp_register_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true ); |
| 222 | - wp_register_script( 'visualizer-clipboardjs', VISUALIZER_ABSURL . 'js/lib/clipboardjs/clipboard.min.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true ); | |
| 223 | 239 | wp_register_style( 'visualizer-front', VISUALIZER_ABSURL . 'css/front.css', array(), Visualizer_Plugin::VERSION ); |
| 224 | 240 | do_action( 'visualizer_pro_frontend_load_resources' ); |
| 225 | 241 | } |
| 226 | 242 | |
| @@ -348,9 +364,9 @@ | ||
| 348 | 364 | |
| 349 | 365 | if ( 'copy' === $key ) { |
| 350 | 366 | $copy = $this->_getDataAs( $atts['id'], 'csv' ); |
| 351 | 367 | $actions_div .= ' data-clipboard-text="' . esc_attr( $copy['csv'] ) . '"'; |
| 352 | - wp_enqueue_script( 'visualizer-clipboardjs' ); | |
| 368 | + wp_enqueue_script( 'clipboard' ); | |
| 353 | 369 | } |
| 354 | 370 | |
| 355 | 371 | $actions_div .= apply_filters( 'visualizer_action_attributes', '', $key, $atts['id'] ); |
| 356 | 372 | $actions_div .= '>' . $label . '</a> '; |
| @@ -379,8 +395,9 @@ | ||
| 379 | 395 | 'charts' => $this->_charts, |
| 380 | 396 | 'language' => $this->get_language(), |
| 381 | 397 | 'map_api_key' => get_option( 'visualizer-map-api-key' ), |
| 382 | 398 | 'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '', |
| 399 | + 'wp_nonce' => wp_create_nonce( 'wp_rest' ), | |
| 383 | 400 | 'i10n' => array( |
| 384 | 401 | 'copied' => __( 'The data has been copied to your clipboard. Hit Ctrl-V/Cmd-V in your spreadsheet editor to paste the data.', 'visualizer' ), |
| 385 | 402 | ), |
| 386 | 403 | 'page_type' => 'frontend', |