Making WordPress.org

Changeset 13460


Ignore:
Timestamp:
04/05/2024 03:44:27 AM (2 years ago)
Author:
dd32
Message:

Plugin Directory: Extract the trademark logic from the upload handler, into a generic class for use in the plugin directory.

See #5868, #6108.

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

Legend:

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

    r13109 r13460  
    143143                // Duplicated from Upload handler.
    144144                // Make sure it doesn't use a TRADEMARK protected slug.
    145                 if ( false !== $upload_handler->has_trademarked_slug()  ) {
     145                $has_trademarked_slug = Trademarks::check_slug( $slug, wp_get_current_user() );
     146                if ( $has_trademarked_slug ) {
    146147                        $error = __( 'That plugin slug includes a restricted term.', 'wporg-plugins' );
    147148
    148                         if ( $upload_handler->has_trademarked_slug() === trim( $upload_handler->has_trademarked_slug(), '-' ) ) {
     149                        if ( $has_trademarked_slug === trim( $has_trademarked_slug, '-' ) ) {
    149150                                // Trademarks that do NOT end in "-" indicate slug cannot contain term at all.
    150151                                $message = sprintf(
     
    152153                                        __( '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' ),
    153154                                        '<code>' . $slug . '</code>',
    154                                         trim( $upload_handler->has_trademarked_slug(), '-' )
     155                                        '<code>' . trim( $has_trademarked_slug, '-' ) . '</code>'
    155156                                );
    156157                        } else {
     
    160161                                        __( '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' ),
    161162                                        '<code>' . $slug . '</code>',
    162                                         trim( $upload_handler->has_trademarked_slug(), '-' )
     163                                        '<code>' . trim( $has_trademarked_slug, '-' ) . '</code>'
    163164                                );
    164165                        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-validator.php

    r13443 r13460  
    33
    44use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
     5use WordPressdotorg\Plugin_Directory\Trademarks;
    56
    67/**
     
    9495                if ( isset( $readme->warnings['invalid_plugin_name_header'] ) ) {
    9596                        $errors['invalid_plugin_name_header'] = $readme->warnings['invalid_plugin_name_header'];
    96                 } elseif (  empty( $readme->name ) ) {
     97                } elseif ( empty( $readme->name ) ) {
    9798                        $errors['invalid_plugin_name_header'] = true;
     99                }
     100
     101                if (
     102                        empty( $errors['invalid_plugin_name_header'] ) &&
     103                        ( $trademark_check = Trademarks::check( $readme->name, wp_get_current_user() ) )
     104                ) {
     105                        $errors['trademarked_name'] = [
     106                                'trademark' => $trademark_check,
     107                                'context'   => $readme->name,
     108                                'where'     => 'readme',
     109                        ];
    98110                }
    99111
     
    383395                                );
    384396
     397                        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>'
     409                                        );
     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>'
     418                                        );
     419                                }
     420
    385421                        /* The are not generated by the Readme Parser, but rather the import parser. */
    386422                        case 'invalid_update_uri':
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php

    r13308 r13460  
    88use WordPressdotorg\Plugin_Directory\Tools;
    99use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
     10use WordPressdotorg\Plugin_Directory\Trademarks;
    1011use WordPressdotorg\Plugin_Directory\Admin\Tools\Upload_Token;
    1112use WordPressdotorg\Plugin_Directory\Clients\HelpScout;
     
    169170                // Make sure it doesn't use a TRADEMARK protected slug.
    170171                if ( ! $updating_existing ) {
    171                         $has_trademarked_slug = $this->has_trademarked_slug( $this->plugin_slug );
     172                        $has_trademarked_slug = Trademarks::check_slug( $this->plugin_slug, wp_get_current_user() );
    172173                } else {
    173174                        // If we're updating an existing plugin, we need to check the new name, but the slug may be different.
    174                         $has_trademarked_slug = $this->has_trademarked_slug(
    175                                 $this->generate_plugin_slug( $this->plugin['Name'] )
    176                         );
    177                 }
     175                        $has_trademarked_slug = Trademarks::check( $this->plugin['Name'], wp_get_current_user() );
     176                }
     177
    178178                if ( false !== $has_trademarked_slug && ! $has_upload_token ) {
    179179                        $error = __( 'Error: The plugin name includes a restricted term.', 'wporg-plugins' );
     
    618618
    619619        /**
    620          * Whether the uploaded plugin uses a trademark in the slug.
    621          *
    622          * @return string|false The trademarked slug if found, false otherwise.
    623          */
    624         public function has_trademarked_slug( $plugin_slug = false ) {
    625                 $plugin_slug = $plugin_slug ?: $this->plugin_slug;
    626 
    627                 $trademarked_slugs = array(
    628                         'adobe-',
    629                         'adsense-',
    630                         'advanced-custom-fields-',
    631                         'adwords-',
    632                         'akismet-',
    633                         'all-in-one-wp-migration',
    634                         'amazon-',
    635                         'android-',
    636                         'apple-',
    637                         'applenews-',
    638                         'applepay-',
    639                         'aws-',
    640                         'azon-',
    641                         'bbpress-',
    642                         'bing-',
    643                         'booking-com',
    644                         'bootstrap-',
    645                         'buddypress-',
    646                         'chatgpt-',
    647                         'chat-gpt-',
    648                         'cloudflare-',
    649                         'contact-form-7-',
    650                         'cpanel-',
    651                         'disqus-',
    652                         'divi-',
    653                         'dropbox-',
    654                         'easy-digital-downloads-',
    655                         'elementor-',
    656                         'envato-',
    657                         'fbook',
    658                         'facebook',
    659                         'fb-',
    660                         'fb-messenger',
    661                         'fedex-',
    662                         'feedburner',
    663                         'firefox-',
    664                         'fontawesome-',
    665                         'font-awesome-',
    666                         'ganalytics-',
    667                         'gberg',
    668                         'github-',
    669                         'givewp-',
    670                         'google-',
    671                         'googlebot-',
    672                         'googles-',
    673                         'gravity-form-',
    674                         'gravity-forms-',
    675                         'gravityforms-',
    676                         'gtmetrix-',
    677                         'gutenberg',
    678                         'guten-',
    679                         'hubspot-',
    680                         'ig-',
    681                         'insta-',
    682                         'instagram',
    683                         'internet-explorer-',
    684                         'ios-',
    685                         'jetpack-',
    686                         'macintosh-',
    687                         'macos-',
    688                         'mailchimp-',
    689                         'microsoft-',
    690                         'ninja-forms-',
    691                         'oculus',
    692                         'onlyfans-',
    693                         'only-fans-',
    694                         'opera-',
    695                         'paddle-',
    696                         'paypal-',
    697                         'pinterest-',
    698                         'plugin',
    699                         'skype-',
    700                         'stripe-',
    701                         'tiktok-',
    702                         'tik-tok-',
    703                         'trustpilot',
    704                         'twitch-',
    705                         'twitter-',
    706                         'tweet',
    707                         'ups-',
    708                         'usps-',
    709                         'vvhatsapp',
    710                         'vvcommerce',
    711                         'vva-',
    712                         'vvoo',
    713                         'wa-',
    714                         'webpush-vn',
    715                         'wh4tsapps',
    716                         'whatsapp',
    717                         'whats-app',
    718                         'watson',
    719                         'windows-',
    720                         'wocommerce',
    721                         'woocom-',
    722                         'woocommerce',  // technically ending with '-for-woocommerce' is allowed.
    723                         'woocomerce',
    724                         'woo-commerce',
    725                         'woo-',
    726                         'wo-',
    727                         'wordpress',
    728                         'wordpess',
    729                         'wpress',
    730                         'wp-',
    731                         'wp-mail-smtp-',
    732                         'yandex-',
    733                         'yahoo-',
    734                         'yoast',
    735                         'youtube-',
    736                         'you-tube-',
    737                 );
    738 
    739                 // Domains from which exceptions would be accepted.
    740                 $trademark_exceptions = array(
    741                         'adobe.com'             => array( 'adobe' ),
    742                         'automattic.com'        => array( 'akismet', 'akismet-', 'jetpack', 'jetpack-', 'wordpress', 'wp-', 'woo', 'woo-', 'woocommerce', 'woocommerce-' ),
    743                         'facebook.com'          => array( 'facebook', 'instagram', 'oculus', 'whatsapp' ),
    744                         'support.microsoft.com' => array( 'bing-', 'microsoft-' ),
    745                         'trustpilot.com'        => array( 'trustpilot' ),
    746                         'microsoft.com'         => array( 'bing-', 'microsoft-' ),
    747                         'yandex-team.ru'        => array( 'yandex' ),
    748                         'yoast.com'             => array( 'yoast' ),
    749                         'opera.com'             => array( 'opera-' ),
    750                         'adobe.com'                             => array( 'adobe-' ),
    751                 );
    752 
    753                 // Trademarks that are allowed as 'for-whatever' ONLY.
    754                 $for_use_exceptions = array(
    755                         'woocommerce',
    756                 );
    757 
    758                 // Commonly used 'combo' names (to prevent things like 'woopress').
    759                 $portmanteaus = array(
    760                         'woo',
    761                 );
    762 
    763                 $has_trademarked_slug = false;
    764 
    765                 foreach ( $trademarked_slugs as $trademark ) {
    766                         if ( '-' === $trademark[-1] ) {
    767                                 // Trademarks ending in "-" indicate slug cannot begin with that term.
    768                                 if ( 0 === strpos( $plugin_slug, $trademark ) ) {
    769                                         $has_trademarked_slug = $trademark;
    770                                         break;
    771                                 }
    772                         } elseif ( false !== strpos( $plugin_slug, $trademark ) ) {
    773                                 // Otherwise, the term cannot appear anywhere in slug.
    774                                 $has_trademarked_slug = $trademark;
    775                                 break;
    776                         }
    777                 }
    778 
    779                 // check for 'for-TRADEMARK' exceptions.
    780                 if ( $has_trademarked_slug && in_array( $has_trademarked_slug, $for_use_exceptions ) ) {
    781                         $for_trademark = '-for-' . $has_trademarked_slug;
    782                         // At this point we might be okay, but there's one more check.
    783                         if ( $for_trademark === substr( $plugin_slug, -1 * strlen( $for_trademark ) ) ) {
    784                                 // Yes the slug ENDS with 'for-TRADEMARK'.
    785                                 $has_trademarked_slug = false;
    786                         }
    787                 }
    788 
    789                 // Check portmanteaus.
    790                 foreach ( $portmanteaus as $portmanteau ) {
    791                         if ( 0 === strpos( $plugin_slug, $portmanteau ) ) {
    792                                 $has_trademarked_slug = $portmanteau;
    793                                 break;
    794                         }
    795                 }
    796 
    797                 // Get the user email domain.
    798                 list( ,$user_email_domain ) = explode( '@', wp_get_current_user()->user_email, 2 );
    799 
    800                 // If email domain is on our list of possible exceptions, we have an extra check.
    801                 if ( $has_trademarked_slug && array_key_exists( $user_email_domain, $trademark_exceptions ) ) {
    802                         // If $has_trademarked_slug is in the array for that domain, they can use the term.
    803                         if ( in_array( $has_trademarked_slug, $trademark_exceptions[ $user_email_domain ] ) ) {
    804                                 $has_trademarked_slug = false;
    805                         }
    806                 }
    807 
    808                 return $has_trademarked_slug;
    809         }
    810 
    811         /**
    812620         * Sends a plugin through Plugin Check.
    813621         *
Note: See TracChangeset for help on using the changeset viewer.