Changeset 3295458
- Timestamp:
- 05/17/2025 09:51:41 PM (11 months ago)
- Location:
- ilachat
- Files:
-
- 20 edited
-
tags/1.2.0/src/Admin/Admin.php (modified) (6 diffs)
-
tags/1.2.0/src/Admin/Connection.php (modified) (7 diffs)
-
tags/1.2.0/src/Frontend/PublicClass.php (modified) (2 diffs)
-
tags/1.2.0/src/Helpers/Helper.php (modified) (1 diff)
-
tags/1.2.0/src/Http/RequestMaker.php (modified) (2 diffs)
-
tags/1.2.0/src/Integrations/Woocommerce.php (modified) (27 diffs)
-
tags/1.2.0/src/Integrations/Wordpress.php (modified) (12 diffs)
-
tags/1.2.0/src/Plugin.php (modified) (2 diffs)
-
tags/1.2.0/templates/admin/wc-integration-page.php (modified) (1 diff)
-
tags/1.2.0/templates/admin/wc-order-notes.php (modified) (2 diffs)
-
trunk/src/Admin/Admin.php (modified) (6 diffs)
-
trunk/src/Admin/Connection.php (modified) (7 diffs)
-
trunk/src/Frontend/PublicClass.php (modified) (2 diffs)
-
trunk/src/Helpers/Helper.php (modified) (1 diff)
-
trunk/src/Http/RequestMaker.php (modified) (2 diffs)
-
trunk/src/Integrations/Woocommerce.php (modified) (27 diffs)
-
trunk/src/Integrations/Wordpress.php (modified) (12 diffs)
-
trunk/src/Plugin.php (modified) (2 diffs)
-
trunk/templates/admin/wc-integration-page.php (modified) (1 diff)
-
trunk/templates/admin/wc-order-notes.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ilachat/tags/1.2.0/src/Admin/Admin.php
r3295390 r3295458 3 3 namespace Ilachat\WpPlugin\Admin; 4 4 5 use Ilachat\WpPlugin\Helpers\TemplateLoader; 6 7 if (! defined('ABSPATH')) { 5 if (!defined('ABSPATH')) { 8 6 exit; 9 7 } 8 9 use Ilachat\WpPlugin\Helpers\TemplateLoader; 10 use Ilachat\WpPlugin\Helpers\Helper; 10 11 11 12 class Admin … … 59 60 public function render_settings_page() 60 61 { 61 $token = get_option('ilachat_token', ''); 62 63 if (empty($token)) { 64 TemplateLoader::get_template('admin/connect-page.php'); 65 } else { 62 if (Helper::is_ilachat_connected()) { 66 63 $bot_data = get_option('ilachat_bot', []); 67 64 TemplateLoader::get_template( … … 71 68 ] 72 69 ); 70 } else { 71 TemplateLoader::get_template('admin/connect-page.php'); 73 72 } 74 73 } … … 82 81 { 83 82 $screen = get_current_screen(); 84 if (! $screen) {83 if (!$screen) { 85 84 return; 86 85 } … … 192 191 { 193 192 // Check if the current user has the required permissions 194 if (! current_user_can('manage_options')) {193 if (!current_user_can('manage_options')) { 195 194 wp_send_json_error(__('You do not have permission to perform this action.', 'ilachat')); 196 195 } … … 200 199 ? sanitize_text_field(wp_unslash($_POST['ilachat_global_settings_nonce_field'])) 201 200 : ''; 202 if (empty($nonce_field) || ! wp_verify_nonce($nonce_field, 'ilachat_global_settings_nonce')) {201 if (empty($nonce_field) || !wp_verify_nonce($nonce_field, 'ilachat_global_settings_nonce')) { 203 202 wp_send_json_error(['message' => __('Invalid nonce.', 'ilachat')]); 204 203 } -
ilachat/tags/1.2.0/src/Admin/Connection.php
r3295390 r3295458 3 3 namespace Ilachat\WpPlugin\Admin; 4 4 5 if (! defined('ABSPATH')) {5 if (!defined('ABSPATH')) { 6 6 exit; 7 7 } 8 8 9 9 use Ilachat\WpPlugin\Http\RequestMaker; 10 use Ilachat\WpPlugin\Helpers\Helper; 10 11 11 12 class Connection … … 38 39 { 39 40 if ( 40 ! isset($_POST['ilachat_action'])41 !isset($_POST['ilachat_action']) 41 42 || $_POST['ilachat_action'] !== 'connect' 42 || ! check_admin_referer('ilachat_connect_nonce', 'ilachat_connect_nonce_field')43 || !check_admin_referer('ilachat_connect_nonce', 'ilachat_connect_nonce_field') 43 44 ) { 44 45 return; … … 68 69 { 69 70 if ( 70 ! isset($_POST['ilachat_action'])71 !isset($_POST['ilachat_action']) 71 72 || $_POST['ilachat_action'] !== 'disconnect' 72 || ! check_admin_referer('ilachat_disconnect_nonce', 'ilachat_disconnect_nonce_field')73 || !check_admin_referer('ilachat_disconnect_nonce', 'ilachat_disconnect_nonce_field') 73 74 ) { 74 75 return; … … 107 108 if ( 108 109 $pagenow !== 'admin.php' 109 || ! isset($_GET['page'])110 || !isset($_GET['page']) 110 111 || $_GET['page'] !== 'ilachat-settings' 111 112 ) { … … 119 120 120 121 if ( 121 ! isset($_GET['wpnonce'])122 || ! wp_verify_nonce(122 !isset($_GET['wpnonce']) 123 || !wp_verify_nonce( 123 124 sanitize_text_field(wp_unslash($_GET['wpnonce'])), 124 125 'ilachat_connect_nonce' … … 201 202 public static function fetch_bot_details($token = ''): array 202 203 { 203 $token = $token ?: get_option('ilachat_token', ''); 204 if (empty($token)) { 204 if (!Helper::is_ilachat_connected()) { 205 205 return []; 206 206 } … … 241 241 242 242 $bot = self::fetch_bot_details($token); 243 if (! empty($bot)) {243 if (!empty($bot)) { 244 244 $widget_code = $bot['widget']['jsCode'] ?? ''; 245 245 $widget_code = wp_strip_all_tags($widget_code); -
ilachat/tags/1.2.0/src/Frontend/PublicClass.php
r3295390 r3295458 5 5 use Ilachat\WpPlugin\Admin\Connection; 6 6 7 if (! defined('ABSPATH')) {7 if (!defined('ABSPATH')) { 8 8 exit; 9 9 } … … 36 36 $widget_code = Connection::get_widget_code_with_cache(); 37 37 38 if (! $widget_code) {38 if (!$widget_code) { 39 39 return; 40 40 } -
ilachat/tags/1.2.0/src/Helpers/Helper.php
r3295390 r3295458 64 64 }); 65 65 } 66 67 /** 68 * Is Ilachat connected. 69 * 70 * @return bool 71 */ 72 public static function is_ilachat_connected() 73 { 74 $token = get_option('ilachat_token', ''); 75 return !empty($token); 76 } 66 77 } -
ilachat/tags/1.2.0/src/Http/RequestMaker.php
r3295270 r3295458 3 3 namespace Ilachat\WpPlugin\Http; 4 4 5 if (! defined('ABSPATH')) {5 if (!defined('ABSPATH')) { 6 6 exit; 7 7 } … … 41 41 $url = self::get_url($endpoint); 42 42 43 if (! empty($queryParams)) {43 if (!empty($queryParams)) { 44 44 $url = add_query_arg($queryParams, $url); 45 45 } -
ilachat/tags/1.2.0/src/Integrations/Woocommerce.php
r3295390 r3295458 13 13 use Automattic\WooCommerce\Utilities\OrderUtil; 14 14 15 if (! defined('ABSPATH')) {15 if (!defined('ABSPATH')) { 16 16 exit; 17 17 } … … 133 133 public function sanitize_array($values) 134 134 { 135 if (! is_array($values)) {135 if (!is_array($values)) { 136 136 return []; 137 137 } … … 220 220 public function sync_variable_links() 221 221 { 222 $token = get_option('ilachat_token', ''); 223 if (empty($token)) { 222 if (!Helper::is_ilachat_connected()) { 224 223 return; 225 224 } … … 278 277 $integration_enabled = get_option('ilachat_woocommerce_integration_enabled', 1); 279 278 $order_tracking_enabled = get_option('ilachat_woocommerce_order_tracking_enabled', 1); 280 if (! $integration_enabled || !$order_tracking_enabled) {279 if (!$integration_enabled || !$order_tracking_enabled) { 281 280 return; 282 281 } … … 327 326 { 328 327 $order_tracking_enabled = get_option('ilachat_woocommerce_order_tracking_enabled', 1); 329 if (! $order_tracking_enabled) {328 if (!$order_tracking_enabled) { 330 329 return new WP_Error('order_tracking_disabled', esc_html__('Order tracking is disabled', 'ilachat'), ['status' => 400]); 331 330 } … … 335 334 $email = $request->get_param('email') ?: ''; 336 335 337 if (! $order_id) {336 if (!$order_id) { 338 337 return new WP_Error('missing_order_id', esc_html__('Order ID is required', 'ilachat'), ['status' => 400]); 339 338 } 340 339 341 340 $order = wc_get_order($order_id); 342 if (! $order) {341 if (!$order) { 343 342 return new WP_Error('no_order', esc_html__('Order not found', 'ilachat'), ['status' => 404]); 344 343 } … … 367 366 public function get_order_details($order) 368 367 { 369 if (! $order) {368 if (!$order) { 370 369 return []; 371 370 } … … 427 426 $data['items'] = []; 428 427 foreach ($order->get_items() as $item) { 429 if (! $item instanceof \WC_Order_Item_Product) {428 if (!$item instanceof \WC_Order_Item_Product) { 430 429 continue; 431 430 } … … 454 453 foreach ($order_notes as $note) { 455 454 // Skip notes that are not visible to the customer. 456 if (! $note->customer_note) {455 if (!$note->customer_note) { 457 456 continue; 458 457 } … … 505 504 { 506 505 $secret_key = $request->get_header('X-ILACHAT-SECRET-KEY') ?: ''; 507 if (! $secret_key || !hash_equals($this->get_secret_key(), $secret_key)) {506 if (!$secret_key || !hash_equals($this->get_secret_key(), $secret_key)) { 508 507 return false; 509 508 } … … 525 524 add_filter('comments_clauses', [$this, 'exclude_special_order_notes']); 526 525 527 if (! (bool) get_option('ilachat_woocommerce_order_special_note', 0)) {526 if (!(bool) get_option('ilachat_woocommerce_order_special_note', 0)) { 528 527 return; 529 528 } … … 599 598 { 600 599 $order = $post_or_order_object instanceof WP_Post ? wc_get_order($post_or_order_object->ID) : $post_or_order_object; 601 if (! $order) {600 if (!$order) { 602 601 return; 603 602 } … … 624 623 $order = wc_get_order($order_id); 625 624 626 if (! $order) {625 if (!$order) { 627 626 wp_send_json_error(esc_html__('Invalid order.', 'ilachat')); 628 627 } … … 633 632 } 634 633 635 if (! (is_user_logged_in() && current_user_can('edit_shop_orders', $order_id))) {634 if (!(is_user_logged_in() && current_user_can('edit_shop_orders', $order_id))) { 636 635 wp_send_json_error(esc_html__('You do not have permission to add notes to this order.', 'ilachat')); 637 636 } 638 637 639 638 $comment_id = self::add_order_note($order_id, $note); 640 if (! $comment_id) {639 if (!$comment_id) { 641 640 wp_send_json_error(esc_html__('Failed to add note.', 'ilachat')); 642 641 } … … 663 662 { 664 663 $order = wc_get_order($order_id); 665 if (! $order) {664 if (!$order) { 666 665 return false; 667 666 } … … 687 686 688 687 $comment_id = wp_insert_comment($comment_data); 689 if (! $comment_id) {688 if (!$comment_id) { 690 689 return false; 691 690 } … … 706 705 707 706 $comment_id = isset($_POST['comment_id']) ? absint($_POST['comment_id']) : 0; 708 if (! $comment_id) {707 if (!$comment_id) { 709 708 wp_send_json_error(esc_html__('Invalid comment ID.', 'ilachat')); 710 709 } 711 710 712 if (! (is_user_logged_in() && current_user_can('edit_shop_orders', $order_id))) {711 if (!(is_user_logged_in() && current_user_can('edit_shop_orders', $order_id))) { 713 712 wp_send_json_error(esc_html__('You do not have permission to add notes to this order.', 'ilachat')); 714 713 } 715 714 716 715 $result = self::delete_order_note($comment_id); 717 if (! $result) {716 if (!$result) { 718 717 wp_send_json_error(esc_html__('Failed to delete note.', 'ilachat')); 719 718 } … … 731 730 { 732 731 $comment = get_comment($comment_id); 733 if (! $comment || 'ilachat_order_note' !== $comment->comment_type) {732 if (!$comment || 'ilachat_order_note' !== $comment->comment_type) { 734 733 return false; 735 734 } 736 735 737 if (! (is_user_logged_in() && current_user_can('edit_shop_orders', $comment->comment_post_ID))) {736 if (!(is_user_logged_in() && current_user_can('edit_shop_orders', $comment->comment_post_ID))) { 738 737 return false; 739 738 } … … 752 751 { 753 752 $order = wc_get_order($order_id); 754 if (! $order) {753 if (!$order) { 755 754 return []; 756 755 } … … 795 794 { 796 795 if ( 797 ! isset($_POST['ilachat_sync_product_nonce']) ||798 ! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['ilachat_sync_product_nonce'])), 'ilachat_sync_product')796 !isset($_POST['ilachat_sync_product_nonce']) || 797 !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['ilachat_sync_product_nonce'])), 'ilachat_sync_product') 799 798 ) { 800 799 return; 801 800 } 802 801 803 if (! current_user_can('edit_post', $post_id)) {804 return; 805 } 806 807 if (! isset($_POST['ilachat_sync_product'])) {802 if (!current_user_can('edit_post', $post_id)) { 803 return; 804 } 805 806 if (!isset($_POST['ilachat_sync_product'])) { 808 807 return; 809 808 } 810 809 811 810 $product = wc_get_product($post_id); 812 if (! $product) {811 if (!$product) { 813 812 return; 814 813 } … … 825 824 public static function sync_product($product) 826 825 { 827 if (! $product) { 826 if (!Helper::is_ilachat_connected()) { 827 return false; 828 } 829 830 if (!$product) { 828 831 return; 829 832 } … … 833 836 } 834 837 835 if (! apply_filters('ilachat_should_sync_product', true, $product)) { 836 return; 837 } 838 839 $token = get_option('ilachat_token', ''); 840 if (empty($token)) { 838 if (!apply_filters('ilachat_should_sync_product', true, $product)) { 841 839 return; 842 840 } … … 872 870 foreach ($options_ids as $option_id) { 873 871 $term = get_term_by('id', $option_id, $attribute->get_name()); 874 if ($term && ! is_wp_error($term)) {872 if ($term && !is_wp_error($term)) { 875 873 $attr_options[] = $term->name; 876 874 } … … 895 893 $variation = wc_get_product($variation_id); 896 894 897 if (! $variation) {895 if (!$variation) { 898 896 continue; 899 897 } … … 960 958 { 961 959 $product = wc_get_product($post_id); 962 if (! $product) {960 if (!$product) { 963 961 return; 964 962 } 965 963 966 964 // Check if the user has permission to delete the product. 967 if (! current_user_can('delete_post', $post_id)) {965 if (!current_user_can('delete_post', $post_id)) { 968 966 return; 969 967 } … … 998 996 { 999 997 global $post; 1000 if (! $post || 'product' !== $post->post_type) {998 if (!$post || 'product' !== $post->post_type) { 1001 999 return; 1002 1000 } 1003 1001 1004 1002 $product = wc_get_product($post->ID); 1005 if (! $product) {1003 if (!$product) { 1006 1004 return; 1007 1005 } … … 1079 1077 public function sync_product_admin_notice() 1080 1078 { 1081 if (! isset($_GET['ilachat_sync_products'])) {1079 if (!isset($_GET['ilachat_sync_products'])) { 1082 1080 return; 1083 1081 } 1084 1082 1085 1083 // Verify nonce to ensure the notice is displayed only when coming from our bulk action. 1086 if (! isset($_GET['_wpnonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'])), 'bulk-posts')) {1084 if (!isset($_GET['_wpnonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'])), 'bulk-posts')) { 1087 1085 return; 1088 1086 } -
ilachat/tags/1.2.0/src/Integrations/Wordpress.php
r3295416 r3295458 6 6 use Ilachat\WpPlugin\Http\RequestMaker; 7 7 8 if (! defined('ABSPATH')) {8 if (!defined('ABSPATH')) { 9 9 exit; 10 10 } … … 107 107 'nonce' => wp_create_nonce('wp_rest'), 108 108 ]); 109 wp_set_script_translations( 'ilachat-editor-sync', 'ilachat');109 wp_set_script_translations('ilachat-editor-sync', 'ilachat'); 110 110 } 111 111 … … 118 118 public static function sync_post($post) 119 119 { 120 if (! $post) { 120 if (!Helper::is_ilachat_connected()) { 121 return false; 122 } 123 124 if (!$post) { 121 125 return false; 122 126 } … … 131 135 } 132 136 133 if (! apply_filters('ilachat_should_sync_post', true, $post)) { 134 return false; 135 } 136 137 $token = get_option('ilachat_token', ''); 138 if (empty($token)) { 137 if (!apply_filters('ilachat_should_sync_post', true, $post)) { 139 138 return false; 140 139 } … … 150 149 $categories_terms = get_the_terms($post_id, 'category'); 151 150 $categories_list = []; 152 if (! empty($categories_terms) && !is_wp_error($categories_terms)) {151 if (!empty($categories_terms) && !is_wp_error($categories_terms)) { 153 152 $categories_list = wp_list_pluck($categories_terms, 'name'); 154 153 } … … 158 157 $tags_terms = get_the_terms($post_id, 'post_tag'); 159 158 $tags_list = []; 160 if (! empty($tags_terms) && !is_wp_error($tags_terms)) {159 if (!empty($tags_terms) && !is_wp_error($tags_terms)) { 161 160 $tags_list = wp_list_pluck($tags_terms, 'name'); 162 161 } … … 177 176 // Remove empty values 178 177 $post_data = array_filter($post_data, function ($value) { 179 return ! empty($value);178 return !empty($value); 180 179 }); 181 180 … … 238 237 239 238 // Check if the post type is in the allowed list 240 if (! in_array($post->post_type, $this->post_types, true)) {239 if (!in_array($post->post_type, $this->post_types, true)) { 241 240 return; 242 241 } 243 242 244 243 // Check if the user has permission to edit the post 245 if (! current_user_can('edit_post', $post_id)) {244 if (!current_user_can('edit_post', $post_id)) { 246 245 return; 247 246 } … … 277 276 { 278 277 global $post; 279 if (! $post) {280 return; 281 } 282 if (! in_array($post->post_type, $this->post_types, true)) {278 if (!$post) { 279 return; 280 } 281 if (!in_array($post->post_type, $this->post_types, true)) { 283 282 return; 284 283 } … … 324 323 foreach ($post_ids as $post_id) { 325 324 // Check if the post is in the allowed post types 326 if (! in_array(get_post_type($post_id), $this->post_types, true)) {325 if (!in_array(get_post_type($post_id), $this->post_types, true)) { 327 326 continue; 328 327 } 329 328 330 329 // Check if the user has permission to edit the post 331 if (! current_user_can('edit_post', $post_id)) {330 if (!current_user_can('edit_post', $post_id)) { 332 331 continue; 333 332 } … … 363 362 public function sync_post_admin_notice() 364 363 { 365 if (! isset($_GET['ilachat_sync_posts'])) {364 if (!isset($_GET['ilachat_sync_posts'])) { 366 365 return; 367 366 } 368 367 369 368 // Verify nonce to ensure the notice is displayed only when coming from our bulk action. 370 if (! isset($_GET['_wpnonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'])), 'bulk-posts')) {369 if (!isset($_GET['_wpnonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'])), 'bulk-posts')) { 371 370 return; 372 371 } … … 412 411 public function handle_delete_post($post_id) 413 412 { 414 if (! in_array(get_post_type($post_id), $this->post_types, true)) {413 if (!in_array(get_post_type($post_id), $this->post_types, true)) { 415 414 return; 416 415 } 417 416 418 417 // Check if the user has permission to delete the post 419 if (! current_user_can('delete_post', $post_id)) {418 if (!current_user_can('delete_post', $post_id)) { 420 419 return; 421 420 } -
ilachat/tags/1.2.0/src/Plugin.php
r3295390 r3295458 8 8 use Ilachat\WpPlugin\Integrations\Wordpress; 9 9 use Ilachat\WpPlugin\Integrations\Woocommerce; 10 use Ilachat\WpPlugin\Helpers\Helper; 10 11 11 if (! defined('ABSPATH')) {12 if (!defined('ABSPATH')) { 12 13 exit; 13 14 } … … 30 31 } 31 32 32 $wordpress = new Wordpress(); 33 $wordpress->init(); 33 if (Helper::is_ilachat_connected()) { 34 $wordpress = new Wordpress(); 35 $wordpress->init(); 34 36 35 if (class_exists('WooCommerce')) { 36 $woocommerce = new Woocommerce(); 37 $woocommerce->init(); 37 if (class_exists('WooCommerce')) { 38 $woocommerce = new Woocommerce(); 39 $woocommerce->init(); 40 } 38 41 } 39 42 -
ilachat/tags/1.2.0/templates/admin/wc-integration-page.php
r3295390 r3295458 7 7 */ 8 8 9 if (! defined('ABSPATH')) {9 if (!defined('ABSPATH')) { 10 10 exit; // Exit if accessed directly. 11 11 } -
ilachat/tags/1.2.0/templates/admin/wc-order-notes.php
r3295390 r3295458 13 13 */ 14 14 15 if (! defined('ABSPATH')) {15 if (!defined('ABSPATH')) { 16 16 exit; 17 17 } … … 24 24 <div id="ilachat_order_notes" data-order_id="<?php echo esc_attr($order_id); ?>"> 25 25 <ul class="ilachat_order_notes"> 26 <?php if (! empty($order_notes)) : ?>26 <?php if (!empty($order_notes)) : ?> 27 27 <?php foreach ($order_notes as $note) : ?> 28 28 <li id="ilachat-note-<?php echo absint($note->comment_ID); ?>" class="note ilachat-note"> -
ilachat/trunk/src/Admin/Admin.php
r3295270 r3295458 3 3 namespace Ilachat\WpPlugin\Admin; 4 4 5 use Ilachat\WpPlugin\Helpers\TemplateLoader; 6 7 if (! defined('ABSPATH')) { 5 if (!defined('ABSPATH')) { 8 6 exit; 9 7 } 8 9 use Ilachat\WpPlugin\Helpers\TemplateLoader; 10 use Ilachat\WpPlugin\Helpers\Helper; 10 11 11 12 class Admin … … 59 60 public function render_settings_page() 60 61 { 61 $token = get_option('ilachat_token', ''); 62 63 if (empty($token)) { 64 TemplateLoader::get_template('admin/connect-page.php'); 65 } else { 62 if (Helper::is_ilachat_connected()) { 66 63 $bot_data = get_option('ilachat_bot', []); 67 64 TemplateLoader::get_template( … … 71 68 ] 72 69 ); 70 } else { 71 TemplateLoader::get_template('admin/connect-page.php'); 73 72 } 74 73 } … … 82 81 { 83 82 $screen = get_current_screen(); 84 if (! $screen) {83 if (!$screen) { 85 84 return; 86 85 } … … 192 191 { 193 192 // Check if the current user has the required permissions 194 if (! current_user_can('manage_options')) {193 if (!current_user_can('manage_options')) { 195 194 wp_send_json_error(__('You do not have permission to perform this action.', 'ilachat')); 196 195 } … … 200 199 ? sanitize_text_field(wp_unslash($_POST['ilachat_global_settings_nonce_field'])) 201 200 : ''; 202 if (empty($nonce_field) || ! wp_verify_nonce($nonce_field, 'ilachat_global_settings_nonce')) {201 if (empty($nonce_field) || !wp_verify_nonce($nonce_field, 'ilachat_global_settings_nonce')) { 203 202 wp_send_json_error(['message' => __('Invalid nonce.', 'ilachat')]); 204 203 } -
ilachat/trunk/src/Admin/Connection.php
r3295364 r3295458 3 3 namespace Ilachat\WpPlugin\Admin; 4 4 5 if (! defined('ABSPATH')) {5 if (!defined('ABSPATH')) { 6 6 exit; 7 7 } 8 8 9 9 use Ilachat\WpPlugin\Http\RequestMaker; 10 use Ilachat\WpPlugin\Helpers\Helper; 10 11 11 12 class Connection … … 38 39 { 39 40 if ( 40 ! isset($_POST['ilachat_action'])41 !isset($_POST['ilachat_action']) 41 42 || $_POST['ilachat_action'] !== 'connect' 42 || ! check_admin_referer('ilachat_connect_nonce', 'ilachat_connect_nonce_field')43 || !check_admin_referer('ilachat_connect_nonce', 'ilachat_connect_nonce_field') 43 44 ) { 44 45 return; … … 68 69 { 69 70 if ( 70 ! isset($_POST['ilachat_action'])71 !isset($_POST['ilachat_action']) 71 72 || $_POST['ilachat_action'] !== 'disconnect' 72 || ! check_admin_referer('ilachat_disconnect_nonce', 'ilachat_disconnect_nonce_field')73 || !check_admin_referer('ilachat_disconnect_nonce', 'ilachat_disconnect_nonce_field') 73 74 ) { 74 75 return; … … 107 108 if ( 108 109 $pagenow !== 'admin.php' 109 || ! isset($_GET['page'])110 || !isset($_GET['page']) 110 111 || $_GET['page'] !== 'ilachat-settings' 111 112 ) { … … 119 120 120 121 if ( 121 ! isset($_GET['wpnonce'])122 || ! wp_verify_nonce(122 !isset($_GET['wpnonce']) 123 || !wp_verify_nonce( 123 124 sanitize_text_field(wp_unslash($_GET['wpnonce'])), 124 125 'ilachat_connect_nonce' … … 201 202 public static function fetch_bot_details($token = ''): array 202 203 { 203 $token = $token ?: get_option('ilachat_token', ''); 204 if (empty($token)) { 204 if (!Helper::is_ilachat_connected()) { 205 205 return []; 206 206 } … … 241 241 242 242 $bot = self::fetch_bot_details($token); 243 if (! empty($bot)) {243 if (!empty($bot)) { 244 244 $widget_code = $bot['widget']['jsCode'] ?? ''; 245 245 $widget_code = wp_strip_all_tags($widget_code); -
ilachat/trunk/src/Frontend/PublicClass.php
r3295270 r3295458 5 5 use Ilachat\WpPlugin\Admin\Connection; 6 6 7 if (! defined('ABSPATH')) {7 if (!defined('ABSPATH')) { 8 8 exit; 9 9 } … … 36 36 $widget_code = Connection::get_widget_code_with_cache(); 37 37 38 if (! $widget_code) {38 if (!$widget_code) { 39 39 return; 40 40 } -
ilachat/trunk/src/Helpers/Helper.php
r3295270 r3295458 64 64 }); 65 65 } 66 67 /** 68 * Is Ilachat connected. 69 * 70 * @return bool 71 */ 72 public static function is_ilachat_connected() 73 { 74 $token = get_option('ilachat_token', ''); 75 return !empty($token); 76 } 66 77 } -
ilachat/trunk/src/Http/RequestMaker.php
r3295270 r3295458 3 3 namespace Ilachat\WpPlugin\Http; 4 4 5 if (! defined('ABSPATH')) {5 if (!defined('ABSPATH')) { 6 6 exit; 7 7 } … … 41 41 $url = self::get_url($endpoint); 42 42 43 if (! empty($queryParams)) {43 if (!empty($queryParams)) { 44 44 $url = add_query_arg($queryParams, $url); 45 45 } -
ilachat/trunk/src/Integrations/Woocommerce.php
r3295364 r3295458 13 13 use Automattic\WooCommerce\Utilities\OrderUtil; 14 14 15 if (! defined('ABSPATH')) {15 if (!defined('ABSPATH')) { 16 16 exit; 17 17 } … … 133 133 public function sanitize_array($values) 134 134 { 135 if (! is_array($values)) {135 if (!is_array($values)) { 136 136 return []; 137 137 } … … 220 220 public function sync_variable_links() 221 221 { 222 $token = get_option('ilachat_token', ''); 223 if (empty($token)) { 222 if (!Helper::is_ilachat_connected()) { 224 223 return; 225 224 } … … 278 277 $integration_enabled = get_option('ilachat_woocommerce_integration_enabled', 1); 279 278 $order_tracking_enabled = get_option('ilachat_woocommerce_order_tracking_enabled', 1); 280 if (! $integration_enabled || !$order_tracking_enabled) {279 if (!$integration_enabled || !$order_tracking_enabled) { 281 280 return; 282 281 } … … 327 326 { 328 327 $order_tracking_enabled = get_option('ilachat_woocommerce_order_tracking_enabled', 1); 329 if (! $order_tracking_enabled) {328 if (!$order_tracking_enabled) { 330 329 return new WP_Error('order_tracking_disabled', esc_html__('Order tracking is disabled', 'ilachat'), ['status' => 400]); 331 330 } … … 335 334 $email = $request->get_param('email') ?: ''; 336 335 337 if (! $order_id) {336 if (!$order_id) { 338 337 return new WP_Error('missing_order_id', esc_html__('Order ID is required', 'ilachat'), ['status' => 400]); 339 338 } 340 339 341 340 $order = wc_get_order($order_id); 342 if (! $order) {341 if (!$order) { 343 342 return new WP_Error('no_order', esc_html__('Order not found', 'ilachat'), ['status' => 404]); 344 343 } … … 367 366 public function get_order_details($order) 368 367 { 369 if (! $order) {368 if (!$order) { 370 369 return []; 371 370 } … … 427 426 $data['items'] = []; 428 427 foreach ($order->get_items() as $item) { 429 if (! $item instanceof \WC_Order_Item_Product) {428 if (!$item instanceof \WC_Order_Item_Product) { 430 429 continue; 431 430 } … … 454 453 foreach ($order_notes as $note) { 455 454 // Skip notes that are not visible to the customer. 456 if (! $note->customer_note) {455 if (!$note->customer_note) { 457 456 continue; 458 457 } … … 505 504 { 506 505 $secret_key = $request->get_header('X-ILACHAT-SECRET-KEY') ?: ''; 507 if (! $secret_key || !hash_equals($this->get_secret_key(), $secret_key)) {506 if (!$secret_key || !hash_equals($this->get_secret_key(), $secret_key)) { 508 507 return false; 509 508 } … … 525 524 add_filter('comments_clauses', [$this, 'exclude_special_order_notes']); 526 525 527 if (! (bool) get_option('ilachat_woocommerce_order_special_note', 0)) {526 if (!(bool) get_option('ilachat_woocommerce_order_special_note', 0)) { 528 527 return; 529 528 } … … 599 598 { 600 599 $order = $post_or_order_object instanceof WP_Post ? wc_get_order($post_or_order_object->ID) : $post_or_order_object; 601 if (! $order) {600 if (!$order) { 602 601 return; 603 602 } … … 624 623 $order = wc_get_order($order_id); 625 624 626 if (! $order) {625 if (!$order) { 627 626 wp_send_json_error(esc_html__('Invalid order.', 'ilachat')); 628 627 } … … 633 632 } 634 633 635 if (! (is_user_logged_in() && current_user_can('edit_shop_orders', $order_id))) {634 if (!(is_user_logged_in() && current_user_can('edit_shop_orders', $order_id))) { 636 635 wp_send_json_error(esc_html__('You do not have permission to add notes to this order.', 'ilachat')); 637 636 } 638 637 639 638 $comment_id = self::add_order_note($order_id, $note); 640 if (! $comment_id) {639 if (!$comment_id) { 641 640 wp_send_json_error(esc_html__('Failed to add note.', 'ilachat')); 642 641 } … … 663 662 { 664 663 $order = wc_get_order($order_id); 665 if (! $order) {664 if (!$order) { 666 665 return false; 667 666 } … … 687 686 688 687 $comment_id = wp_insert_comment($comment_data); 689 if (! $comment_id) {688 if (!$comment_id) { 690 689 return false; 691 690 } … … 706 705 707 706 $comment_id = isset($_POST['comment_id']) ? absint($_POST['comment_id']) : 0; 708 if (! $comment_id) {707 if (!$comment_id) { 709 708 wp_send_json_error(esc_html__('Invalid comment ID.', 'ilachat')); 710 709 } 711 710 712 if (! (is_user_logged_in() && current_user_can('edit_shop_orders', $order_id))) {711 if (!(is_user_logged_in() && current_user_can('edit_shop_orders', $order_id))) { 713 712 wp_send_json_error(esc_html__('You do not have permission to add notes to this order.', 'ilachat')); 714 713 } 715 714 716 715 $result = self::delete_order_note($comment_id); 717 if (! $result) {716 if (!$result) { 718 717 wp_send_json_error(esc_html__('Failed to delete note.', 'ilachat')); 719 718 } … … 731 730 { 732 731 $comment = get_comment($comment_id); 733 if (! $comment || 'ilachat_order_note' !== $comment->comment_type) {732 if (!$comment || 'ilachat_order_note' !== $comment->comment_type) { 734 733 return false; 735 734 } 736 735 737 if (! (is_user_logged_in() && current_user_can('edit_shop_orders', $comment->comment_post_ID))) {736 if (!(is_user_logged_in() && current_user_can('edit_shop_orders', $comment->comment_post_ID))) { 738 737 return false; 739 738 } … … 752 751 { 753 752 $order = wc_get_order($order_id); 754 if (! $order) {753 if (!$order) { 755 754 return []; 756 755 } … … 795 794 { 796 795 if ( 797 ! isset($_POST['ilachat_sync_product_nonce']) ||798 ! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['ilachat_sync_product_nonce'])), 'ilachat_sync_product')796 !isset($_POST['ilachat_sync_product_nonce']) || 797 !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['ilachat_sync_product_nonce'])), 'ilachat_sync_product') 799 798 ) { 800 799 return; 801 800 } 802 801 803 if (! current_user_can('edit_post', $post_id)) {804 return; 805 } 806 807 if (! isset($_POST['ilachat_sync_product'])) {802 if (!current_user_can('edit_post', $post_id)) { 803 return; 804 } 805 806 if (!isset($_POST['ilachat_sync_product'])) { 808 807 return; 809 808 } 810 809 811 810 $product = wc_get_product($post_id); 812 if (! $product) {811 if (!$product) { 813 812 return; 814 813 } … … 825 824 public static function sync_product($product) 826 825 { 827 if (! $product) { 826 if (!Helper::is_ilachat_connected()) { 827 return false; 828 } 829 830 if (!$product) { 828 831 return; 829 832 } … … 833 836 } 834 837 835 if (! apply_filters('ilachat_should_sync_product', true, $product)) { 836 return; 837 } 838 839 $token = get_option('ilachat_token', ''); 840 if (empty($token)) { 838 if (!apply_filters('ilachat_should_sync_product', true, $product)) { 841 839 return; 842 840 } … … 872 870 foreach ($options_ids as $option_id) { 873 871 $term = get_term_by('id', $option_id, $attribute->get_name()); 874 if ($term && ! is_wp_error($term)) {872 if ($term && !is_wp_error($term)) { 875 873 $attr_options[] = $term->name; 876 874 } … … 895 893 $variation = wc_get_product($variation_id); 896 894 897 if (! $variation) {895 if (!$variation) { 898 896 continue; 899 897 } … … 960 958 { 961 959 $product = wc_get_product($post_id); 962 if (! $product) {960 if (!$product) { 963 961 return; 964 962 } 965 963 966 964 // Check if the user has permission to delete the product. 967 if (! current_user_can('delete_post', $post_id)) {965 if (!current_user_can('delete_post', $post_id)) { 968 966 return; 969 967 } … … 998 996 { 999 997 global $post; 1000 if (! $post || 'product' !== $post->post_type) {998 if (!$post || 'product' !== $post->post_type) { 1001 999 return; 1002 1000 } 1003 1001 1004 1002 $product = wc_get_product($post->ID); 1005 if (! $product) {1003 if (!$product) { 1006 1004 return; 1007 1005 } … … 1079 1077 public function sync_product_admin_notice() 1080 1078 { 1081 if (! isset($_GET['ilachat_sync_products'])) {1079 if (!isset($_GET['ilachat_sync_products'])) { 1082 1080 return; 1083 1081 } 1084 1082 1085 1083 // Verify nonce to ensure the notice is displayed only when coming from our bulk action. 1086 if (! isset($_GET['_wpnonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'])), 'bulk-posts')) {1084 if (!isset($_GET['_wpnonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'])), 'bulk-posts')) { 1087 1085 return; 1088 1086 } -
ilachat/trunk/src/Integrations/Wordpress.php
r3295416 r3295458 6 6 use Ilachat\WpPlugin\Http\RequestMaker; 7 7 8 if (! defined('ABSPATH')) {8 if (!defined('ABSPATH')) { 9 9 exit; 10 10 } … … 107 107 'nonce' => wp_create_nonce('wp_rest'), 108 108 ]); 109 wp_set_script_translations( 'ilachat-editor-sync', 'ilachat');109 wp_set_script_translations('ilachat-editor-sync', 'ilachat'); 110 110 } 111 111 … … 118 118 public static function sync_post($post) 119 119 { 120 if (! $post) { 120 if (!Helper::is_ilachat_connected()) { 121 return false; 122 } 123 124 if (!$post) { 121 125 return false; 122 126 } … … 131 135 } 132 136 133 if (! apply_filters('ilachat_should_sync_post', true, $post)) { 134 return false; 135 } 136 137 $token = get_option('ilachat_token', ''); 138 if (empty($token)) { 137 if (!apply_filters('ilachat_should_sync_post', true, $post)) { 139 138 return false; 140 139 } … … 150 149 $categories_terms = get_the_terms($post_id, 'category'); 151 150 $categories_list = []; 152 if (! empty($categories_terms) && !is_wp_error($categories_terms)) {151 if (!empty($categories_terms) && !is_wp_error($categories_terms)) { 153 152 $categories_list = wp_list_pluck($categories_terms, 'name'); 154 153 } … … 158 157 $tags_terms = get_the_terms($post_id, 'post_tag'); 159 158 $tags_list = []; 160 if (! empty($tags_terms) && !is_wp_error($tags_terms)) {159 if (!empty($tags_terms) && !is_wp_error($tags_terms)) { 161 160 $tags_list = wp_list_pluck($tags_terms, 'name'); 162 161 } … … 177 176 // Remove empty values 178 177 $post_data = array_filter($post_data, function ($value) { 179 return ! empty($value);178 return !empty($value); 180 179 }); 181 180 … … 238 237 239 238 // Check if the post type is in the allowed list 240 if (! in_array($post->post_type, $this->post_types, true)) {239 if (!in_array($post->post_type, $this->post_types, true)) { 241 240 return; 242 241 } 243 242 244 243 // Check if the user has permission to edit the post 245 if (! current_user_can('edit_post', $post_id)) {244 if (!current_user_can('edit_post', $post_id)) { 246 245 return; 247 246 } … … 277 276 { 278 277 global $post; 279 if (! $post) {280 return; 281 } 282 if (! in_array($post->post_type, $this->post_types, true)) {278 if (!$post) { 279 return; 280 } 281 if (!in_array($post->post_type, $this->post_types, true)) { 283 282 return; 284 283 } … … 324 323 foreach ($post_ids as $post_id) { 325 324 // Check if the post is in the allowed post types 326 if (! in_array(get_post_type($post_id), $this->post_types, true)) {325 if (!in_array(get_post_type($post_id), $this->post_types, true)) { 327 326 continue; 328 327 } 329 328 330 329 // Check if the user has permission to edit the post 331 if (! current_user_can('edit_post', $post_id)) {330 if (!current_user_can('edit_post', $post_id)) { 332 331 continue; 333 332 } … … 363 362 public function sync_post_admin_notice() 364 363 { 365 if (! isset($_GET['ilachat_sync_posts'])) {364 if (!isset($_GET['ilachat_sync_posts'])) { 366 365 return; 367 366 } 368 367 369 368 // Verify nonce to ensure the notice is displayed only when coming from our bulk action. 370 if (! isset($_GET['_wpnonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'])), 'bulk-posts')) {369 if (!isset($_GET['_wpnonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'])), 'bulk-posts')) { 371 370 return; 372 371 } … … 412 411 public function handle_delete_post($post_id) 413 412 { 414 if (! in_array(get_post_type($post_id), $this->post_types, true)) {413 if (!in_array(get_post_type($post_id), $this->post_types, true)) { 415 414 return; 416 415 } 417 416 418 417 // Check if the user has permission to delete the post 419 if (! current_user_can('delete_post', $post_id)) {418 if (!current_user_can('delete_post', $post_id)) { 420 419 return; 421 420 } -
ilachat/trunk/src/Plugin.php
r3295270 r3295458 8 8 use Ilachat\WpPlugin\Integrations\Wordpress; 9 9 use Ilachat\WpPlugin\Integrations\Woocommerce; 10 use Ilachat\WpPlugin\Helpers\Helper; 10 11 11 if (! defined('ABSPATH')) {12 if (!defined('ABSPATH')) { 12 13 exit; 13 14 } … … 30 31 } 31 32 32 $wordpress = new Wordpress(); 33 $wordpress->init(); 33 if (Helper::is_ilachat_connected()) { 34 $wordpress = new Wordpress(); 35 $wordpress->init(); 34 36 35 if (class_exists('WooCommerce')) { 36 $woocommerce = new Woocommerce(); 37 $woocommerce->init(); 37 if (class_exists('WooCommerce')) { 38 $woocommerce = new Woocommerce(); 39 $woocommerce->init(); 40 } 38 41 } 39 42 -
ilachat/trunk/templates/admin/wc-integration-page.php
r3295270 r3295458 7 7 */ 8 8 9 if (! defined('ABSPATH')) {9 if (!defined('ABSPATH')) { 10 10 exit; // Exit if accessed directly. 11 11 } -
ilachat/trunk/templates/admin/wc-order-notes.php
r3295270 r3295458 13 13 */ 14 14 15 if (! defined('ABSPATH')) {15 if (!defined('ABSPATH')) { 16 16 exit; 17 17 } … … 24 24 <div id="ilachat_order_notes" data-order_id="<?php echo esc_attr($order_id); ?>"> 25 25 <ul class="ilachat_order_notes"> 26 <?php if (! empty($order_notes)) : ?>26 <?php if (!empty($order_notes)) : ?> 27 27 <?php foreach ($order_notes as $note) : ?> 28 28 <li id="ilachat-note-<?php echo absint($note->comment_ID); ?>" class="note ilachat-note">
Note: See TracChangeset
for help on using the changeset viewer.