Skip to content
This repository was archived by the owner on Jul 28, 2023. It is now read-only.
Merged
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
14 changes: 14 additions & 0 deletions phpunit/directives/wp-process-directives.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,18 @@ function( $p ) {
$tags = new WP_HTML_Tag_Processor( $markup );
wp_process_directives( $tags, 'foo-', array(), $attribute_directives );
}

public function test_directives_with_colon_processed_correctly() {
$test_helper = $this->createMock( Helper_Class::class );
$test_helper->expects( $this->atLeastOnce() )
->method( 'process_foo_test' );

$attribute_directives = array(
'foo-test' => array( $test_helper, 'process_foo_test' ),
);

$markup = '<div foo-test:value="abc"></div>';
$tags = new WP_HTML_Tag_Processor( $markup );
wp_process_directives( $tags, 'foo-', array(), $attribute_directives );
}
}
7 changes: 7 additions & 0 deletions src/directives/wp-process-directives.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ function wp_process_directives( $tags, $prefix, $tag_directives, $attribute_dire
}
}
} else {
// Helper that removes the part after the colon before looking
// for the directive processor inside `$attribute_directives`.
$get_directive_type = function ( $attr ) {
return strtok( $attr, ':' );
};

Comment on lines +33 to +38

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe move this outside wp_process_directives's function definition so we don't re-define the $get_directive_type ever so often?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be fine if we create a global function just for that? That feels weird, haha. 😅

Anyway, we can do it in another PR if you think is worth it. 👍

$attributes = $tags->get_attribute_names_with_prefix( $prefix );
$attributes = array_map( $get_directive_type, $attributes );
$attributes = array_intersect( $attributes, array_keys( $attribute_directives ) );

// If this is an open tag, and if it either has attribute directives,
Expand Down