Making WordPress.org

Ticket #2677: 2677.diff

File 2677.diff, 6.4 KB (added by Ipstenu, 6 years ago)

Correct email based on post status

  • trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-review-tools.php

     
    11<?php
    22namespace WordPressdotorg\Plugin_Directory\Admin\Metabox;
    33
     4use WordPressdotorg\Plugin_Directory\Tools;
     5
    46/**
    57 * The Plugin Review metabox.
    68 *
     
    79 * @package WordPressdotorg\Plugin_Directory\Admin\Metabox
    810 */
    911class Review_Tools {
    10         static function display() {
     12
     13        static function display() {             
    1114                $post = get_post();
     15                $author = get_user_by( 'id', $post->post_author );
     16                $slug = $post->post_name;
     17                $author_plugins = get_posts( array(
     18                        'author'       => $author->ID,
     19                        'post_type'    => 'plugin',
     20                        'post__not_in' => array( $post->ID ),
     21                ) );
     22                $author_commit  = Tools::get_users_write_access_plugins( $author );
    1223
    1324                $zip_url = '';
    1425                foreach ( get_attached_media( 'application/zip', $post ) as $zip_file ) {
     
    2435                                sprintf( '<a href="%s">%s</a>', esc_url( $zip_url ), esc_html( $zip_url ) )
    2536                        );
    2637                }
     38               
     39                if ( $post->post_status == 'draft' || $post->post_status == 'pending' ) {
     40                       
     41                        $flagged = array(
     42                                'low' => array (),
     43                                'med' => array (),
     44                                'high' => array (),
     45                        );
     46                                               
     47                        echo "<p><strong>Flagged!</strong>";
     48               
     49                        $reserved_slugs = array (
     50                                // Commonly abused/misused terms
     51                                'wordpress', 'woocommerce', 'google', 'youtube', 'twitter', 'facebook', 'yoast', 'jetpack',
     52                        );
    2753
    2854                if ( 'pending' != $post->post_status ) {
    2955                        echo "<ul>
     
    3662                        echo '<p>' . strip_tags( $post->post_excerpt ) . '</p>';
    3763                }
    3864
     65                        // User account was registered less than 2 weeks ago (but longer than 3 days) (user is still fairly new)
     66                        $twoweeksago  = time() - (2 * 7 * 24 * 60 * 60);
     67                        $threedaysago = time() - (3 * 1 * 24 * 60 * 60);
     68                        if ( strtotime($author->user_registered) > $twoweeksago && strtotime($author->user_registered) < $threedaysago )  array_push( $flagged['low'], __( 'account registered less than 2 weeks ago', 'wporg-plugins' ) );
     69                        if ( strtotime($author->user_registered) > $threedaysago ) array_push( $flagged['low'], __( 'account registered less than 3 days ago', 'wporg-plugins' ) );
     70
     71                        // Username ends in numbers
     72                        if ( is_numeric(substr($author->user_login, -1, 1) ) ) array_push( $flagged['low'], __( 'username ends in numbers', 'wporg-plugins' ) );
     73                       
     74                        // User has no URL
     75                        if ( empty( $author->user_url ) ) array_push( $flagged['low'], __( 'account has no URL', 'wporg-plugins' ) );
     76                       
     77                        // URL matches the weird list
     78                        $weird_urls = array (
     79                                'blogger', 'blogspot', 'example.com', 'weebly', 'squarespace', 'medium.com', 'yahoo.com',
     80                                'mail.com', 'example.org',
     81                        );
     82                        foreach ( $weird_urls as $url ) {
     83                                if ( stripos( $author->user_url , $url ) !== false )
     84                                        array_push( $flagged['med'], __( 'account URL contains ', 'wporg-plugins' ) . $url );
     85                                if ( stripos( $author->user_email , $url ) !== false )
     86                                        array_push( $flagged['med'], __( 'account email contains ', 'wporg-plugins' ) . $url );
     87                        }
     88               
     89                        // Reserved slugs are also often abused domain names (trademark law sucks)
     90                        foreach ( $reserved_slugs as $url ) {
     91                                if ( stripos( $author->user_url , $url ) !== false )
     92                                        array_push( $flagged['high'], __( 'account URL contains ', 'wporg-plugins' ) . $url );
     93                                if ( stripos( $author->user_email , $url ) !== false )
     94                                        array_push( $flagged['med'], __( 'account email contains ', 'wporg-plugins' ) . $url );
     95                        }
     96
     97                        // User Behavior
     98                        // If FORUM ROLE is blocked
     99                        if ( defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) ) {
     100                                $user = new \WP_User( $post->post_author, '', WPORG_SUPPORT_FORUMS_BLOGID );
     101                                if ( ! empty( $user->allcaps['bbp_blocked'] ) )
     102                                        array_push( $flagged['high'], __( 'user is blocked', 'wporg-plugins' ) );       
     103                        }
     104                       
     105                        // No plugins
     106                        if ( empty( $author_commit ) && empty( $author_plugins ) )
     107                                array_push( $flagged['low'], __( 'user has no plugins', 'wporg-plugins' ) );
     108
     109                        // Echo flag results (everyone pretty much has at least one)
     110                        echo "<ul class=\"plugin-flagged\">";
     111                        $noflag = 0;
     112                        foreach ( $flagged as $flag => $reasons ) {
     113                                if (count($reasons) > '0') {
     114                                        $allreasons = array();
     115                                        echo "<li class=\"plugin-flagged-".$flag."\"><strong>".strtoupper($flag)." (".count($reasons)."):</strong> ";
     116                                        foreach( $reasons as $reason) {
     117                                                $allreasons[] = $reason;
     118                                        }
     119                                        echo implode( '; ', $allreasons ) . "</li>";
     120                                } else {
     121                                        $noflag++;
     122                                }
     123                        }
     124                       
     125                        if ($noflag == '3' ) {
     126                                ?><li><?php _e( 'Nothing flagged! You found Matt!', 'wporg-plugins' ); ?></li><?php
     127                        }
     128                       
     129                        echo "</ul>";
     130
     131                } else {
     132                        echo "<ul>
     133                                <li><a href='https://plugins.trac.wordpress.org/log/{$post->post_name}/'>" . __( 'Development Log', 'wporg-plugins' ) . "</a></li>
     134                                <li><a href='https://plugins.svn.wordpress.org/{$post->post_name}/'>" . __( 'Subversion Repository', 'wporg-plugins' ) . "</a></li>
     135                                <li><a href='https://plugins.trac.wordpress.org/browser/{$post->post_name}/'>" . __( 'Browse in Trac', 'wporg-plugins' ) . '</a></li>
     136                        </ul>';
     137                }
     138
    39139                add_filter( 'wp_comment_reply', function( $string ) use ( $post ) {
    40140                        $author = get_user_by( 'id', $post->post_author );
     141                       
     142                        $type   = 'Notice';
     143                        if ( $post->post_status == 'draft' || $post->post_status == 'pending' ) {
     144                                $type = 'Request';
     145                        }
     146                       
    41147                        ?>
    42148                        <form id="contact-author" class="contact-author" method="POST" action="https://supportpress.wordpress.org/plugins/thread-new.php">
    43149                                <input type="hidden" name="to_email" value="<?php echo esc_attr( $author->user_email ); ?>" />
    44150                                <input type="hidden" name="to_name" value="<?php echo esc_attr( $author->display_name ); ?>" />
    45                                 <input type="hidden" name="subject" value="<?php printf( esc_attr__( '[WordPress Plugin Directory] Request: %s', 'wporg-plugins' ), $post->post_title ); ?>" />
     151                                <input type="hidden" name="subject" value="<?php printf( esc_attr__( '[WordPress Plugin Directory] %s: %s', 'wporg-plugins' ), $notice, $post->post_title ); ?>" />
    46152                                <button class="button button-primary" type="submit"><?php _e( 'Contact plugin author', 'wporg-plugins' ); ?></button>
    47153                        </form>
    48154                        <?php
    49155                        return $string;
    50                 } );
     156                }
     157                );
    51158        }
    52 }
    53159
     160}
     161 No newline at end of file