@@ -439,7 +439,20 @@ public function deleteChart() {
439439 }
440440 }
441441 if ( $ success ) {
442- wp_delete_post ( $ chart_id , true );
442+ if ( Visualizer_Module::is_pro () && function_exists ( 'icl_get_languages ' ) ) {
443+ global $ sitepress ;
444+ $ trid = $ sitepress ->get_element_trid ( $ chart_id , 'post_ ' . Visualizer_Plugin::CPT_VISUALIZER );
445+ $ translations = $ sitepress ->get_element_translations ( $ trid );
446+ if ( ! empty ( $ translations ) ) {
447+ foreach ( $ translations as $ translated_post ) {
448+ wp_delete_post ( $ translated_post ->element_id , true );
449+ }
450+ } else {
451+ wp_delete_post ( $ chart_id , true );
452+ }
453+ } else {
454+ wp_delete_post ( $ chart_id , true );
455+ }
443456 }
444457 if ( $ is_post ) {
445458 self ::_sendResponse (
@@ -498,32 +511,68 @@ public function renderChartPages() {
498511 // check chart, if chart not exists, will create new one and redirects to the same page with proper chart id
499512 $ chart_id = isset ( $ _GET ['chart ' ] ) ? filter_var ( $ _GET ['chart ' ], FILTER_VALIDATE_INT ) : '' ;
500513 if ( ! $ chart_id || ! ( $ chart = get_post ( $ chart_id ) ) || $ chart ->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) {
501- $ this ->deleteOldCharts ();
502- $ default_type = isset ( $ _GET ['type ' ] ) && ! empty ( $ _GET ['type ' ] ) ? $ _GET ['type ' ] : 'line ' ;
503- $ source = new Visualizer_Source_Csv ( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples ' . DIRECTORY_SEPARATOR . $ default_type . '.csv ' );
504- $ source ->fetch ();
505- $ chart_id = wp_insert_post (
506- array (
507- 'post_type ' => Visualizer_Plugin::CPT_VISUALIZER ,
508- 'post_title ' => 'Visualization ' ,
509- 'post_author ' => get_current_user_id (),
510- 'post_status ' => 'auto-draft ' ,
511- 'post_content ' => $ source ->getData ( get_post_meta ( $ chart_id , Visualizer_Plugin::CF_EDITABLE_TABLE , true ) ),
512- )
513- );
514- if ( $ chart_id && ! is_wp_error ( $ chart_id ) ) {
515- add_post_meta ( $ chart_id , Visualizer_Plugin::CF_CHART_TYPE , $ default_type );
516- add_post_meta ( $ chart_id , Visualizer_Plugin::CF_DEFAULT_DATA , 1 );
517- add_post_meta ( $ chart_id , Visualizer_Plugin::CF_SOURCE , $ source ->getSourceName () );
518- add_post_meta ( $ chart_id , Visualizer_Plugin::CF_SERIES , $ source ->getSeries () );
519- add_post_meta ( $ chart_id , Visualizer_Plugin::CF_CHART_LIBRARY , '' );
520- add_post_meta (
521- $ chart_id ,
522- Visualizer_Plugin::CF_SETTINGS ,
514+ if ( empty ( $ _GET ['lang ' ] ) || empty ( $ _GET ['parent_chart_id ' ] ) ) {
515+ $ this ->deleteOldCharts ();
516+ $ default_type = isset ( $ _GET ['type ' ] ) && ! empty ( $ _GET ['type ' ] ) ? $ _GET ['type ' ] : 'line ' ;
517+ $ source = new Visualizer_Source_Csv ( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples ' . DIRECTORY_SEPARATOR . $ default_type . '.csv ' );
518+ $ source ->fetch ();
519+ $ chart_id = wp_insert_post (
523520 array (
524- 'focusTarget ' => 'datum ' ,
521+ 'post_type ' => Visualizer_Plugin::CPT_VISUALIZER ,
522+ 'post_title ' => 'Visualization ' ,
523+ 'post_author ' => get_current_user_id (),
524+ 'post_status ' => 'auto-draft ' ,
525+ 'post_content ' => $ source ->getData ( get_post_meta ( $ chart_id , Visualizer_Plugin::CF_EDITABLE_TABLE , true ) ),
525526 )
526527 );
528+ if ( $ chart_id && ! is_wp_error ( $ chart_id ) ) {
529+ add_post_meta ( $ chart_id , Visualizer_Plugin::CF_CHART_TYPE , $ default_type );
530+ add_post_meta ( $ chart_id , Visualizer_Plugin::CF_DEFAULT_DATA , 1 );
531+ add_post_meta ( $ chart_id , Visualizer_Plugin::CF_SOURCE , $ source ->getSourceName () );
532+ add_post_meta ( $ chart_id , Visualizer_Plugin::CF_SERIES , $ source ->getSeries () );
533+ add_post_meta ( $ chart_id , Visualizer_Plugin::CF_CHART_LIBRARY , '' );
534+ add_post_meta (
535+ $ chart_id ,
536+ Visualizer_Plugin::CF_SETTINGS ,
537+ array (
538+ 'focusTarget ' => 'datum ' ,
539+ )
540+ );
541+
542+ do_action ( 'visualizer_pro_new_chart_defaults ' , $ chart_id );
543+ }
544+ } else {
545+ if ( current_user_can ( 'edit_posts ' ) ) {
546+ $ parent_chart_id = isset ( $ _GET ['parent_chart_id ' ] ) ? filter_var ( $ _GET ['parent_chart_id ' ], FILTER_VALIDATE_INT ) : '' ;
547+ $ success = false ;
548+ if ( $ parent_chart_id ) {
549+ $ parent_chart = get_post ( $ parent_chart_id );
550+ $ success = $ parent_chart && $ parent_chart ->post_type === Visualizer_Plugin::CPT_VISUALIZER ;
551+ }
552+ if ( $ success ) {
553+ $ new_chart_id = wp_insert_post (
554+ array (
555+ 'post_type ' => Visualizer_Plugin::CPT_VISUALIZER ,
556+ 'post_title ' => 'Visualization ' ,
557+ 'post_author ' => get_current_user_id (),
558+ 'post_status ' => $ parent_chart ->post_status ,
559+ 'post_content ' => $ parent_chart ->post_content ,
560+ )
561+ );
562+
563+ if ( is_wp_error ( $ new_chart_id ) ) {
564+ do_action ( 'themeisle_log_event ' , Visualizer_Plugin::NAME , sprintf ( 'Error while cloning chart %d = %s ' , $ parent_chart_id , print_r ( $ new_chart_id , true ) ), 'error ' , __FILE__ , __LINE__ );
565+ } else {
566+ $ post_meta = get_post_meta ( $ parent_chart_id );
567+ $ chart_id = $ new_chart_id ;
568+ foreach ( $ post_meta as $ key => $ value ) {
569+ if ( strpos ( $ key , 'visualizer- ' ) !== false ) {
570+ add_post_meta ( $ new_chart_id , $ key , maybe_unserialize ( $ value [0 ] ) );
571+ }
572+ }
573+ }
574+ }
575+ }
527576 do_action ( 'visualizer_pro_new_chart_defaults ' , $ chart_id );
528577 }
529578 wp_redirect ( esc_url_raw ( add_query_arg ( 'chart ' , (int ) $ chart_id ) ) );
0 commit comments