Skip to content

Commit 8b13b32

Browse files
justlevinetheodespmindctrl
authored
chore: misc PHPCS fixes (#73)
* chore: fix mismatched text domains * chore: [PHPCS] fix string translation / escaping * chore: [PHPCS] remove unused params from 'resolve' callback * chore: [PHPCS] use yoda conditionals * chore: add changesets * chore: use wp_kses_post to preserve link * chore: fix typo --------- Co-authored-by: Theofanis Despoudis <328805+theodesp@users.noreply.github.com> Co-authored-by: John Parris <john.parris@wpengine.com>
1 parent 56f1b1e commit 8b13b32

8 files changed

Lines changed: 55 additions & 14 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@wpengine/wp-graphql-content-blocks": patch
3+
---
4+
5+
dev: Change comparison of `$attribute_config['type']` to use Yoda conditional.

.changeset/green-bobcats-cover.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@wpengine/wp-graphql-content-blocks": patch
3+
---
4+
5+
dev: Remove unused method params from the block attribute field resolver callback.

.changeset/hot-files-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@wpengine/wp-graphql-content-blocks": patch
3+
---
4+
5+
fix: Replace the usage of `'wp-graphql'` text-domain with the correct `'wp-graphql-content-blocks'`.

.changeset/ten-fishes-breathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@wpengine/wp-graphql-content-blocks": patch
3+
---
4+
5+
fix: Ensure proper string translation, concatenation, and escaping.

includes/Blocks/Block.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ private function register_block_attributes_as_fields() {
107107
register_graphql_object_type(
108108
$block_attribute_type_name,
109109
array(
110-
'description' => __( 'Attributes of the %s Block Type', 'wp-graphql-content-blocks' ),
110+
'description' => sprintf(
111+
// translators: %s is the block type name.
112+
__( 'Attributes of the %s Block Type', 'wp-graphql-content-blocks' ),
113+
$this->type_name
114+
),
111115
'fields' => $block_attribute_fields,
112116
)
113117
);
@@ -117,7 +121,11 @@ private function register_block_attributes_as_fields() {
117121
'attributes',
118122
array(
119123
'type' => $block_attribute_type_name,
120-
'description' => __( 'Attributes of the %s Block Type', 'wp-graphql-content-blocks' ),
124+
'description' => sprintf(
125+
// translators: %s is the block type name.
126+
__( 'Attributes of the %s Block Type', 'wp-graphql-content-blocks' ),
127+
$this->type_name
128+
),
121129
'resolve' => function ( $block ) {
122130
return $block;
123131
},
@@ -172,8 +180,13 @@ private function get_block_attribute_fields( $block_attributes ) {
172180

173181
$block_attribute_fields[ Utils::format_field_name( $attribute_name ) ] = array(
174182
'type' => $graphql_type,
175-
'description' => __( sprintf( 'The "%1$s" field on the "%2$s" block', $attribute_name, $this->type_name ), 'wp-graphql' ),
176-
'resolve' => function ( $block, $args, $context, $info ) use ( $attribute_name, $attribute_config ) {
183+
'description' => sprintf(
184+
// translators: %1$s is the attribute name, %2$s is the block name.
185+
__( 'The "%1$s" field on the "%2$s" block', 'wp-graphql-content-blocks' ),
186+
$attribute_name,
187+
$this->type_name
188+
),
189+
'resolve' => function ( $block ) use ( $attribute_name, $attribute_config ) {
177190
return $this->resolve_block_attributes( $block, $attribute_name, $attribute_config );
178191
},
179192
);
@@ -282,7 +295,7 @@ private function resolve_block_attributes( $block, $attribute_name, $attribute_c
282295
}//end switch
283296

284297
// if type is set to integer, get the integer value of the attribute.
285-
if ( $attribute_config['type'] === 'integer' ) {
298+
if ( 'integer' === $attribute_config['type'] ) {
286299
$value = intval( $value );
287300
}
288301

includes/Type/InterfaceType/PostTypeBlockInterface.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ public static function register_type( string $post_type, $block_names, TypeRegis
4848
register_graphql_interface_type(
4949
'NodeWith' . ucfirst( $post_type ) . 'EditorBlocks',
5050
array(
51-
'description' => __( 'Node that has ' . $post_type . ' content blocks associated with it', 'wp-graphql-content-blocks' ),
51+
'description' => sprintf(
52+
// translators: %s is the post type.
53+
__( 'Node that has %s content blocks associated with it', 'wp-graphql-content-blocks' ),
54+
$post_type
55+
),
5256
'eagerlyLoadType' => true,
5357
'interfaces' => array( 'NodeWithEditorBlocks' ),
5458
'fields' => array(
@@ -61,7 +65,11 @@ public static function register_type( string $post_type, $block_names, TypeRegis
6165
'type' => 'Boolean',
6266
),
6367
),
64-
'description' => __( 'List of ' . $post_type . ' editor blocks', 'wp-graphql-content-blocks' ),
68+
'description' => sprintf(
69+
// translators: %s is the post type.
70+
__( 'List of %s editor blocks', 'wp-graphql-content-blocks' ),
71+
$post_type
72+
),
6573
'resolve' => function ( $node, $args ) use ( $block_names ) {
6674
return ContentBlocksResolver::resolve_content_blocks( $node, $args, $block_names );
6775
},

includes/WPGraphQLContentBlocks.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static function instance() {
5252
*/
5353
public function __clone() {
5454
// Cloning instances of the class is forbidden.
55-
_doing_it_wrong( __FUNCTION__, esc_html__( 'The WPGraphQLContentBlocks class should not be cloned.', 'wp-graphql' ), '0.0.1' );
55+
_doing_it_wrong( __FUNCTION__, esc_html__( 'The WPGraphQLContentBlocks class should not be cloned.', 'wp-graphql-content-blocks' ), '0.0.1' );
5656
}
5757

5858
/**
@@ -63,7 +63,7 @@ public function __clone() {
6363
*/
6464
public function __wakeup() {
6565
// De-serializing instances of the class is forbidden.
66-
_doing_it_wrong( __FUNCTION__, esc_html__( 'De-serializing instances of the WPGraphQLContentBlocks class is not allowed', 'wp-graphql' ), '0.0.1' );
66+
_doing_it_wrong( __FUNCTION__, esc_html__( 'De-serializing instances of the WPGraphQLContentBlocks class is not allowed', 'wp-graphql-content-blocks' ), '0.0.1' );
6767
}
6868

6969
/**
@@ -117,9 +117,9 @@ function () {
117117

118118
echo sprintf(
119119
'<div class="notice notice-error">' .
120-
'<p>%s</p>' .
120+
'<p>%s</p>' .
121121
'</div>',
122-
__( 'WPGraphQL Content Blocks appears to have been installed without it\'s dependencies. If you meant to download the source code, you can run `composer install` to install dependencies. If you are looking for the production version of the plugin, you can download it from the <a target="_blank" href="https://github.com/wpengine/wp-graphql-content-blocks/releases">GitHub Releases tab.</a>', 'wp-graphql' )
122+
wp_kses_post( 'WPGraphQL Content Blocks appears to have been installed without its dependencies. If you meant to download the source code, you can run `composer install` to install dependencies. If you are looking for the production version of the plugin, you can download it from the <a target="_blank" href="https://github.com/wpengine/wp-graphql-content-blocks/releases">GitHub Releases tab.</a>', 'wp-graphql-content-blocks' )
123123
);
124124
}
125125
);
@@ -139,8 +139,8 @@ function () {
139139
echo sprintf(
140140
'<div class="notice notice-error is-dismissible">' .
141141
'<p>%s</p>' .
142-
'</div>',
143-
__( 'WPGraphQL Content Blocks will not work without WPGraphQL installed and active.', 'wp-graphql' )
142+
'</div>',
143+
esc_html__( 'WPGraphQL Content Blocks will not work without WPGraphQL installed and active.', 'wp-graphql-content-blocks' )
144144
);
145145
}
146146
);

includes/utilities/DomHelpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static function parseAttribute( $html, $selector, $attribute, $default =
2828
$doc = new Document();
2929
$doc->loadHTML( $html );
3030
if ( '*' === $selector ) {
31-
$selector = '*' . '[' . $attribute . ']';
31+
$selector = '*[' . $attribute . ']';
3232
}
3333
$node = $doc->find( $selector );
3434
$default = isset( $default ) ? $default : null;

0 commit comments

Comments
 (0)