From 312518fd808d6039cecf2fa85439ad477ab4685a Mon Sep 17 00:00:00 2001 From: codepuncher Date: Mon, 6 Jan 2025 17:49:05 +0000 Subject: [PATCH] initial commit --- .github/workflows/ci.yml | 17 +- .gitignore | 1 + composer.json | 33 +- composer.lock | 406 ++++++++++++++++++++++++- public/js/gf-giftaid-field-frontend.js | 4 +- src/GiftAidField.php | 185 +++++++++-- 6 files changed, 606 insertions(+), 40 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7aaaf37..91e86b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,7 @@ +# yamllint disable-line rule:document-start name: CI +# yamllint disable-line rule:truthy on: [push] jobs: @@ -9,29 +11,38 @@ jobs: if: "!contains(github.event.head_commit.message, '[ci skip]')" strategy: matrix: - php: ['8.1'] + php: ['8.1', '8.2'] steps: - name: Checkout the project - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup the PHP ${{ matrix.php }} environment on ${{ runner.os }} uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} coverage: xdebug + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Restore the Composer cache directory id: composer-cache run: echo "dir=$(composer config cache-files-dir)" >> "${GITHUB_OUTPUT}" - - uses: actions/cache@v3 + - name: Cache dependencies + uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} + # yamllint disable-line rule:line-length key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} restore-keys: ${{ runner.os }}-${{ matrix.php }}-composer- + - name: Setup Composer Private Packagist authentication + # yamllint disable-line rule:line-length + run: composer config --global --auth http-basic.repo.packagist.com itineris ${{ secrets.PRIVATE_PACKAGIST_TOKEN }} + - name: Install Composer dependencies + # yamllint disable-line rule:line-length run: composer install --no-progress --prefer-dist --optimize-autoloader --no-suggest - name: Execute the PHP lint script diff --git a/.gitignore b/.gitignore index 4b0bb40..226ab24 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ vendor/ .idea/ .vscode/ +wordpress/ diff --git a/composer.json b/composer.json index 3069ac1..6849049 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,11 @@ "name": "Igor Tkachenko", "email": "igor.tkachenko@itineris.co.uk", "role": "Developer" + }, + { + "name": "Lee Hanbury-Pickett", + "email": "lee.hanbury-pickett@itineris.co.uk", + "role": "Developer" } ], "require": { @@ -37,7 +42,10 @@ }, "require-dev": { "roave/security-advisories": "dev-master", - "itinerisltd/itineris-wp-coding-standards": "^1.0" + "itinerisltd/itineris-wp-coding-standards": "^1.0", + "itinerisltd/gravityforms": "^2.9", + "roots/wordpress-no-content": "^6.7", + "roots/wordpress": "^6.7" }, "extra": { "branch-alias": { @@ -52,7 +60,28 @@ }, "config": { "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "composer/installers": true, + "roots/wordpress-core-installer": true + } + }, + "repositories": { + "private-packagist": { + "type": "composer", + "url": "https://repo.packagist.com/itinerisltd/" + } + }, + "extra": { + "installer-paths": { + "wordpress/wp-content/mu-plugins/{$name}/": [ + "type:wordpress-muplugin" + ], + "wordpress/wp-content/plugins/{$name}/": [ + "type:wordpress-plugin" + ], + "wordpress/wp-content/themes/{$name}/": [ + "type:wordpress-theme" + ] } } } diff --git a/composer.lock b/composer.lock index e020c21..ef03975 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,166 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "851f4f7bf0be0afeb1a6f2c2bdd67130", + "content-hash": "317a1680a6dc349cd26f37016a16f3db", "packages": [], "packages-dev": [ + { + "name": "composer/installers", + "version": "v1.12.0", + "source": { + "type": "git", + "url": "https://github.com/composer/installers.git", + "reference": "d20a64ed3c94748397ff5973488761b22f6d3f19" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/installers/zipball/d20a64ed3c94748397ff5973488761b22f6d3f19", + "reference": "d20a64ed3c94748397ff5973488761b22f6d3f19", + "shasum": "", + "mirrors": [ + { + "url": "https://repo.packagist.com/itinerisltd/dists/%package%/%version%/r%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0" + }, + "replace": { + "roundcube/plugin-installer": "*", + "shama/baton": "*" + }, + "require-dev": { + "composer/composer": "1.6.* || ^2.0", + "composer/semver": "^1 || ^3", + "phpstan/phpstan": "^0.12.55", + "phpstan/phpstan-phpunit": "^0.12.16", + "symfony/phpunit-bridge": "^4.2 || ^5", + "symfony/process": "^2.3" + }, + "type": "composer-plugin", + "extra": { + "class": "Composer\\Installers\\Plugin", + "branch-alias": { + "dev-main": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Installers\\": "src/Composer/Installers" + } + }, + "notification-url": "https://repo.packagist.com/itinerisltd/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kyle Robinson Young", + "email": "kyle@dontkry.com", + "homepage": "https://github.com/shama" + } + ], + "description": "A multi-framework Composer library installer", + "homepage": "https://composer.github.io/installers/", + "keywords": [ + "Craft", + "Dolibarr", + "Eliasis", + "Hurad", + "ImageCMS", + "Kanboard", + "Lan Management System", + "MODX Evo", + "MantisBT", + "Mautic", + "Maya", + "OXID", + "Plentymarkets", + "Porto", + "RadPHP", + "SMF", + "Starbug", + "Thelia", + "Whmcs", + "WolfCMS", + "agl", + "aimeos", + "annotatecms", + "attogram", + "bitrix", + "cakephp", + "chef", + "cockpit", + "codeigniter", + "concrete5", + "croogo", + "dokuwiki", + "drupal", + "eZ Platform", + "elgg", + "expressionengine", + "fuelphp", + "grav", + "installer", + "itop", + "joomla", + "known", + "kohana", + "laravel", + "lavalite", + "lithium", + "magento", + "majima", + "mako", + "mediawiki", + "miaoxing", + "modulework", + "modx", + "moodle", + "osclass", + "pantheon", + "phpbb", + "piwik", + "ppi", + "processwire", + "puppet", + "pxcms", + "reindex", + "roundcube", + "shopware", + "silverstripe", + "sydes", + "sylius", + "symfony", + "tastyigniter", + "typo3", + "wordpress", + "yawik", + "zend", + "zikula" + ], + "support": { + "issues": "https://github.com/composer/installers/issues", + "source": "https://github.com/composer/installers/tree/v1.12.0" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2021-09-13T08:19:44+00:00" + }, { "name": "dealerdirect/phpcodesniffer-composer-installer", "version": "v1.0.0", @@ -85,6 +242,49 @@ }, "time": "2023-01-05T11:28:13+00:00" }, + { + "name": "itinerisltd/gravityforms", + "version": "2.9.1.3", + "source": { + "type": "git", + "url": "git@github.com:ItinerisLtd/gravityforms.git", + "reference": "6909b4c4ea87cea4bb56966e2476741c64728caa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ItinerisLtd/gravityforms/zipball/6909b4c4ea87cea4bb56966e2476741c64728caa", + "reference": "6909b4c4ea87cea4bb56966e2476741c64728caa", + "shasum": "", + "mirrors": [ + { + "url": "https://repo.packagist.com/itinerisltd/dists/%package%/%version%/r%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "composer/installers": "^1.6" + }, + "type": "wordpress-plugin", + "extra": { + "composify": { + "zip": "https://composify-go-get-private-4ouwv.kinsta.app/gravityforms/gravityforms", + "file": "gravityforms.php", + "version": "2.9.1.3", + "build-at": "2025-01-03T00:01:03.555Z" + } + }, + "notification-url": "https://repo.packagist.com/itinerisltd/downloads/", + "license": [ + "GPL-2.0+" + ], + "description": "Easily create web forms and manage form entries within the WordPress admin.", + "support": { + "source": "https://github.com/ItinerisLtd/gravityforms/tree/2.9.1.3", + "issues": "https://github.com/ItinerisLtd/gravityforms/issues" + }, + "time": "2025-01-03T00:01:03+00:00" + }, { "name": "itinerisltd/itineris-wp-coding-standards", "version": "1.0.0", @@ -797,6 +997,208 @@ ], "time": "2023-04-13T17:04:11+00:00" }, + { + "name": "roots/wordpress", + "version": "6.7.1", + "source": { + "type": "git", + "url": "https://github.com/roots/wordpress.git", + "reference": "9451af491af7124c12186398c56ab87a6e145123" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/roots/wordpress/zipball/9451af491af7124c12186398c56ab87a6e145123", + "reference": "9451af491af7124c12186398c56ab87a6e145123", + "shasum": "", + "mirrors": [ + { + "url": "https://repo.packagist.com/itinerisltd/dists/%package%/%version%/r%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "roots/wordpress-core-installer": "^1.0.0", + "roots/wordpress-no-content": "self.version" + }, + "type": "metapackage", + "notification-url": "https://repo.packagist.com/itinerisltd/downloads/", + "license": [ + "MIT", + "GPL-2.0-or-later" + ], + "description": "WordPress is open source software you can use to create a beautiful website, blog, or app.", + "homepage": "https://wordpress.org/", + "keywords": [ + "blog", + "cms", + "wordpress" + ], + "support": { + "issues": "https://github.com/roots/wordpress/issues", + "source": "https://github.com/roots/wordpress/tree/6.7.1" + }, + "funding": [ + { + "url": "https://github.com/roots", + "type": "github" + } + ], + "time": "2024-11-13T09:56:09+00:00" + }, + { + "name": "roots/wordpress-core-installer", + "version": "1.100.0", + "source": { + "type": "git", + "url": "https://github.com/roots/wordpress-core-installer.git", + "reference": "73f8488e5178c5d54234b919f823a9095e2b1847" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/roots/wordpress-core-installer/zipball/73f8488e5178c5d54234b919f823a9095e2b1847", + "reference": "73f8488e5178c5d54234b919f823a9095e2b1847", + "shasum": "", + "mirrors": [ + { + "url": "https://repo.packagist.com/itinerisltd/dists/%package%/%version%/r%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.6.0" + }, + "conflict": { + "composer/installers": "<1.0.6" + }, + "replace": { + "johnpbloch/wordpress-core-installer": "*" + }, + "require-dev": { + "composer/composer": "^1.0 || ^2.0", + "phpunit/phpunit": ">=5.7.27" + }, + "type": "composer-plugin", + "extra": { + "class": "Roots\\Composer\\WordPressCorePlugin" + }, + "autoload": { + "psr-4": { + "Roots\\Composer\\": "src/" + } + }, + "notification-url": "https://repo.packagist.com/itinerisltd/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "John P. Bloch", + "email": "me@johnpbloch.com" + }, + { + "name": "Roots", + "email": "team@roots.io" + } + ], + "description": "A custom installer to handle deploying WordPress with composer", + "keywords": [ + "wordpress" + ], + "support": { + "issues": "https://github.com/roots/wordpress-core-installer/issues", + "source": "https://github.com/roots/wordpress-core-installer/tree/master" + }, + "funding": [ + { + "url": "https://github.com/roots", + "type": "github" + }, + { + "url": "https://www.patreon.com/rootsdev", + "type": "patreon" + } + ], + "time": "2020-08-20T00:27:30+00:00" + }, + { + "name": "roots/wordpress-no-content", + "version": "6.7.1", + "source": { + "type": "git", + "url": "https://github.com/WordPress/WordPress.git", + "reference": "6.7.1" + }, + "dist": { + "type": "zip", + "url": "https://downloads.wordpress.org/release/wordpress-6.7.1-no-content.zip", + "shasum": "321a5b819369e772ce606fbc12b1e264fb73da5b", + "mirrors": [ + { + "url": "https://repo.packagist.com/itinerisltd/dists/%package%/%version%/r%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "php": ">= 7.2.24" + }, + "provide": { + "wordpress/core-implementation": "6.7.1" + }, + "suggest": { + "ext-curl": "Performs remote request operations.", + "ext-dom": "Used to validate Text Widget content and to automatically configuring IIS7+.", + "ext-exif": "Works with metadata stored in images.", + "ext-fileinfo": "Used to detect mimetype of file uploads.", + "ext-hash": "Used for hashing, including passwords and update packages.", + "ext-imagick": "Provides better image quality for media uploads.", + "ext-json": "Used for communications with other servers.", + "ext-libsodium": "Validates Signatures and provides securely random bytes.", + "ext-mbstring": "Used to properly handle UTF8 text.", + "ext-mysqli": "Connects to MySQL for database interactions.", + "ext-openssl": "Permits SSL-based connections to other hosts.", + "ext-pcre": "Increases performance of pattern matching in code searches.", + "ext-xml": "Used for XML parsing, such as from a third-party site.", + "ext-zip": "Used for decompressing Plugins, Themes, and WordPress update packages." + }, + "type": "wordpress-core", + "notification-url": "https://repo.packagist.com/itinerisltd/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "WordPress Community", + "homepage": "https://wordpress.org/about/" + } + ], + "description": "WordPress is open source software you can use to create a beautiful website, blog, or app.", + "homepage": "https://wordpress.org/", + "keywords": [ + "blog", + "cms", + "wordpress" + ], + "support": { + "docs": "https://developer.wordpress.org/", + "forum": "https://wordpress.org/support/", + "irc": "irc://irc.freenode.net/wordpress", + "issues": "https://core.trac.wordpress.org/", + "rss": "https://wordpress.org/news/feed/", + "source": "https://core.trac.wordpress.org/browser", + "wiki": "https://codex.wordpress.org/" + }, + "funding": [ + { + "url": "https://wordpressfoundation.org/donate/", + "type": "other" + } + ], + "time": "2024-11-21T14:15:19+00:00" + }, { "name": "slevomat/coding-standard", "version": "8.10.0", @@ -982,5 +1384,5 @@ "php": "^8.1" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/public/js/gf-giftaid-field-frontend.js b/public/js/gf-giftaid-field-frontend.js index b2b6aac..df7f386 100644 --- a/public/js/gf-giftaid-field-frontend.js +++ b/public/js/gf-giftaid-field-frontend.js @@ -16,7 +16,7 @@ function initGiftAid(_, form_id) { } window.gform.addAction( 'gform_input_change', - function (elem) { + function(elem) { if ( !(elem instanceof HTMLInputElement) || !elem.closest(totalSelector) || @@ -49,7 +49,7 @@ function initGiftAid(_, form_id) { * @returns {string} The class of the total field. */ function totalFieldSelector(gravityForm, fallback) { - const giftAidComponent = gravityForm.querySelector('.gift-box-wrapper'); + const giftAidComponent = gravityForm.querySelector('.ginput_container_giftaid'); if (!(giftAidComponent instanceof HTMLElement)) { return fallback; } diff --git a/src/GiftAidField.php b/src/GiftAidField.php index 376785b..2c92771 100644 --- a/src/GiftAidField.php +++ b/src/GiftAidField.php @@ -5,6 +5,7 @@ namespace Itineris\GfGiftaidField; use GF_Field; +use GFFormsModel; class GiftAidField extends GF_Field { @@ -41,6 +42,8 @@ public function get_form_editor_field_settings(): array return [ 'selected_price_field_setting', 'label_setting', + 'label_placement_setting', + 'admin_label_setting', 'description_setting', 'rules_setting', 'error_message_setting', @@ -50,11 +53,6 @@ public function get_form_editor_field_settings(): array ]; } - public function is_value_submission_array(): bool - { - return true; - } - /** * @param array $form * @param string|array $value @@ -65,51 +63,71 @@ public function is_value_submission_array(): bool public function get_field_input($form, $value = '', $entry = null): string { $id = (int) $this->id; - $is_form_editor = $this->is_form_editor(); + $is_form_editor = $this->is_form_editor(); + $target_input_id = $this->get_first_input_id($form); + $extra_describedby_ids = []; + if (! empty($this->description)) { + $extra_describedby_ids = ["gfield_giftaid_description_{$form['id']}_{$this->id}"]; + } + $aria_describedby = $this->get_aria_describedby($extra_describedby_ids); + $giftaidImage = plugins_url('public/img/giftaid.svg', __DIR__); $selectedPriceField = $this->selectedPriceField ?? ''; ob_start(); ?>
- data-selected-price-field-id="" + data-selected-price-field-id="" > - + description) && $this->is_description_above($form)) : ?> + + get_description($this->description, 'gfield_description'); ?> + +
get_calculated_gift())); ?>
-
-
-
-
- - - - > - -
-
-
+
+ + + + + disabled="disabled" + + get_tabindex()); ?> + + + + + > +
-
description); ?>
+ description) && ! $this->is_description_above($form)) : ?> + + get_description($this->description, 'gfield_description'); ?> +
isValueYes($value)) { + return esc_html__('Yes', 'itineris-gf-giftaid-field'); + } + + return esc_html__('No', 'itineris-gf-giftaid-field'); + } + + /** + * @phpcs:disable Generic.Files.LineLength.TooLong + * + * @param string|array $value The field value. + * @param string $currency The entry currency code. + * @param bool $use_text When processing choice based fields should the choice text be returned instead of the value. + * @param string $format The format requested for the location the merge is being used. Possible values: html, text or url. + * @param string $media The location where the value will be displayed. Possible values: screen or email. + * + * @return string + */ + public function get_value_entry_detail($value, $currency = '', $use_text = false, $format = 'html', $media = 'screen'): string + { + // phpcs:enable Generic.Files.LineLength.TooLong + if ($this->isValueYes($value)) { + return esc_html__('Yes', 'itineris-gf-giftaid-field'); + } + + return esc_html__('No', 'itineris-gf-giftaid-field'); + } + + /** + * @phpcs:disable Generic.Files.LineLength.TooLong + * + * @param array $entry The entry currently being processed. + * @param string $input_id The field or input ID. + * @param bool|false $use_text When processing choice based fields should the choice text be returned instead of the value. + * @param bool|false $is_csv Is the value going to be used in the .csv entries export. + * + * @return string|array + */ + public function get_value_export($entry, $input_id = '', $use_text = false, $is_csv = false): string|array + { + // phpcs:enable Generic.Files.LineLength.TooLong + if (empty($input_id)) { + return ''; + } + + $value = parent::get_value_export($entry, $input_id, $use_text, $is_csv); + if ($this->isValueYes($value)) { + return esc_html__('Yes', 'itineris-gf-giftaid-field'); + } + + return esc_html__('No', 'itineris-gf-giftaid-field'); + } + public function sanitize_settings(): void { parent::sanitize_settings(); $this->checkboxLabel = $this->maybe_wp_kses($this->checkboxLabel); } + + public function get_filter_settings(): array + { + $filter_settings = [ + 'key' => $this->id, + 'text' => GFFormsModel::get_label($this), + 'preventMultiple' => false, + 'operators' => $this->get_filter_operators(), + ]; + + $values = $this->get_filter_values(); + if (! empty($values)) { + $filter_settings['values'] = $values; + } + + return $filter_settings; + } + + public function get_filter_operators(): array + { + return ['is', 'isnot']; + } + + public function get_filter_values(): array + { + return [ + [ + 'value' => '1', + 'text' => esc_html__('Yes', 'itineris-gf-giftaid-field'), + ], + [ + 'value' => '0', + 'text' => esc_html__('No', 'itineris-gf-giftaid-field'), + ], + ]; + } }