Plugin Directory

Changeset 3490668


Ignore:
Timestamp:
03/25/2026 09:05:11 AM (4 days ago)
Author:
notifyevents
Message:

Fix false event triggers on WP 3.6+ auto-draft and WooCommerce 8.3+ block checkout

Location:
notify-events/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • notify-events/trunk/modules/woocommerce/models/events/order/NewOrder.php

    r2432603 r3490668  
    2929    {
    3030        add_action('woocommerce_checkout_order_processed', static::class . '::handle', 10, 3);
     31        // Блочный чекаут (WooCommerce 8.3+) передаёт только объект заказа
     32        add_action('woocommerce_store_api_checkout_order_processed', static::class . '::handle_block', 10, 1);
     33    }
     34
     35    /**
     36     * Обработчик для блочного чекаута (Gutenberg block checkout).
     37     * Хук woocommerce_store_api_checkout_order_processed передаёт только $order.
     38     *
     39     * @param WC_Order $order
     40     * @throws ErrorException
     41     */
     42    public static function handle_block($order)
     43    {
     44        static::handle($order->get_id(), [], $order);
    3145    }
    3246
  • notify-events/trunk/modules/woocommerce/models/events/product/ProductAdded.php

    r2919893 r3490668  
    2626    public static function register()
    2727    {
    28         add_action('wp_insert_post', static::class . '::handle', 10, 3);
     28        // transition_post_status позволяет точно определить первое ручное сохранение:
     29        // - auto-draft → draft: WP 3.6+, открытие редактора создаёт auto-draft, пользователь сохраняет черновик
     30        // - new → draft: WP < 3.6, продукт создаётся только в момент первого сохранения
     31        add_action('transition_post_status', static::class . '::handle', 10, 3);
    2932    }
    3033
    3134    /**
    32      * @param int     $post_id
     35     * @param string  $new_status
     36     * @param string  $old_status
    3337     * @param WP_Post $post
    34      * @param bool    $update
    3538     * @throws ErrorException
    3639     */
    37     public static function handle($post_id, $post, $update)
     40    public static function handle($new_status, $old_status, $post)
    3841    {
    39         if ($update) {
     42        if ($new_status !== 'draft' || !in_array($old_status, ['auto-draft', 'new'], true)) {
    4043            return;
    4144        }
    4245
    43         if ($post->post_type != 'product') {
     46        if ($post->post_type !== 'product') {
    4447            return;
    4548        }
  • notify-events/trunk/modules/wordpress/models/events/post/PostAdded.php

    r2432603 r3490668  
    2626    public static function register()
    2727    {
    28         add_action('wp_insert_post', static::class . '::handle', 10, 3);
     28        // transition_post_status позволяет точно определить первое ручное сохранение:
     29        // - auto-draft → draft: WP 3.6+, открытие редактора создаёт auto-draft, пользователь сохраняет черновик
     30        // - new → draft: WP < 3.6, пост создаётся только в момент первого сохранения
     31        add_action('transition_post_status', static::class . '::handle', 10, 3);
    2932    }
    3033
    3134    /**
    32      * @param int     $post_id
     35     * @param string  $new_status
     36     * @param string  $old_status
    3337     * @param WP_Post $post
    34      * @param bool    $update
    3538     * @throws ErrorException
    3639     */
    37     public static function handle($post_id, $post, $update)
     40    public static function handle($new_status, $old_status, $post)
    3841    {
    39         if ($update) {
     42        if ($new_status !== 'draft' || !in_array($old_status, ['auto-draft', 'new'], true)) {
    4043            return;
    4144        }
    4245
    43         if ($post->post_type != 'post') {
     46        if ($post->post_type !== 'post') {
    4447            return;
    4548        }
  • notify-events/trunk/modules/wordpress/views/event/post_custom.php

    r2919893 r3490668  
    3838            <?= $this->render('form/_multi_select', [
    3939                'model' => $event,
    40                 'title' => __('Post Type', WPNE),
     40                'title' => __('Type', WPNE),
    4141                'field' => 'post_type',
    4242                'items' => $event::post_type_list(),
     
    4949            <?= $this->render('form/_multi_select', [
    5050                'model' => $event,
    51                 'title' => __('Old Type', WPNE),
     51                'title' => __('Old Status', WPNE),
    5252                'field' => 'post_old_status',
    5353                'items' => $event::post_status_list(),
  • notify-events/trunk/notify-events.php

    r3489780 r3490668  
    66Author: Notify.Events
    77Author URI: https://notify.events/
    8 Version: 1.4.3
     8Version: 1.4.4
    99License: GPL-2.0
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • notify-events/trunk/readme.txt

    r3489780 r3490668  
    55Requires PHP: 5.6
    66Tested up to: 7.0
    7 Stable tag: 1.4.3
     7Stable tag: 1.4.4
    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.