Making WordPress.org

Ticket #2695: 2695.diff

File 2695.diff, 5.1 KB (added by denisco, 5 years ago)
  • new file wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-forum-icon.php

    diff --git a/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-forum-icon.php b/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-forum-icon.php
    new file mode 100644
    index 000000000..87999a6a2
    - +  
     1<?php
     2
     3namespace WordPressdotorg\Forums;
     4
     5class Forum_Icon {
     6        const FIELD_NAME = 'wporg_bbp_forum_icon';
     7        const META       = '_wporg_bbp_forum_icon';
     8
     9        public function __construct() {
     10                add_action( 'bbp_forum_metabox', array( $this, 'add_forum_icon_field' ) );
     11                add_action( 'bbp_forum_attributes_metabox_save', array( $this, 'update_forum_icon' ) );
     12
     13                add_action( 'wporg_support_before_forum_title', array( $this, 'display_forum_icon' ) );
     14        }
     15
     16        /**
     17         * Adds the forum icon field to the Forum Attributes metabox.
     18         */
     19        public function add_forum_icon_field() {
     20                $field_name = self::FIELD_NAME;
     21                $icon       = $this->get_forum_icon();
     22                ?>
     23                <p>
     24                        <strong class="label"><?php esc_html_e( 'Icon:', 'wporg-forums' ); ?></strong>
     25                        <label class="screen-reader-text" for="<?php echo esc_attr( $field_name ); ?>"><?php esc_html_e( 'Icon:', 'wporg-forums' ); ?></label>
     26                        <input name="<?php echo esc_attr( $field_name ); ?>" type="text" id="<?php echo esc_attr( $field_name ); ?>" value="<?php echo esc_attr( $icon ); ?>" />
     27                </p>
     28                <?php
     29        }
     30
     31        /**
     32         * Updates the forum icon.
     33         */
     34        public function update_forum_icon() {
     35                if ( isset( $_POST[ self::FIELD_NAME ] ) ) {
     36                        $icon = sanitize_text_field( wp_unslash( $_POST[ self::FIELD_NAME ] ) );
     37                        update_post_meta( get_the_ID(), self::META, $icon );
     38                }
     39        }
     40
     41        /**
     42         * Adds the specified forum icon to the forum title.
     43         */
     44        public function display_forum_icon() {
     45                if ( ! bbp_is_forum_archive() ) {
     46                        return;
     47                }
     48
     49                $icon = $this->get_forum_icon();
     50                if ( $icon ) {
     51                        echo '<span class="forum-icon dashicons ' . esc_attr( $icon ) . '"></span>';
     52                }
     53        }
     54
     55        /**
     56         * Retrieves the forum icon.
     57         *
     58         * @return string Dashicons icon class.
     59         */
     60        public function get_forum_icon() {
     61                return get_post_meta( get_the_ID(), self::META, true );
     62        }
     63}
  • wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-plugin.php

    diff --git a/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-plugin.php b/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-plugin.php
    index 0885d54a3..f4f6958bf 100644
    a b class Plugin { 
    4242                $this->moderators   = new Moderators;
    4343                $this->hooks        = new Hooks;
    4444                $this->report_topic = new Report_Topic;
     45                $this->user_notes   = new Forum_Icon;
    4546
    4647                // These modifications are specific to https://wordpress.org/support/
    4748                $blog_id = get_current_blog_id();
  • wordpress.org/public_html/wp-content/plugins/support-forums/support-forums.php

    diff --git a/wordpress.org/public_html/wp-content/plugins/support-forums/support-forums.php b/wordpress.org/public_html/wp-content/plugins/support-forums/support-forums.php
    index e43e9ccf2..e613bd439 100644
    a b include( dirname( __FILE__ ) . '/inc/class-user-notes.php' ); 
    2525include( dirname( __FILE__ ) . '/inc/class-moderators.php' );
    2626include( dirname( __FILE__ ) . '/inc/class-hooks.php' );
    2727include( dirname( __FILE__ ) . '/inc/class-report-topic.php' );
     28include( dirname( __FILE__ ) . '/inc/class-forum-icon.php' );
    2829
    2930// Compat-only includes.
    3031include( dirname( __FILE__ ) . '/inc/class-dropin.php' );
  • wordpress.org/public_html/wp-content/themes/pub/wporg-support/bbpress/loop-single-forum-homepage.php

    diff --git a/wordpress.org/public_html/wp-content/themes/pub/wporg-support/bbpress/loop-single-forum-homepage.php b/wordpress.org/public_html/wp-content/themes/pub/wporg-support/bbpress/loop-single-forum-homepage.php
    index bf7e41bef..3934cdc2b 100644
    a b  
    11<div id="bbp-forum-<?php bbp_forum_id(); ?>" <?php bbp_forum_class( bbp_get_forum_id(), array( '' ) ); ?>>
    22
    3         <a class="bbp-forum-title" href="<?php bbp_forum_permalink(); ?>" title="<?php bbp_forum_title(); ?>"><h3><?php bbp_forum_title(); ?></h3></a>
     3        <a class="bbp-forum-title" href="<?php bbp_forum_permalink(); ?>" title="<?php bbp_forum_title(); ?>"><?php do_action( 'wporg_support_before_forum_title' ); ?><h3><?php bbp_forum_title(); ?></h3></a>
    44
    55        <p><?php bbp_forum_content(); ?></p>
    66
  • wordpress.org/public_html/wp-content/themes/pub/wporg-support/sass/site/_bbpress.scss

    diff --git a/wordpress.org/public_html/wp-content/themes/pub/wporg-support/sass/site/_bbpress.scss b/wordpress.org/public_html/wp-content/themes/pub/wporg-support/sass/site/_bbpress.scss
    index 6d7aa0361..776bf0e0f 100644
    a b select { 
    874874                        }
    875875                }
    876876        }
     877
     878        .bbp-forum-title {
     879                display: flex;
     880                align-items: center;
     881        }
     882
     883        .forum-icon {
     884                margin-right: 5px;
     885                color: #23282d;
     886        }
    877887}
    878888
    879889