Making WordPress.org

Ticket #5535: 5535.patch

File 5535.patch, 5.3 KB (added by Clorith, 2 years ago)
  • new file sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-move-topic-to-extension-forum.php

    <+>UTF-8
    diff --git a/sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-move-topic-to-extension-forum.php b/sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-move-topic-to-extension-forum.php
    new file mode 100644
    - +  
     1<?php
     2
     3namespace WordPressdotorg\Forums;
     4
     5class Move_Topic_To_Extension_Forum {
     6
     7        public function __construct() {
     8                // The plugin and theme forums only exist on the primary forums on WordPress.org/support.
     9                if ( defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) && WPORG_SUPPORT_FORUMS_BLOGID == get_current_blog_id() ) {
     10                        add_action( 'bbp_theme_after_topic_form_forum', array( $this, 'add_edit_topic_field' ) );
     11
     12                        add_action( 'bbp_edit_topic_post_extras', array( $this, 'maybe_move_topic' ) );
     13                }
     14        }
     15
     16        /**
     17         * Add the form field for assigning a new plugin or theme location for a topic.
     18         *
     19         * @return void
     20         */
     21        public function add_edit_topic_field() {
     22                // Only add this field to the edit form, and only for moderators.
     23                if ( ! bbp_is_topic_edit() || ! current_user_can( 'moderate' ) ) {
     24                        return;
     25                }
     26
     27                ?>
     28
     29                <p>
     30                        <label for="move_topic_to_extension">
     31                                <?php esc_html_e( 'Move topic to this plugin or theme:', 'wporg-forums' ); ?>
     32                        </label>
     33                        <br>
     34                        <input type="text" size="40" name="move_topic_to_extension" id="move_topic_to_extension" placeholder="https://wordpress.org/plugins/gutenberg/" aria-describedby="move_topic_to_extension_description">
     35                        <br>
     36                        <em id="move_topic_to_extension_description">
     37                                <?php esc_html_e( 'Put in the link to the plugin or theme page on WordPress.org that this topic relates to.', 'wporg-forums' ); ?>
     38                        </em>
     39                </p>
     40
     41                <?php
     42
     43        }
     44
     45        /**
     46         * Change the forum associated with a plugin or theme if applicable.
     47         *
     48         * @param int $topic_id The topic ID being edited.
     49         *
     50         * @return void
     51         */
     52        public function maybe_move_topic( $topic_id ) {
     53                if ( ! current_user_can( 'moderate' ) ) {
     54                        return;
     55                }
     56
     57                if ( ! empty( $_POST['move_topic_to_extension'] ) ) {
     58                        preg_match( '/wordpress\.org\/(?P<type>plugins|themes)\/(?P<slug>.+)\/?/si', $_POST['move_topic_to_extension'], $move_attributes );
     59
     60                        if ( isset( $move_attributes['type'] ) && ! empty( $move_attributes['type'] ) ) {
     61                                switch ( $move_attributes['type'] ) {
     62                                        case 'plugins':
     63                                                // Clear any theme reference, if set.
     64                                                wp_set_post_terms( $topic_id, '', 'topic-theme', false );
     65                                                // Override the plugin tag with only the new one.
     66                                                wp_set_post_terms( $topic_id, sanitize_title( $move_attributes['slug'] ), 'topic-plugin', false );
     67                                                break;
     68                                        case 'themes':
     69                                                // Clear any plugin reference, if set.
     70                                                wp_set_post_terms( $topic_id, '', 'topic-plugin', false );
     71                                                // Override the theme tag with only the new one.
     72                                                wp_set_post_terms( $topic_id, sanitize_title( $move_attributes['slug'] ), 'topic-theme', false );
     73                                                break;
     74                                }
     75                        } else {
     76                                error_log( 'No matching url ');
     77                        }
     78                }
     79        }
     80
     81}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-plugin.php

    <+>UTF-8
    diff --git a/sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-plugin.php b/sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-plugin.php
    a b  
    3737         * Instantiate a new Plugin object.
    3838         */
    3939        private function __construct() {
    40                 $this->users        = new Users;
    41                 $this->user_notes   = new User_Notes;
    42                 $this->moderators   = new Moderators;
    43                 $this->hooks        = new Hooks;
    44                 $this->report_topic = new Report_Topic;
    45                 $this->nsfw_handler = new NSFW_Handler;
     40                $this->users             = new Users;
     41                $this->user_notes        = new User_Notes;
     42                $this->moderators        = new Moderators;
     43                $this->hooks             = new Hooks;
     44                $this->report_topic      = new Report_Topic;
     45                $this->nsfw_handler      = new NSFW_Handler;
     46                $this->move_to_extension = new Move_Topic_To_Extension_Forum;
    4647
    4748                // These modifications are specific to https://wordpress.org/support/
    4849                $blog_id = get_current_blog_id();
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/support-forums.php

    <+>UTF-8
    diff --git a/sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/support-forums.php b/sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/support-forums.php
    a b  
    2626include( dirname( __FILE__ ) . '/inc/class-hooks.php' );
    2727include( dirname( __FILE__ ) . '/inc/class-report-topic.php' );
    2828include( dirname( __FILE__ ) . '/inc/class-nsfw-handler.php' );
     29include( dirname( __FILE__ ) . '/inc/class-move-topic-to-extension-forum.php' );
    2930
    3031// Compat-only includes.
    3132include( dirname( __FILE__ ) . '/inc/class-dropin.php' );