Plugin Directory

Changeset 3490339


Ignore:
Timestamp:
03/24/2026 08:09:20 PM (2 days ago)
Author:
srdjan121
Message:

Update plugin code for version 1.1.7

Location:
businesscentralconnector/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • businesscentralconnector/trunk/businesscentralconnector.php

    r3476671 r3490339  
    44 * Plugin URI: https://help.synfynal.com/articles/index.html
    55 * Description: Extends WooCommerce API for Business Central integration via Synfynal Connector. Requires Business Central/WooCommerce Connector from AppSource.
    6  * Version: 1.1.6
     6 * Version: 1.1.7
    77 * Author: Synfynal
    88 * Author URI: https://www.synfynal.com/
     
    213213
    214214add_action('woocommerce_rest_insert_customer', 'bccentralconnector_sync_elex_pricing', 20, 3);
     215
     216/**
     217 * =====================================================================
     218 * Polylang translation sync via REST API
     219 *
     220 * When a PUT/POST to /wp-json/wc/v3/products/{id} includes
     221 *   { "key": "should_update", "value": "true" }
     222 * in meta_data, this simulates an admin Save by creating a valid
     223 * Polylang nonce and calling wp_update_post in admin context.
     224 * This fires save_post with all hooks — including Polylang's sync
     225 * to translated products — exactly as the admin Save button does.
     226 * =====================================================================
     227 */
     228function bccentralconnector_handle_product_update(WC_Product $product, WP_REST_Request $request, bool $creating) {
     229    $user_agent = $request->get_header('user_agent');
     230    if (empty($user_agent) || stripos($user_agent, 'Synfynal') === false) {
     231        return;
     232    }
     233
     234    $meta_data = $request->get_param('meta_data');
     235    if (!is_array($meta_data)) {
     236        return;
     237    }
     238
     239    foreach ($meta_data as $meta) {
     240        if (isset($meta['key'], $meta['value']) && $meta['key'] === 'should_update') {
     241            if (filter_var($meta['value'], FILTER_VALIDATE_BOOLEAN)) {
     242                // Provide a valid Polylang nonce and briefly set admin context so
     243                // Polylang's save_post handler passes its security checks and
     244                // propagates meta to all translated product variants.
     245                $_POST['pll_nonce'] = wp_create_nonce('pll_language');
     246                add_filter('is_admin', '__return_true');
     247                wp_update_post(array('ID' => $product->get_id()));
     248                remove_filter('is_admin', '__return_true');
     249                unset($_POST['pll_nonce']);
     250            }
     251            return;
     252        }
     253    }
     254}
     255add_action('woocommerce_rest_insert_product_object', 'bccentralconnector_handle_product_update', 10, 3);
    215256
    216257/**
  • businesscentralconnector/trunk/readme.txt

    r3476671 r3490339  
    55Requires PHP: 7.0
    66Tested up to: 6.8
    7 Stable tag: 1.1.6
     7Stable tag: 1.1.7
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.