WordPress.org

Making WordPress.org

Changeset 772


Ignore:
Timestamp:
07/30/2014 09:45:47 PM (7 years ago)
Author:
coffee2code
Message:

Handbook plugin: make watch/unwatch feature an action link instead of a widget

  • Remove WPorg_Handbook_Widget and WPorg_Handbook_Widget_for_Pages classes and usage thereof
  • Add WPorg_Handbook_Watchlist class in new inc/watchlist.php
  • Add title text to links to provide context about what watching actually does

Fixes #437

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook
Files:
1 added
4 edited

Legend:

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

    r705 r772  
    1111new WPorg_Handbook_TOC( array( 'page' ) );
    1212
    13 add_action( 'widgets_init', 'wporg_handbook_functionality_for_pages_widget', 12 );
    14 function wporg_handbook_functionality_for_pages_widget() {
    15     require_once dirname( __FILE__ ) . '/inc/widgets.php';
    16     register_widget( 'WPorg_Handbook_Widget_for_Pages' );
    17 }
    18 
    1913add_filter( 'wporg_email_changes_for_post_types', 'wporg_email_changes_for_pages' );
    2014function wporg_email_changes_for_pages( $post_types ) {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/handbook.php

    r770 r772  
    99require_once dirname( __FILE__ ) . '/inc/table-of-contents.php';
    1010require_once dirname( __FILE__ ) . '/inc/email-post-changes.php';
     11require_once dirname( __FILE__ ) . '/inc/watchlist.php';
    1112
    1213//WPorg_Handbook_Glossary::init();
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/email-post-changes.php

    r707 r772  
    88
    99    public static function init() {
    10         add_action( 'widgets_init', array( __CLASS__, 'handbook_sidebar' ), 11 ); // After P2
    1110        add_filter( 'email_post_changes_emails', array( __CLASS__, 'email_post_changes_emails' ), 10, 3 );
    1211        add_action( 'admin_post_wporg_watchlist', array( __CLASS__, 'update_watchlist' ) );
    1312        add_action( 'option_email_post_changes', array( __CLASS__, 'option_email_post_changes' ) );
    14     }
    15 
    16     public static function handbook_sidebar() {
    17         require_once dirname( __FILE__ ) . '/widgets.php';
    18         register_widget( 'WPorg_Handbook_Widget' );
    1913    }
    2014
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/widgets.php

    r707 r772  
    11<?php
    2 
    3 class WPorg_Handbook_Widget extends WP_Widget {
    4 
    5     protected $post_types = array( 'handbook' );
    6 
    7     function __construct() {
    8         $this->post_types = (array) apply_filters( 'handbook_post_types', $this->post_types );
    9         $this->post_types = array_map( array( $this, 'append_suffix' ), $this->post_types );
    10         parent::__construct( 'handbook', __( 'Handbook Tools', 'wporg' ), array( 'classname' => 'widget_wporg_handbook', 'description' => __( 'Shows watch/unwatch links for handbook pages.', 'wporg' ) ) );
    11     }
    12 
    13     function widget( $args, $instance ) {
    14         if ( ! is_user_logged_in() )
    15             return;
    16 
    17         $post = get_post();
    18         if ( $post->post_type == 'page' || ( in_array( $post->post_type, $this->post_types ) && ! is_post_type_archive( $this->post_types ) ) ) {
    19             $watchlist = get_post_meta( $post->ID, '_wporg_watchlist', true );
    20             if ( isset( $args['before_widget'] ) && $args['before_widget'] ) {
    21                 echo $args['before_widget'];
    22             }
    23             echo '<p>';
    24             if ( $watchlist && in_array( get_current_user_id(), $watchlist ) ) {
    25                 printf( __( 'You are watching this page. <a href="%s">Unwatch</a>', 'wporg' ),
    26                 wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&post_id=' . $post->ID ), 'unwatch-' . $post->ID ) );
    27             } else {
    28                 printf( __( '<a href="%s">Watch this page</a>', 'wporg' ),
    29                 wp_nonce_url( admin_url( 'admin-post.php?action=wporg_watchlist&watch=1&post_id=' . $post->ID ), 'watch-' . $post->ID ) );
    30             }
    31             echo '</p>';
    32             if ( isset( $args['after_widget'] ) && $args['after_widget'] ) {
    33                 echo $args['after_widget'];
    34             }
    35         } else {
    36             return;
    37         }
    38 
    39     }
    40 
    41     function append_suffix( $t ) {
    42         if ( in_array( $t, array( 'handbook', 'page' ) ) ) {
    43             return $t;
    44         }
    45 
    46         return $t . '-handbook';
    47     }
    48 }
    49 
    50 class WPorg_Handbook_Widget_for_Pages extends WPorg_Handbook_Widget {
    51 
    52     protected $post_types = array( 'page' );
    53 
    54     function __construct() {
    55         WP_Widget::__construct( 'handbook_for_pages', __( 'Handbook Tools (for Pages)', 'wporg' ), array( 'classname' => 'widget_wporg_handbook', 'description' => __( 'Shows watch/unwatch links for Pages.', 'wporg' ) ) );
    56     }
    57 }
    582
    593class WPorg_Handbook_Pages_Widget extends WP_Widget_Pages {
Note: See TracChangeset for help on using the changeset viewer.