Making WordPress.org


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.