Making WordPress.org

Changeset 10791


Ignore:
Timestamp:
03/07/2021 08:38:58 PM (3 years ago)
Author:
coffee2code
Message:

Handbooks, Watchlist: Improve code formatting and docs for WPorg_Handbook_Watchlist.

  • Add and improve docblocks
  • Use short array syntax
File:
1 edited

Legend:

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

    r10768 r10791  
    11<?php
     2/**
     3 * Class providing P2/O2 watchlist functionality.
     4 *
     5 * @package handbook
     6 */
    27
    38class WPorg_Handbook_Watchlist {
    49
     10    /**
     11     * Memoized array of handbook post types.
     12     *
     13     * @var array
     14     */
    515    private static $post_types;
    616
     17    /**
     18     * Initializes actions.
     19     */
    720    public static function init() {
    8         add_action( 'init', array( __CLASS__, 'on_init' ) );
     21        add_action( 'init', [ __CLASS__, 'on_init' ] );
    922    }
    1023
     24    /**
     25     * Performs actions intended to occur during 'init' action.
     26     */
    1127    public static function on_init() {
    1228        self::$post_types = WPorg_Handbook_Init::get_post_types();
    1329
    14         add_action( 'p2_action_links', array(__CLASS__, 'display_action_link'), 100 );
    15         add_filter( 'o2_filter_post_actions', array( __CLASS__, 'add_o2_action_link' ) );
    16         add_filter( 'o2_filter_post_action_html', array( __CLASS__, 'get_o2_action_link' ), 10, 2 );
     30        add_action( 'p2_action_links',            [ __CLASS__, 'display_action_link' ], 100 );
     31        add_filter( 'o2_filter_post_actions',     [ __CLASS__, 'add_o2_action_link' ] );
     32        add_filter( 'o2_filter_post_action_html', [ __CLASS__, 'get_o2_action_link' ], 10, 2 );
    1733    }
    1834
    1935    /**
    20      * Adds a 'Watch' action link to O2
     36     * Adds a 'Watch' action link to O2.
     37     *
     38     * @param array $actions Array of O2 actions.
     39     * @return array
    2140     */
    2241    public static function add_o2_action_link( $actions ) {
     
    5170            }
    5271        }
     72
    5373        return $actions;
    5474    }
    5575
    5676    /**
    57      * Create the HTML for the watch o2 post action.
     77     * Returns the HTML for the watch o2 post action.
     78     *
     79     * @param string $html   The HTML for the given action.
     80     * @param array  $action Data about the action.
     81     * @return string
    5882     */
    5983    public static function get_o2_action_link( $html, $action ) {
     
    7296
    7397    /**
    74      * Adds a 'Watch' action link to P2
     98     * Outputs a 'Watch' action link to P2.
    7599     */
    76100    public static function display_action_link() {
    77 
    78101        if ( ! is_user_logged_in() ) {
    79102            return;
     
    83106
    84107        if ( 'page' == $post->post_type || ( in_array( $post->post_type, self::$post_types ) && ! is_post_type_archive( self::$post_types ) ) ) {
    85 
    86108            $watchlist = get_post_meta( $post->ID, '_wporg_watchlist', true );
    87109
     
    101123                );
    102124            }
    103 
    104125        }
    105 
    106126    }
    107127
     
    109129
    110130WPorg_Handbook_Watchlist::init();
    111 
Note: See TracChangeset for help on using the changeset viewer.