Making WordPress.org

Changeset 3900


Ignore:
Timestamp:
09/01/2016 02:18:57 AM (10 years ago)
Author:
jmdodd
Message:

Support Forums: Add plugin/theme new topic handlers.

Displays the new topic form with hidden input fields for the compat and plugin/theme slug at the bottom of the support and reviews views.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-directory-compat.php

    r3892 r3900  
    1515        abstract protected function do_view_sidebar();
    1616        abstract protected function do_topic_sidebar();
    17         abstract protected function get_view_header();
     17        abstract protected function do_view_header();
    1818
    1919        var $authors      = null;
     
    3434                        // Check to see if an individual topic is compat.
    3535                        add_action( 'template_redirect', array( $this, 'check_topic_for_compat' ) );
     36
     37                        // Always check to see if a topic title needs a compat prefix.
     38                        add_filter( 'bbp_get_topic_title', array( $this, 'get_topic_title' ), 9, 2 );
     39
     40                        // Always check to see if a new topic is being posted.
     41                        add_action( 'bbp_new_topic_post_extras', array( $this, 'topic_post_extras' ) );
    3642                }
    3743        }
     
    5460
    5561                        // Add output filters and actions.
    56                         add_filter( 'bbp_get_view_link',  array( $this, 'get_view_link' ), 10, 2 );
    57                         add_filter( 'bbp_breadcrumbs',    array( $this, 'breadcrumbs' ) );
    58                         add_filter( 'bbp_get_breadcrumb', array( $this, 'get_breadcrumb' ), 10, 3 );
     62                        add_filter( 'bbp_get_view_link', array( $this, 'get_view_link' ), 10, 2 );
     63                        add_filter( 'bbp_breadcrumbs',   array( $this, 'breadcrumbs' ) );
     64
     65                        add_action( 'wporg_compat_before_single_view', array( $this, 'do_view_header' ) );
     66
     67                        // Handle new topic form at the bottom of support view.
     68                        add_action( 'wporg_compat_after_single_view',      array( $this, 'add_topic_form' ) );
     69                        add_action( 'bbp_theme_before_topic_form_content', array( $this, 'add_topic_form_content' ) );
    5970                }
    6071        }
     
    8293                        }
    8394                }
     95        }
     96
     97        public function get_topic_title( $title, $topic_id ) {
     98                if ( bbp_is_single_topic() || ( bbp_is_single_view() && in_array( bbp_get_view_id(), array( $this->compat(), 'reviews', 'active' ) ) ) ) {
     99                        return $title;
     100                }
     101
     102                $slug = wp_get_object_terms( $topic_id, $this->taxonomy(), array( 'fields' => 'slugs' ) );
     103                if ( ! empty( $slug ) ) {
     104                        $slug = $slug[0];
     105                        $object = $this->get_object( $slug );
     106                        $title = sprintf( "[%s] %s", esc_html( $object->post_title ), esc_html( $title ) );
     107                }
     108                return $title;
    84109        }
    85110
     
    158183                        array(
    159184                                'post_parent'   => Plugin::REVIEWS_FORUM_ID,
    160                                 'meta_query'    => array( array(
    161                                         'key'       => '_bbp_last_active_time',
    162                                         'type'      => 'DATETIME',
    163                                 ) ),
    164185                                'tax_query'     => array( array(
    165186                                        'taxonomy'  => $this->taxonomy(),
     
    168189                                ) ),
    169190                                'show_stickies' => false,
    170                                 'orderby'       => 'meta_value',
     191                                'orderby'       => 'ID',
    171192                        )
    172193                );
     
    252273
    253274        /**
    254          * Prefix a single view-specific header using the breadcrumb filter.
     275         * Add the new topic form at the bottom of appropriate views.
    255276         */
    256         public function get_breadcrumb( $trail, $crumbs, $r ) {
    257                 if ( bbp_is_single_view() && in_array( bbp_get_view_id(), array( 'theme', 'plugin', 'reviews' ) ) ) {
    258                         $view_header = $this->get_view_header();
    259                         $trail = $view_header . $trail;
    260                 }
    261                 return $trail;
     277        public function add_topic_form() {
     278                if ( ! bbp_is_single_view() ) {
     279                        return;
     280                }
     281
     282                $view = bbp_get_view_id();
     283                if ( ! in_array( $view, array( $this->compat(), 'reviews', 'active' ) ) ) {
     284                        return;
     285                }
     286
     287                bbp_get_template_part( 'form', 'topic' );
     288        }
     289
     290        public function add_topic_form_content() {
     291                if ( ! bbp_is_single_view() ) {
     292                        return;
     293                }
     294
     295                $view = bbp_get_view_id();
     296                if ( ! in_array( $view, array( $this->compat(), 'reviews', 'active' ) ) ) {
     297                        return;
     298                }
     299
     300                if ( 'reviews' == $view ) {
     301                        $forum_id = Plugin::REVIEWS_FORUM_ID;
     302                } else {
     303                        $forum_id = $this->forum_id();
     304                }
     305                ?>
     306                <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php echo esc_attr( $forum_id ); ?>" />
     307                <input type="hidden" name="wporg_compat" id="wporg_compat" value="<?php echo esc_attr( $this->compat() ); ?>" />
     308                <input type="hidden" name="wporg_compat_slug" id="wporg_compat_slug" value="<?php echo esc_attr( $this->slug() ); ?>" />
     309                <?php
     310        }
     311
     312        public function topic_post_extras( $topic_id ) {
     313                if (
     314                        ( isset( $_POST['wporg_compat'] ) && $_POST['wporg_compat'] == $this->compat() )
     315                &&
     316                        ( isset( $_POST['wporg_compat_slug'] ) && $_POST['wporg_compat_slug'] == $this->slug() )
     317                ) {
     318                        // Check against the canonical plugin/theme records for slug existence.
     319                        $object = $this->get_object( $_POST['wporg_compat_slug'] );
     320
     321                        if ( ! empty( $object ) ) {
     322                                wp_set_object_terms( $topic_id, $this->slug(), $this->taxonomy(), false );
     323                        }
     324                }
    262325        }
    263326
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-plugin-directory-compat.php

    r3892 r3900  
    111111        }
    112112
    113         /**
    114          * Return a custom view header string so that get_breadcrumbs will display it.
    115          */
    116         public function get_view_header() {
     113        public function do_view_header() {
    117114                $slug        = esc_attr( $this->slug );
    118115                $description = esc_html__( 'Description', 'wporg-forums' );
    119116                $support     = esc_html__( 'Support', 'wporg-forums' );
    120117                $reviews     = esc_html__( 'Reviews', 'wporg-forums' );
    121 
    122                 $header = <<<EOT
     118                ?>
    123119                <ul id="sections">
    124120                        <li class="section-description">
    125                                 <a href="//wordpress.org/plugins/{$slug}/">{$description}</a>
     121                                <a href="//wordpress.org/plugins/<?php echo $slug; ?>/"><?php echo $description; ?></a>
    126122                        </li>
    127123                        <li class="section-support">
    128                                 <a href="//wordpress.org/support/plugin/{$slug}/">{$support}</a>
     124                                <a href="//wordpress.org/support/plugin/<?php echo $slug; ?>/"><?php echo $support; ?></a>
    129125                        <li>
    130126                        <li class="section-reviews">
    131                                 <a href="//wordpress.org/support/plugin/{$slug}/reviews/">{$reviews}</a>
     127                                <a href="//wordpress.org/support/plugin/<?php echo $slug; ?>/reviews/"><?php echo $reviews; ?></a>
    132128                        </li>
    133                         </ul>
    134 EOT;
    135                 return $header;
     129                </ul>
     130                <?php
    136131        }
    137132}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-theme-directory-compat.php

    r3892 r3900  
    105105        }
    106106
    107 
    108         /**
    109          * Return a custom view header string so that get_breadcrumbs will display it.
    110          */
    111         public function get_view_header() {
     107        public function do_view_header() {
    112108                $slug        = esc_attr( $this->slug );
    113109                $description = esc_html__( 'Description', 'wporg-forums' );
    114110                $support     = esc_html__( 'Support', 'wporg-forums' );
    115111                $reviews     = esc_html__( 'Reviews', 'wporg-forums' );
    116 
    117                 $header = <<<EOT
     112                ?>
    118113                <ul id="sections">
    119114                        <li class="section-description">
    120                                 <a href="//wordpress.org/themes/{$slug}/">{$description}</a>
     115                                <a href="//wordpress.org/themes/<?php echo $slug; ?>/"><?php echo $description; ?></a>
    121116                        </li>
    122117                        <li class="section-support">
    123                                 <a href="//wordpress.org/support/theme/{$slug}/">{$support}</a>
     118                                <a href="//wordpress.org/support/theme/<?php echo $slug; ?>/"><?php echo $support; ?></a>
    124119                        <li>
    125120                        <li class="section-reviews">
    126                                 <a href="//wordpress.org/support/theme/{$slug}/reviews/">{$reviews}</a>
     121                                <a href="//wordpress.org/support/theme/<?php echo $slug; ?>/reviews/"><?php echo $reviews; ?></a>
    127122                        </li>
    128                         </ul>
    129 EOT;
    130                 return $header;
     123                </ul>
     124                <?php
    131125        }
    132126}
Note: See TracChangeset for help on using the changeset viewer.