Changeset 199764 for sydney/2.26/inc/dashboard/class-dashboard.php
- Timestamp:
- 08/21/2023 12:42:32 PM (2 years ago)
- Location:
- sydney/2.26
- Files:
-
- 1 edited
- 1 copied
-
. (copied) (copied from sydney/2.25)
-
inc/dashboard/class-dashboard.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sydney/2.26/inc/dashboard/class-dashboard.php
r193604 r199764 45 45 if( $this->is_sydney_dashboard_page() ) { 46 46 add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); 47 48 if( defined( 'SYDNEY_PRO_VERSION' ) ) { 49 add_action( 'admin_footer', 'sydney_templates_display_conditions_script_template' ); 50 } 47 51 } 48 52 … … 60 64 add_action( 'wp_ajax_sydney_module_activation_handler', array( $this, 'ajax_module_activation_handler' ) ); 61 65 add_action( 'wp_ajax_sydney_module_activation_all_handler', array( $this, 'ajax_module_activation_all_handler' ) ); 66 add_action( 'wp_ajax_sydney_template_builder_data', array( $this, 'ajax_template_builder_data' ) ); 67 add_action( 'wp_ajax_insert_template_part_callback', array( $this, 'insert_template_part_callback' ) ); 68 add_action( 'wp_ajax_edit_template_part_callback', array( $this, 'edit_template_part_callback' ) ); 62 69 63 70 add_action('switch_theme', array($this, 'reset_notices')); … … 116 123 } 117 124 118 wp_enqueue_script('sydney-dashboard', get_template_directory_uri() . '/inc/dashboard/assets/js/sydney-dashboard.min.js', array('jquery'), '20230525', true); 125 wp_enqueue_script('sydney-dashboard', get_template_directory_uri() . '/inc/dashboard/assets/js/sydney-dashboard.min.js', array('jquery', 'wp-util', 'jquery-ui-sortable' ), '20230525', true); 126 127 wp_enqueue_script( 'sydney-select2-js', get_template_directory_uri() . '/inc/customizer/controls/typography/select2.full.min.js', array( 'jquery' ), '4.0.13', true ); 128 wp_enqueue_style( 'sydney-select2-css', get_template_directory_uri() . '/inc/customizer/controls/typography/select2.min.css', array(), '4.0.13', 'all' ); 119 129 120 130 wp_localize_script('sydney-dashboard', 'sydney_dashboard', array( … … 127 137 'activating' => esc_html__('Activating...', 'sydney'), 128 138 'deactivating' => esc_html__('Deactivating...', 'sydney'), 139 'loading' => esc_html__('Loading...', 'sydney'), 140 'saving' => esc_html__('Saving...', 'sydney'), 141 'saved' => esc_html__('Saved!', 'sydney'), 142 'unsaved_changes' => esc_html__('You have unsaved changes.', 'sydney'), 143 'save' => esc_html__('Save', 'sydney'), 129 144 'redirecting' => esc_html__('Redirecting...', 'sydney'), 130 145 'activated' => esc_html__('Activated', 'sydney'), … … 308 323 $text = sprintf( 309 324 /* translators: %s: https://wordpress.org/ */ 310 __( 'Thank you for creating the website with <a href="%s" class="sydney-dashboard-footer-link" target="_blank">sydney</a>.', 'sydney' ),325 __( 'Thank you for creating your website with <a href="%s" class="sydney-dashboard-footer-link" target="_blank">Sydney</a>.', 'sydney' ), 311 326 'https://athemes.com/sydney-upgrade/' 312 327 ); … … 326 341 $user_read_meta = get_user_meta( $user_id, 'sydney_dashboard_notifications_latest_read', true ); 327 342 328 $last_notification_date = strtotime( is_string( $this->settings[ 'notifications' ][0]-> date ) ? $this->settings[ 'notifications' ][0]->date : '' );343 $last_notification_date = strtotime( is_string( $this->settings[ 'notifications' ][0]->post_date ) ? $this->settings[ 'notifications' ][0]->post_date : '' ); 329 344 $last_notification_date_ondb = $user_read_meta ? strtotime( $user_read_meta ) : false; 330 345 … … 474 489 475 490 /** 491 * Templates builder 492 */ 493 function ajax_template_builder_data() { 494 check_ajax_referer('nonce-bt-dashboard', 'nonce'); 495 496 if( ! current_user_can( 'manage_options' ) ) { 497 wp_send_json_error(); 498 } 499 500 $data = $_POST[ 'data' ]; 501 502 $data = stripslashes_deep($data); 503 504 update_option('sydney_template_builder_data', $data); 505 506 wp_send_json_success($data); 507 } 508 509 /** 510 * Get option text 511 */ 512 function get_option_text( $value ) { 513 514 switch ( $value['condition'] ) { 515 516 case 'post-id': 517 case 'page-id': 518 case 'product-id': 519 case 'cpt-post-id': 520 return get_the_title( $value['id'] ); 521 break; 522 523 case 'tag-id': 524 case 'category-id': 525 526 $term = get_term( $value['id'] ); 527 528 if ( ! empty( $term ) ) { 529 return $term->name; 530 } 531 532 break; 533 534 case 'cpt-term-id': 535 536 $term = get_term( $value['id'] ); 537 538 if ( ! empty( $term ) ) { 539 return $term->name; 540 } 541 542 break; 543 544 case 'cpt-taxonomy-id': 545 546 $taxonomy = get_taxonomy( $value['id'] ); 547 548 if ( ! empty( $taxonomy ) ) { 549 return $taxonomy->label; 550 } 551 552 break; 553 554 case 'author': 555 case 'author-id': 556 return get_the_author_meta( 'display_name', $value['id'] ); 557 break; 558 559 } 560 561 // user-roles 562 if ( substr( $value['condition'], 0, 10 ) === 'user_role_' ) { 563 $user_rules = get_editable_roles(); 564 if ( ! empty( $user_rules[ $value['id'] ] ) ) { 565 return $user_rules[ $value['id'] ]['name']; 566 } 567 } 568 569 return $value['id']; 570 571 } 572 573 /** 574 * Insert a new template 575 */ 576 function insert_template_part_callback() { 577 578 check_ajax_referer('nonce-bt-dashboard', 'nonce'); 579 580 if ( ! isset( $_POST['key'] ) ) { 581 wp_send_json_error(); 582 } 583 584 $post_name = sanitize_text_field( wp_unslash( $_POST['key'] ) ) . '-' . sanitize_text_field( wp_unslash( $_POST['part_type'] ) ); 585 $page_builder = sanitize_text_field( wp_unslash( $_POST['page_builder'] ) ); 586 587 $post_title = ''; 588 $args = array( 589 'post_type' => 'athemes_hf', 590 'name' => $post_name, 591 'post_status' => 'publish', 592 'update_post_term_cache' => false, 593 'update_post_meta_cache' => false, 594 'posts_per_page' => 1, 595 ); 596 597 $post = get_posts( $args ); 598 599 if ( empty( $post ) ) { 600 601 $key = sanitize_text_field( wp_unslash( $_POST['key'] ) ); 602 603 $post_title = 'Sydney Template Part - ' . str_replace( 'sydney-template-', '', $key ) . '-' . sanitize_text_field( wp_unslash( $_POST['part_type'] ) ); 604 605 $params = array( 606 'post_content' => '', 607 'post_type' => 'athemes_hf', 608 'post_title' => $post_title, 609 'post_name' => $post_name, 610 'post_status' => 'publish', 611 ); 612 613 if( $page_builder == 'elementor' ) { 614 $params['meta_input'] = array( 615 '_elementor_edit_mode' => 'builder', 616 '_wp_page_template' => 'elementor_canvas', 617 ); 618 } 619 620 $post_id = wp_insert_post( $params ); 621 622 } else { // edit post. 623 $post_id = $post[0]->ID; 624 $post_title = $post[0]->post_title; 625 } 626 627 $action = $page_builder == 'elementor' ? 'elementor' : 'edit'; 628 629 $edit_url = get_admin_url() . 'post.php?post=' . $post_id . '&action=' . $action; 630 631 $result = array( 632 'url' => $edit_url, 633 'id' => $post_id, 634 'title' => $post_title, 635 ); 636 637 wp_send_json_success( $result ); 638 } 639 640 /** 641 * Edit template 642 */ 643 function edit_template_part_callback() { 644 645 check_ajax_referer('nonce-bt-dashboard', 'nonce'); 646 647 if ( ! isset( $_POST['key'] ) ) { 648 wp_send_json_error(); 649 } 650 651 $post_id = sanitize_text_field( wp_unslash( $_POST['key'] ) ); 652 653 $post = get_post( $post_id ); 654 655 if ( empty( $post ) ) { 656 wp_send_json_error(); 657 } 658 659 $action = 'edit'; 660 661 if( class_exists( 'Elementor\Plugin' ) && Elementor\Plugin::$instance->documents->get( $post_id )->is_built_with_elementor() ) { 662 $action = 'elementor'; 663 } 664 665 $edit_url = get_admin_url() . 'post.php?post=' . $post_id . '&action=' . $action; 666 667 $result = array( 668 'url' => $edit_url, 669 'id' => $post_id, 670 'title' => $post->post_title, 671 ); 672 673 wp_send_json_success( $result ); 674 } 675 676 /** 677 * Get athemes templates CPT 678 */ 679 function get_template_parts() { 680 $args = array( 681 'numberposts' => -1, 682 'post_type' => 'athemes_hf', 683 ); 684 685 $posts = get_posts( $args ); 686 687 $parts = array(); 688 689 if ( ! empty( $posts ) ) { 690 foreach ( $posts as $post ) { 691 $parts[ $post->ID ] = $post->post_title; 692 } 693 } 694 695 return $parts; 696 } 697 698 /** 699 * Existing parts select 700 */ 701 function existing_parts_select( $parts = array() ) { 702 703 $html = '<div class="existing-parts-wrapper">'; 704 705 if ( empty( $parts ) ) { 706 $html .= '<div>' . esc_html__( 'No templates found.', 'sydney' ) . '</div>'; 707 } else { 708 $html .= '<select class="existing-parts-select">'; 709 $html .= '<option value="">' . esc_html__( 'Select existing', 'sydney' ) . '</option>'; 710 711 foreach ( $parts as $id => $title ) { 712 713 $page_builder = 'editor'; 714 if ( class_exists( 'Elementor\Plugin' ) && Elementor\Plugin::$instance->documents->get( $id )->is_built_with_elementor() ) { 715 $page_builder = 'elementor'; 716 } 717 718 $html .= '<option data-page-builder="' . $page_builder . '" value="' . $id . '">' . $title . '</option>'; 719 } 720 721 $html .= '</select>'; 722 } 723 724 $html .= '</div>'; 725 726 return $html; 727 } 728 729 /** 476 730 * HTML Dashboard 477 731 */ … … 482 736 $notifications_count = 1; 483 737 484 $theme_version = wp_get_theme()->get( 'Version' ); 738 $theme_slug = get_template(); 739 $theme_version = wp_get_theme()->get( 'Version' ); 485 740 486 741 ?> … … 523 778 <?php require get_template_directory() . '/inc/dashboard/html-notifications-sidebar.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound ?> 524 779 525 <div class="sydney-dashboard-container" >780 <div class="sydney-dashboard-container" data-theme="<?php echo esc_attr( $theme_slug ); ?>"> 526 781 <?php require get_template_directory() . '/inc/dashboard/html-hero.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound ?> 527 782
Note: See TracChangeset
for help on using the changeset viewer.