HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: //proc/thread-self/cwd/wp-content/plugins/automatewoo/admin/coupons-list.php
<?php
// phpcs:ignoreFile

if ( ! defined( 'ABSPATH' ) ) exit;

/**
 * @class AW_Admin_Coupons_List
 */
class AW_Admin_Coupons_List {


	function __construct() {
		add_action( 'pre_get_posts', [ $this, 'modify_results' ] );
		add_filter( 'views_edit-shop_coupon' , [ $this, 'filter_views' ] );
		add_filter( 'wp_count_posts' , [ $this, 'filter_counts' ], 10, 2 );
	}



	function filter_views( $views ) {

		$url = add_query_arg( [
			'post_type' => 'shop_coupon',
			'filter_automatewoo' => '1'
		], admin_url( 'edit.php' ) );

		$trash = aw_array_extract( $views, 'trash' );

		$count = number_format_i18n( $this->get_count() );
		$views['automatewoo'] = '<a href="' . $url . '"' . ( aw_request( 'filter_automatewoo' ) ? 'class="current"' : '' ) . '>' . __( 'AutomateWoo', 'automatewoo' ) . ' <span class="count">(' . $count . ')</span></a>';

		if ( $trash ) {
			$views['trash'] = $trash;
		}

		return $views;
	}


	/**
	 * @param $counts
	 * @param $type
	 * @return mixed
	 */
	function filter_counts( $counts, $type ) {

		if ( $type !== 'shop_coupon' ) {
			return $counts;
		}

		if ( ! isset( $counts->automatewoo ) ) {
			$count = $this->get_count();
			$counts->publish -= $count;
			$counts->automatewoo = $count;
		}

		return $counts;
	}


	/**
	 * @return int
	 */
	function get_count() {
		$coupons = get_posts([
			'post_type' => 'shop_coupon',
			'fields' => 'ids',
			'posts_per_page' => -1,
			'meta_query' => [
				[
					'key' => '_is_aw_coupon',
					'value' => '1'
				]
			]
		]);
		return count( $coupons );
	}


	/**
	 * @param $query WP_Query
	 */
	function modify_results( $query ) {

		if ( ! $query->is_main_query() ) return;

		if ( ! isset( $query->query_vars['meta_query'] ) ) {
			$query->query_vars['meta_query'] = [];
		}

		if ( aw_request( 'filter_automatewoo' ) ) {
			$query->query_vars['meta_query'][] = [
				'key' => '_is_aw_coupon',
				'value' => '1'
			];
		}
		elseif ( aw_request( 'post_status' ) == 'publish' ) {
			$query->query_vars['meta_query'][] = [
				'key' => '_is_aw_coupon',
				'compare' => 'NOT EXISTS'
			];
		}
	}

}