Changeset 2112
- Timestamp:
- 11/22/2015 09:54:40 PM (9 years ago)
- 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 1 1 <?php 2 /** 3 * Plugin name: GlotPress: Help Page 4 */ 2 5 3 class GP_Help_Page_Plugin extends GP_Plugin{4 public $id = 'wporg-help'; 6 class WPorg_GP_Help_Page { 7 5 8 private $hide_notice = 'wporg_help_hide_notice'; 6 9 const handbook_link = 'https://make.wordpress.org/polyglots/handbook/tools/glotpress-translate-wordpress-org/'; 7 10 8 11 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' ) ); 14 15 } 15 16 16 17 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' ) ); 20 20 } 21 21 22 22 function after_hello() { 23 if ( GP::$user->logged_in() || $this->is_notice_hidden() ) {23 if ( is_user_logged_in() || $this->is_notice_hidden() ) { 24 24 echo '<em><a class="secondary" href="' . self::handbook_link . '">Need help?</a></em>'; 25 25 } … … 27 27 28 28 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 ) ) ); 30 30 } 31 31 32 32 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 ); 35 35 } 36 36 setcookie( $this->hide_notice, '1', time() + 3600*24*30, gp_url( '/' ) ); // a month … … 38 38 39 39 function after_notices() { 40 if ( $this->is_notice_hidden() ) return; 40 if ( $this->is_notice_hidden() ) { 41 return; 42 } 41 43 $hide_url = gp_url( '/getting-started/hide-notice' ); 42 44 ?> … … 58 60 } 59 61 60 class GP_Help_Page_Plugin_Route extends GP_Route {62 class WPorg_GP_Help_Page_Route extends GP_Route { 61 63 62 64 function __construct() { 63 65 parent::__construct(); 64 $this->template_path = GP::$plugins->wporg_help->template_path;65 66 } 66 67 67 68 function getting_started() { 68 GP::$plugins->wporg_help->remove_action( 'after_notices' );69 wporg_gp_help_page()->remove_action( 'after_notices' ); 69 70 70 gp_redirect( GP_Help_Page_Plugin::handbook_link, 301 );71 wp_redirect( GP_Help_Page_Plugin::handbook_link, 301 ); 71 72 exit; 72 73 } 73 74 74 75 function hide_notice() { 75 GP::$plugins->wporg_help->hide_notice();76 wporg_gp_help_page()->hide_notice(); 76 77 } 77 78 78 79 } 79 80 80 GP::$plugins->wporg_help = new GP_Help_Page_Plugin; 81 function 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 } 90 add_action( 'plugins_loaded', 'wporg_gp_help_page' );
Note: See TracChangeset
for help on using the changeset viewer.