Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@
"wporg/wporg-mu-plugins": "dev-build"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"phpcompatibility/phpcompatibility-wp": "*",
"phpunit/phpunit": "^9.5",
"rmccue/requests": "^1.8.1",
"wp-coding-standards/wpcs": "2.*",
"wp-coding-standards/wpcs": "^3.4",
"wp-phpunit/wp-phpunit": "~6.0",
"wporg/wporg-parent-2021": "dev-build",
"yoast/phpunit-polyfills": "^1.1"
Expand Down
294 changes: 250 additions & 44 deletions composer.lock

Large diffs are not rendered by default.

26 changes: 19 additions & 7 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
<!-- It's often obvious what the placeholder is, so whether or not to include a comment is a judgement call. -->
<exclude name="WordPress.WP.I18n.MissingTranslatorsComment" />

<!-- I know it's a language construct, but it just looks better using the function call syntax. -->
<exclude name="PEAR.Files.IncludingFile.BracketsNotRequired" />

<!-- This requires passing a whitelist of prefixes in order to work, which is not practical for a large and varied codebase. It's also fixes a problem that we're unlikely to cause. -->
<exclude name="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound" />
<exclude name="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound" />
Expand Down Expand Up @@ -79,11 +76,17 @@
<!-- print_r() is perfectly accepted in some circumstances, like WP_CLI commands. -->
<exclude name="WordPress.PHP.DevelopmentFunctions.error_log_print_r" />

<!-- PSR-12's file-header grammar fixes the order of the docblock, namespace and `use` groups, and
forbids interleaving them. This codebase groups its imports by what they import rather than by
kind, and puts the `use` statements directly after the namespace, which is the same preference
recorded below for PSR2.Namespaces.NamespaceDeclaration.BlankLineAfter. New in WPCS 3.0. -->
<exclude name="PSR12.Files.FileHeader" />

<!-- Allow short ternary pattern. -->
<exclude name="WordPress.PHP.DisallowShortTernary.Found" />
<exclude name="Universal.Operators.DisallowShortTernary.Found" />

<!-- Allow short array syntax. -->
<exclude name="Generic.Arrays.DisallowShortArraySyntax.Found" />
<exclude name="Universal.Arrays.DisallowShortArraySyntax.Found" />
</rule>

<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
Expand All @@ -93,7 +96,7 @@

<rule ref="WordPress.NamingConventions.ValidVariableName">
<properties>
<property name="customPropertiesWhitelist" type="array">
<property name="allowed_custom_properties" type="array">
<element value="nodeValue"/>
<element value="parentNode"/>
</property>
Expand Down Expand Up @@ -148,7 +151,16 @@
provided as a comma-delimited list. -->
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array" value="wporg-patterns" />
<property name="text_domain" type="array">
<element value="wporg-patterns" />
</property>
</properties>
</rule>

