Make WordPress Core


Ignore:
Timestamp:
10/05/2023 10:40:48 PM (3 years ago)
Author:
SergeyBiryukov
Message:

HTML API: Rename WP_HTML_Processor::createFragment() to follow WPCS.

WP_HTML_Processor::create_fragment() is the correct method name as per the WordPress PHP coding standards.

Follow-up to [56274].

Props dmsnell, jrf, hellofromTonya, SergeyBiryukov.
Fixes #59547.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-processor.php

    r56702 r56790  
    4040 * Example:
    4141 *
    42  *     $processor = WP_HTML_Processor::createFragment( $html );
     42 *     $processor = WP_HTML_Processor::create_fragment( $html );
    4343 *     if ( $processor->next_tag( array( 'breadcrumbs' => array( 'DIV', 'FIGURE', 'IMG' ) ) ) ) {
    4444 *         $processor->add_class( 'responsive-image' );
    … …  
    5959 * when parsed, the return value from `get_breadcrumbs()` will always
    6060 * contain any implicit outermost elements. For example, when parsing
    61  * with `createFragment()` in the `BODY` context (the default), any
     61 * with `create_fragment()` in the `BODY` context (the default), any
    6262 * tag in the given HTML document will contain `array( 'HTML', 'BODY', … )`
    6363 * in its breadcrumbs.
    … …  
    240240         * @return WP_HTML_Processor|null The created processor if successful, otherwise null.
    241241         */
    242         public static function createFragment( $html, $context = '<body>', $encoding = 'UTF-8' ) {
     242        public static function create_fragment( $html, $context = '<body>', $encoding = 'UTF-8' ) {
    243243                if ( '<body>' !== $context || 'UTF-8' !== $encoding ) {
    244244                        return null;
    … …  
    281281         * @since 6.4.0
    282282         *
    283          * @see WP_HTML_Processor::createFragment()
     283         * @see WP_HTML_Processor::create_fragment()
    284284         *
    285285         * @param string      $html                                  HTML to process.
    … …  
    293293                                __METHOD__,
    294294                                sprintf(
    295                                         /* translators: %s: WP_HTML_Processor::createFragment. */
     295                                        /* translators: %s: WP_HTML_Processor::create_fragment(). */
    296296                                        __( 'Call %s to create an HTML Processor instead of calling the constructor directly.' ),
    297                                         '<code>WP_HTML_Processor::createFragment</code>'
     297                                        '<code>WP_HTML_Processor::create_fragment()</code>'
    298298                                ),
    299299                                '6.4.0'
    … …  
    325325         * Example
    326326         *
    327          *     $processor = WP_HTML_Processor::createFragment( '<template><strong><button><em><p><em>' );
     327         *     $processor = WP_HTML_Processor::create_fragment( '<template><strong><button><em><p><em>' );
    328328         *     false === $processor->next_tag();
    329329         *     WP_HTML_Processor::ERROR_UNSUPPORTED === $processor->get_last_error();
    … …  
    429429         * Example:
    430430         *
    431          *     $processor = WP_HTML_Processor::createFragment( '<div><span><figure><img></figure></span></div>' );
     431         *     $processor = WP_HTML_Processor::create_fragment( '<div><span><figure><img></figure></span></div>' );
    432432         *     $processor->next_tag( 'img' );
    433433         *     true  === $processor->matches_breadcrumbs( array( 'figure', 'img' ) );
    … …  
    558558         * Example
    559559         *
    560          *     $processor = WP_HTML_Processor::createFragment( '<p><strong><em><img></em></strong></p>' );
     560         *     $processor = WP_HTML_Processor::create_fragment( '<p><strong><em><img></em></strong></p>' );
    561561         *     $processor->next_tag( 'IMG' );
    562562         *     $processor->get_breadcrumbs() === array( 'HTML', 'BODY', 'P', 'STRONG', 'EM', 'IMG' );
    … …  
    14401440         * @access private
    14411441         */
    1442         const CONSTRUCTOR_UNLOCK_CODE = 'Use WP_HTML_Processor::createFragment instead of calling the class constructor directly.';
     1442        const CONSTRUCTOR_UNLOCK_CODE = 'Use WP_HTML_Processor::create_fragment() instead of calling the class constructor directly.';
    14431443}
Note: See TracChangeset for help on using the changeset viewer.