Files
Geoff TaylorandGitHub 088d337ef5 fix: address WordPress.org plugin review (rename + prefixing + headers) (#1019)
* fix: address WordPress.org plugin review feedback

- Prefix the session transaction queue transient with the plugin's
  graphql_woocommerce_ namespace instead of the generic "woo_" word, to
  avoid collisions (Plugin Directory: prefix data storage).
- Declare the WooCommerce dependency via the "Requires Plugins: woocommerce"
  plugin header.
- Bump README.txt "Tested up to" to 7.0.
- Ship composer.json in the distributed plugin (drop it, and composer.lock,
  from composer archive excludes) so the build is reproducible/reviewable.

* chore: rename plugin to "GraphQL for eCommerce" for trademark compliance

The WordPress.org plugin review flagged the display name/slug for beginning
with the "WPGraphQL" trademark (and the "WooGraphQL" portmanteau of the
WooCommerce mark), which can imply official affiliation.

- Display name (plugin header + readme title) -> "GraphQL for eCommerce".
- Slug/text domain -> "graphql-for-ecommerce" (header, all i18n string
  literals, and the PHPCS WordPress.WP.I18n text_domain config).
- Update user-facing notices/errors that named the old plugin.

"WooGraphQL" remains the project's informal nickname (repo, docs, community),
just not in the WordPress.org directory's official name/slug. Internal file
names and GitHub URLs are unchanged.

* fix: keep test-only dev deps out of the committed composer.json

The committed manifest mirrors develop (lint/stan dev deps only); CI adds the
test suite deps at runtime via `composer installTestEnv`. A previous commit
captured the installTestEnv-modified composer.json, desyncing it from
composer.lock and breaking `composer install` in CI.

* chore: regenerate composer.lock (refresh dev dependencies)

Regenerate the lock from the manifest so it is in sync (fixes the CI
`composer install` failure) and refresh dependencies in the process —
firebase/php-jwt v7.0.4 -> v7.1.0 plus 11 others, with vendor-prefixed
re-strauss'd to match. Full wpunit suite passes against the updated deps
(305 tests, 835 assertions).

* chore: rename text domain in createdVia/attribution strings from #1018

#1018 (createdVia + order attribution) merged into develop after the rename
commit was authored, so its new i18n strings still used the old
'wp-graphql-woocommerce' text domain. Update them to 'graphql-for-ecommerce'
to match the rename.
2026-06-30 10:16:21 -04:00

165 lines
4.0 KiB
PHP

<?php
/**
* Defines helper functions for executing mutations related to the WC Settings API.
*
* @package WPGraphQL\WooCommerce\Data\Mutation
* @since 0.20.0
*/
namespace WPGraphQL\WooCommerce\Data\Mutation;
use GraphQL\Error\UserError;
/**
* Class - Settings_Mutation
*/
class Settings_Mutation {
/**
* Validate a text value for a text based setting.
*
* @param string $value Value.
* @param array $setting Setting.
* @return string
*/
public static function validate_setting_text_field( $value, $setting ) {
$value = is_null( $value ) ? '' : $value;
return wp_kses_post( trim( stripslashes( $value ) ) );
}
/**
* Validate select based settings.
*
* @param string $value Value.
* @param array $setting Setting.
*
* @throws \GraphQL\Error\UserError If an invalid setting value was passed.
*
* @return string
*/
public static function validate_setting_select_field( $value, $setting ) {
if ( array_key_exists( $value, $setting['options'] ) ) {
return $value;
} else {
throw new UserError( __( 'An invalid setting value was passed.', 'graphql-for-ecommerce' ), 400 );
}
}
/**
* Validate multiselect based settings.
*
* @param array $values Values.
* @param array $setting Setting.
*
* @throws \GraphQL\Error\UserError If an invalid setting value was passed.
*
* @return array
*/
public static function validate_setting_multiselect_field( $values, $setting ) {
if ( empty( $values ) ) {
return [];
}
if ( ! is_array( $values ) ) {
throw new UserError( __( 'An invalid setting value was passed.', 'graphql-for-ecommerce' ), 400 );
}
$final_values = [];
foreach ( $values as $value ) {
if ( array_key_exists( $value, $setting['options'] ) ) {
$final_values[] = $value;
}
}
return $final_values;
}
/**
* Validate image_width based settings.
*
* @param array $values Values.
* @param array $setting Setting.
*
* @throws \GraphQL\Error\UserError If an invalid setting value was passed.
*
* @return string
*/
public static function validate_setting_image_width_field( $values, $setting ) {
if ( ! is_array( $values ) ) {
throw new UserError( __( 'An invalid setting value was passed.', 'graphql-for-ecommerce' ), 400 );
}
$current = $setting['value'];
if ( isset( $values['width'] ) ) {
$current['width'] = intval( $values['width'] );
}
if ( isset( $values['height'] ) ) {
$current['height'] = intval( $values['height'] );
}
if ( isset( $values['crop'] ) ) {
$current['crop'] = (bool) $values['crop'];
}
return $current;
}
/**
* Validate radio based settings.
*
* @param string $value Value.
* @param array $setting Setting.
*
* @throws \GraphQL\Error\UserError If an invalid setting value was passed.
*
* @return string
*/
public static function validate_setting_radio_field( $value, $setting ) {
return self::validate_setting_select_field( $value, $setting );
}
/**
* Validate checkbox based settings.
*
* @param string $value Value.
* @param array $setting Setting.
*
* @throws \GraphQL\Error\UserError If an invalid setting value was passed.
*
* @return string
*/
public static function validate_setting_checkbox_field( $value, $setting ) {
if ( in_array( $value, [ 'yes', 'no' ], true ) ) {
return $value;
} elseif ( empty( $value ) ) {
$value = isset( $setting['default'] ) ? $setting['default'] : 'no';
return $value;
} else {
throw new UserError( __( 'An invalid setting value was passed.', 'graphql-for-ecommerce' ), 400 );
}
}
/**
* Validate textarea based settings.
*
* @param string $value Value.
* @param array $setting Setting.
*
* @return string
*/
public static function validate_setting_textarea_field( $value, $setting ) {
$value = is_null( $value ) ? '' : $value;
return wp_kses(
trim( stripslashes( $value ) ),
array_merge(
[
'iframe' => [
'src' => true,
'style' => true,
'id' => true,
'class' => true,
],
],
wp_kses_allowed_html( 'post' )
)
);
}
}