<!-- I know it's a language construct, but it just looks better using the function call syntax.
Silenced here rather than excluded from `WordPress-Core`, because `WordPress-Extra` re-includes
`WordPress-Core` and reinstates it; this must stay after the `WordPress-Extra` rule to win. -->
<rule ref="PEAR.Files.IncludingFile.BracketsNotRequired">
<severity>0</severity>
</rule>
</ruleset>
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function pattern_creator_init() {
wp_deregister_style( 'wporg-parent-2021-style' );
wp_deregister_style( 'global-styles' );

$dir = dirname( __FILE__ );
$dir = __DIR__;
$script_asset_path = "$dir/build/index.asset.php";
if ( ! file_exists( $script_asset_path ) ) {
throw new \Error( 'You need to run `npm run start:creator` or `npm run build:creator` for the Pattern Creator.' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace WordPressdotorg\Pattern_Creator;
use const WordPressdotorg\Pattern_Directory\Pattern_Post_Type\POST_TYPE;

add_filter( 'body_class', function( $classes ) {
add_filter( 'body_class', function ( $classes ) {
$classes[] = 'admin-color-modern';
return $classes;
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@
);
}
}
} else {
if ( $opts['verbose'] ) {
echo "{$pattern->ID}: Not spam.\n"; // phpcs:ignore
}
} elseif ( $opts['verbose'] ) {
echo "{$pattern->ID}: Not spam.\n"; // phpcs:ignore
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@ function flag_list_table_views( $views ) {
if ( $parent_id ) {
$views = array_map(
// Add a post_parent parameter to each view's URL.
function( $item ) use ( $parent_id ) {
function ( $item ) use ( $parent_id ) {
return preg_replace_callback(
'|href=[\'"]+([^\'"]+)[\'"]+|',
function( $matches ) use ( $parent_id ) {
function ( $matches ) use ( $parent_id ) {
$old_url = wp_kses_decode_entities( $matches[1] );
$new_url = add_query_arg( array( 'post_parent' => $parent_id ), $old_url );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use const WordPressdotorg\Pattern_Directory\Pattern_Flag_Post_Type\POST_TYPE as FLAG;
use const WordPressdotorg\Pattern_Directory\Pattern_Flag_Post_Type\TAX_TYPE as FLAG_REASON;
use const WordPressdotorg\Pattern_Directory\Pattern_Flag_Post_Type\PENDING_STATUS;
use const WordPressdotorg\Pattern_Directory\Pattern_Post_Type\{ UNLISTED_STATUS, SPAM_STATUS };
use const WordPressdotorg\Pattern_Directory\Pattern_Post_Type\{ UNLISTED_STATUS, SPAM_STATUS };

defined( 'WPINC' ) || die();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function admin_init() {
'wporg-pattern-default_status',
array(
'type' => 'string',
'sanitize_callback' => function( $value ) {
'sanitize_callback' => function ( $value ) {
return in_array( $value, array( 'publish', 'pending' ) ) ? $value : 'publish';
},
'default' => 'publish',
Expand All @@ -73,7 +73,7 @@ function admin_init() {
'wporg-pattern-flag_threshold',
array(
'type' => 'integer',
'sanitize_callback' => function( $value ) {
'sanitize_callback' => function ( $value ) {
$value = absint( $value );

if ( $value < 1 || $value > 100 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function get_snapshot_meta_data() {
* @return array
*/
function get_export_form_inputs() {
$date_filter = function( $string ) {
$date_filter = function ( $string ) {
$success = preg_match( '|([0-9]{4}\-[0-9]{2}\-[0-9]{2})|', $string, $match );

if ( $success ) {
Expand Down Expand Up @@ -230,7 +230,7 @@ function handle_csv_export() {
}

$data = array_map(
function( $snapshot ) use ( $schema ) {
function ( $snapshot ) use ( $schema ) {
$date = get_the_date( 'Y-m-d', $snapshot );
$row = array( $date );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function set_filename( $name_segments ) {
$name_segments = (array) $name_segments;
}

$name_segments = array_map( function( $segment ) {
$name_segments = array_map( function ( $segment ) {
$segment = strtolower( $segment );
$segment = str_replace( '_', '-', $segment );
$segment = sanitize_file_name( $segment );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function init() {

$args = array(
'id' => array(
'validate_callback' => function( $param, $request, $key ) {
'validate_callback' => function ( $param, $request, $key ) {
return is_numeric( $param );
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function notify_pattern_flagged( $post ) {
}
}
$reasons = array_map(
function( \WP_Term $reason ) {
function ( \WP_Term $reason ) {
return wp_strip_all_tags( $reason->description );
},
$reasons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function register_post_type_data() {
'type' => 'string',
'description' => 'A list of block types this pattern supports for transforms.',
'single' => false,
'sanitize_callback' => function( $value, $key, $type ) {
'sanitize_callback' => function ( $value, $key, $type ) {
return preg_replace( '/[^a-z0-9-\/]/', '', $value );
},
'auth_callback' => __NAMESPACE__ . '\can_edit_this_pattern',
Expand All @@ -216,7 +216,7 @@ function register_post_type_data() {
'type' => 'string',
'description' => 'The language used when creating this pattern.',
'single' => true,
'sanitize_callback' => function( $value ) {
'sanitize_callback' => function ( $value ) {
if ( ! in_array( $value, array_keys( get_locales() ), true ) ) {
return 'en_US';
}
Expand Down Expand Up @@ -291,7 +291,7 @@ function register_rest_fields() {
POST_TYPE,
'category_slugs',
array(
'get_callback' => function() {
'get_callback' => function () {
$slugs = wp_list_pluck( wp_get_object_terms( get_the_ID(), 'wporg-pattern-category' ), 'slug' );
$slugs = array_map( 'sanitize_title', $slugs );
$slugs = array_diff( $slugs, [ 'featured' ] );
Expand All @@ -314,7 +314,7 @@ function register_rest_fields() {
POST_TYPE,
'keyword_slugs',
array(
'get_callback' => function() {
'get_callback' => function () {
$slugs = wp_list_pluck( wp_get_object_terms( get_the_ID(), 'wporg-pattern-keyword' ), 'slug' );

return array_map( 'sanitize_title', $slugs );
Expand All @@ -340,7 +340,7 @@ function register_rest_fields() {
POST_TYPE,
'pattern_content',
array(
'get_callback' => function( $response_data ) {
'get_callback' => function ( $response_data ) {
$pattern = get_post( $response_data['id'] );
return decode_pattern_content( $pattern->post_content );
},
Expand All @@ -358,7 +358,7 @@ function register_rest_fields() {
POST_TYPE,
'favorite_count',
array(
'get_callback' => function() {
'get_callback' => function () {
return get_favorite_count( get_the_ID() );
},

Expand All @@ -376,7 +376,7 @@ function register_rest_fields() {
POST_TYPE,
'author_meta',
array(
'get_callback' => function( $post ) {
'get_callback' => function ( $post ) {
return array(
'name' => esc_html( get_the_author_meta( 'display_name', $post['author'] ) ),
'url' => esc_url( home_url( '/author/' . get_the_author_meta( 'user_nicename', $post['author'] ) ) ),
Expand Down Expand Up @@ -420,7 +420,7 @@ function register_rest_fields() {
POST_TYPE,
'unlisted_reason',
array(
'get_callback' => function() {
'get_callback' => function () {
$reasons = wp_get_object_terms( get_the_ID(), FLAG_REASON );
if ( count( $reasons ) > 0 ) {
$reason = array_shift( $reasons );
Expand Down Expand Up @@ -560,7 +560,7 @@ function enqueue_editor_assets() {
return;
}

$dir = dirname( dirname( __FILE__ ) );
$dir = dirname( __DIR__ );

$script_asset_path = "$dir/build/pattern-post-type.asset.php";
if ( ! file_exists( $script_asset_path ) ) {
Expand All @@ -570,7 +570,7 @@ function enqueue_editor_assets() {
$script_asset = require $script_asset_path;
wp_enqueue_script(
'wporg-pattern-post-type',
plugins_url( 'build/pattern-post-type.js', dirname( __FILE__ ) ),
plugins_url( 'build/pattern-post-type.js', __DIR__ ),
$script_asset['dependencies'],
$script_asset['version'],
true
Expand All @@ -588,7 +588,7 @@ function enqueue_editor_assets() {

wp_enqueue_style(
'wporg-pattern-post-type',
plugins_url( 'build/pattern-post-type.css', dirname( __FILE__ ) ),
plugins_url( 'build/pattern-post-type.css', __DIR__ ),
array(),
$script_asset['version'],
);
Expand Down Expand Up @@ -665,7 +665,7 @@ function filter_patterns_collection_params( $query_params ) {
$query_params['author_name'] = array(
'description' => __( 'Limit result set to patterns by a single author.', 'wporg-patterns' ),
'type' => 'string',
'validate_callback' => function( $value ) {
'validate_callback' => function ( $value ) {
$user = get_user_by( 'slug', $value );
return (bool) $user;
},
Expand Down Expand Up @@ -904,23 +904,23 @@ function setup_preview_theme() {
if ( preg_match( '#/view/$#', $request_uri ) || preg_match( '#[?&]view=[1|true]#', $request_uri ) ) {
add_filter( 'show_admin_bar', '__return_false', 2000 );

add_filter( 'template', function() {
add_filter( 'template', function () {
if ( 'local' === wp_get_environment_type() ) {
return 'twentytwentythree';
} else {
return 'core/twentytwentythree';
}
} );

add_filter( 'stylesheet', function() {
add_filter( 'stylesheet', function () {
if ( 'local' === wp_get_environment_type() ) {
return 'twentytwentythree';
} else {
return 'core/twentytwentythree';
}
} );

add_filter( 'wp_enqueue_scripts', function() {
add_filter( 'wp_enqueue_scripts', function () {
wp_deregister_style( 'wp4-styles' );
wp_deregister_style( 'wporg-global-header-footer' );
}, 201 );
Expand Down Expand Up @@ -992,7 +992,7 @@ function load_pattern_preview( $template ) {
*/
add_action(
'the_post',
function( $post ) {
function ( $post ) {
$post->post_content = decode_pattern_content( $post->post_content );
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function validate_content( $prepared_post, $request ) {

// Check that each block in the list has a blockName and is registered.
$registry = \WP_Block_Type_Registry::get_instance();
$invalid_blocks = array_filter( $all_blocks, function( $block ) use ( $registry ) {
$invalid_blocks = array_filter( $all_blocks, function ( $block ) use ( $registry ) {
$block_type = $registry->get_registered( $block['blockName'] );
return is_null( $block['blockName'] ) || is_null( $block_type );
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function modify_es_query_args( $es_query_args, $wp_query ) {

// Requests for a specific locale will still include `en_US` as a fallback.
if ( count( $locales ) > 1 ) {
$primary_locale = array_reduce( $locales, function( $carry, $item ) {
$primary_locale = array_reduce( $locales, function ( $carry, $item ) {
// This assumes there will only be 2 items in $locale.
if ( 'en_US' !== $item ) {
$carry = $item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,3 @@ public function test_invalid_empty_existing_title() {
$this->assertSame( 'rest_pattern_empty_title', $data['code'] );
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function json( $_, $args ) {
$patterns = $this->get_patterns_or_exit( $args );

// Flatten parent to just being the slug.
array_walk( $patterns, function( $pattern ) {
array_walk( $patterns, function ( $pattern ) {
$pattern->parent = $pattern->parent->name ?? $pattern->parent;
} );

Expand Down Expand Up @@ -139,5 +139,4 @@ private function get_patterns_or_exit( $args ) {

return $patterns;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function register_cron_tasks() {
if ( ! wp_next_scheduled( 'pattern_import_translations_to_directory' ) ) {
wp_schedule_event( time(), 'twicedaily', 'pattern_import_translations_to_directory' );
}

}
add_action( 'admin_init', __NAMESPACE__ . '\register_cron_tasks' );

Expand Down Expand Up @@ -72,7 +71,7 @@ function pattern_import_translations_to_directory( $pattern_ids = array() ) {
// Raise the memory limit for this process to at least 512M.
add_filter(
'cron_memory_limit',
function() {
function () {
return '512M';
}
);
Expand Down
Loading