Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Refresh - Validate URL in Locate Template#6502

Open
shail-mehta wants to merge 15 commits into
WordPress:trunkfrom
shail-mehta:validate-url-in-locate-template
Open

Refresh - Validate URL in Locate Template#6502
shail-mehta wants to merge 15 commits into
WordPress:trunkfrom
shail-mehta:validate-url-in-locate-template

Conversation

@shail-mehta

Copy link
Copy Markdown
Member

Added refresh patch for Validate url in locate template.

Trac ticket: https://core.trac.wordpress.org/ticket/58905

@github-actions

github-actions Bot commented May 4, 2024

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props shailu25, jorbin, joemcgill, mukesh27, martinkrcho, peterwilsoncc.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@shail-mehta shail-mehta changed the title Validate URL in Locate Template Refresh - Validate URL in Locate Template May 4, 2024
@github-actions

github-actions Bot commented May 4, 2024

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@shail-mehta shail-mehta force-pushed the validate-url-in-locate-template branch from d3ff41f to 8ae3447 Compare May 5, 2024 08:59

@mukeshpanchal27 mukeshpanchal27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will impact the performance.

Comment thread src/wp-includes/template.php Outdated

@martinkrcho martinkrcho left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just a small suggestion.

Comment on lines +500 to +504
* @dataProvider data_locate_template_only_loads_theme_files
*
* @ticket 58905
*
* @covers ::locate_template

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* @dataProvider data_locate_template_only_loads_theme_files
*
* @ticket 58905
*
* @covers ::locate_template
* @ticket 58905
*
* @covers ::locate_template
*
* @dataProvider data_locate_template_only_loads_theme_files

Correct the annotation order.

@mukeshpanchal27 mukeshpanchal27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I did some benchmark for script execution over 1,000 iterations. Overall, the new_locate_template() function shows a performance decrease ranging from 29.5% to 109.7% compared to the locate_template() function in most cases.

Benchmark result: Average time spent for 1 x 1000 iterations

locate_template() - 2327291, new_locate_template() - 3371709, Difference: 1044418, Change: 44.9%
locate_template() - 4217750, new_locate_template() - 5885542, Difference: 1667792, Change: 39.5%
locate_template() - 2649750, new_locate_template() - 3660833, Difference: 1011083, Change: 38.2%
locate_template() - 4466125, new_locate_template() - 5970000, Difference: 1503875, Change: 33.7%
locate_template() - 2321167, new_locate_template() - 4868625, Difference: 2547458, Change: 109.7%
locate_template() - 3231500, new_locate_template() - 4728166, Difference: 1496666, Change: 46.3%
locate_template() - 2417042, new_locate_template() - 3442250, Difference: 1025208, Change: 42.4%
locate_template() - 3219166, new_locate_template() - 4169375, Difference: 950209, Change: 29.5%
locate_template() - 2725250, new_locate_template() - 3653625, Difference: 928375, Change: 34.1%
locate_template() - 2405292, new_locate_template() - 3170375, Difference: 765083, Change: 31.8%
locate_template() - 2573292, new_locate_template() - 3570792, Difference: 997500, Change: 38.8%
locate_template() - 2514834, new_locate_template() - 3419583, Difference: 904749, Change: 36%
locate_template() - 5061292, new_locate_template() - 3319542, Difference: -1741750, Change: -34.4%
locate_template() - 2762333, new_locate_template() - 4013458, Difference: 1251125, Change: 45.3%
locate_template() - 2581125, new_locate_template() - 3664292, Difference: 1083167, Change: 42%
locate_template() - 2170583, new_locate_template() - 3384125, Difference: 1213542, Change: 55.9%
locate_template() - 2738209, new_locate_template() - 3909125, Difference: 1170916, Change: 42.8%
locate_template() - 2437917, new_locate_template() - 4095667, Difference: 1657750, Change: 68%
locate_template() - 3242500, new_locate_template() - 4309958, Difference: 1067458, Change: 32.9%
locate_template() - 4649834, new_locate_template() - 6784333, Difference: 2134499, Change: 45.9%
locate_template() - 2123125, new_locate_template() - 3151250, Difference: 1028125, Change: 48.4%
locate_template() - 2147125, new_locate_template() - 3126417, Difference: 979292, Change: 45.6%
locate_template() - 2574291, new_locate_template() - 3646625, Difference: 1072334, Change: 41.7%
locate_template() - 2506208, new_locate_template() - 3698250, Difference: 1192042, Change: 47.6%

