@@ -138,14 +138,14 @@ public function setJsonSchedule() {
138138 );
139139
140140 if ( Visualizer_Module ::is_pro () ) {
141- $ is_woocommerce_report = filter_input (
142- INPUT_POST ,
143- 'is_woocommerce_report ' ,
144- FILTER_VALIDATE_BOOLEAN
145- );
141+ $ is_woocommerce_report = isset ( $ _POST ['is_woocommerce_report ' ] ) ? filter_var ( wp_unslash ( $ _POST ['is_woocommerce_report ' ] ), FILTER_VALIDATE_BOOLEAN ) : false ;
146142
147143 if ( $ is_woocommerce_report ) {
144+ if ( ! current_user_can ( 'view_woocommerce_reports ' ) ) {
145+ wp_send_json_error ( array ( 'msg ' => esc_html__ ( 'You do not have permission to access WooCommerce reports. ' , 'visualizer ' ) ), 403 );
146+ }
148147 update_post_meta ( $ chart_id , Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE , true );
148+ update_post_meta ( $ chart_id , Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER , get_current_user_id () );
149149 } else {
150150 delete_post_meta ( $ chart_id , Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE );
151151 }
@@ -220,7 +220,7 @@ public function getJsonData() {
220220 wp_send_json_error ( array ( 'msg ' => esc_html__ ( 'Unable to fetch data from the endpoint. Please try again. ' , 'visualizer ' ) ) );
221221 }
222222
223- $ data = Visualizer_Render_Layout ::show ( 'editor-table ' , $ data , $ chart_id , 'viz-json-table ' , false , false );
223+ $ data = Visualizer_Render_Layout ::show ( 'editor-table ' , self :: sanitize_chart_data ( $ data ) , $ chart_id , 'viz-json-table ' , false , false );
224224 wp_send_json_success ( array ( 'table ' => $ data , 'root ' => $ params ['root ' ], 'url ' => $ params ['url ' ], 'paging ' => $ source ->getPaginationElements () ) );
225225 }
226226
@@ -253,7 +253,7 @@ public function setJsonData() {
253253 update_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_SERIES , $ source ->getSeries () );
254254 update_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_SOURCE , $ source ->getSourceName () );
255255 update_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_DEFAULT_DATA , 0 );
256- update_post_meta ( $ chart ->ID , Visualizer_Plugin:: CF_JSON_URL , $ params ['url ' ] );
256+ self :: update_json_url ( $ chart ->ID , $ params ['url ' ] );
257257 update_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_JSON_ROOT , $ params ['root ' ] );
258258
259259 delete_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_JSON_HEADERS );
@@ -304,7 +304,7 @@ public function setJsonData() {
304304
305305 $ render = new Visualizer_Render_Page_Update ();
306306 $ render ->id = $ chart ->ID ;
307- $ render ->data = json_encode ( $ source ->getRawData ( get_post_meta ( $ chart_id , Visualizer_Plugin::CF_EDITABLE_TABLE , true ) ) );
307+ $ render ->data = json_encode ( self :: sanitize_chart_data ( $ source ->getRawData ( get_post_meta ( $ chart_id , Visualizer_Plugin::CF_EDITABLE_TABLE , true ) ) ) );
308308 $ render ->series = json_encode ( $ source ->getSeries () );
309309 $ render ->render ();
310310
@@ -631,7 +631,8 @@ public function renderChartPages() {
631631 $ post_meta = get_post_meta ( $ parent_chart_id );
632632 $ chart_id = $ new_chart_id ;
633633 foreach ( $ post_meta as $ key => $ value ) {
634- if ( strpos ( $ key , 'visualizer- ' ) !== false ) {
634+ // A copy refreshes reports with its own author's access.
635+ if ( strpos ( $ key , 'visualizer- ' ) !== false && Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER !== $ key ) {
635636 add_post_meta ( $ new_chart_id , $ key , self ::maybe_decode_content ( $ value [0 ] ) );
636637 }
637638 }
@@ -1420,7 +1421,7 @@ public function uploadData() {
14201421 }
14211422
14221423 $ render ->id = $ chart ->ID ;
1423- $ render ->data = json_encode ( $ source ->getRawData ( get_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_EDITABLE_TABLE , true ) ) );
1424+ $ render ->data = json_encode ( self :: sanitize_chart_data ( $ source ->getRawData ( get_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_EDITABLE_TABLE , true ) ) ) );
14241425 $ render ->series = json_encode ( $ source ->getSeries () );
14251426 $ render ->settings = json_encode ( $ settings );
14261427 } else {
@@ -1475,7 +1476,8 @@ public function cloneChart() {
14751476 } else {
14761477 $ post_meta = get_post_meta ( $ chart_id );
14771478 foreach ( $ post_meta as $ key => $ value ) {
1478- if ( strpos ( $ key , 'visualizer- ' ) !== false ) {
1479+ // A copy refreshes reports with its own author's access.
1480+ if ( strpos ( $ key , 'visualizer- ' ) !== false && Visualizer_Plugin::CF_WOOCOMMERCE_REPORT_USER !== $ key ) {
14791481 add_post_meta ( $ new_chart_id , $ key , self ::maybe_decode_content ( $ value [0 ] ) );
14801482 }
14811483 }
@@ -1682,7 +1684,7 @@ public function saveQuery() {
16821684 'post_content ' => $ source ->getData ( get_post_meta ( $ chart_id , Visualizer_Plugin::CF_EDITABLE_TABLE , true ) ),
16831685 )
16841686 );
1685- $ render ->data = json_encode ( $ source ->getRawData ( get_post_meta ( $ chart_id , Visualizer_Plugin::CF_EDITABLE_TABLE , true ) ) );
1687+ $ render ->data = json_encode ( self :: sanitize_chart_data ( $ source ->getRawData ( get_post_meta ( $ chart_id , Visualizer_Plugin::CF_EDITABLE_TABLE , true ) ) ) );
16861688 $ render ->series = json_encode ( $ source ->getSeries () );
16871689 $ render ->id = $ chart_id ;
16881690 } else {
0 commit comments