Making WordPress.org


Ignore:
Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook
Files:
3 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/handbook.php

    r10837 r10356  
    33 * Plugin Name: Handbook
    44 * Description: Features for a handbook, complete with glossary and table of contents
    5  * Version:     2.0
    65 * Author:      WordPress.org
    76 * Author URI:  https://wordpress.org/
    … …  
    2625require_once __DIR__ . '/inc/blocks.php';
    2726
    28 add_action( 'plugins_loaded', function () {
    29         if ( class_exists( 'WordPressdotorg\\Markdown\\Importer' ) ) {
    30                 require_once __DIR__ . '/inc/importer.php';
    31         }
    32 }, 1 );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/admin-notices.php

    r10837 r10356  
    99
    1010        /**
    11          * Initializes functionality.
     11         * Constructor.
    1212         *
    1313         * @access public
    1414         */
    15         public static function init() {
    16                 add_action( 'admin_notices', [ __CLASS__, 'show_new_handbook_message' ] );
    17                 add_action( 'admin_notices', [ __CLASS__, 'show_imported_handbook_notice' ] );
    18                 add_action( 'admin_notices', [ __CLASS__, 'show_imported_handbook_config_errors' ] );
     15        public function __construct() {
     16                add_action( 'admin_notices', array( $this, 'show_new_handbook_message' ) );
    1917        }
    2018
    … …  
    2624         * @access public
    2725         */
    28         public static function show_new_handbook_message() {
     26        public function show_new_handbook_message() {
    2927                global $wp_query;
    3028
    … …  
    3331                // Only show message in listing of handbook posts when no posts are present yet.
    3432                if (
    35                         $current_screen
    36                 &&
    3733                        'edit' === $current_screen->base
    3834                &&
    … …  
    4036                &&
    4137                        0 === $wp_query->post_count
    42                 &&
    43                         ( empty( $wp_query->query_vars['post_status'] ) || 'publish' === $wp_query->query_vars['post_status'] )
    4438                ) {
    4539                        echo '<div class="notice notice-success"><p>';
    46 
    47                         $suggested_slugs = array_unique( [
    48                                 str_replace( '-handbook', '', $current_screen->post_type ),
    49                                 'welcome',
    50                                 $current_screen->post_type,
    51                                 'handbook',
    52                         ] );
    53                         $suggested_slugs = array_map( function( $x ) { return "<code>{$x}</code>"; }, $suggested_slugs );
    54 
    5540                        printf(
    5641                                /* translators: 1: example landing page title that includes post type name, 2: comma-separated list of acceptable post slugs */
    57                                 __( '<strong>Welcome to your new handbook!</strong> It is recommended that the first post you create is the landing page for the handbook. You can title it anything you like (suggestions: <code>%1$s</code> or <code>Welcome</code>). However, you must ensure that it has one of the following slugs: %2$s. The slug will ultimately be omitted from the page&#8216;s permalink URL, but will still appear in the permalinks for sub-pages.', 'wporg' ),
     42                                __( '<strong>Welcome to your new handbook!</strong> It is recommended that the first post you create is the landing page for the handbook. You can title it anything you like (suggestions: <code>%1$s</code> or <code>Welcome</code>). However, you must ensure that it has one of the following slugs: %2$s.', 'wporg' ),
    5843                                WPorg_Handbook::get_name( $current_screen->post_type ),
    59                                 implode( ', ', $suggested_slugs )
     44                                '<code>' . str_replace( '-handbook', '', $current_screen->post_type ) . '</code>, <code>welcome</code>, <code>' . $current_screen->post_type . '</code>, <code>handbook</code>'
    6045                        );
    6146                        echo "</p></div>\n";
    … …  
    6348        }
    6449
    65         /**
    66          * Outputs admin notice indicating the handbook is an imported handbook, if applicable.
    67          *
    68          * @access public
    69          */
    70         public static function show_imported_handbook_notice() {
    71                 global $wp_query;
    72 
    73                 // Bail if handbook importer is not available.
    74                 if ( ! class_exists( 'WPorg_Handbook_Importer' ) ) {
    75                         return;
    76                 }
    77 
    78                 $current_screen = get_current_screen();
    79 
    80                 // Only show message in listing of handbook posts when no posts are present yet.
    81                 if (
    82                         $current_screen
    83                 &&
    84                         'edit' === $current_screen->base
    85                 &&
    86                         in_array( $current_screen->post_type, wporg_get_handbook_post_types() )
    87                 &&
    88                         WPorg_Handbook_Importer::is_handbook_imported( $current_screen->post_type )
    89                 ) {
    90                         $handbook_config = WPorg_Handbook_Init::get_handbooks_config( $current_screen->post_type );
    91 
    92                         $handbook = WPorg_Handbook_Init::get_handbook( $current_screen->post_type );
    93                         if ( ! $handbook ) {
    94                                 return;
    95                         }
    96 
    97                         $importer = $handbook->get_importer();
    98                         $interval = $importer ? $importer->get_cron_interval( false ) : [];
    99                         $interval_display = ! empty( $interval['display'] ) ? strtolower( $interval['display'] ) : __( 'DISABLED', 'wporg' );
    100 
    101                         echo '<div class="notice notice-info"><p>';
    102                         printf(
    103                                 /* translators: 1: URL to remote manifest. 2: cron interval. */
    104                                 __( '<strong>This is an imported handbook!</strong> This handbook is imported according to a <a href="%1$s">remote manifest</a>. Any local changes will be overwritten during the next import, so make any changes at the remote location. Import interval: <strong>%2$s</strong>.', 'wporg' ),
    105                                 $handbook_config['manifest'],
    106                                 $interval_display
    107                         );
    108                         echo "</p></div>\n";
    109                 }
    110         }
    111 
    112         /**
    113          * Outputs admin error notice(s) for any misconfigured imported handbooks.
    114          *
    115          * @access public
    116          */
    117         public static function show_imported_handbook_config_errors() {
    118                 global $wp_query;
    119 
    120                 // Bail if handbook importer is not available.
    121                 if ( ! class_exists( 'WPorg_Handbook_Importer' ) ) {
    122                         return;
    123                 }
    124 
    125                 $current_screen = get_current_screen();
    126 
    127                 // Only show message in listing of handbook posts when no posts are present yet.
    128                 if (
    129                         $current_screen
    130                 &&
    131                         'edit' === $current_screen->base
    132                 &&
    133                         in_array( $current_screen->post_type, wporg_get_handbook_post_types() )
    134                 &&
    135                         WPorg_Handbook_Importer::is_handbook_imported( $current_screen->post_type )
    136                 ) {
    137                         $handbook_config = WPorg_Handbook_Init::get_handbooks_config( $current_screen->post_type );
    138 
    139                         $handbook = WPorg_Handbook_Init::get_handbook( $current_screen->post_type );
    140                         if ( ! $handbook ) {
    141                                 return;
    142                         }
    143 
    144                         $handbook_config = $handbook->get_config();
    145                         $cron_intervals = wp_get_schedules();
    146                         $interval_display = $handbook_config[ 'cron_interval' ] ?? '';
    147 
    148                         if ( ! empty( $cron_intervals[ $interval_display ] ) ) {
    149                                 return;
    150                         }
    151 
    152                         echo '<div class="notice notice-warning"><p>';
    153                         printf(
    154                                 /* translators: %s: cron interval. */
    155                                 __( '<strong>Misconfigured cron interval!</strong> This imported handbook has a misconfigured cron interval. The config defines an interval of <strong>%s</strong>, which has not been defined. The fallback import interval shown in a notice above includes the default cron interval currently in use.', 'wporg' ),
    156                                 $interval_display
    157                         );
    158                         echo "</p></div>\n";
    159                 }
    160         }
    16150}
    16251
    163 add_action( 'plugins_loaded', [ 'WPorg_Handbook_Admin_Notices', 'init' ] );
     52$admin_notices = new WPorg_Handbook_Admin_Notices();
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/breadcrumbs.php

    r10837 r10356  
    3030        public static function do_init() {
    3131                // Note if the WPorg_Handbook_Pages_Widget widget is in use.
    32                 if ( class_exists( 'WPorg_Handbook_Pages_Widget' ) && is_active_widget( false, false, WPorg_Handbook_Pages_Widget::get_widget_id_base(), true ) ) {
     32                if ( is_active_widget( false, false, WPorg_Handbook_Pages_Widget::get_widget_id_base(), true ) ) {
    3333                        self::$using_pages_widget = true;
    3434                }
    … …  
    5454
    5555                // Second link is always link to handbook home page.
    56                 $handbook_name = wporg_get_current_handbook_name();
    5756                if ( wporg_is_handbook_landing_page() ) {
    58                         $links[] = $handbook_name;
     57                        $links[] = __( 'Handbook', 'wporg' );
    5958                } else {
    60                         $links[] = sprintf( '<a href="%s">%s</a>', esc_url( wporg_get_current_handbook_home_url() ), $handbook_name );
     59                        $links[] = sprintf( '<a href="%s">%s</a>', esc_url( wporg_get_current_handbook_home_url() ), __( 'Handbook', 'wporg' ) );
    6160                }
    6261
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/handbook.php

    r10837 r10356  
    88class WPorg_Handbook {
    99
    10         /**
    11          * The handbook post type.
    12          *
    13          * @var string
    14          */
    1510        public $post_type = '';
    16 
    17         /**
    18          * The handbook's settings.
    19          *
    20          * @var array
    21          */
    22         public $settings = [];
    23 
    24         /**
    25          * The name of the setting for the handbook's name.
    26          *
    27          * @var string
    28          */
    2911        public $setting_name = '';
    3012
    31         /**
    32          * The memoized and filtered label text for the handbook.
    33          *
    34          * @var string
    35          */
    3613        protected $label = '';
    3714
    38         /**
    39          * The associated importer object, if warranted.
    40          */
    41         protected $importer;
    42 
    43         /**
    44          * Returns the custom handbook-related capabilities granted to site users.
    45          *
    46          * @return array
    47          */
    48         public static function caps() {
    49                 return [
    50                         'edit_handbook_pages',
    51                         'edit_others_handbook_pages',
     15        static function caps() {
     16                return array(
     17                        'edit_handbook_pages', 'edit_others_handbook_pages',
    5218                        'edit_published_handbook_pages',
    53                 ];
    54         }
    55 
    56         /**
    57          * Returns the custom capabilities granted to handbook editors.
    58          *
    59          * @return array
    60          */
    61         public static function editor_caps() {
    62                 return [
     19                );
     20        }
     21
     22        static function editor_caps() {
     23                return array(
    6324                        'publish_handbook_pages',
    64                         'delete_handbook_pages',
    65                         'delete_others_handbook_pages',
    66                         'delete_published_handbook_pages',
    67                         'delete_private_handbook_pages',
    68                         'edit_private_handbook_pages',
    69                         'read_private_handbook_pages',
    70                 ];
    71         }
    72 
    73         /**
    74          * Returns handbook default config.
    75          *
    76          * @return array
    77          */
    78         public static function get_default_handbook_config() {
    79                 /**
    80                  * Filters default handbook configuration array.
    81                  *
    82                  * @param array $config {
    83                  *     Associative array of handbook configuration.
    84                  *
    85                  *     @type string $cron_interval The cron interval for which an imported handbook gets
    86                  *                                 imported, e.g. 'hourly', 'daily'. If defined as an
    87                  *                                 unrecognized interval, 'hourly' will be used.
    88                  *                                 Default '15_minutes'.
    89                  *     @type string $label The label for the handbook. Default is the
    90                  *                         post type slug converted to titlecase (e.g.
    91                  *                         plugin-handbok => "Plugin Handbook").
    92                  *     @type string manifest       The URL to the manifest JSON file for an imported
    93                  *                                 handbook.
    94                  *     @type string $slug  The slug for the post type. Default is the
    95                  *                         post type.
    96                  * }
    97                  */
    98                 return (array) apply_filters( 'handbook_default_handbook_config', [
    99                         'cron_interval' => '15_minutes',
    100                         'label'         => '',
    101                         'manifest'      => '',
    102                         'slug'          => '',
    103                 ] );
     25                        'delete_handbook_pages', 'delete_others_handbook_pages',
     26                        'delete_published_handbook_pages', 'delete_private_handbook_pages',
     27                        'edit_private_handbook_pages', 'read_private_handbook_pages',
     28                );
    10429        }
    10530
    … …  
    11338         * @return string
    11439         */
    115         public static function get_name( $post_type = 'handbook', $raw = false ) {
     40        static function get_name( $post_type = 'handbook', $raw = false ) {
    11641                // Prefer explicitly configured handbook name.
    11742                $name = get_option( $post_type . '_name' );
    11843
    119                 // If handbook name isn't set, try configured label.
    120                 if ( ! $raw && ! $name ) {
    121                         $config = WPorg_Handbook_Init::get_handbooks_config( $post_type );
    122                         if ( ! empty( $config['label'] ) ) {
    123                                 $name = $config['label'];
    124                         }
    125                 }
    126 
    12744                // If handbook name isn't set, try root relative site path.
    128                 if ( ! $raw && ! $name ) {
     45                if ( ! $raw && empty( $name ) ) {
    12946                        if ( is_multisite() ) {
    13047                                $name = trim( get_blog_details()->path, '/' );
    … …  
    13451
    13552                        // If no name defined yet, try handbook post type if not standard.
    136                         if ( ! $name && ( 'handbook' !== $post_type ) ) {
    137                                 $name = str_replace( '-handbook', '', $post_type );
     53                        if ( empty( $name ) && ( 'handbook' != $post_type ) ) {
     54                                $name = ucfirst( substr( $post_type, 0, -9 ) );
    13855                        }
    13956
    14057                        $name .= ' Handbook';
    141                         $name = ucfirst( $name );
    14258                }
    14359
    … …  
    14561        }
    14662
    147         /**
    148          * Constructor
    149          *
    150          * @param string $type   The post type for the handbook.
    151          * @param array  $config The config array for the handbook.
    152          */
    153         public function __construct( $type, $config = [] ) {
    154                 $this->post_type = sanitize_title( $type );
    155 
    156                 $config = $this->config = wp_parse_args( $config, self::get_default_handbook_config() );
    157 
    158                 $this->label = apply_filters(
    159                         'handbook_label',
    160                         $config['label'] ?: ucwords( str_replace( [ '-', '_' ], ' ', $this->post_type ) ),
    161                         $this->post_type
    162                 );
     63        function __construct( $type ) {
     64                if ( 'handbook' != $type ) {
     65                        $this->post_type = $type . '-handbook';
     66                } else {
     67                        $this->post_type = $type;
     68                }
     69
     70                $this->label = ucwords( str_replace( array( '-', '_' ), ' ', $this->post_type ) );
     71                $this->label = apply_filters( 'handbook_label', $this->label, $this->post_type );
    16372
    16473                $this->setting_name = $this->post_type . '_name';
    16574
    166                 add_action( 'after_handbooks_init',               [ $this, 'init_importer' ] );
    167                 add_filter( 'user_has_cap',                       [ $this, 'grant_handbook_caps' ] );
    168                 add_action( 'widgets_init',                       [ $this, 'register_post_type' ] );
    169                 add_filter( 'post_type_link',                     [ $this, 'post_type_link' ], 10, 2 );
    170                 add_action( 'template_redirect',                  [ $this, 'redirect_handbook_root_page' ] );
    171                 add_filter( 'template_include',                   [ $this, 'template_include' ] );
    172                 add_filter( 'pre_get_posts',                      [ $this, 'pre_get_posts' ] );
    173                 add_filter( 'posts_pre_query',                    [ $this, 'posts_pre_query' ], 10, 2 );
    174                 add_action( 'widgets_init',                       [ $this, 'handbook_sidebar' ], 11 ); // After P2
    175                 add_action( 'wporg_email_changes_for_post_types', [ $this, 'wporg_email_changes_for_post_types' ] );
    176                 add_action( 'p2_action_links',                    [ $this, 'disable_p2_resolved_posts_action_links' ] );
    177                 add_action( 'admin_init',                         [ $this, 'add_name_setting' ] );
    178                 add_filter( 'body_class',                         [ $this, 'add_body_class' ] );
    179                 add_filter( 'post_class',                         [ $this, 'add_post_class' ] );
    180                 add_filter( 'o2_process_the_content',             [ $this, 'disable_o2_processing' ] );
    181                 add_filter( 'o2_application_container',           [ $this, 'o2_application_container' ] );
    182                 add_filter( 'o2_view_type',                       [ $this, 'o2_view_type' ] );
    183                 add_filter( 'o2_post_fragment',                   [ $this, 'o2_post_fragment' ] );
    184                 add_filter( 'comments_open',                      [ $this, 'comments_open' ], 10, 2 );
    185                 add_filter( 'wp_nav_menu_objects',                [ $this, 'highlight_menu_handbook_link' ] );
    186                 add_filter( 'display_post_states',                [ $this, 'display_post_states' ], 10, 2 );
    187         }
    188 
    189         /**
    190          * Returns the configuration array for handbooks.
    191          *
    192          * @return array
    193          */
    194         public function get_config() {
    195                 return $this->config;
    196         }
    197 
    198         /**
    199          * Returns the handbook's importer object, if applicable.
    200          *
    201          * @return WPorg_Handbook_Importer|null
    202          */
    203         public function get_importer() {
    204                 return $this->importer;
    205         }
    206 
    207         /**
    208          * Initializes the importer, if applicable.
    209          */
    210         public function init_importer() {
    211                 $config = $this->get_config();
    212 
    213                 if ( class_exists( 'WPorg_Handbook_Importer' ) ) {
    214                         if ( WPorg_Handbook_Importer::is_handbook_imported( $this->post_type ) ) {
    215                                 $this->importer = new WPorg_Handbook_Importer( $this );
    216                         }
    217                 } elseif ( is_admin() && ( $config['manifest'] ?: false ) ) {
    218                         add_action( 'admin_notices', function () {
    219                                 echo '<div class="notice notice-error"><p>' . __( 'Error: The <strong>WPORG Markdown Importer</strong> plugin needs to be activated in order to allow importing of handbooks.', 'wporg' ) . '</p></div>';
    220                         } );
    221                 }
     75                add_filter( 'user_has_cap',                       array( $this, 'grant_handbook_caps' ) );
     76                add_action( 'widgets_init',                       array( $this, 'register_post_type' ) );
     77                add_filter( 'post_type_link',                     array( $this, 'post_type_link' ), 10, 2 );
     78                add_action( 'template_redirect',                  array( $this, 'redirect_handbook_root_page' ) );
     79                add_filter( 'template_include',                   array( $this, 'template_include' ) );
     80                add_filter( 'pre_get_posts',                      array( $this, 'pre_get_posts' ) );
     81                add_action( 'widgets_init',                       array( $this, 'handbook_sidebar' ), 11 ); // After P2
     82                add_action( 'wporg_email_changes_for_post_types', array( $this, 'wporg_email_changes_for_post_types' ) );
     83                add_action( 'p2_action_links',                    array( $this, 'disable_p2_resolved_posts_action_links' ) );
     84                add_action( 'admin_init',                         array( $this, 'add_name_setting' ) );
     85                add_filter( 'body_class',                         array( $this, 'add_body_class' ) );
     86                add_filter( 'post_class',                         array( $this, 'add_post_class' ) );
     87                add_filter( 'o2_process_the_content',             array( $this, 'disable_o2_processing' ) );
     88                add_filter( 'o2_application_container',           array( $this, 'o2_application_container' ) );
     89                add_filter( 'o2_view_type',                       array( $this, 'o2_view_type' ) );
     90                add_filter( 'o2_post_fragment',                   array( $this, 'o2_post_fragment' ) );
     91                add_filter( 'comments_open',                      array( $this, 'comments_open' ), 10, 2 );
     92                add_filter( 'wp_nav_menu_objects',                array( $this, 'highlight_menu_handbook_link' ) );
     93                add_filter( 'display_post_states',                array( $this, 'display_post_states' ), 10, 2 );
    22294        }
    22395
    … …  
    229101         * @return string[]
    230102         */
    231         public function display_post_states( $post_states, $post ) {
     103        function display_post_states( $post_states, $post ) {
    232104                if ( $this->post_is_landing_page( $post ) ) {
    233105                        $post_states[] = __( 'Handbook Front Page', 'wporg' );
    … …  
    247119         * @return array
    248120         */
    249         public function add_body_class( $classes ) {
     121        function add_body_class( $classes ) {
    250122                if ( is_singular() && wporg_is_handbook( $this->post_type ) ) {
    251123                        $classes[] = 'single-handbook';
    … …  
    270142         * @return array
    271143         */
    272         public function add_post_class( $classes ) {
     144        function add_post_class( $classes ) {
    273145                if ( $this->post_type === get_post_type() ) {
    274146                        $classes[] = 'type-handbook';
    … …  
    278150        }
    279151
    280         /**
    281          * Adds the setting for the handbook's name.
    282          */
    283         public function add_name_setting() {
     152        function add_name_setting() {
    284153                register_setting( 'general', $this->setting_name, 'esc_attr' );
    285154
    286                 $label = ( 'handbook' === $this->post_type ) ?
     155                $label = ( 'handbook' == $this->post_type ) ?
    287156                        __( 'Handbook name', 'wporg' ) :
    288                         sprintf( __( 'Handbook name (%s)', 'wporg' ), str_replace( '-handbook', '', $this->post_type ) );
     157                        sprintf( __( 'Handbook name (%s)', 'wporg' ), substr( $this->post_type, 0, -9 ) );
    289158
    290159                add_settings_field(
    291160                        $this->setting_name,
    292161                        '<label for="' . esc_attr( $this->setting_name ) . '">' . $label . '</label>',
    293                         [ $this, 'name_setting_html' ],
     162                        array( $this, 'name_setting_html' ),
    294163                        'general'
    295164                );
    296165        }
    297166
    298         /**
    299          * Outputs the HTML for the input field for the handbook's name.
    300          */
    301         public function name_setting_html() {
     167        function name_setting_html() {
    302168                $value = get_option( $this->setting_name, '' );
    303169                echo '<input type="text" id="' . esc_attr( $this->setting_name ) . '" name="' . esc_attr( $this->setting_name ) . '" value="' . esc_attr( $value ) . '" class="regular-text ltr" />';
    304170        }
    305171
    306         /**
    307          * Grants handbook caps to the current user.
    308          *
    309          * @return array
    310          */
    311         public function grant_handbook_caps( $caps ) {
     172        function grant_handbook_caps( $caps ) {
    312173                if ( ! is_user_member_of_blog() ) {
    313174                        return $caps;
    … …  
    327188        }
    328189
    329         /**
    330          * Registers handbook post types.
    331          */
    332         public function register_post_type() {
    333                 $config = $this->get_config();
    334 
    335                 if ( ! empty( $config['slug'] ) ) {
    336                         $slug = $config['slug'];
    337                 } elseif ( 'handbook' !== $this->post_type ) {
    338                         $slug = str_replace( '-handbook', '', $this->post_type );
     190        function register_post_type() {
     191                if ( 'handbook' != $this->post_type ) {
     192                        $slug = substr( $this->post_type, 0, -9 );
    339193                } else {
    340194                        $slug = 'handbook';
    341195                }
    342196
    343                 $default_config = [
    344                         'labels' => [
     197                $default_config = array(
     198                        'labels' => array(
    345199                                'name'          => $this->label,
    346200                                'singular_name' => sprintf( __( '%s Page', 'wporg' ), $this->label ),
    347201                                'menu_name'     => $this->label,
    348202                                'all_items'     => sprintf( __( '%s Pages', 'wporg' ), $this->label ),
    349                         ],
     203                        ),
    350204                        'public'            => true,
    351205                        'show_ui'           => true,
    … …  
    357211                        'menu_icon'         => 'dashicons-book',
    358212                        'menu_position'     => 11,
    359                         'rewrite' => [
     213                        'rewrite' => array(
    360214                                'feeds'         => false,
    361215                                'slug'          => $slug,
    362216                                'with_front'    => false,
    363                         ],
     217                        ),
    364218                        'delete_with_user'  => false,
    365                         'supports'          => [ 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'revisions', 'wpcom-markdown' ],
    366                 ];
     219                        'supports'          => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'revisions', 'wpcom-markdown' ),
     220                );
    367221                // Allow customization of the default post type configuration via filter.
    368                 $config = (array) apply_filters( 'handbook_post_type_defaults', $default_config, $slug );
    369 
    370                 // Override the presumed label with a potentially customized value.
    371                 if ( ! empty( $config['labels']['name'] ) ) {
    372                         $this->label = $config['labels']['name'];
    373                 }
     222                $config = apply_filters( 'handbook_post_type_defaults', $default_config, $slug );
     223
     224                $this->label = $config['labels']['name'];
    374225
    375226                register_post_type( $this->post_type, $config );
    … …  
    384235         *              handbook's landing page.
    385236         */
    386         public function post_is_landing_page( $post = null ) {
     237        protected function post_is_landing_page( $post = null ) {
    387238                $is_landing_page = false;
    388239
    … …  
    418269         * @param WP_Post $post      The post in question.
    419270         */
    420         public function post_type_link( $post_link, $post ) {
     271        function post_type_link( $post_link, $post ) {
    421272                $post_type = get_post_type( $post );
    422273
    … …  
    433284         * post type archive link for the handbook.
    434285         */
    435         public function redirect_handbook_root_page() {
     286        function redirect_handbook_root_page() {
    436287                global $wp_query;
    437288
    … …  
    458309         * @return string
    459310         */
    460         public function template_include( $template ) {
     311        function template_include( $template ) {
    461312                global $wp_query;
    462313
    … …  
    466317                }
    467318
    468                 $handbook_templates = [];
     319                $handbook_templates = array();
    469320
    470321                // For singular handbook pages not of the 'handbook' post type.
    471322                if ( is_singular( $this->post_type ) && 'handbook' !== $this->post_type ) {
    472                         $handbook_templates = [ "single-{$this->post_type}.php", 'single-handbook.php' ];
     323                        $handbook_templates = array( "single-{$this->post_type}.php", 'single-handbook.php' );
    473324                }
    474325                // For handbook landing page.
    … …  
    489340        }
    490341
    491         /**
    492          * Pre-emptively sets the query posts to the handbook landing page when
    493          * appropriate.
    494          *
    495          * @param array $posts    Posts.
    496          * @param WP_Query $query Query object.
    497          * @return array
    498          */
    499         public function posts_pre_query( $posts, $query ) {
    500                 if ( $query->is_main_query() && ! $query->is_admin && ! $query->is_search && $query->is_handbook_root ) {
    501                         $posts = [ $query->is_handbook_root ];
    502                 }
    503 
    504                 return $posts;
    505         }
    506 
    507         /**
    508          * Performs query object adjustments for handbook requests prior to querying
    509          * for posts.
    510          */
    511         public function pre_get_posts( $query ) {
     342        function pre_get_posts( $query ) {
    512343                // Bail early if query is not for this handbook's post type.
    513344                if ( get_query_var( 'post_type' ) !== $this->post_type ) {
    … …  
    526357                        $page = get_page_by_path( $this->post_type, OBJECT, $this->post_type );
    527358                        if ( ! $page ) {
    528                                 $slug = str_replace( '-handbook', '', $this->post_type );
    529                                 if ( $slug !== $this->post_type ) {
    530                                         $page = get_page_by_path( $slug, OBJECT, $this->post_type );
    531                                 }
    532                         }
    533                         if ( ! $page && 'handbook' !== $this->post_type ) {
     359                                $slug = substr( $this->post_type, 0, -9 );
     360                                $page = get_page_by_path( $slug, OBJECT, $this->post_type );
     361                        }
     362                        if ( ! $page ) {
    534363                                $page = get_page_by_path( 'handbook', OBJECT, $this->post_type );
    535364                        }
    536                         if ( ! $page && 'welcome' !== $this->post_type ) {
     365                        if ( ! $page ) {
    537366                                $page = get_page_by_path( 'welcome', OBJECT, $this->post_type );
    538367                        }
    539368                        if ( $page ) {
    540369                                $query->set( 'page_id', $page->ID );
    541                                 $query->is_handbook_root     = $page;
     370                                $query->is_handbook_root     = true;
    542371
    543372                                $query->is_archive           = false;
    … …  
    550379        }
    551380
    552         /**
    553          * Registers sidebar and widgets for handbook pages.
    554          */
    555         public function handbook_sidebar() {
    556                 $sidebar_args = [
    557                         'id'            => $this->post_type,
    558                         'name'          => sprintf( __( '%s Sidebar', 'wporg' ), $this->label ),
    559                         'description'   => sprintf( __( 'Used on %s pages', 'wporg' ), $this->label ),
     381        function handbook_sidebar() {
     382                $sidebar_args = array(
     383                        'id'          => $this->post_type,
     384                        'name'        => sprintf( __( '%s Sidebar', 'wporg' ), $this->label ),
     385                        'description' => sprintf( __( 'Used on %s pages', 'wporg' ), $this->label ),
    560386                        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    561387                        'after_widget'  => '</aside>',
    562388                        'before_title'  => '<h2 class="widget-title">',
    563389                        'after_title'   => '</h2>',
    564                 ];
     390                );
    565391
    566392                $sidebar_args = apply_filters( 'wporg_handbook_sidebar_args', $sidebar_args, $this );
    … …  
    572398        }
    573399
    574         /**
    575          * Amends list of post types for which users can opt into receiving emails
    576          * about changes.
    577          *
    578          * @param array $post_types Post types.
    579          * @return array
    580          */
    581         public function wporg_email_changes_for_post_types( $post_types ) {
     400        function wporg_email_changes_for_post_types( $post_types ) {
    582401                if ( ! in_array( $this->post_type, $post_types ) ) {
    583402                        $post_types[] = $this->post_type;
    … …  
    591410         * if that plugin is active.
    592411         */
    593         public function disable_p2_resolved_posts_action_links() {
    594                 if ( ( $this->post_type === get_post_type() ) && class_exists( 'P2_Resolved_Posts' ) && isset( $GLOBALS['p2_resolved_posts'] ) && is_object( $GLOBALS['p2_resolved_posts'] ) ) {
    595                         remove_filter( 'p2_action_links', [ P2_Resolved_Posts::instance(), 'p2_action_links' ], 100 );
     412        function disable_p2_resolved_posts_action_links() {
     413                if ( ( $this->post_type == get_post_type() ) && class_exists( 'P2_Resolved_Posts' ) && isset( $GLOBALS['p2_resolved_posts'] ) && is_object( $GLOBALS['p2_resolved_posts'] ) ) {
     414                        remove_filter( 'p2_action_links', array( P2_Resolved_Posts::instance(), 'p2_action_links' ), 100 );
    596415                }
    597416        }
    … …  
    603422         * @return bool
    604423         */
    605         public function disable_o2_processing( $process_with_o2 ) {
     424        function disable_o2_processing( $process_with_o2 ) {
    606425                return ( is_singular() && $this->post_type === get_post_type() ) ? false : $process_with_o2;
    607426        }
    … …  
    613432         * @return string
    614433         */
    615         public function o2_application_container( $container ) {
     434        function o2_application_container( $container ) {
    616435                return ( is_singular() && $this->post_type === get_post_type() ) ? '#primary' : $container;
    617436        }
    … …  
    624443         * @return string
    625444         */
    626         public function o2_view_type( $view_type ) {
     445        function o2_view_type( $view_type ) {
    627446                return ( is_singular() && $this->post_type === get_post_type() ) ? 'single' : $view_type;
    628447        }
    … …  
    634453         * @return array
    635454         */
    636         public function o2_post_fragment( $post_fragment ) {
    637                 if ( empty( $post_fragment['id'] ) ) {
    638                         return $post_fragment;
    639                 }
    640 
     455        function o2_post_fragment( $post_fragment ) {
    641456                $post = get_post( $post_fragment['id'] );
    642457                if ( ! $post ) {
    … …  
    658473         * @return bool
    659474         */
    660         public function comments_open( $open, $post_id ) {
     475        function comments_open( $open, $post_id ) {
    661476                $post = get_post( $post_id );
    662477                if ( ! $post ) {
    … …  
    684499         * @return array
    685500         */
    686         public function highlight_menu_handbook_link( $menu_items ) {
     501        function highlight_menu_handbook_link( $menu_items ) {
    687502                // Must be on a handbook page that isn't the handbook landing page (which will already be handled).
    688                 if ( ! is_page( [ 'handbook', 'handbooks' ] ) && ( ! wporg_is_handbook() || wporg_is_handbook_landing_page() ) ) {
     503                if ( ! is_page( array( 'handbook', 'handbooks' ) ) && ( ! wporg_is_handbook() || wporg_is_handbook_landing_page() ) ) {
    689504                        return $menu_items;
    690505                }
    691506
    692507                // Menu must not have an item that is already noted as being current.
    693                 $current_menu_item = wp_filter_object_list( $menu_items, [ 'current' => true ] );
     508                $current_menu_item = wp_filter_object_list( $menu_items, array( 'current' => true ) );
    694509                if ( $current_menu_item ) {
    695510                        return $menu_items;
    … …  
    697512
    698513                // Menu must have an item that links to handbook home page.
    699                 $root_handbook_menu_item = wp_filter_object_list( $menu_items, [ 'url' => wporg_get_current_handbook_home_url() ] );
     514                $root_handbook_menu_item = wp_filter_object_list( $menu_items, array( 'url' => wporg_get_current_handbook_home_url() ) );
    700515                if ( ! $root_handbook_menu_item ) {
    701516                        // Or it must have an item that links to a 'handbook' or 'handbooks' page.
    … …  
    703518                        $page = get_page_by_path( $page_slug );
    704519                        if ( $page ) {
    705                                 $root_handbook_menu_item = wp_filter_object_list( $menu_items, [ 'object_id' => $page->ID ] );
     520                                $root_handbook_menu_item = wp_filter_object_list( $menu_items, array( 'object_id' => $page->ID ) );
    706521                        }
    707522                }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/init.php

    r10837 r10356  
    88class WPorg_Handbook_Init {
    99
    10         /**
    11          * Asociative array of WPorg_Handbook objects.
    12          *
    13          * @var array
    14          */
    15         protected static $handbooks = [];
    16 
    17         /**
    18          * Returns the handbook objects.
    19          *
    20          * @return WPorg_Handbook[]
    21          */
    22         public static function get_handbook_objects() {
    23                 return self::$handbooks;
     10        public static function get_post_types() {
     11                return (array) apply_filters( 'handbook_post_types', array( 'handbook' ) );
    2412        }
    2513
    26         /**
    27          * Returns a handbook of the given post type.
    28          *
    29          * @param string $post_type The handbook post type.
    30          * @return WPorg_Handbook|false The handbook object, or false if no such
    31          *                              handbook.
    32          */
    33         public static function get_handbook( $post_type ) {
    34                 $handbooks = self::get_handbook_objects();
    35                 return $handbooks[ $post_type ] ?? false;
     14        static function init() {
     15
     16                $post_types = self::get_post_types();
     17
     18                new WPorg_Handbook_TOC( $post_types );
     19
     20                foreach ( $post_types as $type ) {
     21                        new WPorg_Handbook( $type );
     22                }
     23
     24                WPorg_Handbook_Glossary::init();
     25
     26                add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_styles' ) );
     27                add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) );
    3628        }
    3729
    38         /**
    39          * Returns the post types of all handbooks.
    40          *
    41          * @return array
    42          */
    43         public static function get_post_types() {
    44                 return array_keys( self::$handbooks );
     30        static public function enqueue_styles() {
     31                wp_enqueue_style( 'wporg-handbook-css', plugins_url( 'stylesheets/callout-boxes.css', WPORG_HANDBOOK_PLUGIN_FILE ), array(), '20200121' );
    4532        }
    4633
    47         /**
    48          * Returns the handbooks configurations.
    49          *
    50          * @param string $handbook Optional. A specific handbook to return config for.
    51          *                         If none specified, then all are returned. Default ''.
    52          * @return array|false If $handbook defined, then the config for that handbook
    53          *                     if handbook exists, else false. If no $handbook specified,
    54          *                     then an associative array of config for all handbooks,
    55          *                     keyed by post type.
    56          */
    57         public static function get_handbooks_config( $handbook = '' ) {
    58                 $return = false;
    59                 $handbooks = self::get_handbook_objects();
    60 
    61                 // If no handbook specified, return configs for all handbooks.
    62                 if ( ! $handbook ) {
    63                         $return = [];
    64                         foreach ( $handbooks as $type => $handbook_obj ) {
    65                                 $return[ $type ] = $handbook_obj->get_config();
    66                         }
    67                 }
    68 
    69                 return ( $handbook && ! empty( $handbooks[ $handbook ] ) && is_a( $handbooks[ $handbook ], 'WPorg_Handbook' ) )
    70                         ? $handbooks[ $handbook ]->get_config()
    71                         : $return;
    72         }
    73 
    74         /**
    75          * Resets memoized and cached variables.
    76          *
    77          * @param bool $delete_handbook_objects Optional. Delete associated handbook
    78          *                                      objects? Default false.
    79          */
    80         public static function reset( $delete_handbook_objects = false ) {
    81                 if ( $delete_handbook_objects ) {
    82                         foreach ( self::get_handbook_objects() as $obj ) {
    83                                 unset( $obj );
    84                         }
    85                 }
    86 
    87                 self::$handbooks  = [];
    88         }
    89 
    90         /**
    91          * Initializes handbooks.
    92          */
    93         public static function init() {
    94                 $config = [];
    95                 $handbooks_config = [];
    96 
    97                 /**
    98                  * Fires before handbooks have been initialized.
    99                  */
    100                 do_action( 'before_handbooks_init' );
    101 
    102                 /**
    103                  * Filters the handbook post types for creating handbooks.
    104                  *
    105                  * @deprecated Use {@see 'handbooks_config'} instead.
    106                  *
    107                  * @param array $handbooks Array of handbook post types. Default empty
    108                  *                         array, which later will be interpreted to
    109                  *                         be 'handbook'.
    110                  */
    111                 $post_types = (array) apply_filters( 'handbook_post_types', [] );
    112 
    113                 foreach ( $post_types as $post_type ) {
    114                         $config[ $post_type ] = [];
    115                 }
    116 
    117                 /**
    118                  * Defines and configures all handbooks.
    119                  *
    120                  * @see WPorg_Handbook::get_default_handbook_config()
    121                  *
    122                  * @param array $config Associative array of handbooks and their
    123                  *                      configuration options. Keys should be the handbook
    124                  *                      post type (which will get appended '-handbook' if
    125                  *                      the post type isn't 'handbook' and doesn't already
    126                  *                      contain '-handbook'. See
    127                  *                      {@see WPorg_Handbook::get_default_handbook_config()}
    128                  *                      for list of per-handbook configuration options.
    129                  */
    130                 $config = (array) apply_filters( 'handbooks_config', $config );
    131 
    132                 // If no handbooks were configured, default to a basic handbook.
    133                 if ( ! $config ) {
    134                         $config = [ 'handbook' => [] ];
    135                 }
    136 
    137                 // Get default settings for a handbook.
    138                 $defaults = WPorg_Handbook::get_default_handbook_config();
    139 
    140                 // Determine each handbook's config.
    141                 foreach ( $config as $key => $value ) {
    142                         $key = sanitize_title( $key );
    143                         $post_type = ( 'handbook' === $key || false !== strpos( $key, '-handbook' ) ) ? $key : $key . '-handbook';
    144 
    145                         $handbooks_config[ $post_type ] = wp_parse_args( $value, $defaults );
    146 
    147                         // Set slug if not explicitly set.
    148                         if ( empty( $handbooks_config[ $post_type ]['slug'] ) ) {
    149                                 $handbooks_config[ $post_type ]['slug'] = $key;
    150                         }
    151                 }
    152 
    153                 $post_types = array_keys( $handbooks_config );
    154 
    155                 // Enable table of contents.
    156                 new WPorg_Handbook_TOC( $post_types );
    157 
    158                 // Instantiate each of the handbooks.
    159                 self::$handbooks = [];
    160                 foreach ( $handbooks_config as $type => $conf ) {
    161                         self::$handbooks[ $type ] = new WPorg_Handbook( $type, $conf );
    162                 }
    163 
    164                 // Enable glossary.
    165                 WPorg_Handbook_Glossary::init();
    166 
    167                 // Enqueue styles and scripts.
    168                 add_action( 'wp_enqueue_scripts', [ __CLASS__, 'enqueue_styles' ] );
    169                 add_action( 'wp_enqueue_scripts', [ __CLASS__, 'enqueue_scripts' ] );
    170 
    171                 /**
    172                  * Fires after handbooks have been initialized.
    173                  */
    174                 do_action( 'after_handbooks_init' );
    175         }
    176 
    177         /**
    178          * Enqueues styles.
    179          */
    180         public static function enqueue_styles() {
    181                 wp_enqueue_style( 'wporg-handbook-css', plugins_url( 'stylesheets/callout-boxes.css', WPORG_HANDBOOK_PLUGIN_FILE ), [], '20200121' );
    182         }
    183 
    184         /**
    185          * Enqueues scripts.
    186          */
    187         public static function enqueue_scripts() {
    188                 wp_enqueue_script( 'wporg-handbook', plugins_url( 'scripts/handbook.js', WPORG_HANDBOOK_PLUGIN_FILE ), [ 'jquery' ], '20150930' );
     34        static public function enqueue_scripts() {
     35                wp_enqueue_script( 'wporg-handbook', plugins_url( 'scripts/handbook.js', WPORG_HANDBOOK_PLUGIN_FILE ), array( 'jquery' ), '20150930' );
    18936        }
    19037
    19138}
    19239
    193 add_action( 'after_setup_theme', [ 'WPorg_Handbook_Init', 'init' ] );
     40add_action( 'after_setup_theme', array( 'WPorg_Handbook_Init', 'init' ) );
     41
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/table-of-contents.php

    r10837 r10356  
    4040
    4141        function load_filters() {
     42                $this->post_types = array_map( array( $this, 'append_suffix' ), $this->post_types );
     43
    4244                if ( is_singular( $this->post_types ) && ! is_embed() ) {
    4345                        add_filter( 'the_content', array( $this, 'add_toc' ) );
    4446                }
     47        }
     48
     49        function append_suffix( $t ) {
     50                if ( in_array( $t, array( 'handbook', 'page' ) ) ) {
     51                        return $t;
     52                }
     53
     54                return $t . '-handbook';
    4555        }
    4656
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/template-tags.php

    r10837 r10356  
    66 * Wrapper function for WPorg_Handbook_Init::get_post_types().
    77 *
    8  * @return array Array of handbook post types.
     8 * @return array Array with full handbook post type names {post-type}-handbook.
    99 */
    1010function wporg_get_handbook_post_types() {
    … …  
    1313        }
    1414
    15         return WPorg_Handbook_Init::get_post_types();
     15        $post_types = WPorg_Handbook_Init::get_post_types();
     16
     17        foreach ( $post_types as $key => $post_type ) {
     18                if ( 'handbook' !== $post_type ) {
     19                        $post_types[ $key ] = $post_type . '-handbook';
     20                }
     21        }
     22
     23        return $post_types;
    1624}
    1725
    … …  
    7583 * @return bool True if the current page is the landing page for a handbook, false otherwise.
    7684 */
    77 function wporg_is_handbook_landing_page() {
    78         return (
    79                 $GLOBALS['wp_query']->is_handbook_root
    80         ||
    81                 (
    82                         ! empty( $GLOBALS['wp_query']->query_vars['handbook'] )
    83                 &&
    84                         $GLOBALS['wp_query']->found_posts === 1
    85                 &&
    86                         ! empty( $GLOBALS['wp_query']->query_vars['page_id'] )
    87                 )
    88         );
     85 function wporg_is_handbook_landing_page() {
     86         return $GLOBALS['wp_query']->is_handbook_root;
    8987 }
    9088
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/watchlist.php

    r10837 r10356  
    11<?php
    2 /**
    3  * Class providing P2/O2 watchlist functionality.
    4  *
    5  * @package handbook
    6  */
    72
    83class WPorg_Handbook_Watchlist {
    94
    10         /**
    11          * Memoized array of handbook post types.
    12          *
    13          * @var array
    14          */
    15         private static $post_types;
     5        private static $post_types = array( 'handbook' );
    166
    17         /**
    18          * Initializes actions.
    19          */
    207        public static function init() {
    21                 add_action( 'init', [ __CLASS__, 'on_init' ] );
     8                add_action( 'init', array( __CLASS__, 'on_init' ) );
     9        }
     10
     11        public static function on_init() {
     12                self::$post_types = (array) apply_filters( 'handbook_post_types', self::$post_types );
     13                self::$post_types = array_map( array( __CLASS__, 'append_suffix' ), self::$post_types );
     14
     15                add_action( 'p2_action_links', array(__CLASS__, 'display_action_link'), 100 );
     16                add_filter( 'o2_filter_post_actions', array( __CLASS__, 'add_o2_action_link' ) );
     17                add_filter( 'o2_filter_post_action_html', array( __CLASS__, 'get_o2_action_link' ), 10, 2 );
    2218        }
    2319
    2420        /**
    25          * Performs actions intended to occur during 'init' action.
     21         * Appends '-handbook' to the dynamic post type, if not already 'handbook'.
     22         *
     23         * @param  string $t Hanbook post type name.
     24         * @return string
    2625         */
    27         public static function on_init() {
    28                 self::$post_types = WPorg_Handbook_Init::get_post_types();
     26        private static function append_suffix( $t ) {
     27                if ( in_array( $t, array( 'handbook', 'page' ) ) ) {
     28                        return $t;
     29                }
    2930
    30                 self::o2_register_default_post_action_states();
    31 
    32                 add_action( 'p2_action_links',            [ __CLASS__, 'display_action_link' ], 100 );
    33                 add_filter( 'o2_filter_post_actions',     [ __CLASS__, 'add_o2_action_link' ] );
    34                 add_filter( 'o2_filter_post_action_html', [ __CLASS__, 'get_o2_action_link' ], 10, 2 );
     31                return $t . '-handbook';
    3532        }
    3633
    3734        /**
    38          * Returns default post action info.
    39          *
    40          * @param string $type The post action type. Either 'watch' or 'unwatch'.
    41          * @return array
    42          */
    43         protected static function get_default_post_action_info( $type ) {
    44                 $info = [];
    45 
    46                 if ( ! in_array( $type, [ 'unwatch', 'watch' ] ) ) {
    47                         return $info;
    48                 }
    49 
    50                 if ( 'watch' === $type ) {
    51                         $info = [
    52                                 'shortText' => __( 'Watch', 'wporg' ),
    53                                 'title'     => __( 'Get notified about changes to this page', 'wporg' ),
    54                                 'genericon' => 'genericon-subscribe',
    55                                 'classes'   => [ 'genericon', 'genericon-subscribe' ],
    56                                 'rel'       => false,
    57                         ];
    58                 } else {
    59                         $info = [
    60                                 'shortText' => __( 'Unwatch', 'wporg' ),
    61                                 'title'     => __( 'Stop getting notified about changes to this page', 'wporg' ),
    62                                 'genericon' => 'genericon-unsubscribe',
    63                                 'classes'   => [ 'genericon', 'genericon-unsubscribe' ],
    64                                 'rel'       => false,
    65                         ];
    66                 }
    67 
    68                 return $info;
    69         }
    70 
    71         /**
    72          * Registers default post action states.
    73          */
    74         public static function o2_register_default_post_action_states() {
    75                 if( ! function_exists( 'o2_register_post_action_states' ) ) {
    76                         return;
    77                 }
    78 
    79                 o2_register_post_action_states( 'watch', [
    80                         'unwatch' => self::get_default_post_action_info( 'unwatch' ),
    81                         'watch'   => self::get_default_post_action_info( 'watch' ),
    82                 ] );
    83         }
    84 
    85         /**
    86          * Adds a 'Watch' action link to O2.
    87          *
    88          * @param array $actions Array of O2 actions.
    89          * @return array
     35         * Adds a 'Watch' action link to O2
    9036         */
    9137        public static function add_o2_action_link( $actions ) {
    … …  
    9945                }
    10046
    101                 if ( in_array( $post->post_type, self::$post_types ) && ! is_post_type_archive( self::$post_types ) ) {
     47                if ( 'page' == $post->post_type || ( in_array( $post->post_type, self::$post_types ) && ! is_post_type_archive( self::$post_types ) ) ) {
    10248                        $watchlist = get_post_meta( $post->ID, '_wporg_watchlist', true );
    10349
    10450                        if ( $watchlist && in_array( get_current_user_id(), $watchlist ) ) {
    105                                 $actions[35] = wp_parse_args( [
     51                                $actions[35] = [
    10652                                        'action'  => 'watch',
     53                                        'text'    => __( 'Unwatch', 'wporg' ),
    10754                                        'href'    => wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&post_id=' . $post->ID ), 'unwatch-' . $post->ID ),
    108                                         'initialState' => 'unwatch',
    109                                 ], self::get_default_post_action_info( 'unwatch' ) );
     55                                        'title'   => __( 'Stop getting notified about changes to this page', 'wporg' ),
     56                                        'classes' => [ 'genericon', 'genericon-unsubscribe' ], 
     57                                ];
    11058                        } else {
    111                                 $actions[35] = wp_parse_args( [
     59                                $actions[35] = [
    11260                                        'action'  => 'watch',
     61                                        'text'    => __( 'Watch', 'wporg' ),
    11362                                        'href'    => wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&watch=1&post_id=' . $post->ID ), 'watch-' . $post->ID ),
    114                                         'initialState' => 'watch',
    115                                 ], self::get_default_post_action_info( 'watch' ) );
     63                                        'title'   => __( 'Get notified about changes to this page', 'wporg' ),
     64                                        'classes' => [ 'genericon', 'genericon-subscribe' ],
     65                                ];
    11666                        }
    11767                }
    118 
    11968                return $actions;
    12069        }
    12170
    12271        /**
    123          * Returns the HTML for the watch o2 post action.
    124          *
    125          * @param string $html   The HTML for the given action.
    126          * @param array  $action Data about the action.
    127          * @return string
     72         * Create the HTML for the watch o2 post action.
    12873         */
    12974        public static function get_o2_action_link( $html, $action ) {
    … …  
    13479                                $action['title'],
    13580                                implode( ' ', $action['classes'] ),
    136                                 $action['shortText']
     81                                $action['text']
    13782                        );
    13883                }
    … …  
    14287
    14388        /**
    144          * Outputs a 'Watch' action link to P2.
     89         * Adds a 'Watch' action link to P2
    14590         */
    14691        public static function display_action_link() {
     92
    14793                if ( ! is_user_logged_in() ) {
    14894                        return;
    … …  
    15096
    15197                $post = get_post();
    152                 if ( ! $post ) {
    153                         return;
    154                 }
    15598
    156                 if ( in_array( $post->post_type, self::$post_types ) && ! is_post_type_archive( self::$post_types ) ) {
     99                if ( 'page' == $post->post_type || ( in_array( $post->post_type, self::$post_types ) && ! is_post_type_archive( self::$post_types ) ) ) {
     100
    157101                        $watchlist = get_post_meta( $post->ID, '_wporg_watchlist', true );
    158102
    … …  
    172116                                );
    173117                        }
     118
    174119                }
     120
    175121        }
    176122
    … …  
    178124
    179125WPorg_Handbook_Watchlist::init();
     126
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/widgets.php

    r10837 r10356  
    1111        protected static $widget_id_base = 'handbook_pages';
    1212
    13         protected $post_types;
     13        protected $post_types = array( 'handbook' );
    1414
    1515        /**
    … …  
    7272                }
    7373
    74                 $this->post_types = WPorg_Handbook_Init::get_post_types();
     74                $this->post_types = (array) apply_filters( 'handbook_post_types', $this->post_types );
     75                $this->post_types = array_map( array( $this, 'append_suffix' ), $this->post_types );
    7576
    7677                $post_type = '';
    … …  
    9394
    9495                // Exclude root handbook page from the table of contents.
    95                 $page = get_page_by_path( $post_type, OBJECT, $post_type );
     96                $page = get_page_by_path( $this->append_suffix( $post_type ), OBJECT, $post_type );
    9697                if ( ! $page ) {
    97                         $slug = str_replace( '-handbook', '', $post_type );
     98                        $slug = substr( $post_type, 0, -9 );
    9899                        $page = get_page_by_path( $slug, OBJECT, $post_type );
    99100                }
    … …  
    107108
    108109                return $args;
     110        }
     111
     112        public function append_suffix( $t ) {
     113                if ( in_array( $t, array( 'handbook', 'page' ) ) ) {
     114                        return $t;
     115                }
     116
     117                return $t . '-handbook';
    109118        }
    110119
Note: See TracChangeset for help on using the changeset viewer.