Making WordPress.org

Ticket #2018: 2018-2.patch

File 2018-2.patch, 4.3 KB (added by denisco, 4 years ago)
  • new file wordpress.org/public_html/wp-content/plugins/wporg-bbp-topic-nsfw/inc/class-plugin.php

    diff --git wordpress.org/public_html/wp-content/plugins/wporg-bbp-topic-nsfw/inc/class-plugin.php wordpress.org/public_html/wp-content/plugins/wporg-bbp-topic-nsfw/inc/class-plugin.php
    new file mode 100644
    index 000000000..ba794f3a1
    - +  
     1<?php
     2
     3namespace WordPressdotorg\Forums\Topic_NSFW;
     4
     5class Plugin {
     6
     7        /**
     8         * @var Plugin The singleton instance.
     9         */
     10        private static $instance;
     11
     12        const META_KEY = 'topic_nsfw';
     13
     14        /**
     15         * Always return the same instance of this plugin.
     16         *
     17         * @return Plugin
     18         */
     19        public static function get_instance() {
     20                if ( ! ( self::$instance instanceof Plugin ) ) {
     21                        self::$instance = new Plugin();
     22                }
     23                return self::$instance;
     24        }
     25
     26        /**
     27         * Instantiates a new Plugin object.
     28         */
     29        private function __construct() {
     30                add_action( 'bbp_loaded', array( $this, 'bbp_loaded' ) );
     31        }
     32
     33        /**
     34         * Initializes the plugin.
     35         */
     36        public function bbp_loaded() {
     37                // Change the topic title when NSFW flag checked.
     38                add_filter( 'bbp_get_topic_title', array( $this, 'get_topic_title' ), 10, 2 );
     39
     40                // Display the form for new/edit topics.
     41                add_action( 'bbp_theme_before_topic_form_subscriptions', array( $this, 'form_topic_nsfw_checkbox' ), 15 );
     42
     43                // Process field submission for topics.
     44                add_action( 'bbp_new_topic_post_extras', array( $this, 'topic_post_extras' ) );
     45                add_action( 'bbp_edit_topic_post_extras', array( $this, 'topic_post_extras' ) );
     46        }
     47
     48        /**
     49         * Add "NSFW" status to title.
     50         */
     51        public function get_topic_title( $title, $topic_id ) {
     52                // Don't run in the admin.
     53                if ( is_admin() ) {
     54                        return $title;
     55                }
     56
     57                // Don't run when viewing a topic edit page or a reply edit page.
     58                if ( bbp_is_topic_edit() || bbp_is_reply_edit() ) {
     59                        return $title;
     60                }
     61
     62                if ( $this->is_nsfw_topic( $topic_id ) ) {
     63                        $title = sprintf(
     64                                '<abbr title="%s">%s</abbr> ',
     65                                esc_attr__( 'Not safe for work', 'wporg-forums' ),
     66                                esc_html__( '[NSFW]', 'wporg-forums' )
     67                        ) . $title;
     68                }
     69
     70                return $title;
     71        }
     72
     73        /**
     74         * Output topic NSFW checkbox.
     75         */
     76        public function form_topic_nsfw_checkbox() {
     77                $is_nsfw = $this->is_nsfw_topic();
     78                ?>
     79                <p>
     80                        <label for="topic-nsfw">
     81                                <input type="checkbox" name="<?php echo esc_attr( self::META_KEY ); ?>" id="topic-nsfw" value="yes"<?php checked( $is_nsfw, 'yes' ); ?>>
     82                                        <?php esc_html_e( 'My site or content may be considered Not Safe for Work (NSFW)', 'wporg-forums' ); ?>
     83                        </label>
     84                </p>
     85                <?php
     86        }
     87
     88        /**
     89         * Process topic form submission.
     90         */
     91        public function topic_post_extras( $topic_id ) {
     92                if ( isset( $_POST[ self::META_KEY ] ) ) {
     93                        update_post_meta( $topic_id, self::META_KEY, 'yes' );
     94                } else {
     95                        delete_post_meta( $topic_id, self::META_KEY );
     96                }
     97        }
     98
     99        /**
     100         * Is a NSFW topic?
     101         */
     102        public function is_nsfw_topic() {
     103                return get_post_meta( get_the_ID(), self::META_KEY, true );
     104        }
     105}
  • new file wordpress.org/public_html/wp-content/plugins/wporg-bbp-topic-nsfw/wporg-bbp-topic-nsfw.php

    diff --git wordpress.org/public_html/wp-content/plugins/wporg-bbp-topic-nsfw/wporg-bbp-topic-nsfw.php wordpress.org/public_html/wp-content/plugins/wporg-bbp-topic-nsfw/wporg-bbp-topic-nsfw.php
    new file mode 100644
    index 000000000..8dbdfe24b
    - +  
     1<?php
     2/**
     3 * Plugin Name: bbPress: Topic NSFW
     4 * Description: Display a topic NSFW flag on new/edit topic forms.
     5 * Version:     1.0
     6 * Author:      WordPress.org
     7 * Author URI:  http://wordpress.org/
     8 * License:     GPLv2 or later
     9 */
     10
     11namespace WordPressdotorg\Forums\Topic_NSFW;
     12
     13// Store the root plugin file for usage with functions which use the plugin basename.
     14define( __NAMESPACE__ . '\PLUGIN_FILE', __FILE__ );
     15
     16// Includes.
     17require dirname( __FILE__ ) . '/inc/class-plugin.php';
     18
     19// Instantiate the Plugin.
     20Plugin::get_instance();
  • wordpress.org/public_html/wp-content/themes/pub/wporg-support/sass/_normalize.scss

    diff --git wordpress.org/public_html/wp-content/themes/pub/wporg-support/sass/_normalize.scss wordpress.org/public_html/wp-content/themes/pub/wporg-support/sass/_normalize.scss
    index a3e8be90f..aab717c5e 100644
    a:hover { 
    5252
    5353abbr[title] {
    5454        border-bottom: 1px dotted;
     55        text-decoration: none;
    5556}
    5657
    5758b,