HEX
Server: nginx/1.18.0
System: Linux iZj6c1ieg2jrpk1z5tzi19Z 6.3.9-1.el7.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 21 22:18:40 EDT 2023 x86_64
User: www (1001)
PHP: 8.2.4
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,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_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/www.cytocare.cn/wp-content/plugins/mailpoet/lib/API/JSON/v1/Coupons.php
<?php declare(strict_types = 1);

namespace MailPoet\API\JSON\v1;

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


use MailPoet\API\JSON\Endpoint as APIEndpoint;
use MailPoet\API\JSON\SuccessResponse;
use MailPoet\Config\AccessControl;
use MailPoet\WooCommerce\Helper;
use MailPoet\WP\Functions as WPFunctions;

class Coupons extends APIEndpoint {
  public const DEFAULT_PAGE_SIZE = 100;

  /** @var Helper  */
  public $helper;

  /*** @var WPFunctions */
  private $wp;

  public $permissions = [
    'global' => AccessControl::PERMISSION_MANAGE_EMAILS,
  ];

  public function __construct(
    WPFunctions $wp,
    Helper $helper
  ) {
    $this->wp = $wp;
    $this->helper = $helper;
  }

  public function getCoupons(array $data = []): SuccessResponse {
    $pageSize = $data['page_size'] ?? self::DEFAULT_PAGE_SIZE;
    $pageNumber = $data['page_number'] ?? 1;
    $discountType = $data['discount_type'] ?? null;
    $search = $data['search'] ?? null;
    $includeCouponIds = $data['include_coupon_ids'] ?? [];
    return $this->successResponse(
      $this->formatCoupons($this->helper->getCouponList(
        (int)$pageSize,
        (int)$pageNumber,
        $discountType,
        $search,
        $includeCouponIds
      ))
    );
  }

  /**
   * @param array $couponPosts
   * @return array
   */
  private function formatCoupons(array $couponPosts): array {
    return array_map(function (\WP_Post $post): array {
      $discountType = $this->wp->getPostMeta($post->ID, 'discount_type', true);
      return [
        'id' => $post->ID,
        'text' => $post->post_title, // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
        'excerpt' => $post->post_excerpt, // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
        'discountType' => $discountType,
      ];
    }, $couponPosts);
  }
}