Plugin Directory

Changeset 3140508


Ignore:
Timestamp:
08/23/2024 06:41:56 PM (19 months ago)
Author:
EmranAhmed
Message:

Release 3.0.3

Location:
woo-2checkout
Files:
154 added
30 edited

Legend:

Unmodified
Added
Removed
  • woo-2checkout/trunk/README.txt

    r3081706 r3140508  
    22Contributors: EmranAhmed, getwooplugins
    33Tags: 2checkout, 2checkout for woocommerce, 2checkout payment gateway, payment gateway, woocommerce payment gateway
    4 Stable tag: 3.0.2
     4Stable tag: 3.0.3
    55Requires PHP: 7.4
    66Requires at least: 6.1
     
    84847. Activate the plugin
    8585
     86== Frequently Asked Questions ==
     87
     88= Do I need to create products on 2Checkout? =
     89
     90No, you don't need to create any products on 2Checkout.
     91
     92= Does it support WooCommerce Checkout Block? =
     93
     94Yes, this payment gateway plugin support woocommerce checkout block too.
     95
     96= Is there any known issue? =
     97
     98Yes, Please make sure your can generate link on 2checkout account with "Dynamic Products".
     99
    86100== Changelog ==
     101
     102= 3.0.3 =
     103
     104* Add: WC 9.2+ compatibility.
     105* Add: WP 6.6+ compatibility.
    87106
    88107= 3.0.2 =
  • woo-2checkout/trunk/build/convert-plus-block.asset.php

    r3044506 r3140508  
    1 <?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '8b5ecf98ba2c2e217c51');
     1<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '3feed1c8c9f5d2c504d6');
  • woo-2checkout/trunk/build/convert-plus-block.js

    r3044506 r3140508  
    1 (()=>{"use strict";const e=window.React,t=window.wp.i18n,n=window.wc.wcBlocksRegistry,o=window.wp.htmlEntities,c=window.wc.wcSettings,s="woo-2checkout",r=window.wp.element,a=(0,c.getPaymentMethodData)(s,{}),l=(0,o.decodeEntities)(a?.title||(0,t.__)("2Checkout","woo-2checkout")),i=(0,o.decodeEntities)(a?.order_button_text||(0,t.__)("Proceed to 2Checkout","woo-2checkout")),u=a?.icon_uri,m=a?.is_demo;function w(){const n=(0,o.decodeEntities)(a.description||"");return m?(0,e.createElement)(e.Fragment,null,n,(0,e.createElement)("br",null),(0,e.createElement)("strong",null,(0,t.__)("DEMO MODE ENABLED.","woo-2checkout"))," ",(0,t.__)("Use a","woo-2checkout")," ",(0,e.createElement)("a",{target:"_blank",href:"https://verifone.cloud/docs/2checkout/Documentation/09Test_ordering_system/01Test_payment_methods",rel:"noreferrer"},(0,t.__)("test payment cards","woo-2checkout"))):n}const d={name:s,label:(0,e.createElement)((function(t){const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(n,{text:l})," ",(0,e.createElement)("img",{alt:l,className:"woo-2checkout-gateway-pay-image",src:u}))}),null),content:(0,e.createElement)((function(t){return function(e,t){const{eventRegistration:n,emitResponse:o}=e,{onCheckoutFail:c}=n;(0,r.useEffect)((()=>{const e=c((({processingResponse:e})=>{const{paymentDetails:t,paymentStatus:n}=e;return"failure"!==n||{type:o.responseTypes.ERROR,message:t?.messages,messageContext:o.noticeContexts.PAYMENTS,retry:!0}}));return()=>{e()}}),[o.responseTypes.ERROR,o.responseTypes.SUCCESS,o.noticeContexts.PAYMENTS,c])}(t),(0,e.createElement)(w,null)}),null),edit:(0,e.createElement)((function(){return(0,e.createElement)(w,null)}),null),canMakePayment:function(){return!0},placeOrderButtonLabel:i,icons:null,ariaLabel:l,supports:{features:a.supports}};(0,n.registerPaymentMethod)(d)})();
     1(()=>{"use strict";var e={20:(e,t,o)=>{var n=o(609),r=Symbol.for("react.element"),s=Symbol.for("react.fragment"),c=Object.prototype.hasOwnProperty,i=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function u(e,t,o){var n,s={},u=null,p=null;for(n in void 0!==o&&(u=""+o),void 0!==t.key&&(u=""+t.key),void 0!==t.ref&&(p=t.ref),t)c.call(t,n)&&!a.hasOwnProperty(n)&&(s[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===s[n]&&(s[n]=t[n]);return{$$typeof:r,type:e,key:u,ref:p,props:s,_owner:i.current}}t.Fragment=s,t.jsx=u,t.jsxs=u},848:(e,t,o)=>{e.exports=o(20)},609:e=>{e.exports=window.React}},t={};const o=window.wp.i18n,n=window.wc.wcBlocksRegistry,r=window.wp.htmlEntities,s=window.wc.wcSettings,c="woo-2checkout",i=window.wp.element;var a=function o(n){var r=t[n];if(void 0!==r)return r.exports;var s=t[n]={exports:{}};return e[n](s,s.exports,o),s.exports}(848);const u=(0,s.getPaymentMethodData)(c,{}),p=(0,r.decodeEntities)(u?.title||(0,o.__)("2Checkout","woo-2checkout")),d=(0,r.decodeEntities)(u?.order_button_text||(0,o.__)("Proceed to 2Checkout","woo-2checkout")),l=u?.icon_uri,_=u?.is_demo;function w(e){const{PaymentMethodLabel:t}=e.components;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(t,{text:p})," ",(0,a.jsx)("img",{alt:p,className:"woo-2checkout-gateway-pay-image",src:l})]})}function f(e){return function(e){const{eventRegistration:t,emitResponse:o}=e,{onCheckoutFail:n}=t;(0,i.useEffect)((()=>{const e=n((({processingResponse:e})=>{const{paymentDetails:t,paymentStatus:n}=e;return"failure"!==n||{type:o.responseTypes.ERROR,message:t?.messages,messageContext:o.noticeContexts.PAYMENTS,retry:!0}}));return()=>{e()}}),[o.responseTypes.ERROR,o.responseTypes.SUCCESS,o.noticeContexts.PAYMENTS,n])}(e),(0,a.jsx)(m,{})}function m(){const e=(0,r.decodeEntities)(u.description||"");return _?(0,a.jsxs)(a.Fragment,{children:[e,(0,a.jsx)("br",{}),(0,a.jsx)("strong",{children:(0,o.__)("DEMO MODE ENABLED.","woo-2checkout")})," ",(0,o.__)("Use a","woo-2checkout")," ",(0,a.jsx)("a",{target:"_blank",href:"https://verifone.cloud/docs/2checkout/Documentation/09Test_ordering_system/01Test_payment_methods",rel:"noreferrer",children:(0,o.__)("test payment cards","woo-2checkout")})]}):e}function y(){return(0,a.jsx)(m,{})}const x={name:c,label:(0,a.jsx)(w,{}),content:(0,a.jsx)(f,{}),edit:(0,a.jsx)(y,{}),canMakePayment:function(){return!0},placeOrderButtonLabel:d,icons:null,ariaLabel:p,supports:{features:u.supports}};(0,n.registerPaymentMethod)(x)})();
  • woo-2checkout/trunk/changelog.txt

    r3081706 r3140508  
    11== Payment Gateway - 2Checkout for WooCommerce ==
     2
     3= 3.0.3 - 2024-08-21 =
     4
     5* Add - WC 9.1+ compatibility.
     6* Add - WP 6.6+ compatibility.
    27
    38= 3.0.2 - 2024-05-05 =
  • woo-2checkout/trunk/includes/API.php

    r3081706 r3140508  
    110110            'return-url',
    111111            'return-type',
     112            //'back-url',
    112113            'expiration',
    113114            'order-ext-ref',
     
    121122            'price',
    122123            'qty',
     124            //'tangible',
    123125            'type',
    124126            'opt',
  • woo-2checkout/trunk/includes/ConvertPlus/ConvertPlus_Gateway.php

    r3081706 r3140508  
    260260        if ( $order->has_billing_address() ) {
    261261            $args['address']  = esc_html( $order->get_billing_address_1() );
    262             $args['address2'] = esc_html( $order->get_billing_address_2() );
     262            if( $order->get_billing_address_2() ){
     263                $args['address2'] = esc_html( $order->get_billing_address_2() );
     264            }
    263265        }
    264266
     
    441443        $parameters = $this->payment_args( $order );
    442444
     445        ksort( $parameters);
     446
    443447        $this->log( "PAYMENT ARGS:\n" . print_r( $parameters, true ) ); // phpcs:ignore.
    444448
    445449        $payment_url = $this->get_payment_url( $parameters );
     450
     451        $this->log( "PAYMENT LINK:\n" . $payment_url ); // phpcs:ignore.
    446452
    447453        if ( ! empty( $payment_url ) ) {
  • woo-2checkout/trunk/includes/Plugin.php

    r3044506 r3140508  
    121121     * Includes.
    122122     *
     123     * @throws Exception When class files loading fails.
    123124     * @since 1.0.0
    124125     */
    125126    public function includes() {
    126127
    127         if ( file_exists( $this->vendor_path() . '/autoload.php' ) ) {
    128             require_once $this->vendor_path() . '/autoload.php';
     128        if ( file_exists( $this->vendor_path() . '/autoload_packages.php' ) ) {
     129            require_once $this->vendor_path() . '/autoload_packages.php';
    129130            require_once __DIR__ . '/functions.php';
    130         }
     131            return;
     132        }
     133
     134        throw new Exception( '"vendor/autoload_packages.php" file missing. Please run `composer install`' );
    131135    }
    132136
  • woo-2checkout/trunk/languages/woo-2checkout.pot

    r3081706 r3140508  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Payment Gateway - 2Checkout for WooCommerce 3.0.2\n"
     5"Project-Id-Version: Payment Gateway - 2Checkout for WooCommerce 3.0.3\n"
    66"Report-Msgid-Bugs-To: https://getwooplugins.com/new-ticket/\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2024-05-06T06:54:50+00:00\n"
     12"POT-Creation-Date: 2024-08-23T18:38:11+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    14 "X-Generator: WP-CLI 2.10.0\n"
     14"X-Generator: WP-CLI 2.11.0\n"
    1515"language-team: LANGUAGE <EMAIL@ADDRESS>\n"
    1616"X-Domain: woo-2checkout\n"
     
    4848#: includes/Payment_Gateway.php:102
    4949#: includes/Payment_Gateway.php:260
    50 #: src/convert-plus-block.js:27
     50#: build/convert-plus-block.js:1
    5151msgid "Proceed to 2Checkout"
    5252msgstr ""
     
    5555#: includes/Payment_Gateway.php:100
    5656#: includes/Payment_Gateway.php:245
    57 #: src/convert-plus-block.js:23
     57#: build/convert-plus-block.js:1
    5858msgid "2Checkout"
    5959msgstr ""
     
    6666
    6767#. translators: Shipping Method Name
    68 #: includes/ConvertPlus/ConvertPlus_Gateway.php:401
     68#: includes/ConvertPlus/ConvertPlus_Gateway.php:403
    6969msgid "Shipping via %s"
    7070msgstr ""
    7171
    72 #: includes/ConvertPlus/ConvertPlus_Gateway.php:454
     72#: includes/ConvertPlus/ConvertPlus_Gateway.php:460
    7373msgid "Failed to Generate 2Checkout ConvertPlus URL."
    7474msgstr ""
     
    259259msgstr ""
    260260
    261 #: includes/Plugin.php:177
     261#: includes/Plugin.php:181
    262262msgid "Payment Gateway - 2Checkout for WooCommerce - Pro "
    263263msgstr ""
    264264
    265265#. translators: %s: Pro version link.
    266 #: includes/Plugin.php:181
     266#: includes/Plugin.php:185
    267267msgid "Upgrade to %s to get WooCommerce Subscriptions payments, issue refunds from wp admin, inline popup checkout and more."
    268268msgstr ""
    269269
    270 #: includes/Plugin.php:480
     270#: includes/Plugin.php:484
    271271msgid "Settings"
    272272msgstr ""
     
    280280msgstr ""
    281281
    282 #: src/convert-plus-block.js:89
     282#: build/convert-plus-block.js:1
    283283msgid "DEMO MODE ENABLED."
    284284msgstr ""
    285285
    286 #: src/convert-plus-block.js:91
     286#: build/convert-plus-block.js:1
    287287msgid "Use a"
    288288msgstr ""
    289289
    290 #: src/convert-plus-block.js:98
     290#: build/convert-plus-block.js:1
    291291msgid "test payment cards"
    292292msgstr ""
  • woo-2checkout/trunk/vendor/autoload.php

    r3081706 r3140508  
    2323require_once __DIR__ . '/composer/autoload_real.php';
    2424
    25 return ComposerAutoloaderInitce260624bbcd03fad5e82c3fe1f7a15c::getLoader();
     25return ComposerAutoloaderInitfbd493a17f366db9959bbabb6910870d::getLoader();
  • woo-2checkout/trunk/vendor/composer/ClassLoader.php

    r3044506 r3140508  
    4646    private static $includeFile;
    4747
    48     /** @var ?string */
     48    /** @var string|null */
    4949    private $vendorDir;
    5050
    5151    // PSR-4
    5252    /**
    53      * @var array[]
    54      * @psalm-var array<string, array<string, int>>
     53     * @var array<string, array<string, int>>
    5554     */
    5655    private $prefixLengthsPsr4 = array();
    5756    /**
    58      * @var array[]
    59      * @psalm-var array<string, array<int, string>>
     57     * @var array<string, list<string>>
    6058     */
    6159    private $prefixDirsPsr4 = array();
    6260    /**
    63      * @var array[]
    64      * @psalm-var array<string, string>
     61     * @var list<string>
    6562     */
    6663    private $fallbackDirsPsr4 = array();
     
    6865    // PSR-0
    6966    /**
    70      * @var array[]
    71      * @psalm-var array<string, array<string, string[]>>
     67     * List of PSR-0 prefixes
     68     *
     69     * Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
     70     *
     71     * @var array<string, array<string, list<string>>>
    7272     */
    7373    private $prefixesPsr0 = array();
    7474    /**
    75      * @var array[]
    76      * @psalm-var array<string, string>
     75     * @var list<string>
    7776     */
    7877    private $fallbackDirsPsr0 = array();
     
    8281
    8382    /**
    84      * @var string[]
    85      * @psalm-var array<string, string>
     83     * @var array<string, string>
    8684     */
    8785    private $classMap = array();
     
    9189
    9290    /**
    93      * @var bool[]
    94      * @psalm-var array<string, bool>
     91     * @var array<string, bool>
    9592     */
    9693    private $missingClasses = array();
    9794
    98     /** @var ?string */
     95    /** @var string|null */
    9996    private $apcuPrefix;
    10097
    10198    /**
    102      * @var self[]
     99     * @var array<string, self>
    103100     */
    104101    private static $registeredLoaders = array();
    105102
    106103    /**
    107      * @param ?string $vendorDir
     104     * @param string|null $vendorDir
    108105     */
    109106    public function __construct($vendorDir = null)
     
    114111
    115112    /**
    116      * @return string[]
     113     * @return array<string, list<string>>
    117114     */
    118115    public function getPrefixes()
     
    126123
    127124    /**
    128      * @return array[]
    129      * @psalm-return array<string, array<int, string>>
     125     * @return array<string, list<string>>
    130126     */
    131127    public function getPrefixesPsr4()
     
    135131
    136132    /**
    137      * @return array[]
    138      * @psalm-return array<string, string>
     133     * @return list<string>
    139134     */
    140135    public function getFallbackDirs()
     
    144139
    145140    /**
    146      * @return array[]
    147      * @psalm-return array<string, string>
     141     * @return list<string>
    148142     */
    149143    public function getFallbackDirsPsr4()
     
    153147
    154148    /**
    155      * @return string[] Array of classname => path
    156      * @psalm-return array<string, string>
     149     * @return array<string, string> Array of classname => path
    157150     */
    158151    public function getClassMap()
     
    162155
    163156    /**
    164      * @param string[] $classMap Class to filename map
    165      * @psalm-param array<string, string> $classMap
     157     * @param array<string, string> $classMap Class to filename map
    166158     *
    167159     * @return void
     
    180172     * appending or prepending to the ones previously set for this prefix.
    181173     *
    182      * @param string          $prefix  The prefix
    183      * @param string[]|string $paths   The PSR-0 root directories
    184      * @param bool            $prepend Whether to prepend the directories
     174     * @param string              $prefix  The prefix
     175     * @param list<string>|string $paths   The PSR-0 root directories
     176     * @param bool                $prepend Whether to prepend the directories
    185177     *
    186178     * @return void
     
    188180    public function add($prefix, $paths, $prepend = false)
    189181    {
     182        $paths = (array) $paths;
    190183        if (!$prefix) {
    191184            if ($prepend) {
    192185                $this->fallbackDirsPsr0 = array_merge(
    193                     (array) $paths,
     186                    $paths,
    194187                    $this->fallbackDirsPsr0
    195188                );
     
    197190                $this->fallbackDirsPsr0 = array_merge(
    198191                    $this->fallbackDirsPsr0,
    199                     (array) $paths
     192                    $paths
    200193                );
    201194            }
     
    206199        $first = $prefix[0];
    207200        if (!isset($this->prefixesPsr0[$first][$prefix])) {
    208             $this->prefixesPsr0[$first][$prefix] = (array) $paths;
     201            $this->prefixesPsr0[$first][$prefix] = $paths;
    209202
    210203            return;
     
    212205        if ($prepend) {
    213206            $this->prefixesPsr0[$first][$prefix] = array_merge(
    214                 (array) $paths,
     207                $paths,
    215208                $this->prefixesPsr0[$first][$prefix]
    216209            );
     
    218211            $this->prefixesPsr0[$first][$prefix] = array_merge(
    219212                $this->prefixesPsr0[$first][$prefix],
    220                 (array) $paths
     213                $paths
    221214            );
    222215        }
     
    227220     * appending or prepending to the ones previously set for this namespace.
    228221     *
    229      * @param string          $prefix  The prefix/namespace, with trailing '\\'
    230      * @param string[]|string $paths   The PSR-4 base directories
    231      * @param bool            $prepend Whether to prepend the directories
     222     * @param string              $prefix  The prefix/namespace, with trailing '\\'
     223     * @param list<string>|string $paths   The PSR-4 base directories
     224     * @param bool                $prepend Whether to prepend the directories
    232225     *
    233226     * @throws \InvalidArgumentException
     
    237230    public function addPsr4($prefix, $paths, $prepend = false)
    238231    {
     232        $paths = (array) $paths;
    239233        if (!$prefix) {
    240234            // Register directories for the root namespace.
    241235            if ($prepend) {
    242236                $this->fallbackDirsPsr4 = array_merge(
    243                     (array) $paths,
     237                    $paths,
    244238                    $this->fallbackDirsPsr4
    245239                );
     
    247241                $this->fallbackDirsPsr4 = array_merge(
    248242                    $this->fallbackDirsPsr4,
    249                     (array) $paths
     243                    $paths
    250244                );
    251245            }
     
    257251            }
    258252            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
    259             $this->prefixDirsPsr4[$prefix] = (array) $paths;
     253            $this->prefixDirsPsr4[$prefix] = $paths;
    260254        } elseif ($prepend) {
    261255            // Prepend directories for an already registered namespace.
    262256            $this->prefixDirsPsr4[$prefix] = array_merge(
    263                 (array) $paths,
     257                $paths,
    264258                $this->prefixDirsPsr4[$prefix]
    265259            );
     
    268262            $this->prefixDirsPsr4[$prefix] = array_merge(
    269263                $this->prefixDirsPsr4[$prefix],
    270                 (array) $paths
     264                $paths
    271265            );
    272266        }
     
    277271     * replacing any others previously set for this prefix.
    278272     *
    279      * @param string          $prefix The prefix
    280      * @param string[]|string $paths  The PSR-0 base directories
     273     * @param string              $prefix The prefix
     274     * @param list<string>|string $paths  The PSR-0 base directories
    281275     *
    282276     * @return void
     
    295289     * replacing any others previously set for this namespace.
    296290     *
    297      * @param string          $prefix The prefix/namespace, with trailing '\\'
    298      * @param string[]|string $paths  The PSR-4 base directories
     291     * @param string              $prefix The prefix/namespace, with trailing '\\'
     292     * @param list<string>|string $paths  The PSR-4 base directories
    299293     *
    300294     * @throws \InvalidArgumentException
     
    430424    {
    431425        if ($file = $this->findFile($class)) {
    432             (self::$includeFile)($file);
     426            $includeFile = self::$includeFile;
     427            $includeFile($file);
    433428
    434429            return true;
     
    481476
    482477    /**
    483      * Returns the currently registered loaders indexed by their corresponding vendor directories.
    484      *
    485      * @return self[]
     478     * Returns the currently registered loaders keyed by their corresponding vendor directories.
     479     *
     480     * @return array<string, self>
    486481     */
    487482    public static function getRegisteredLoaders()
     
    561556    }
    562557
    563     private static function initializeIncludeClosure(): void
     558    /**
     559     * @return void
     560     */
     561    private static function initializeIncludeClosure()
    564562    {
    565563        if (self::$includeFile !== null) {
     
    575573         * @return void
    576574         */
    577         self::$includeFile = static function($file) {
     575        self::$includeFile = \Closure::bind(static function($file) {
    578576            include $file;
    579         };
     577        }, null, null);
    580578    }
    581579}
  • woo-2checkout/trunk/vendor/composer/InstalledVersions.php

    r3044506 r3140508  
    9999        foreach (self::getInstalled() as $installed) {
    100100            if (isset($installed['versions'][$packageName])) {
    101                 return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
     101                return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
    102102            }
    103103        }
     
    120120    public static function satisfies(VersionParser $parser, $packageName, $constraint)
    121121    {
    122         $constraint = $parser->parseConstraints($constraint);
     122        $constraint = $parser->parseConstraints((string) $constraint);
    123123        $provided = $parser->parseConstraints(self::getVersionRanges($packageName));
    124124
     
    329329                    $installed[] = self::$installedByVendor[$vendorDir];
    330330                } elseif (is_file($vendorDir.'/composer/installed.php')) {
    331                     $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
     331                    /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
     332                    $required = require $vendorDir.'/composer/installed.php';
     333                    $installed[] = self::$installedByVendor[$vendorDir] = $required;
    332334                    if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
    333335                        self::$installed = $installed[count($installed) - 1];
     
    341343            // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
    342344            if (substr(__DIR__, -8, 1) !== 'C') {
    343                 self::$installed = require __DIR__ . '/installed.php';
     345                /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
     346                $required = require __DIR__ . '/installed.php';
     347                self::$installed = $required;
    344348            } else {
    345349                self::$installed = array();
    346350            }
    347351        }
    348         $installed[] = self::$installed;
     352
     353        if (self::$installed !== array()) {
     354            $installed[] = self::$installed;
     355        }
    349356
    350357        return $installed;
  • woo-2checkout/trunk/vendor/composer/autoload_classmap.php

    r3044506 r3140508  
    77
    88return array(
     9    'Automattic\\Jetpack\\Autoloader\\AutoloadFileWriter' => $vendorDir . '/automattic/jetpack-autoloader/src/AutoloadFileWriter.php',
     10    'Automattic\\Jetpack\\Autoloader\\AutoloadGenerator' => $vendorDir . '/automattic/jetpack-autoloader/src/AutoloadGenerator.php',
     11    'Automattic\\Jetpack\\Autoloader\\AutoloadProcessor' => $vendorDir . '/automattic/jetpack-autoloader/src/AutoloadProcessor.php',
     12    'Automattic\\Jetpack\\Autoloader\\CustomAutoloaderPlugin' => $vendorDir . '/automattic/jetpack-autoloader/src/CustomAutoloaderPlugin.php',
     13    'Automattic\\Jetpack\\Autoloader\\ManifestGenerator' => $vendorDir . '/automattic/jetpack-autoloader/src/ManifestGenerator.php',
    914    'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
     15    'StorePress\\AdminUtils\\Common' => $vendorDir . '/storepress/admin-utils/includes/Common.php',
    1016    'StorePress\\AdminUtils\\Field' => $vendorDir . '/storepress/admin-utils/includes/Field.php',
    1117    'StorePress\\AdminUtils\\Fields' => $vendorDir . '/storepress/admin-utils/includes/Fields.php',
  • woo-2checkout/trunk/vendor/composer/autoload_psr4.php

    r3044506 r3140508  
    99    'StorePress\\TwoCheckoutPaymentGateway\\' => array($baseDir . '/includes'),
    1010    'StorePress\\AdminUtils\\' => array($vendorDir . '/storepress/admin-utils/includes'),
     11    'Automattic\\Jetpack\\Autoloader\\' => array($vendorDir . '/automattic/jetpack-autoloader/src'),
    1112);
  • woo-2checkout/trunk/vendor/composer/autoload_real.php

    r3081706 r3140508  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInitce260624bbcd03fad5e82c3fe1f7a15c
     5class ComposerAutoloaderInitfbd493a17f366db9959bbabb6910870d
    66{
    77    private static $loader;
     
    2525        require __DIR__ . '/platform_check.php';
    2626
    27         spl_autoload_register(array('ComposerAutoloaderInitce260624bbcd03fad5e82c3fe1f7a15c', 'loadClassLoader'), true, true);
     27        spl_autoload_register(array('ComposerAutoloaderInitfbd493a17f366db9959bbabb6910870d', 'loadClassLoader'), true, true);
    2828        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
    29         spl_autoload_unregister(array('ComposerAutoloaderInitce260624bbcd03fad5e82c3fe1f7a15c', 'loadClassLoader'));
     29        spl_autoload_unregister(array('ComposerAutoloaderInitfbd493a17f366db9959bbabb6910870d', 'loadClassLoader'));
    3030
    3131        require __DIR__ . '/autoload_static.php';
    32         call_user_func(\Composer\Autoload\ComposerStaticInitce260624bbcd03fad5e82c3fe1f7a15c::getInitializer($loader));
     32        call_user_func(\Composer\Autoload\ComposerStaticInitfbd493a17f366db9959bbabb6910870d::getInitializer($loader));
    3333
    3434        $loader->register(true);
  • woo-2checkout/trunk/vendor/composer/autoload_static.php

    r3081706 r3140508  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInitce260624bbcd03fad5e82c3fe1f7a15c
     7class ComposerStaticInitfbd493a17f366db9959bbabb6910870d
    88{
    99    public static $prefixLengthsPsr4 = array (
     
    1212            'StorePress\\TwoCheckoutPaymentGateway\\' => 37,
    1313            'StorePress\\AdminUtils\\' => 22,
     14        ),
     15        'A' =>
     16        array (
     17            'Automattic\\Jetpack\\Autoloader\\' => 30,
    1418        ),
    1519    );
     
    2428            0 => __DIR__ . '/..' . '/storepress/admin-utils/includes',
    2529        ),
     30        'Automattic\\Jetpack\\Autoloader\\' =>
     31        array (
     32            0 => __DIR__ . '/..' . '/automattic/jetpack-autoloader/src',
     33        ),
    2634    );
    2735
    2836    public static $classMap = array (
     37        'Automattic\\Jetpack\\Autoloader\\AutoloadFileWriter' => __DIR__ . '/..' . '/automattic/jetpack-autoloader/src/AutoloadFileWriter.php',
     38        'Automattic\\Jetpack\\Autoloader\\AutoloadGenerator' => __DIR__ . '/..' . '/automattic/jetpack-autoloader/src/AutoloadGenerator.php',
     39        'Automattic\\Jetpack\\Autoloader\\AutoloadProcessor' => __DIR__ . '/..' . '/automattic/jetpack-autoloader/src/AutoloadProcessor.php',
     40        'Automattic\\Jetpack\\Autoloader\\CustomAutoloaderPlugin' => __DIR__ . '/..' . '/automattic/jetpack-autoloader/src/CustomAutoloaderPlugin.php',
     41        'Automattic\\Jetpack\\Autoloader\\ManifestGenerator' => __DIR__ . '/..' . '/automattic/jetpack-autoloader/src/ManifestGenerator.php',
    2942        'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
     43        'StorePress\\AdminUtils\\Common' => __DIR__ . '/..' . '/storepress/admin-utils/includes/Common.php',
    3044        'StorePress\\AdminUtils\\Field' => __DIR__ . '/..' . '/storepress/admin-utils/includes/Field.php',
    3145        'StorePress\\AdminUtils\\Fields' => __DIR__ . '/..' . '/storepress/admin-utils/includes/Fields.php',
     
    4862    {
    4963        return \Closure::bind(function () use ($loader) {
    50             $loader->prefixLengthsPsr4 = ComposerStaticInitce260624bbcd03fad5e82c3fe1f7a15c::$prefixLengthsPsr4;
    51             $loader->prefixDirsPsr4 = ComposerStaticInitce260624bbcd03fad5e82c3fe1f7a15c::$prefixDirsPsr4;
    52             $loader->classMap = ComposerStaticInitce260624bbcd03fad5e82c3fe1f7a15c::$classMap;
     64            $loader->prefixLengthsPsr4 = ComposerStaticInitfbd493a17f366db9959bbabb6910870d::$prefixLengthsPsr4;
     65            $loader->prefixDirsPsr4 = ComposerStaticInitfbd493a17f366db9959bbabb6910870d::$prefixDirsPsr4;
     66            $loader->classMap = ComposerStaticInitfbd493a17f366db9959bbabb6910870d::$classMap;
    5367
    5468        }, null, ClassLoader::class);
  • woo-2checkout/trunk/vendor/composer/installed.json

    r3081706 r3140508  
    22    "packages": [
    33        {
     4            "name": "automattic/jetpack-autoloader",
     5            "version": "v3.0.9",
     6            "version_normalized": "3.0.9.0",
     7            "source": {
     8                "type": "git",
     9                "url": "https://github.com/Automattic/jetpack-autoloader.git",
     10                "reference": "a571038214fc3e142e10f38d1bb97e470fa7b0ec"
     11            },
     12            "dist": {
     13                "type": "zip",
     14                "url": "https://api.github.com/repos/Automattic/jetpack-autoloader/zipball/a571038214fc3e142e10f38d1bb97e470fa7b0ec",
     15                "reference": "a571038214fc3e142e10f38d1bb97e470fa7b0ec",
     16                "shasum": ""
     17            },
     18            "require": {
     19                "composer-plugin-api": "^1.1 || ^2.0",
     20                "php": ">=7.0"
     21            },
     22            "require-dev": {
     23                "automattic/jetpack-changelogger": "^4.2.5",
     24                "composer/composer": "^1.1 || ^2.0",
     25                "yoast/phpunit-polyfills": "1.1.0"
     26            },
     27            "time": "2024-07-10T07:51:07+00:00",
     28            "type": "composer-plugin",
     29            "extra": {
     30                "autotagger": true,
     31                "class": "Automattic\\Jetpack\\Autoloader\\CustomAutoloaderPlugin",
     32                "mirror-repo": "Automattic/jetpack-autoloader",
     33                "changelogger": {
     34                    "link-template": "https://github.com/Automattic/jetpack-autoloader/compare/v${old}...v${new}"
     35                },
     36                "version-constants": {
     37                    "::VERSION": "src/AutoloadGenerator.php"
     38                },
     39                "branch-alias": {
     40                    "dev-trunk": "3.0.x-dev"
     41                }
     42            },
     43            "installation-source": "dist",
     44            "autoload": {
     45                "psr-4": {
     46                    "Automattic\\Jetpack\\Autoloader\\": "src"
     47                },
     48                "classmap": [
     49                    "src/AutoloadGenerator.php"
     50                ]
     51            },
     52            "notification-url": "https://packagist.org/downloads/",
     53            "license": [
     54                "GPL-2.0-or-later"
     55            ],
     56            "description": "Creates a custom autoloader for a plugin or theme.",
     57            "keywords": [
     58                "autoload",
     59                "autoloader",
     60                "composer",
     61                "jetpack",
     62                "plugin",
     63                "wordpress"
     64            ],
     65            "support": {
     66                "source": "https://github.com/Automattic/jetpack-autoloader/tree/v3.0.9"
     67            },
     68            "install-path": "../automattic/jetpack-autoloader"
     69        },
     70        {
    471            "name": "storepress/admin-utils",
    5             "version": "1.8.5",
    6             "version_normalized": "1.8.5.0",
     72            "version": "1.8.8",
     73            "version_normalized": "1.8.8.0",
    774            "source": {
    875                "type": "git",
    976                "url": "https://github.com/EmranAhmed/storepress-admin-utils.git",
    10                 "reference": "36b4d595519ae25f3be2625f70e16b9ef8769cfa"
     77                "reference": "69b5cb4b5a2b4625dbdb2a6bd3344c5e35fa5837"
    1178            },
    1279            "dist": {
    1380                "type": "zip",
    14                 "url": "https://api.github.com/repos/EmranAhmed/storepress-admin-utils/zipball/36b4d595519ae25f3be2625f70e16b9ef8769cfa",
    15                 "reference": "36b4d595519ae25f3be2625f70e16b9ef8769cfa",
     81                "url": "https://api.github.com/repos/EmranAhmed/storepress-admin-utils/zipball/69b5cb4b5a2b4625dbdb2a6bd3344c5e35fa5837",
     82                "reference": "69b5cb4b5a2b4625dbdb2a6bd3344c5e35fa5837",
    1683                "shasum": ""
    1784            },
    18             "require": {
    19                 "php": ">=7.4"
     85            "require-dev": {
     86                "automattic/vipwpcs": "^3.0",
     87                "php-stubs/woocommerce-stubs": "^9.0",
     88                "phpcompatibility/phpcompatibility-wp": "^2.1.5",
     89                "phpstan/extension-installer": "^1.4",
     90                "phpstan/phpstan-strict-rules": "^1.6",
     91                "szepeviktor/phpstan-wordpress": "^1.3",
     92                "woocommerce/woocommerce-sniffs": "^1.0.0",
     93                "wp-cli/i18n-command": "^v2.6.0",
     94                "wp-coding-standards/wpcs": "^3.1.0"
    2095            },
    21             "require-dev": {
    22                 "phpcompatibility/phpcompatibility-wp": "^2.1.4",
    23                 "wp-coding-standards/wpcs": "^3.0.1"
    24             },
    25             "time": "2024-04-24T07:44:14+00:00",
     96            "time": "2024-07-01T12:29:55+00:00",
    2697            "type": "library",
    2798            "installation-source": "dist",
     
    33104            "notification-url": "https://packagist.org/downloads/",
    34105            "license": [
    35                 "GPL-3.0-or-later"
     106                "GPL-2.0-or-later"
    36107            ],
    37108            "authors": [
     
    42113            ],
    43114            "description": "Utility Classes for WordPress Plugin Projects.",
     115            "homepage": "https://github.com/EmranAhmed/storepress-admin-utils#readme",
    44116            "keywords": [
    45117                "plugin",
     
    53125            "support": {
    54126                "issues": "https://github.com/EmranAhmed/storepress-admin-utils/issues",
    55                 "source": "https://github.com/EmranAhmed/storepress-admin-utils/tree/1.8.5"
     127                "source": "https://github.com/EmranAhmed/storepress-admin-utils/tree/1.8.8"
    56128            },
    57129            "install-path": "../storepress/admin-utils"
  • woo-2checkout/trunk/vendor/composer/installed.php

    r3081706 r3140508  
    44        'pretty_version' => 'dev-master',
    55        'version' => 'dev-master',
    6         'reference' => 'bb7bfb37f35a118844290275253ed6720fa7a5ab',
     6        'reference' => 'be918cf066aec0cb8d530068b20d3f1ec069e8a8',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1111    ),
    1212    'versions' => array(
     13        'automattic/jetpack-autoloader' => array(
     14            'pretty_version' => 'v3.0.9',
     15            'version' => '3.0.9.0',
     16            'reference' => 'a571038214fc3e142e10f38d1bb97e470fa7b0ec',
     17            'type' => 'composer-plugin',
     18            'install_path' => __DIR__ . '/../automattic/jetpack-autoloader',
     19            'aliases' => array(),
     20            'dev_requirement' => false,
     21        ),
    1322        'storepress/admin-utils' => array(
    14             'pretty_version' => '1.8.5',
    15             'version' => '1.8.5.0',
    16             'reference' => '36b4d595519ae25f3be2625f70e16b9ef8769cfa',
     23            'pretty_version' => '1.8.8',
     24            'version' => '1.8.8.0',
     25            'reference' => '69b5cb4b5a2b4625dbdb2a6bd3344c5e35fa5837',
    1726            'type' => 'library',
    1827            'install_path' => __DIR__ . '/../storepress/admin-utils',
     
    2332            'pretty_version' => 'dev-master',
    2433            'version' => 'dev-master',
    25             'reference' => 'bb7bfb37f35a118844290275253ed6720fa7a5ab',
     34            'reference' => 'be918cf066aec0cb8d530068b20d3f1ec069e8a8',
    2635            'type' => 'wordpress-plugin',
    2736            'install_path' => __DIR__ . '/../../',
  • woo-2checkout/trunk/vendor/composer/platform_check.php

    r3044506 r3140508  
    55$issues = array();
    66
    7 if (!(PHP_VERSION_ID >= 70400)) {
    8     $issues[] = 'Your Composer dependencies require a PHP version ">= 7.4.0". You are running ' . PHP_VERSION . '.';
     7if (!(PHP_VERSION_ID >= 70000)) {
     8    $issues[] = 'Your Composer dependencies require a PHP version ">= 7.0.0". You are running ' . PHP_VERSION . '.';
    99}
    1010
  • woo-2checkout/trunk/vendor/storepress/admin-utils/README.md

    r3044506 r3140508  
    1111## Usage
    1212
    13 ### Plugin Class
     13### Plugin instance
     14
    1415```php
    1516<?php
     
    2728
    2829### Plugin `AdminPage.php`
     30
    2931```php
    3032<?php
     
    8688    // URL will be: `/wp-json/<page_id>/<rest_api_version>/settings`
    8789    public function show_in_rest(): ?string {
    88         return false;
    89     }
     90        return false;
     91    }
    9092    // NOTE: You have to create and proper access to get REST API response.
    9193    // Create: "Application Passwords" from "WP Admin -> Users -> Profile" to use.
    9294    // Will return: /wp-json/my-custom-uri/settings
    93     public function show_in_rest(): ?string {
    94         return 'my-custom-uri';
    95     }
     95    public function show_in_rest(): ?string {
     96        return 'my-custom-uri';
     97      }
    9698   
    9799    // Settings and Rest API Display Capability. Default is: manage_options
    98     public function capability(): string {
     100    public function capability(): string {
    99101        return 'edit_posts';
    100102    }
    101103   
    102104    // Change rest api version. Default is: v1
    103     public function rest_api_version(): string {
     105    public function rest_api_version(): string {
    104106        return 'v2';
    105107    }
     
    296298}
    297299```
    298 ### Section data structure.
     300
     301### Section data structure
     302
    299303```php
    300304array(
     
    304308)
    305309```
    306 ### Field data structure.
     310
     311### Field data structure
     312
    307313```php
    308314array(
     
    360366}
    361367```
     368
    362369- Now use `Settings::instance();` on `Plugin::init()`
    363370
     
    366373- URL will be: `/wp-json/<page_id>/<rest_api_version>/settings`
    367374
    368 ### Upgrade Notice:
     375### Upgrade Notice
     376
    369377- Show notice for incompatible extended plugin.
     378
    370379```php
    371380namespace Plugin_A;
     
    411420- Now use `Upgrade_Notice::instance();` on `Plugin::init()`
    412421
    413 ### Plugin Update:
     422### Plugin Update
     423
    414424- You must add `Update URI:` on plugin file header to perform update.
     425
    415426```php
    416427<?php
     
    421432*/
    422433```
     434
    423435### Plugin `Updater.php` file
     436
    424437```php
    425438<?php
     
    484497- Now use `Updater::instance();` on `Plugin::init()`
    485498
    486 ## Update Server:
     499## Update Server
    487500
    488501```php
  • woo-2checkout/trunk/vendor/storepress/admin-utils/composer.json

    r3081706 r3140508  
    11{
    2   "name" : "storepress/admin-utils",
    3   "description" : "Utility Classes for WordPress Plugin Projects.",
    4   "version" : "1.8.5",
    5   "license" : "GPL-3.0-or-later",
    6   "type" : "library",
    7   "keywords" : [
    8     "wordpress",
    9     "storepress",
    10     "plugin-settings-panel",
    11     "plugin-settings-api",
    12     "plugin-settings-rest-api",
    13     "plugin-updater",
    14     "plugin"
    15   ],
    16   "authors" : [
    17     {
    18       "name" : "Emran Ahmed",
    19       "email" : "emran.bd.08@gmail.com"
    20     }
    21   ],
    22   "minimum-stability" : "dev",
    23   "require" : {
    24     "php" : ">=7.4"
    25   },
    26   "require-dev" : {
    27     "phpcompatibility/phpcompatibility-wp" : "^2.1.4",
    28     "wp-coding-standards/wpcs" : "^3.0.1"
    29   },
    30   "autoload" : {
    31     "psr-4" : {
    32       "StorePress\\AdminUtils\\" : "includes/"
    33     }
    34   },
    35   "config" : {
    36     "optimize-autoloader" : true,
    37     "sort-packages" : true,
    38     "allow-plugins" : {
    39       "dealerdirect/phpcodesniffer-composer-installer" : true
    40     }
    41   }
     2    "name" : "storepress/admin-utils",
     3    "description" : "Utility Classes for WordPress Plugin Projects.",
     4    "version" : "1.8.8",
     5    "license" : "GPL-2.0-or-later",
     6    "type" : "library",
     7    "keywords" : [
     8        "wordpress",
     9        "storepress",
     10        "plugin-settings-panel",
     11        "plugin-settings-api",
     12        "plugin-settings-rest-api",
     13        "plugin-updater",
     14        "plugin"
     15    ],
     16    "authors" : [
     17        {
     18            "name" : "Emran Ahmed",
     19            "email" : "emran.bd.08@gmail.com"
     20        }
     21    ],
     22    "homepage" : "https://github.com/EmranAhmed/storepress-admin-utils#readme",
     23    "minimum-stability" : "dev",
     24    "require-dev" : {
     25        "automattic/vipwpcs" : "^3.0",
     26        "phpcompatibility/phpcompatibility-wp" : "^2.1.5",
     27        "woocommerce/woocommerce-sniffs" : "^1.0.0",
     28        "wp-cli/i18n-command" : "^v2.6.0",
     29        "wp-coding-standards/wpcs" : "^3.1.0",
     30        "php-stubs/woocommerce-stubs" : "^9.0",
     31        "phpstan/extension-installer" : "^1.4",
     32        "phpstan/phpstan-strict-rules" : "^1.6",
     33        "szepeviktor/phpstan-wordpress" : "^1.3"
     34    },
     35    "autoload" : {
     36        "psr-4" : {
     37            "StorePress\\AdminUtils\\" : "includes/"
     38        }
     39    },
     40    "config" : {
     41        "optimize-autoloader" : true,
     42        "sort-packages" : true,
     43        "allow-plugins" : {
     44            "dealerdirect/phpcodesniffer-composer-installer" : true,
     45            "phpstan/extension-installer" : true
     46        }
     47    },
     48    "scripts" : {
     49        "phpstan" : "./vendor/bin/phpstan analyse . --memory-limit=2G -vvv",
     50        "phpstan-report" : "./vendor/bin/phpstan analyse . --memory-limit=2G -vvv > phpstan.report.txt",
     51        "format" : "./vendor/bin/phpcbf --standard=phpcs.xml",
     52        "lint" : "./vendor/bin/phpcs --standard=phpcs.xml --warning-severity=6 --report-summary --report-source --ignore-annotations --report-full=phpcs-report.txt"
     53    }
    4254}
  • woo-2checkout/trunk/vendor/storepress/admin-utils/includes/Field.php

    r3044506 r3140508  
    11<?php
    22    /**
    3      * Admin Settings Field
     3     * Admin Settings Field Class File.
    44     *
    55     * @package    StorePress/AdminUtils
    6      * @version    1.0
     6     * @since      1.0.0
     7     * @version    1.0.0
    78     */
    89
     10    declare(strict_types=1);
     11
    912    namespace StorePress\AdminUtils;
    1013
    1114    defined( 'ABSPATH' ) || die( 'Keep Silent' );
    12 
    1315
    1416if ( ! class_exists( '\StorePress\AdminUtils\Field' ) ) {
    1517    /**
    16      * Admin Settings Field
     18     * Admin Settings Field Class.
    1719     *
    1820     * @name Field
     
    2022    class Field {
    2123
    22         /**
    23          * @var array
     24        use Common;
     25
     26        /**
     27         * Single field.
     28         *
     29         * @var string[]|array<string, mixed>
    2430         */
    2531        private array $field;
    2632        /**
     33         * Setting Object.
     34         *
    2735         * @var Settings
    2836         */
     
    3038
    3139        /**
     40         * Setting ID.
     41         *
    3242         * @var string
    3343         */
     
    3545
    3646        /**
    37          * Field
    38          *
    39          * @param array $field field Array.
     47         * Construct Field
     48         *
     49         * @param string[]|array<string, mixed> $field field Array.
    4050         */
    4151        public function __construct( array $field ) {
     
    4353        }
    4454
    45         /***
    46          * @param Settings $settings
    47          * @param array    $values
     55        /**
     56         * Add Settings.
     57         *
     58         * @param Settings             $settings Settings Object.
     59         * @param array<string, mixed> $values Settings values. Default is: array().
    4860         *
    4961         * @return self
     
    5264            $this->settings = $settings;
    5365
    54             if ( empty( $values ) ) {
     66            if ( $this->is_empty_array( $values ) ) {
    5567                $this->populate_option_values();
    5668            } else {
     
    6476
    6577        /**
     78         * Populate all values.
     79         *
    6680         * @return void
    6781         */
     
    8195
    8296        /**
    83          * @param array $values
     97         * Populate from passed values.
     98         *
     99         * @param array<string, mixed> $values Values.
    84100         *
    85101         * @return void
     
    92108        }
    93109
    94         /***
     110        /**
     111         * Get Settings Object.
     112         *
    95113         * @return Settings
    96114         */
     
    100118
    101119        /**
    102          * @param mixed $value
     120         * Add value.
     121         *
     122         * @param string|string[]|numeric|bool|null $value Pass value.
    103123         *
    104124         * @return self
     
    111131
    112132        /**
     133         * Get settings id.
     134         *
    113135         * @return string
    114136         */
     
    118140
    119141        /**
    120          * @param string $settings_id
     142         * Add settings id.
     143         *
     144         * @param string $settings_id Settings ID.
    121145         *
    122146         * @return self
     
    129153
    130154        /**
    131          * @return mixed|null
     155         * Get default value.
     156         *
     157         * @return string|string[]|bool|numeric|null
    132158         */
    133159        public function get_default_value() {
     
    136162
    137163        /**
    138          * @param boolean $is_group
     164         * Generate setting name
     165         *
     166         * @param boolean $is_group Pass group name to get name based on group.
    139167         *
    140168         * @return string
     
    148176
    149177        /**
     178         * Generate private name.
     179         *
    150180         * @return string
    151181         */
     
    158188
    159189        /**
     190         * Check field is private or not.
     191         *
    160192         * @return bool
    161193         */
     
    165197
    166198        /**
    167          * @param $default
    168          *
    169          * @return mixed|null
    170          */
    171         public function get_value( $default = null ) {
    172             return $this->get_attribute( 'value', $default ?? $this->get_default_value() );
    173         }
    174 
    175         /**
    176          * @return array
     199         * Get value
     200         *
     201         * @param bool|string|string[]|null $default_value Default value.
     202         *
     203         * @return bool|string|string[]|null
     204         */
     205        public function get_value( $default_value = null ) {
     206            return $this->get_attribute( 'value', $default_value ?? $this->get_default_value() );
     207        }
     208
     209        /**
     210         * Get available options
     211         *
     212         * @return string[]|array<string, string>
    177213         */
    178214        public function get_options(): array {
     
    181217
    182218        /**
     219         * Get field type.
     220         *
    183221         * @return string
    184222         */
     
    188226            $keys  = array_keys( $alias );
    189227
    190             if ( in_array( $type, $keys ) ) {
     228            if ( in_array( $type, $keys, true ) ) {
    191229                return $alias[ $type ];
    192230            }
     
    196234
    197235        /**
     236         * Get field raw type
     237         *
    198238         * @return string
    199239         */
     
    203243
    204244        /**
     245         * Check field has custom sanitize function.
     246         *
    205247         * @return bool
    206248         */
     
    210252
    211253        /**
     254         * Check field has custom escaping function.
     255         *
    212256         * @return bool
    213257         */
     
    232276                case 'email':
    233277                    return 'sanitize_email';
    234                     break;
    235278                case 'url':
    236279                    return 'sanitize_url';
    237                     break;
    238280                case 'textarea':
    239281                    return 'sanitize_textarea_field';
    240                     break;
    241282                case 'color':
    242283                    return 'sanitize_hex_color';
    243                     break;
    244284                case 'number':
    245285                    return 'absint';
    246                     break;
    247286                default:
    248287                    return 'sanitize_text_field';
    249                     break;
    250             }
    251         }
    252 
    253         /**
    254          * Escape data before display from database. Escape data on output.
     288            }
     289        }
     290
     291        /**
     292         * Escaping function. escape data before display from database. Escape data on output.
    255293         *
    256294         * @return string
     
    267305                case 'email':
    268306                    return 'sanitize_email';
    269                     break;
    270307                case 'url':
    271308                    return 'esc_url';
    272                     break;
    273309                case 'textarea':
    274310                    return 'esc_textarea';
    275                     break;
    276311                case 'color':
    277312                    return 'sanitize_hex_color';
    278                     break;
    279313                case 'number':
    280314                    return 'absint';
    281                     break;
    282315                default:
    283316                    return 'esc_html';
    284                     break;
    285             }
    286         }
    287 
    288         /**
     317            }
     318        }
     319
     320        /**
     321         * Check is group type.
     322         *
    289323         * @return bool
    290324         */
     
    294328
    295329        /**
     330         * Get field id.
     331         *
    296332         * @return string|null
    297333         */
     
    300336        }
    301337
     338        /**
     339         * Get available field sizes.
     340         *
     341         * @return string[]
     342         */
    302343        public function get_field_size_css_classes(): array {
    303344            return array( 'regular-text', 'small-text', 'tiny-text', 'large-text' );
     
    305346
    306347        /**
    307          * @param mixed $classes
    308          * @param mixed $default
     348         * Prepare field classes.
     349         *
     350         * @param string|string[] $classes Class names.
     351         * @param string|string[] $default_value Default value.
    309352         *
    310353         * @return string[]
    311354         */
    312         public function prepare_classes( $classes, $default = '' ): array {
    313 
    314             $default_classnames = is_array( $default ) ? $default : explode( ' ', $default );
     355        public function prepare_classes( $classes, $default_value = '' ): array {
     356
     357            $default_classnames = is_array( $default_value ) ? $default_value : explode( ' ', $default_value );
    315358            $setting_classnames = is_array( $classes ) ? $classes : explode( ' ', $classes );
    316359
     
    318361            $remove_default_size_class = false;
    319362
     363            /**
     364             * Settings Classes.
     365             *
     366             * @var string[] $setting_classnames
     367             */
    320368            foreach ( $setting_classnames as $setting_classname ) {
    321                 if ( in_array( $setting_classname, $this->get_field_size_css_classes() ) ) {
     369                if ( in_array( $setting_classname, $this->get_field_size_css_classes(), true ) ) {
    322370                    $remove_default_size_class = true;
    323371                }
    324372            }
    325373
     374            /**
     375             * Default Classes.
     376             *
     377             * @var string[] $default_classnames
     378             */
    326379            foreach ( $default_classnames as $default_classname ) {
    327                 if ( $remove_default_size_class && in_array( $default_classname, $this->get_field_size_css_classes() ) ) {
     380                if ( $remove_default_size_class && in_array( $default_classname, $this->get_field_size_css_classes(), true ) ) {
    328381                    continue;
    329382                }
     
    335388
    336389        /**
    337          * @return string|array
     390         * Get field class.
     391         *
     392         * @return string|string[]
    338393         */
    339394        public function get_css_class() {
     
    342397
    343398        /**
    344          * @return string
     399         * Get field suffix.
     400         *
     401         * @return string|null
    345402         */
    346403        public function get_suffix(): ?string {
     
    349406
    350407        /**
     408         * Get field title.
     409         *
    351410         * @return string|null
    352411         */
     
    356415
    357416        /**
    358          * @return array
     417         * Get field data.
     418         *
     419         * @return string[]|array<string, mixed>
    359420         */
    360421        public function get_field(): array {
     
    362423        }
    363424
    364 
    365         /**
    366          * @param string $attribute
     425        /**
     426         * Check has attribute.
     427         *
     428         * @param string $attribute Attribute name to check.
    367429         *
    368430         * @return bool
     
    375437
    376438        /**
    377          * @param string $attribute
    378          * @param mixed  $default . Default null.
    379          *
    380          * @return mixed|null
    381          */
    382         public function get_attribute( string $attribute, $default = null ) {
     439         * Check field shown in rest api.
     440         *
     441         * @return bool
     442         */
     443        public function has_show_in_rest(): bool {
     444
     445            if ( ! $this->has_attribute( 'show_in_rest' ) ) {
     446                return false;
     447            }
     448
     449            if ( false === $this->get_attribute( 'show_in_rest' ) ) {
     450                return false;
     451            }
     452
     453            if ( is_string( $this->get_attribute( 'show_in_rest' ) ) && $this->is_empty_string( $this->get_attribute( 'show_in_rest' ) ) ) {
     454                return false;
     455            }
     456
     457            return true;
     458        }
     459
     460        /**
     461         * Get attribute.
     462         *
     463         * @param string                    $attribute Attribute name.
     464         * @param string|string[]|null|bool $default_value Default value. Default null.
     465         *
     466         * @return string|string[]|null|bool
     467         */
     468        public function get_attribute( string $attribute, $default_value = null ) {
    383469            $field = $this->get_field();
    384470
    385             return $field[ $attribute ] ?? $default;
    386         }
    387 
     471            return $field[ $attribute ] ?? $default_value;
     472        }
     473
     474        /**
     475         * Get group inputs.
     476         *
     477         * @return string[]
     478         */
    388479        public function group_inputs(): array {
    389480            return array( 'radio', 'checkbox', 'group' );
     
    391482
    392483        /**
    393          * @param array $attrs
    394          * @param array $additional_attrs . Default array
    395          *
    396          * @return string
    397          */
    398         public function get_html_attributes( array $attrs, array $additional_attrs = array() ): string {
     484         * Get HTML Attributes.
     485         *
     486         * @param array<string, mixed> $attrs Attributes.
     487         * @param array<string, mixed> $additional_attrs Additional attributes. Default array().
     488         *
     489         * @return string
     490         */
     491        public function get_input_attributes( array $attrs, array $additional_attrs = array() ): string {
    399492
    400493            $attributes = wp_parse_args( $additional_attrs, $attrs );
    401494
    402             return implode(
    403                 ' ',
    404                 array_map(
    405                     function ( $key ) use ( $attributes ) {
    406 
    407                         if ( is_bool( $attributes[ $key ] ) ) {
    408                             return $attributes[ $key ] ? $key : '';
    409                         }
    410 
    411                                 $value = $attributes[ $key ];
    412 
    413                         if ( in_array( $key, array( 'class' ) ) ) {
    414 
    415                             if ( is_array( $attributes[ $key ] ) ) {
    416                                         // Class name sanitized.
    417                                         $value = implode( ' ', array_unique( $attributes[ $key ] ) );
    418                             }
    419                         }
    420 
    421                                 return sprintf( '%s="%s"', esc_attr( $key ), esc_attr( $value ) );
    422                     },
    423                     array_keys( $attributes )
    424                 )
    425             );
    426         }
    427 
     495            return $this->get_html_attributes( $attributes );
     496        }
     497
     498        /**
     499         * Creating custom input field.
     500         *
     501         * @return string
     502         */
    428503        public function custom_input(): string {
    429504
     
    435510
    436511            $message = sprintf( 'Field: "%s" not implemented. Please add "Settings::custom_field" method to implement.', $type );
    437             $this->get_settings()->trigger_error( '', $message );
     512            wp_trigger_error( '', $message );
    438513
    439514            return '';
    440515        }
    441516
    442         public function text_input( $css_class = 'regular-text' ): string {
     517        /**
     518         * Text input markup.
     519         *
     520         * @param string $css_class Input CSS class.
     521         *
     522         * @return string
     523         */
     524        public function text_input( string $css_class = 'regular-text' ): string {
    443525
    444526            $id                    = $this->get_id();
     
    475557            }
    476558
    477             return sprintf( '<input %s> %s', $this->get_html_attributes( $attributes, $additional_attributes ), $this->get_suffix() );
    478         }
    479 
    480         public function textarea_input( $css_class = 'regular-text' ): string {
     559            return sprintf( '<input %s /> %s', $this->get_input_attributes( $attributes, $additional_attributes ), $this->get_suffix() );
     560        }
     561
     562        /**
     563         * TextArea Input Markup.
     564         *
     565         * @param string $css_class TextArea css class.
     566         *
     567         * @return string
     568         */
     569        public function textarea_input( string $css_class = 'regular-text' ): string {
    481570
    482571            $id                    = $this->get_id();
     
    507596            }
    508597
    509             return sprintf( '<textarea %s>%s</textarea>', $this->get_html_attributes( $attributes, $additional_attributes ), $value );
    510         }
    511 
     598            return sprintf( '<textarea %s>%s</textarea>', $this->get_input_attributes( $attributes, $additional_attributes ), $value );
     599        }
     600
     601        /**
     602         * Checkbox Input
     603         *
     604         * @return string
     605         */
    512606        public function check_input(): string {
    513607
     
    519613            $options = $this->get_options();
    520614
    521             // group checkbox
     615            // Group checkbox. Options will be an array.
    522616            if ( 'checkbox' === $type && count( $options ) > 1 ) {
    523617                $name = $this->get_name( true );
    524618            }
    525619
    526             // single checkbox
    527             if ( 'checkbox' === $type && empty( $options ) ) {
     620            // Single checkbox. Option will be string.
     621            if ( 'checkbox' === $type && $this->is_empty_array( $options ) ) {
    528622                $options = array( 'yes' => $title );
    529623            }
    530624
    531             // check radio input have options declared.
    532             if ( 'radio' === $type && empty( $options ) ) {
    533                 $message = sprintf( 'Input Field: "%s". Title: "%s" need options to choose.', $id, $title );
    534                 $this->get_settings()->trigger_error( '', $message );
     625            // Check radio input have options declared.
     626            if ( 'radio' === $type && $this->is_empty_array( $options ) ) {
     627                $message = sprintf( 'Input Field: "%s". Title: "%s" need options to choose. "option"=>["key"=>"value"]', $id, $title );
     628                wp_trigger_error( '', $message );
    535629
    536630                return '';
     
    539633            $inputs = array();
    540634
     635            /**
     636             * Group Options.
     637             *
     638             * @var array<string, string> $options
     639             */
    541640            foreach ( $options as $option_key => $option_value ) {
    542641                $uniq_id = sprintf( '%s-%s', $id, $option_key );
     
    547646                    'name'    => $name,
    548647                    'value'   => esc_attr( $option_key ),
    549                     'checked' => ( 'checkbox' === $type ) ? in_array( $option_key, is_array( $value ) ? $value : array( $value ) ) : $value === $option_key,
     648                    'checked' => ( 'checkbox' === $type ) ? in_array( $option_key, is_array( $value ) ? $value : array( $value ), true ) : $value === $option_key,
    550649                );
    551650
    552                 $inputs[] = sprintf( '<label for="%s"><input %s /><span>%s</span></label>', esc_attr( $uniq_id ), $this->get_html_attributes( $attributes ), esc_html( $option_value ) );
     651                $inputs[] = sprintf( '<label for="%s"><input %s /><span>%s</span></label>', esc_attr( $uniq_id ), $this->get_input_attributes( $attributes ), esc_html( $option_value ) );
    553652            }
    554653
     
    556655        }
    557656
     657        /**
     658         * Select Input box.
     659         *
     660         * @return string
     661         */
    558662        public function select_input(): string {
    559663
     
    598702
    599703            foreach ( $options as $option_key => $option_value ) {
    600                 $selected = ( $is_multiple ) ? in_array( $option_key, is_array( $value ) ? $value : array( $value ) ) : $value === $option_key;
    601                 $inputs[] = sprintf( '<option %s value="%s"><span>%s</span></option>', $this->get_html_attributes( array( 'selected' => $selected ) ), esc_attr( $option_key ), esc_html( $option_value ) );
    602             }
    603 
    604             return sprintf( '<select %s>%s</select>', $this->get_html_attributes( $attributes, $additional_attributes ), implode( '', $inputs ) );
    605         }
    606 
    607         /**
    608          * @return self[]
     704                $selected = ( $is_multiple ) ? in_array( $option_key, is_array( $value ) ? $value : array( $value ), true ) : $value === $option_key;
     705                $inputs[] = sprintf( '<option %s value="%s"><span>%s</span></option>', $this->get_input_attributes( array( 'selected' => $selected ) ), esc_attr( $option_key ), esc_html( $option_value ) );
     706            }
     707
     708            return sprintf( '<select %s>%s</select>', $this->get_input_attributes( $attributes, $additional_attributes ), implode( '', $inputs ) );
     709        }
     710
     711        /**
     712         * Get group fields.
     713         *
     714         * @return Field[]
    609715         */
    610716        public function get_group_fields(): array {
     
    616722            $fields = array();
    617723
     724            /**
     725             * Group Filed object array
     726             *
     727             * @var array<string, string|string[]> $group_fields $group_fields
     728             */
     729
    618730            foreach ( $group_fields as $field ) {
    619731                $fields[] = ( new Field( $field ) )->add_settings( $this->get_settings(), $group_value )->add_settings_id( $name );
     
    623735        }
    624736
     737        /**
     738         * Get REST API Group values.
     739         *
     740         * @return array<string, string|string[]>
     741         */
    625742        public function get_rest_group_values(): array {
    626743
     
    629746            foreach ( $this->get_group_fields() as $field ) {
    630747
    631                 if ( empty( $field->get_attribute( 'show_in_rest' ) ) ) {
     748                if ( false === $field->has_show_in_rest() ) {
    632749                    continue;
    633750                }
     
    643760        }
    644761
     762        /**
     763         * Get REST API Value.
     764         *
     765         * @return mixed
     766         */
    645767        public function get_rest_value() {
    646768            $escape_callback = $this->get_escape_callback();
     
    649771        }
    650772
     773        /**
     774         * Get Group Values.
     775         *
     776         * @return array<string, mixed>
     777         */
    651778        public function get_group_values(): array {
    652779
     
    663790
    664791        /**
    665          * @param string $field_id
    666          * @param mixed  $default
    667          *
    668          * @return mixed|null
    669          */
    670         public function get_group_value( string $field_id, $default = null ) {
     792         * Get Group value.
     793         *
     794         * @param string                    $field_id Field ID.
     795         * @param bool|null|string|string[] $default_value Default group value.
     796         *
     797         * @return bool|null|string|string[]
     798         */
     799        public function get_group_value( string $field_id, $default_value = null ) {
    671800
    672801            foreach ( $this->get_group_fields() as $field ) {
    673802                $id = $field->get_id();
    674803                if ( $id === $field_id ) {
    675                     return $field->get_value( $default );
     804                    return $field->get_value( $default_value );
    676805                }
    677806            }
    678807
    679             return $default;
    680         }
    681 
    682         public function group_input( $css_class = 'small-text' ): string {
     808            return $default_value;
     809        }
     810
     811        /**
     812         * Group Input Markup.
     813         *
     814         * @param string $css_class Css Class.
     815         *
     816         * @return string
     817         */
     818        public function group_input( string $css_class = 'small-text' ): string {
    683819
    684820            $id           = $this->get_id();
     
    714850                );
    715851
    716                 // Group checkbox name
    717                 if ( 'checkbox' === $field_type && $field_options && count( $field_options ) > 1 ) {
     852                // Group checkbox name.
     853                if ( 'checkbox' === $field_type && count( $field_options ) > 1 ) {
    718854                    $attributes['name'] = $field->get_name( true );
    719855                }
    720856
    721                 if ( in_array( $field_type, $this->group_inputs() ) ) {
     857                if ( in_array( $field_type, $this->group_inputs(), true ) ) {
    722858
    723859                    $attributes['class'] = array();
    724860
    725                     // Single checkbox
    726                     if ( 'checkbox' === $field_type && empty( $field_options ) ) {
     861                    // Single checkbox.
     862                    if ( 'checkbox' === $field_type && $this->is_empty_array( $field_options ) ) {
    727863                        $attributes['value']   = 'yes';
    728864                        $attributes['checked'] = 'yes' === $field_value;
    729865
    730                         $inputs[] = sprintf( '<p class="input-wrapper"><label for="%s"><input %s /><span>%s</span></label></p>', esc_attr( $uniq_id ), $this->get_html_attributes( $attributes ), esc_html( $field_title ) );
     866                        $inputs[] = sprintf( '<p class="input-wrapper"><label for="%s"><input %s /><span>%s</span></label></p>', esc_attr( $uniq_id ), $this->get_input_attributes( $attributes ), esc_html( $field_title ) );
    731867
    732868                        continue;
    733869                    }
    734870
    735                     // Checkbox and Radio
     871                    // Checkbox and Radio.
    736872                    $inputs[] = '<ul class="input-wrapper">';
     873                    /**
     874                     * Group Options.
     875                     *
     876                     * @var array<string, string> $field_options
     877                     */
    737878                    foreach ( $field_options as $option_key => $option_value ) {
    738879                        $uniq_id               = sprintf( '%s-%s-%s__group', $id, $field_id, $option_key );
    739880                        $attributes['value']   = esc_attr( $option_key );
    740                         $attributes['checked'] = is_array( $field_value ) ? in_array( $option_key, $field_value ) : $option_key == $field_value;
     881                        $attributes['checked'] = is_array( $field_value ) ? in_array( $option_key, $field_value, true ) : $option_key == $field_value;
    741882                        $attributes['id']      = $uniq_id;
    742                         $inputs[]              = sprintf( '<li><label for="%s"><input %s /><span>%s</span></label></li>', esc_attr( $uniq_id ), $this->get_html_attributes( $attributes ), esc_html( $option_value ) );
     883                        $inputs[]              = sprintf( '<li><label for="%s"><input %s /><span>%s</span></label></li>', esc_attr( $uniq_id ), $this->get_input_attributes( $attributes ), esc_html( $option_value ) );
    743884                    }
    744885                    $inputs[] = '</ul>';
    745886
     887                } elseif ( 'textarea' === $field_type ) {
     888                    // Input box.
     889                        $attributes['value'] = false;
     890                        $inputs[]            = sprintf( '<p class="input-wrapper"><label for="%s"><span>%s</span></label> <textarea %s>%s</textarea></p>', esc_attr( $uniq_id ), esc_html( $field_title ), $this->get_input_attributes( $attributes, $field_attributes ), $field_value );
    746891                } else {
    747                     // Input
    748 
    749                     if ( 'textarea' === $field_type ) {
    750                         $attributes['value'] = false;
    751                         $inputs[]            = sprintf( '<p class="input-wrapper"><label for="%s"><span>%s</span></label> <textarea %s>%s</textarea></p>', esc_attr( $uniq_id ), esc_html( $field_title ), $this->get_html_attributes( $attributes, $field_attributes ), $field_value );
    752                     } else {
    753                         $inputs[] = sprintf( '<p class="input-wrapper"><label for="%s"><span>%s</span></label> <input %s /> %s</p>', esc_attr( $uniq_id ), esc_html( $field_title ), $this->get_html_attributes( $attributes, $field_attributes ), esc_html( $field_suffix ) );
    754                     }
     892                    $inputs[] = sprintf( '<p class="input-wrapper"><label for="%s"><span>%s</span></label> <input %s /> %s</p>', esc_attr( $uniq_id ), esc_html( $field_title ), $this->get_input_attributes( $attributes, $field_attributes ), esc_html( $field_suffix ) );
    755893                }
    756894            }
     
    759897        }
    760898
    761         public function get_rest_type(): ?string {
     899        /**
     900         * Get REST Type Primitive Types.
     901         *
     902         * @return string
     903         * @see https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#primitive-types
     904         * @example array( 'number', 'integer', 'string', 'boolean', 'array', 'object' )
     905         */
     906        public function get_rest_type(): string {
    762907
    763908            $type        = $this->get_type();
    764909            $options     = $this->get_options();
    765             $is_single   = empty( $options );
     910            $is_single   = $this->is_empty_array( $options );
    766911            $is_multiple = $this->has_attribute( 'multiple' );
    767912
    768             // array( 'number', 'integer', 'string', 'boolean', 'array', 'object' )
    769 
    770913            switch ( $type ) {
    771                 case 'textarea';
    772                 case 'email';
    773                 case 'url';
    774                 case 'text';
    775                 case 'regular-text';
    776                 case 'color';
    777                 case 'small-text';
    778                 case 'tiny-text';
    779                 case 'large-text';
    780                 case 'radio';
    781                 case 'code';
     914                case 'textarea':
     915                case 'email':
     916                case 'url':
     917                case 'text':
     918                case 'regular-text':
     919                case 'color':
     920                case 'small-text':
     921                case 'tiny-text':
     922                case 'large-text':
     923                case 'radio':
     924                case 'code':
    782925                    return 'string';
    783                     break;
    784                 case 'number';
     926                case 'number':
    785927                    return 'number';
    786                     break;
    787                 case 'checkbox';
     928                case 'checkbox':
    788929                    return $is_single ? 'string' : 'array';
    789                     break;
    790                 case 'select2';
    791                 case 'select';
     930                case 'select2':
     931                case 'select':
    792932                    return $is_multiple ? 'array' : 'string';
    793                     break;
    794                 case 'group';
     933                case 'group':
    795934                    return 'object';
    796                     break;
    797935            }
    798936
     
    801939
    802940        /**
     941         * Label Markup.
     942         *
    803943         * @return string
    804944         * @todo Label based on input
     
    810950            $type  = $this->get_type();
    811951
    812             if ( in_array( $type, $this->group_inputs() ) ) {
     952            if ( in_array( $type, $this->group_inputs(), true ) ) {
    813953                return $title;
    814954            }
     
    822962
    823963        /**
     964         * Get field type alias.
     965         *
    824966         * @return string[]
    825967         */
     
    836978        }
    837979
    838         /***
     980        /**
     981         * Get Input Markups
     982         *
    839983         * @return string
    840984         * @todo Add More Fields
    841985         * @see  Settings::sanitize_fields()
     986         * @example: input, code, textarea, select, select2, regular-text, small-text, tiny-text, large-text, color
    842987         */
    843988        public function get_input_markup(): string {
    844989            $type = $this->get_type();
    845             // input, code, textarea, select, select2, regular-text, small-text, tiny-text, large-text, color
    846990
    847991            switch ( $type ) {
    848                 case 'text';
    849                 case 'regular-text';
    850                 case 'code';
     992                case 'text':
     993                case 'regular-text':
     994                case 'code':
    851995                    return $this->text_input();
    852                     break;
    853                 case 'color';
    854                 case 'number';
    855                 case 'small-text';
     996                case 'color':
     997                case 'number':
     998                case 'small-text':
    856999                    return $this->text_input( 'small-text' );
    857                     break;
    858                 case 'tiny-text';
     1000                case 'tiny-text':
    8591001                    return $this->text_input( 'tiny-text' );
    860                     break;
    861                 case 'large-text';
     1002                case 'large-text':
    8621003                    return $this->text_input( 'large-text' );
    863                     break;
    864                 case 'radio';
    865                 case 'checkbox';
     1004                case 'radio':
     1005                case 'checkbox':
    8661006                    return $this->check_input();
    867                     break;
    868                 case 'select';
    869                 case 'select2';
     1007                case 'select':
     1008                case 'select2':
    8701009                    return $this->select_input();
    871                     break;
    872                 case 'group';
     1010                case 'group':
    8731011                    return $this->group_input();
    874                     break;
    875                 case 'textarea';
     1012                case 'textarea':
    8761013                    return $this->textarea_input();
    877                     break;
    8781014                default:
    8791015                    return $this->custom_input();
    880                     break;
    881             }
    882         }
    883 
    884         /**
     1016            }
     1017        }
     1018
     1019        /**
     1020         * Get field description markup.
     1021         *
    8851022         * @return string
    8861023         */
     
    8921029
    8931030        /**
     1031         * Display generated field
     1032         *
    8941033         * @return string
    8951034         */
  • woo-2checkout/trunk/vendor/storepress/admin-utils/includes/Fields.php

    r3044506 r3140508  
    11<?php
     2    /**
     3     * Admin Settings Fields Class File.
     4     *
     5     * @package    StorePress/AdminUtils
     6     * @since      1.0.0
     7     * @version    1.0.0
     8     */
     9
     10    declare(strict_types=1);
    211
    312    namespace StorePress\AdminUtils;
     
    514    defined( 'ABSPATH' ) || die( 'Keep Silent' );
    615
     16if ( ! class_exists( '\StorePress\AdminUtils\Fields' ) ) {
    717    /**
    8      * Admin Settings
     18     * Admin Settings Fields Class.
    919     *
    10      * @package    StorePress/AdminUtils
    1120     * @name Fields
    12      * @version    1.0
    1321     */
     22    class Fields {
    1423
    15 if ( ! class_exists( '\StorePress\AdminUtils\Fields' ) ) {
    16     class Fields {
     24        use Common;
     25
    1726        /**
    18          * @var array
     27         * Sections.
     28         *
     29         * @var array<string, object>
    1930         */
    2031        private array $sections = array();
    2132        /**
     33         * Last section ID.
     34         *
    2235         * @var string
    2336         */
     
    2538
    2639        /**
    27          * @param array    $fields
    28          * @param Settings $settings
     40         * Class Construct.
     41         *
     42         * @param array<string, string|string[]> $fields Field list.
     43         * @param Settings                       $settings Settings Class Instance.
    2944         */
    3045        public function __construct( array $fields, Settings $settings ) {
    3146
     47            /**
     48             * Fields
     49             *
     50             * @var array<string, string|string[]> $fields
     51             */
    3252            foreach ( $fields as $field ) {
    3353
     
    4868
    4969                // Generate section id when section not available on a tab.
    50                 if ( empty( $this->last_section_id ) ) {
     70                if ( $this->is_empty_string( $this->last_section_id ) ) {
    5171                    $this->sections[ $section_id ] = new Section(
    5272                        array(
     
    5878
    5979                if ( $this->is_field( $field ) ) {
    60                     // $value = $this->get_saved_value( $_field );
    61                     // $f     = $_field->add_value( $value )->add_settings_id( $this->get_settings()->get_settings_id() );
    6280                    $this->sections[ $this->last_section_id ]->add_field( $_field );
    6381                }
     
    6684
    6785        /**
    68          * @param array $field
     86         * Check is section or not.
     87         *
     88         * @param array<string, string> $field Single field.
    6989         *
    7090         * @return bool
     
    7595
    7696        /**
    77          * @param array $field
     97         * Check is field or not.
     98         *
     99         * @param array<string, string> $field Field array.
    78100         *
    79101         * @return bool
     
    84106
    85107        /**
     108         * Get section id.
     109         *
    86110         * @return string
    87111         */
     
    91115
    92116        /**
    93          * @param array $field
     117         * Get Field ID.
    94118         *
    95          * @return mixed
     119         * @param array<string, string> $field Field array.
     120         *
     121         * @return string
    96122         */
    97         public function get_field_id( array $field ) {
     123        public function get_field_id( array $field ): string {
    98124            return $field['id'];
    99125        }
    100126
    101127        /**
    102          * @return array
     128         * Get Sections.
     129         *
     130         * @return array<string, object>
    103131         */
    104132        public function get_sections(): array {
     
    107135
    108136        /**
     137         * Display fields with section wrapped.
     138         *
    109139         * @return void
    110140         */
    111141        public function display() {
     142
     143            $allowed_input_html = $this->get_kses_allowed_input_html();
    112144            /**
     145             * Section Instance.
     146             *
    113147             * @var Section $section
    114148             */
    115149            foreach ( $this->get_sections() as $section ) {
    116                 echo $section->display();
     150                echo wp_kses_post( $section->display() );
    117151
    118152                if ( $section->has_fields() ) {
    119153
    120                     echo $section->before_display_fields();
     154                    echo wp_kses_post( $section->before_display_fields() );
    121155                    /**
     156                     * Field Instance.
     157                     *
    122158                     * @var Field $field
    123159                     */
    124160                    foreach ( $section->get_fields() as $field ) {
    125                         echo $field->display();
     161                        echo wp_kses( $field->display(), $allowed_input_html );
    126162                    }
    127163
    128                     echo $section->after_display_fields();
     164                    echo wp_kses_post( $section->after_display_fields() );
    129165                }
    130166            }
  • woo-2checkout/trunk/vendor/storepress/admin-utils/includes/Menu.php

    r3044506 r3140508  
    11<?php
    2    
    3     namespace StorePress\AdminUtils;
    4    
    5     defined( 'ABSPATH' ) || die( 'Keep Silent' );
    6    
    72    /**
    8      * Admin Menu
     3     * Admin Settings Menu Class File.
    94     *
    105     * @package    StorePress/AdminUtils
     6     * @since      1.0.0
     7     * @version    1.0.0
     8     */
     9
     10    declare(strict_types=1);
     11
     12    namespace StorePress\AdminUtils;
     13
     14    defined( 'ABSPATH' ) || die( 'Keep Silent' );
     15
     16if ( ! class_exists( '\StorePress\AdminUtils\Menu' ) ) {
     17    /**
     18     * Admin Settings Menu Class.
     19     *
    1120     * @name Menu
    12      * @version    1.0
    1321     */
    14     if ( ! class_exists( '\StorePress\AdminUtils\Menu' ) ) {
    15        
    16         abstract class Menu {
    17            
    18             private static int   $position          = 2;
    19             private static array $slug_usages       = array();
    20             private string       $current_page_slug = '';
    21            
    22             /**
    23              * Menu constructor.
    24              */
    25             public function __construct() {
    26                
    27                 add_action( 'admin_menu', function () {
    28                     global $submenu, $menu;
    29                    
    30                     // Bail if submenu
     22    abstract class Menu {
     23
     24        use Common;
     25
     26        /**
     27         * Menu Position
     28         *
     29         * @var int $position Menu Position.
     30         */
     31        private static int $position = 2;
     32
     33        /**
     34         * Used menu slugs.
     35         *
     36         * @var array<string, int> $slug_usages Slug used in menu.
     37         */
     38
     39        private static array $slug_usages = array();
     40
     41        /**
     42         * Current Page Slug.
     43         *
     44         * @var string $current_page_slug Store Current visiting page slug.
     45         */
     46        private string $current_page_slug = '';
     47
     48        /**
     49         * Menu constructor.
     50         */
     51        public function __construct() {
     52
     53            add_action(
     54                'admin_menu',
     55                function () {
     56                    // Bail if submenu.
    3157                    if ( $this->is_submenu() ) {
    3258                        return;
    3359                    }
    34                    
    35                     // Create unique Menu.
    36                     foreach ( $menu as $m ) {
    37                         if ( $m[ 2 ] === $this->get_parent_slug() ) {
    38                             return;
    39                         }
     60
     61                    // Create Unique Parent Menu.
     62                    $parent_menu_url = (bool) trim( menu_page_url( $this->get_parent_slug(), false ) );
     63
     64                    if ( $parent_menu_url ) {
     65                        return;
    4066                    }
    41                    
     67
    4268                    $capability = $this->get_capability();
    43                    
    44                     $separator_menu_position = sprintf( '%s.%s', $this->get_menu_position(), self::$position );
     69
     70                    $separator_menu_position = (float) sprintf( '%d.%d', $this->get_menu_position(), self::$position );
    4571                    $this->admin_menu_separator( $separator_menu_position, $this->get_parent_slug(), $capability );
    46                     self::$position ++;
    47                    
    48                     $menu_position = sprintf( '%s.%s', $this->get_menu_position(), self::$position );
    49                     add_menu_page( $this->get_parent_menu_title(), $this->get_parent_menu_title(), $capability, $this->get_parent_slug(), '', $this->get_menu_icon(), $menu_position );
    50                     self::$position ++;
    51                 },          9 );
    52                
    53                 add_action( 'admin_menu', function () {
    54                     global $submenu, $menu;
    55                    
     72                    self::$position++;
     73
     74                    $menu_position = (float) sprintf( '%d.%d', $this->get_menu_position(), self::$position );
     75                    add_menu_page(
     76                        $this->get_parent_menu_title(),
     77                        $this->get_parent_menu_title(),
     78                        $capability,
     79                        $this->get_parent_slug(),
     80                        '__return_false',
     81                        $this->get_menu_icon(),
     82                        $menu_position
     83                    );
     84                    self::$position++;
     85                },
     86                9
     87            );
     88
     89            add_action(
     90                'admin_menu',
     91                function () {
     92
    5693                    $parent_slug = $this->get_parent_slug();
    57                    
     94
    5895                    $menu_slug = $this->get_page_slug();
    59                    
     96
    6097                    if ( ! isset( self::$slug_usages[ $menu_slug ] ) ) {
    6198                        self::$slug_usages[ $menu_slug ] = 0;
     
    63100                        self::$slug_usages[ $menu_slug ] += 1;
    64101                    }
    65                    
     102
    66103                    if ( 0 === self::$slug_usages[ $menu_slug ] ) {
    67104                        $this->current_page_slug = sprintf( '%s', $menu_slug );
     
    69106                        $this->current_page_slug = sprintf( '%s-%s', $menu_slug, self::$slug_usages[ $menu_slug ] );
    70107                    }
    71                    
     108
    72109                    $capability = $this->get_capability();
    73                    
    74                     $settings_page = add_submenu_page( $parent_slug, $this->page_title(), $this->menu_title(), $capability, $this->get_current_page_slug(), function () {
    75                        
    76                         if ( ! current_user_can( $this->get_capability() ) ) {
    77                             return;
     110
     111                    $settings_page = add_submenu_page(
     112                        $parent_slug,
     113                        $this->page_title(),
     114                        $this->menu_title(),
     115                        $capability,
     116                        $this->get_current_page_slug(),
     117                        function () {
     118
     119                            if ( ! current_user_can( $this->get_capability() ) ) {
     120                                return;
     121                            }
     122
     123                            $this->display_settings_page();
    78124                        }
    79                        
    80                         $this->display_settings_page();
    81                     } );
    82                    
    83                     add_action( 'load-' . $settings_page, function () {
    84                        
    85                         if ( ! current_user_can( $this->get_capability() ) ) {
    86                             return;
     125                    );
     126
     127                    add_action(
     128                        'load-' . $settings_page,
     129                        function () {
     130
     131                            if ( ! current_user_can( $this->get_capability() ) ) {
     132                                return;
     133                            }
     134
     135                            $this->settings_page_init();
    87136                        }
    88                        
    89                         $this->settings_page_init();
    90                     } );
    91                 },          12 );
    92                
    93                 add_action( 'admin_menu', function () {
    94                    
    95                     global $submenu, $menu;
    96                    
     137                    );
     138                },
     139                12
     140            );
     141
     142            add_action(
     143                'admin_menu',
     144                function () {
     145
    97146                    if ( $this->is_submenu() ) {
    98147                        return;
    99148                    }
    100                    
    101                     $slug = $this->get_parent_slug();
    102                    
    103                     if ( ! isset( $submenu[ $slug ] ) ) {
    104                         return;
    105                     }
    106                    
    107                     unset( $submenu[ $slug ][ 0 ] );
    108                 },          60 );
    109                
    110                 add_action( 'admin_init', function () {
    111                    
    112                     // Settings Actions
     149
     150                    // Remove duplicate menu.
     151                    $menu_slug = $this->get_parent_slug();
     152
     153                    remove_submenu_page( $menu_slug, $menu_slug );
     154                },
     155                60
     156            );
     157
     158            add_action(
     159                'admin_init',
     160                function () {
     161
     162                    // Process Settings Actions.
    113163                    $this->settings_actions();
    114                    
    115                     // Settings Init
     164
     165                    // Load Settings.
    116166                    $this->settings_init();
    117                 } );
    118                
    119                 add_action( 'rest_api_init', function () {
    120                     // Settings REST Init
     167                }
     168            );
     169
     170            add_action(
     171                'rest_api_init',
     172                function () {
     173                    // Settings REST Init.
    121174                    $this->rest_api_init();
    122                 } );
     175                }
     176            );
     177
     178            add_action(
     179                'admin_enqueue_scripts',
     180                function () {
     181                    wp_add_inline_style( 'admin-menu', '#adminmenu li.menu-top.wp-menu-separator { min-height: auto; }' );
     182                }
     183            );
     184        }
     185
     186        /**
     187         * REST API Init.
     188         *
     189         * @return void
     190         */
     191        abstract public function rest_api_init();
     192
     193        /**
     194         * Settings Init.
     195         *
     196         * @return void
     197         */
     198        abstract public function settings_init();
     199
     200        /**
     201         * Load Settings Page.
     202         *
     203         * @return void
     204         */
     205        abstract public function settings_page_init();
     206
     207        /**
     208         * Process Settings Actions.
     209         *
     210         * @return void
     211         */
     212        abstract public function settings_actions();
     213
     214        /**
     215         * Process Single Settings action.
     216         *
     217         * @param string $current_action action key.
     218         *
     219         * @return void
     220         */
     221        abstract public function process_actions( string $current_action );
     222
     223        /**
     224         * Set Parent Menu Slug
     225         *
     226         * @return string
     227         */
     228        abstract public function parent_menu(): string;
     229
     230        /**
     231         * Settings template. Can override for custom ui page.
     232         *
     233         * @see https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions
     234         * @return void
     235         */
     236        abstract public function display_settings_page();
     237
     238        /**
     239         * Get Parent Menu or Main Menu name
     240         *
     241         * @return string
     242         */
     243        public function get_parent_menu(): string {
     244            return $this->parent_menu();
     245        }
     246
     247        /**
     248         * Set Parent Menu Title
     249         *
     250         * @return string
     251         */
     252        abstract public function parent_menu_title(): string;
     253
     254        /**
     255         * Get Parent or Main Menu Title
     256         *
     257         * @return string menu title;
     258         */
     259        public function get_parent_menu_title(): string {
     260            return $this->parent_menu_title();
     261        }
     262
     263        /**
     264         * Assign Parent Menu Icon
     265         *
     266         * @return string
     267         */
     268        abstract public function menu_icon(): string;
     269
     270        /**
     271         * Get Main Menu Icon
     272         *
     273         * @return string menu icon;
     274         */
     275        public function get_menu_icon(): string {
     276            return $this->menu_icon();
     277        }
     278
     279        /**
     280         * Assign Parent Menu Position
     281         *
     282         * @return int
     283         */
     284        abstract public function menu_position(): int;
     285
     286        /**
     287         * Get Main Menu Position
     288         *
     289         * @return int menu position;
     290         */
     291        public function get_menu_position(): int {
     292            return $this->menu_position();
     293        }
     294
     295        /**
     296         * Assign Settings Page Title.
     297         *
     298         * @return string Settings Page Title.
     299         */
     300        abstract public function page_title(): string;
     301
     302        /**
     303         * Get Settings Page Title.
     304         *
     305         * @return string Get Settings Page Title.
     306         */
     307        public function get_page_title(): string {
     308            return $this->page_title();
     309        }
     310
     311        /**
     312         * Assign Settings Page Menu Title.
     313         *
     314         * @return string Settings Page Menu Title.
     315         */
     316        abstract public function menu_title(): string;
     317
     318        /**
     319         * Get Settings Page Menu Title.
     320         *
     321         * @return string
     322         */
     323        public function get_menu_title(): string {
     324            return $this->menu_title();
     325        }
     326
     327        /**
     328         * Assign Settings Page ID.
     329         *
     330         * @return string Settings Page ID.
     331         */
     332        abstract public function page_id(): string;
     333
     334        /**
     335         * Get Settings Page ID.
     336         *
     337         * @return string
     338         */
     339        public function get_page_id(): string {
     340            return $this->page_id();
     341        }
     342
     343        /**
     344         * Assign Settings Page Showing Capability.
     345         *
     346         * @return string
     347         */
     348        abstract public function capability(): string;
     349
     350        /**
     351         * Get Settings Page Showing Capability.
     352         *
     353         * @return string
     354         */
     355        public function get_capability(): string {
     356            return $this->capability();
     357        }
     358
     359        /**
     360         * Add Menu Separator.
     361         *
     362         * @return bool
     363         */
     364        public function add_menu_separator(): bool {
     365            return true;
     366        }
     367
     368        /**
     369         * Adding Main Admin Menu Separator
     370         *
     371         * @param float  $position Separator Position.
     372         * @param string $separator_additional_class Separator Additional Class. Default: empty.
     373         * @param string $capability                 Menu Separator Capability. Default: manage_options.
     374         *
     375         * @return void
     376         */
     377        private function admin_menu_separator( float $position, string $separator_additional_class = '', string $capability = 'manage_options' ): void {
     378
     379            if ( ! current_user_can( $capability ) ) {
     380                return;
    123381            }
    124            
    125             abstract public function rest_api_init();
    126            
    127             abstract public function settings_init();
    128            
    129             abstract public function settings_page_init();
    130            
    131             abstract public function settings_actions();
    132            
    133             abstract public function process_actions( $current_action );
    134            
    135             /**
    136              * Parent Menu Slug
    137              *
    138              * @return string
    139              */
    140             abstract public function parent_menu(): string;
    141            
    142             /**
    143              * Get Parent or Main Menu name
    144              *
    145              * @return string menu unique name;
    146              */
    147             public function get_parent_menu(): string {
    148                 return $this->parent_menu();
     382
     383            if ( ! $this->add_menu_separator() ) {
     384                return;
    149385            }
    150            
    151             /**
    152              * Parent Menu and Page Title
    153              *
    154              * @return string
    155              */
    156             abstract public function parent_menu_title(): string;
    157            
    158             /**
    159              * Get Parent or Main Menu Title
    160              *
    161              * @return string menu title;
    162              */
    163             public function get_parent_menu_title(): string {
    164                 return $this->parent_menu_title();
    165             }
    166            
    167             /**
    168              * Parent Menu Icon
    169              *
    170              * @return string
    171              */
    172             abstract public function menu_icon(): string;
    173            
    174             /**
    175              * Get Main Menu Icon
    176              *
    177              * @return string menu icon;
    178              */
    179             public function get_menu_icon(): string {
    180                 return $this->menu_icon();
    181             }
    182            
    183             /**
    184              * Parent Menu Position
    185              *
    186              * @return string
    187              */
    188             abstract public function menu_position(): string;
    189            
    190             /**
    191              * Get Main Menu Position
    192              *
    193              * @return string menu position;
    194              */
    195             public function get_menu_position(): string {
    196                 return $this->menu_position();
    197             }
    198            
    199             /**
    200              * @return string
    201              */
    202             abstract public function page_title(): string;
    203            
    204             /**
    205              * @return string
    206              */
    207             public function get_page_title(): string {
    208                 return $this->page_title();
    209             }
    210            
    211             /**
    212              * @return string
    213              */
    214             abstract public function menu_title(): string;
    215            
    216             /**
    217              * @return string
    218              */
    219             public function get_menu_title(): string {
    220                 return $this->menu_title();
    221             }
    222            
    223             /**
    224              * @return string
    225              */
    226             abstract public function page_id(): string;
    227            
    228             /**
    229              * @return string
    230              */
    231             public function get_page_id(): string {
    232                 return $this->page_id();
    233             }
    234            
    235             /**
    236              * @return string
    237              */
    238             abstract public function capability(): string;
    239            
    240             /**
    241              * @return string
    242              */
    243             public function get_capability(): string {
    244                 return $this->capability();
    245             }
    246            
    247             /**
    248              * @return bool
    249              */
    250             public function add_menu_separator(): bool {
    251                 return true;
    252             }
    253            
    254             /**
    255              * Adding Main Admin Menu Separator
    256              *
    257              * @param numeric-string $position                   Separator Position
    258              * @param string         $separator_additional_class Separator Additional Class. Default: empty.
    259              * @param string         $capability                 Menu Separator Capability. Default: manage_options.
    260              *
    261              * @return void
    262              */
    263             private function admin_menu_separator( string $position, string $separator_additional_class = '', string $capability = 'manage_options' ): void {
    264                 global $menu;
    265                
    266                 if ( ! current_user_can( $capability ) ) {
    267                     return;
    268                 }
    269                
    270                 if ( ! $this->add_menu_separator() ) {
    271                     return;
    272                 }
    273                
    274                 $menu[ $position ] = array(
    275                     '',
    276                     'read',
    277                     sprintf( 'separator-%s', strtolower( $separator_additional_class ) ),
    278                     '',
    279                     sprintf( 'wp-menu-separator %s', strtolower( $separator_additional_class ) ),
    280                 );
    281                 ksort( $menu );
    282             }
    283            
    284             /**
    285              * Check if menu is main menu or submenu
    286              *
    287              * @return boolean
    288              */
    289             public function is_submenu(): bool {
    290                 return str_contains( $this->get_parent_slug(), '.php' );
    291             }
    292            
    293             /**
    294              * @return string
    295              */
    296             private function get_page_slug(): string {
    297                 return $this->get_page_id();
    298             }
    299            
    300             /**
    301              * @return string
    302              */
    303             public function get_current_page_slug(): string {
    304                 return $this->current_page_slug;
    305             }
    306            
    307             /**
    308              * @return string
    309              */
    310             public function get_parent_slug(): string {
    311                 return $this->get_parent_menu();
    312             }
    313            
    314             /**
    315              * @param string $function_name
    316              * @param string $message
    317              *
    318              * @return void
    319              */
    320             final public function trigger_error( string $function_name, string $message ) {
    321                
    322                 // Bail out if WP_DEBUG is not turned on.
    323                 if ( ! WP_DEBUG ) {
    324                     return;
    325                 }
    326                
    327                 if ( function_exists( 'wp_trigger_error' ) ) {
    328                     wp_trigger_error( $function_name, $message );
    329                 } else {
    330                    
    331                     if ( ! empty( $function_name ) ) {
    332                         $message = sprintf( '%s(): %s', $function_name, $message );
    333                     }
    334                    
    335                     $message = wp_kses( $message, array(
    336                         'a' => array( 'href' ),
    337                         'br',
    338                         'code',
    339                         'em',
    340                         'strong',
    341                     ),                  array( 'http', 'https' ) );
    342                    
    343                     trigger_error( $message );
    344                 }
    345             }
     386
     387            $menu_slug = sprintf( 'menu_separator_%s wp-menu-separator', strtolower( $separator_additional_class ) );
     388
     389            add_menu_page(
     390                '',
     391                '',
     392                $capability,
     393                $menu_slug,
     394                '__return_false',
     395                'none',
     396                $position
     397            );
     398        }
     399
     400        /**
     401         * Check if menu is main menu or submenu
     402         *
     403         * @return boolean
     404         */
     405        public function is_submenu(): bool {
     406            return str_contains( $this->get_parent_slug(), '.php' );
     407        }
     408
     409        /**
     410         * Get Page ID.
     411         *
     412         * @return string
     413         */
     414        private function get_page_slug(): string {
     415            return $this->get_page_id();
     416        }
     417
     418        /**
     419         * Get Current Page Slug.
     420         *
     421         * @return string
     422         */
     423        public function get_current_page_slug(): string {
     424            return $this->current_page_slug;
     425        }
     426
     427        /**
     428         * Get parent page slug.
     429         *
     430         * @return string
     431         */
     432        public function get_parent_slug(): string {
     433            return $this->get_parent_menu();
    346434        }
    347435    }
     436}
  • woo-2checkout/trunk/vendor/storepress/admin-utils/includes/REST_API.php

    r3081706 r3140508  
    11<?php
    2 
    3     namespace StorePress\AdminUtils;
    4 
    5     defined( 'ABSPATH' ) || die( 'Keep Silent' );
    6 
    72    /**
    8      * Settings REST API
     3     * Admin Settings Rest API Class File.
    94     *
    105     * @package    StorePress/AdminUtils
     6     * @since      1.0.0
     7     * @version    1.0.0
     8     */
     9
     10    declare(strict_types=1);
     11
     12    namespace StorePress\AdminUtils;
     13
     14    defined( 'ABSPATH' ) || die( 'Keep Silent' );
     15
     16if ( ! class_exists( '\StorePress\AdminUtils\REST_API' ) ) {
     17    /**
     18     * Admin Settings REST API Class.
     19     *
    1120     * @name REST_API
    12      * @see        WP_REST_Controller
     21     * @see \WP_REST_Controller
    1322     * @example    Default REST URL /wp-json/<plugin-page-id>/v1/settings
    14      * @version    1.0
    1523     */
    16 
    17 if ( ! class_exists( '\StorePress\AdminUtils\REST_API' ) ) {
    1824    class REST_API extends \WP_REST_Controller {
    1925
    20         /**
    21          * Constructor.
     26        use Common;
     27
     28        /**
     29         * Settings Object.
     30         *
     31         * @var Settings
    2232         */
    2333        protected Settings $settings;
     34        /**
     35         * API Display Permission.
     36         *
     37         * @var string
     38         */
    2439        protected string $permission;
    2540
     41        /**
     42         * API Namespace.
     43         *
     44         * @var string
     45         */
    2646        protected $namespace;
     47
     48        /**
     49         * Rest base.
     50         *
     51         * @var string
     52         */
    2753        protected $rest_base = 'settings';
    2854
     55        /**
     56         * Construct.
     57         *
     58         * @param Settings $settings Setting Class Instance.
     59         */
    2960        public function __construct( Settings $settings ) {
    3061            $this->settings   = $settings;
     
    3465
    3566        /**
     67         * Get Settings Object.
     68         *
    3669         * @return Settings
    3770         */
     
    4376         * Registers the routes for the StorePress's settings.
    4477         *
     78         * @return void
    4579         * @see register_rest_route()
    4680         */
    4781        public function register_routes() {
    4882
    49             if ( empty( $this->namespace ) ) {
     83            if ( $this->is_empty_string( $this->namespace ) ) {
    5084                return;
    5185            }
    5286
    53             // See: https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/
     87            // @see: https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/
    5488            register_rest_route(
    5589                $this->namespace,
     
    71105         * Checks if a given request has access to read and manage settings.
    72106         *
     107         * @phpstan-param \WP_REST_Request $request
    73108         * @param \WP_REST_Request $request Full details about the request.
    74109         *
    75          * @return bool True if the request has read access for the item, otherwise false.
     110         * @return bool TRUE if the request has read access for the item, otherwise FALSE.
     111         * @phpstan-ignore missingType.generics, method.childReturnType
    76112         */
    77113        public function get_item_permissions_check( $request ): bool {
     
    85121         *
    86122         * @return \WP_REST_Response|\WP_Error Array on success, or WP_Error object on failure.
     123         * @see \WP_REST_Settings_Controller::get_item()
     124         * @phpstan-ignore missingType.generics
    87125         */
    88126        public function get_item( $request ) {
    89             $options = $this->get_registered_options();
    90             $page_id = $this->get_settings()->get_page_id();
     127            $options  = $this->get_registered_options();
     128            $page_id  = $this->get_settings()->get_page_id();
    91129            $response = array();
    92130
     
    103141                 * @param string $name   Setting name (as shown in REST API responses).
    104142                 * @param array  $args   Custom field array with value.
     143                 * @since 1.0.0
    105144                 */
    106                 $response[ $name ] = apply_filters( "rest_pre_get_{$page_id}_setting", null, $name, $args );
     145                $response[ $name ] = apply_filters( "storepress_rest_pre_get_{$page_id}_setting", null, $name, $args );
    107146
    108147                if ( is_null( $response[ $name ] ) ) {
    109                     // Set value
     148                    // Set value.
    110149                    $response[ $name ] = $args['value'];
    111150                }
     
    117156                $response[ $name ] = $this->prepare_value( $response[ $name ], $args['schema'] );
    118157            }
    119            
     158
    120159            return new \WP_REST_Response( $response, 200 );
    121             // return $response;
    122160        }
    123161
     
    125163         * Prepares a value for output based off a schema array.
    126164         *
    127          * @param mixed $value  Value to prepare.
    128          * @param array $schema Schema to match.
     165         * @param mixed                          $value  Value to prepare.
     166         * @param array<string, string|string[]> $schema Schema to match.
    129167         *
    130168         * @return mixed The prepared value.
    131169         */
    132         protected function prepare_value( $value, $schema ) {
     170        protected function prepare_value( $value, array $schema ) {
    133171            /*
    134172             * If the value is not valid by the schema, set the value to null.
     
    146184         * Retrieves all the registered options for the Settings API.
    147185         *
    148          * @return array Array of registered options.
     186         * @return array<string, mixed> Array of registered options.
     187         * @see https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/
    149188         */
    150189        protected function get_registered_options(): array {
    151190            $rest_options = array();
    152191
    153             // See: https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/ .
    154 
    155192            foreach ( $this->get_settings()->get_all_fields() as $name => $field ) {
    156193
    157                 if ( empty( $field->get_attribute( 'show_in_rest' ) ) ) {
     194                if ( ! $field->has_show_in_rest() ) {
    158195                    continue;
    159196                }
     
    166203
    167204                $defaults = array(
    168                     'name'   => ! empty( $rest_args['name'] ) ? $rest_args['name'] : $field->get_id(),
     205                    'name'   => $rest_args['name'] ?? $field->get_id(),
    169206                    'schema' => array(),
    170207                );
     
    175212                    'type'        => $field->get_rest_type(),
    176213                    'description' => $field->get_title(),
    177                     // 'readonly'    => true,
     214                    /** 'readonly'    => true,
    178215                    // 'context'     => array( 'view' ),
    179216                    // 'default'     => $field->get_default_value(),
     217                    */
    180218                );
    181219
     
    191229                    $default_schema['format'] = 'uri';
    192230                }
    193                
     231
    194232                if ( 'email' === $field->get_type() ) {
    195233                    $default_schema['format'] = 'email';
     
    206244                        $id = $group_field->get_id();
    207245
    208                         if ( empty( $group_field->get_attribute( 'show_in_rest' ) ) ) {
     246                        if ( ! $group_field->has_show_in_rest() ) {
    209247                            continue;
    210248                        }
     
    225263
    226264                        if ( 'color' === $group_field->get_type() ) {
     265                            // @phpstan-ignore offsetAssign.dimType
    227266                            $default_properties[ $id ]['type']['format'] = 'hex-color';
    228267                        }
     
    253292
    254293                // Skip over settings that don't have a defined type in the schema.
    255                 if ( empty( $rest_args['schema']['type'] ) ) {
     294                if ( $this->is_empty_string( $rest_args['schema']['type'] ) ) {
    256295                    continue;
    257296                }
     
    276315         * Retrieves the site setting schema, conforming to JSON Schema.
    277316         *
    278          * @return array Item schema data.
     317         * @return array<string, mixed> Item schema data.
    279318         */
    280319        public function get_item_schema(): array {
    281             if ( $this->schema ) {
     320            if ( $this->is_empty_array( $this->schema ) ) {
    282321                return $this->add_additional_fields_schema( $this->schema );
    283322            }
     
    316355         *
    317356         * @return mixed|\WP_Error
    318          */
    319         public function sanitize_callback( $value, $request, $param ) {
     357         * @phpstan-ignore missingType.generics
     358         */
     359        public function sanitize_callback( $value, \WP_REST_Request $request, string $param ) {
    320360            if ( is_null( $value ) ) {
    321361                return $value;
  • woo-2checkout/trunk/vendor/storepress/admin-utils/includes/Section.php

    r3044506 r3140508  
    11<?php
     2    /**
     3     * Admin Settings Section Class File.
     4     *
     5     * @package    StorePress/AdminUtils
     6     * @since      1.0.0
     7     * @version    1.0.0
     8     */
     9
     10    declare(strict_types=1);
    211
    312    namespace StorePress\AdminUtils;
     
    514    defined( 'ABSPATH' ) || die( 'Keep Silent' );
    615
     16if ( ! class_exists( '\StorePress\AdminUtils\Section' ) ) {
    717    /**
    8      * Admin Settings
     18     * Admin Settings Section Class.
    919     *
    10      * @package    StorePress/AdminUtils
    1120     * @name Section
    12      * @version    1.0
    1321     */
    14 if ( ! class_exists( '\StorePress\AdminUtils\Section' ) ) {
    1522    class Section {
    1623
     24        use Common;
     25
    1726        /**
    18          * @var array
     27         * Section data.
     28         *
     29         * @var array<string, mixed>
    1930         */
    2031        private array $section;
    2132
    2233        /**
    23          * @param array $section
     34         * Construct section from array.
     35         *
     36         * @param array<string, mixed> $section Section array.
    2437         */
    2538        public function __construct( array $section ) {
     
    3649
    3750        /**
     51         * Get section ID.
     52         *
    3853         * @return string
    3954         */
     
    4358
    4459        /**
     60         * Get Section title.
     61         *
    4562         * @return string
    4663         */
     
    4966        }
    5067
    51         public function has_title(): string {
    52             return ! empty( $this->section['title'] );
     68        /**
     69         * Check section title.
     70         *
     71         * @return bool
     72         */
     73        public function has_title(): bool {
     74            return ! $this->is_empty_string( $this->section['title'] );
    5375        }
    5476
    5577        /**
     78         * Get section description.
     79         *
    5680         * @return string
    5781         */
     
    6084        }
    6185
    62         public function has_description(): string {
    63             return ! empty( $this->section['description'] );
     86        /**
     87         * Check section has description defined.
     88         *
     89         * @return bool
     90         */
     91        public function has_description(): bool {
     92            return ! $this->is_empty_string( $this->section['description'] );
    6493        }
    6594
    6695        /**
    67          * @return array
     96         * Get fields array from section.
     97         *
     98         * @return array<string, mixed>
    6899         */
    69100        public function get_fields(): array {
     
    72103
    73104        /**
     105         * Check fields available on section.
     106         *
    74107         * @return bool
    75108         */
    76109        public function has_fields(): bool {
    77             return ! empty( $this->section['fields'] );
     110            return ! $this->is_empty_array( $this->section['fields'] );
    78111        }
    79112
    80113        /**
    81          * @param Field $field
     114         * Add field to section.
     115         *
     116         * @param Field $field Field object.
    82117         *
    83118         * @return self
     
    90125
    91126        /**
     127         * Return section display.
     128         *
    92129         * @return string
    93130         */
     
    101138
    102139        /**
     140         * Markup before display section fields.
     141         *
    103142         * @return string
    104143         */
     
    112151
    113152        /**
     153         * Markup after display section fields.
     154         *
    114155         * @return string
    115156         */
  • woo-2checkout/trunk/vendor/storepress/admin-utils/includes/Settings.php

    r3081706 r3140508  
    11<?php
    2 
    3     namespace StorePress\AdminUtils;
    4 
    5     defined( 'ABSPATH' ) || die( 'Keep Silent' );
    6 
    72    /**
    8      * Admin Settings
     3     * Admin Settings Class file.
    94     *
    105     * @package    StorePress/AdminUtils
     6     * @since      1.0.0
     7     * @version    1.0.0
     8     */
     9
     10    declare(strict_types=1);
     11
     12    namespace StorePress\AdminUtils;
     13
     14    defined( 'ABSPATH' ) || die( 'Keep Silent' );
     15
     16if ( ! class_exists( '\StorePress\AdminUtils\Settings' ) ) {
     17
     18    /**
     19     * Admin Settings Class
     20     *
    1121     * @name Settings
    12      * @version    1.0
     22     * @see Menu
    1323     */
    14 if ( ! class_exists( '\StorePress\AdminUtils\Settings' ) ) {
    1524    abstract class Settings extends Menu {
    1625
    1726        /**
     27         * Fields callback function name convention.
     28         *
    1829         * @var string $fields_callback_fn_name_convention
    1930         */
    2031        private string $fields_callback_fn_name_convention = 'add_%s_settings_fields';
    2132        /**
     33         * Sidebar callback function name convention.
     34         *
    2235         * @var string $sidebar_callback_fn_name_convention
    2336         */
    2437        private string $sidebar_callback_fn_name_convention = 'add_%s_settings_sidebar';
    2538        /**
     39         * Page callback function name convention.
     40         *
    2641         * @var string $page_callback_fn_name_convention
    2742         */
    2843        private string $page_callback_fn_name_convention = 'add_%s_settings_page';
    2944        /**
    30          * @var array $options Store All Saved Options
     45         * Store All Saved Options
     46         *
     47         * @var array<string, mixed> $options
    3148         */
    3249        private array $options = array();
    3350
    3451        /**
     52         * Add Setting ID.
     53         *
    3554         * @return string
    3655         */
     
    3857
    3958        /**
     59         * Plugin File name.
     60         *
    4061         * @return string
    4162         */
     
    4364
    4465        /**
    45          * Show Settings in REST. If empty rest api will disable.
    46          *
     66         * Show Settings in REST. If empty or false rest api will disable.
     67         *
     68         * @return string|bool
    4769         * @example GET: /wp-json/<page-id>/<rest-api-version>/settings
    48          * @return string|bool
    49          */
    50         public function show_in_rest(): ?string {
     70         */
     71        public function show_in_rest() {
    5172            return sprintf( '%s/%s', $this->get_page_id(), $this->rest_api_version() );
    5273        }
     
    7091        }
    7192
     93        /**
     94         * Settings Hook
     95         *
     96         * @return void
     97         */
    7298        final public function settings_init() {
    7399            add_action( 'admin_enqueue_scripts', array( $this, 'register_admin_scripts' ), 20 );
    74             add_action( 'plugin_action_links_' . plugin_basename( $this->get_plugin_file() ), array( $this, 'plugin_action_links' ) );
    75         }
    76 
     100            add_filter( 'plugin_action_links_' . plugin_basename( $this->get_plugin_file() ), array( $this, 'plugin_action_links' ) );
     101        }
     102
     103        /**
     104         * Setting Action
     105         *
     106         * @return void
     107         */
    77108        final public function settings_actions() {
    78109
    79             $plugin_page    = sanitize_text_field( wp_unslash( $_GET['page'] ?? false ) );
    80             $current_action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ?? false ) );
    81 
    82             if ( $plugin_page && $current_action && $plugin_page === $this->get_current_page_slug() ) {
     110            if ( ! isset( $_REQUEST['action'] ) || ! isset( $_GET['page'] ) || $_GET['page'] !== $this->get_current_page_slug() ) {
     111                return;
     112            }
     113
     114            check_admin_referer( $this->get_nonce_action() );
     115
     116            $plugin_page    = sanitize_text_field( wp_unslash( $_GET['page'] ) );
     117            $current_action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) );
     118
     119            $has_plugin_page = ! $this->is_empty_string( $plugin_page );
     120            $has_action      = ! $this->is_empty_string( $current_action );
     121
     122            if ( $has_plugin_page && $has_action && $plugin_page === $this->get_current_page_slug() ) {
    83123                $this->process_actions( $current_action );
    84124            }
    85125        }
    86126
    87         // GET: /wp-json/<page-id>/<rest-api-version>/settings
     127        /**
     128         * Init rest api.
     129         *
     130         * @example GET /wp-json/<page-id>/<rest-api-version>/settings
     131         * @return void
     132         */
    88133        public function rest_api_init() {
    89134            ( new REST_API( $this ) )->register_routes();
    90135        }
    91136
    92         public function plugin_action_links( $links ): array {
     137        /**
     138         * Plugin page plugin action link.
     139         *
     140         * @param string[] $links Plugin action available links.
     141         *
     142         * @return string[]
     143         */
     144        public function plugin_action_links( array $links ): array {
    93145
    94146            $strings = $this->localize_strings();
    95147
    96             $action_links = array(
    97                 'settings' => sprintf( '<a href="%1$s" aria-label="%2$s">%2$s</a>', esc_url( $this->get_settings_uri() ), esc_html( $strings['settings_link_text'] ) ),
    98             );
    99 
    100             return array_merge( $action_links, $links );
    101         }
    102 
    103         /**
    104          * Admin Scripts
     148            $action_links = sprintf( '<a href="%1$s" aria-label="%2$s">%2$s</a>', esc_url( $this->get_settings_uri() ), esc_html( $strings['settings_link_text'] ) );
     149
     150            $links[] = $action_links;
     151
     152            return $links;
     153        }
     154
     155        /**
     156         * Register admin Scripts
    105157         *
    106158         * @return void
     
    112164                $plugin_dir_path = untrailingslashit( plugin_dir_path( $this->get_plugin_file() ) );
    113165
    114                 $script_src_url    = $plugin_dir_url . '/vendor/storepress/admin-utils/assets/admin-settings.js';
    115                 $style_src_url     = $plugin_dir_url . '/vendor/storepress/admin-utils/assets/admin-settings.css';
    116                 $script_asset_file = $plugin_dir_path . '/vendor/storepress/admin-utils/assets/admin-settings.asset.php';
     166                $script_src_url    = $plugin_dir_url . '/vendor/storepress/admin-utils/build/admin-settings.js';
     167                $style_src_url     = $plugin_dir_url . '/vendor/storepress/admin-utils/build/admin-settings.css';
     168                $script_asset_file = $plugin_dir_path . '/vendor/storepress/admin-utils/build/admin-settings.asset.php';
    117169                $script_assets     = include $script_asset_file;
    118170
     
    124176
    125177        /**
     178         * Enqueue Scripts.
     179         *
    126180         * @return void
    127181         */
     
    132186
    133187        /**
    134          * Translated Strings
     188         * Translated Strings.
    135189         *
    136190         * @abstract
     191         *
    137192         * @return array{
     193         *     'unsaved_warning_text': string,
     194         *     'reset_warning_text': string,
     195         *     'reset_button_text': string,
     196         *     'settings_nav_label_text': string,
     197         *     'settings_link_text': string,
     198         *     'settings_error_message_text': string,
     199         *     'settings_updated_message_text': string,
     200         *     'settings_deleted_message_text': string
     201         * }
     202         * @example array{
    138203         *     unsaved_warning_text: string,
    139204         *     reset_warning_text: string,
    140205         *     reset_button_text: string,
     206         *     settings_nav_label_text: string,
    141207         *     settings_link_text: string,
     208         *     settings_error_message_text: string,
    142209         *     settings_updated_message_text: string,
    143210         *     settings_deleted_message_text:string
     
    146213        public function localize_strings(): array {
    147214
    148             $message = esc_html__( 'not implemented. Must be overridden in subclass.' );
    149             $this->trigger_error( __METHOD__, $message );
     215            /* translators: %s: Method name. */
     216            $message = sprintf( esc_html__( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ );
     217            wp_trigger_error( __METHOD__, $message );
    150218
    151219            return array(
     
    153221                'reset_warning_text'            => 'Are you sure to reset?',
    154222                'reset_button_text'             => 'Reset All',
     223                'settings_nav_label_text'       => 'Secondary menu',
    155224                'settings_link_text'            => 'Settings',
     225                'settings_error_message_text'   => 'Settings not saved',
    156226                'settings_updated_message_text' => 'Settings Saved',
    157227                'settings_deleted_message_text' => 'Settings Reset',
     
    160230
    161231        /**
     232         * Get localize string by string key. Previously added on localize_strings()
     233         *
     234         * @param string $string_key Localized string key.
     235         * @see localize_strings()
     236         * @return string
     237         */
     238        public function get_localized_string( string $string_key ): string {
     239            $strings = $this->localize_strings();
     240
     241            return $strings[ $string_key ] ?? '';
     242        }
     243
     244        /**
     245         * Add Settings.
     246         *
    162247         * @abstract
    163          * @return array
     248         * @return array<string, mixed>
    164249         */
    165250        public function add_settings(): array {
    166251
    167             $message = esc_html__( 'not implemented. Must be overridden in subclass.' );
    168             $this->trigger_error( __METHOD__, $message );
    169 
     252            /* translators: %s: Method name. */
     253            $message = sprintf( esc_html__( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ );
     254            wp_trigger_error( __METHOD__, $message );
    170255            return array();
    171256        }
    172257
    173258        /**
    174          * @return array
     259         * Get settings.
     260         *
     261         * @return array<string, mixed>
    175262         */
    176263        final public function get_settings(): array {
     
    178265        }
    179266
    180         // used on ui template.
    181 
    182         /**
     267        /**
     268         * Display Sidebar. Used on UI template.
     269         *
    183270         * @return void
    184271         */
    185272        final public function display_sidebar() {
    186273            $tab_sidebar = $this->get_tab_sidebar();
    187 
     274            // Load sidebar based on callback.
    188275            if ( is_callable( $tab_sidebar ) ) {
    189276                call_user_func( $tab_sidebar );
    190277            } else {
    191                 // load default sidebar
     278                // Load default sidebar.
    192279                $this->get_default_sidebar();
    193280            }
     
    195282
    196283        /**
     284         * Get tab sidebar callback.
     285         *
    197286         * @return callable|null
    198287         */
     
    204293
    205294        /**
     295         * Get default sidebar.
     296         *
    206297         * @abstract
    207298         * @return void
     
    210301            $current_tab       = $this->get_current_tab();
    211302            $callback_function = sprintf( $this->sidebar_callback_fn_name_convention, $current_tab );
    212             $message           = sprintf( __( 'not implemented. Must be overridden in subclass. Create "%1$s" method for "%2$s" tab sidebar.' ), $callback_function, $current_tab );
    213             $this->trigger_error( __METHOD__, $message );
    214         }
    215 
    216         // used on ui template.
    217 
    218         /**
     303
     304            /* translators: %s: Method name. */
     305            $message  = sprintf( esc_html__( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ );
     306            $message .= sprintf( 'Create "%1$s" method for "%2$s" tab sidebar.', $callback_function, $current_tab );
     307            wp_trigger_error( __METHOD__, $message );
     308        }
     309
     310        /**
     311         * Display Fields. Used on UI template.
     312         *
    219313         * @return void
    220314         */
     
    246340                $page_fn_name   = sprintf( $this->page_callback_fn_name_convention, $current_tab );
    247341                $message        = sprintf( 'Should return fields array from "<strong>%s()</strong>". Or For custom page create "<strong>%s()</strong>"', $fields_fn_name, $page_fn_name );
    248                 $this->trigger_error( '', $message );
    249             }
    250         }
    251 
    252         /**
     342                wp_trigger_error( '', $message );
     343            }
     344        }
     345
     346        /**
     347         * Display action buttons.
     348         *
    253349         * @return void
    254350         */
    255351        public function display_buttons() {
    256             $submit_button = get_submit_button( null, 'primary large', 'submit', false, null );
    257             $reset_button  = $this->get_reset_button();
    258             printf( '<p class="submit">%s %s</p>', $submit_button, $reset_button );
    259         }
    260 
    261         /**
     352            $submit_button      = get_submit_button( '', 'primary large', 'submit', false, '' );
     353            $reset_button       = $this->get_reset_button();
     354            $allowed_input_html = $this->get_kses_allowed_input_html();
     355            printf( '<p class="submit">%s %s</p>', wp_kses( $submit_button, $allowed_input_html ), wp_kses_post( $reset_button ) );
     356        }
     357
     358        /**
     359         * Get settings reset button.
     360         *
    262361         * @return string
    263362         */
     
    273372
    274373        /**
     374         * Get tab field callable function.
     375         *
    275376         * @return callable|null
    276377         */
     
    282383
    283384        /**
     385         * Get tab page callable function.
     386         *
    284387         * @return callable|null
    285388         */
     
    290393        }
    291394
    292         // used on ui template.
    293 
    294         /**
     395        /**
     396         * Display page. Used on UI Template.
     397         *
    295398         * @return void
    296399         */
     
    304407
    305408        /**
    306          * @return array
     409         * Get tabs.
     410         *
     411         * @return array<int|string, mixed>
    307412         */
    308413        final public function get_tabs(): array {
     
    310415            $navs = array();
    311416
     417            $first_key = array_key_first( $tabs );
     418
    312419            foreach ( $tabs as $key => $tab ) {
    313                 if ( empty( $key ) ) {
     420                if ( is_string( $first_key ) && $this->is_empty_string( $first_key ) ) {
     421                    $key = $this->default_tab_name();
     422                }
     423
     424                if ( 0 === $first_key ) {
    314425                    $key = $this->default_tab_name();
    315426                }
     
    323434                    'css-classes' => array(),
    324435                    'sidebar'     => true,
    325                     // 'page_callback'    => null,
    326                     // 'fields_callback'  => null,
    327                     // 'sidebar_callback' => null,
     436                    /**
     437                     * More item.
     438                     *
     439                     * @example:
     440                     * 'page_callback'    => null,
     441                     * 'fields_callback'  => null,
     442                     * 'sidebar_callback' => null,
     443                     */
    328444                );
    329445
     
    343459                $navs[ $key ]['fields_callback']  = is_callable( $fields_callback ) ? $fields_callback : null;
    344460                $navs[ $key ]['sidebar_callback'] = is_callable( $sidebar_callback ) ? $sidebar_callback : null;
    345 
    346461            }
    347462
     
    349464        }
    350465
    351         /***
     466        /**
     467         * Get Fields
     468         *
    352469         * @return Field[]
    353470         */
    354471        public function get_all_fields(): array {
    355             $tabs       = $this->get_tabs();
     472            $tabs = $this->get_tabs();
     473
    356474            $all_fields = array();
    357475
     
    369487
    370488                        $all_fields[ $field['id'] ] = $_field;
    371                         // $all_fields[ $field[ 'id' ] ] = $field;
    372489                    }
    373490                }
     
    378495
    379496        /**
     497         * Check unique field ids.
     498         *
    380499         * @return void
    381500         */
     
    392511                    $fields = call_user_func( $fields_callback );
    393512                    /**
    394                      * @var array $field
     513                     * Fields.
     514                     *
     515                     * @var array<string, mixed> $field
    395516                     */
    396517                    foreach ( $fields as $field ) {
     
    404525                            $message        = sprintf( 'Duplicate field id "<strong>%s</strong>" found. Please use unique field id.', $field['id'] );
    405526
    406                             $this->trigger_error( $fields_fn_name, $message );
     527                            wp_trigger_error( $fields_fn_name, $message );
    407528
    408529                        } else {
     
    418539
    419540        /**
     541         * Display tabs. Used on UI template.
     542         *
    420543         * @return void
    421544         */
    422545        final public function display_tabs() {
    423             echo implode( '', $this->get_navs() );
    424         }
    425 
    426         /**
    427          * @return array
     546            echo wp_kses_post( implode( '', $this->get_navs() ) );
     547        }
     548
     549        /**
     550         * Get navigations.
     551         *
     552         * @return string[]
    428553         */
    429554        private function get_navs(): array {
     
    435560            $navs = array();
    436561            /**
    437              * @var array $tab
     562             * Available tabs.
     563             *
     564             * @var array<int|string, mixed> $tab
    438565             */
     566
     567
    439568            foreach ( $tabs as $tab_id => $tab ) {
    440569
    441                 if ( ! empty( $tab['hidden'] ) ) {
     570                if ( true === $tab['hidden'] ) {
    442571                    continue;
    443572                }
     
    450579                }
    451580
    452                 $tab_url    = empty( $tab['external'] ) ? $this->get_tab_uri( $tab_id ) : $tab['external'];
    453                 $tab_target = empty( $tab['external'] ) ? '_self' : '_blank';
    454                 $icon       = empty( $tab['icon'] ) ? '' : sprintf( '<span class="%s"></span>', $tab['icon'] );
     581                $tab_url    = false === $tab['external'] ? $this->get_tab_uri( $tab_id ) : $tab['external'];
     582                $tab_target = false === $tab['external'] ? '_self' : '_blank';
     583                $icon       = is_null( $tab['icon'] ) ? '' : sprintf( '<span class="%s"></span>', $tab['icon'] );
    455584                $attributes = $tab['attributes'];
    456585
     
    459588                    array_map(
    460589                        function ( $key ) use ( $attributes ) {
    461 
    462                             if ( in_array( $key, array( 'target', 'href', 'class' ), true ) ) {
    463                                         return '';
    464                             }
    465590
    466591                            if ( is_bool( $attributes[ $key ] ) ) {
     
    480605        }
    481606
    482         // used on ui template.
    483 
    484         /**
    485          * @return string
    486          */
    487         final public function get_action_uri(): string {
    488             return $this->get_settings_uri();
    489         }
    490 
    491         // used on ui template.
    492 
    493         /**
     607        /**
     608         * Get action uri. used on settings form.
     609         *
     610         * @param array<string, mixed> $extra Extra arguments.
     611         * @return string
     612         */
     613        final public function get_action_uri( array $extra = array() ): string {
     614            return $this->get_settings_uri( $extra );
     615        }
     616
     617        /**
     618         * Get reset uri. used on ui template.
     619         *
    494620         * @return string
    495621         */
    496622        final public function get_reset_uri(): string {
    497             // return wp_nonce_url( $this->get_settings_uri( array( $this->action_query_args() => 'reset' ) ), $this->get_nonce() );
    498             return wp_nonce_url( $this->get_settings_uri( array( 'action' => 'reset' ) ), $this->get_nonce() );
    499         }
    500 
    501         /**
    502          * @return string
    503          */
    504         final public function get_nonce(): string {
     623            return wp_nonce_url( $this->get_settings_uri( array( 'action' => 'reset' ) ), $this->get_nonce_action() );
     624        }
     625
     626        /**
     627         * Get nonce action.
     628         *
     629         * @return string
     630         */
     631        final public function get_nonce_action(): string {
    505632            $group = $this->get_option_group_name();
    506633
     
    509636
    510637        /**
     638         * Get option group name for ui template.
     639         *
    511640         * @return string
    512641         */
     
    519648
    520649        /**
     650         * Get plugin file.
     651         *
    521652         * @return string
    522653         */
     
    526657
    527658        /**
     659         * Get settings ID.
     660         *
    528661         * @return string
    529662         */
     
    532665        }
    533666
    534         // override for custom ui page
    535 
    536         /**
     667        /**
     668         * Settings template. Can override for custom ui page.
     669         *
     670         * @see https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions
    537671         * @return void
    538672         */
    539673        public function display_settings_page() {
    540             // Follow: https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions
    541             include __DIR__ . '/templates/classic-template.php';
    542         }
    543 
    544 
    545         public function process_actions( $current_action ) {
     674            include_once __DIR__ . '/templates/classic-template.php';
     675        }
     676
     677        /**
     678         * Process actions.
     679         *
     680         * @param string $current_action Current requested action.
     681         *
     682         * @return void
     683         */
     684        public function process_actions( string $current_action ) {
    546685
    547686            if ( 'update' === $current_action ) {
     
    555694
    556695        /**
     696         * Process update settings.
     697         *
     698         * @see wp_removable_query_args()
    557699         * @return void
    558700         */
    559701        public function process_action_update() {
    560702
    561             check_admin_referer( $this->get_nonce() );
    562 
    563             $_post = wp_unslash( $_POST[ $this->get_settings_id() ] );
     703            check_admin_referer( $this->get_nonce_action() );
     704
     705            if ( ! isset( $_POST[ $this->get_settings_id() ] ) ) {
     706                wp_safe_redirect(
     707                    $this->get_action_uri(
     708                        array(
     709                            'message' => 'error',
     710                        )
     711                    )
     712                );
     713                exit;
     714            }
     715
     716            $_post = map_deep( wp_unslash( $_POST[ $this->get_settings_id() ] ), 'sanitize_text_field' );
    564717
    565718            $data = $this->sanitize_fields( $_post );
     
    567720            $this->update_options( $data );
    568721
    569             wp_safe_redirect( add_query_arg( 'message', 'updated', $this->get_action_uri() ) );
     722            wp_safe_redirect(
     723                $this->get_action_uri(
     724                    array( 'message' => 'updated' )
     725                )
     726            );
    570727            exit;
    571728        }
    572729
    573730        /**
     731         * Process reset action.
     732         *
     733         * @see wp_removable_query_args()
    574734         * @return void
    575735         */
    576736        public function process_action_reset() {
    577737
    578             check_admin_referer( $this->get_nonce() );
     738            check_admin_referer( $this->get_nonce_action() );
    579739
    580740            $this->delete_options();
    581741
    582             wp_safe_redirect( add_query_arg( 'message', 'deleted', $this->get_action_uri() ) );
     742            wp_safe_redirect(
     743                $this->get_action_uri(
     744                    array( 'message' => 'deleted' )
     745                )
     746            );
    583747            exit;
    584748        }
    585749
    586750        /**
     751         * Settings messages
     752         *
     753         * @see process_action_update()
     754         * @see process_action_reset()
     755         * @see wp_removable_query_args()
    587756         * @return void
    588757         */
    589758        public function settings_messages() {
     759
     760            // We are just checking message request from uri redirect.
     761            if ( ! isset( $_GET['message'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
     762                return;
     763            }
     764
    590765            $strings = $this->localize_strings();
    591             $message = sanitize_text_field( wp_slash( $_GET['message'] ?? '' ) );
     766
     767            $message = sanitize_text_field( $_GET['message'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
     768
    592769            if ( 'updated' === $message ) {
    593                 $this->add_settings_message( esc_html( $strings['settings_updated_message_text'] ) );
     770                $this->add_settings_message( $strings['settings_updated_message_text'] );
    594771            }
    595772            if ( 'deleted' === $message ) {
    596                 $this->add_settings_message( esc_html( $strings['settings_deleted_message_text'] ) );
    597             }
    598         }
    599        
    600         /**
    601          * @param array $default . Default: empty array
    602          *
    603          * @return array|false|mixed|null
    604          */
    605         public function get_options( array $default = array() ) {
    606 
    607             if ( ! empty( $this->options ) ) {
     773                $this->add_settings_message( $strings['settings_deleted_message_text'] );
     774            }
     775            if ( 'error' === $message ) {
     776                $this->add_settings_message( $strings['settings_error_message_text'], 'error' );
     777            }
     778        }
     779
     780        /**
     781         * Get All Saved Options
     782         *
     783         * @param array<string, mixed> $default_value Default Value. Default: empty array.
     784         *
     785         * @return bool|array<string, mixed>|null
     786         */
     787        public function get_options( array $default_value = array() ) {
     788
     789            if ( ! $this->is_empty_array( $this->options ) ) {
    608790                return $this->options;
    609791            }
    610             $this->options = get_option( $this->get_settings_id(), $default );
     792            $this->options = get_option( $this->get_settings_id(), $default_value );
    611793
    612794            return $this->options;
     
    614796
    615797        /**
     798         * Delete Option
     799         *
    616800         * @return bool
    617801         */
     
    621805
    622806        /**
    623          * @param array $data
    624          *
    625          * @return void
    626          */
    627         final private function update_options( array $data ) {
     807         * Update Option
     808         *
     809         * @param array<string, mixed> $data Updated data.
     810         *
     811         * @return void
     812         */
     813        private function update_options( array $data ) {
    628814
    629815            $old_data = $this->get_options();
    630816
    631             if ( ! empty( $old_data ) ) {
     817            if ( ! $this->is_empty_array( $old_data ) ) {
    632818                $current_data = array_merge( $old_data, $data['public'] );
    633819            } else {
     
    643829
    644830        /**
    645          * @param string $field_id
    646          * @param mixed  $default . Default null
     831         * Get Option
     832         *
     833         * @param string $field_id Option field id.
     834         * @param mixed  $default_value Pass default value. Default is null.
    647835         *
    648836         * @return mixed|null
    649837         */
    650         public function get_option( string $field_id, $default = null ) {
     838        public function get_option( string $field_id, $default_value = null ) {
    651839            $field = $this->get_field( $field_id );
    652840
    653             return $field->get_value( $default );
    654         }
    655 
    656         /**
    657          * @param string $group_id
    658          * @param string $field_id
    659          * @param mixed  $default . Default: null
     841            return $field->get_value( $default_value );
     842        }
     843
     844        /**
     845         * Get Group Option
     846         *
     847         * @param string $group_id Group Id.
     848         * @param string $field_id Field Id.
     849         * @param mixed  $default_value Default: null.
    660850         *
    661851         * @return mixed|null
    662852         */
    663         public function get_group_option( string $group_id, string $field_id, $default = null ) {
     853        public function get_group_option( string $group_id, string $field_id, $default_value = null ) {
    664854            $field = $this->get_field( $group_id );
    665855
    666             return $field->get_group_value( $field_id, $default );
    667         }
    668 
    669         // Current tab fields
    670 
    671         /***
     856            return $field->get_group_value( $field_id, $default_value );
     857        }
     858
     859        /**
     860         * Get Available fields.
     861         *
    672862         * @return Field[]
    673863         */
     
    678868                $fields = call_user_func( $field_cb );
    679869                /**
    680                  * @var array $field
     870                 * Field
     871                 *
     872                 * @var array<string, mixed> $field
    681873                 */
    682874                foreach ( $fields as $field ) {
     
    691883        }
    692884
    693         // Current tab
    694 
    695         /**
    696          * @param string $field_id
     885        /**
     886         * Get available field.
     887         *
     888         * @param string $field_id Field id.
    697889         *
    698890         * @return Field|null
     891         * @phpstan-ignore method.unused
    699892         */
    700893        private function get_available_field( string $field_id ): ?Field {
     
    705898
    706899        /**
    707          * @param string $field_id
     900         * Get field.
     901         *
     902         * @param string $field_id Field id.
    708903         *
    709904         * @return Field|null
     
    716911
    717912        /**
    718          *
    719          * @param array $_post
    720          *
    721          * @return array{ public: array, private: array }
     913         * Sanitize fields.
     914         *
     915         * @param array<string, mixed> $_post global post.
     916         *
     917         * @return array{ public: array<string, mixed>, private: array<string, mixed> }
    722918         */
    723919        private function sanitize_fields( array $_post ): array {
     
    742938                switch ( $type ) {
    743939                    case 'checkbox':
    744                         // Add default checkbox value
     940                        // Add default checkbox value.
    745941                        if ( ! isset( $_post[ $key ] ) ) {
    746942                            $_post[ $key ] = ( count( $options ) > 0 ) ? array() : 'no';
     
    759955                            $group_sanitize_callback = $field->get_sanitize_callback();
    760956
    761                             // Add default checkbox value
     957                            // Add default checkbox value.
    762958                            if ( 'checkbox' === $group_field_type ) {
    763959                                if ( ! isset( $_post[ $key ][ $group_field_id ] ) ) {
     
    783979
    784980        /**
     981         * Settings page init.
     982         *
    785983         * @return void
    786984         */
     
    791989
    792990        /**
    793          * used on ui template.
     991         * Display settings message. Used on ui template.
    794992         *
    795993         * @return void
     
    800998
    801999        /**
    802          * @param string $message  Message
     1000         * Add settings message.
     1001         *
     1002         * @param string $message  Message.
    8031003         * @param string $type     Message type. Optional. Message type, controls HTML class. Possible values include 'error',
    8041004         *                         'success', 'warning', 'info', 'updated'. Default: 'updated'.
     
    8131013
    8141014        /**
     1015         * Parent menu slug.
     1016         *
    8151017         * @return string Parent Menu Slug
    8161018         */
     
    8191021        }
    8201022
     1023        /**
     1024         * Get settings capability.
     1025         *
     1026         * @return string
     1027         */
    8211028        public function capability(): string {
    8221029            return 'manage_options';
    8231030        }
    8241031
    825         public function menu_position(): string {
    826             return '45';
    827         }
    828 
     1032        /**
     1033         * Menu position.
     1034         *
     1035         * @return int
     1036         */
     1037        public function menu_position(): int {
     1038            return 45;
     1039        }
     1040
     1041        /**
     1042         * Menu Icon.
     1043         *
     1044         * @return string
     1045         */
    8291046        public function menu_icon(): string {
    8301047            return 'dashicons-admin-settings';
    8311048        }
    8321049
     1050        /**
     1051         * Default tab name.
     1052         *
     1053         * @return string
     1054         */
    8331055        public function default_tab_name(): string {
    8341056            return 'general';
    8351057        }
    8361058
     1059        /**
     1060         * Get current tab.
     1061         *
     1062         * @return string
     1063         */
    8371064        final public function get_current_tab(): string {
    8381065            $default_tab_query_key = $this->default_tab_name();
     
    8401067            $available_tab_keys = array_keys( $this->get_tabs() );
    8411068
    842             $tab_query_key = in_array( $default_tab_query_key, $available_tab_keys, true ) ? $default_tab_query_key : $available_tab_keys[0];
    843 
    844             return empty( $_GET['tab'] ) ? $tab_query_key : sanitize_title( wp_unslash( $_GET['tab'] ) ); // WPCS: input var okay, CSRF ok.
    845         }
    846 
    847         final public function get_tab( $tab_id = '' ) {
     1069            $tab_query_key = in_array( $default_tab_query_key, $available_tab_keys, true ) ? $default_tab_query_key : (string) $available_tab_keys[0];
     1070
     1071            return ! isset( $_GET['tab'] ) ? sanitize_title( $tab_query_key ) : sanitize_title( wp_unslash( $_GET['tab'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
     1072        }
     1073
     1074        /**
     1075         * Get tab.
     1076         *
     1077         * @param string $tab_id tab id.
     1078         *
     1079         * @return array<string, mixed>
     1080         */
     1081        final public function get_tab( string $tab_id = '' ): array {
    8481082            $tabs = $this->get_tabs();
    8491083
    850             $_tab_id = empty( $tab_id ) ? $this->get_current_tab() : $tab_id;
    851 
    852             return $tabs[ $_tab_id ] ?? array('page_callback'=>function(){
    853                  echo '<div class="notice error"><p>Settings Tab is not available.</p></div>';
    854             });
    855         }
    856 
     1084            $_tab_id = $this->is_empty_string( $tab_id ) ? $this->get_current_tab() : $tab_id;
     1085
     1086            return $tabs[ $_tab_id ] ?? array(
     1087                'page_callback' => function () {
     1088                    echo '<div class="notice error"><p>Settings Tab is not available.</p></div>';
     1089                },
     1090            );
     1091        }
     1092
     1093        /**
     1094         * Have save button.
     1095         *
     1096         * @return bool
     1097         */
    8571098        final public function has_save_button(): bool {
    8581099            $data = $this->get_tab();
    8591100
    860             return ! empty( $data['buttons'] );
    861         }
    862 
     1101            return true === $data['buttons'];
     1102        }
     1103
     1104        /**
     1105         * Has sidebar.
     1106         *
     1107         * @return bool
     1108         */
    8631109        final public function has_sidebar(): bool {
    8641110            $data = $this->get_tab();
    8651111
    866             return ! empty( $data['sidebar'] );
    867         }
    868 
    869         /**
    870          * @param $tab_id
    871          *
    872          * @return string
    873          */
    874         public function get_tab_uri( $tab_id ): string {
     1112            return true === $data['sidebar'];
     1113        }
     1114
     1115        /**
     1116         * Get Tab URI.
     1117         *
     1118         * @param string $tab_id Tab id.
     1119         *
     1120         * @return string
     1121         */
     1122        public function get_tab_uri( string $tab_id ): string {
    8751123            return $this->get_settings_uri( array( 'tab' => $tab_id ) );
    8761124        }
    8771125
    8781126        /**
    879          * @param array $extra
     1127         * Get Settings uri.
     1128         *
     1129         * @param array<string, mixed> $extra Extra arguments for uri.
    8801130         *
    8811131         * @return string
     
    8901140
    8911141        /**
    892          * @param array $extra
    893          *
    894          * @return array
     1142         * Get Settings URI Arguments.
     1143         *
     1144         * @param array<string, mixed> $extra Extra arguments.
     1145         *
     1146         * @return array<string, mixed>
    8951147         */
    8961148        public function get_uri_args( array $extra = array() ): array {
     
    9021154            );
    9031155
    904             if ( ! empty( $current_tab ) ) {
     1156            if ( ! $this->is_empty_string( $current_tab ) ) {
    9051157                $args['tab'] = $current_tab;
    9061158            }
     
    9101162
    9111163        /**
     1164         * Check is admin page.
     1165         *
    9121166         * @return bool
    9131167         */
    9141168        public function is_admin_page(): bool {
    915             return ( is_admin() && isset( $_GET['page'] ) && $this->get_current_page_slug() === $_GET['page'] );
     1169            // We have to check is valid current page.
     1170            return ( is_admin() && isset( $_GET['page'] ) && $this->get_current_page_slug() === $_GET['page'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
    9161171        }
    9171172    }
  • woo-2checkout/trunk/vendor/storepress/admin-utils/includes/Updater.php

    r3044506 r3140508  
    11<?php
    22    /**
    3      * Plugin Updater API
     3     * Plugin Updater API Class File.
    44     *
    55     * @package    StorePress/AdminUtils
    6      * @version    1.0
     6     * @since      1.0.0
     7     * @version    1.0.0
    78     */
    89
     10    declare(strict_types=1);
     11
    912    namespace StorePress\AdminUtils;
    1013
     
    1417
    1518    /**
    16      * Plugin Updater API
     19     * Plugin Updater API Class.
    1720     *
    1821     * @name Updater
     
    2023    abstract class Updater {
    2124
     25        use Common;
     26
    2227        /**
    2328         * Plugin Data.
    2429         *
    25          * @var array
     30         * @var array<string, mixed>
    2631         */
    2732        private array $plugin_data = array();
     
    5459            $plugin_data = $this->get_plugin_data();
    5560
    56             if ( empty( $plugin_data['UpdateURI'] ) ) {
     61            if ( ! isset( $plugin_data['UpdateURI'] ) ) {
    5762                $msg = 'Plugin "Update URI" is not available. Please add "Update URI" field on plugin file header.';
    58                 $this->trigger_error( __METHOD__, $msg );
     63                wp_trigger_error( __METHOD__, $msg );
    5964
    6065                return;
    6166            }
    6267
    63             if ( empty( $plugin_data['Tested up to'] ) ) {
     68            if ( ! isset( $plugin_data['Tested up to'] ) ) {
    6469                $msg = 'Plugin "Tested up to" is not available. Please add "Tested up to" field on plugin file header.';
    65                 $this->trigger_error( __METHOD__, $msg );
     70                wp_trigger_error( __METHOD__, $msg );
    6671
    6772                return;
     
    7681
    7782            // Check plugin update information from server.
    78             add_filter( "update_plugins_{$plugin_hostname}", array( $this, 'update_check' ), 10, 4 );
     83            add_filter( "update_plugins_{$plugin_hostname}", array( $this, 'update_check' ), 10, 3 );
    7984
    8085            // Add some info at the end of plugin update notice like: notice to update license data.
    81             add_action( "in_plugin_update_message-{$plugin_id}", array( $this, 'update_message' ), 10, 2 );
     86            add_action( "in_plugin_update_message-{$plugin_id}", array( $this, 'update_message' ) );
    8287
    8388            // Add force update check link.
     
    8893        }
    8994
     95        /**
     96         * Absolute Plugin File.
     97         *
     98         * @return string
     99         */
    90100        abstract public function plugin_file(): string;
    91101
     102        /**
     103         * License Key.
     104         *
     105         * @return string
     106         */
    92107        abstract public function license_key(): string;
    93108
     109        /**
     110         * License key empty message text.
     111         *
     112         * @return string
     113         */
    94114        abstract public function license_key_empty_message(): string;
    95115
     116        /**
     117         * Check update link text.
     118         *
     119         * @return string
     120         */
    96121        abstract public function check_update_link_text(): string;
    97122
     123        /**
     124         * Product ID for update server.
     125         *
     126         * @return string
     127         */
    98128        abstract public function product_id(): string;
    99129
    100         final private function get_plugin_data(): array {
    101 
    102             if ( ! empty( $this->plugin_data ) ) {
     130        /**
     131         * Get Provided Plugin Data.
     132         *
     133         * @return array<string, mixed>
     134         */
     135        public function get_plugin_data(): array {
     136
     137            if ( array_key_exists( 'Name', $this->plugin_data ) ) {
    103138                return $this->plugin_data;
    104139            }
     
    109144        }
    110145
     146        /**
     147         * Get Plugin absolute file
     148         *
     149         * @return string
     150         */
    111151        public function get_plugin_file(): string {
    112152            return $this->plugin_file();
     
    133173        }
    134174
     175        /**
     176         * Get license key.
     177         *
     178         * @return string
     179         */
    135180        public function get_license_key(): string {
    136181            return $this->license_key();
    137182        }
    138183
     184        /**
     185         * Get Product ID.
     186         *
     187         * @return string
     188         */
    139189        public function get_product_id(): string {
    140190            return $this->product_id();
    141191        }
    142192
     193        /**
     194         * Add additional request for Updater Rest API.
     195         *
     196         * @return array<string, string>
     197         */
    143198        public function additional_request_args(): array {
    144199            return array();
     
    154209            $update_server_hostname = untrailingslashit( $data['UpdateURI'] );
    155210
    156             return wp_parse_url( sanitize_url( $update_server_hostname ), PHP_URL_HOST );
    157         }
    158 
     211            return (string) wp_parse_url( sanitize_url( $update_server_hostname ), PHP_URL_HOST );
     212        }
     213
     214        /**
     215         * Get Update server uri.
     216         *
     217         * @return string
     218         */
    159219        final public function get_update_server_uri(): string {
    160220
     
    208268        }
    209269
     270        /**
     271         * Check plugin update forcefully.
     272         *
     273         * @return void
     274         */
    210275        final public function force_update_check() {
    211276            if ( current_user_can( 'update_plugins' ) ) {
     
    219284
    220285                wp_safe_redirect( admin_url( 'plugins.php' ) );
    221             }
    222         }
    223 
     286                exit;
     287            }
     288        }
     289
     290        /**
     291         * Get check update action id.
     292         *
     293         * @return string
     294         */
    224295        private function get_action_id(): string {
    225296            return sprintf( '%s_check_update', $this->get_plugin_dirname() );
    226297        }
    227298
    228         public function check_for_update_link( $links, $file ): array {
    229 
    230             if ( $file === $this->get_plugin_slug() && current_user_can( 'update_plugins' ) ) {
    231 
    232                 $id   = $this->get_action_id();
    233                 $url  = wp_nonce_url( add_query_arg( array( 'action' => $id ), admin_url( 'plugins.php' ) ), $this->get_plugin_slug() );
    234                 $text = $this->check_update_link_text();
    235 
    236                 $row_meta[ $id ] = sprintf( '<a href="%1$s" aria-label="%2$s">%2$s</a>', esc_url( $url ), esc_html( $text ) );
    237 
    238                 return array_merge( $links, $row_meta );
    239             }
    240 
    241             return $links;
    242         }
    243 
    244         public function add_tested_upto_info( $headers ): array {
     299        /**
     300         * Check for update link.
     301         *
     302         * @param string[] $plugin_meta  An array of the plugin's metadata, including
     303         *                               the version, author, author URI, and plugin URI.
     304         * @param string   $plugin_file  Path to the plugin file relative to the plugins directory.
     305         *
     306         * @return array<string, string>
     307         */
     308        public function check_for_update_link( array $plugin_meta, string $plugin_file ): array {
     309
     310            if ( $plugin_file === $this->get_plugin_slug() && current_user_can( 'update_plugins' ) ) {
     311
     312                $id       = $this->get_action_id();
     313                $url      = wp_nonce_url( add_query_arg( array( 'action' => $id ), admin_url( 'plugins.php' ) ), $this->get_plugin_slug() );
     314                $text     = $this->check_update_link_text();
     315                $row_meta = sprintf( '<a href="%1$s" aria-label="%2$s">%2$s</a>', esc_url( $url ), esc_html( $text ) );
     316
     317                $plugin_meta[] = $row_meta;
     318            }
     319
     320            return $plugin_meta;
     321        }
     322
     323        /**
     324         * Add tested upto support on plugin header.
     325         *
     326         * @param string[] $headers Available plugin header info.
     327         *
     328         * @return string[]
     329         */
     330        public function add_tested_upto_info( array $headers ): array {
    245331            return array_merge( $headers, array( 'Tested up to' ) );
    246332        }
    247333
     334        /**
     335         * Get Plugin Banners.
     336         *
     337         * @return array<string, string>
     338         * @example [ 'high' => '', 'low' => '' ]
     339         */
    248340        public function get_plugin_info_banners(): array {
    249341
     
    259351         * Add Plugin banners.
    260352         *
    261          * @return array [
    262          * '2x' => '',
    263          * '1x' => ''
    264          * ]
     353         * @return array<string, string>
     354         * @example [ '2x' => '', '1x' => '' ]
    265355         */
    266356        abstract public function plugin_banners(): array;
     
    269359         * Get Plugin Banners.
    270360         *
    271          * @return array [
    272          *  '2x' => '',
    273          *  '1x' => ''
    274          *  ]
     361         * @return array<string, string>
     362         * @example [ '2x' => '', '1x' => '' ]
    275363         */
    276364        public function get_plugin_banners(): array {
     
    281369         * Add Plugin Icons.
    282370         *
    283          * @return array [
    284          * '2x'  => '',
    285          * '1x'  => '',
    286          * 'svg' => ''
    287          * ] Plugin Icons array.
     371         * @return array<string, string>
     372         * @example [ '2x'  => '', '1x'  => '', 'svg' => '' ]
    288373         */
    289374        abstract public function plugin_icons(): array;
     
    292377         * Get Plugin Icons.
    293378         *
    294          * @return array [
    295          * '2x'  => '',
    296          * '1x'  => '',
    297          * 'svg' => '',
    298          * ]
     379         * @return array<string, string>
     380         * @example [ '2x'  => '', '1x'  => '', 'svg' => '' ]
    299381         */
    300382        public function get_plugin_icons(): array {
     
    321403
    322404        /**
    323          * @return array
     405         * Get request argument for request.
     406         *
     407         * @return array<string, mixed>
    324408         */
    325409        protected function get_request_args(): array {
    326410            return array(
    327                 'timeout' => 10,
    328411                'body'    => array(
    329412                    'type'        => 'plugins',
     
    342425         * Remote plugin data.
    343426         *
    344          * @return false|string[]
     427         * @return bool|array<string, string>
    345428         */
    346429        public function get_remote_plugin_data() {
    347430            $params = $this->get_request_args();
    348431
    349             $raw_response = wp_remote_get( $this->get_update_server_uri(), $params );
     432            $raw_response = wp_safe_remote_get( $this->get_update_server_uri(), $params );
    350433
    351434            if ( is_wp_error( $raw_response ) || 200 !== wp_remote_retrieve_response_code( $raw_response ) ) {
     
    357440
    358441        /**
    359          * @param          $update
    360          * @param array    $plugin_data
    361          * @param string   $plugin_file
    362          * @param string[] $locales
    363          *
    364          * @return array|mixed
     442         * Update check.
     443         *
     444         * @param bool|array<string, mixed> $update The plugin update data with the latest details.
     445         * @param array<string, mixed>      $plugin_data Plugin headers.
     446         * @param string                    $plugin_file Plugin filename.
     447         *
     448         * @return bool|array<string, mixed>
    365449         * @see     WP_Site_Health::detect_plugin_theme_auto_update_issues()
    366450         * @see     wp_update_plugins()
    367451         */
    368         final public function update_check( $update, array $plugin_data, string $plugin_file, $locales ) {
     452        final public function update_check( $update, array $plugin_data, string $plugin_file ) {
    369453
    370454            if ( $plugin_file !== $this->get_plugin_slug() ) {
     
    372456            }
    373457
    374             if ( ! empty( $update ) ) {
     458            if ( is_array( $update ) ) {
    375459                return $update;
    376460            }
     
    379463            $plugin_data = $this->get_plugin_data();
    380464
    381             if ( empty( $remote_data ) ) {
     465            if ( false === $remote_data ) {
    382466                return $update;
    383467            }
     
    388472            $requires_php   = $plugin_data['RequiresPHP'];
    389473
    390             /**
    391              * @var string $plugin_id plugin unique id. Example: w.org/plugins/xyz-plugin.
    392              */
    393             $plugin_id = url_shorten( $plugin_uri, 150 );
     474            $plugin_id = url_shorten( (string) $plugin_uri, 150 );
    394475
    395476            $item = array(
    396                 'id'            => $plugin_id, // w.org/plugins/xyz-plugin
    397                 'slug'          => $this->get_plugin_dirname(), // xyz-plugin
    398                 'plugin'        => $this->get_plugin_slug(), // xyz-plugin/xyz-plugin.php
     477                'id'            => $plugin_id, // @example: w.org/plugins/xyz-plugin
     478                'slug'          => $this->get_plugin_dirname(), // @example: xyz-plugin
     479                'plugin'        => $this->get_plugin_slug(), // @example: xyz-plugin/xyz-plugin.php
    399480                'version'       => $plugin_version,
    400481                'url'           => $plugin_uri,
     
    413494
    414495        /**
    415          * @param array|false $remote_data
    416          *
    417          * @return array [
     496         * Prepare Remote data to use.
     497         *
     498         * @param bool|array<string, mixed> $remote_data Remote data.
     499         *
     500         * @return array<string, mixed>
     501         * @example
     502         * array [
    418503         *
    419504         *     'description'=>'',
     
    448533            $item = array();
    449534
    450             if ( empty( $remote_data ) ) {
     535            if ( ( is_bool( $remote_data ) && false === $remote_data ) || ( is_array( $remote_data ) && $this->is_empty_array( $remote_data ) ) ) {
    451536                return $item;
    452537            }
    453538
    454539            if ( isset( $remote_data['description'] ) ) {
    455                 $item['sections']['description'] = wp_kses_post( $remote_data['description'] );
     540                $item['sections']['description'] = $remote_data['description'];
    456541            }
    457542
    458543            if ( isset( $remote_data['changelog'] ) ) {
    459                 $item['sections']['changelog'] = wp_kses_post( $remote_data['changelog'] );
     544                $item['sections']['changelog'] = $remote_data['changelog'];
    460545            }
    461546
     
    500585
    501586        /**
    502          * @param $default
    503          * @param $action
    504          * @param $args
    505          *
    506          * @return array|mixed
     587         * Plugin Information.
     588         *
     589         * @param false|object|array<string, mixed> $result The result object or array. Default false.
     590         * @param string                            $action The type of information being requested from the Plugin Installation API.
     591         * @param object                            $args   Plugin API arguments.
     592         *
     593         * @return false|array<string, mixed>|object
    507594         * @see     plugins_api()
    508595         * @example https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&slug=hello-dolly
    509596         */
    510         final public function plugin_information( $default, $action, $args ) {
     597        final public function plugin_information( $result, string $action, object $args ) {
    511598
    512599            if ( ! ( 'plugin_information' === $action ) ) {
    513                 return $default;
     600                return $result;
    514601            }
    515602
     
    523610                $version            = $plugin_data['Version'];
    524611
    525                 $get_description = $this->get_plugin_description_section();
    526                 $get_changelog   = $this->get_plugin_changelog_section();
    527                 $description     = empty( $get_description ) ? wpautop( $plugin_description ) : $get_description;
     612                $get_description = trim( $this->get_plugin_description_section() );
     613                $get_changelog   = trim( $this->get_plugin_changelog_section() );
     614                $description     = '' === $get_description ? $plugin_description : $get_description;
    528615
    529616                $item = array(
     
    533620                    'banners'  => $this->get_plugin_info_banners(),
    534621                    'author'   => $author,
    535                     'homepage' => esc_url( $plugin_homepage ),
     622                    'homepage' => $plugin_homepage,
    536623                    'sections' => array(
    537                         'description' => wp_kses_post( $description ),
     624                        'description' => $description,
    538625                    ),
    539626                );
    540627
    541                 if ( ! empty( $get_changelog ) ) {
     628                if ( strlen( $get_changelog ) > 0 ) {
    542629                    $item['sections']['changelog'] = $get_changelog;
    543630                }
     
    552639            }
    553640
    554             return $default;
    555         }
    556 
    557         public function update_message( $plugin_data, $response ) {
    558 
    559             $license_key    = trim( $this->get_license_key() );
    560             $upgrade_notice = $plugin_data['upgrade_notice'] ?? false;
    561 
    562             if ( empty( $license_key ) ) {
     641            return $result;
     642        }
     643
     644        /**
     645         * Plugin Update Message.
     646         *
     647         * @param array<string, string> $plugin_data An array of plugin metadata.
     648         *
     649         * @return void
     650         */
     651        public function update_message( array $plugin_data ) {
     652
     653            $license_key    = $this->get_license_key();
     654            $upgrade_notice = $plugin_data['upgrade_notice'] ?? '';
     655
     656            if ( $this->is_empty_string( $license_key ) ) {
    563657                printf( ' <strong>%s</strong>', esc_html( $this->license_key_empty_message() ) );
    564658            }
    565659
    566             if ( $upgrade_notice ) {
     660            if ( ! $this->is_empty_string( $upgrade_notice ) ) {
    567661                printf( ' <br /><br /><strong><em>%s</em></strong>', esc_html( $upgrade_notice ) );
    568             }
    569         }
    570 
    571         /**
    572          * @param string $function_name
    573          * @param string $message
    574          *
    575          * @return void
    576          */
    577         final public function trigger_error( string $function_name, string $message ) {
    578 
    579             // Bail out if WP_DEBUG is not turned on.
    580             if ( ! WP_DEBUG ) {
    581                 return;
    582             }
    583 
    584             if ( function_exists( 'wp_trigger_error' ) ) {
    585                 wp_trigger_error( $function_name, $message );
    586             } else {
    587 
    588                 if ( ! empty( $function_name ) ) {
    589                     $message = sprintf( '%s(): %s', $function_name, $message );
    590                 }
    591 
    592                 $message = wp_kses(
    593                     $message,
    594                     array(
    595                         'a' => array( 'href' ),
    596                         'br',
    597                         'code',
    598                         'em',
    599                         'strong',
    600                     ),
    601                     array( 'http', 'https' )
    602                 );
    603 
    604                 trigger_error( $message );
    605662            }
    606663        }
  • woo-2checkout/trunk/vendor/storepress/admin-utils/includes/Upgrade_Notice.php

    r3072401 r3140508  
    11<?php
    22    /**
    3      * Upgrade Notice
     3     * Plugin Upgrade Notice Class File.
    44     *
    55     * @package    StorePress/AdminUtils
    6      * @version    1.0
     6     * @since      1.0.0
     7     * @version    1.0.0
    78     */
     9
     10    declare(strict_types=1);
    811
    912    namespace StorePress\AdminUtils;
     
    1316if ( ! class_exists( '\StorePress\AdminUtils\Upgrade_Notice' ) ) {
    1417    /**
    15      * Upgrade Notice
     18     * Plugin Upgrade Notice Class.
    1619     */
    1720    abstract class Upgrade_Notice {
     
    2023         * Plugin Data.
    2124         *
    22          * @var array
     25         * @var array<string, string|bool>
    2326         */
    2427        private array $data = array();
     
    3235
    3336        /**
    34          * Upgrade notice.
     37         * Class construct.
    3538         */
    3639        protected function __construct() {
     
    4144
    4245        /**
    43          * Get absolute file path
     46         * Get absolute file path.
    4447         *
    4548         * @param string $plugin_file relative or absolute path.
     
    214217         */
    215218        private function is_compatible(): bool {
    216             $current_version  = sanitize_text_field( $this->data['Version'] );
     219            $current_version  = sanitize_text_field( (string) $this->data['Version'] );
    217220            $required_version = $this->compatible_version();
    218221
     
    227230        public function get_notice_content(): string {
    228231
    229             $name               = sanitize_text_field( $this->data['Name'] );
    230             $version            = sanitize_text_field( $this->data['Version'] );
     232            $name               = sanitize_text_field( (string) $this->data['Name'] );
     233            $version            = sanitize_text_field( (string) $this->data['Version'] );
    231234            $compatible_version = $this->compatible_version();
    232235
     
    237240         * Notice string format.
    238241         *
     242         * @abstract
    239243         * @return string
    240244         */
    241245        public function localize_notice_format(): string {
    242246
    243             $message = esc_html__( 'not implemented. Must be overridden in subclass.' );
    244             $this->trigger_error( __METHOD__, $message );
     247            /* translators: %s: Method name. */
     248            $message = sprintf( esc_html__( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ );
     249            wp_trigger_error( __METHOD__, $message );
    245250
    246251            // translators: 1: Extended Plugin Name. 2: Extended Plugin Version. 3: Extended Plugin Compatible Version.
    247252            return 'You are using an incompatible version of <strong>%1$s - (%2$s)</strong>. Please upgrade to version <strong>%3$s</strong> or upper.';
    248253        }
    249 
    250         /**
    251          * Trigger user error.
    252          *
    253          * @param string $function_name Function name.
    254          * @param string $message       Message.
    255          *
    256          * @return void
    257          */
    258         final public function trigger_error( string $function_name, string $message ) {
    259 
    260             // Bail out if WP_DEBUG is not turned on.
    261             if ( ! WP_DEBUG ) {
    262                 return;
    263             }
    264 
    265             if ( function_exists( 'wp_trigger_error' ) ) {
    266                 wp_trigger_error( $function_name, $message );
    267             } else {
    268 
    269                 if ( ! empty( $function_name ) ) {
    270                     $message = sprintf( '%s(): %s', $function_name, $message );
    271                 }
    272 
    273                 $message = wp_kses(
    274                     $message,
    275                     array(
    276                         'a' => array( 'href' ),
    277                         'br',
    278                         'code',
    279                         'em',
    280                         'strong',
    281                     ),
    282                     array( 'http', 'https' )
    283                 );
    284 
    285                 trigger_error( $message ); // phpcs:ignore.
    286             }
    287         }
    288254    }
    289255}
  • woo-2checkout/trunk/vendor/storepress/admin-utils/includes/templates/classic-template.php

    r3044506 r3140508  
    11<?php
    2 
    32    /**
    4      * StorePress Settings Template.
     3     * Admin Settings Template File.
    54     *
    6      * @global \StorePress\AdminUtils\Settings $this - Settings Class Instance.
     5     * @package StorePress/AdminUtils
     6     * @var \StorePress\AdminUtils\Settings $this - Settings Class Instance.
     7     * @since 1.0.0
     8     * @version 1.0.0
    79     */
    810
    911    defined( 'ABSPATH' ) || die( 'Keep Silent' );
    10 
    1112?>
    1213<div class="wrap storepress-settings-wrapper">
    1314    <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
    14    
     15
    1516    <?php
    1617        $this->display_settings_messages();
    1718    ?>
    1819
    19     <nav class="nav-tab-wrapper storepress-nav-tab-wrapper" aria-label="Secondary menu">
     20    <nav class="nav-tab-wrapper storepress-nav-tab-wrapper" aria-label="<?php echo esc_attr( $this->get_localized_string( 'settings_nav_label_text' ) ); ?>">
    2021        <?php $this->display_tabs(); ?>
    2122    </nav>
     
    3132            <?php endif; ?>
    3233        </div>
    33        
     34
    3435        <?php if ( $this->has_sidebar() ) : ?>
    3536            <div class="storepress-settings-sidebar">
  • woo-2checkout/trunk/woo-2checkout.php

    r3081706 r3140508  
    1010 * Description:          2Checkout Payment Gateway for WooCommerce.
    1111 * Author:               Emran Ahmed
    12  * Version:              3.0.2
     12 * Version:              3.0.3
    1313 * Requires PHP:         7.4
    1414 * Requires at least:    6.1
    15  * Tested up to:         6.5
     15 * Tested up to:         6.6
    1616 * WC requires at least: 8.1
    17  * WC tested up to:      8.8
     17 * WC tested up to:      9.2
    1818 * Text Domain:          woo-2checkout
    1919 * Author URI:           https://getwooplugins.com/
Note: See TracChangeset for help on using the changeset viewer.