芝麻web文件管理V1.00
编辑当前文件:/var/www/cognitio.in/wp-content/plugins/woocommerce/src/Admin/RemoteInboxNotifications/StoredStateSetupForProducts.php
there_were_no_products = ! self::are_there_products(); $stored_state->there_are_now_products = ! $stored_state->there_were_no_products; return $stored_state; } /** * Are there products query. * * @return bool */ private static function are_there_products() { $query = new \WC_Product_Query( array( 'limit' => 1, 'paginate' => true, 'return' => 'ids', 'status' => array( 'publish' ), ) ); $products = $query->get_products(); $count = $products->total; return $count > 0; } /** * Runs on product importer steps. */ public static function run_on_product_importer() { // We're only interested in when the importer completes. // phpcs:disable WordPress.Security.NonceVerification.Recommended if ( ! isset( $_REQUEST['step'] ) ) { return; } if ( 'done' !== $_REQUEST['step'] ) { return; } // phpcs:enable self::update_stored_state_and_possibly_run_remote_notifications(); } /** * Runs when a post status transitions, but we're only interested if it is * a product being published. * * @param string $new_status The new status. * @param string $old_status The old status. * @param Post $post The post. */ public static function run_on_transition_post_status( $new_status, $old_status, $post ) { if ( 'product' !== $post->post_type || 'publish' !== $new_status ) { return; } self::update_stored_state_and_possibly_run_remote_notifications(); } /** * Enqueues an async action (using action-scheduler) to run remote * notifications. */ private static function update_stored_state_and_possibly_run_remote_notifications() { $stored_state = RemoteInboxNotificationsEngine::get_stored_state(); // If the stored_state is the same, we don't need to run remote notifications to avoid unnecessary action scheduling. if ( true === $stored_state->there_are_now_products ) { return; } $stored_state->there_are_now_products = true; RemoteInboxNotificationsEngine::update_stored_state( $stored_state ); // Run self::run_remote_notifications asynchronously. as_enqueue_async_action( self::ASYNC_RUN_REMOTE_NOTIFICATIONS_ACTION_NAME ); } }