Making WordPress.org


Ignore:
Timestamp:
04/05/2024 03:44:27 AM (6 months 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/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':
Note: See TracChangeset for help on using the changeset viewer.