Making WordPress.org

Changeset 13462

Timestamp:
04/05/2024 04:55:33 AM (4 months ago)
Author:
dd32
Message:

Plugin Directory: Expand the trademark checks to match multiple trademarks in the field checked.

Simplifies the error message and centralises the 3 uses of it.

See #5868.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-upload.php

    r13460 r13462  
    66use WordPressdotorg\Plugin_Directory\API\Base;
    77use WordPressdotorg\Plugin_Directory\Shortcodes\Upload_Handler;
     8
     9
    810use WP_REST_Server;
    911use WP_Error;
     
    141143        }
    142144
    143         // Duplicated from Upload handler.
    144145        // Make sure it doesn't use a TRADEMARK protected slug.
    145146        $has_trademarked_slug = Trademarks::check_slug( $slug, wp_get_current_user() );
    146147        if ( $has_trademarked_slug ) {
    147             $error = __( 'That plugin slug includes a restricted term.', 'wporg-plugins' );
    148 
    149             if ( $has_trademarked_slug === trim( $has_trademarked_slug, '-' ) ) {
    150                 // Trademarks that do NOT end in "-" indicate slug cannot contain term at all.
    151                 $message = sprintf(
    152                     /* translators: 1: plugin slug, 2: trademarked term, 3: 'Plugin Name:', 4: plugin email address */
    153                     __( 'Your chosen plugin slug - %1$s - contains the restricted term "%2$s", which cannot be used at all in your plugin permalink nor the display name.', 'wporg-plugins' ),
    154                     '<code>' . $slug . '</code>',
    155                     '<code>' . trim( $has_trademarked_slug, '-' ) . '</code>'
    156                 );
    157             } else {
    158                 // Trademarks ending in "-" indicate slug cannot BEGIN with that term.
    159                 $message = sprintf(
    160                     /* translators: 1: plugin slug, 2: trademarked term, 3: 'Plugin Name:', 4: plugin email address */
    161                     __( 'Your chosen plugin slug - %1$s - contains the restricted term "%2$s" and cannot be used to begin your permalink or display name. We disallow the use of certain terms in ways that are abused, or potentially infringe on and/or are misleading with regards to trademarks.', 'wporg-plugins' ),
    162                     '<code>' . $slug . '</code>',
    163                     '<code>' . trim( $has_trademarked_slug, '-' ) . '</code>'
    164                 );
    165             }
    166 
    167             return new WP_Error( 'trademarked_slug', $error . ' ' . $message );
     148            return new WP_Error(
     149                'trademarked_slug',
     150                Readme_Validator::instance()->translate_code_to_message(
     151                    'trademarked_slug',
     152                    [
     153                        'trademark' => $has_trademarked_slug,
     154                        'context'   => $slug
     155                    ]
     156                )
     157            );
    168158        }
    169159
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-trademarks.php

    r13460 r13462  
    171171     * @param string $check                     The plugin name to check.
    172172     * @param array|WP_User|WP_Post $exceptions An array of exceptions to the trademark checks, or a WP_User or WP_Post object to fetch their exceptions.
    173      * @return string|false The trademarked slug if found, false otherwise.
     173     * @return |false The trademarked slug if found, false otherwise.
    174174     */
    175175    public static function check( $check, $exceptions = [] ) {
     
    188188     * @param string                $plugin_slug The slug-like-text to check.
    189189     * @param array|WP_User|WP_Post $exceptions  An array of exceptions to the trademark checks, or a WP_User or WP_Post object to fetch their exceptions.
    190      * @return string|false The trademarked slug if found, false otherwise.
     190     * @return |false The trademarked slug if found, false otherwise.
    191191     */
    192192    public static function check_slug( $plugin_slug, $exceptions = [] ) {
     
    220220        }
    221221
    222         $has_trademarked_slug = false;
     222        $has_trademarked_slug = ;
    223223
    224224        foreach ( $trademarked_slugs as $trademark ) {
     
    226226                // Trademarks ending in "-" indicate slug cannot begin with that term.
    227227                if ( str_starts_with( $plugin_slug, $trademark ) ) {
    228                     $has_trademarked_slug = $trademark;
    229                     break;
     228                    $has_trademarked_slug[] = $trademark;
    230229                }
    231230
     
    246245
    247246                // The term cannot exist anywhere in the plugin slug, and it's not a for-use exception.
    248                 $has_trademarked_slug = $trademark;
    249                 break;
     247                $has_trademarked_slug[] = $trademark;
    250248            }
    251249        }
     
    254252        foreach ( $portmanteaus as $portmanteau ) {
    255253            if ( str_starts_with( $plugin_slug, $portmanteau ) ) {
    256                 $has_trademarked_slug = $portmanteau;
    257                 break;
     254                $has_trademarked_slug[] = $portmanteau . '-'; // State that the portmanteau cannnot start the text.
    258255            }
    259256        }
    260257
    261         return $has_trademarked_slug;
     258        return ;
    262259    }
    263260
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-validator.php

    r13460 r13462  
    396396
    397397            case 'trademarked_name':
    398                 $trademark = $data['trademark'];
    399                 $context   = $data['context'];
    400 
    401                 if ( str_ends_with( $trademark, '-' ) ) {
    402                     // Trademarks ending in "-" indicate slug cannot BEGIN with that term.
    403                     return sprintf(
    404                         /* translators: 1: plugin name/slug, 2: trademarked term, 3: plugin email address */
    405                         __( 'The plugin name includes a restricted term. Your chosen plugin name - %1$s - contains the restricted term "%2$s" and cannot be used to begin your slug, permalink, display name, or plugin name. We disallow the use of certain terms in ways that are abused, or potentially infringe on and/or are misleading with regards to trademarks. If you feel this is in error, such as you legally own the trademark for the term, please email us at %4$s and explain your situation.', 'wporg-plugins' ),
    406                         '<code>' . esc_html( $context ) . '</code>',
    407                         '<code>' . esc_html( trim( $trademark, '-' ) ) . '</code>',
    408                         '<code>plugins@wordpress.org</code>'
     398            case 'trademarked_slug':
     399            case 'trademarked':
     400                $trademarks = (array) $data['trademark'];
     401                $context    = $data['context'];
     402                $messages   = [];
     403   
     404                $cannot_start_with = array_filter( $trademarks, function( $slug ) {
     405                    return str_ends_with( $slug, '-' );
     406                } );
     407                $cannot_contain    = array_diff( $trademarks, $cannot_start_with );
     408
     409                if ( $cannot_start_with ) {
     410                    $messages[] = sprintf(
     411                        /* translators: 1: plugin slug, 2: trademarked term, 3: 'Plugin Name:', 4: plugin email address */
     412                        _n(
     413                            'Your chosen plugin name - %1$s - contains the restricted term "%2$s" which cannot be used to begin your permalink or display name. We disallow the use of certain terms in ways that are abused, or potentially infringe on and/or are misleading with regards to trademarks.',
     414                            'Your chosen plugin name - %1$s - contains the restricted terms "%2$s" which cannot be used to begin your permalink or display name. We disallow the use of certain terms in ways that are abused, or potentially infringe on and/or are misleading with regards to trademarks.',
     415                            count( $cannot_start_with ),
     416                            'wporg-plugins'
     417                        ),
     418                        '<code>' . $context . '</code>',
     419                        '<code>' . implode( '</code>", "<code>', $cannot_start_with ) . '</code>'
    409420                    );
    410                 } else {
    411                     // Trademarks that do NOT end in "-" indicate slug cannot contain term at all.
    412                     return sprintf(
    413                         /* translators: 1: plugin name/slug, 2: trademarked term, 3: plugin email address */
    414                         __( 'The plugin name includes a restricted term. Your chosen plugin name - %1$s - contains the restricted term "%2$s" and cannot be used at all in your plugin permalink nor the display name. If you feel this is in error, such as you legally own the trademark for a term, please email us at %3$s and explain your situation.', 'wporg-plugins' ),
    415                         '<code>' . esc_html( $context ) . '</code>',
    416                         '<code>' . esc_html( trim( $trademark, '-' ) ) . '</code>',
    417                         '<code>plugins@wordpress.org</code>'
     421                }
     422                if ( $cannot_contain ) {
     423                    $messages[] = sprintf(
     424                        /* translators: 1: plugin slug, 2: trademarked term, 3: 'Plugin Name:', 4: plugin email address */
     425                        _n(
     426                            'Your chosen plugin name - %1$s - contains the restricted term "%2$s", which cannot be used at all in your plugin permalink nor the display name.',
     427                            'Your chosen plugin name - %1$s - contains the restricted terms "%2$s", which cannot be used at all in your plugin permalink nor the display name.',
     428                            count( $cannot_contain ),
     429                            'wporg-plugins'
     430                        ),
     431                        '<code>' . $context . '</code>',
     432                        '<code>' . implode( '</code>", "<code>', $cannot_contain ) . '</code>'
    418433                    );
    419434                }
     435
     436
    420437
    421438            /* The are not generated by the Readme Parser, but rather the import parser. */
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php

    r13460 r13462  
    66use WordPressdotorg\Plugin_Directory\Readme\Parser;
    77use WordPressdotorg\Plugin_Directory\Plugin_Directory;
     8
    89use WordPressdotorg\Plugin_Directory\Tools;
    910use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
     
    168169        }
    169170
    170         // Make sure it doesn't use a TRADEMARK protected slug.
    171         if ( ! $updating_existing ) {
     171        // Make sure it doesn't use a TRADEMARK. We check the name first, and then the slug.
     172        $has_trademarked_slug = Trademarks::check( $this->plugin['Name'], wp_get_current_user() );
     173        $trademark_context    = $this->plugin['Name'];
     174
     175        if ( ! $has_trademarked_slug && ! $updating_existing ) {
     176            // Check the slug on new submissions in addition to the name.
    172177            $has_trademarked_slug = Trademarks::check_slug( $this->plugin_slug, wp_get_current_user() );
    173         } else {
    174             // If we're updating an existing plugin, we need to check the new name, but the slug may be different.
    175             $has_trademarked_slug = Trademarks::check( $this->plugin['Name'], wp_get_current_user() );
    176         }
    177 
    178         if ( false !== $has_trademarked_slug && ! $has_upload_token ) {
    179             $error = __( 'Error: The plugin name includes a restricted term.', 'wporg-plugins' );
    180 
    181             if ( $has_trademarked_slug === trim( $has_trademarked_slug, '-' ) ) {
    182                 // Trademarks that do NOT end in "-" indicate slug cannot contain term at all.
    183                 $message = sprintf(
    184                     /* translators: 1: plugin slug, 2: trademarked term, 3: 'Plugin Name:', 4: plugin email address */
    185                     __( 'Your chosen plugin name - %1$s - contains the restricted term "%2$s" and cannot be used at all in your plugin permalink nor the display name. To proceed with this submission you must remove "%2$s" from the %3$s line in both your main plugin file and readme entirely. Once you\'ve finished, you may upload the plugin again. Do not attempt to work around this by removing letters (i.e. WordPess) or using numbers (4 instead of A). Those are seen as intentional actions to avoid our restrictions, and are not permitted. If you feel this is in error, such as you legally own the trademark for a term, please email us at %4$s and explain your situation.', 'wporg-plugins' ),
    186                     '<code>' . esc_html( $this->plugin['Name'] ) . '</code>',
    187                     trim( $has_trademarked_slug, '-' ),
    188                     '<code>Plugin Name:</code>',
    189                     '<code>plugins@wordpress.org</code>'
    190                 );
    191             } else {
    192                 // Trademarks ending in "-" indicate slug cannot BEGIN with that term.
    193                 $message = sprintf(
    194                     /* translators: 1: plugin slug, 2: trademarked term, 3: 'Plugin Name:', 4: plugin email address */
    195                     __( 'Your chosen plugin name - %1$s - contains the restricted term "%2$s" and cannot be used to begin your permalink or display name. We disallow the use of certain terms in ways that are abused, or potentially infringe on and/or are misleading with regards to trademarks. In order to proceed with this submission, you must change the %3$s line in your main plugin file and readme to end with  "-%2$s" instead. Once you\'ve finished, you may upload the plugin again. If you feel this is in error, such as you legally own the trademark for the term, please email us at %4$s and explain your situation.', 'wporg-plugins' ),
    196                     '<code>' . esc_html( $this->plugin['Name'] ) . '</code>',
    197                     trim( $has_trademarked_slug, '-' ),
    198                     '<code>Plugin Name:</code>',
    199                     '<code>plugins@wordpress.org</code>'
    200                 );
    201             }
    202 
    203             return new WP_Error( 'trademarked_name', $error . ' ' . $message );
     178            $trademark_context    = $this->plugin_slug;
     179        }
     180
     181        if ( $has_trademarked_slug && ! $has_upload_token ) {
     182            $error = Readme_Validator::instance()->translate_code_to_message(
     183                'trademarked_slug',
     184                [
     185                    'trademark' => $has_trademarked_slug,
     186                    'context'   => $trademark_context,
     187                ]
     188            );
     189
     190            $to_proceed_text = sprintf(
     191                /* translators: 1: Plugin Name header */
     192                __( 'To proceed with this submission you must change your %1$s line in both your main plugin file and readme to abide by these requirements. Once you\'ve finished, you may upload the plugin again. Do not attempt to work around this by removing letters (i.e. WordPess) or using numbers (4 instead of A). Those are seen as intentional actions to avoid our restrictions, and are not permitted.', 'wporg-plugins' ),
     193                '<code>Plugin Name:</code>'
     194            );
     195            $in_error_text   = sprintf(
     196                /* translators: plugins@wordpress.org */
     197                __( 'If you feel this is in error, such as you legally own the trademark for the term, please email us at %1$s and explain your situation.', 'wporg-plugins' ),
     198                'plugins@wordpress.org'
     199            );
     200
     201            return new WP_Error( 'trademarked_name', "{$error} {$to_proceed_text} {$in_error_text}" );
    204202        }
    205203
Note: See TracChangeset for help on using the changeset viewer.