Making WordPress.org

Ticket #1570: 1570.diff

File 1570.diff, 4.3 KB (added by obenland, 8 years ago)
  • wp-content/plugins/plugin-directory/admin/class-customizations.php

     
    174174                        $query->query_vars['post_status'] = array( 'publish', 'future', 'draft', 'pending', 'disabled', 'closed', 'rejected', 'approved' );
    175175                }
    176176
     177                // Make it possible to search for plugins that were submitted from a specific IP.
     178                if ( ! empty( $query->query['s'] ) && filter_var( $query->query['s'], FILTER_VALIDATE_IP ) ) {
     179                        $query->query_vars['meta_key']   = '_author_ip';
     180                        $query->query_vars['meta_value'] = $query->query_vars['s'];
     181                        unset( $query->query_vars['s'] );
     182
     183                        add_filter( 'get_search_query', function() use ( $query ) {
     184                                return esc_html( $query->query_vars['meta_value'] );
     185                        } );
     186                }
     187
    177188                $user = wp_get_current_user();
    178189
    179190                if ( ! current_user_can( 'plugin_approve' ) && empty( $query->query['post_status']) || ( isset( $query->query['author'] ) && $query->query['author'] == $user->ID ) ) {
  • wp-content/plugins/plugin-directory/admin/metabox/class-author-card.php

     
    7878                        echo '<p>This user is: <strong>' . implode( ', ', $unsavory ) . '</strong></p>';
    7979                }
    8080
    81                 $user_ips = array();// $wpdb->get_col( $wpdb->prepare( 'SELECT DISTINCT poster_ip FROM plugin_2_posts WHERE poster_id = %s', $author->ID ) );
    82                 $user_ips = array_filter( $user_ips, 'strlen' );
     81                $post_ids = get_posts( array(
     82                        'fields'         => 'ids',
     83                        'post_type'      => 'plugin',
     84                        'author'         => $author->ID,
     85                        'meta_key'       => '_author_ip',
     86                        'posts_per_page' => -1,
     87                ) );
     88
     89                $user_ips = array_unique( array_map( function( $post_id ) {
     90                        return get_post_meta( $post_id, '_author_ip', true );
     91                }, $post_ids ) );
     92
    8393                if ( $user_ips ) :
    8494                        sort( $user_ips, SORT_NUMERIC );
    8595
    86                         $user_ips = array_map( array( 'Author_Card', 'link_ip' ), $user_ips );
    87 
    88                         echo '<p>IPs : ' . implode( ', ', $user_ips ) . '</p>';
     96                        printf( '<p>IPs : %s</p>', implode( ', ', array_map( array( __NAMESPACE__ . '\Author_Card', 'link_ip' ), $user_ips ) ) );
    8997                endif;
    9098
    9199                if ( $author->user_pass == '~~~' ) : ?>
     
    190198                 */
    191199                do_action( 'wporg_plugins_author_card', $post, $author, $all_plugins );
    192200        }
     201
     202        /**
     203         * Builds a link to a list of plugins submitted from a given IP.
     204         *
     205         * @param string $ip IP address of the plugin author.
     206         * @return string
     207         */
     208        protected static function link_ip( $ip ) {
     209                return sprintf( '<a href="%1$s">%2$s</a>', esc_url( add_query_arg( array(
     210                        'post_type' => 'plugin',
     211                        's'         => $ip,
     212                ), admin_url( 'edit.php' ) ) ), $ip );
     213        }
    193214}
  • wp-content/plugins/plugin-directory/cli/class-import.php

     
    170170                }
    171171                update_post_meta( $plugin->ID, 'assets_banners_color', wp_slash( $banner_average_color ) );
    172172
     173                $ip = $wpdb->get_var( $wpdb->prepare( 'SELECT poster_ip FROM ' . PLUGINS_TABLE_PREFIX . 'posts WHERE topic_id = %s', $topic->topic_id ) );
     174                if ( $ip ) {
     175                        update_post_meta( $plugin->ID, '_author_ip', wp_slash( $ip ) );
     176                }
     177
    173178                // Give committers a role on this site.
    174179                foreach ( Tools::get_plugin_committers( $plugin_slug ) as $committer ) {
    175180                        // @todo: Enable.
  • wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php

     
    203203                                        'assets_banners_color'     => false,
    204204                                        'support_threads'          => 0,
    205205                                        'support_threads_resolved' => 0,
     206                                        '_author_ip'               => preg_replace( '/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR'] ),
    206207                                ),
    207208                        ) );
    208209                        if ( is_wp_error( $plugin_post ) ) {