Plugin Directory

Changeset 3295458


Ignore:
Timestamp:
05/17/2025 09:51:41 PM (11 months ago)
Author:
ilachat
Message:

Tagging v1.2.0

Location:
ilachat
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • ilachat/tags/1.2.0/src/Admin/Admin.php

    r3295390 r3295458  
    33namespace Ilachat\WpPlugin\Admin;
    44
    5 use Ilachat\WpPlugin\Helpers\TemplateLoader;
    6 
    7 if (! defined('ABSPATH')) {
     5if (!defined('ABSPATH')) {
    86    exit;
    97}
     8
     9use Ilachat\WpPlugin\Helpers\TemplateLoader;
     10use Ilachat\WpPlugin\Helpers\Helper;
    1011
    1112class Admin
     
    5960    public function render_settings_page()
    6061    {
    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()) {
    6663            $bot_data = get_option('ilachat_bot', []);
    6764            TemplateLoader::get_template(
     
    7168                ]
    7269            );
     70        } else {
     71            TemplateLoader::get_template('admin/connect-page.php');
    7372        }
    7473    }
     
    8281    {
    8382        $screen = get_current_screen();
    84         if (! $screen) {
     83        if (!$screen) {
    8584            return;
    8685        }
     
    192191    {
    193192        // Check if the current user has the required permissions
    194         if (! current_user_can('manage_options')) {
     193        if (!current_user_can('manage_options')) {
    195194            wp_send_json_error(__('You do not have permission to perform this action.', 'ilachat'));
    196195        }
     
    200199            ? sanitize_text_field(wp_unslash($_POST['ilachat_global_settings_nonce_field']))
    201200            : '';
    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')) {
    203202            wp_send_json_error(['message' => __('Invalid nonce.', 'ilachat')]);
    204203        }
  • ilachat/tags/1.2.0/src/Admin/Connection.php

    r3295390 r3295458  
    33namespace Ilachat\WpPlugin\Admin;
    44
    5 if (! defined('ABSPATH')) {
     5if (!defined('ABSPATH')) {
    66    exit;
    77}
    88
    99use Ilachat\WpPlugin\Http\RequestMaker;
     10use Ilachat\WpPlugin\Helpers\Helper;
    1011
    1112class Connection
     
    3839    {
    3940        if (
    40             ! isset($_POST['ilachat_action'])
     41            !isset($_POST['ilachat_action'])
    4142            || $_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')
    4344        ) {
    4445            return;
     
    6869    {
    6970        if (
    70             ! isset($_POST['ilachat_action'])
     71            !isset($_POST['ilachat_action'])
    7172            || $_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')
    7374        ) {
    7475            return;
     
    107108        if (
    108109            $pagenow !== 'admin.php'
    109             || ! isset($_GET['page'])
     110            || !isset($_GET['page'])
    110111            || $_GET['page'] !== 'ilachat-settings'
    111112        ) {
     
    119120
    120121        if (
    121             ! isset($_GET['wpnonce'])
    122             || ! wp_verify_nonce(
     122            !isset($_GET['wpnonce'])
     123            || !wp_verify_nonce(
    123124                sanitize_text_field(wp_unslash($_GET['wpnonce'])),
    124125                'ilachat_connect_nonce'
     
    201202    public static function fetch_bot_details($token = ''): array
    202203    {
    203         $token = $token ?: get_option('ilachat_token', '');
    204         if (empty($token)) {
     204        if (!Helper::is_ilachat_connected()) {
    205205            return [];
    206206        }
     
    241241
    242242        $bot = self::fetch_bot_details($token);
    243         if (! empty($bot)) {
     243        if (!empty($bot)) {
    244244            $widget_code = $bot['widget']['jsCode'] ?? '';
    245245            $widget_code = wp_strip_all_tags($widget_code);
  • ilachat/tags/1.2.0/src/Frontend/PublicClass.php

    r3295390 r3295458  
    55use Ilachat\WpPlugin\Admin\Connection;
    66
    7 if (! defined('ABSPATH')) {
     7if (!defined('ABSPATH')) {
    88    exit;
    99}
     
    3636        $widget_code = Connection::get_widget_code_with_cache();
    3737
    38         if (! $widget_code) {
     38        if (!$widget_code) {
    3939            return;
    4040        }
  • ilachat/tags/1.2.0/src/Helpers/Helper.php

    r3295390 r3295458  
    6464        });
    6565    }
     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    }
    6677}
  • ilachat/tags/1.2.0/src/Http/RequestMaker.php

    r3295270 r3295458  
    33namespace Ilachat\WpPlugin\Http;
    44
    5 if (! defined('ABSPATH')) {
     5if (!defined('ABSPATH')) {
    66    exit;
    77}
     
    4141        $url = self::get_url($endpoint);
    4242
    43         if (! empty($queryParams)) {
     43        if (!empty($queryParams)) {
    4444            $url = add_query_arg($queryParams, $url);
    4545        }
  • ilachat/tags/1.2.0/src/Integrations/Woocommerce.php

    r3295390 r3295458  
    1313use Automattic\WooCommerce\Utilities\OrderUtil;
    1414
    15 if (! defined('ABSPATH')) {
     15if (!defined('ABSPATH')) {
    1616    exit;
    1717}
     
    133133    public function sanitize_array($values)
    134134    {
    135         if (! is_array($values)) {
     135        if (!is_array($values)) {
    136136            return [];
    137137        }
     
    220220    public function sync_variable_links()
    221221    {
    222         $token = get_option('ilachat_token', '');
    223         if (empty($token)) {
     222        if (!Helper::is_ilachat_connected()) {
    224223            return;
    225224        }
     
    278277        $integration_enabled   = get_option('ilachat_woocommerce_integration_enabled', 1);
    279278        $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) {
    281280            return;
    282281        }
     
    327326    {
    328327        $order_tracking_enabled = get_option('ilachat_woocommerce_order_tracking_enabled', 1);
    329         if (! $order_tracking_enabled) {
     328        if (!$order_tracking_enabled) {
    330329            return new WP_Error('order_tracking_disabled', esc_html__('Order tracking is disabled', 'ilachat'), ['status' => 400]);
    331330        }
     
    335334        $email        = $request->get_param('email') ?: '';
    336335
    337         if (! $order_id) {
     336        if (!$order_id) {
    338337            return new WP_Error('missing_order_id', esc_html__('Order ID is required', 'ilachat'), ['status' => 400]);
    339338        }
    340339
    341340        $order = wc_get_order($order_id);
    342         if (! $order) {
     341        if (!$order) {
    343342            return new WP_Error('no_order', esc_html__('Order not found', 'ilachat'), ['status' => 404]);
    344343        }
     
    367366    public function get_order_details($order)
    368367    {
    369         if (! $order) {
     368        if (!$order) {
    370369            return [];
    371370        }
     
    427426            $data['items'] = [];
    428427            foreach ($order->get_items() as $item) {
    429                 if (! $item instanceof \WC_Order_Item_Product) {
     428                if (!$item instanceof \WC_Order_Item_Product) {
    430429                    continue;
    431430                }
     
    454453            foreach ($order_notes as $note) {
    455454                // Skip notes that are not visible to the customer.
    456                 if (! $note->customer_note) {
     455                if (!$note->customer_note) {
    457456                    continue;
    458457                }
     
    505504    {
    506505        $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)) {
    508507            return false;
    509508        }
     
    525524        add_filter('comments_clauses', [$this, 'exclude_special_order_notes']);
    526525
    527         if (! (bool) get_option('ilachat_woocommerce_order_special_note', 0)) {
     526        if (!(bool) get_option('ilachat_woocommerce_order_special_note', 0)) {
    528527            return;
    529528        }
     
    599598    {
    600599        $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) {
    602601            return;
    603602        }
     
    624623        $order    = wc_get_order($order_id);
    625624
    626         if (! $order) {
     625        if (!$order) {
    627626            wp_send_json_error(esc_html__('Invalid order.', 'ilachat'));
    628627        }
     
    633632        }
    634633
    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))) {
    636635            wp_send_json_error(esc_html__('You do not have permission to add notes to this order.', 'ilachat'));
    637636        }
    638637
    639638        $comment_id = self::add_order_note($order_id, $note);
    640         if (! $comment_id) {
     639        if (!$comment_id) {
    641640            wp_send_json_error(esc_html__('Failed to add note.', 'ilachat'));
    642641        }
     
    663662    {
    664663        $order = wc_get_order($order_id);
    665         if (! $order) {
     664        if (!$order) {
    666665            return false;
    667666        }
     
    687686
    688687        $comment_id = wp_insert_comment($comment_data);
    689         if (! $comment_id) {
     688        if (!$comment_id) {
    690689            return false;
    691690        }
     
    706705
    707706        $comment_id = isset($_POST['comment_id']) ? absint($_POST['comment_id']) : 0;
    708         if (! $comment_id) {
     707        if (!$comment_id) {
    709708            wp_send_json_error(esc_html__('Invalid comment ID.', 'ilachat'));
    710709        }
    711710
    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))) {
    713712            wp_send_json_error(esc_html__('You do not have permission to add notes to this order.', 'ilachat'));
    714713        }
    715714
    716715        $result = self::delete_order_note($comment_id);
    717         if (! $result) {
     716        if (!$result) {
    718717            wp_send_json_error(esc_html__('Failed to delete note.', 'ilachat'));
    719718        }
     
    731730    {
    732731        $comment = get_comment($comment_id);
    733         if (! $comment || 'ilachat_order_note' !== $comment->comment_type) {
     732        if (!$comment || 'ilachat_order_note' !== $comment->comment_type) {
    734733            return false;
    735734        }
    736735
    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))) {
    738737            return false;
    739738        }
     
    752751    {
    753752        $order = wc_get_order($order_id);
    754         if (! $order) {
     753        if (!$order) {
    755754            return [];
    756755        }
     
    795794    {
    796795        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')
    799798        ) {
    800799            return;
    801800        }
    802801
    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'])) {
    808807            return;
    809808        }
    810809
    811810        $product = wc_get_product($post_id);
    812         if (! $product) {
     811        if (!$product) {
    813812            return;
    814813        }
     
    825824    public static function sync_product($product)
    826825    {
    827         if (! $product) {
     826        if (!Helper::is_ilachat_connected()) {
     827            return false;
     828        }
     829
     830        if (!$product) {
    828831            return;
    829832        }
     
    833836        }
    834837
    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)) {
    841839            return;
    842840        }
     
    872870                foreach ($options_ids as $option_id) {
    873871                    $term = get_term_by('id', $option_id, $attribute->get_name());
    874                     if ($term && ! is_wp_error($term)) {
     872                    if ($term && !is_wp_error($term)) {
    875873                        $attr_options[] = $term->name;
    876874                    }
     
    895893                $variation = wc_get_product($variation_id);
    896894
    897                 if (! $variation) {
     895                if (!$variation) {
    898896                    continue;
    899897                }
     
    960958    {
    961959        $product = wc_get_product($post_id);
    962         if (! $product) {
     960        if (!$product) {
    963961            return;
    964962        }
    965963
    966964        // 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)) {
    968966            return;
    969967        }
     
    998996    {
    999997        global $post;
    1000         if (! $post || 'product' !== $post->post_type) {
     998        if (!$post || 'product' !== $post->post_type) {
    1001999            return;
    10021000        }
    10031001
    10041002        $product = wc_get_product($post->ID);
    1005         if (! $product) {
     1003        if (!$product) {
    10061004            return;
    10071005        }
     
    10791077    public function sync_product_admin_notice()
    10801078    {
    1081         if (! isset($_GET['ilachat_sync_products'])) {
     1079        if (!isset($_GET['ilachat_sync_products'])) {
    10821080            return;
    10831081        }
    10841082
    10851083        // 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')) {
    10871085            return;
    10881086        }
  • ilachat/tags/1.2.0/src/Integrations/Wordpress.php

    r3295416 r3295458  
    66use Ilachat\WpPlugin\Http\RequestMaker;
    77
    8 if (! defined('ABSPATH')) {
     8if (!defined('ABSPATH')) {
    99    exit;
    1010}
     
    107107            'nonce'       => wp_create_nonce('wp_rest'),
    108108        ]);
    109         wp_set_script_translations( 'ilachat-editor-sync', 'ilachat' );
     109        wp_set_script_translations('ilachat-editor-sync', 'ilachat');
    110110    }
    111111
     
    118118    public static function sync_post($post)
    119119    {
    120         if (! $post) {
     120        if (!Helper::is_ilachat_connected()) {
     121            return false;
     122        }
     123
     124        if (!$post) {
    121125            return false;
    122126        }
     
    131135        }
    132136
    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)) {
    139138            return false;
    140139        }
     
    150149        $categories_terms = get_the_terms($post_id, 'category');
    151150        $categories_list = [];
    152         if (! empty($categories_terms) && ! is_wp_error($categories_terms)) {
     151        if (!empty($categories_terms) && !is_wp_error($categories_terms)) {
    153152            $categories_list = wp_list_pluck($categories_terms, 'name');
    154153        }
     
    158157        $tags_terms = get_the_terms($post_id, 'post_tag');
    159158        $tags_list = [];
    160         if (! empty($tags_terms) && ! is_wp_error($tags_terms)) {
     159        if (!empty($tags_terms) && !is_wp_error($tags_terms)) {
    161160            $tags_list = wp_list_pluck($tags_terms, 'name');
    162161        }
     
    177176        // Remove empty values
    178177        $post_data = array_filter($post_data, function ($value) {
    179             return ! empty($value);
     178            return !empty($value);
    180179        });
    181180
     
    238237
    239238        // 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)) {
    241240            return;
    242241        }
    243242
    244243        // 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)) {
    246245            return;
    247246        }
     
    277276    {
    278277        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)) {
    283282            return;
    284283        }
     
    324323        foreach ($post_ids as $post_id) {
    325324            // 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)) {
    327326                continue;
    328327            }
    329328
    330329            // 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)) {
    332331                continue;
    333332            }
     
    363362    public function sync_post_admin_notice()
    364363    {
    365         if (! isset($_GET['ilachat_sync_posts'])) {
     364        if (!isset($_GET['ilachat_sync_posts'])) {
    366365            return;
    367366        }
    368367
    369368        // 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')) {
    371370            return;
    372371        }
     
    412411    public function handle_delete_post($post_id)
    413412    {
    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)) {
    415414            return;
    416415        }
    417416
    418417        // 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)) {
    420419            return;
    421420        }
  • ilachat/tags/1.2.0/src/Plugin.php

    r3295390 r3295458  
    88use Ilachat\WpPlugin\Integrations\Wordpress;
    99use Ilachat\WpPlugin\Integrations\Woocommerce;
     10use Ilachat\WpPlugin\Helpers\Helper;
    1011
    11 if (! defined('ABSPATH')) {
     12if (!defined('ABSPATH')) {
    1213    exit;
    1314}
     
    3031        }
    3132
    32         $wordpress = new Wordpress();
    33         $wordpress->init();
     33        if (Helper::is_ilachat_connected()) {
     34            $wordpress = new Wordpress();
     35            $wordpress->init();
    3436
    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            }
    3841        }
    3942
  • ilachat/tags/1.2.0/templates/admin/wc-integration-page.php

    r3295390 r3295458  
    77 */
    88
    9 if (! defined('ABSPATH')) {
     9if (!defined('ABSPATH')) {
    1010    exit; // Exit if accessed directly.
    1111}
  • ilachat/tags/1.2.0/templates/admin/wc-order-notes.php

    r3295390 r3295458  
    1313 */
    1414
    15 if (! defined('ABSPATH')) {
     15if (!defined('ABSPATH')) {
    1616    exit;
    1717}
     
    2424<div id="ilachat_order_notes" data-order_id="<?php echo esc_attr($order_id); ?>">
    2525    <ul class="ilachat_order_notes">
    26         <?php if (! empty($order_notes)) : ?>
     26        <?php if (!empty($order_notes)) : ?>
    2727            <?php foreach ($order_notes as $note) : ?>
    2828                <li id="ilachat-note-<?php echo absint($note->comment_ID); ?>" class="note ilachat-note">
  • ilachat/trunk/src/Admin/Admin.php

    r3295270 r3295458  
    33namespace Ilachat\WpPlugin\Admin;
    44
    5 use Ilachat\WpPlugin\Helpers\TemplateLoader;
    6 
    7 if (! defined('ABSPATH')) {
     5if (!defined('ABSPATH')) {
    86    exit;
    97}
     8
     9use Ilachat\WpPlugin\Helpers\TemplateLoader;
     10use Ilachat\WpPlugin\Helpers\Helper;
    1011
    1112class Admin
     
    5960    public function render_settings_page()
    6061    {
    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()) {
    6663            $bot_data = get_option('ilachat_bot', []);
    6764            TemplateLoader::get_template(
     
    7168                ]
    7269            );
     70        } else {
     71            TemplateLoader::get_template('admin/connect-page.php');
    7372        }
    7473    }
     
    8281    {
    8382        $screen = get_current_screen();
    84         if (! $screen) {
     83        if (!$screen) {
    8584            return;
    8685        }
     
    192191    {
    193192        // Check if the current user has the required permissions
    194         if (! current_user_can('manage_options')) {
     193        if (!current_user_can('manage_options')) {
    195194            wp_send_json_error(__('You do not have permission to perform this action.', 'ilachat'));
    196195        }
     
    200199            ? sanitize_text_field(wp_unslash($_POST['ilachat_global_settings_nonce_field']))
    201200            : '';
    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')) {
    203202            wp_send_json_error(['message' => __('Invalid nonce.', 'ilachat')]);
    204203        }
  • ilachat/trunk/src/Admin/Connection.php

    r3295364 r3295458  
    33namespace Ilachat\WpPlugin\Admin;
    44
    5 if (! defined('ABSPATH')) {
     5if (!defined('ABSPATH')) {
    66    exit;
    77}
    88
    99use Ilachat\WpPlugin\Http\RequestMaker;
     10use Ilachat\WpPlugin\Helpers\Helper;
    1011
    1112class Connection
     
    3839    {
    3940        if (
    40             ! isset($_POST['ilachat_action'])
     41            !isset($_POST['ilachat_action'])
    4142            || $_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')
    4344        ) {
    4445            return;
     
    6869    {
    6970        if (
    70             ! isset($_POST['ilachat_action'])
     71            !isset($_POST['ilachat_action'])
    7172            || $_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')
    7374        ) {
    7475            return;
     
    107108        if (
    108109            $pagenow !== 'admin.php'
    109             || ! isset($_GET['page'])
     110            || !isset($_GET['page'])
    110111            || $_GET['page'] !== 'ilachat-settings'
    111112        ) {
     
    119120
    120121        if (
    121             ! isset($_GET['wpnonce'])
    122             || ! wp_verify_nonce(
     122            !isset($_GET['wpnonce'])
     123            || !wp_verify_nonce(
    123124                sanitize_text_field(wp_unslash($_GET['wpnonce'])),
    124125                'ilachat_connect_nonce'
     
    201202    public static function fetch_bot_details($token = ''): array
    202203    {
    203         $token = $token ?: get_option('ilachat_token', '');
    204         if (empty($token)) {
     204        if (!Helper::is_ilachat_connected()) {
    205205            return [];
    206206        }
     
    241241
    242242        $bot = self::fetch_bot_details($token);
    243         if (! empty($bot)) {
     243        if (!empty($bot)) {
    244244            $widget_code = $bot['widget']['jsCode'] ?? '';
    245245            $widget_code = wp_strip_all_tags($widget_code);
  • ilachat/trunk/src/Frontend/PublicClass.php

    r3295270 r3295458  
    55use Ilachat\WpPlugin\Admin\Connection;
    66
    7 if (! defined('ABSPATH')) {
     7if (!defined('ABSPATH')) {
    88    exit;
    99}
     
    3636        $widget_code = Connection::get_widget_code_with_cache();
    3737
    38         if (! $widget_code) {
     38        if (!$widget_code) {
    3939            return;
    4040        }
  • ilachat/trunk/src/Helpers/Helper.php

    r3295270 r3295458  
    6464        });
    6565    }
     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    }
    6677}
  • ilachat/trunk/src/Http/RequestMaker.php

    r3295270 r3295458  
    33namespace Ilachat\WpPlugin\Http;
    44
    5 if (! defined('ABSPATH')) {
     5if (!defined('ABSPATH')) {
    66    exit;
    77}
     
    4141        $url = self::get_url($endpoint);
    4242
    43         if (! empty($queryParams)) {
     43        if (!empty($queryParams)) {
    4444            $url = add_query_arg($queryParams, $url);
    4545        }
  • ilachat/trunk/src/Integrations/Woocommerce.php

    r3295364 r3295458  
    1313use Automattic\WooCommerce\Utilities\OrderUtil;
    1414
    15 if (! defined('ABSPATH')) {
     15if (!defined('ABSPATH')) {
    1616    exit;
    1717}
     
    133133    public function sanitize_array($values)
    134134    {
    135         if (! is_array($values)) {
     135        if (!is_array($values)) {
    136136            return [];
    137137        }
     
    220220    public function sync_variable_links()
    221221    {
    222         $token = get_option('ilachat_token', '');
    223         if (empty($token)) {
     222        if (!Helper::is_ilachat_connected()) {
    224223            return;
    225224        }
     
    278277        $integration_enabled   = get_option('ilachat_woocommerce_integration_enabled', 1);
    279278        $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) {
    281280            return;
    282281        }
     
    327326    {
    328327        $order_tracking_enabled = get_option('ilachat_woocommerce_order_tracking_enabled', 1);
    329         if (! $order_tracking_enabled) {
     328        if (!$order_tracking_enabled) {
    330329            return new WP_Error('order_tracking_disabled', esc_html__('Order tracking is disabled', 'ilachat'), ['status' => 400]);
    331330        }
     
    335334        $email        = $request->get_param('email') ?: '';
    336335
    337         if (! $order_id) {
     336        if (!$order_id) {
    338337            return new WP_Error('missing_order_id', esc_html__('Order ID is required', 'ilachat'), ['status' => 400]);
    339338        }
    340339
    341340        $order = wc_get_order($order_id);
    342         if (! $order) {
     341        if (!$order) {
    343342            return new WP_Error('no_order', esc_html__('Order not found', 'ilachat'), ['status' => 404]);
    344343        }
     
    367366    public function get_order_details($order)
    368367    {
    369         if (! $order) {
     368        if (!$order) {
    370369            return [];
    371370        }
     
    427426            $data['items'] = [];
    428427            foreach ($order->get_items() as $item) {
    429                 if (! $item instanceof \WC_Order_Item_Product) {
     428                if (!$item instanceof \WC_Order_Item_Product) {
    430429                    continue;
    431430                }
     
    454453            foreach ($order_notes as $note) {
    455454                // Skip notes that are not visible to the customer.
    456                 if (! $note->customer_note) {
     455                if (!$note->customer_note) {
    457456                    continue;
    458457                }
     
    505504    {
    506505        $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)) {
    508507            return false;
    509508        }
     
    525524        add_filter('comments_clauses', [$this, 'exclude_special_order_notes']);
    526525
    527         if (! (bool) get_option('ilachat_woocommerce_order_special_note', 0)) {
     526        if (!(bool) get_option('ilachat_woocommerce_order_special_note', 0)) {
    528527            return;
    529528        }
     
    599598    {
    600599        $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) {
    602601            return;
    603602        }
     
    624623        $order    = wc_get_order($order_id);
    625624
    626         if (! $order) {
     625        if (!$order) {
    627626            wp_send_json_error(esc_html__('Invalid order.', 'ilachat'));
    628627        }
     
    633632        }
    634633
    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))) {
    636635            wp_send_json_error(esc_html__('You do not have permission to add notes to this order.', 'ilachat'));
    637636        }
    638637
    639638        $comment_id = self::add_order_note($order_id, $note);
    640         if (! $comment_id) {
     639        if (!$comment_id) {
    641640            wp_send_json_error(esc_html__('Failed to add note.', 'ilachat'));
    642641        }
     
    663662    {
    664663        $order = wc_get_order($order_id);
    665         if (! $order) {
     664        if (!$order) {
    666665            return false;
    667666        }
     
    687686
    688687        $comment_id = wp_insert_comment($comment_data);
    689         if (! $comment_id) {
     688        if (!$comment_id) {
    690689            return false;
    691690        }
     
    706705
    707706        $comment_id = isset($_POST['comment_id']) ? absint($_POST['comment_id']) : 0;
    708         if (! $comment_id) {
     707        if (!$comment_id) {
    709708            wp_send_json_error(esc_html__('Invalid comment ID.', 'ilachat'));
    710709        }
    711710
    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))) {
    713712            wp_send_json_error(esc_html__('You do not have permission to add notes to this order.', 'ilachat'));
    714713        }
    715714
    716715        $result = self::delete_order_note($comment_id);
    717         if (! $result) {
     716        if (!$result) {
    718717            wp_send_json_error(esc_html__('Failed to delete note.', 'ilachat'));
    719718        }
     
    731730    {
    732731        $comment = get_comment($comment_id);
    733         if (! $comment || 'ilachat_order_note' !== $comment->comment_type) {
     732        if (!$comment || 'ilachat_order_note' !== $comment->comment_type) {
    734733            return false;
    735734        }
    736735
    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))) {
    738737            return false;
    739738        }
     
    752751    {
    753752        $order = wc_get_order($order_id);
    754         if (! $order) {
     753        if (!$order) {
    755754            return [];
    756755        }
     
    795794    {
    796795        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')
    799798        ) {
    800799            return;
    801800        }
    802801
    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'])) {
    808807            return;
    809808        }
    810809
    811810        $product = wc_get_product($post_id);
    812         if (! $product) {
     811        if (!$product) {
    813812            return;
    814813        }
     
    825824    public static function sync_product($product)
    826825    {
    827         if (! $product) {
     826        if (!Helper::is_ilachat_connected()) {
     827            return false;
     828        }
     829
     830        if (!$product) {
    828831            return;
    829832        }
     
    833836        }
    834837
    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)) {
    841839            return;
    842840        }
     
    872870                foreach ($options_ids as $option_id) {
    873871                    $term = get_term_by('id', $option_id, $attribute->get_name());
    874                     if ($term && ! is_wp_error($term)) {
     872                    if ($term && !is_wp_error($term)) {
    875873                        $attr_options[] = $term->name;
    876874                    }
     
    895893                $variation = wc_get_product($variation_id);
    896894
    897                 if (! $variation) {
     895                if (!$variation) {
    898896                    continue;
    899897                }
     
    960958    {
    961959        $product = wc_get_product($post_id);
    962         if (! $product) {
     960        if (!$product) {
    963961            return;
    964962        }
    965963
    966964        // 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)) {
    968966            return;
    969967        }
     
    998996    {
    999997        global $post;
    1000         if (! $post || 'product' !== $post->post_type) {
     998        if (!$post || 'product' !== $post->post_type) {
    1001999            return;
    10021000        }
    10031001
    10041002        $product = wc_get_product($post->ID);
    1005         if (! $product) {
     1003        if (!$product) {
    10061004            return;
    10071005        }
     
    10791077    public function sync_product_admin_notice()
    10801078    {
    1081         if (! isset($_GET['ilachat_sync_products'])) {
     1079        if (!isset($_GET['ilachat_sync_products'])) {
    10821080            return;
    10831081        }
    10841082
    10851083        // 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')) {
    10871085            return;
    10881086        }
  • ilachat/trunk/src/Integrations/Wordpress.php

    r3295416 r3295458  
    66use Ilachat\WpPlugin\Http\RequestMaker;
    77
    8 if (! defined('ABSPATH')) {
     8if (!defined('ABSPATH')) {
    99    exit;
    1010}
     
    107107            'nonce'       => wp_create_nonce('wp_rest'),
    108108        ]);
    109         wp_set_script_translations( 'ilachat-editor-sync', 'ilachat' );
     109        wp_set_script_translations('ilachat-editor-sync', 'ilachat');
    110110    }
    111111
     
    118118    public static function sync_post($post)
    119119    {
    120         if (! $post) {
     120        if (!Helper::is_ilachat_connected()) {
     121            return false;
     122        }
     123
     124        if (!$post) {
    121125            return false;
    122126        }
     
    131135        }
    132136
    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)) {
    139138            return false;
    140139        }
     
    150149        $categories_terms = get_the_terms($post_id, 'category');
    151150        $categories_list = [];
    152         if (! empty($categories_terms) && ! is_wp_error($categories_terms)) {
     151        if (!empty($categories_terms) && !is_wp_error($categories_terms)) {
    153152            $categories_list = wp_list_pluck($categories_terms, 'name');
    154153        }
     
    158157        $tags_terms = get_the_terms($post_id, 'post_tag');
    159158        $tags_list = [];
    160         if (! empty($tags_terms) && ! is_wp_error($tags_terms)) {
     159        if (!empty($tags_terms) && !is_wp_error($tags_terms)) {
    161160            $tags_list = wp_list_pluck($tags_terms, 'name');
    162161        }
     
    177176        // Remove empty values
    178177        $post_data = array_filter($post_data, function ($value) {
    179             return ! empty($value);
     178            return !empty($value);
    180179        });
    181180
     
    238237
    239238        // 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)) {
    241240            return;
    242241        }
    243242
    244243        // 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)) {
    246245            return;
    247246        }
     
    277276    {
    278277        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)) {
    283282            return;
    284283        }
     
    324323        foreach ($post_ids as $post_id) {
    325324            // 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)) {
    327326                continue;
    328327            }
    329328
    330329            // 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)) {
    332331                continue;
    333332            }
     
    363362    public function sync_post_admin_notice()
    364363    {
    365         if (! isset($_GET['ilachat_sync_posts'])) {
     364        if (!isset($_GET['ilachat_sync_posts'])) {
    366365            return;
    367366        }
    368367
    369368        // 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')) {
    371370            return;
    372371        }
     
    412411    public function handle_delete_post($post_id)
    413412    {
    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)) {
    415414            return;
    416415        }
    417416
    418417        // 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)) {
    420419            return;
    421420        }
  • ilachat/trunk/src/Plugin.php

    r3295270 r3295458  
    88use Ilachat\WpPlugin\Integrations\Wordpress;
    99use Ilachat\WpPlugin\Integrations\Woocommerce;
     10use Ilachat\WpPlugin\Helpers\Helper;
    1011
    11 if (! defined('ABSPATH')) {
     12if (!defined('ABSPATH')) {
    1213    exit;
    1314}
     
    3031        }
    3132
    32         $wordpress = new Wordpress();
    33         $wordpress->init();
     33        if (Helper::is_ilachat_connected()) {
     34            $wordpress = new Wordpress();
     35            $wordpress->init();
    3436
    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            }
    3841        }
    3942
  • ilachat/trunk/templates/admin/wc-integration-page.php

    r3295270 r3295458  
    77 */
    88
    9 if (! defined('ABSPATH')) {
     9if (!defined('ABSPATH')) {
    1010    exit; // Exit if accessed directly.
    1111}
  • ilachat/trunk/templates/admin/wc-order-notes.php

    r3295270 r3295458  
    1313 */
    1414
    15 if (! defined('ABSPATH')) {
     15if (!defined('ABSPATH')) {
    1616    exit;
    1717}
     
    2424<div id="ilachat_order_notes" data-order_id="<?php echo esc_attr($order_id); ?>">
    2525    <ul class="ilachat_order_notes">
    26         <?php if (! empty($order_notes)) : ?>
     26        <?php if (!empty($order_notes)) : ?>
    2727            <?php foreach ($order_notes as $note) : ?>
    2828                <li id="ilachat-note-<?php echo absint($note->comment_ID); ?>" class="note ilachat-note">
Note: See TracChangeset for help on using the changeset viewer.