Making WordPress.org

Changeset 2112


Ignore:
Timestamp:
11/22/2015 09:54:40 PM (9 years ago)
Author:
ocean90
Message:

Translate: Convert the GP plugin "wporg-help" to a WP plugin.

See #1352.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-help
Files:
2 copied

Legend:

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

    r2102 r2112  
    11<?php
     2/**
     3 * Plugin name: GlotPress: Help Page
     4 */
    25
    3 class GP_Help_Page_Plugin extends GP_Plugin {
    4     public $id = 'wporg-help';
     6class WPorg_GP_Help_Page {
     7
    58    private $hide_notice = 'wporg_help_hide_notice';
    69    const handbook_link = 'https://make.wordpress.org/polyglots/handbook/tools/glotpress-translate-wordpress-org/';
    710
    811    function __construct() {
    9         parent::__construct();
    10         $this->template_path = dirname( __FILE__ );
    11         $this->add_action( 'init' );
    12         $this->add_action( 'after_hello' );
    13         $this->add_action( 'after_notices' );
     12        add_action( 'init', array( $this, 'init' ) );
     13        add_action( 'after_hello', array( $this, 'after_hello' ) );
     14        add_action( 'gp_after_notices', array( $this, 'after_notices' ) );
    1415    }
    1516
    1617    function init() {
    17         GP::$router->add( '/getting-started', array('GP_Help_Page_Plugin_Route', 'getting_started') );
    18         GP::$router->add( '/getting-started/', array('GP_Help_Page_Plugin_Route', 'getting_started') );
    19         GP::$router->add( '/getting-started/hide-notice', array('GP_Help_Page_Plugin_Route', 'hide_notice') );
     18        GP::$router->add( '/getting-started/?', array( 'WPorg_GP_Help_Page_Route', 'getting_started' ) );
     19        GP::$router->add( '/getting-started/hide-notice', array( 'WPorg_GP_Help_Page_Route', 'hide_notice' ) );
    2020    }
    2121
    2222    function after_hello() {
    23         if ( GP::$user->logged_in() || $this->is_notice_hidden() ) {
     23        if ( is_user_logged_in() || $this->is_notice_hidden() ) {
    2424            echo '<em><a class="secondary" href="' . self::handbook_link . '">Need help?</a></em>';
    2525        }
     
    2727
    2828    function is_notice_hidden() {
    29         return ( gp_array_get( $_COOKIE, $this->hide_notice ) || ( GP::$user->logged_in() && GP::$user->current()->get_meta( $this->hide_notice ) ) );
     29        return ( gp_array_get( $_COOKIE, $this->hide_notice ) || ( is_user_logged_in() && get_user_meta( get_current_user_id(), $this->hide_notice ) ) );
    3030    }
    3131
    3232    function hide_notice() {
    33         if ( GP::$user->logged_in() ) {
    34             GP::$user->current()->set_meta( $this->hide_notice, true );
     33        if ( is_user_logged_in() ) {
     34            update_user_meta( get_current_user_id(), $this->hide_notice, true );
    3535        }
    3636        setcookie( $this->hide_notice, '1', time() + 3600*24*30, gp_url( '/' ) ); // a month
     
    3838
    3939    function after_notices() {
    40         if ( $this->is_notice_hidden() ) return;
     40        if ( $this->is_notice_hidden() ) {
     41            return;
     42        }
    4143        $hide_url = gp_url( '/getting-started/hide-notice' );
    4244?>
     
    5860}
    5961
    60 class GP_Help_Page_Plugin_Route extends GP_Route {
     62class WPorg_GP_Help_Page_Route extends GP_Route {
    6163
    6264    function __construct() {
    6365        parent::__construct();
    64         $this->template_path = GP::$plugins->wporg_help->template_path;
    6566    }
    6667
    6768    function getting_started() {
    68         GP::$plugins->wporg_help->remove_action( 'after_notices' );
     69        wporg_gp_help_page()->remove_action( 'after_notices' );
    6970
    70         gp_redirect( GP_Help_Page_Plugin::handbook_link, 301 );
     71        wp_redirect( GP_Help_Page_Plugin::handbook_link, 301 );
    7172        exit;
    7273    }
    7374
    7475    function hide_notice() {
    75         GP::$plugins->wporg_help->hide_notice();
     76        wporg_gp_help_page()->hide_notice();
    7677    }
    7778
    7879}
    7980
    80 GP::$plugins->wporg_help = new GP_Help_Page_Plugin;
     81function wporg_gp_help_page() {
     82    global $wporg_gp_help_page;
     83
     84    if ( ! isset( $wporg_gp_help_page ) ) {
     85        $wporg_gp_help_page = new WPorg_GP_Help_Page();
     86    }
     87
     88    return $wporg_gp_help_page;
     89}
     90add_action( 'plugins_loaded', 'wporg_gp_help_page' );
Note: See TracChangeset for help on using the changeset viewer.