From 28decba87958247ef3120cd4316c2e927c2bcd34 Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Mon, 19 Aug 2024 03:55:04 +0000 Subject: [PATCH 1/7] feat: register_meta --- .gitignore | 4 +- composer.json | 3 + composer.lock | 1639 ++++++++++++++++++++++++- inc/field-registry.php | 45 + inc/field.php | 117 ++ inc/fields/background.php | 14 + inc/fields/button.php | 4 + inc/fields/checkbox.php | 11 + inc/fields/choice.php | 18 + inc/fields/custom-html.php | 7 + inc/fields/divider.php | 9 + inc/fields/fieldset-text.php | 18 + inc/fields/file.php | 10 + inc/fields/heading.php | 7 + inc/fields/input.php | 11 + inc/fields/media.php | 14 + inc/fields/multiple-values.php | 16 + inc/fields/number.php | 11 + inc/fields/range.php | 11 + inc/fields/slider.php | 11 + inc/fields/switch.php | 11 + inc/fields/taxonomy-advanced.php | 4 + inc/meta-box.php | 5 +- phpunit.xml | 8 + tests/bootstrap.php | 50 + tests/phpunit/FieldReturnTypeTest.php | 131 ++ tests/phpunit/RegisterMetaTest.php | 92 ++ 27 files changed, 2276 insertions(+), 5 deletions(-) create mode 100644 phpunit.xml create mode 100644 tests/bootstrap.php create mode 100644 tests/phpunit/FieldReturnTypeTest.php create mode 100644 tests/phpunit/RegisterMetaTest.php diff --git a/.gitignore b/.gitignore index b338dcdd..ce35fa1e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ package-lock.json yarn.lock .DS_Store .idea -vendor \ No newline at end of file +vendor +.phpunit.result.cache +.phpunit.cache \ No newline at end of file diff --git a/composer.json b/composer.json index 5a1c8dd3..815a7520 100644 --- a/composer.json +++ b/composer.json @@ -26,5 +26,8 @@ "psr-4": { "MetaBox\\": "src/" } + }, + "require-dev": { + "phpunit/phpunit": "^11.3" } } diff --git a/composer.lock b/composer.lock index 345027e3..b3381ee7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,1642 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2ecfb313af70de53ae33703de60ea8aa", + "content-hash": "da83f796ba5551dd96e4d49699bbe54c", "packages": [], - "packages-dev": [], + "packages-dev": [ + { + "name": "myclabs/deep-copy", + "version": "1.12.0", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "conflict": { + "doctrine/collections": "<1.6.8", + "doctrine/common": "<2.13.3 || >=3 <3.2.2" + }, + "require-dev": { + "doctrine/collections": "^1.6.8", + "doctrine/common": "^2.13.3 || ^3.2.2", + "phpspec/prophecy": "^1.10", + "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" + }, + "type": "library", + "autoload": { + "files": [ + "src/DeepCopy/deep_copy.php" + ], + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2024-06-12T14:39:25+00:00" + }, + { + "name": "nikic/php-parser", + "version": "v5.1.0", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/683130c2ff8c2739f4822ff7ac5c873ec529abd1", + "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-json": "*", + "ext-tokenizer": "*", + "php": ">=7.4" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v5.1.0" + }, + "time": "2024-07-01T20:03:41+00:00" + }, + { + "name": "phar-io/manifest", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "54750ef60c58e43759730615a392c31c80e23176" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176", + "reference": "54750ef60c58e43759730615a392c31c80e23176", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-phar": "*", + "ext-xmlwriter": "*", + "phar-io/version": "^3.0.1", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/2.0.4" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:33:53+00:00" + }, + { + "name": "phar-io/version", + "version": "3.2.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/3.2.1" + }, + "time": "2022-02-21T01:04:05+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "11.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "19b6365ab8b59a64438c0c3f4241feeb480c9861" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/19b6365ab8b59a64438c0c3f4241feeb480c9861", + "reference": "19b6365ab8b59a64438c0c3f4241feeb480c9861", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-xmlwriter": "*", + "nikic/php-parser": "^5.0", + "php": ">=8.2", + "phpunit/php-file-iterator": "^5.0", + "phpunit/php-text-template": "^4.0", + "sebastian/code-unit-reverse-lookup": "^4.0", + "sebastian/complexity": "^4.0", + "sebastian/environment": "^7.0", + "sebastian/lines-of-code": "^3.0", + "sebastian/version": "^5.0", + "theseer/tokenizer": "^1.2.0" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "suggest": { + "ext-pcov": "PHP extension that provides line coverage", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "11.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.5" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:05:37+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "5.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "6ed896bf50bbbfe4d504a33ed5886278c78e4a26" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6ed896bf50bbbfe4d504a33ed5886278c78e4a26", + "reference": "6ed896bf50bbbfe4d504a33ed5886278c78e4a26", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/5.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:06:37+00:00" + }, + { + "name": "phpunit/php-invoker", + "version": "5.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-invoker.git", + "reference": "c1ca3814734c07492b3d4c5f794f4b0995333da2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/c1ca3814734c07492b3d4c5f794f4b0995333da2", + "reference": "c1ca3814734c07492b3d4c5f794f4b0995333da2", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "ext-pcntl": "*", + "phpunit/phpunit": "^11.0" + }, + "suggest": { + "ext-pcntl": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Invoke callables with a timeout", + "homepage": "https://github.com/sebastianbergmann/php-invoker/", + "keywords": [ + "process" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-invoker/issues", + "security": "https://github.com/sebastianbergmann/php-invoker/security/policy", + "source": "https://github.com/sebastianbergmann/php-invoker/tree/5.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:07:44+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "3e0404dc6b300e6bf56415467ebcb3fe4f33e964" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/3e0404dc6b300e6bf56415467ebcb3fe4f33e964", + "reference": "3e0404dc6b300e6bf56415467ebcb3fe4f33e964", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "security": "https://github.com/sebastianbergmann/php-text-template/security/policy", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/4.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:08:43+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "7.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "3b415def83fbcb41f991d9ebf16ae4ad8b7837b3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3b415def83fbcb41f991d9ebf16ae4ad8b7837b3", + "reference": "3b415def83fbcb41f991d9ebf16ae4ad8b7837b3", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "7.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "security": "https://github.com/sebastianbergmann/php-timer/security/policy", + "source": "https://github.com/sebastianbergmann/php-timer/tree/7.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:09:35+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "11.3.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "fe179875ef0c14e90b75617002767eae0a742641" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fe179875ef0c14e90b75617002767eae0a742641", + "reference": "fe179875ef0c14e90b75617002767eae0a742641", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.12.0", + "phar-io/manifest": "^2.0.4", + "phar-io/version": "^3.2.1", + "php": ">=8.2", + "phpunit/php-code-coverage": "^11.0.5", + "phpunit/php-file-iterator": "^5.0.1", + "phpunit/php-invoker": "^5.0.1", + "phpunit/php-text-template": "^4.0.1", + "phpunit/php-timer": "^7.0.1", + "sebastian/cli-parser": "^3.0.2", + "sebastian/code-unit": "^3.0.1", + "sebastian/comparator": "^6.0.2", + "sebastian/diff": "^6.0.2", + "sebastian/environment": "^7.2.0", + "sebastian/exporter": "^6.1.3", + "sebastian/global-state": "^7.0.2", + "sebastian/object-enumerator": "^6.0.1", + "sebastian/type": "^5.0.1", + "sebastian/version": "^5.0.1" + }, + "suggest": { + "ext-soap": "To be able to generate mocks based on WSDL files" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "11.3-dev" + } + }, + "autoload": { + "files": [ + "src/Framework/Assert/Functions.php" + ], + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "security": "https://github.com/sebastianbergmann/phpunit/security/policy", + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.3.1" + }, + "funding": [ + { + "url": "https://phpunit.de/sponsors.html", + "type": "custom" + }, + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit", + "type": "tidelift" + } + ], + "time": "2024-08-13T06:14:23+00:00" + }, + { + "name": "sebastian/cli-parser", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/cli-parser.git", + "reference": "15c5dd40dc4f38794d383bb95465193f5e0ae180" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/15c5dd40dc4f38794d383bb95465193f5e0ae180", + "reference": "15c5dd40dc4f38794d383bb95465193f5e0ae180", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for parsing CLI options", + "homepage": "https://github.com/sebastianbergmann/cli-parser", + "support": { + "issues": "https://github.com/sebastianbergmann/cli-parser/issues", + "security": "https://github.com/sebastianbergmann/cli-parser/security/policy", + "source": "https://github.com/sebastianbergmann/cli-parser/tree/3.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:41:36+00:00" + }, + { + "name": "sebastian/code-unit", + "version": "3.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit.git", + "reference": "6bb7d09d6623567178cf54126afa9c2310114268" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/6bb7d09d6623567178cf54126afa9c2310114268", + "reference": "6bb7d09d6623567178cf54126afa9c2310114268", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the PHP code units", + "homepage": "https://github.com/sebastianbergmann/code-unit", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit/issues", + "security": "https://github.com/sebastianbergmann/code-unit/security/policy", + "source": "https://github.com/sebastianbergmann/code-unit/tree/3.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:44:28+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "183a9b2632194febd219bb9246eee421dad8d45e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/183a9b2632194febd219bb9246eee421dad8d45e", + "reference": "183a9b2632194febd219bb9246eee421dad8d45e", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "security": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/security/policy", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/4.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:45:54+00:00" + }, + { + "name": "sebastian/comparator", + "version": "6.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "450d8f237bd611c45b5acf0733ce43e6bb280f81" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/450d8f237bd611c45b5acf0733ce43e6bb280f81", + "reference": "450d8f237bd611c45b5acf0733ce43e6bb280f81", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-mbstring": "*", + "php": ">=8.2", + "sebastian/diff": "^6.0", + "sebastian/exporter": "^6.0" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "security": "https://github.com/sebastianbergmann/comparator/security/policy", + "source": "https://github.com/sebastianbergmann/comparator/tree/6.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-08-12T06:07:25+00:00" + }, + { + "name": "sebastian/complexity", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/complexity.git", + "reference": "ee41d384ab1906c68852636b6de493846e13e5a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/ee41d384ab1906c68852636b6de493846e13e5a0", + "reference": "ee41d384ab1906c68852636b6de493846e13e5a0", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^5.0", + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for calculating the complexity of PHP code units", + "homepage": "https://github.com/sebastianbergmann/complexity", + "support": { + "issues": "https://github.com/sebastianbergmann/complexity/issues", + "security": "https://github.com/sebastianbergmann/complexity/security/policy", + "source": "https://github.com/sebastianbergmann/complexity/tree/4.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:49:50+00:00" + }, + { + "name": "sebastian/diff", + "version": "6.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "b4ccd857127db5d41a5b676f24b51371d76d8544" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/b4ccd857127db5d41a5b676f24b51371d76d8544", + "reference": "b4ccd857127db5d41a5b676f24b51371d76d8544", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0", + "symfony/process": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "security": "https://github.com/sebastianbergmann/diff/security/policy", + "source": "https://github.com/sebastianbergmann/diff/tree/6.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:53:05+00:00" + }, + { + "name": "sebastian/environment", + "version": "7.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "855f3ae0ab316bbafe1ba4e16e9f3c078d24a0c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/855f3ae0ab316bbafe1ba4e16e9f3c078d24a0c5", + "reference": "855f3ae0ab316bbafe1ba4e16e9f3c078d24a0c5", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "suggest": { + "ext-posix": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "7.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "https://github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "security": "https://github.com/sebastianbergmann/environment/security/policy", + "source": "https://github.com/sebastianbergmann/environment/tree/7.2.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:54:44+00:00" + }, + { + "name": "sebastian/exporter", + "version": "6.1.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "c414673eee9a8f9d51bbf8d61fc9e3ef1e85b20e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/c414673eee9a8f9d51bbf8d61fc9e3ef1e85b20e", + "reference": "c414673eee9a8f9d51bbf8d61fc9e3ef1e85b20e", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": ">=8.2", + "sebastian/recursion-context": "^6.0" + }, + "require-dev": { + "phpunit/phpunit": "^11.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "https://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "security": "https://github.com/sebastianbergmann/exporter/security/policy", + "source": "https://github.com/sebastianbergmann/exporter/tree/6.1.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:56:19+00:00" + }, + { + "name": "sebastian/global-state", + "version": "7.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "3be331570a721f9a4b5917f4209773de17f747d7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/3be331570a721f9a4b5917f4209773de17f747d7", + "reference": "3be331570a721f9a4b5917f4209773de17f747d7", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "sebastian/object-reflector": "^4.0", + "sebastian/recursion-context": "^6.0" + }, + "require-dev": { + "ext-dom": "*", + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "7.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "https://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "security": "https://github.com/sebastianbergmann/global-state/security/policy", + "source": "https://github.com/sebastianbergmann/global-state/tree/7.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:57:36+00:00" + }, + { + "name": "sebastian/lines-of-code", + "version": "3.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/lines-of-code.git", + "reference": "d36ad0d782e5756913e42ad87cb2890f4ffe467a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/d36ad0d782e5756913e42ad87cb2890f4ffe467a", + "reference": "d36ad0d782e5756913e42ad87cb2890f4ffe467a", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^5.0", + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for counting the lines of code in PHP source code", + "homepage": "https://github.com/sebastianbergmann/lines-of-code", + "support": { + "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", + "security": "https://github.com/sebastianbergmann/lines-of-code/security/policy", + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/3.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T04:58:38+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "6.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "f5b498e631a74204185071eb41f33f38d64608aa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/f5b498e631a74204185071eb41f33f38d64608aa", + "reference": "f5b498e631a74204185071eb41f33f38d64608aa", + "shasum": "" + }, + "require": { + "php": ">=8.2", + "sebastian/object-reflector": "^4.0", + "sebastian/recursion-context": "^6.0" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "security": "https://github.com/sebastianbergmann/object-enumerator/security/policy", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/6.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:00:13+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "6e1a43b411b2ad34146dee7524cb13a068bb35f9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/6e1a43b411b2ad34146dee7524cb13a068bb35f9", + "reference": "6e1a43b411b2ad34146dee7524cb13a068bb35f9", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "security": "https://github.com/sebastianbergmann/object-reflector/security/policy", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/4.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:01:32+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "6.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "694d156164372abbd149a4b85ccda2e4670c0e16" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/694d156164372abbd149a4b85ccda2e4670c0e16", + "reference": "694d156164372abbd149a4b85ccda2e4670c0e16", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "https://github.com/sebastianbergmann/recursion-context", + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "security": "https://github.com/sebastianbergmann/recursion-context/security/policy", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/6.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:10:34+00:00" + }, + { + "name": "sebastian/type", + "version": "5.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/type.git", + "reference": "fb6a6566f9589e86661291d13eba708cce5eb4aa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/fb6a6566f9589e86661291d13eba708cce5eb4aa", + "reference": "fb6a6566f9589e86661291d13eba708cce5eb4aa", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the types of the PHP type system", + "homepage": "https://github.com/sebastianbergmann/type", + "support": { + "issues": "https://github.com/sebastianbergmann/type/issues", + "security": "https://github.com/sebastianbergmann/type/security/policy", + "source": "https://github.com/sebastianbergmann/type/tree/5.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:11:49+00:00" + }, + { + "name": "sebastian/version", + "version": "5.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "45c9debb7d039ce9b97de2f749c2cf5832a06ac4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/45c9debb7d039ce9b97de2f749c2cf5832a06ac4", + "reference": "45c9debb7d039ce9b97de2f749c2cf5832a06ac4", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "security": "https://github.com/sebastianbergmann/version/security/policy", + "source": "https://github.com/sebastianbergmann/version/tree/5.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2024-07-03T05:13:08+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.2.3", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "reference": "737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/1.2.3" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2024-03-03T12:36:25+00:00" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], @@ -14,5 +1647,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/inc/field-registry.php b/inc/field-registry.php index f7030e59..04aaf38c 100644 --- a/inc/field-registry.php +++ b/inc/field-registry.php @@ -7,6 +7,8 @@ class RWMB_Field_Registry { private $data = []; + private $meta_box; + /** * Add a single field to the registry. * @@ -27,9 +29,52 @@ public function add( array $field, string $type, string $object_type = 'post' ) } $this->data[ $object_type ][ $type ][ $field['id'] ] = $field; + // $this->register_meta( $field, $type, $object_type ); + do_action( 'rwmb_field_registered', $field, $type, $object_type ); } + public function set_meta_box( array $meta_box ) { + $this->meta_box = $meta_box; + } + + public function get_meta_box() { + return $this->meta_box; + } + + public function register_meta( $field, $type, $object_type ) { + // Bail early if the field is implicitly not registered as meta. + if ( ! $field['register_meta'] ) { + return; + } + + // Bail if the meta box storage is custom table. + if ( ! isset( $field['storage'] ) || ! $field['storage'] instanceof RWMB_Post_Storage ) { + return; + } + + $type_default = $this->get_return_type_and_default( $field ); + + $args = [ + 'object_subtype' => $object_type, + 'type' => $type_default['type'], + 'description' => $field['desc'] ?? '', + 'single' => ! $field['multiple'], + 'default' => $type_default['default'], + 'show_in_rest' => true, + 'revision_enabled' => ( isset( $this->meta_box['revision'] ) && $this->meta_box['revision'] && $object_type === 'post' ) || false, + ]; + + $field_register_meta = is_array( $field['register_meta'] ) ? $field['register_meta'] : []; + + // Merge the args with the field's args. + $args = array_merge( $args, $field_register_meta ); + + register_meta( $object_type, $field['id'], $args ); + } + + + /** * Retrieve a field. * diff --git a/inc/field.php b/inc/field.php index 19052516..c3a31404 100644 --- a/inc/field.php +++ b/inc/field.php @@ -317,6 +317,7 @@ public static function normalize( $field ) { 'attributes' => [], 'sanitize_callback' => null, + 'register_meta' => true, ] ); // Store the original ID to run correct filters for the clonable field. @@ -575,4 +576,120 @@ public static function filter() { return $value; } + + public static function register_meta( $field, $meta_box, $post_type ) { + // Bail early if the field is implicitly not registered as meta. + if ( ! $field['register_meta'] ) { + return; + } + + // Bail if the meta box storage is custom table. + if ( ! isset( $field['storage'] ) || ! $field['storage'] instanceof RWMB_Post_Storage ) { + return; + } + + $revisions_enabled = $meta_box['revision'] ?? false; + + $args = [ + 'type' => 'string', + 'description' => $field['desc'] ?? '', + 'single' => ! $field['multiple'], + 'default' => '', + 'show_in_rest' => true, + 'revisions_enabled' => $revisions_enabled, + ]; + + $args = array_merge( $args, self::get_register_meta_args( $field ) ); + + register_meta( $post_type, $field['id'], $args ); + } + + /** + * Define the schema for the field. + * + * @return array + */ + public static function get_register_meta_args( $field ) { + // If the schema is explicitly defined, use it. + if ( is_array( $field['register_meta'] ) ) { + return $field['register_meta']; + } + + $schema = self::call( 'get_schema', $field ); + + // HTML, Heading, Divider, etc. don't have a schema. + if ( ! $schema ) { + return []; + } + + $return_type = $schema['type'] ?? 'string'; + + if ( $field['clone'] ) { + $return_type = 'array'; + + $schema = [ + 'type' => 'array', + 'items' => $schema, + ]; + } + + $args['type'] = $return_type; + $args['default'] = self::get_validated_default_value( $field, $return_type ); + + if ( in_array ( $return_type, [ 'array', 'object' ] ) ) { + $args['show_in_rest'] = [ + 'schema' => $schema + ]; + } + + return $args; + } + + private static function get_validated_default_value( $field, $return_type ) { + $default = $field['std'] ?? ''; + + if ( 'array' === $return_type && ! is_array( $default ) ) { + return []; + } + + if ( 'boolean' === $return_type && ! is_bool( $default ) ) { + $default = false; + } + + if ( 'integer' === $return_type && ! is_int( $default ) ) { + $default = 0; + } + + if ( 'number' === $return_type && ! is_float( $default ) ) { + $default = 0; + } + + if ( 'object' === $return_type && ! is_array( $default ) ) { + $default = []; + } + + return $default; + } + + protected static function get_full_schema( $field ) { + $field = self::call( 'normalize', $field ); + $schema = self::call( 'get_schema', $field ); + + if ( ! $schema ) { + return false; + } + + if ( $field['clone'] === true ) { + $schema = [ + 'type' => 'array', + 'items' => $schema, + ]; + } + + return $schema; + } + + protected static function get_schema( $field ) { + return [ 'type' => 'string' ]; + } } diff --git a/inc/fields/background.php b/inc/fields/background.php index 4b622cc1..080fe189 100644 --- a/inc/fields/background.php +++ b/inc/fields/background.php @@ -155,4 +155,18 @@ public static function format_single_value( $field, $value, $args, $post_id ) { } return $output; } + + public static function get_schema( $field ) { + return [ + 'type' => 'object', + 'properties' => [ + 'color' => [ 'type' => 'string' ], + 'image' => [ 'type' => 'string' ], + 'repeat' => [ 'type' => 'string' ], + 'attachment' => [ 'type' => 'string' ], + 'position' => [ 'type' => 'string' ], + 'size' => [ 'type' => 'string' ], + ], + ]; + } } diff --git a/inc/fields/button.php b/inc/fields/button.php index 63d35854..47106eec 100644 --- a/inc/fields/button.php +++ b/inc/fields/button.php @@ -47,4 +47,8 @@ public static function get_attributes( $field, $value = null ) { return $attributes; } + + protected static function get_schema( $field ) { + return false; + } } diff --git a/inc/fields/checkbox.php b/inc/fields/checkbox.php index 0997aa75..29a10af4 100644 --- a/inc/fields/checkbox.php +++ b/inc/fields/checkbox.php @@ -42,4 +42,15 @@ protected static function input_description( array $field ) : string { public static function format_single_value( $field, $value, $args, $post_id ) { return $value ? __( 'Yes', 'meta-box' ) : __( 'No', 'meta-box' ); } + + /** + * Get the type of a single item. + * + * @param array $field Field parameters. + * + * @return array + */ + protected static function get_schema( $field ) { + return [ 'type' => 'integer' ]; + } } diff --git a/inc/fields/choice.php b/inc/fields/choice.php index affb313e..594531f8 100644 --- a/inc/fields/choice.php +++ b/inc/fields/choice.php @@ -66,4 +66,22 @@ public static function format_single_value( $field, $value, $args, $post_id ) { $options = self::transform_options( $field['options'] ); return isset( $options[ $value ] ) ? $options[ $value ]->label : ''; } + + /** + * Get the type of a single item. + * + * @param array $field Field parameters. + * + * @return array + */ + protected static function get_schema( $field ) { + if ( $field['multiple'] ) { + return [ + 'type' => 'array', + 'items' => [ 'type' => 'string' ], + ]; + } + + return [ 'type' => 'string' ]; + } } diff --git a/inc/fields/custom-html.php b/inc/fields/custom-html.php index ad39844a..fd49782a 100644 --- a/inc/fields/custom-html.php +++ b/inc/fields/custom-html.php @@ -20,4 +20,11 @@ public static function html( $meta, $field ) { } return $html; } + + /** + * Get the type of a single item. + */ + protected static function get_schema( $field ) { + return false; + } } diff --git a/inc/fields/divider.php b/inc/fields/divider.php index e382099d..b3763e0a 100644 --- a/inc/fields/divider.php +++ b/inc/fields/divider.php @@ -18,4 +18,13 @@ protected static function begin_html( array $field ) : string { public static function end_html( array $field ) : string { return ''; } + + /** + * Divider field does not have a schema. + * @param array $field + * @return bool + */ + protected static function get_schema( $field ) { + return false; + } } diff --git a/inc/fields/fieldset-text.php b/inc/fields/fieldset-text.php index 69ab12a0..11c0c4b4 100644 --- a/inc/fields/fieldset-text.php +++ b/inc/fields/fieldset-text.php @@ -102,4 +102,22 @@ public static function format_single_value( $field, $value, $args, $post_id ) { $output .= ''; return $output; } + + /** + * Get the type of a single item. + * + * @param array $field Field parameters. + */ + protected static function get_schema( $field ) { + $properties = []; + + foreach ( $field['options'] as $key => $label ) { + $properties[ $key ] = [ 'type' => 'string' ]; + } + + return [ + 'type' => 'object', + 'properties' => $properties + ]; + } } diff --git a/inc/fields/file.php b/inc/fields/file.php index daa3628b..f44c89ab 100644 --- a/inc/fields/file.php +++ b/inc/fields/file.php @@ -492,4 +492,14 @@ public static function convert_path_to_url( string $path ) : string { return home_url( $relative_path ); } + + /** + * This field saves multiple file IDs in db. + */ + protected static function get_schema( $field ) { + return [ + 'type' => 'array', + 'items' => [ 'type' => 'integer' ] + ]; + } } diff --git a/inc/fields/heading.php b/inc/fields/heading.php index ea7eb3a6..c0fa085c 100644 --- a/inc/fields/heading.php +++ b/inc/fields/heading.php @@ -18,4 +18,11 @@ protected static function begin_html( array $field ) : string { protected static function end_html( array $field ) : string { return self::input_description( $field ); } + + /** + * Get the type of a single item. + */ + protected static function get_schema( $field ) { + return false; + } } diff --git a/inc/fields/input.php b/inc/fields/input.php index eb3925d5..6c2da207 100644 --- a/inc/fields/input.php +++ b/inc/fields/input.php @@ -109,4 +109,15 @@ protected static function datalist( array $field ) : string { $html .= ''; return $html; } + + /** + * Get the type of a single item. + * + * @param array $field Field parameters. + * + * @return array + */ + protected static function get_schema( $field ) { + return [ 'type' => 'string' ]; + } } diff --git a/inc/fields/media.php b/inc/fields/media.php index 9f354204..456eb6be 100644 --- a/inc/fields/media.php +++ b/inc/fields/media.php @@ -212,4 +212,18 @@ public static function save( $new, $old, $post_id, $field ) { public static function print_templates() { require RWMB_INC_DIR . 'templates/media.php'; } + + /** + * This field saves multiple file IDs in db. + */ + protected static function get_schema( $field ) { + if ( $field['multiple'] ) { + return [ + 'type' => 'array', + 'items' => [ 'type' => 'integer' ] + ]; + } + + return [ 'type' => 'integer' ]; + } } diff --git a/inc/fields/multiple-values.php b/inc/fields/multiple-values.php index 4307ea7a..788aea87 100644 --- a/inc/fields/multiple-values.php +++ b/inc/fields/multiple-values.php @@ -42,4 +42,20 @@ public static function normalize( $field ) { public static function format_single_value( $field, $value, $args, $post_id ) { return $field['options'][ $value ]; } + + /** + * Get the type of a single item. + * + * @param array $field Field parameters. + * + * @return array + */ + protected static function get_schema( $field ) { + return [ + 'type' => 'array', + 'items' => [ + 'type' => 'string', + ], + ]; + } } diff --git a/inc/fields/number.php b/inc/fields/number.php index 7d8004af..218a9b05 100644 --- a/inc/fields/number.php +++ b/inc/fields/number.php @@ -40,4 +40,15 @@ public static function get_attributes( $field, $value = null ) { ] ); return $attributes; } + + /** + * Get the type of a single item. + * + * @param array $field Field parameters. + * + * @return array + */ + protected static function get_schema( $field ) { + return [ 'type' => 'number' ]; + } } diff --git a/inc/fields/range.php b/inc/fields/range.php index ecf526c5..77ab6c32 100644 --- a/inc/fields/range.php +++ b/inc/fields/range.php @@ -66,4 +66,15 @@ public static function value( $new, $old, $post_id, $field ) { } return $new; } + + /** + * Get the type of a single item. + * + * @param array $field Field parameters. + * + * @return array + */ + protected static function get_schema( $field ) { + return [ 'type' => 'number' ]; + } } diff --git a/inc/fields/slider.php b/inc/fields/slider.php index 42c4eacf..ddc2fef7 100644 --- a/inc/fields/slider.php +++ b/inc/fields/slider.php @@ -69,4 +69,15 @@ public static function normalize( $field ) { return $field; } + + /** + * Get the type of a single item. + * + * @param array $field Field parameters. + * + * @return array + */ + protected static function get_schema( $field ) { + return [ 'type' => 'number' ]; + } } diff --git a/inc/fields/switch.php b/inc/fields/switch.php index 80c06307..c5ba8895 100644 --- a/inc/fields/switch.php +++ b/inc/fields/switch.php @@ -85,4 +85,15 @@ public static function format_single_value( $field, $value, $args, $post_id ) { $off = $field['off_label'] ?: __( 'Off', 'meta-box' ); return $value ? $on : $off; } + + /** + * Get the type of a single item. + * + * @param array $field Field parameters. + * + * @return array + */ + protected static function get_schema( $field ) { + return [ 'type' => 'integer' ]; + } } diff --git a/inc/fields/taxonomy-advanced.php b/inc/fields/taxonomy-advanced.php index 8f6bb6d0..69952974 100644 --- a/inc/fields/taxonomy-advanced.php +++ b/inc/fields/taxonomy-advanced.php @@ -102,4 +102,8 @@ public static function terms_info( $field, $term_ids, $args ) { $info = is_array( $info ) ? $info : []; return $field['multiple'] ? $info : reset( $info ); } + + protected static function get_schema( $field ) { + return [ 'type' => 'string' ]; + } } diff --git a/inc/meta-box.php b/inc/meta-box.php index bb241143..884de470 100644 --- a/inc/meta-box.php +++ b/inc/meta-box.php @@ -62,10 +62,13 @@ public function __construct( array $meta_box ) { public function register_fields() { $field_registry = rwmb_get_registry( 'field' ); - + $field_registry->set_meta_box( $this->meta_box ); + foreach ( $this->post_types as $post_type ) { foreach ( $this->fields as $field ) { $field_registry->add( $field, $post_type ); + + RWMB_Field::call( 'register_meta', $field, $this->meta_box, $post_type ); } } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 00000000..a4a16bf8 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,8 @@ + + + + + ./tests/phpunit + + + diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 00000000..68331dc9 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,50 @@ + 'test-register-meta', + 'title' => 'Test Register Meta', + 'revision' => true, + 'fields' => [ + // RegisterMetaTest::testFieldRegisteredByDefault() + [ + 'name' => 'rmt_simple_text', + 'desc' => 'Basic text field', + 'id' => 'rmt_simple_text', + 'type' => 'text', + 'std' => 'Simple Text Default', + ], + // RegisterMetaTest::testNotRegisteredFieldShouldNotBeRegistered() + [ + 'name' => 'rmt_text_no_register_meta', + 'desc' => 'Text No Register Meta Description', + 'id' => 'rmt_text_no_register_meta', + 'type' => 'text', + 'register_meta' => false + ], + // RegisterMetaTest::testOverrideArgs() + [ + 'id' => 'rmt_text_override', + 'type' => 'text', + 'name' => 'rmt_text_override', + 'register_meta' => [ + 'description' => 'This is an overridden description', + 'revisions_enabled' => false, // Should override value from meta box + 'single' => true, + 'show_in_rest' => false, + 'default' => 'This is a default value', + 'type' => 'string', + ], + ], + ], +]; + +$mb = new RW_Meta_Box($meta_boxes); +$mb->register_fields(); \ No newline at end of file diff --git a/tests/phpunit/FieldReturnTypeTest.php b/tests/phpunit/FieldReturnTypeTest.php new file mode 100644 index 00000000..1bf78721 --- /dev/null +++ b/tests/phpunit/FieldReturnTypeTest.php @@ -0,0 +1,131 @@ + 'array', + 'background' => 'object', // All fields that return key-value pairs should return an object + 'button' => false, + 'button_group' => 'string', + 'checkbox_list' => 'array', + 'checkbox' => 'integer', + 'color' => 'string', + 'custom_html' => false, + 'date' => 'string', + 'datetime' => 'string', + 'divider' => false, + 'file_advanced' => 'array', + 'file_input' => 'string', + 'file_upload' => 'array', + 'file' => 'array', + 'icon' => 'string', + 'image_advanced' => 'array', + 'image_select' => 'string', + 'image_upload' => 'array', + 'image' => 'array', + 'key_value' => 'string', + 'map' => 'string', + 'oembed' => 'string', + 'osm' => 'string', + 'post' => 'string', + 'radio' => 'string', + 'range' => 'number', + 'select_advanced' => 'string', + 'select' => 'string', + 'sidebar' => 'string', + 'single_image' => 'integer', + 'switch' => 'integer', + 'taxonomy_advanced' => 'string', + 'taxonomy' => 'string', + 'text_list' => 'array', + 'textarea' => 'string', + 'user' => 'string', + 'video' => 'array', + 'wysiwyg' => 'string', + ]; + + private function setupField( $field_id, $props = [] ) { + $field = [ + 'id' => $field_id, + 'type' => $field_id, + ...$props, + ]; + + $field = RWMB_Field::call( 'normalize', $field ); + + return $field; + } + + public function testfieldShouldMatchReturnType() { + foreach ( $this->field_return_types as $field_id => $expected_return_type ) { + $field = $this->setupField( $field_id ); + $schema = RWMB_Field::call( 'get_schema', $field ); + $type = $schema['type'] ?? false; + + $this->assertEquals( $expected_return_type, $type, "Field $field_id should return $expected_return_type" ); + } + } + + public function testCloneFieldShouldReturnArray() { + foreach ( $this->field_return_types as $field_id => $single_return_type ) { + $field = $this->setupField( $field_id, [ 'clone' => true ] ); + + $schema = RWMB_Field::call( 'get_full_schema', $field ); + + if ( ! $schema || ! isset( $schema['type'] ) ) { + continue; + } + + // Some fields don't have a clone property + if ( ! $field['clone'] ) { + continue; + } + + $type = $schema['type']; + + $this->assertEquals( 'array', $type, "Field $field_id should return array" ); + $this->assertEquals( $single_return_type, $schema['items']['type'], "Item in field $field_id should return $single_return_type" ); + } + } + + public function testGroupFieldShouldReturnObject() { + $field = $this->setupField( 'group', [ 'fields' => [ + $this->setupField( 'text' ), + $this->setupField( 'textarea' ), + ] ] ); + + $schema = RWMB_Field::call( 'get_full_schema', $field ); + + $this->assertEquals( 'object', $schema['type'], 'Group field should return object' ); + } + + public function testCloneableGroupShouldReturnArrayObject() { + $field = $this->setupField( 'group', [ 'fields' => [ + $this->setupField( 'text' ), + $this->setupField( 'textarea' ), + ], 'clone' => true ] ); + + $schema = RWMB_Field::call( 'get_full_schema', $field ); + + $this->assertEquals( 'array', $schema['type'], 'Cloneable group field should return array' ); + $this->assertEquals( 'object', $schema['items']['type'], 'Cloneable group field should return object' ); + } + + public function testFieldsetTextShouldReturnObject() { + $field = $this->setupField( 'fieldset_text', [ 'options' => [ 'name' => 'Name', 'email' => 'Email' ] ] ); + $schema = RWMB_Field::call( 'get_full_schema', $field ); + + $this->assertEquals( 'object', $schema['type'], 'Fieldset text field should return object' ); + $this->assertArrayHasKey('properties', $schema, 'Fieldset text field should have properties' ); + $this->assertArrayHasKey('name', $schema['properties'], 'Fieldset text field should have name property' ); + $this->assertArrayHasKey('email', $schema['properties'], 'Fieldset text field should have email property' ); + $this->assertEquals('string', $schema['properties']['name']['type'], 'Fieldset text field name property should return string' ); + $this->assertEquals('string', $schema['properties']['email']['type'], 'Fieldset text field email property should return string' ); + } +} \ No newline at end of file diff --git a/tests/phpunit/RegisterMetaTest.php b/tests/phpunit/RegisterMetaTest.php new file mode 100644 index 00000000..a91520f8 --- /dev/null +++ b/tests/phpunit/RegisterMetaTest.php @@ -0,0 +1,92 @@ +meta = get_registered_meta_keys( 'post' ); + } + + public function testFieldRegisteredByDefault() { + $this->assertArrayHasKey( 'rmt_simple_text', $this->meta ); + } + + public function testNotRegisteredFieldShouldNotBeRegistered() { + $this->assertArrayNotHasKey( 'rmt_text_no_register_meta', $this->meta ); + } + + /** + * If we set 'register_meta' to array, it should be merged with the default args + */ + public function testOverrideArgs() { + $this->assertArrayIsEqualToArrayIgnoringListOfKeys( $this->meta['rmt_text_override'], [ + 'description' => 'This is an overridden description', + 'revisions_enabled' => false, + 'single' => true, + 'show_in_rest' => false, + 'default' => 'This is a default value', + 'type' => 'string', + ], [ + 'sanitize_callback', + 'auth_callback', + ] ); + } + + /** + * 1. Revision should be set to inherit from the meta box (false) by default + * 2. If field['register_meta']['revisions_enabled'] is set, it should be used + */ + public function testRevisionArgument() { + // This inherits from the meta box + $this->assertEquals( true, $this->meta['rmt_simple_text']['revisions_enabled'] ); + + // This is set to false + $this->assertEquals( false, $this->meta['rmt_text_override']['revisions_enabled'] ); + } + + /** + * 1. $args['single'] should be inversion of $field['multiple'] + * 2. If $field['register_meta']['multiple'] is set, it should be used + */ + public function testSingleArgument() { + $this->assertEquals( true, $this->meta['rmt_simple_text']['single'] ); + } + + /** + * 1. By default, show_in_rest should be set to true + * 2. If $field['register_meta']['show_in_rest'] is set, it should be used + */ + public function testShowInRestArgument() { + $this->assertEquals( true, $this->meta['rmt_simple_text']['show_in_rest'] ); + + $this->assertEquals( false, $this->meta['rmt_text_override']['show_in_rest'] ); + } + + /** + * !IMPORTANT: Need more discussion about this + * + * It's ideal and possible to use rwmb_the_value() to get the value of the field for the schema so it matches the prepared value, + * match with MB Rest API. + * + * HOWEVER, we should not use rwmb_the_value() to get the value of the field because WP uses get_post_meta() to get the value + * and it doesn't have any filter to alter with rwmb_the_value() + * + * Although, we can use get_{$meta_type}_metadata filter to alter the value, it's still dangerous + * + * The same applies to "update_{$meta_type}_metadata", we define schema is an array but the POST value should be a string|number|boolean + * Need to test if possible to skip the schema validation on POST request + * + * Ref: function _block_bindings_post_meta_get_value( array $source_args, $block_instance ) { + * Ref: get_{$meta_type}_metadata + * Ref: update_{$meta_type}_metadata + * @return void + */ + public function testValidSchema() { + //$check = rest_validate_value_from_schema( $args['default'], $schema ); + + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } +} \ No newline at end of file From 7adffb5ecbcf2be8c12d8315725404141325dd83 Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Mon, 19 Aug 2024 04:16:40 +0000 Subject: [PATCH 2/7] fix: remove unused code --- inc/field-registry.php | 41 ----------------------------------------- inc/meta-box.php | 1 - 2 files changed, 42 deletions(-) diff --git a/inc/field-registry.php b/inc/field-registry.php index 04aaf38c..0bfab364 100644 --- a/inc/field-registry.php +++ b/inc/field-registry.php @@ -34,47 +34,6 @@ public function add( array $field, string $type, string $object_type = 'post' ) do_action( 'rwmb_field_registered', $field, $type, $object_type ); } - public function set_meta_box( array $meta_box ) { - $this->meta_box = $meta_box; - } - - public function get_meta_box() { - return $this->meta_box; - } - - public function register_meta( $field, $type, $object_type ) { - // Bail early if the field is implicitly not registered as meta. - if ( ! $field['register_meta'] ) { - return; - } - - // Bail if the meta box storage is custom table. - if ( ! isset( $field['storage'] ) || ! $field['storage'] instanceof RWMB_Post_Storage ) { - return; - } - - $type_default = $this->get_return_type_and_default( $field ); - - $args = [ - 'object_subtype' => $object_type, - 'type' => $type_default['type'], - 'description' => $field['desc'] ?? '', - 'single' => ! $field['multiple'], - 'default' => $type_default['default'], - 'show_in_rest' => true, - 'revision_enabled' => ( isset( $this->meta_box['revision'] ) && $this->meta_box['revision'] && $object_type === 'post' ) || false, - ]; - - $field_register_meta = is_array( $field['register_meta'] ) ? $field['register_meta'] : []; - - // Merge the args with the field's args. - $args = array_merge( $args, $field_register_meta ); - - register_meta( $object_type, $field['id'], $args ); - } - - - /** * Retrieve a field. * diff --git a/inc/meta-box.php b/inc/meta-box.php index 884de470..2af6ba50 100644 --- a/inc/meta-box.php +++ b/inc/meta-box.php @@ -62,7 +62,6 @@ public function __construct( array $meta_box ) { public function register_fields() { $field_registry = rwmb_get_registry( 'field' ); - $field_registry->set_meta_box( $this->meta_box ); foreach ( $this->post_types as $post_type ) { foreach ( $this->fields as $field ) { From f82a4c8358c14bc525bc29c30dc4446ca960157d Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Mon, 19 Aug 2024 04:55:42 +0000 Subject: [PATCH 3/7] fix: use strict type as wp does --- inc/field.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/field.php b/inc/field.php index c3a31404..78433073 100644 --- a/inc/field.php +++ b/inc/field.php @@ -664,8 +664,8 @@ private static function get_validated_default_value( $field, $return_type ) { $default = 0; } - if ( 'object' === $return_type && ! is_array( $default ) ) { - $default = []; + if ( 'object' === $return_type && ! is_object( $default ) ) { + $default = new stdClass(); } return $default; From e0de7700838814ce816cdcfbe5f818ba2d89aebe Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Mon, 19 Aug 2024 07:52:08 +0000 Subject: [PATCH 4/7] refactor: type hinting for field schema --- inc/field-registry.php | 2 -- inc/field.php | 19 ++++++++++++------- inc/fields/background.php | 7 +++++++ inc/fields/button.php | 11 ++++++++++- inc/fields/checkbox.php | 15 +++++++++------ inc/fields/choice.php | 10 +++++----- inc/fields/custom-html.php | 9 +++++++-- inc/fields/divider.php | 10 +++++++--- inc/fields/fieldset-text.php | 8 +++++--- inc/fields/file.php | 19 ++++++++++++++++--- inc/fields/heading.php | 10 ++++++++-- inc/fields/input.php | 15 ++++++++------- inc/fields/media.php | 6 +++++- tests/bootstrap.php | 10 +++++----- tests/phpunit/FieldReturnTypeTest.php | 6 +++--- tests/phpunit/RegisterMetaTest.php | 16 ++++++++-------- 16 files changed, 115 insertions(+), 58 deletions(-) diff --git a/inc/field-registry.php b/inc/field-registry.php index 0bfab364..bbe3d7d1 100644 --- a/inc/field-registry.php +++ b/inc/field-registry.php @@ -7,8 +7,6 @@ class RWMB_Field_Registry { private $data = []; - private $meta_box; - /** * Add a single field to the registry. * diff --git a/inc/field.php b/inc/field.php index 78433073..90b4b314 100644 --- a/inc/field.php +++ b/inc/field.php @@ -317,7 +317,7 @@ public static function normalize( $field ) { 'attributes' => [], 'sanitize_callback' => null, - 'register_meta' => true, + 'register_meta' => false, ] ); // Store the original ID to run correct filters for the clonable field. @@ -601,6 +601,10 @@ public static function register_meta( $field, $meta_box, $post_type ) { $args = array_merge( $args, self::get_register_meta_args( $field ) ); + if ( $args['type'] === 'null' ) { + return; + } + register_meta( $post_type, $field['id'], $args ); } @@ -616,11 +620,6 @@ public static function get_register_meta_args( $field ) { } $schema = self::call( 'get_schema', $field ); - - // HTML, Heading, Divider, etc. don't have a schema. - if ( ! $schema ) { - return []; - } $return_type = $schema['type'] ?? 'string'; @@ -672,7 +671,6 @@ private static function get_validated_default_value( $field, $return_type ) { } protected static function get_full_schema( $field ) { - $field = self::call( 'normalize', $field ); $schema = self::call( 'get_schema', $field ); if ( ! $schema ) { @@ -689,6 +687,13 @@ protected static function get_full_schema( $field ) { return $schema; } + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ protected static function get_schema( $field ) { return [ 'type' => 'string' ]; } diff --git a/inc/fields/background.php b/inc/fields/background.php index 080fe189..2af82252 100644 --- a/inc/fields/background.php +++ b/inc/fields/background.php @@ -156,6 +156,13 @@ public static function format_single_value( $field, $value, $args, $post_id ) { return $output; } + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ public static function get_schema( $field ) { return [ 'type' => 'object', diff --git a/inc/fields/button.php b/inc/fields/button.php index 47106eec..a239edc0 100644 --- a/inc/fields/button.php +++ b/inc/fields/button.php @@ -48,7 +48,16 @@ public static function get_attributes( $field, $value = null ) { return $attributes; } + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ protected static function get_schema( $field ) { - return false; + return [ + 'type' => 'null', + ]; } } diff --git a/inc/fields/checkbox.php b/inc/fields/checkbox.php index 29a10af4..c12a270c 100644 --- a/inc/fields/checkbox.php +++ b/inc/fields/checkbox.php @@ -44,13 +44,16 @@ public static function format_single_value( $field, $value, $args, $post_id ) { } /** - * Get the type of a single item. - * - * @param array $field Field parameters. - * - * @return array + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} */ protected static function get_schema( $field ) { - return [ 'type' => 'integer' ]; + return [ + 'type' => 'integer', + ]; } + } diff --git a/inc/fields/choice.php b/inc/fields/choice.php index 594531f8..172e8244 100644 --- a/inc/fields/choice.php +++ b/inc/fields/choice.php @@ -68,11 +68,11 @@ public static function format_single_value( $field, $value, $args, $post_id ) { } /** - * Get the type of a single item. - * - * @param array $field Field parameters. - * - * @return array + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} */ protected static function get_schema( $field ) { if ( $field['multiple'] ) { diff --git a/inc/fields/custom-html.php b/inc/fields/custom-html.php index fd49782a..e6621252 100644 --- a/inc/fields/custom-html.php +++ b/inc/fields/custom-html.php @@ -22,9 +22,14 @@ public static function html( $meta, $field ) { } /** - * Get the type of a single item. + * Get the schema for the field. + * + * @param array $field + * @return array{type: string, items: ?array, properties: ?array} */ protected static function get_schema( $field ) { - return false; + return [ + 'type' => 'null', + ]; } } diff --git a/inc/fields/divider.php b/inc/fields/divider.php index b3763e0a..41669898 100644 --- a/inc/fields/divider.php +++ b/inc/fields/divider.php @@ -20,11 +20,15 @@ public static function end_html( array $field ) : string { } /** - * Divider field does not have a schema. + * Get the schema for the field. + * * @param array $field - * @return bool + * + * @return array{type: string, items: ?array, properties: ?array} */ protected static function get_schema( $field ) { - return false; + return [ + 'type' => 'null', + ]; } } diff --git a/inc/fields/fieldset-text.php b/inc/fields/fieldset-text.php index 11c0c4b4..6c50e3c1 100644 --- a/inc/fields/fieldset-text.php +++ b/inc/fields/fieldset-text.php @@ -104,9 +104,11 @@ public static function format_single_value( $field, $value, $args, $post_id ) { } /** - * Get the type of a single item. - * - * @param array $field Field parameters. + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} */ protected static function get_schema( $field ) { $properties = []; diff --git a/inc/fields/file.php b/inc/fields/file.php index f44c89ab..c5f75cb3 100644 --- a/inc/fields/file.php +++ b/inc/fields/file.php @@ -446,7 +446,7 @@ public static function format_single_value( $field, $value, $args, $post_id ) { * @param string $file_id File ID in $_FILES when uploading. * @param array $field Field settings. * - * @return string URL to uploaded file. + * @return string|void URL to uploaded file. */ public static function handle_upload_custom_dir( $file_id, $field ) { // @codingStandardsIgnoreStart @@ -494,12 +494,25 @@ public static function convert_path_to_url( string $path ) : string { } /** - * This field saves multiple file IDs in db. + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} */ protected static function get_schema( $field ) { return [ 'type' => 'array', - 'items' => [ 'type' => 'integer' ] + 'items' => [ + 'type' => 'object', + 'properties' => [ + 'ID' => [ 'type' => 'integer' ], + 'name' => [ 'type' => 'string' ], + 'path' => [ 'type' => 'string' ], + 'url' => [ 'type' => 'string' ], + 'title' => [ 'type' => 'string' ], + ], + ] ]; } } diff --git a/inc/fields/heading.php b/inc/fields/heading.php index c0fa085c..e7c13360 100644 --- a/inc/fields/heading.php +++ b/inc/fields/heading.php @@ -20,9 +20,15 @@ protected static function end_html( array $field ) : string { } /** - * Get the type of a single item. + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} */ protected static function get_schema( $field ) { - return false; + return [ + 'type' => 'null', + ]; } } diff --git a/inc/fields/input.php b/inc/fields/input.php index 6c2da207..5c92cd3d 100644 --- a/inc/fields/input.php +++ b/inc/fields/input.php @@ -110,14 +110,15 @@ protected static function datalist( array $field ) : string { return $html; } - /** - * Get the type of a single item. - * - * @param array $field Field parameters. - * - * @return array + /** + * Get the schema for the field. + * + * @param array $field + * @return array{type: string, items: ?array, properties: ?array} */ protected static function get_schema( $field ) { - return [ 'type' => 'string' ]; + return [ + 'type' => 'string', + ]; } } diff --git a/inc/fields/media.php b/inc/fields/media.php index 456eb6be..9ed0b391 100644 --- a/inc/fields/media.php +++ b/inc/fields/media.php @@ -214,7 +214,11 @@ public static function print_templates() { } /** - * This field saves multiple file IDs in db. + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} */ protected static function get_schema( $field ) { if ( $field['multiple'] ) { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 68331dc9..8c558931 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -13,7 +13,7 @@ 'title' => 'Test Register Meta', 'revision' => true, 'fields' => [ - // RegisterMetaTest::testFieldRegisteredByDefault() + // RegisterMetaTest::testFieldNotRegisteredByDefault() [ 'name' => 'rmt_simple_text', 'desc' => 'Basic text field', @@ -21,13 +21,13 @@ 'type' => 'text', 'std' => 'Simple Text Default', ], - // RegisterMetaTest::testNotRegisteredFieldShouldNotBeRegistered() + // RegisterMetaTest::testRegisteredField() [ - 'name' => 'rmt_text_no_register_meta', + 'name' => 'rmt_text_register_meta', 'desc' => 'Text No Register Meta Description', - 'id' => 'rmt_text_no_register_meta', + 'id' => 'rmt_text_register_meta', 'type' => 'text', - 'register_meta' => false + 'register_meta' => true ], // RegisterMetaTest::testOverrideArgs() [ diff --git a/tests/phpunit/FieldReturnTypeTest.php b/tests/phpunit/FieldReturnTypeTest.php index 1bf78721..cd6cae15 100644 --- a/tests/phpunit/FieldReturnTypeTest.php +++ b/tests/phpunit/FieldReturnTypeTest.php @@ -11,15 +11,15 @@ class FieldReturnTypeTest extends TestCase { protected $field_return_types = [ 'autocomplete' => 'array', 'background' => 'object', // All fields that return key-value pairs should return an object - 'button' => false, + 'button' => 'null', 'button_group' => 'string', 'checkbox_list' => 'array', 'checkbox' => 'integer', 'color' => 'string', - 'custom_html' => false, + 'custom_html' => 'null', 'date' => 'string', 'datetime' => 'string', - 'divider' => false, + 'divider' => 'null', 'file_advanced' => 'array', 'file_input' => 'string', 'file_upload' => 'array', diff --git a/tests/phpunit/RegisterMetaTest.php b/tests/phpunit/RegisterMetaTest.php index a91520f8..30736173 100644 --- a/tests/phpunit/RegisterMetaTest.php +++ b/tests/phpunit/RegisterMetaTest.php @@ -8,12 +8,12 @@ public function setUp(): void { $this->meta = get_registered_meta_keys( 'post' ); } - public function testFieldRegisteredByDefault() { - $this->assertArrayHasKey( 'rmt_simple_text', $this->meta ); + public function testFieldNotRegisteredByDefault() { + $this->assertArrayNotHasKey( 'rmt_simple_text', $this->meta ); } - public function testNotRegisteredFieldShouldNotBeRegistered() { - $this->assertArrayNotHasKey( 'rmt_text_no_register_meta', $this->meta ); + public function testRegisteredField() { + $this->assertArrayHasKey( 'rmt_text_register_meta', $this->meta ); } /** @@ -39,7 +39,7 @@ public function testOverrideArgs() { */ public function testRevisionArgument() { // This inherits from the meta box - $this->assertEquals( true, $this->meta['rmt_simple_text']['revisions_enabled'] ); + $this->assertEquals( true, $this->meta['rmt_text_register_meta']['revisions_enabled'] ); // This is set to false $this->assertEquals( false, $this->meta['rmt_text_override']['revisions_enabled'] ); @@ -50,7 +50,7 @@ public function testRevisionArgument() { * 2. If $field['register_meta']['multiple'] is set, it should be used */ public function testSingleArgument() { - $this->assertEquals( true, $this->meta['rmt_simple_text']['single'] ); + $this->assertEquals( true, $this->meta['rmt_text_register_meta']['single'] ); } /** @@ -58,7 +58,7 @@ public function testSingleArgument() { * 2. If $field['register_meta']['show_in_rest'] is set, it should be used */ public function testShowInRestArgument() { - $this->assertEquals( true, $this->meta['rmt_simple_text']['show_in_rest'] ); + $this->assertEquals( true, $this->meta['rmt_text_register_meta']['show_in_rest'] ); $this->assertEquals( false, $this->meta['rmt_text_override']['show_in_rest'] ); } @@ -78,7 +78,7 @@ public function testShowInRestArgument() { * Need to test if possible to skip the schema validation on POST request * * Ref: function _block_bindings_post_meta_get_value( array $source_args, $block_instance ) { - * Ref: get_{$meta_type}_metadata + * Ref: get_{$meta_type}_metadata * Ref: update_{$meta_type}_metadata * @return void */ From 9190d448e91851202f4f9c621d9da43b4c54e268 Mon Sep 17 00:00:00 2001 From: Anh Tran Date: Tue, 20 Aug 2024 07:12:31 +0700 Subject: [PATCH 5/7] Change params for update_meta & update type hint --- inc/field-registry.php | 2 -- inc/field.php | 32 ++++++++++++++------------------ inc/fields/background.php | 6 +++--- inc/fields/button.php | 6 +++--- inc/fields/checkbox.php | 7 +++---- inc/fields/choice.php | 8 ++++---- inc/fields/custom-html.php | 4 ++-- inc/fields/divider.php | 6 +++--- inc/fields/fieldset-text.php | 6 +++--- inc/fields/file.php | 14 +++++++------- inc/fields/heading.php | 6 +++--- inc/fields/input.php | 4 ++-- inc/fields/media.php | 14 +++++++------- inc/fields/multiple-values.php | 6 +++--- inc/fields/number.php | 2 +- inc/fields/range.php | 2 +- inc/fields/slider.php | 2 +- inc/fields/switch.php | 2 +- inc/fields/taxonomy-advanced.php | 9 ++++++++- inc/meta-box.php | 4 ++-- 20 files changed, 71 insertions(+), 71 deletions(-) diff --git a/inc/field-registry.php b/inc/field-registry.php index bbe3d7d1..f7030e59 100644 --- a/inc/field-registry.php +++ b/inc/field-registry.php @@ -27,8 +27,6 @@ public function add( array $field, string $type, string $object_type = 'post' ) } $this->data[ $object_type ][ $type ][ $field['id'] ] = $field; - // $this->register_meta( $field, $type, $object_type ); - do_action( 'rwmb_field_registered', $field, $type, $object_type ); } diff --git a/inc/field.php b/inc/field.php index 90b4b314..40cf6ebe 100644 --- a/inc/field.php +++ b/inc/field.php @@ -577,7 +577,7 @@ public static function filter() { return $value; } - public static function register_meta( $field, $meta_box, $post_type ) { + public static function register_meta( array $field, array $meta_box, string $post_type ): void { // Bail early if the field is implicitly not registered as meta. if ( ! $field['register_meta'] ) { return; @@ -591,8 +591,9 @@ public static function register_meta( $field, $meta_box, $post_type ) { $revisions_enabled = $meta_box['revision'] ?? false; $args = [ + 'object_subtype' => $post_type, 'type' => 'string', - 'description' => $field['desc'] ?? '', + 'description' => $field['desc'] ?: $field['label_description'], 'single' => ! $field['multiple'], 'default' => '', 'show_in_rest' => true, @@ -605,15 +606,10 @@ public static function register_meta( $field, $meta_box, $post_type ) { return; } - register_meta( $post_type, $field['id'], $args ); + register_meta( 'post', $field['id'], $args ); } - /** - * Define the schema for the field. - * - * @return array - */ - public static function get_register_meta_args( $field ) { + private static function get_register_meta_args( array $field ): array { // If the schema is explicitly defined, use it. if ( is_array( $field['register_meta'] ) ) { return $field['register_meta']; @@ -629,7 +625,7 @@ public static function get_register_meta_args( $field ) { $schema = [ 'type' => 'array', 'items' => $schema, - ]; + ]; } $args['type'] = $return_type; @@ -640,11 +636,11 @@ public static function get_register_meta_args( $field ) { 'schema' => $schema ]; } - + return $args; } - private static function get_validated_default_value( $field, $return_type ) { + private static function get_validated_default_value( array $field, string $return_type ) { $default = $field['std'] ?? ''; if ( 'array' === $return_type && ! is_array( $default ) ) { @@ -670,11 +666,11 @@ private static function get_validated_default_value( $field, $return_type ) { return $default; } - protected static function get_full_schema( $field ) { + protected static function get_full_schema( array $field ): array { $schema = self::call( 'get_schema', $field ); if ( ! $schema ) { - return false; + return []; } if ( $field['clone'] === true ) { @@ -686,15 +682,15 @@ protected static function get_full_schema( $field ) { return $schema; } - + /** * Get the schema for the field. - * + * * @param array $field - * + * * @return array{type: string, items: ?array, properties: ?array} */ - protected static function get_schema( $field ) { + protected static function get_schema( array $field ): array { return [ 'type' => 'string' ]; } } diff --git a/inc/fields/background.php b/inc/fields/background.php index 2af82252..0cf545b6 100644 --- a/inc/fields/background.php +++ b/inc/fields/background.php @@ -158,12 +158,12 @@ public static function format_single_value( $field, $value, $args, $post_id ) { /** * Get the schema for the field. - * + * * @param array $field - * + * * @return array{type: string, items: ?array, properties: ?array} */ - public static function get_schema( $field ) { + protected static function get_schema( array $field ): array { return [ 'type' => 'object', 'properties' => [ diff --git a/inc/fields/button.php b/inc/fields/button.php index a239edc0..3fc6fa4e 100644 --- a/inc/fields/button.php +++ b/inc/fields/button.php @@ -50,12 +50,12 @@ public static function get_attributes( $field, $value = null ) { /** * Get the schema for the field. - * + * * @param array $field - * + * * @return array{type: string, items: ?array, properties: ?array} */ - protected static function get_schema( $field ) { + protected static function get_schema( array $field ): array { return [ 'type' => 'null', ]; diff --git a/inc/fields/checkbox.php b/inc/fields/checkbox.php index c12a270c..6adefcae 100644 --- a/inc/fields/checkbox.php +++ b/inc/fields/checkbox.php @@ -45,15 +45,14 @@ public static function format_single_value( $field, $value, $args, $post_id ) { /** * Get the schema for the field. - * + * * @param array $field - * + * * @return array{type: string, items: ?array, properties: ?array} */ - protected static function get_schema( $field ) { + protected static function get_schema( array $field ): array { return [ 'type' => 'integer', ]; } - } diff --git a/inc/fields/choice.php b/inc/fields/choice.php index 172e8244..def17a13 100644 --- a/inc/fields/choice.php +++ b/inc/fields/choice.php @@ -69,19 +69,19 @@ public static function format_single_value( $field, $value, $args, $post_id ) { /** * Get the schema for the field. - * + * * @param array $field - * + * * @return array{type: string, items: ?array, properties: ?array} */ - protected static function get_schema( $field ) { + protected static function get_schema( array $field ): array { if ( $field['multiple'] ) { return [ 'type' => 'array', 'items' => [ 'type' => 'string' ], ]; } - + return [ 'type' => 'string' ]; } } diff --git a/inc/fields/custom-html.php b/inc/fields/custom-html.php index e6621252..5be30f95 100644 --- a/inc/fields/custom-html.php +++ b/inc/fields/custom-html.php @@ -23,11 +23,11 @@ public static function html( $meta, $field ) { /** * Get the schema for the field. - * + * * @param array $field * @return array{type: string, items: ?array, properties: ?array} */ - protected static function get_schema( $field ) { + protected static function get_schema( array $field ): array { return [ 'type' => 'null', ]; diff --git a/inc/fields/divider.php b/inc/fields/divider.php index 41669898..c391e0cd 100644 --- a/inc/fields/divider.php +++ b/inc/fields/divider.php @@ -21,12 +21,12 @@ public static function end_html( array $field ) : string { /** * Get the schema for the field. - * + * * @param array $field - * + * * @return array{type: string, items: ?array, properties: ?array} */ - protected static function get_schema( $field ) { + protected static function get_schema( array $field ): array { return [ 'type' => 'null', ]; diff --git a/inc/fields/fieldset-text.php b/inc/fields/fieldset-text.php index 6c50e3c1..6f954210 100644 --- a/inc/fields/fieldset-text.php +++ b/inc/fields/fieldset-text.php @@ -105,12 +105,12 @@ public static function format_single_value( $field, $value, $args, $post_id ) { /** * Get the schema for the field. - * + * * @param array $field - * + * * @return array{type: string, items: ?array, properties: ?array} */ - protected static function get_schema( $field ) { + protected static function get_schema( array $field ): array { $properties = []; foreach ( $field['options'] as $key => $label ) { diff --git a/inc/fields/file.php b/inc/fields/file.php index c5f75cb3..9e281add 100644 --- a/inc/fields/file.php +++ b/inc/fields/file.php @@ -495,15 +495,15 @@ public static function convert_path_to_url( string $path ) : string { /** * Get the schema for the field. - * + * * @param array $field - * + * * @return array{type: string, items: ?array, properties: ?array} */ - protected static function get_schema( $field ) { - return [ - 'type' => 'array', - 'items' => [ + protected static function get_schema( array $field ): array { + return [ + 'type' => 'array', + 'items' => [ 'type' => 'object', 'properties' => [ 'ID' => [ 'type' => 'integer' ], @@ -512,7 +512,7 @@ protected static function get_schema( $field ) { 'url' => [ 'type' => 'string' ], 'title' => [ 'type' => 'string' ], ], - ] + ] ]; } } diff --git a/inc/fields/heading.php b/inc/fields/heading.php index e7c13360..7725ed25 100644 --- a/inc/fields/heading.php +++ b/inc/fields/heading.php @@ -21,12 +21,12 @@ protected static function end_html( array $field ) : string { /** * Get the schema for the field. - * + * * @param array $field - * + * * @return array{type: string, items: ?array, properties: ?array} */ - protected static function get_schema( $field ) { + protected static function get_schema( array $field ): array { return [ 'type' => 'null', ]; diff --git a/inc/fields/input.php b/inc/fields/input.php index 5c92cd3d..963f9695 100644 --- a/inc/fields/input.php +++ b/inc/fields/input.php @@ -112,11 +112,11 @@ protected static function datalist( array $field ) : string { /** * Get the schema for the field. - * + * * @param array $field * @return array{type: string, items: ?array, properties: ?array} */ - protected static function get_schema( $field ) { + protected static function get_schema( array $field ): array { return [ 'type' => 'string', ]; diff --git a/inc/fields/media.php b/inc/fields/media.php index 9ed0b391..5bc81e7e 100644 --- a/inc/fields/media.php +++ b/inc/fields/media.php @@ -215,19 +215,19 @@ public static function print_templates() { /** * Get the schema for the field. - * + * * @param array $field - * + * * @return array{type: string, items: ?array, properties: ?array} */ - protected static function get_schema( $field ) { + protected static function get_schema( array $field ): array { if ( $field['multiple'] ) { - return [ - 'type' => 'array', - 'items' => [ 'type' => 'integer' ] + return [ + 'type' => 'array', + 'items' => [ 'type' => 'integer' ] ]; } - + return [ 'type' => 'integer' ]; } } diff --git a/inc/fields/multiple-values.php b/inc/fields/multiple-values.php index 788aea87..ce865321 100644 --- a/inc/fields/multiple-values.php +++ b/inc/fields/multiple-values.php @@ -50,10 +50,10 @@ public static function format_single_value( $field, $value, $args, $post_id ) { * * @return array */ - protected static function get_schema( $field ) { - return [ + protected static function get_schema( array $field ): array { + return [ 'type' => 'array', - 'items' => [ + 'items' => [ 'type' => 'string', ], ]; diff --git a/inc/fields/number.php b/inc/fields/number.php index 218a9b05..695235ae 100644 --- a/inc/fields/number.php +++ b/inc/fields/number.php @@ -48,7 +48,7 @@ public static function get_attributes( $field, $value = null ) { * * @return array */ - protected static function get_schema( $field ) { + protected static function get_schema( array $field ): array { return [ 'type' => 'number' ]; } } diff --git a/inc/fields/range.php b/inc/fields/range.php index 77ab6c32..368c5f07 100644 --- a/inc/fields/range.php +++ b/inc/fields/range.php @@ -74,7 +74,7 @@ public static function value( $new, $old, $post_id, $field ) { * * @return array */ - protected static function get_schema( $field ) { + protected static function get_schema( array $field ): array { return [ 'type' => 'number' ]; } } diff --git a/inc/fields/slider.php b/inc/fields/slider.php index ddc2fef7..9a5570c9 100644 --- a/inc/fields/slider.php +++ b/inc/fields/slider.php @@ -77,7 +77,7 @@ public static function normalize( $field ) { * * @return array */ - protected static function get_schema( $field ) { + protected static function get_schema( array $field ): array { return [ 'type' => 'number' ]; } } diff --git a/inc/fields/switch.php b/inc/fields/switch.php index c5ba8895..2e84fea6 100644 --- a/inc/fields/switch.php +++ b/inc/fields/switch.php @@ -93,7 +93,7 @@ public static function format_single_value( $field, $value, $args, $post_id ) { * * @return array */ - protected static function get_schema( $field ) { + protected static function get_schema( array $field ): array { return [ 'type' => 'integer' ]; } } diff --git a/inc/fields/taxonomy-advanced.php b/inc/fields/taxonomy-advanced.php index 69952974..d31c3a11 100644 --- a/inc/fields/taxonomy-advanced.php +++ b/inc/fields/taxonomy-advanced.php @@ -103,7 +103,14 @@ public static function terms_info( $field, $term_ids, $args ) { return $field['multiple'] ? $info : reset( $info ); } - protected static function get_schema( $field ) { + /** + * Get the type of a single item. + * + * @param array $field Field parameters. + * + * @return array + */ + protected static function get_schema( array $field ): array { return [ 'type' => 'string' ]; } } diff --git a/inc/meta-box.php b/inc/meta-box.php index 2af6ba50..a551fc4e 100644 --- a/inc/meta-box.php +++ b/inc/meta-box.php @@ -62,11 +62,11 @@ public function __construct( array $meta_box ) { public function register_fields() { $field_registry = rwmb_get_registry( 'field' ); - + foreach ( $this->post_types as $post_type ) { foreach ( $this->fields as $field ) { $field_registry->add( $field, $post_type ); - + RWMB_Field::call( 'register_meta', $field, $this->meta_box, $post_type ); } } From 558d119c6c05bd049d50f57eb92ad76bee01232c Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Tue, 20 Aug 2024 03:40:30 +0000 Subject: [PATCH 6/7] refactor: update schema and test --- inc/field.php | 49 ++++++++++----------------- inc/fields/post.php | 18 ++++++++++ inc/fields/taxonomy-advanced.php | 12 ++++--- inc/fields/taxonomy.php | 11 ++++++ inc/fields/user.php | 18 ++++++++++ tests/phpunit/FieldReturnTypeTest.php | 21 +++++++++--- tests/phpunit/RegisterMetaTest.php | 2 +- 7 files changed, 89 insertions(+), 42 deletions(-) diff --git a/inc/field.php b/inc/field.php index 40cf6ebe..0c5140b6 100644 --- a/inc/field.php +++ b/inc/field.php @@ -615,29 +615,31 @@ private static function get_register_meta_args( array $field ): array { return $field['register_meta']; } - $schema = self::call( 'get_schema', $field ); + $schema = self::call( 'get_full_schema', $field ); - $return_type = $schema['type'] ?? 'string'; + $args['type'] = $schema['type']; + $args['default'] = self::get_validated_default_value( $field, $schema['type'] ); - if ( $field['clone'] ) { - $return_type = 'array'; - - $schema = [ - 'type' => 'array', - 'items' => $schema, + if ( in_array ( $schema['type'], [ 'array', 'object' ] ) ) { + $args['show_in_rest'] = [ + 'schema' => $schema ]; } - $args['type'] = $return_type; - $args['default'] = self::get_validated_default_value( $field, $return_type ); + return $args; + } + + protected static function get_full_schema( array $field ): array { + $schema = self::call( 'get_schema', $field ); - if ( in_array ( $return_type, [ 'array', 'object' ] ) ) { - $args['show_in_rest'] = [ - 'schema' => $schema + if ( $field['clone'] ) { + $schema = [ + 'type' => 'array', + 'items' => $schema, ]; } - return $args; + return $schema; } private static function get_validated_default_value( array $field, string $return_type ) { @@ -656,7 +658,7 @@ private static function get_validated_default_value( array $field, string $retur } if ( 'number' === $return_type && ! is_float( $default ) ) { - $default = 0; + $default = 0.0; } if ( 'object' === $return_type && ! is_object( $default ) ) { @@ -666,23 +668,6 @@ private static function get_validated_default_value( array $field, string $retur return $default; } - protected static function get_full_schema( array $field ): array { - $schema = self::call( 'get_schema', $field ); - - if ( ! $schema ) { - return []; - } - - if ( $field['clone'] === true ) { - $schema = [ - 'type' => 'array', - 'items' => $schema, - ]; - } - - return $schema; - } - /** * Get the schema for the field. * diff --git a/inc/fields/post.php b/inc/fields/post.php index 665cfeba..65fafa76 100644 --- a/inc/fields/post.php +++ b/inc/fields/post.php @@ -248,4 +248,22 @@ public static function add_new_form( array $field ): string { esc_html( $post_type_object->labels->add_new_item ) ); } + + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + if ( $field['multiple'] ) { + return [ + 'type' => 'array', + 'items' => [ 'type' => 'integer' ], + ]; + } + + return [ 'type' => 'integer' ]; + } } diff --git a/inc/fields/taxonomy-advanced.php b/inc/fields/taxonomy-advanced.php index d31c3a11..655e9e7a 100644 --- a/inc/fields/taxonomy-advanced.php +++ b/inc/fields/taxonomy-advanced.php @@ -104,13 +104,17 @@ public static function terms_info( $field, $term_ids, $args ) { } /** - * Get the type of a single item. + * Get the schema for the field. * - * @param array $field Field parameters. + * @param array $field * - * @return array + * @return array{type: string, items: ?array, properties: ?array} */ protected static function get_schema( array $field ): array { - return [ 'type' => 'string' ]; + if ( $field['multiple'] ) { + return [ 'type' => 'string' ]; + } + + return [ 'type' => 'integer' ]; } } diff --git a/inc/fields/taxonomy.php b/inc/fields/taxonomy.php index 382c0397..eaf06e57 100644 --- a/inc/fields/taxonomy.php +++ b/inc/fields/taxonomy.php @@ -323,4 +323,15 @@ protected static function get_taxonomy_singular_name( array $field ): string { return false === $taxonomy_object ? '' : $taxonomy_object->labels->singular_name; } + + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + return [ 'type' => 'integer' ]; + } } diff --git a/inc/fields/user.php b/inc/fields/user.php index f440bbfe..20875c40 100644 --- a/inc/fields/user.php +++ b/inc/fields/user.php @@ -189,4 +189,22 @@ public static function add_new_form( array $field ): string { esc_html__( 'Add New User', 'meta-box' ) ); } + + /** + * Get the schema for the field. + * + * @param array $field + * + * @return array{type: string, items: ?array, properties: ?array} + */ + protected static function get_schema( array $field ): array { + if ( $field['multiple'] ) { + return [ + 'type' => 'array', + 'items' => [ 'type' => 'integer' ], + ]; + } + + return [ 'type' => 'integer' ]; + } } diff --git a/tests/phpunit/FieldReturnTypeTest.php b/tests/phpunit/FieldReturnTypeTest.php index cd6cae15..414e0b06 100644 --- a/tests/phpunit/FieldReturnTypeTest.php +++ b/tests/phpunit/FieldReturnTypeTest.php @@ -33,7 +33,7 @@ class FieldReturnTypeTest extends TestCase { 'map' => 'string', 'oembed' => 'string', 'osm' => 'string', - 'post' => 'string', + 'post' => 'integer', 'radio' => 'string', 'range' => 'number', 'select_advanced' => 'string', @@ -41,11 +41,10 @@ class FieldReturnTypeTest extends TestCase { 'sidebar' => 'string', 'single_image' => 'integer', 'switch' => 'integer', - 'taxonomy_advanced' => 'string', - 'taxonomy' => 'string', + 'taxonomy' => 'integer', 'text_list' => 'array', 'textarea' => 'string', - 'user' => 'string', + 'user' => 'integer', 'video' => 'array', 'wysiwyg' => 'string', ]; @@ -66,7 +65,7 @@ public function testfieldShouldMatchReturnType() { foreach ( $this->field_return_types as $field_id => $expected_return_type ) { $field = $this->setupField( $field_id ); $schema = RWMB_Field::call( 'get_schema', $field ); - $type = $schema['type'] ?? false; + $type = $schema['type'] ?? 'null'; $this->assertEquals( $expected_return_type, $type, "Field $field_id should return $expected_return_type" ); } @@ -128,4 +127,16 @@ public function testFieldsetTextShouldReturnObject() { $this->assertEquals('string', $schema['properties']['name']['type'], 'Fieldset text field name property should return string' ); $this->assertEquals('string', $schema['properties']['email']['type'], 'Fieldset text field email property should return string' ); } + + public function testTaxonomyAdvancedField() { + $field_single = $this->setupField( 'taxonomy_advanced', [ 'taxonomy' => 'category' ] ); + $schema = RWMB_Field::call( 'get_full_schema', $field_single ); + + $this->assertEquals( 'integer', $schema['type'], 'Single taxonomy advanced should return integer' ); + + $field_multiple = $this->setupField( 'taxonomy_advanced_multiple', [ 'taxonomy' => 'category', 'multiple' => true ] ); + $schema_multiple = RWMB_Field::call( 'get_full_schema', $field_multiple ); + + $this->assertEquals( 'string', $schema_multiple['type'], 'Multiple taxonomy advanced should return CSV' ); + } } \ No newline at end of file diff --git a/tests/phpunit/RegisterMetaTest.php b/tests/phpunit/RegisterMetaTest.php index 30736173..b8375557 100644 --- a/tests/phpunit/RegisterMetaTest.php +++ b/tests/phpunit/RegisterMetaTest.php @@ -5,7 +5,7 @@ class RegisterMetaTest extends TestCase { private $meta; public function setUp(): void { - $this->meta = get_registered_meta_keys( 'post' ); + $this->meta = get_registered_meta_keys( 'post', 'post' ); } public function testFieldNotRegisteredByDefault() { From f8e114165d3cbcde4c050776b0f60b1b6fc8bc21 Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Tue, 20 Aug 2024 03:42:58 +0000 Subject: [PATCH 7/7] fix: schema for file.php --- inc/fields/file.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/inc/fields/file.php b/inc/fields/file.php index 9e281add..fa3b397a 100644 --- a/inc/fields/file.php +++ b/inc/fields/file.php @@ -502,17 +502,8 @@ public static function convert_path_to_url( string $path ) : string { */ protected static function get_schema( array $field ): array { return [ - 'type' => 'array', - 'items' => [ - 'type' => 'object', - 'properties' => [ - 'ID' => [ 'type' => 'integer' ], - 'name' => [ 'type' => 'string' ], - 'path' => [ 'type' => 'string' ], - 'url' => [ 'type' => 'string' ], - 'title' => [ 'type' => 'string' ], - ], - ] + 'type' => 'array', + 'items' => [ 'type' => 'integer' ], ]; } }