From eaca1da32810d8c86a5fd07816f03d7afed4204a Mon Sep 17 00:00:00 2001 From: Anumit Jooloor Date: Fri, 26 Jan 2024 03:36:23 -0800 Subject: [PATCH 01/14] Commit by Anumit Jooloor Testing for Anumit Jooloor. Just to check if changes get sent to development repository. --- uninstall.php | 1 + 1 file changed, 1 insertion(+) diff --git a/uninstall.php b/uninstall.php index 71e5375..01e64b6 100644 --- a/uninstall.php +++ b/uninstall.php @@ -1,5 +1,6 @@ Date: Fri, 26 Jan 2024 14:33:52 +0100 Subject: [PATCH 02/14] Try to change Anumit comment --- uninstall.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/uninstall.php b/uninstall.php index 01e64b6..1c716b0 100644 --- a/uninstall.php +++ b/uninstall.php @@ -1,6 +1,9 @@ Date: Fri, 26 Jan 2024 14:34:43 +0100 Subject: [PATCH 03/14] Add icons as shared package --- src/packages/icons.js | 144 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 src/packages/icons.js diff --git a/src/packages/icons.js b/src/packages/icons.js new file mode 100644 index 0000000..8d1992e --- /dev/null +++ b/src/packages/icons.js @@ -0,0 +1,144 @@ +/** + * WordPress dependencies + */ +import { Icon } from '@wordpress/components'; + +function IconWrapper( { className, icon } ) { + return ( +
+ +
+ ); +} + +export const ballIcon = ( { className } ) => { + return IconWrapper( { + className, + icon: () => ( + + + + ), + } ); +}; + +export const animationIcon = () => ( + ( + + + + + + ) } + /> +); + +export const copyrightIcon = () => ( + ( + + + + + + + + + ) } + /> +); + +export const slidesIcon = () => ( + ( + + + + + + + + ) } + /> +); From 052844a61c438b2ca9f9fced018cbf5932b78e20 Mon Sep 17 00:00:00 2001 From: Giacomo Secchi Date: Fri, 26 Jan 2024 14:35:52 +0100 Subject: [PATCH 04/14] Update import paths for icons --- src/blocks/animation/edit.js | 2 +- src/blocks/animation/index.js | 2 +- src/blocks/animation/variations.js | 2 +- src/blocks/copyright/index.js | 2 + src/blocks/slider/Carousel.js | 94 ++++++++++++++++++++---------- src/blocks/slider/edit.js | 4 +- src/blocks/slider/index.js | 2 + 7 files changed, 72 insertions(+), 36 deletions(-) diff --git a/src/blocks/animation/edit.js b/src/blocks/animation/edit.js index 35e7ecb..b6204f7 100644 --- a/src/blocks/animation/edit.js +++ b/src/blocks/animation/edit.js @@ -46,7 +46,7 @@ import './editor.scss'; * Internal dependencies */ import { settings } from './index'; -import { animationIcon } from './icons'; +import { animationIcon } from '../../packages/icons'; function AnimationPlaceholder( { setAttributes } ) { return ( diff --git a/src/blocks/animation/index.js b/src/blocks/animation/index.js index 92a63d6..2a45b12 100644 --- a/src/blocks/animation/index.js +++ b/src/blocks/animation/index.js @@ -23,7 +23,7 @@ import save from './save'; import metadata from './block.json'; import options from './options'; import variations from './variations'; -import { animationIcon } from './icons'; +import { animationIcon } from '../../packages/icons'; export const settings = { options, diff --git a/src/blocks/animation/variations.js b/src/blocks/animation/variations.js index a69ebbf..b93aa27 100644 --- a/src/blocks/animation/variations.js +++ b/src/blocks/animation/variations.js @@ -6,7 +6,7 @@ import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ -import { ballIcon, animationIcon } from './icons'; +import { ballIcon, animationIcon } from '../../packages/icons'; /** @typedef {import('@wordpress/blocks').WPBlockVariation} WPBlockVariation */ diff --git a/src/blocks/copyright/index.js b/src/blocks/copyright/index.js index d82621b..4014cb7 100644 --- a/src/blocks/copyright/index.js +++ b/src/blocks/copyright/index.js @@ -19,6 +19,7 @@ import './style.scss'; */ import Edit from './edit'; import metadata from './block.json'; +import { copyrightIcon } from '../../packages/icons'; /** * Every block starts by registering a new block type definition. @@ -26,6 +27,7 @@ import metadata from './block.json'; * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ */ registerBlockType( metadata.name, { + icon: copyrightIcon, /** * @see ./edit.js */ diff --git a/src/blocks/slider/Carousel.js b/src/blocks/slider/Carousel.js index 346b5b5..c74a43d 100644 --- a/src/blocks/slider/Carousel.js +++ b/src/blocks/slider/Carousel.js @@ -3,43 +3,73 @@ */ // import React from 'react'; // import Swiper JS +// import Swiper core and required modules +import { + Autoplay, + Navigation, + Pagination, + Scrollbar, + A11y, +} from 'swiper/modules'; import { Swiper, SwiperSlide } from 'swiper/react'; -import { Autoplay, Virtual } from 'swiper/modules'; -// import Swiper styles +// Import Swiper styles import 'swiper/css'; +import 'swiper/css/navigation'; +import 'swiper/css/pagination'; +import 'swiper/css/scrollbar'; -const Carousel = ( { delay, children } ) => { - debugger; - return ( - console.log( 'slide change' ) } - onSwiper={ ( swiper ) => console.log( swiper ) } - modules={ [ Autoplay ] } - > - Slide 1 - Slide 2 - Slide 3 - Slide 4 +const Carousel = ( { delay, elements } ) => { + // debugger; + // filter out not valid values like null, undefined, false, 0, empty string + const slides = elements.filter( ( child ) => !! child ); - { - /* loop through the children array and create a slide for each child */ - children.map( ( slideContent, index ) => ( - // You can do something with each child here - // For example, clone the child and add a key prop: - - { slideContent } - - ) ) - } - + return ( + /* here we use a conditional ternary operator to check if the slides are more than one */ + slides.length === 1 ? ( + elements + ) : ( + /* print Carousel custom component with properties */ + console.log( 'slide change' ) } + onSwiper={ ( swiper ) => console.log( swiper ) } + modules={ [ + Autoplay, + Navigation, + Pagination, + Scrollbar, + A11y, + ] } + > + { + /* loop through the children array and create a slide for each child */ + slides.map( ( slideContent, index ) => ( + // You can do something with each child here + // For example, clone the child and add a key prop: + + { slideContent } + + ) ) + } + + ) ); }; diff --git a/src/blocks/slider/edit.js b/src/blocks/slider/edit.js index f066a12..f642c35 100644 --- a/src/blocks/slider/edit.js +++ b/src/blocks/slider/edit.js @@ -74,6 +74,8 @@ export default function Edit( props ) { // this is an array of ReactNodes const reactNodeArray = [ + '', + '', 'Test', 42, I'm a span, @@ -95,7 +97,7 @@ export default function Edit( props ) { ) : ( /* print Carousel custom component with properties */ - + ) } diff --git a/src/blocks/slider/index.js b/src/blocks/slider/index.js index c6c1f59..9d51760 100644 --- a/src/blocks/slider/index.js +++ b/src/blocks/slider/index.js @@ -20,6 +20,7 @@ import './style.scss'; import edit from './edit'; import save from './save'; import metadata from './block.json'; +import { slidesIcon } from '../../packages/icons'; /** * Every block starts by registering a new block type definition. @@ -27,6 +28,7 @@ import metadata from './block.json'; * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ */ registerBlockType( metadata.name, { + icon: slidesIcon, /** * @see ./edit.js */ From 42fb457030c6786814cf9474cf844b7cca5667dc Mon Sep 17 00:00:00 2001 From: Giacomo Secchi Date: Fri, 2 Feb 2024 22:22:23 +0100 Subject: [PATCH 05/14] Update plugin versions in .wp-env.json --- .wp-env.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.wp-env.json b/.wp-env.json index 09049c8..9701902 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -2,11 +2,11 @@ "core": null, "plugins": [ ".", - "https://downloads.wordpress.org/plugin/jetpack.12.5.zip", - "https://downloads.wordpress.org/plugin/duracelltomi-google-tag-manager.1.18.1.zip", - "https://downloads.wordpress.org/plugin/woocommerce.8.0.3.zip", - "https://downloads.wordpress.org/plugin/query-monitor.3.13.1.zip", - "https://downloads.wordpress.org/plugin/sg-security.1.4.5.zip" + "https://downloads.wordpress.org/plugin/jetpack.13.0.zip", + "https://downloads.wordpress.org/plugin/duracelltomi-google-tag-manager.1.19.1.zip", + "https://downloads.wordpress.org/plugin/woocommerce.8.5.2.zip", + "https://downloads.wordpress.org/plugin/query-monitor.3.15.0.zip", + "https://downloads.wordpress.org/plugin/sg-security.1.4.10.zip" ], "themes": [ "./themes/twentytwenty-child" ], "mappings": { From 492295de5b1477c33f9d3407e074f11f45019787 Mon Sep 17 00:00:00 2001 From: Giacomo Secchi Date: Fri, 2 Feb 2024 22:31:07 +0100 Subject: [PATCH 06/14] Add coding standards and scripts to composer.json --- .phpcs.xml | 153 +++++++++ README.md | 13 +- composer.json | 21 +- composer.lock | 395 ++++++++++++++++++++++- woocommerce/single-product/tabs/tabs.php | 6 +- 5 files changed, 580 insertions(+), 8 deletions(-) create mode 100644 .phpcs.xml diff --git a/.phpcs.xml b/.phpcs.xml new file mode 100644 index 0000000..1ba4508 --- /dev/null +++ b/.phpcs.xml @@ -0,0 +1,153 @@ + + + + A custom set of rules to check for a WPized WordPress project + + + + . + + + /docroot/wp-admin/* + /docroot/wp-includes/* + /docroot/wp-*.php + /docroot/index.php + /docroot/xmlrpc.php + /docroot/wp-content/plugins/* + + + /vendor/* + + + /node_modules/* + + + *.js + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /path/to/Tests/*Test\.php + + + /path/to/Tests/*Test\.php + + + diff --git a/README.md b/README.md index 1a403b9..61bafd3 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,15 @@ Remember that the `pathMappings` inside `.vscode/launch.json` file should be as } ``` +## Coding Standard + + +Run the following command from the root directory to check the code for "sniffs". + +```bash +vendor/bin/phpcs -ps +``` + ## Creating a stable release @@ -76,9 +85,9 @@ Contributors who want to make a new release, follow these steps: 2. Add a git tag to the last commit with the same number of the plugin version, like this: ```bash - git tag -a 0.2.1 HEAD -m "Release 0.2.1" +git tag -a 0.2.1 HEAD -m "Release 0.2.1" ``` 3. To trigger the release GitHub Action run: ```bash - git push --tags +git push --tags ``` diff --git a/composer.json b/composer.json index 4f19261..053ff36 100644 --- a/composer.json +++ b/composer.json @@ -14,5 +14,24 @@ "name": "Giacomo Secchi", "email": "giacomo.secchi@gmail.com" } - ] + ], + "require-dev": { + "wp-coding-standards/wpcs": "^3.0" + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } + }, + "scripts": { + "check-cs": [ + "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs -ps" + ], + "fix-cs": [ + "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf --report=summary,source" + ], + "check-all": [ + "@check-cs" + ] + } } diff --git a/composer.lock b/composer.lock index 8a912a1..ecbc204 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "091377942a1b84db958a5c1b20542688", + "content-hash": "e44223ffbad13c0c382aaaa7277ab765", "packages": [ { "name": "antecedent/patchwork", @@ -2122,7 +2122,398 @@ "time": "2023-09-27T10:25:08+00:00" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/composer-installer.git", + "reference": "4be43904336affa5c2f70744a348312336afd0da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/4be43904336affa5c2f70744a348312336afd0da", + "reference": "4be43904336affa5c2f70744a348312336afd0da", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "ext-json": "*", + "ext-zip": "*", + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0", + "yoast/phpunit-polyfills": "^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcbf", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/composer-installer/issues", + "source": "https://github.com/PHPCSStandards/composer-installer" + }, + "time": "2023-01-05T11:28:13+00:00" + }, + { + "name": "phpcsstandards/phpcsextra", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", + "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", + "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpcsstandards/phpcsutils": "^1.0.9", + "squizlabs/php_codesniffer": "^3.8.0" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "phpcsstandards/phpcsdevtools": "^1.2.1", + "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSExtra/graphs/contributors" + } + ], + "description": "A collection of sniffs and standards for use with PHP_CodeSniffer.", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues", + "security": "https://github.com/PHPCSStandards/PHPCSExtra/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSExtra" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2023-12-08T16:49:07+00:00" + }, + { + "name": "phpcsstandards/phpcsutils", + "version": "1.0.9", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", + "reference": "908247bc65010c7b7541a9551e002db12e9dae70" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/908247bc65010c7b7541a9551e002db12e9dae70", + "reference": "908247bc65010c7b7541a9551e002db12e9dae70", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.8.0 || 4.0.x-dev@dev" + }, + "require-dev": { + "ext-filter": "*", + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "yoast/phpunit-polyfills": "^1.1.0 || ^2.0.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "autoload": { + "classmap": [ + "PHPCSUtils/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSUtils/graphs/contributors" + } + ], + "description": "A suite of utility functions for use with PHP_CodeSniffer", + "homepage": "https://phpcsutils.com/", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "phpcs3", + "standards", + "static analysis", + "tokens", + "utility" + ], + "support": { + "docs": "https://phpcsutils.com/", + "issues": "https://github.com/PHPCSStandards/PHPCSUtils/issues", + "security": "https://github.com/PHPCSStandards/PHPCSUtils/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSUtils" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2023-12-08T14:50:00+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.8.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "14f5fff1e64118595db5408e946f3a22c75807f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/14f5fff1e64118595db5408e946f3a22c75807f7", + "reference": "14f5fff1e64118595db5408e946f3a22c75807f7", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "bin": [ + "bin/phpcbf", + "bin/phpcs" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-01-11T20:47:48+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "3.0.1", + "source": { + "type": "git", + "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", + "reference": "b4caf9689f1a0e4a4c632679a44e638c1c67aff1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/b4caf9689f1a0e4a4c632679a44e638c1c67aff1", + "reference": "b4caf9689f1a0e4a4c632679a44e638c1c67aff1", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "ext-libxml": "*", + "ext-tokenizer": "*", + "ext-xmlreader": "*", + "php": ">=5.4", + "phpcsstandards/phpcsextra": "^1.1.0", + "phpcsstandards/phpcsutils": "^1.0.8", + "squizlabs/php_codesniffer": "^3.7.2" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcompatibility/php-compatibility": "^9.0", + "phpcsstandards/phpcsdevtools": "^1.2.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "ext-iconv": "For improved results", + "ext-mbstring": "For improved results" + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues", + "source": "https://github.com/WordPress/WordPress-Coding-Standards", + "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" + }, + "funding": [ + { + "url": "https://opencollective.com/thewpcc/contribute/wp-php-63406", + "type": "custom" + } + ], + "time": "2023-09-14T07:06:09+00:00" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], diff --git a/woocommerce/single-product/tabs/tabs.php b/woocommerce/single-product/tabs/tabs.php index bcf0941..5717eac 100644 --- a/woocommerce/single-product/tabs/tabs.php +++ b/woocommerce/single-product/tabs/tabs.php @@ -19,7 +19,7 @@ exit; } -use \WritePoetry\Api\PluginConfig; +use WritePoetry\Api\PluginConfig; /** * Filter tabs and allow third parties to add their own. @@ -29,8 +29,8 @@ * @see woocommerce_default_product_tabs() */ $product_tabs = apply_filters( 'woocommerce_product_tabs', array() ); -$config = PluginConfig::getInstance(); -$layout = get_option( "{$config->prefix}_product_infos_layout" ); +$config = PluginConfig::getInstance(); +$layout = get_option( "{$config->prefix}_product_infos_layout" ); if ( ! empty( $product_tabs ) ) : ?> From 2578cd9082ee29c8251cab8b1c47c3f7de81a314 Mon Sep 17 00:00:00 2001 From: Giacomo Secchi Date: Sat, 3 Feb 2024 09:10:14 +0100 Subject: [PATCH 07/14] Add code sniffing commands --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 61bafd3..f40a432 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,11 @@ Remember that the `pathMappings` inside `.vscode/launch.json` file should be as Run the following command from the root directory to check the code for "sniffs". +```bash +npm run composer run-script check-cs +``` + +If you were unable to install the Docker program, as an alternative, you can [install composer the traditional way](https://getcomposer.org/download/) and run this command to check for "sniffs". ```bash vendor/bin/phpcs -ps From b2626c6b243d89fa4bbb0493b4778dead38123df Mon Sep 17 00:00:00 2001 From: Giacomo Secchi Date: Sat, 3 Feb 2024 17:20:45 +0100 Subject: [PATCH 08/14] Add contributing guidelines and update README.md to link it --- CONTRIBUTING.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 32 ++++--------------------------- 2 files changed, 55 insertions(+), 28 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..26e8f7f --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,51 @@ + +## Git Good Practices + +### Set Your Committer Name & Email +To set your personal infos run the following command, paying attention to use your name and surname +and email + +```bash +git config user.name "John Doe" +git config user.email "john@doe.org" +``` +Some hints [here](https://www.git-tower.com/learn/git/faq/change-author-name-email) + +Commit all your changes in your own branch. Before making any code change, start a new Git branch where all your changes will be made. + + + +## Coding Standard + +- Ensure you stick to the [WordPress Coding Standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/). + +Run the following command from the root directory to check the code for "sniffs". +```bash +npm run composer run-script check-cs +``` + +If you were unable to install the Docker program, as an alternative, you can [install composer the traditional way](https://getcomposer.org/download/) and run this command to check for "sniffs". + +```bash +vendor/bin/phpcs -ps +``` + + + +## Creating a stable release + +Contributors who want to make a new release, follow these steps: + +1. Change the plugin `version` header field in the [main plugin file](write-poetry.php) and the `Stable tag` field in the Header informations of [readme.txt](readme.txt) file following the [WordPress versioning scheme](https://make.wordpress.org/core/handbook/about/release-cycle/version-numbering/) + +**N.B.: Don't forget to update the changelog with the details of the changes made in the new version.** + + +2. Add a git tag to the last commit with the same number of the plugin version, like this: +```bash +git tag -a 0.2.1 HEAD -m "Release 0.2.1" +``` +3. To trigger the release GitHub Action run: +```bash +git push --tags +``` diff --git a/README.md b/README.md index f40a432..f42b948 100644 --- a/README.md +++ b/README.md @@ -64,35 +64,11 @@ Remember that the `pathMappings` inside `.vscode/launch.json` file should be as } ``` -## Coding Standard +Contributing to WooCommerce +If you have a patch or have stumbled upon an issue with WooCommerce core, you can contribute this back to the code. Please read our contributor guidelines for more information on how you can do this. -Run the following command from the root directory to check the code for "sniffs". -```bash -npm run composer run-script check-cs -``` - -If you were unable to install the Docker program, as an alternative, you can [install composer the traditional way](https://getcomposer.org/download/) and run this command to check for "sniffs". - -```bash -vendor/bin/phpcs -ps -``` - - -## Creating a stable release +## Contributing to WritePoetry -Contributors who want to make a new release, follow these steps: +Please read this plugin [contributor guidelines](CONTRIBUTING.md) for more information on how you can do this. -1. Change the plugin `version` header field in the [main plugin file](write-poetry.php) and the `Stable tag` field in the Header informations of [readme.txt](readme.txt) file following the [WordPress versioning scheme](https://make.wordpress.org/core/handbook/about/release-cycle/version-numbering/) - -**N.B.: Don't forget to update the changelog with the details of the changes made in the new version.** - - -2. Add a git tag to the last commit with the same number of the plugin version, like this: -```bash -git tag -a 0.2.1 HEAD -m "Release 0.2.1" -``` -3. To trigger the release GitHub Action run: -```bash -git push --tags -``` From 98fe5d83d5eca87091d5b4886b6166da80501248 Mon Sep 17 00:00:00 2001 From: Giacomo Secchi Date: Sun, 4 Feb 2024 08:42:26 +0100 Subject: [PATCH 09/14] Add code sniffing commands --- .phpcs.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.phpcs.xml b/.phpcs.xml index 1ba4508..749fcbb 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -29,6 +29,9 @@ *.js + + *.css + From 2904a9e5db378ff46ab4df2834c8ce30824fc6d0 Mon Sep 17 00:00:00 2001 From: Giacomo Secchi Date: Sun, 4 Feb 2024 08:55:44 +0100 Subject: [PATCH 10/14] Fix code formatting and remove unnecessary comments via PHPCS --- includes/Api/PluginConfig.php | 39 ++- includes/Api/RegisterPostTaxonomies.php | 45 ++- includes/Api/RegisterPostTypes.php | 54 ++-- includes/Base/Activate.php | 2 +- includes/Base/AddMimeTypes.php | 22 +- includes/Base/BaseController.php | 44 +-- includes/Base/Deactivate.php | 4 +- includes/Base/Development/Example.php | 10 +- includes/Base/Development/MaintenanceMode.php | 13 +- includes/Base/Development/Utils.php | 5 +- includes/Base/RemoveUnwantedFeatures.php | 24 +- includes/Base/Updater/Smashing_Updater.php | 104 ++++--- includes/Base/Updater/Updater.php | 1 - includes/Base/Utils.php | 30 +- includes/FSE/Blocks.php | 9 +- includes/FSE/Theme/Assets.php | 38 ++- includes/Init.php | 36 +-- includes/Pages/Admin/CustomMediaType.php | 35 +-- includes/Pages/Admin/LoginScreen.php | 19 +- includes/Pages/Admin/SettingsLink.php | 13 +- includes/Pages/Admin/SettingsPage.php | 151 +++++----- includes/Pages/Admin/Views/HtmlContent.php | 16 +- includes/Pages/Admin/WooCommercePage.php | 166 ++++++----- includes/Pages/AdminController.php | 8 +- includes/Plugins/Gtm4wp.php | 10 +- includes/Plugins/Jetpack/Portfolio.php | 63 ++--- includes/Plugins/WooCommerce/CartRedirect.php | 29 +- .../WooCommerce/ProductAdditionalInfos.php | 72 ++--- includes/Plugins/WooCommerce/ProductZoom.php | 30 +- .../Plugins/WooCommerce/QuantityLayout.php | 63 +++-- .../WooCommerce/WooCommerceController.php | 54 ++-- mu-plugins/project-custom-functions.php | 263 ++++++++++-------- tests/bootstrap.php | 2 +- themes/twentytwenty-child/functions.php | 76 ++--- themes/twentytwenty-child/home-old.php | 2 +- woocommerce/global/quantity-input.php | 6 +- write-poetry.php | 21 +- 37 files changed, 801 insertions(+), 778 deletions(-) diff --git a/includes/Api/PluginConfig.php b/includes/Api/PluginConfig.php index 362de1c..d398ef0 100644 --- a/includes/Api/PluginConfig.php +++ b/includes/Api/PluginConfig.php @@ -12,9 +12,8 @@ namespace WritePoetry\Api; - class PluginConfig { - private static $instance; + private static $instance; public $plugin_path; public $plugin_url; public $build_path; @@ -27,24 +26,24 @@ class PluginConfig { public $authorize; - public function __construct() { - $this->plugin_path = wp_normalize_path( plugin_dir_path( dirname( __FILE__, 2 ) ) ); - $this->plugin_url = plugin_dir_url( dirname( __FILE__, 2 ) ); - $this->build_path = $this->plugin_path . 'build'; - $this->build_url = $this->plugin_url . 'build'; - $this->plugin_name = plugin_basename( dirname( __FILE__, 3 ) . '/write-poetry.php' ); - $this->plugin_main_file = wp_normalize_path( $this->plugin_path .'write-poetry.php' ); - $this->prefix = preg_replace( "/[^A-Za-z0-9 ]/", '', plugin_basename( $this->plugin_path ) ); - $this->github_username = 'giacomo-secchi'; - $this->github_repo = 'write-poetry'; - $this->authorize = 'abcdefghijk1234567890'; - } + public function __construct() { + $this->plugin_path = wp_normalize_path( plugin_dir_path( dirname( __DIR__, 1 ) ) ); + $this->plugin_url = plugin_dir_url( dirname( __DIR__, 1 ) ); + $this->build_path = $this->plugin_path . 'build'; + $this->build_url = $this->plugin_url . 'build'; + $this->plugin_name = plugin_basename( dirname( __DIR__, 2 ) . '/write-poetry.php' ); + $this->plugin_main_file = wp_normalize_path( $this->plugin_path . 'write-poetry.php' ); + $this->prefix = preg_replace( '/[^A-Za-z0-9 ]/', '', plugin_basename( $this->plugin_path ) ); + $this->github_username = 'giacomo-secchi'; + $this->github_repo = 'write-poetry'; + $this->authorize = 'abcdefghijk1234567890'; + } - public static function getInstance() { - if (self::$instance === null) { - self::$instance = new self(); - } + public static function getInstance() { + if ( self::$instance === null ) { + self::$instance = new self(); + } - return self::$instance; - } + return self::$instance; + } } diff --git a/includes/Api/RegisterPostTaxonomies.php b/includes/Api/RegisterPostTaxonomies.php index 6f151e6..753bd0c 100644 --- a/includes/Api/RegisterPostTaxonomies.php +++ b/includes/Api/RegisterPostTaxonomies.php @@ -10,35 +10,33 @@ * @since 0.2.5 */ - namespace WritePoetry\Api; +namespace WritePoetry\Api; use WritePoetry\Base\BaseController; class RegisterPostTaxonomies extends BaseController { - /** - * Initialize the class - */ - public function register() { - add_action( 'init', array( $this, 'register_custom_taxonomies' ) ); - } - /** - * Register Custom Taxonomies - * - * @since 0.2.5 - * @access public - * @return void - */ - public function register_custom_taxonomies() { + * Initialize the class + */ + public function register() { + add_action( 'init', array( $this, 'register_custom_taxonomies' ) ); + } + /** + * Register Custom Taxonomies + * + * @since 0.2.5 + * @access public + * @return void + */ + public function register_custom_taxonomies() { $default_args = array( - 'hierarchical' => true, - 'public' => true, - 'show_in_nav_menus' => true - ); - + 'hierarchical' => true, + 'public' => true, + 'show_in_nav_menus' => true, + ); foreach ( apply_filters( "{$this->prefix}_add_custom_taxonomies", array() ) as $taxonomy => $args ) { if ( taxonomy_exists( $taxonomy ) ) { @@ -47,12 +45,9 @@ public function register_custom_taxonomies() { $args = array_merge( $default_args, $args ); - - $object_type = $args["post_type"]; + $object_type = $args['post_type']; register_taxonomy( $taxonomy, $object_type, $args ); // Register Custom Post Type } - } + } } - - diff --git a/includes/Api/RegisterPostTypes.php b/includes/Api/RegisterPostTypes.php index a87adca..aed9f13 100644 --- a/includes/Api/RegisterPostTypes.php +++ b/includes/Api/RegisterPostTypes.php @@ -16,48 +16,46 @@ class RegisterPostTypes extends BaseController { - /** - * Initialize the class - */ - public function register() { - add_action( 'init', array( $this, 'register_post_types') ); - } - - - /** - * Register All Post Type - * - * @since 0.2.5 - * @access public - * @return void - */ - public function register_post_types() { - + /** + * Initialize the class + */ + public function register() { + add_action( 'init', array( $this, 'register_post_types' ) ); + } + + + /** + * Register All Post Type + * + * @since 0.2.5 + * @access public + * @return void + */ + public function register_post_types() { $default_args = array( - 'show_in_rest' => true, - 'can_export' => true, // Allows export in Tools > Export - 'hierarchical' => false, // Allows your posts to behave like Hierarchy Pages - 'public' => true, - 'publicly_queryable' => false, - 'has_archive' => true, - 'supports' => array( + 'show_in_rest' => true, + 'can_export' => true, // Allows export in Tools > Export + 'hierarchical' => false, // Allows your posts to behave like Hierarchy Pages + 'public' => true, + 'publicly_queryable' => false, + 'has_archive' => true, + 'supports' => array( 'title', 'editor', 'excerpt', - 'thumbnail' + 'thumbnail', ), ); - foreach ( apply_filters( "{$this->prefix}_add_custom_post_types", array() ) as $post_type => $args ) { if ( post_type_exists( $post_type ) ) { return; } - $args = array_merge( $default_args , $args ); + $args = array_merge( $default_args, $args ); register_post_type( $post_type, $args ); // Register Custom Post Type } - } + } } diff --git a/includes/Base/Activate.php b/includes/Base/Activate.php index 8013adb..878f8af 100644 --- a/includes/Base/Activate.php +++ b/includes/Base/Activate.php @@ -12,7 +12,7 @@ namespace WritePoetry\Base; -use \WritePoetry\Api\PluginConfig; +use WritePoetry\Api\PluginConfig; class Activate { diff --git a/includes/Base/AddMimeTypes.php b/includes/Base/AddMimeTypes.php index 3cad3dd..3e33198 100644 --- a/includes/Base/AddMimeTypes.php +++ b/includes/Base/AddMimeTypes.php @@ -12,10 +12,9 @@ namespace WritePoetry\Base; - /** -* -*/ + * + */ class AddMimeTypes { public $media_types = array(); @@ -29,33 +28,28 @@ public function register() { // New allowed mime types. $this->media_types = array( - 'svg' => 'image/svg+xml', + 'svg' => 'image/svg+xml', // SVGZ allowed mime types. - 'svgz' => 'application/x-gzip', + 'svgz' => 'application/x-gzip', // Allow uploading fonts files. - 'ttf' => 'font/ttf', - 'woff' => 'font/woff', - 'woff2' =>'font/woff2' + 'ttf' => 'font/ttf', + 'woff' => 'font/woff', + 'woff2' => 'font/woff2', ); add_filter( 'upload_mimes', array( $this, 'addMimeType' ) ); add_filter( 'mime_types', array( $this, 'addMimeType' ) ); - - } public function addMimeType( $mimes ) { foreach ( $this->media_types as $t => $media_type ) { - $mimes[$t] = $media_type; + $mimes[ $t ] = $media_type; } - return $mimes; } - } - diff --git a/includes/Base/BaseController.php b/includes/Base/BaseController.php index ab5d8b3..efdf3b3 100644 --- a/includes/Base/BaseController.php +++ b/includes/Base/BaseController.php @@ -11,12 +11,13 @@ */ namespace WritePoetry\Base; -use \WritePoetry\Api\PluginConfig; + +use WritePoetry\Api\PluginConfig; /** -* -*/ + * + */ class BaseController { @@ -28,29 +29,30 @@ public function __construct() { $this->config = new PluginConfig(); } - /** - * Magic method that allows accessing configuration properties as if they were class properties. - * - * @param string $property The name of the property to retrieve from the $config object. - * - * @return mixed The value of the requested property if it exists in $config. - * @throws \Exception If the requested property does not exist in the $config object. - */ + /** + * Magic method that allows accessing configuration properties as if they were class properties. + * + * @param string $property The name of the property to retrieve from the $config object. + * + * @return mixed The value of the requested property if it exists in $config. + * @throws \Exception If the requested property does not exist in the $config object. + */ public function __get( $property ) { if ( property_exists( $this->config, $property ) ) { - return $this->config->$property; - } else { - throw new \Exception("Property '$property' does not exist."); - } - } + return $this->config->$property; + } else { + throw new \Exception( "Property '$property' does not exist." ); + } + } public function is_woocommerce_activated() { - add_filter( 'plugins_loaded', function () { - - return class_exists( 'WooCommerce' ) ? true : false; - } ); + add_filter( + 'plugins_loaded', + function () { + return class_exists( 'WooCommerce' ) ? true : false; + } + ); } } - diff --git a/includes/Base/Deactivate.php b/includes/Base/Deactivate.php index b9adffa..ef08aae 100644 --- a/includes/Base/Deactivate.php +++ b/includes/Base/Deactivate.php @@ -12,8 +12,8 @@ namespace WritePoetry\Base; -class Deactivate -{ +class Deactivate { + public static function deactivate() { flush_rewrite_rules(); } diff --git a/includes/Base/Development/Example.php b/includes/Base/Development/Example.php index 2368281..872bc16 100644 --- a/includes/Base/Development/Example.php +++ b/includes/Base/Development/Example.php @@ -12,11 +12,11 @@ namespace WritePoetry\Base\Development; -use \WritePoetry\Base\BaseController; +use WritePoetry\Base\BaseController; /** -* -*/ + * + */ class Example extends BaseController { /** * Invoke hooks. @@ -32,8 +32,4 @@ function enqueue() { wp_enqueue_style( 'mypluginstyle', $this->plugin_url . 'assets/mystyle.css' ); wp_enqueue_script( 'mypluginscript', $this->plugin_url . 'assets/myscript.js' ); } - - - } - diff --git a/includes/Base/Development/MaintenanceMode.php b/includes/Base/Development/MaintenanceMode.php index 5b0fda6..653ba17 100644 --- a/includes/Base/Development/MaintenanceMode.php +++ b/includes/Base/Development/MaintenanceMode.php @@ -12,12 +12,12 @@ namespace WritePoetry\Base\Development; -use \WritePoetry\Base\BaseController; -use \WritePoetry\Base\Utils; +use WritePoetry\Base\BaseController; +use WritePoetry\Base\Utils; /** -* -*/ + * + */ class MaintenanceMode extends BaseController { /** * Invoke hooks. @@ -35,7 +35,7 @@ public function register() { return; } - add_action('wp', array( $this, 'excluded_pages' ) ); + add_action( 'wp', array( $this, 'excluded_pages' ) ); } @@ -58,7 +58,6 @@ public function excluded_pages() { if ( '1' == get_option( "{$this->prefix}_maintenance_mode" ) ) { $this->wp_maintenance(); } - } public function wp_maintenance() { @@ -78,6 +77,4 @@ public function wp_maintenance() { 503 ); } - } - diff --git a/includes/Base/Development/Utils.php b/includes/Base/Development/Utils.php index c5ea2b2..477a893 100644 --- a/includes/Base/Development/Utils.php +++ b/includes/Base/Development/Utils.php @@ -33,7 +33,6 @@ public function register() { add_filter( 'style_loader_src', array( $this, 'remove_query_string_from_static_files' ), 10, 2 ); add_filter( 'script_loader_src', array( $this, 'remove_query_string_from_static_files' ), 10, 2 ); } - } @@ -49,12 +48,10 @@ public static function is_development() { // Remove version query string from static CSS files public static function remove_query_string_from_static_files( $src ) { - if ( strpos( $src, 'ver=' ) ) { + if ( strpos( $src, 'ver=' ) ) { $src = remove_query_arg( 'ver', $src ); } return $src; } - } - diff --git a/includes/Base/RemoveUnwantedFeatures.php b/includes/Base/RemoveUnwantedFeatures.php index afd9522..b0aa946 100644 --- a/includes/Base/RemoveUnwantedFeatures.php +++ b/includes/Base/RemoveUnwantedFeatures.php @@ -25,30 +25,32 @@ class RemoveUnwantedFeatures extends BaseController { public function register() { $this->turn_off_stuff(); - } /** - * Disable features - * - * @since 0.2.5 - * @access public - * @return void - */ + * Disable features + * + * @since 0.2.5 + * @access public + * @return void + */ public function turn_off_stuff() { - $hook_names = apply_filters( "{$this->prefix}_disable_features", array( - 'big_image_size_threshold' // https://make.wordpress.org/core/2019/10/09/introducing-handling-of-big-images-in-wordpress-5-3/ - ) ); + $hook_names = apply_filters( + "{$this->prefix}_disable_features", + array( + 'big_image_size_threshold', // https://make.wordpress.org/core/2019/10/09/introducing-handling-of-big-images-in-wordpress-5-3/ + ) + ); foreach ( $hook_names as $hook_name ) { if ( empty( $hook_name ) ) { return; } - add_filter( $hook_name, '__return_false' ); + add_filter( $hook_name, '__return_false' ); } } } diff --git a/includes/Base/Updater/Smashing_Updater.php b/includes/Base/Updater/Smashing_Updater.php index 976ae8a..68e4be9 100644 --- a/includes/Base/Updater/Smashing_Updater.php +++ b/includes/Base/Updater/Smashing_Updater.php @@ -9,8 +9,6 @@ namespace WritePoetry\Base\Updater; - - class Smashing_Updater { private $file; @@ -39,9 +37,9 @@ public function __construct( $file ) { } public function set_plugin_properties() { - $this->plugin = get_plugin_data( $this->file ); + $this->plugin = get_plugin_data( $this->file ); $this->basename = plugin_basename( $this->file ); - $this->active = is_plugin_active( $this->basename ); + $this->active = is_plugin_active( $this->basename ); } public function set_username( $username ) { @@ -57,33 +55,34 @@ public function authorize( $token ) { } private function get_repository_info() { - if ( is_null( $this->github_response ) ) { // Do we have a response? - $args = array(); - $request_uri = sprintf( 'https://api.github.com/repos/%s/%s/releases', $this->username, $this->repository ); // Build URI + if ( is_null( $this->github_response ) ) { // Do we have a response? + $args = array(); + $request_uri = sprintf( 'https://api.github.com/repos/%s/%s/releases', $this->username, $this->repository ); // Build URI - if( $this->authorize_token ) { // Is there an access token? - $args['headers']['Authorization'] = "bearer {$this->authorize_token}"; // Set the headers - } + if ( $this->authorize_token ) { // Is there an access token? + $args['headers']['Authorization'] = "bearer {$this->authorize_token}"; // Set the headers + } - $response = json_decode( wp_remote_retrieve_body( wp_remote_get( $request_uri, $args ) ), true ); // Get JSON and parse it + $response = json_decode( wp_remote_retrieve_body( wp_remote_get( $request_uri, $args ) ), true ); // Get JSON and parse it - if( is_array( $response ) ) { // If it is an array - $response = current( $response ); // Get the first item - } + if ( is_array( $response ) ) { // If it is an array + $response = current( $response ); // Get the first item + } - $this->github_response = $response; // Set it to our property - } + $this->github_response = $response; // Set it to our property + } } public function initialize() { add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'modify_transient' ), 10, 1 ); - add_filter( 'plugins_api', array( $this, 'plugin_popup' ), 10, 3); + add_filter( 'plugins_api', array( $this, 'plugin_popup' ), 10, 3 ); add_filter( 'upgrader_post_install', array( $this, 'after_install' ), 10, 3 ); // Add Authorization Token to download_package - add_filter( 'upgrader_pre_download', - function() { - add_filter( 'http_request_args', [ $this, 'download_package' ], 15, 2 ); + add_filter( + 'upgrader_pre_download', + function () { + add_filter( 'http_request_args', array( $this, 'download_package' ), 15, 2 ); return false; // upgrader_pre_download filter default return value. } ); @@ -91,28 +90,28 @@ function() { public function modify_transient( $transient ) { - if( property_exists( $transient, 'checked') ) { // Check if transient has a checked property + if ( property_exists( $transient, 'checked' ) ) { // Check if transient has a checked property - if( $checked = $transient->checked ) { // Did Wordpress check for updates? + if ( $checked = $transient->checked ) { // Did WordPress check for updates? $this->get_repository_info(); // Get the repo info $out_of_date = version_compare( $this->github_response['tag_name'], $checked[ $this->basename ], 'gt' ); // Check if we're out of date - if( $out_of_date ) { + if ( $out_of_date ) { $new_files = $this->github_response['zipball_url']; // Get the ZIP - $slug = current( explode('/', $this->basename ) ); // Create valid slug + $slug = current( explode( '/', $this->basename ) ); // Create valid slug $plugin = array( // setup our plugin info - 'url' => $this->plugin["PluginURI"], - 'slug' => $slug, - 'package' => $new_files, - 'new_version' => $this->github_response['tag_name'] + 'url' => $this->plugin['PluginURI'], + 'slug' => $slug, + 'package' => $new_files, + 'new_version' => $this->github_response['tag_name'], ); - $transient->response[$this->basename] = (object) $plugin; // Return it in response + $transient->response[ $this->basename ] = (object) $plugin; // Return it in response } } } @@ -122,38 +121,37 @@ public function modify_transient( $transient ) { public function plugin_popup( $result, $action, $args ) { - if( ! empty( $args->slug ) ) { // If there is a slug + if ( ! empty( $args->slug ) ) { // If there is a slug - if( $args->slug == current( explode( '/' , $this->basename ) ) ) { // And it's our slug + if ( $args->slug == current( explode( '/', $this->basename ) ) ) { // And it's our slug $this->get_repository_info(); // Get our repo info // Set it to an array $plugin = array( - 'name' => $this->plugin["Name"], - 'slug' => $this->basename, - 'requires' => '3.3', - 'tested' => '4.4.1', - 'rating' => '100.0', - 'num_ratings' => '10823', - 'downloaded' => '14249', - 'added' => '2016-01-05', - 'version' => $this->github_response['tag_name'], - 'author' => $this->plugin["AuthorName"], - 'author_profile' => $this->plugin["AuthorURI"], - 'last_updated' => $this->github_response['published_at'], - 'homepage' => $this->plugin["PluginURI"], - 'short_description' => $this->plugin["Description"], - 'sections' => array( - 'Description' => $this->plugin["Description"], - 'Updates' => $this->github_response['body'], + 'name' => $this->plugin['Name'], + 'slug' => $this->basename, + 'requires' => '3.3', + 'tested' => '4.4.1', + 'rating' => '100.0', + 'num_ratings' => '10823', + 'downloaded' => '14249', + 'added' => '2016-01-05', + 'version' => $this->github_response['tag_name'], + 'author' => $this->plugin['AuthorName'], + 'author_profile' => $this->plugin['AuthorURI'], + 'last_updated' => $this->github_response['published_at'], + 'homepage' => $this->plugin['PluginURI'], + 'short_description' => $this->plugin['Description'], + 'sections' => array( + 'Description' => $this->plugin['Description'], + 'Updates' => $this->github_response['body'], ), - 'download_link' => $this->github_response['zipball_url'] + 'download_link' => $this->github_response['zipball_url'], ); return (object) $plugin; // Return the data } - } return $result; // Otherwise return default } @@ -161,12 +159,12 @@ public function plugin_popup( $result, $action, $args ) { public function download_package( $args, $url ) { if ( null !== $args['filename'] ) { - if( $this->authorize_token ) { - $args = array_merge( $args, array( "headers" => array( "Authorization" => "token {$this->authorize_token}" ) ) ); + if ( $this->authorize_token ) { + $args = array_merge( $args, array( 'headers' => array( 'Authorization' => "token {$this->authorize_token}" ) ) ); } } - remove_filter( 'http_request_args', [ $this, 'download_package' ] ); + remove_filter( 'http_request_args', array( $this, 'download_package' ) ); return $args; } diff --git a/includes/Base/Updater/Updater.php b/includes/Base/Updater/Updater.php index ca2e76b..06d583a 100644 --- a/includes/Base/Updater/Updater.php +++ b/includes/Base/Updater/Updater.php @@ -2,7 +2,6 @@ /** * Wrap the Smashing_Updater class - * */ namespace WritePoetry\Base\Updater; diff --git a/includes/Base/Utils.php b/includes/Base/Utils.php index 7de7f4a..a818f60 100644 --- a/includes/Base/Utils.php +++ b/includes/Base/Utils.php @@ -16,8 +16,8 @@ /** -* -*/ + * + */ class Utils extends BaseController { /** * Invoke hooks. @@ -30,15 +30,15 @@ public function register() { /** - * Add query string parameters site-wide - * - * @since 0.2.2 - * @access public - * @return viod - */ + * Add query string parameters site-wide + * + * @since 0.2.2 + * @access public + * @return viod + */ public function add_query_vars( $qvars ) { - foreach( apply_filters( "{$this->prefix}_query_vars", array() ) as $qv ) { + foreach ( apply_filters( "{$this->prefix}_query_vars", array() ) as $qv ) { $qvars[] = $qv; } @@ -46,14 +46,14 @@ public function add_query_vars( $qvars ) { } /** - * This method attempts to retrieve the user's IP address by checking + * This method attempts to retrieve the user's IP address by checking * the 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', and 'REMOTE_ADDR' * server variables in that order, and returns the first valid IP address. - * - * @since 0.2.6 - * @access public - * @return string The user's IP address or an empty string if not found. - */ + * + * @since 0.2.6 + * @access public + * @return string The user's IP address or an empty string if not found. + */ public static function get_user_ip() { return $_SERVER['HTTP_CLIENT_IP'] ?? $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR']; } diff --git a/includes/FSE/Blocks.php b/includes/FSE/Blocks.php index 43e853b..c5f63d9 100644 --- a/includes/FSE/Blocks.php +++ b/includes/FSE/Blocks.php @@ -12,11 +12,11 @@ namespace WritePoetry\FSE; -use \WritePoetry\Base\BaseController; +use WritePoetry\Base\BaseController; /** -* -*/ + * + */ class Blocks extends BaseController { private $block_name = array(); @@ -58,7 +58,7 @@ public function register_multiple_blocks_callback( $attributes, $content, $block foreach ( $this->block_name as $block_name ) { $template_path = $this->build_path . '/blocks/' . $block_name . '/template.php'; - if ( ! empty( $block->block_type->view_script_handles )) { + if ( ! empty( $block->block_type->view_script_handles ) ) { // viewScript is defined wp_enqueue_script( $block->block_type->view_script_handles ); } @@ -96,4 +96,3 @@ function register_block_styles() { } } } - diff --git a/includes/FSE/Theme/Assets.php b/includes/FSE/Theme/Assets.php index 1be529d..d25999b 100644 --- a/includes/FSE/Theme/Assets.php +++ b/includes/FSE/Theme/Assets.php @@ -15,10 +15,10 @@ use WritePoetry\Base\BaseController; /** -* -*/ + * + */ class Assets extends BaseController { -/** + /** * Initialize the class */ public function register() { @@ -40,7 +40,6 @@ public function get_theme_version() { /** * Get active theme name. - * */ public function get_theme_slug() { return get_stylesheet(); @@ -54,7 +53,7 @@ public function get_theme_slug() { function scripts() { // Get configuration data from write-poetry-theme.json - $wp_theme_json_file = get_theme_file_path( '/write-poetry-theme.json' ); + $wp_theme_json_file = get_theme_file_path( '/write-poetry-theme.json' ); // Check if the file exists if ( ! file_exists( $wp_theme_json_file ) ) { @@ -63,7 +62,7 @@ function scripts() { // Get the JSON string from the file // Decode the JSON string to a PHP array - $decoded_file = json_decode( file_get_contents( $wp_theme_json_file ), true ); + $decoded_file = json_decode( file_get_contents( $wp_theme_json_file ), true ); // Check if the necessary keys exist in the theme data. if ( ! array_key_exists( 'files', $decoded_file ) ) { @@ -85,7 +84,6 @@ function scripts() { */ private function check_conditional_tags( $params ) { - foreach ( $params as $conditional_tag => $param ) { if ( strpos( $conditional_tag, 'is_' ) === 0 ) { @@ -100,7 +98,6 @@ private function check_conditional_tags( $params ) { } } } - } return true; // All conditions are met. @@ -115,8 +112,7 @@ private function check_conditional_tags( $params ) { */ private function enqueue_theme_files( $files, $type ) { - $version_string = empty( $file['ver'] ) ? $this->get_theme_version() : $file['ver']; - + $version_string = empty( $file['ver'] ) ? $this->get_theme_version() : $file['ver']; foreach ( $files as $file ) { // Check required dependencies @@ -125,7 +121,7 @@ private function enqueue_theme_files( $files, $type ) { $this->check_conditional_tags( $file ); $params = array( - $file['handle'] + $file['handle'], ); if ( ! empty( $file['src'] ) ) { @@ -171,10 +167,10 @@ function load_blocks_styles() { // Get the base assets path using a filter hook. // This allows customization of the path through the 'writepoetry_blocks_styles_asset_path' filter. - $base_assets_path = apply_filters( "{$this->prefix}_blocks_styles_asset_path", join( DIRECTORY_SEPARATOR, array('assets', 'css', 'blocks') ) ); + $base_assets_path = apply_filters( "{$this->prefix}_blocks_styles_asset_path", join( DIRECTORY_SEPARATOR, array( 'assets', 'css', 'blocks' ) ) ); // Use glob to get the list of stylesheets files in the assets folder - $blocks_path = glob( get_theme_file_path( $base_assets_path ) .'/*/*.css' ); + $blocks_path = glob( get_theme_file_path( $base_assets_path ) . '/*/*.css' ); /* * Load additional block styles. @@ -190,13 +186,15 @@ function load_blocks_styles() { $block_slug = str_replace( '/', '-', $block_name ); // Enqueue asset. - wp_enqueue_block_style( $block_name, array( - 'handle' => "$theme_slug-block-$block_slug", - 'src' => get_theme_file_uri( "$base_assets_path/$block_name.css" ), - 'path' => wp_normalize_path( $block_path ), - 'ver' => $this->get_theme_version() - ) ); + wp_enqueue_block_style( + $block_name, + array( + 'handle' => "$theme_slug-block-$block_slug", + 'src' => get_theme_file_uri( "$base_assets_path/$block_name.css" ), + 'path' => wp_normalize_path( $block_path ), + 'ver' => $this->get_theme_version(), + ) + ); } } } - diff --git a/includes/Init.php b/includes/Init.php index bcfe3ac..0577066 100644 --- a/includes/Init.php +++ b/includes/Init.php @@ -11,14 +11,16 @@ */ namespace WritePoetry; -use \WritePoetry\Api\PluginConfig; +use WritePoetry\Api\PluginConfig; -final class Init -{ + +final class Init { + /** * Store all the classes inside an array + * * @return array Full list of classes */ public static function get_services() { @@ -37,9 +39,9 @@ public static function get_services() { // Plugins\Gtm4wp::class ); - if ( is_admin() ) { - array_push( $services, + array_push( + $services, Pages\Admin\SettingsPage::class, Pages\Admin\CustomMediaType::class, Pages\Admin\SettingsLink::class, @@ -48,30 +50,29 @@ public static function get_services() { ); } - - // TODO: Restore filter to be sure that all plugins are loaded before check if WooCommerce is enabled // add_filter( 'plugins_loaded', function ( ) use ( $services ) { - if ( class_exists( 'WooCommerce' ) ) { - array_push( $services, - Plugins\WooCommerce\CartRedirect::class, - Plugins\WooCommerce\ProductZoom::class, - Plugins\WooCommerce\ProductAdditionalInfos::class, - Plugins\WooCommerce\WooCommerceController::class, - Plugins\WooCommerce\QuantityLayout::class - ); - } + if ( class_exists( 'WooCommerce' ) ) { + array_push( + $services, + Plugins\WooCommerce\CartRedirect::class, + Plugins\WooCommerce\ProductZoom::class, + Plugins\WooCommerce\ProductAdditionalInfos::class, + Plugins\WooCommerce\WooCommerceController::class, + Plugins\WooCommerce\QuantityLayout::class + ); + } // } ); - return $services; } /** * Loop through the classes, initialize them, * and call the register() method if it exists + * * @return */ public static function register_services() { @@ -85,6 +86,7 @@ public static function register_services() { /** * Initialize the class + * * @param class $class class from the services array * @return class instance new instance of the class */ diff --git a/includes/Pages/Admin/CustomMediaType.php b/includes/Pages/Admin/CustomMediaType.php index 3ca7260..d08cb79 100644 --- a/includes/Pages/Admin/CustomMediaType.php +++ b/includes/Pages/Admin/CustomMediaType.php @@ -12,13 +12,13 @@ namespace WritePoetry\Pages\Admin; -use \WritePoetry\Base\AddMimeTypes; -use \WritePoetry\Pages\AdminController; +use WritePoetry\Base\AddMimeTypes; +use WritePoetry\Pages\AdminController; /** -* -*/ + * + */ class CustomMediaType extends AdminController { public $settings; @@ -29,13 +29,13 @@ class CustomMediaType extends AdminController { * * @return void */ - public function register () { + public function register() { /** * register wp_setting_init to the admin_init action hook */ - add_action( 'admin_init', array( $this,'wp_setting_init' ) ); - } + add_action( 'admin_init', array( $this, 'wp_setting_init' ) ); + } public function __construct() { parent::__construct(); @@ -50,25 +50,20 @@ public function __construct() { */ // section content cb - function supported_media_types_section_cb () { + function supported_media_types_section_cb() { esc_html( - printf( implode( ', ', array_keys( wp_get_mime_types() ) ) ) + printf( implode( ', ', array_keys( wp_get_mime_types() ) ) ) ); } public function wp_setting_init() { - // register a new section in the "reading" page + // register a new section in the "reading" page add_settings_section( - "{$this->prefix}_supported_media_types_section", - __( 'Supported media types', 'write-poetry' ), - array( $this, 'supported_media_types_section_cb' ), - 'media' - ); - - + "{$this->prefix}_supported_media_types_section", + __( 'Supported media types', 'write-poetry' ), + array( $this, 'supported_media_types_section_cb' ), + 'media' + ); } - - } - diff --git a/includes/Pages/Admin/LoginScreen.php b/includes/Pages/Admin/LoginScreen.php index 9cd7c5f..2ff0209 100644 --- a/includes/Pages/Admin/LoginScreen.php +++ b/includes/Pages/Admin/LoginScreen.php @@ -12,11 +12,11 @@ namespace WritePoetry\Pages\Admin; -use \WritePoetry\Pages\AdminController; +use WritePoetry\Pages\AdminController; /** -* -*/ + * + */ class LoginScreen extends AdminController { /** * Invoke hooks. @@ -25,22 +25,21 @@ class LoginScreen extends AdminController { */ public function register() { - add_action( 'login_head', array( $this, 'custom_loginlogo' ) ); - add_filter( 'login_headerurl', array( $this, 'custom_loginlogo_url') ); + add_filter( 'login_headerurl', array( $this, 'custom_loginlogo_url' ) ); add_filter( 'login_headertext', array( $this, 'custom_login_title' ) ); add_filter( 'login_title', array( $this, 'custom_login_title' ) ); } function custom_loginlogo() { - $site_icon = get_site_icon_url(); + $site_icon = get_site_icon_url(); $background_image = ''; if ( ! empty( $site_icon ) ) { $background_image = $site_icon; - } else if ( function_exists( 'the_custom_logo' ) && has_custom_logo() ) { - $custom_logo_id = get_theme_mod( 'custom_logo' ); - $image = wp_get_attachment_image_src( $custom_logo_id , 'full' ); + } elseif ( function_exists( 'the_custom_logo' ) && has_custom_logo() ) { + $custom_logo_id = get_theme_mod( 'custom_logo' ); + $image = wp_get_attachment_image_src( $custom_logo_id, 'full' ); $background_image = $image[0]; } @@ -55,7 +54,6 @@ function custom_loginlogo() { } '; } - } function custom_loginlogo_url( $url ) { @@ -67,4 +65,3 @@ function custom_login_title() { return get_bloginfo( 'name' ); } } - diff --git a/includes/Pages/Admin/SettingsLink.php b/includes/Pages/Admin/SettingsLink.php index fe9751f..bc4f003 100644 --- a/includes/Pages/Admin/SettingsLink.php +++ b/includes/Pages/Admin/SettingsLink.php @@ -12,33 +12,32 @@ namespace WritePoetry\Pages\Admin; -use \WritePoetry\Pages\AdminController; +use WritePoetry\Pages\AdminController; /** -* -*/ + * + */ class SettingsLink extends AdminController { /** * Invoke hooks. * * @return void */ - public function register () { + public function register() { add_action( "plugin_action_links_$this->plugin_name", array( $this, 'add_action_links' ) ); } - public function add_action_links ( $actions ) { + public function add_action_links( $actions ) { $settingsPage = new SettingsPage(); // Build URL. $url = add_query_arg( 'page', $settingsPage->getPageSlug(), get_admin_url() . 'options-general.php' ); $mylinks = array( - '' . esc_html__( 'Settings', 'write-poetry' ) . '', + '' . esc_html__( 'Settings', 'write-poetry' ) . '', ); $actions = array_merge( $mylinks, $actions ); return $actions; } } - diff --git a/includes/Pages/Admin/SettingsPage.php b/includes/Pages/Admin/SettingsPage.php index 967cb8d..9aa332c 100644 --- a/includes/Pages/Admin/SettingsPage.php +++ b/includes/Pages/Admin/SettingsPage.php @@ -10,39 +10,39 @@ * @since 0.2.4 */ - namespace WritePoetry\Pages\Admin; +namespace WritePoetry\Pages\Admin; - use \WritePoetry\Pages\AdminController; +use WritePoetry\Pages\AdminController; /** -* -*/ + * + */ class SettingsPage extends AdminController { private $page_slug; private $option_group; - /** - * Holds the values to be used in the fields callbacks - */ - private $options; + /** + * Holds the values to be used in the fields callbacks + */ + private $options; public function __construct() { parent::__construct(); - $this->page_slug = "{$this->prefix}-settings"; + $this->page_slug = "{$this->prefix}-settings"; $this->option_group = "{$this->prefix}-settings-group"; } public function getPageSlug() { - return $this->page_slug; - } + return $this->page_slug; + } public function getOptionGroup() { - return $this->option_group; - } + return $this->option_group; + } /** * Invoke hooks. @@ -59,20 +59,20 @@ public function adminMenu() { $page_title = __( 'Write Poetry', 'write-poetry' ); $menu_title = __( 'Write Poetry', 'write-poetry' ); $capability = 'manage_options'; - $menu_slug = $this->page_slug; - $callback = array( $this, 'createAdminPage' ); - $position = 24; + $menu_slug = $this->page_slug; + $callback = array( $this, 'createAdminPage' ); + $position = 24; // This page will be under "Settings" add_options_page( $page_title, $menu_title, $capability, $menu_slug, $callback, $position ); } /** - * Options page callback - */ + * Options page callback + */ public function createAdminPage() { - if ( ! current_user_can('manage_options') ) { - wp_die('Unauthorized user'); + if ( ! current_user_can( 'manage_options' ) ) { + wp_die( 'Unauthorized user' ); } // Set class property @@ -82,67 +82,63 @@ public function createAdminPage() { /** * Register and add settings - */ - public function pageInit() - { - $page = $this->page_slug; + */ + public function pageInit() { + $page = $this->page_slug; $option_group = $this->option_group; - $sections = array( array( - 'id' => 'setting_section_custom_login', - 'title' => __( 'Customize login page', 'write-poetry' ), + 'id' => 'setting_section_custom_login', + 'title' => __( 'Customize login page', 'write-poetry' ), 'description' => sprintf( __( 'Replace the default WordPress logo, link and link text on the login screen page with your site logo or site icon if no logo is configured. Add the site icon.', 'write-poetry' ), self_admin_url( '/customize.php?autofocus[section]=title_tagline' ), __( 'Customizer' ) - - ) + ), ), array( - 'id' => 'setting_section_maintenance_mode', - 'title' => __( 'Enhanced maintenance mode', 'write-poetry' ), - 'description' => __( 'Put your website under maintenance', 'write-poetry' ) - ) + 'id' => 'setting_section_maintenance_mode', + 'title' => __( 'Enhanced maintenance mode', 'write-poetry' ), + 'description' => __( 'Put your website under maintenance', 'write-poetry' ), + ), // Add more sections as needed ); foreach ( $sections as $section ) { - $id = $section['id']; - $title = $section['title']; + $id = $section['id']; + $title = $section['title']; $callback = function () use ( $section ) { $callback_name = $section['callback'] ?? 'section_callback'; call_user_func( array( $this, $callback_name ), $section ); }; - add_settings_section( $id, $title, $callback, $page ); + add_settings_section( $id, $title, $callback, $page ); } - $fields = array( array( - 'id' => "{$this->prefix}_maintenance_mode", - 'title' => __( 'Enable Maintenance', 'write-poetry' ), + 'id' => "{$this->prefix}_maintenance_mode", + 'title' => __( 'Enable Maintenance', 'write-poetry' ), 'callback' => 'checkboxInputTemplate', - 'section' => 'setting_section_maintenance_mode' + 'section' => 'setting_section_maintenance_mode', ), array( - 'id' => "{$this->prefix}_custom_login", - 'title' => __( 'Enable custom login page', 'write-poetry' ), + 'id' => "{$this->prefix}_custom_login", + 'title' => __( 'Enable custom login page', 'write-poetry' ), 'callback' => 'checkboxInputTemplate', - 'section' => 'setting_section_custom_login' - ) + 'section' => 'setting_section_custom_login', + ), // Add more sections as needed ); foreach ( $fields as $field ) { $option_name = $field['id']; - $title = $field['title']; - $section = $field['section']; - $callback = function () use ( $field ) { + $title = $field['title']; + $section = $field['section']; + $callback = function () use ( $field ) { call_user_func( array( $this, $field['callback'] ), $field ); }; @@ -150,16 +146,20 @@ public function pageInit() add_settings_field( $option_name, $title, $callback, $page, $section ); $args = array( - 'type' => 'string', + 'type' => 'string', 'sanitize_callback' => array( $this, 'sanitize' ), - 'default' => 1, + 'default' => 1, ); - register_setting( $option_group, $option_name, function () use ( $args ) { - call_user_func( array( $this, 'sanitize' ), $args ); - } ); + register_setting( + $option_group, + $option_name, + function () use ( $args ) { + call_user_func( array( $this, 'sanitize' ), $args ); + } + ); } - } + } /** * Section callback function. @@ -175,40 +175,39 @@ function section_callback( $args ) { /** - * Sanitize each setting field as needed - * - * @param array $input Contains all settings fields as array keys - */ - public function sanitize( $input ) - { - + * Sanitize each setting field as needed + * + * @param array $input Contains all settings fields as array keys + */ + public function sanitize( $input ) { - $new_input = array(); - if ( isset( $input['id_number'] ) ){ + $new_input = array(); + if ( isset( $input['id_number'] ) ) { } - $new_input['id_number'] = absint( $input['id_number'] ); + $new_input['id_number'] = absint( $input['id_number'] ); - if( isset( $input['title'] ) ) - $new_input['title'] = sanitize_text_field( $input['title'] ); + if ( isset( $input['title'] ) ) { + $new_input['title'] = sanitize_text_field( $input['title'] ); + } - return $new_input; - } + return $new_input; + } /** - * Get the settings option array and print one of its values - */ - public function checkboxInputTemplate( $args ) - { + * Get the settings option array and print one of its values + */ + public function checkboxInputTemplate( $args ) { $disable_checkbox_field = $this->hasFiltersForOption( $args['id'] ); - $checked = get_option( $args['id'] ); - $current = 1; - $disable_current = true; - ?> /> + $checked = get_option( $args['id'] ); + $current = 1; + $disable_current = true; + ?> + /> getPageSlug(); + $page = $settingsPage->getPageSlug(); $option_group = $settingsPage->getOptionGroup(); ?>
-

+

prefix}-settings-group" + // output security fields for the registered setting "{$config->prefix}-settings-group" settings_fields( $option_group ); // output setting sections and their fields // (sections are registered for "{$config->prefix}-settings", each field is registered to a specific section) @@ -31,6 +31,6 @@ public static function getForm() { ?>
- $setting ) { if ( isset( $setting['id'] ) && $setting['id'] == 'woocommerce_cart_redirect_after_add' ) { - $settings[$index] = array( - 'name' => __( 'Add to cart behaviour', 'woocommerce' ), + $settings[ $index ] = array( + 'name' => __( 'Add to cart behaviour', 'woocommerce' ), // 'desc_tip' => $regeneration_aborted_warning, - 'id' => "{$this->prefix}_redirect_after_add", - 'type' => 'select', - 'default' => '', + 'id' => "{$this->prefix}_redirect_after_add", + 'type' => 'select', + 'default' => '', // 'css' => 'min-width:300px;', - 'desc' => __( 'Choose which page to redirect after a successful addition', 'write-poetry' ), - 'options' => array( - '' => __( 'Default (No redirect)', 'write-poetry' ), - 'cart' => __( 'Redirect to the cart page', 'write-poetry' ), - 'checkout' => __( 'Redirect to the checkout page', 'write-poetry' ), - // 'product-cart' => __( 'Redirect to cart page (only from single product page)', 'write-poetry' ), - // 'product-checkout' => __( 'Redirect to checkout page (only from single product page)', 'write-poetry' ), - ), // array of options for select/multiselects only - 'custom_attributes' => $this->setCustomAttribute( "{$this->prefix}_redirect_after_add" ) + 'desc' => __( 'Choose which page to redirect after a successful addition', 'write-poetry' ), + 'options' => array( + '' => __( 'Default (No redirect)', 'write-poetry' ), + 'cart' => __( 'Redirect to the cart page', 'write-poetry' ), + 'checkout' => __( 'Redirect to the checkout page', 'write-poetry' ), + // 'product-cart' => __( 'Redirect to cart page (only from single product page)', 'write-poetry' ), + // 'product-checkout' => __( 'Redirect to checkout page (only from single product page)', 'write-poetry' ), + ), // array of options for select/multiselects only + 'custom_attributes' => $this->setCustomAttribute( "{$this->prefix}_redirect_after_add" ), ); } if ( isset( $setting['id'] ) && $setting['id'] == 'woocommerce_enable_ajax_add_to_cart' ) { - $settings[$index]['checkboxgroup'] ='start'; + $settings[ $index ]['checkboxgroup'] = 'start'; } } @@ -98,104 +97,103 @@ function all_settings( $settings, $current_section ) { /** * Check the current section is what we want - **/ + */ if ( $current_section == 'appearance' ) { $settings_appearance = array(); // Add Title to the Settings - $settings_appearance[] = array( 'name' => __( 'Appearence', 'write-poetry' ), 'type' => 'title', 'desc' => __( 'The following options are used to configure single product page design', 'write-poetry' ), 'id' => 'appeareance' ); - + $settings_appearance[] = array( + 'name' => __( 'Appearence', 'write-poetry' ), + 'type' => 'title', + 'desc' => __( 'The following options are used to configure single product page design', 'write-poetry' ), + 'id' => 'appeareance', + ); // Add quantity layout field option $settings_appearance[] = array( - 'name' => __( 'Product quantity selector', 'write-poetry' ), - 'id' => "{$this->prefix}_product_quantity_layout", - 'default' => 'input', - 'type' => 'select', - 'value' => get_option( "{$this->prefix}_product_quantity_layout" ), - 'desc' => __( 'Choose the layout of quantity selector on the product page', 'write-poetry' ), - 'options' => array( - 'hidden' => __( 'Hidden (Product quantity will be always forced to one item)', 'write-poetry' ), - 'input' => __( 'Input', 'write-poetry' ), - 'select' => __( 'Select', 'write-poetry' ), - 'buttons' => __( 'Buttons', 'write-poetry' ) - ), // array of options for select/multiselects only - 'custom_attributes' => $this->setCustomAttribute( "{$this->prefix}_product_quantity_layout" ) + 'name' => __( 'Product quantity selector', 'write-poetry' ), + 'id' => "{$this->prefix}_product_quantity_layout", + 'default' => 'input', + 'type' => 'select', + 'value' => get_option( "{$this->prefix}_product_quantity_layout" ), + 'desc' => __( 'Choose the layout of quantity selector on the product page', 'write-poetry' ), + 'options' => array( + 'hidden' => __( 'Hidden (Product quantity will be always forced to one item)', 'write-poetry' ), + 'input' => __( 'Input', 'write-poetry' ), + 'select' => __( 'Select', 'write-poetry' ), + 'buttons' => __( 'Buttons', 'write-poetry' ), + ), // array of options for select/multiselects only + 'custom_attributes' => $this->setCustomAttribute( "{$this->prefix}_product_quantity_layout" ), ); - // Add single product checkbox option $settings_appearance[] = array( - 'id' => "{$this->prefix}_product_max_quantity", - 'type' => 'number', - 'css' => 'width:80px;', - 'desc' => __( 'Max quantity input', 'write-poetry' ), - 'custom_attributes' => $this->setCustomAttribute( "{$this->prefix}_product_max_quantity" ) + 'id' => "{$this->prefix}_product_max_quantity", + 'type' => 'number', + 'css' => 'width:80px;', + 'desc' => __( 'Max quantity input', 'write-poetry' ), + 'custom_attributes' => $this->setCustomAttribute( "{$this->prefix}_product_max_quantity" ), ); // Add single product minal quantity option $settings_appearance[] = array( - 'id' => "{$this->prefix}_product_min_quantity", - 'type' => 'number', - 'css' => 'width:80px;', - 'desc' => __( 'Min quantity input', 'write-poetry' ), - 'custom_attributes' => $this->setCustomAttribute( "{$this->prefix}_product_min_quantity" ) + 'id' => "{$this->prefix}_product_min_quantity", + 'type' => 'number', + 'css' => 'width:80px;', + 'desc' => __( 'Min quantity input', 'write-poetry' ), + 'custom_attributes' => $this->setCustomAttribute( "{$this->prefix}_product_min_quantity" ), ); - // Add single product checkbox option quantity input steps values $settings_appearance[] = array( - 'desc_tip' => __( 'Adjust the quantity input steps values', 'write-poetry' ), - 'id' => "{$this->prefix}_quantity_input_step", - 'type' => 'number', - 'css' => 'width:80px;', - 'desc' => __( 'Product quantity input steps', 'write-poetry' ), - 'custom_attributes' => $this->setCustomAttribute( "{$this->prefix}_quantity_input_step" ) + 'desc_tip' => __( 'Adjust the quantity input steps values', 'write-poetry' ), + 'id' => "{$this->prefix}_quantity_input_step", + 'type' => 'number', + 'css' => 'width:80px;', + 'desc' => __( 'Product quantity input steps', 'write-poetry' ), + 'custom_attributes' => $this->setCustomAttribute( "{$this->prefix}_quantity_input_step" ), ); - // Add product zoom checkbox option $settings_appearance[] = array( - 'name' => __( 'Zoom behaviour', 'write-poetry' ), - 'desc_tip' => __( 'This will enable or disable product image zoom on single product page', 'write-poetry' ), - 'id' => "{$this->prefix}_product_zoom", - 'type' => 'checkbox', - 'default' => 'yes', - 'value' => get_option( "{$this->prefix}_product_zoom" ), - 'css' => 'min-width:300px;', - 'desc' => __( 'Enable Product Zoom', 'write-poetry' ), - 'custom_attributes' => $this->setCustomAttribute( "{$this->prefix}_product_zoom" ) + 'name' => __( 'Zoom behaviour', 'write-poetry' ), + 'desc_tip' => __( 'This will enable or disable product image zoom on single product page', 'write-poetry' ), + 'id' => "{$this->prefix}_product_zoom", + 'type' => 'checkbox', + 'default' => 'yes', + 'value' => get_option( "{$this->prefix}_product_zoom" ), + 'css' => 'min-width:300px;', + 'desc' => __( 'Enable Product Zoom', 'write-poetry' ), + 'custom_attributes' => $this->setCustomAttribute( "{$this->prefix}_product_zoom" ), ); - - - // Add additional info layout field option $settings_appearance[] = array( - 'name' => __( 'Additional infos layout', 'write-poetry' ), - 'id' => "{$this->prefix}_product_infos_layout", - 'type' => 'select', - 'desc' => __( 'Choose the layout of additional informations box with this option!', 'write-poetry' ), - 'default' => 'tabs', - 'options' => array( - 'tabs' => 'Tabs', - 'list' => 'List', + 'name' => __( 'Additional infos layout', 'write-poetry' ), + 'id' => "{$this->prefix}_product_infos_layout", + 'type' => 'select', + 'desc' => __( 'Choose the layout of additional informations box with this option!', 'write-poetry' ), + 'default' => 'tabs', + 'options' => array( + 'tabs' => 'Tabs', + 'list' => 'List', 'accordion' => 'Accordion', ), // array of options for select/multiselects only - 'custom_attributes' => $this->setCustomAttribute( "{$this->prefix}_product_infos_layout" ) + 'custom_attributes' => $this->setCustomAttribute( "{$this->prefix}_product_infos_layout" ), ); - $settings_appearance[] = array( 'type' => 'sectionend', 'id' => 'appearance' ); + $settings_appearance[] = array( + 'type' => 'sectionend', + 'id' => 'appearance', + ); return $settings_appearance; - /** - * If not, return the standard settings - **/ + /** + * If not, return the standard settings + */ } else { return $settings; } } - } - diff --git a/includes/Pages/AdminController.php b/includes/Pages/AdminController.php index ee4f7e3..36a7d58 100644 --- a/includes/Pages/AdminController.php +++ b/includes/Pages/AdminController.php @@ -12,12 +12,12 @@ namespace WritePoetry\Pages; -use \WritePoetry\Base\BaseController; +use WritePoetry\Base\BaseController; /** -* -*/ + * + */ class AdminController extends BaseController { @@ -58,6 +58,4 @@ public function hasFiltersForOption( $option ) { return false; } - } - diff --git a/includes/Plugins/Gtm4wp.php b/includes/Plugins/Gtm4wp.php index 73861f5..6f0ed5d 100644 --- a/includes/Plugins/Gtm4wp.php +++ b/includes/Plugins/Gtm4wp.php @@ -12,10 +12,9 @@ namespace WritePoetry\Plugins; - /** -* -*/ + * + */ class Gtm4wp { /** * Invoke hooks. @@ -35,8 +34,7 @@ public function register() { * @return void */ public function GTM_noscript_container_code() { - if ( function_exists( 'gtm4wp_the_gtm_tag' ) ) { gtm4wp_the_gtm_tag(); } + if ( function_exists( 'gtm4wp_the_gtm_tag' ) ) { + gtm4wp_the_gtm_tag(); } } - } - diff --git a/includes/Plugins/Jetpack/Portfolio.php b/includes/Plugins/Jetpack/Portfolio.php index de3ed3f..8fb3880 100644 --- a/includes/Plugins/Jetpack/Portfolio.php +++ b/includes/Plugins/Jetpack/Portfolio.php @@ -12,11 +12,11 @@ namespace WritePoetry\Plugins\Jetpack; -use \WritePoetry\Base\BaseController; +use WritePoetry\Base\BaseController; /** -* -*/ + * + */ class Portfolio extends BaseController { /** * Invoke hooks. @@ -40,7 +40,7 @@ public function enqueue_block_assets() { $file_name = 'plugin-jetpack'; // Automatically load imported dependencies and assets version. - $asset_file = include( sprintf( '%s%s%s.asset.php', $this->build_path, DIRECTORY_SEPARATOR, $file_name ) ); + $asset_file = include sprintf( '%s%s%s.asset.php', $this->build_path, DIRECTORY_SEPARATOR, $file_name ); wp_enqueue_script( 'writepoetry-gutenberg-sidebar', @@ -57,51 +57,51 @@ public function register_portfolio_meta() { 'jetpack-portfolio', '_writepoetry_project_year', array( - 'show_in_rest' => true, - 'type' => 'number', - 'single' => true, + 'show_in_rest' => true, + 'type' => 'number', + 'single' => true, 'auth_callback' => function () { return current_user_can( 'edit_posts' ); - } + }, ) ); register_post_meta( 'jetpack-portfolio', '_writepoetry_project_client', - array( - 'show_in_rest' => true, - 'type' => 'string', - 'single' => true, - 'auth_callback' => function () { - return current_user_can( 'edit_posts' ); - } + array( + 'show_in_rest' => true, + 'type' => 'string', + 'single' => true, + 'auth_callback' => function () { + return current_user_can( 'edit_posts' ); + }, ) ); register_post_meta( 'jetpack-portfolio', '_writepoetry_project_expertise', - array( - 'show_in_rest' => true, - 'type' => 'string', - 'single' => true, - 'auth_callback' => function () { - return current_user_can( 'edit_posts' ); - } + array( + 'show_in_rest' => true, + 'type' => 'string', + 'single' => true, + 'auth_callback' => function () { + return current_user_can( 'edit_posts' ); + }, ) ); register_post_meta( 'jetpack-portfolio', '_writepoetry_project_industry', - array( - 'show_in_rest' => true, - 'type' => 'string', - 'single' => true, - 'auth_callback' => function () { - return current_user_can( 'edit_posts' ); - } + array( + 'show_in_rest' => true, + 'type' => 'string', + 'single' => true, + 'auth_callback' => function () { + return current_user_can( 'edit_posts' ); + }, ) ); } @@ -117,9 +117,4 @@ public function add_portfolio_meta_box() { array( '__back_compat_meta_box' => true ) ); } - } - - - - diff --git a/includes/Plugins/WooCommerce/CartRedirect.php b/includes/Plugins/WooCommerce/CartRedirect.php index ce45b34..b77874f 100644 --- a/includes/Plugins/WooCommerce/CartRedirect.php +++ b/includes/Plugins/WooCommerce/CartRedirect.php @@ -12,11 +12,11 @@ namespace WritePoetry\Plugins\WooCommerce; -use \WritePoetry\Base\BaseController; +use WritePoetry\Base\BaseController; /** -* -*/ + * + */ class CartRedirect extends WooCommerceController { /** * Invoke hooks. @@ -29,34 +29,32 @@ public function register() { return false; } - add_filter( 'woocommerce_add_to_cart_redirect', array( $this, 'skip_cart_redirect_checkout' ) ); add_filter( 'woocommerce_product_add_to_cart_text', array( $this, 'product_add_to_cart_text' ), 10, 2 ); add_filter( 'woocommerce_product_single_add_to_cart_text', array( $this, 'product_add_to_cart_text' ), 10, 2 ); add_filter( 'woocommerce_loop_add_to_cart_link', array( $this, 'loop_add_to_cart_link' ) ); add_filter( 'wc_add_to_cart_message_html', array( $this, 'remove_add_to_cart_message' ) ); - } public function skip_cart_redirect_checkout( $url ) { $this->disable_ajax_cart(); if ( 'cart' === get_option( "{$this->prefix}_redirect_after_add" ) ) { - return wc_get_cart_url(); + return wc_get_cart_url(); } return wc_get_checkout_url(); } /** - * Go to checkout page bypassing cart + * Go to checkout page bypassing cart * based on the story of https://rudrastyh.com/woocommerce/redirect-to-checkout-skip-cart.html - * - * @since 0.2.5 - * @access public - * @return viod - */ - public function disable_ajax_cart( ){ + * + * @since 0.2.5 + * @access public + * @return viod + */ + public function disable_ajax_cart() { if ( 'no' === get_option( 'woocommerce_enable_ajax_add_to_cart' ) ) { return; @@ -67,7 +65,7 @@ public function disable_ajax_cart( ){ // define the product_add_to_cart_text callback public function product_add_to_cart_text( $text, $product ) { - return $product->is_purchasable() && $product->is_in_stock() || $product->is_type( 'grouped') ? __( 'Buy now', 'woocommerce' ) : __( 'Read more', 'woocommerce' ); + return $product->is_purchasable() && $product->is_in_stock() || $product->is_type( 'grouped' ) ? __( 'Buy now', 'woocommerce' ) : __( 'Read more', 'woocommerce' ); } @@ -76,8 +74,7 @@ public function loop_add_to_cart_link( $add_to_cart_html ) { } - public function remove_add_to_cart_message( $message ){ + public function remove_add_to_cart_message( $message ) { return ''; } } - diff --git a/includes/Plugins/WooCommerce/ProductAdditionalInfos.php b/includes/Plugins/WooCommerce/ProductAdditionalInfos.php index ed49796..300d668 100644 --- a/includes/Plugins/WooCommerce/ProductAdditionalInfos.php +++ b/includes/Plugins/WooCommerce/ProductAdditionalInfos.php @@ -12,11 +12,11 @@ namespace WritePoetry\Plugins\WooCommerce; -use \WritePoetry\Base\BaseController; +use WritePoetry\Base\BaseController; /** -* -*/ + * + */ class ProductAdditionalInfos extends WooCommerceController { /** * Invoke hooks. @@ -27,50 +27,56 @@ public function register() { // Additional informations if ( 'tabs' === get_option( "{$this->prefix}_product_infos_layout" ) ) { - add_filter( "{$this->prefix}_exclude_woocommerce_template", function( $templates ) { - $templates[] = 'single-product/tabs/tabs.php'; - return $templates; - } ); + add_filter( + "{$this->prefix}_exclude_woocommerce_template", + function ( $templates ) { + $templates[] = 'single-product/tabs/tabs.php'; + return $templates; + } + ); } - if ( 'accordion' === get_option( "{$this->prefix}_product_infos_layout" ) ) { - add_filter( 'wp_enqueue_scripts', function() { - wp_enqueue_script( 'jquery-ui-accordion' ); - wp_add_inline_script( 'jquery-ui-accordion', ' + add_filter( + 'wp_enqueue_scripts', + function () { + wp_enqueue_script( 'jquery-ui-accordion' ); + wp_add_inline_script( + 'jquery-ui-accordion', + ' jQuery( function( $ ) { $( "#accordion" ).accordion(); });' - ); - } ); + ); + } + ); } - } - public function woocommerce_custom_tabs () { - add_filter( 'woocommerce_product_tabs', function( $tabs ) { + public function woocommerce_custom_tabs() { + add_filter( + 'woocommerce_product_tabs', + function ( $tabs ) { - // Remove additional information tab on Product Page - unset( $tabs['reviews'] ); - unset( $tabs['additional_information'] ); + // Remove additional information tab on Product Page + unset( $tabs['reviews'] ); + unset( $tabs['additional_information'] ); + // Insert additional information into description tab on Product Page + $tabs['description']['callback'] = function () { + global $product; + wc_get_template( 'single-product/tabs/description.php' ); - // Insert additional information into description tab on Product Page - $tabs['description']['callback'] = function() { - global $product; - wc_get_template( 'single-product/tabs/description.php' ); + if ( $product && ( $product->has_attributes() || apply_filters( 'wc_product_enable_dimensions_display', $product->has_weight() || $product->has_dimensions() ) ) ) { + wc_get_template( 'single-product/tabs/additional-information.php' ); + } + }; - if ( $product && ( $product->has_attributes() || apply_filters( 'wc_product_enable_dimensions_display', $product->has_weight() || $product->has_dimensions() ) ) ) { - wc_get_template( 'single-product/tabs/additional-information.php' ); - } - }; - - return $tabs; - }, 20 ); + return $tabs; + }, + 20 + ); } - - } - diff --git a/includes/Plugins/WooCommerce/ProductZoom.php b/includes/Plugins/WooCommerce/ProductZoom.php index 0a588c4..7f711ff 100644 --- a/includes/Plugins/WooCommerce/ProductZoom.php +++ b/includes/Plugins/WooCommerce/ProductZoom.php @@ -12,11 +12,11 @@ namespace WritePoetry\Plugins\WooCommerce; -use \WritePoetry\Base\BaseController; +use WritePoetry\Base\BaseController; /** -* -*/ + * + */ class ProductZoom extends WooCommerceController { /** * Invoke hooks. @@ -33,15 +33,21 @@ public function register() { // Disable product zoom public function disable_product_zoom() { - add_action( 'wp', function () { - remove_theme_support( 'wc-product-gallery-zoom' ); - // remove_theme_support( 'wc-product-gallery-lightbox' ); - // remove_theme_support( 'wc-product-gallery-slider' ); - } , 100 ); + add_action( + 'wp', + function () { + remove_theme_support( 'wc-product-gallery-zoom' ); + // remove_theme_support( 'wc-product-gallery-lightbox' ); + // remove_theme_support( 'wc-product-gallery-slider' ); + }, + 100 + ); - add_filter( 'woocommerce_single_product_image_thumbnail_html', function ( $html ) { - return strip_tags( $html, '
' ); - } ); + add_filter( + 'woocommerce_single_product_image_thumbnail_html', + function ( $html ) { + return strip_tags( $html, '
' ); + } + ); } } - diff --git a/includes/Plugins/WooCommerce/QuantityLayout.php b/includes/Plugins/WooCommerce/QuantityLayout.php index cd565b6..b02d08b 100644 --- a/includes/Plugins/WooCommerce/QuantityLayout.php +++ b/includes/Plugins/WooCommerce/QuantityLayout.php @@ -12,11 +12,11 @@ namespace WritePoetry\Plugins\WooCommerce; -use \WritePoetry\Base\BaseController; +use WritePoetry\Base\BaseController; /** -* -*/ + * + */ class QuantityLayout extends WooCommerceController { /** * Invoke hooks. @@ -37,15 +37,16 @@ public function register() { $min_quantity = get_option( "{$this->prefix}_product_min_quantity" ); } - // product quantity selector configurations // this filter prevent to override the `quantity-input.php` template - add_filter( "{$this->prefix}_exclude_woocommerce_template", function( $templates ) { - $templates[] = 'global/quantity-input.php'; - return $templates; - } ); - + add_filter( + "{$this->prefix}_exclude_woocommerce_template", + function ( $templates ) { + $templates[] = 'global/quantity-input.php'; + return $templates; + } + ); if ( 'input' == get_option( "{$this->prefix}_product_quantity_layout" ) ) { return false; @@ -56,7 +57,7 @@ public function register() { $this->change_quantity_input( $min_quantity ); } - if ( 'buttons' === get_option("{$this->prefix}_product_quantity_layout" ) ) { + if ( 'buttons' === get_option( "{$this->prefix}_product_quantity_layout" ) ) { add_action( 'woocommerce_before_quantity_input_field', array( $this, 'display_quantity_minus' ) ); add_action( 'woocommerce_after_quantity_input_field', array( $this, 'display_quantity_plus' ) ); add_action( 'wp_footer', array( $this, 'add_cart_quantity_plus_minus' ) ); @@ -65,25 +66,30 @@ public function register() { } - if ( 'select' === get_option("{$this->prefix}_product_quantity_layout" ) ) { + if ( 'select' === get_option( "{$this->prefix}_product_quantity_layout" ) ) { $this->change_quantity_input( $max_quantity, $min_quantity ); - // this readd quantity input to the filter - add_filter( "{$this->prefix}_exclude_woocommerce_template", function( $templates ) { - return array_filter( $templates, fn($template) => strpos( $template, 'global/quantity-input.php' ) === false ); - } ); - + add_filter( + "{$this->prefix}_exclude_woocommerce_template", + function ( $templates ) { + return array_filter( $templates, fn( $template ) => strpos( $template, 'global/quantity-input.php' ) === false ); + } + ); } // product quantity input configurations if ( get_option( "{$this->prefix}_quantity_input_step" ) ) { - add_filter( 'woocommerce_quantity_input_step', function ( $step, $product ) { - return get_option( "{$this->prefix}_quantity_input_step" ); - }, 10, 2 ); + add_filter( + 'woocommerce_quantity_input_step', + function ( $step, $product ) { + return get_option( "{$this->prefix}_quantity_input_step" ); + }, + 10, + 2 + ); } - } @@ -118,7 +124,8 @@ function add_cart_quantity_plus_minus() { return false; } - wc_enqueue_js( " + wc_enqueue_js( + " $(document).on( 'click', 'button.quantity__plus, button.quantity__minus', function() { @@ -149,11 +156,12 @@ function add_cart_quantity_plus_minus() { }); - " ); - + " + ); - - wp_add_inline_style( 'woocommerce-blocktheme', ' + wp_add_inline_style( + 'woocommerce-blocktheme', + ' /* Works for Chrome, Safari, Edge, Opera */ input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { @@ -165,8 +173,7 @@ function add_cart_quantity_plus_minus() { input[type="number"] { -moz-appearance: textfield; } - '); + ' + ); } - } - diff --git a/includes/Plugins/WooCommerce/WooCommerceController.php b/includes/Plugins/WooCommerce/WooCommerceController.php index 8a404c3..4c1bef0 100644 --- a/includes/Plugins/WooCommerce/WooCommerceController.php +++ b/includes/Plugins/WooCommerce/WooCommerceController.php @@ -12,11 +12,11 @@ namespace WritePoetry\Plugins\WooCommerce; -use \WritePoetry\Base\BaseController; +use WritePoetry\Base\BaseController; /** -* -*/ + * + */ class WooCommerceController extends BaseController { @@ -29,24 +29,34 @@ public function __construct() { // Disable quantity selector for product and product variation public function change_quantity_input( $max_qty, $min_qty = null ) { - add_filter( 'woocommerce_quantity_input_args', function ( $args, $product ) use ( $max_qty, $min_qty ) { - $args['max_value'] = $max_qty; + add_filter( + 'woocommerce_quantity_input_args', + function ( $args, $product ) use ( $max_qty, $min_qty ) { + $args['max_value'] = $max_qty; + + if ( $min_qty ) { + $args['min_value'] = $min_qty; + } + return $args; + }, + 10, + 2 + ); - if ( $min_qty ) { - $args['min_value'] = $min_qty; - } - return $args; - }, 10, 2 ); + add_filter( + 'woocommerce_available_variation', + function ( $data, $product, $variation ) use ( $max_qty, $min_qty ) { + $data['max_qty'] = $max_qty; - add_filter( 'woocommerce_available_variation', function ( $data, $product, $variation ) use ($max_qty, $min_qty ) { - $data['max_qty'] = $max_qty; + if ( $min_qty ) { + $data['min_qty'] = $min_qty; + } - if ( $min_qty ) { - $data['min_qty'] = $min_qty; - } - - return $data; - }, 10, 3 ); + return $data; + }, + 10, + 3 + ); } // https://wisdmlabs.com/blog/override-woocommerce-templates-plugin/ @@ -58,7 +68,7 @@ public function addon_plugin_template( $template, $template_name, $template_path $template_path = $woocommerce->template_url; } - $plugin_path = untrailingslashit( $this->plugin_path ) . '/woocommerce/'; + $plugin_path = untrailingslashit( $this->plugin_path ) . '/woocommerce/'; // Apply filter to exclude specific template $excluded_templates = apply_filters( "{$this->prefix}_exclude_woocommerce_template", array() ); @@ -73,12 +83,11 @@ public function addon_plugin_template( $template, $template_name, $template_path $template = locate_template( array( $template_path . $template_name, - $template_name + $template_name, ) ); - - if( ! $template && file_exists( $plugin_path . $template_name ) ) { + if ( ! $template && file_exists( $plugin_path . $template_name ) ) { $template = $plugin_path . $template_name; } @@ -89,4 +98,3 @@ public function addon_plugin_template( $template, $template_name, $template_path return $template; } } - diff --git a/mu-plugins/project-custom-functions.php b/mu-plugins/project-custom-functions.php index fc9bc25..3693063 100644 --- a/mu-plugins/project-custom-functions.php +++ b/mu-plugins/project-custom-functions.php @@ -30,149 +30,184 @@ add_filter( 'writepoetry_remove_query_strings', '__return_true' ); // Enable maintenance mode -add_filter( 'pre_option_writepoetry_maintenance_mode', function ( $default ) { - return 0; -} ); +add_filter( + 'pre_option_writepoetry_maintenance_mode', + function ( $default ) { + return 0; + } +); // Exclude specific pages from being in maintenance mode -add_filter( 'writepoetry_maintenance_excluded_pages', function ( $condition ) { - $condition[''] = 'cart'; - return $condition; -} ); +add_filter( + 'writepoetry_maintenance_excluded_pages', + function ( $condition ) { + $condition[''] = 'cart'; + return $condition; + } +); // Choose to enable or disable product image zoom on product page (to disable change 'yes' to 'no') -add_filter( 'pre_option_writepoetry_product_zoom', function ( $default ) { - return 'yes'; -} ); - - -add_filter( 'pre_option_writepoetry_product_quantity_layout', function ( $default ) { - // 'hidden'; - // 'input'; - // 'buttons'; - // 'select'; - return 'buttons'; -} ); +add_filter( + 'pre_option_writepoetry_product_zoom', + function ( $default ) { + return 'yes'; + } +); + + +add_filter( + 'pre_option_writepoetry_product_quantity_layout', + function ( $default ) { + // 'hidden'; + // 'input'; + // 'buttons'; + // 'select'; + return 'buttons'; + } +); // Choose to what page redirect after add to cart -add_filter( 'pre_option_writepoetry_redirect_after_add', function ( $default ) { - // 'product-checkout'; - // 'product-cart'; - // 'checkout'; - // 'cart'; - return 'checkout'; -} ); - - -add_filter( 'pre_option_writepoetry_product_min_quantity', function ( $default ) { - return 2; -} ); - - -add_filter( 'pre_option_writepoetry_product_max_quantity', function ( $default ) { - return 20; -} ); +add_filter( + 'pre_option_writepoetry_redirect_after_add', + function ( $default ) { + // 'product-checkout'; + // 'product-cart'; + // 'checkout'; + // 'cart'; + return 'checkout'; + } +); + + +add_filter( + 'pre_option_writepoetry_product_min_quantity', + function ( $default ) { + return 2; + } +); + + +add_filter( + 'pre_option_writepoetry_product_max_quantity', + function ( $default ) { + return 20; + } +); // What kind of design do you want for single product page additional info (possible vaules are accordion, tabs or list) -add_filter( 'pre_option_writepoetry_product_infos_layout', function ( $default ) { - // 'tabs' - // 'list' - // 'accordion' - return 'list'; -} ); +add_filter( + 'pre_option_writepoetry_product_infos_layout', + function ( $default ) { + // 'tabs' + // 'list' + // 'accordion' + return 'list'; + } +); -add_filter( 'pre_option_writepoetry_quantity_input_step', function ( $default ) { - return 5; -} ); +add_filter( + 'pre_option_writepoetry_quantity_input_step', + function ( $default ) { + return 5; + } +); // Disable elements -add_filter( 'writepoetry_disable_features', function ( $args ) { - $args[] = 'woocommerce_sale_flash'; - // $args[] = 'woocommerce_twenty_twenty_two_styles'; +add_filter( + 'writepoetry_disable_features', + function ( $args ) { + $args[] = 'woocommerce_sale_flash'; + // $args[] = 'woocommerce_twenty_twenty_two_styles'; - return $args; -}, 10, 1 ); + return $args; + }, + 10, + 1 +); // Add parameters to url -add_filter( 'writepoetry_query_vars', function () { - // Test here http://localhost:8888/sample-page/?test-param=ciao&test-param2=caro - return array( 'test-param', 'test-param2' ); -} ); - - - -add_filter( 'writepoetry_add_custom_taxonomies', function () { - $string = array( - 'product-type' => array( - 'post_type' => 'product', - 'labels' => array( - 'name' => esc_html( 'Product Type' ) +add_filter( + 'writepoetry_query_vars', + function () { + // Test here http://localhost:8888/sample-page/?test-param=ciao&test-param2=caro + return array( 'test-param', 'test-param2' ); + } +); + + + +add_filter( + 'writepoetry_add_custom_taxonomies', + function () { + $string = array( + 'product-type' => array( + 'post_type' => 'product', + 'labels' => array( + 'name' => esc_html( 'Product Type' ), + ), + 'show_ui' => true, + // 'show_admin_column' => true, + 'show_in_nav_menus' => true, + 'show_tagcloud' => true, ), - 'show_ui' => true, - // 'show_admin_column' => true, - 'show_in_nav_menus' => true, - 'show_tagcloud' => true - ), - 'product-format' => array( - 'post_type' => 'product', - 'labels' => array( - 'name' => esc_html( 'Product Format' ) + 'product-format' => array( + 'post_type' => 'product', + 'labels' => array( + 'name' => esc_html( 'Product Format' ), + ), + 'show_ui' => true, + 'show_tagcloud' => true, ), - 'show_ui' => true, - 'show_tagcloud' => true - ), - ); + ); - return $string; -}, 10, 3 ); + return $string; + }, + 10, + 3 +); -add_filter( 'writepoetry_add_custom_post_types', function () { - $string = array( - 'come-raggiungerci' => - array( - 'labels' => array( - 'name' => esc_html( 'Come Raggiungerci' ), - 'singular_name' => esc_html( 'Come Raggiungerci' ) +add_filter( + 'writepoetry_add_custom_post_types', + function () { + $string = array( + 'come-raggiungerci' => + array( + 'labels' => array( + 'name' => esc_html( 'Come Raggiungerci' ), + 'singular_name' => esc_html( 'Come Raggiungerci' ), + ), + 'publicly_queryable' => true, ), - 'publicly_queryable' => true, - ), - 'punti_di_interesse' => - array( - 'labels' => array( - 'name' => esc_html( 'Napoli e Dintorni' ), - 'singular_name' => esc_html( 'Napoli e Dintorni' ) - ) - ), - - 'escursioni' => - array( - 'labels' => array( - 'name' => 'Transfer ed Escursioni', - 'singular_name' => 'Escursione' + 'punti_di_interesse' => + array( + 'labels' => array( + 'name' => esc_html( 'Napoli e Dintorni' ), + 'singular_name' => esc_html( 'Napoli e Dintorni' ), + ), ), - 'publicly_queryable' => true, - ) - ); - - return $string; -}, 10, 3 ); - - - - - - - - + 'escursioni' => + array( + 'labels' => array( + 'name' => 'Transfer ed Escursioni', + 'singular_name' => 'Escursione', + ), + 'publicly_queryable' => true, + ), + ); + return $string; + }, + 10, + 3 +); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 483263d..ef3bd9d 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -23,7 +23,7 @@ * Manually load the plugin being tested. */ function _manually_load_plugin() { - require dirname( dirname( __FILE__ ) ) . '/sample-plugin.php'; + require dirname( __DIR__ ) . '/sample-plugin.php'; } tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); diff --git a/themes/twentytwenty-child/functions.php b/themes/twentytwenty-child/functions.php index 0e7f4bd..6d8e539 100644 --- a/themes/twentytwenty-child/functions.php +++ b/themes/twentytwenty-child/functions.php @@ -9,7 +9,7 @@ // Use this filter to change the default path for additional blocks styles. // add_filter( 'writepoetry_blocks_styles_asset_path', function () { -// return 'assets/block'; +// return 'assets/block'; // } ); @@ -20,49 +20,51 @@ // some particular mime type added by this plugin // add_filter( 'upload_mimes', function( $mimes ) { -// // Optional. Remove a mime type. -// unset( $mimes['exe'] ); -// unset( $mimes['svg'] ); -// unset( $mimes['svgz'] ); +// Optional. Remove a mime type. +// unset( $mimes['exe'] ); +// unset( $mimes['svg'] ); +// unset( $mimes['svgz'] ); -// return $mimes; +// return $mimes; // } ); // add_filter( 'mime_types', function( $wp_get_mime_types ) { -// // Optional. Remove a mime type. -// unset( $wp_get_mime_types['exe'] ); -// unset( $wp_get_mime_types['svg'] ); -// unset( $wp_get_mime_types['svgz'] ); +// Optional. Remove a mime type. +// unset( $wp_get_mime_types['exe'] ); +// unset( $wp_get_mime_types['svg'] ); +// unset( $wp_get_mime_types['svgz'] ); -// return $wp_get_mime_types; +// return $wp_get_mime_types; // } ); -add_filter( 'writepoetry_register_block_style', function () { - // Define block styles with their labels and CSS styles - $block_styles = array( - 'core/group' => array( - 'name' => 'inline', - 'label' => __( 'Inline', 'twenties' ), - // 'is_default' => true, - 'inline_style' => '.wp-block-group.is-style-inline { display: inline-flex; }' - ), - 'core/cover' => array( - array( - 'name' => 'inline1', - 'label' => __( 'Inline1', 'twenties' ), - // 'is_default' => true, - 'inline_style' => ' .is-style-inline1 { display: block; }' +add_filter( + 'writepoetry_register_block_style', + function () { + // Define block styles with their labels and CSS styles + $block_styles = array( + 'core/group' => array( + 'name' => 'inline', + 'label' => __( 'Inline', 'twenties' ), + // 'is_default' => true, + 'inline_style' => '.wp-block-group.is-style-inline { display: inline-flex; }', ), - array( - 'name' => 'inline2', - 'label' => __( 'Inline2', 'twenties' ), - // 'is_default' => true, - 'inline_style' => ' .is-style-inline2 { display: inline-flex; }' - ) - ) - ); - - return $block_styles; + 'core/cover' => array( + array( + 'name' => 'inline1', + 'label' => __( 'Inline1', 'twenties' ), + // 'is_default' => true, + 'inline_style' => ' .is-style-inline1 { display: block; }', + ), + array( + 'name' => 'inline2', + 'label' => __( 'Inline2', 'twenties' ), + // 'is_default' => true, + 'inline_style' => ' .is-style-inline2 { display: inline-flex; }', + ), + ), + ); -} ); + return $block_styles; + } +); diff --git a/themes/twentytwenty-child/home-old.php b/themes/twentytwenty-child/home-old.php index a2f3cd6..f3b7f36 100644 --- a/themes/twentytwenty-child/home-old.php +++ b/themes/twentytwenty-child/home-old.php @@ -1 +1 @@ -= 1 && $i == $input_value ) ? 'selected' : ''; - $options .= ''; + for ( $i = $min_value; $i <= $max_value; $i += $step ) : + $selected = ( '' !== $input_value && $input_value >= 1 && $i == $input_value ) ? 'selected' : ''; + $options .= ''; endfor; // Change input name on select field diff --git a/write-poetry.php b/write-poetry.php index cffc638..a0f58f1 100644 --- a/write-poetry.php +++ b/write-poetry.php @@ -29,28 +29,35 @@ if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { - require __DIR__ . '/vendor/autoload.php'; + require __DIR__ . '/vendor/autoload.php'; } /** * The code that runs during plugin activation */ -register_activation_hook( __FILE__, function() { - WritePoetry\Base\Activate::activate(); -} ); +register_activation_hook( + __FILE__, + function () { + WritePoetry\Base\Activate::activate(); + } +); /** * The code that runs during plugin deactivation */ -register_deactivation_hook( __FILE__, function() { - WritePoetry\Base\Deactivate::deactivate(); -} ); +register_deactivation_hook( + __FILE__, + function () { + WritePoetry\Base\Deactivate::deactivate(); + } +); /** * Initialize all the core classes of the plugin + * * @since 0.2.2 */ if ( class_exists( 'WritePoetry\\Init' ) ) { From 8fa668d1963cf57f2e280ec4b465393779f261f9 Mon Sep 17 00:00:00 2001 From: Giacomo Secchi Date: Sun, 4 Feb 2024 09:41:37 +0100 Subject: [PATCH 11/14] Add suggestions for commit messages --- CONTRIBUTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 26e8f7f..011dbb6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,6 +13,8 @@ Some hints [here](https://www.git-tower.com/learn/git/faq/change-author-name-ema Commit all your changes in your own branch. Before making any code change, start a new Git branch where all your changes will be made. +### Suggestions for commit messages +Read here for some guidelines on [writing better commit messages](https://www.freecodecamp.org/news/how-to-write-better-git-commit-messages/). ## Coding Standard From a568071444787782f5bc510dae41aff6a359a961 Mon Sep 17 00:00:00 2001 From: Giacomo Secchi Date: Sun, 4 Feb 2024 10:26:34 +0100 Subject: [PATCH 12/14] Add autoload.php file and delete plugin options in uninstall.php --- uninstall.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/uninstall.php b/uninstall.php index 1c716b0..78fdace 100644 --- a/uninstall.php +++ b/uninstall.php @@ -10,12 +10,16 @@ die; } +if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { + require __DIR__ . '/vendor/autoload.php'; +} use \WritePoetry\Api\PluginConfig; $config = PluginConfig::getInstance(); $all_options = wp_load_alloptions(); +// Delete all plugin options in wp_otions table foreach ( $all_options as $option_name => $option_value ) { if ( stristr( $option_name, $config->prefix ) ) { delete_option( $option_name ); From 3432f76a32fd075b26a7fea588bbdd9ac133d13d Mon Sep 17 00:00:00 2001 From: Giacomo Secchi Date: Mon, 5 Feb 2024 22:03:36 +0100 Subject: [PATCH 13/14] Refactor uninstall.php file --- CONTRIBUTING.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 011dbb6..cd4fb7b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,6 +25,12 @@ Run the following command from the root directory to check the code for "sniffs" ```bash npm run composer run-script check-cs ``` +Run PHP Code Beautifier and Fixer script to automatically correct coding standard violations. + +```bash +npm run composer run-script fix-cs +``` + If you were unable to install the Docker program, as an alternative, you can [install composer the traditional way](https://getcomposer.org/download/) and run this command to check for "sniffs". @@ -32,7 +38,11 @@ If you were unable to install the Docker program, as an alternative, you can [in vendor/bin/phpcs -ps ``` +and this command to fix them. +```bash +php vendor/bin/phpcbf +``` ## Creating a stable release From 1643ec6670510377b8e23eacd1d6fe91d7040aaf Mon Sep 17 00:00:00 2001 From: Giacomo Secchi Date: Mon, 5 Feb 2024 22:04:13 +0100 Subject: [PATCH 14/14] Refactor uninstall.php file --- uninstall.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/uninstall.php b/uninstall.php index 78fdace..df33e6c 100644 --- a/uninstall.php +++ b/uninstall.php @@ -1,22 +1,21 @@