Plugin Directory

Changeset 3110705


Ignore:
Timestamp:
07/01/2024 06:15:46 PM (21 months ago)
Author:
api2cartdev
Message:

Updated to 2.5.4

Location:
api2cart-bridge-connector/trunk
Files:
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • api2cart-bridge-connector/trunk/api2cart-bridge-connector.php

    r3110704 r3110705  
    55Author: API2Cart
    66Author URI: https://api2cart.com/
    7 Version: 2.5.3
     7Version: 2.5.4
    88*/
    99
  • api2cart-bridge-connector/trunk/bridge2cart/bridge.php

    r3091096 r3110705  
    916916        }
    917917
    918         if ( file_exists( A2CBC_STORE_BASE_DIR . 'wp-content' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'shopp' . DIRECTORY_SEPARATOR . 'Shopp.php' )
    919                  || file_exists( A2CBC_STORE_BASE_DIR . 'wp-content' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'wp-e-commerce' . DIRECTORY_SEPARATOR . 'editor.php' ) ) {
    920             $this->imagesDir              = 'wp-content' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'wpsc' . DIRECTORY_SEPARATOR;
     918        if ( file_exists( WP_CONTENT_DIR. DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'shopp' . DIRECTORY_SEPARATOR . 'Shopp.php' )
     919         || file_exists( WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'wp-e-commerce' . DIRECTORY_SEPARATOR . 'editor.php' ) ) {
     920            $this->imagesDir              = wp_upload_dir( null, false )['basedir'] . DIRECTORY_SEPARATOR . 'wpsc' . DIRECTORY_SEPARATOR;
    921921            $this->categoriesImagesDir    = $this->imagesDir . 'category_images' . DIRECTORY_SEPARATOR;
    922922            $this->productsImagesDir      = $this->imagesDir . 'product_images' . DIRECTORY_SEPARATOR;
    923923            $this->manufacturersImagesDir = $this->imagesDir;
    924         } elseif ( file_exists( A2CBC_STORE_BASE_DIR . 'wp-content' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'wp-e-commerce' . DIRECTORY_SEPARATOR . 'wp-shopping-cart.php' ) ) {
    925             $this->imagesDir              = 'wp-content' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . '';
     924        } elseif ( file_exists( WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'wp-e-commerce' . DIRECTORY_SEPARATOR . 'wp-shopping-cart.php' ) ) {
     925            $this->imagesDir              = wp_upload_dir( null, false )['basedir'] . DIRECTORY_SEPARATOR . '';
    926926            $this->categoriesImagesDir    = $this->imagesDir . 'wpsc' . DIRECTORY_SEPARATOR . 'category_images' . DIRECTORY_SEPARATOR;
    927927            $this->productsImagesDir      = $this->imagesDir;
     
    980980
    981981                if ( defined( 'WP_CONTENT_URL' ) ) {
    982                     $this->cartVars['wp_content_url'] = WP_CONTENT_URL;
     982                    $this->cartVars['wp_content_url'] = content_url();
    983983                }
    984984            } elseif ( defined( 'WP_CONTENT_URL' ) ) {
    985                 $this->cartVars['wp_content_url'] = WP_CONTENT_URL;
     985                $this->cartVars['wp_content_url'] = content_url();
    986986            }
    987987
     
    11191119
    11201120                            // translators: %1$s is the tracking provider, %2$s is the tracking number
    1121                             $note = sprintf( __( 'Tracking info was deleted for tracking provider %1$s with tracking number %2$s',
    1122                                 'woo-advanced-shipment-tracking' ),
     1121                            $note = sprintf( esc_html__( 'Tracking info was deleted for tracking provider %1$s with tracking number %2$s',
     1122                                'api2cart-bridge-connector' ),
    11231123                                $trackingProvider,
    11241124                                $trackingNumber );
     
    13071307
    13081308            foreach ( $a2cData['strings'] as $key => $stringData ) {
    1309                 $response['result'][ $key ] = call_user_func('__', $stringData['id'], $stringData['domain'] );
     1309                $response['result'][ $key ] = call_user_func('esc_html__', $stringData['id'], $stringData['domain'] );
    13101310            }
    13111311        } catch ( Exception $e ) {
     
    13381338        };
    13391339
    1340         $getAdminId = function () {
    1341             global $wpdb;
    1342 
    1343             $wpUserSearch = $wpdb->get_results( 'SELECT ID FROM ' . $wpdb->users . ' ORDER BY ID' );
    1344             $adminId      = false;
    1345 
    1346             foreach ( $wpUserSearch as $userId ) {
    1347                 $currentUser = get_userdata( $userId->ID );
    1348 
    1349                 if ( ! empty( $currentUser->user_level ) && $currentUser->user_level >= 8 ) {//levels 8, 9 and 10 are admin
    1350                     $adminId = $userId->ID;
    1351                     break;
    1352                 }
    1353             }
    1354 
    1355             return $adminId;
    1356         };
    1357 
    13581340        try {
    13591341            if ( function_exists( 'switch_to_blog' ) ) {
     
    13691351                if ( empty( $a2cData['from'] ) ) {
    13701352                    /* translators: %s: new order status */
    1371                     $transition_note = sprintf( __( 'Order status set to %s.', 'woocommerce' ), wc_get_order_status_name( $a2cData['to'] ) );
     1353                    $transition_note = sprintf( esc_html__( 'Order status set to %s.', 'api2cart-bridge-connector' ), wc_get_order_status_name( $a2cData['to'] ) );
    13721354
    13731355                    if ( empty( $a2cData['added_by_user'] ) ) {
    1374                         $order->add_order_note( $transition_note );
     1356                        $this->_addOrderNote( $order->get_id(), $transition_note );
    13751357                    } else {
    1376                         $adminId = $getAdminId();
    1377 
    1378                         if ( $adminId ) {
    1379                             wp_set_current_user( $adminId );
    1380                         }
    1381 
    1382                         $order->add_order_note( $transition_note, 0, true );
     1358                        $this->_addOrderNote( $order->get_id(), $transition_note, 0, true );
    13831359                    }
    13841360                } else {
    13851361                    /* translators: 1: old order status 2: new order status */
    1386                     $transition_note = sprintf( __( 'Order status changed from %1$s to %2$s.', 'woocommerce' ),
     1362                    $transition_note = sprintf( esc_html__( 'Order status changed from %1$s to %2$s.', 'api2cart-bridge-connector' ),
    13871363                        wc_get_order_status_name( $a2cData['from'] ),
    13881364                        wc_get_order_status_name( $a2cData['to'] ) );
    13891365
    13901366                    if ( empty( $a2cData['added_by_user'] ) ) {
    1391                         $order->add_order_note( $transition_note );
     1367                        $this->_addOrderNote( $order->get_id(), $transition_note );
    13921368                    } else {
    1393                         $adminId = $getAdminId();
    1394 
    1395                         if ( $adminId ) {
    1396                             wp_set_current_user( $adminId );
    1397                         }
    1398 
    1399                         $order->add_order_note( $transition_note, 0, true );
     1369                        $this->_addOrderNote( $order->get_id(), $transition_note, 0, true );
    14001370                    }
    14011371                }
     
    15461516
    15471517            if ( isset( $a2cData['order']['admin_comment'] ) ) {
    1548                 wp_set_current_user( $a2cData['order']['admin_comment']['admin_user_id'] );
    1549                 $entity->add_order_note( $a2cData['order']['admin_comment']['text'], 1 );
     1518                $this->_addOrderNote( $entity->get_id(), $a2cData['order']['admin_comment']['text'], 1 );
    15501519            }
    15511520
     
    15551524
    15561525            if ( isset( $a2cData['order']['admin_private_comment'] ) ) {
    1557                 wp_set_current_user( $a2cData['order']['admin_private_comment']['admin_user_id'] );
    1558                 $entity->add_order_note( $a2cData['order']['admin_private_comment']['text'], 0, true );
     1526                $this->_addOrderNote( $entity->get_id(), $a2cData['order']['admin_private_comment']['text'], 0, true );
    15591527            }
    15601528
     
    16711639                    do_action( 'wpml_set_element_language_details', $setLanguageArgs );
    16721640                } else {
    1673                     throw new Exception( __( '[BRIDGE ERROR]: Can\'t create category!', 'woocommerce' ) );
     1641                    throw new Exception( esc_html__( '[BRIDGE ERROR]: Can\'t create category!', 'api2cart-bridge-connector' ) );
    16741642                }
    16751643            } else {
     
    18781846                if ( $file[ 'error' ] !== false ) {
    18791847                    /* translators: %s: File name */
    1880                     throw new Exception( sprintf( __( '[BRIDGE ERROR]: File save failed %s!', 'woocommerce' ), $filename ) );
     1848                    throw new Exception( sprintf( esc_html__( '[BRIDGE ERROR]: File save failed %s!', 'api2cart-bridge-connector' ), $filename ) );
    18811849                }
    18821850
     
    18881856                if ( !$parsedUrl || !is_array( $parsedUrl ) ) {
    18891857                    /* translators: %s: Image Url */
    1890                     throw new Exception( sprintf( __( '[BRIDGE ERROR]: Invalid URL %s!', 'woocommerce' ), $parsedUrl ) );
     1858                    throw new Exception( sprintf( esc_html__( '[BRIDGE ERROR]: Invalid URL %s!', 'api2cart-bridge-connector' ), $parsedUrl ) );
    18911859                }
    18921860
     
    19041872                    throw new Exception(
    19051873                    /* translators: %s: Image Url */
    1906                         sprintf( __( '[BRIDGE ERROR]: Some error occurred while retrieving the remote image by URL: %s!', 'woocommerce' ), $imageUrl ) . ' ' . sprintf(
     1874                        sprintf( esc_html__( '[BRIDGE ERROR]: Some error occurred while retrieving the remote image by URL: %s!', 'api2cart-bridge-connector' ), $imageUrl ) . ' ' . sprintf(
    19071875                        /* translators: %s: Error message */
    1908                             __( 'Error: %s', 'woocommerce' ),
     1876                            esc_html__( 'Error: %s', 'api2cart-bridge-connector' ),
    19091877                            $fileArray[ 'tmp_name' ]->get_error_message()
    19101878                        )
     
    19311899
    19321900            if ( empty( $file['file'] ) ) {
    1933                 throw new Exception( __( '[BRIDGE ERROR]: No image has been uploaded!', 'woocommerce' ) );
     1901                throw new Exception( esc_html__( '[BRIDGE ERROR]: No image has been uploaded!', 'api2cart-bridge-connector' ) );
    19341902            }
    19351903
     
    19481916
    19491917                    $trid         = apply_filters( 'wpml_element_trid', null, $objectId, 'post_product' );
    1950                     $translations = apply_filters( 'wpml_get_element_translations', null, $trid, 'post_product' );
     1918                    $translations = apply_filters( 'wpml_get_element_translations', null, $trid, 'post_product', false, true );
    19511919
    19521920                    foreach ( $translations as $translation ) {
     
    19671935
    19681936                    $trid         = apply_filters( 'wpml_element_trid', null, $objectId, 'post_product_variation' );
    1969                     $translations = apply_filters( 'wpml_get_element_translations', null, $trid, 'post_product_variation' );
     1937                    $translations = apply_filters( 'wpml_get_element_translations', null, $trid, 'post_product_variation', false, true );
    19701938
    19711939                    foreach ( $translations as $translation ) {
     
    21312099        if ( !class_exists( $className ) ) {
    21322100            /* translators: %s: Class name */
    2133             throw new Exception( sprintf( __( '[BRIDGE ERROR]: Class %s not exist!', 'woocommerce' ), $className ) );
     2101            throw new Exception( sprintf( esc_html__( '[BRIDGE ERROR]: Class %s not exist!', 'api2cart-bridge-connector' ), $className ) );
    21342102        }
    21352103
     
    22302198            $sitepress = WPML\Container\make( '\SitePress' );
    22312199
    2232             $activeLanguages     = apply_filters( 'wpml_active_languages', null, '' );
     2200            $activeLanguages     = $sitepress->get_active_languages( true );
    22332201            $productLangCode     = apply_filters( 'wpml_element_language_code', null, ['element_id' => $productId, 'element_type' => 'post_product'] );
    22342202            $trIdProduct         = apply_filters( 'wpml_element_trid', null, $productId, 'post_product' );
    2235             $productTranslations = apply_filters( 'wpml_get_element_translations', null, $trIdProduct, 'post_product' );
     2203            $productTranslations = apply_filters( 'wpml_get_element_translations', null, $trIdProduct, 'post_product', false, true );
    22362204
    22372205            if ( isset( $a2cData['product_data']['terms_data']['product_cat'] ) ) {
     
    22542222                do_action( 'wpml_switch_language', $a2cData['product_data']['internal_data']['wpml_only_translate_to'] );
    22552223                $sitepress->make_duplicate( $productId, $a2cData['product_data']['internal_data']['wpml_only_translate_to'] );
    2256                 $productTranslations = apply_filters( 'wpml_get_element_translations', null, $trIdProduct, 'post_product' );
     2224                $productTranslations = apply_filters( 'wpml_get_element_translations', null, $trIdProduct, 'post_product', false, true );
    22572225            }
    22582226
     
    24292397        if ( isset( $a2cData['product_data']['protected_data'] ) ) {
    24302398            $trIdProduct         = apply_filters( 'wpml_element_trid', null, $productId, 'post_product' );
    2431             $productTranslations = apply_filters( 'wpml_get_element_translations', null, $trIdProduct, 'post_product' );
     2399            $productTranslations = apply_filters( 'wpml_get_element_translations', null, $trIdProduct, 'post_product', false, true );
    24322400
    24332401            foreach ( $productTranslations as $translation ) {
    24342402                if ( $productLangCode !== $translation->language_code && isset( $a2cData['product_data']['protected_data'][ $translation->language_code ] ) ) {
    2435                     $fields  = rtrim(implode( ' = %s,', array_keys( $a2cData['product_data']['protected_data'][ $translation->language_code ] ) ), ',' ) . ' = %s';
     2403                    $fieldAssignments = [];
     2404                    $values = [];
     2405
     2406                    foreach ($a2cData['product_data']['protected_data'][ $translation->language_code ] as $field => $value) {
     2407                        $fieldAssignments[] = "$field = %s";
     2408                        $values[] = $value;
     2409                    }
     2410
     2411                    $fields = implode(', ', $fieldAssignments);
     2412
     2413                    $values[] = $translation->element_id;
     2414
    24362415                    $wpdb->query(
    24372416                        $wpdb->prepare("
    24382417                            UPDATE {$wpdb->posts}
    2439                             SET {$wpdb->prepare( $fields, ...array_values( $a2cData['product_data']['protected_data'][ $translation->language_code ] ) )}
     2418                            SET {$fields}
    24402419                            WHERE ID = %d",
    2441                             $translation->element_id
     2420                            $values
    24422421                        )
    24432422                    );
     
    25182497            if ( defined( 'ICL_SITEPRESS_VERSION' ) && defined( 'ICL_PLUGIN_INACTIVE' ) && !ICL_PLUGIN_INACTIVE && class_exists( 'SitePress' ) ) {
    25192498                $trIdProduct         = apply_filters( 'wpml_element_trid', null, $productId, 'post_product' );
    2520                 $productTranslations = apply_filters( 'wpml_get_element_translations', null, $trIdProduct, 'post_product' );
     2499                $productTranslations = apply_filters( 'wpml_get_element_translations', null, $trIdProduct, 'post_product', false, true );
    25212500
    25222501                foreach ( $productTranslations as $translation ) {
     
    25372516        } catch ( Throwable $e ) {
    25382517        }
     2518    }
     2519
     2520    /**
     2521     * Adds a note (comment) to the order. Order must exist.
     2522     *
     2523     * @param string $orderId        Order ID
     2524     * @param string $note           Note to add.
     2525     * @param int    $isCustomerNote Is this a note for the customer?.
     2526     * @param bool   $addedByAdmin   Was the note added by a admin?
     2527     *
     2528     * @return int                       Comment ID.
     2529     */
     2530    protected function _addOrderNote( string $orderId, string $note, int $isCustomerNote = 0, bool $addedByAdmin = false ) {
     2531        if ($addedByAdmin) {
     2532            $comment_admin_email = get_option( 'admin_email' );
     2533            $user                = get_user_by( 'email', $comment_admin_email );
     2534
     2535            if ( $user ) {
     2536                $comment_author = $user->display_name;
     2537            } else {
     2538                $comment_author = $comment_admin_email;
     2539            }
     2540        } else {
     2541            $comment_author        = esc_html__( 'WooCommerce', '%plugin_slug%' );
     2542            $comment_author_email  = esc_html__( 'WooCommerce', '%plugin_slug%' ) . '@';
     2543            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) ) : 'noreply.com';
     2544            $comment_author_email  = sanitize_email( $comment_author_email );
     2545        }
     2546
     2547        $commentdata = apply_filters(
     2548            'woocommerce_new_order_note_data',
     2549            array(
     2550                'comment_post_ID'      => $orderId,
     2551                'comment_author'       => $comment_author,
     2552                'comment_author_email' => $comment_author_email,
     2553                'comment_author_url'   => '',
     2554                'comment_content'      => $note,
     2555                'comment_agent'        => 'WooCommerce',
     2556                'comment_type'         => 'order_note',
     2557                'comment_parent'       => 0,
     2558                'comment_approved'     => 1,
     2559            ),
     2560            array(
     2561                'order_id'         => $orderId,
     2562                'is_customer_note' => $isCustomerNote,
     2563            )
     2564        );
     2565
     2566        $commentId = wp_insert_comment( $commentdata );
     2567
     2568        if ( $isCustomerNote ) {
     2569            add_comment_meta( $commentId, 'is_customer_note', 1 );
     2570
     2571            do_action(
     2572                'woocommerce_new_customer_note',
     2573                array(
     2574                    'order_id'      => $orderId,
     2575                    'customer_note' => $commentdata['comment_content'],
     2576                )
     2577            );
     2578        }
     2579
     2580        return $commentId;
    25392581    }
    25402582}
     
    36973739if ( ! defined( 'ABSPATH' ) ) exit;
    36983740
    3699 define( 'A2CBC_BRIDGE_VERSION', '153' );
     3741define( 'A2CBC_BRIDGE_VERSION', '156' );
    37003742define( 'A2CBC_BRIDGE_CHECK_REQUEST_KEY_LINK', 'http://app.api2cart.com/request/key/check' );
    37013743define( 'A2CBC_BRIDGE_DIRECTORY_NAME', basename( getcwd() ) );
  • api2cart-bridge-connector/trunk/readme.txt

    r3091096 r3110705  
    8686= 2.5.2 =* Fix bug
    8787= 2.5.3 =* Fix bug
     88= 2.5.4 =*'Updated bridge to 156 version. The code was refactored to meet WordPress requirements'
Note: See TracChangeset for help on using the changeset viewer.