Changes in sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/admin-notices.php [9636:10836]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/admin-notices.php
r9636 r10836 9 9 10 10 /** 11 * Constructor.11 * Initializes functionality. 12 12 * 13 13 * @access public 14 14 */ 15 public function __construct() { 16 add_action( 'admin_notices', array( $this, 'show_new_handbook_message' ) ); 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' ] ); 17 19 } 18 20 … … 24 26 * @access public 25 27 */ 26 public function show_new_handbook_message() {28 public static function show_new_handbook_message() { 27 29 global $wp_query; 28 30 … … 31 33 // Only show message in listing of handbook posts when no posts are present yet. 32 34 if ( 35 $current_screen 36 && 33 37 'edit' === $current_screen->base 34 38 && … … 36 40 && 37 41 0 === $wp_query->post_count 42 && 43 ( empty( $wp_query->query_vars['post_status'] ) || 'publish' === $wp_query->query_vars['post_status'] ) 38 44 ) { 39 45 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 40 55 printf( 41 56 /* translators: 1: example landing page title that includes post type name, 2: comma-separated list of acceptable post slugs */ 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' ),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‘s permalink URL, but will still appear in the permalinks for sub-pages.', 'wporg' ), 43 58 WPorg_Handbook::get_name( $current_screen->post_type ), 44 '<code>' . str_replace( '-handbook', '', $current_screen->post_type ) . '</code>, <code>welcome</code>, <code>' . $current_screen->post_type . '</code>, <code>handbook</code>'59 implode( ', ', $suggested_slugs ) 45 60 ); 46 61 echo "</p></div>\n"; … … 48 63 } 49 64 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 } 50 161 } 51 162 52 $admin_notices = new WPorg_Handbook_Admin_Notices();163 add_action( 'plugins_loaded', [ 'WPorg_Handbook_Admin_Notices', 'init' ] );
Note: See TracChangeset
for help on using the changeset viewer.