WordPress.org

Making WordPress.org

Ticket #2860: plugin-dir-plugin-closed-date.patch

File plugin-dir-plugin-closed-date.patch, 1.5 KB (added by joostdevalk, 8 months ago)

Patch to add plugin close date to a post meta

  • wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    diff --git wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
    index 2aa264c4..f2af213e 100644
    class Plugin_Directory { 
    340340                        'label_count'               => _n_noop( 'Rejected <span class="count">(%s)</span>', 'Rejected <span class="count">(%s)</span>', 'wporg-plugins' ),
    341341                ) );
    342342
     343                add_action( 'transition_post_status', array( $this, 'plugin_close_date' ), 10, 3 );
     344
    343345                /**
    344346                 * TODO
    345347                 * Use register_rest_field() to add array and object meta data to the API:
    class Plugin_Directory { 
    13021304
    13031305                return $result;
    13041306        }
     1307
     1308        /**
     1309         * Save the date a plugin was closed and delete that date when it's reopened.
     1310         *
     1311         * @param string  $new_status The new plugin status.
     1312         * @param string  $old_status The old plugin status.
     1313         * @param WP_Post $post Post data.
     1314         */
     1315        public function plugin_close_date( $new_status, $old_status, $post ) {
     1316                if ( in_array( $new_status, array( 'closed', 'disabled' ) ) ) {
     1317                        update_post_meta( $post->ID, 'plugin_closed_date', current_time( 'mysql' ) );
     1318                }
     1319                if ( 'publish' === $new_status && in_array( $old_status, array( 'closed', 'disabled' ) ) ) {
     1320                        delete_post_meta( $post->ID, 'plugin_closed_date' );
     1321                }
     1322        }
    13051323}