Note: To run the benchmark, I use the Twenty Twenty-One theme and make duplicate templates from existing ones so it will not used cached version.

@peterwilsoncc

Copy link
Copy Markdown
Contributor

@mukeshpanchal27 Are you able to edit the comment above to note the raw difference. As the benchmarking script is using hrtime() (nanoseconds) I think the raw numbers could be more helpful than a percentage.

@mukeshpanchal27

Copy link
Copy Markdown
Member

@peterwilsoncc Updated #6502 (review)

@peterwilsoncc

Copy link
Copy Markdown
Contributor

Converting the raw times from nanoseconds to milliseconds is showing a showdown of between 0.7ms to 2.5ms over 1000 iterations so I don't think it's worth considering the performance impacts as a reason to block the benefits of avoiding using the function to include files outside of the template paths.

@joemcgill

joemcgill commented Feb 19, 2025

Copy link
Copy Markdown
Member

Updated this PR from trunk to try to address Unit Test failures, but something is causing these to error out before reporting failures in the workflow. I've run them locally to see if I can diagnose what the issue is.

Looks like the failures can be seen when running the template group tests, i.e. --group template. Failure output below:

There were 5 failures:

1) Tests_General_Template::test_get_header_returns_nothing_on_success
Unexpected deprecation notice for Theme without header.php.
File Theme without header.php is deprecated since version 3.0.0 with no alternative available. Please include a header.php template in your theme.
Failed asserting that an array is empty.

/var/www/tests/phpunit/includes/abstract-testcase.php:643
/var/www/tests/phpunit/includes/abstract-testcase.php:655
/var/www/vendor/yoast/phpunit-polyfills/src/TestCases/TestCasePHPUnitGte8.php:88

2) Tests_General_Template::test_get_footer_returns_nothing_on_success
Unexpected deprecation notice for Theme without footer.php.
File Theme without footer.php is deprecated since version 3.0.0 with no alternative available. Please include a footer.php template in your theme.
Unexpected deprecation notice for the_block_template_skip_link.
Function the_block_template_skip_link is deprecated since version 6.4.0! Use wp_enqueue_block_template_skip_link() instead.
Failed asserting that an array is empty.

/var/www/tests/phpunit/includes/abstract-testcase.php:643
/var/www/tests/phpunit/includes/abstract-testcase.php:655
/var/www/vendor/yoast/phpunit-polyfills/src/TestCases/TestCasePHPUnitGte8.php:88

3) Tests_General_Template::test_get_sidebar_returns_nothing_on_success
Unexpected deprecation notice for Theme without sidebar.php.
File Theme without sidebar.php is deprecated since version 3.0.0 with no alternative available. Please include a sidebar.php template in your theme.
Failed asserting that an array is empty.

/var/www/tests/phpunit/includes/abstract-testcase.php:643
/var/www/tests/phpunit/includes/abstract-testcase.php:655
/var/www/vendor/yoast/phpunit-polyfills/src/TestCases/TestCasePHPUnitGte8.php:88

4) Tests_General_Template::test_get_template_part_returns_nothing_on_success
Failed asserting that false is null.

/var/www/tests/phpunit/tests/general/template.php:574

5) Tests_General_Template::test_get_template_part_passes_arguments_to_template
Failed asserting that '' matches PCRE pattern "/{"foo":"baz"}/".

@joemcgill

Copy link
Copy Markdown
Member

I've also found that the reason the PHPUnit Tests workflow are not showing failures is because the test suite is failing silently on Tests_Embed_Template::test_oembed_output_post. This will also require investigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants