Changeset 3476671
- Timestamp:
- 03/06/2026 07:55:37 PM (3 weeks ago)
- Location:
- businesscentralconnector/trunk
- Files:
-
- 2 edited
-
businesscentralconnector.php (modified) (4 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
businesscentralconnector/trunk/businesscentralconnector.php
r3476596 r3476671 4 4 * Plugin URI: https://help.synfynal.com/articles/index.html 5 5 * Description: Extends WooCommerce API for Business Central integration via Synfynal Connector. Requires Business Central/WooCommerce Connector from AppSource. 6 * Version: 1.1. 56 * Version: 1.1.6 7 7 * Author: Synfynal 8 8 * Author URI: https://www.synfynal.com/ … … 119 119 // Option name ELEX uses to store its eligible users list. 120 120 define('BCCENTRALCONNECTOR_ELEX_OPTION', 'eh_pricing_discount_product_on_users'); 121 define('BCCENTRALCONNECTOR_ELEX_ROLE_OPTION', 'eh_pricing_discount_product_price_user_role'); 121 122 122 123 /** … … 227 228 add_action('rest_api_init', 'bccentralconnector_register_user_roles_endpoint'); 228 229 add_action('rest_api_init', 'bccentralconnector_register_ping_endpoint'); 230 add_action('rest_api_init', 'bccentralconnector_register_eligible_roles_endpoint'); 229 231 230 232 function bccentralconnector_register_user_roles_endpoint() { … … 326 328 /** 327 329 * ===================================================================== 330 * Custom REST endpoint: POST /wp-json/wc/v3/bccentralconnector/eligible-roles 331 * 332 * Adds the supplied role slugs to the ELEX eligible roles list without 333 * removing any roles that are already stored. Unknown slugs (not 334 * registered in this WordPress installation) are silently discarded. 335 * Resending an already-stored slug has no effect (deduplication). 336 * 337 * Request body (JSON): 338 * { "roles": ["Company_D", "Company_E"] } 339 * 340 * Response: 341 * { "eligible_roles": ["Company_A", "Company_B", "Company_D", "Company_E"] } 342 * ===================================================================== 343 */ 344 function bccentralconnector_register_eligible_roles_endpoint() { 345 register_rest_route( 346 'wc/v3', 347 '/bccentralconnector/eligible-roles', 348 array( 349 'methods' => WP_REST_Server::CREATABLE, 350 'callback' => 'bccentralconnector_set_eligible_roles', 351 'permission_callback' => 'bccentralconnector_user_roles_permission_check', 352 'args' => array( 353 'roles' => array( 354 'required' => true, 355 'type' => 'array', 356 'items' => array('type' => 'string'), 357 'sanitize_callback' => function($value) { 358 return array_map('sanitize_text_field', (array) $value); 359 }, 360 'description' => __('Array of role slugs to add to the ELEX discount-eligible list.', 'businesscentralconnector'), 361 ), 362 ), 363 ) 364 ); 365 } 366 367 /** 368 * Callback for POST /wp-json/wc/v3/bccentralconnector/eligible-roles. 369 * 370 * Validates each incoming slug against the registered WordPress roles, 371 * then merges them into the existing `eh_pricing_discount_product_price_user_role` 372 * option — existing roles are never removed. 373 * 374 * @param WP_REST_Request $request 375 * @return WP_REST_Response 376 */ 377 function bccentralconnector_set_eligible_roles(WP_REST_Request $request) { 378 $allowed_roles = array_keys(wp_roles()->roles); 379 $requested = (array) $request->get_param('roles'); 380 381 // Keep only slugs that actually exist in this WordPress installation. 382 $valid = array_filter($requested, function($slug) use ($allowed_roles) { 383 return in_array($slug, $allowed_roles, true); 384 }); 385 386 // Merge with the existing list — do not remove roles that are already stored. 387 $existing = get_option(BCCENTRALCONNECTOR_ELEX_ROLE_OPTION, array()); 388 if (!is_array($existing)) { 389 $existing = array(); 390 } 391 $merged = array_values(array_unique(array_merge($existing, $valid))); 392 393 update_option(BCCENTRALCONNECTOR_ELEX_ROLE_OPTION, $merged); 394 395 return rest_ensure_response(array( 396 'eligible_roles' => $merged, 397 )); 398 } 399 400 /** 401 * ===================================================================== 328 402 * Add a "WooCommerce Connector" download link in the Plugins list 329 403 * ===================================================================== -
businesscentralconnector/trunk/readme.txt
r3476596 r3476671 5 5 Requires PHP: 7.0 6 6 Tested up to: 6.8 7 Stable tag: 1.1. 57 Stable tag: 1.1.6 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 52 52 53 53 == Changelog == 54 = 1.1.6 = 55 * Added the '/bccentralconnector/eligible-roles' edpoint to update eligible user roles. 56 54 57 = 1.1.5 = 55 58 * Added the '/bccentralconnector/user-roles' endpoint to return existing user roles from the webstore. … … 71 74 72 75 == Upgrade Notice == 76 = 1.1.6 = 77 This release introduces the ability to update eligible user roles for discounts via the API. 78 73 79 = 1.1.5 = 74 80 This release introduces the ability to retrieve existing user roles from the webstore via the API.
Note: See TracChangeset
for help on using the changeset viewer.