Making WordPress.org

Changeset 13308


Ignore:
Timestamp:
03/12/2024 02:27:28 AM (9 months ago)
Author:
dd32
Message:

Plugin Directory: Upload: Don't overwrite the post_date field when uploading a new version of the plugin.

This will allow for more performant queries for pending plugins.

See #7384

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

Legend:

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

    r13259 r13308  
    18341834        $slug  = $args['post_name'] ?: sanitize_title( $title );
    18351835
     1836        // Remove null items (date-related fields) to fallback to the defaults below.
     1837        $args = array_filter(
     1838            $args,
     1839            function( $item ) {
     1840                return ! is_null( $item );
     1841            }
     1842        );
     1843
    18361844        $post_date     = current_time( 'mysql' );
    18371845        $post_date_gmt = current_time( 'mysql', 1 );
     
    18471855        ) );
    18481856
    1849         $update = ! empty( $args['ID'] );
    18501857        $result = wp_insert_post( $args, true );
    18511858
    18521859        if ( ! is_wp_error( $result ) ) {
    18531860            wp_cache_set( $result, $slug, 'plugin-slugs' );
     1861
    18541862            $result = get_post( $result );
    1855 
    1856             if ( ! $update ) {
    1857                 $owner = get_userdata( $result->post_author );
    1858                 Tools::audit_log( sprintf(
    1859                     'Submitted by <a href="%s">%s</a>.',
    1860                     esc_url( 'https://profiles.wordpress.org/' . $owner->user_nicename . '/' ),
    1861                     $owner->user_login
    1862                 ), $result->ID );
    1863             }
    18641863        }
    18651864
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-upload-handler.php

    r13202 r13308  
    66use WordPressdotorg\Plugin_Directory\Readme\Parser;
    77use WordPressdotorg\Plugin_Directory\Plugin_Directory;
     8use WordPressdotorg\Plugin_Directory\Tools;
    89use WordPressdotorg\Plugin_Directory\Tools\Filesystem;
    910use WordPressdotorg\Plugin_Directory\Admin\Tools\Upload_Token;
     
    422423
    423424        $post_args = array(
    424             'ID'           => $plugin_post->ID ?? 0,
    425             'post_title'   => $this->plugin['Name'],
    426             'post_name'    => $this->plugin_slug,
    427             'post_status'  => $plugin_post->post_status ?? 'new',
    428             'post_content' => $content,
    429             'post_excerpt' => $this->plugin['Description'],
     425            'ID'            => $plugin_post->ID ?? 0,
     426            'post_title'    => $this->plugin['Name'],
     427            'post_name'     => $this->plugin_slug,
     428            'post_status'   => $plugin_post->post_status ?? 'new',
     429            'post_content'  => $content,
     430            'post_excerpt'  => $this->plugin['Description'],
     431            'post_date'     => $plugin_post->post_date ?? null,
     432            'post_date_gmt' => $plugin_post->post_date_gmt ?? null,
    430433            // 'tax_input'    => wp_unslash( $_POST['tax_input'] ), // for category selection
    431434            'meta_input'   => array(
     
    466469
    467470        // First time submission, track some additional metadata.
    468         if ( ! $plugin_post ) {
     471        if ( ! $updating_existing ) {
    469472            $post_args['meta_input']['_author_ip']        = preg_replace( '/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR'] );
    470473            $post_args['meta_input']['_submitted_date']   = time();
     
    477480        if ( is_wp_error( $plugin_post ) ) {
    478481            return $plugin_post;
     482        }
     483
     484        // Record the submitter.
     485        if ( ! $updating_existing ) {
     486            Tools::audit_log(
     487                sprintf(
     488                    'Submitted by <a href="%s">%s</a>.',
     489                    esc_url( 'https://profiles.wordpress.org/' . wp_get_current_user()->user_nicename . '/' ),
     490                    wp_get_current_user()->user_login
     491                ),
     492                $plugin_post->ID
     493            );
    479494        }
    480495
Note: See TracChangeset for help on using the changeset viewer.