Changeset 3110705
- Timestamp:
- 07/01/2024 06:15:46 PM (21 months ago)
- Location:
- api2cart-bridge-connector/trunk
- Files:
-
- 2 edited
- 1 moved
-
api2cart-bridge-connector.php (moved) (moved from api2cart-bridge-connector/trunk/connectorMain.php) (1 diff)
-
bridge2cart/bridge.php (modified) (22 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
api2cart-bridge-connector/trunk/api2cart-bridge-connector.php
r3110704 r3110705 5 5 Author: API2Cart 6 6 Author URI: https://api2cart.com/ 7 Version: 2.5. 37 Version: 2.5.4 8 8 */ 9 9 -
api2cart-bridge-connector/trunk/bridge2cart/bridge.php
r3091096 r3110705 916 916 } 917 917 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; 921 921 $this->categoriesImagesDir = $this->imagesDir . 'category_images' . DIRECTORY_SEPARATOR; 922 922 $this->productsImagesDir = $this->imagesDir . 'product_images' . DIRECTORY_SEPARATOR; 923 923 $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 . ''; 926 926 $this->categoriesImagesDir = $this->imagesDir . 'wpsc' . DIRECTORY_SEPARATOR . 'category_images' . DIRECTORY_SEPARATOR; 927 927 $this->productsImagesDir = $this->imagesDir; … … 980 980 981 981 if ( defined( 'WP_CONTENT_URL' ) ) { 982 $this->cartVars['wp_content_url'] = WP_CONTENT_URL;982 $this->cartVars['wp_content_url'] = content_url(); 983 983 } 984 984 } elseif ( defined( 'WP_CONTENT_URL' ) ) { 985 $this->cartVars['wp_content_url'] = WP_CONTENT_URL;985 $this->cartVars['wp_content_url'] = content_url(); 986 986 } 987 987 … … 1119 1119 1120 1120 // 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' ), 1123 1123 $trackingProvider, 1124 1124 $trackingNumber ); … … 1307 1307 1308 1308 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'] ); 1310 1310 } 1311 1311 } catch ( Exception $e ) { … … 1338 1338 }; 1339 1339 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 admin1350 $adminId = $userId->ID;1351 break;1352 }1353 }1354 1355 return $adminId;1356 };1357 1358 1340 try { 1359 1341 if ( function_exists( 'switch_to_blog' ) ) { … … 1369 1351 if ( empty( $a2cData['from'] ) ) { 1370 1352 /* 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'] ) ); 1372 1354 1373 1355 if ( empty( $a2cData['added_by_user'] ) ) { 1374 $ order->add_order_note($transition_note );1356 $this->_addOrderNote( $order->get_id(), $transition_note ); 1375 1357 } 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 ); 1383 1359 } 1384 1360 } else { 1385 1361 /* 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' ), 1387 1363 wc_get_order_status_name( $a2cData['from'] ), 1388 1364 wc_get_order_status_name( $a2cData['to'] ) ); 1389 1365 1390 1366 if ( empty( $a2cData['added_by_user'] ) ) { 1391 $ order->add_order_note($transition_note );1367 $this->_addOrderNote( $order->get_id(), $transition_note ); 1392 1368 } 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 ); 1400 1370 } 1401 1371 } … … 1546 1516 1547 1517 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 ); 1550 1519 } 1551 1520 … … 1555 1524 1556 1525 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 ); 1559 1527 } 1560 1528 … … 1671 1639 do_action( 'wpml_set_element_language_details', $setLanguageArgs ); 1672 1640 } 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' ) ); 1674 1642 } 1675 1643 } else { … … 1878 1846 if ( $file[ 'error' ] !== false ) { 1879 1847 /* 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 ) ); 1881 1849 } 1882 1850 … … 1888 1856 if ( !$parsedUrl || !is_array( $parsedUrl ) ) { 1889 1857 /* 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 ) ); 1891 1859 } 1892 1860 … … 1904 1872 throw new Exception( 1905 1873 /* 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( 1907 1875 /* translators: %s: Error message */ 1908 __( 'Error: %s', 'woocommerce' ),1876 esc_html__( 'Error: %s', 'api2cart-bridge-connector' ), 1909 1877 $fileArray[ 'tmp_name' ]->get_error_message() 1910 1878 ) … … 1931 1899 1932 1900 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' ) ); 1934 1902 } 1935 1903 … … 1948 1916 1949 1917 $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 ); 1951 1919 1952 1920 foreach ( $translations as $translation ) { … … 1967 1935 1968 1936 $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 ); 1970 1938 1971 1939 foreach ( $translations as $translation ) { … … 2131 2099 if ( !class_exists( $className ) ) { 2132 2100 /* 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 ) ); 2134 2102 } 2135 2103 … … 2230 2198 $sitepress = WPML\Container\make( '\SitePress' ); 2231 2199 2232 $activeLanguages = apply_filters( 'wpml_active_languages', null, '');2200 $activeLanguages = $sitepress->get_active_languages( true ); 2233 2201 $productLangCode = apply_filters( 'wpml_element_language_code', null, ['element_id' => $productId, 'element_type' => 'post_product'] ); 2234 2202 $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 ); 2236 2204 2237 2205 if ( isset( $a2cData['product_data']['terms_data']['product_cat'] ) ) { … … 2254 2222 do_action( 'wpml_switch_language', $a2cData['product_data']['internal_data']['wpml_only_translate_to'] ); 2255 2223 $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 ); 2257 2225 } 2258 2226 … … 2429 2397 if ( isset( $a2cData['product_data']['protected_data'] ) ) { 2430 2398 $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 ); 2432 2400 2433 2401 foreach ( $productTranslations as $translation ) { 2434 2402 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 2436 2415 $wpdb->query( 2437 2416 $wpdb->prepare(" 2438 2417 UPDATE {$wpdb->posts} 2439 SET {$ wpdb->prepare( $fields, ...array_values( $a2cData['product_data']['protected_data'][ $translation->language_code ] ) )}2418 SET {$fields} 2440 2419 WHERE ID = %d", 2441 $ translation->element_id2420 $values 2442 2421 ) 2443 2422 ); … … 2518 2497 if ( defined( 'ICL_SITEPRESS_VERSION' ) && defined( 'ICL_PLUGIN_INACTIVE' ) && !ICL_PLUGIN_INACTIVE && class_exists( 'SitePress' ) ) { 2519 2498 $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 ); 2521 2500 2522 2501 foreach ( $productTranslations as $translation ) { … … 2537 2516 } catch ( Throwable $e ) { 2538 2517 } 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; 2539 2581 } 2540 2582 } … … 3697 3739 if ( ! defined( 'ABSPATH' ) ) exit; 3698 3740 3699 define( 'A2CBC_BRIDGE_VERSION', '15 3' );3741 define( 'A2CBC_BRIDGE_VERSION', '156' ); 3700 3742 define( 'A2CBC_BRIDGE_CHECK_REQUEST_KEY_LINK', 'http://app.api2cart.com/request/key/check' ); 3701 3743 define( 'A2CBC_BRIDGE_DIRECTORY_NAME', basename( getcwd() ) ); -
api2cart-bridge-connector/trunk/readme.txt
r3091096 r3110705 86 86 = 2.5.2 =* Fix bug 87 87 = 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.