Making WordPress.org

Changeset 12166


Ignore:
Timestamp:
10/31/2022 05:14:50 AM (4 years ago)
Author:
dd32
Message:

Plugin Directory: Add a button in wp-admin to trigger a plugin import from SVN.

Fixes #5277.

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

Legend:

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

    r11312 r12166  
    6161                add_filter( 'wp_ajax_delete-support-rep', array( __NAMESPACE__ . '\Metabox\Support_Reps', 'remove_support_rep' ) );
    6262                add_action( 'wp_ajax_plugin-author-lookup', array( __NAMESPACE__ . '\Metabox\Author', 'lookup_author' ) );
     63                add_action( 'wp_ajax_plugin-svn-sync', array( __NAMESPACE__ . '\Metabox\Review_Tools', 'svn_sync' ) );
    6364
    6465                add_action( 'save_post', array( __NAMESPACE__ . '\Metabox\Release_Confirmation', 'save_post' ) );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-review-tools.php

    r10184 r12166  
    1010use WordPressdotorg\Plugin_Directory\Template;
    1111use WordPressdotorg\Plugin_Directory\Tools;
     12use WordPressdotorg\Plugin_Directory\Jobs\Plugin_Import;
    1213
    1314/**
    … …  
    282283                                <?php endif; ?>
    283284                        </ul>
     285                        <p>
     286                                <?php
     287                                $svn_sync_url = add_query_arg(
     288                                        array(
     289                                                'action'      => 'plugin-svn-sync',
     290                                                'slug'        => $post->post_name,
     291                                                '_ajax_nonce' => wp_create_nonce( 'wporg_plugins_svn_sync-' . $post->post_name ),
     292                                        ),
     293                                        admin_url( 'admin-ajax.php' )
     294                                );
     295                                ?>
     296                                <a id="svn-sync" class="button button-secondary" href="<?php echo esc_url( $svn_sync_url ); ?>">Trigger svn sync</a>
     297                                <script>
     298                                jQuery( function( $ ) {
     299                                        $( '#svn-sync' ).click( function( e ) {
     300                                                e.preventDefault();
     301
     302                                                var $this = $(this),
     303                                                    url = $this.attr('href');
     304
     305                                                $this.addClass( 'disabled' );
     306                                                $this.prop( 'href', '' );
     307
     308                                                if ( url ) {
     309                                                        $.get( url ).then( function( response ) {
     310                                                                alert( response );
     311                                                        } );
     312                                                }
     313                                        } );
     314                                });
     315                                </script>
     316                        </p>
    284317                        <?php
    285318                }
    … …  
    329362                } );
    330363        }
     364
     365        /**
     366         * admin-ajax.php handler for queueing a plugin import.
     367         */
     368        static function svn_sync() {
     369                $plugin_slug = sanitize_text_field( wp_unslash( $_REQUEST['slug'] ) );
     370
     371                check_ajax_referer( 'wporg_plugins_svn_sync-' . $plugin_slug );
     372
     373                Plugin_Import::queue(
     374                        $plugin_slug,
     375                        array(
     376                                'tags_touched' => [
     377                                        'trunk'
     378                                ],
     379                                'source' => 'wp-admin svn-sync button'
     380                        )
     381                );
     382
     383                die( "Queued SVN import for {$plugin_slug}." );
     384        }
    331385}
Note: See TracChangeset for help on using the changeset viewer.