Changes in sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/admin-notices.php [10836:9636]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/admin-notices.php
r10836 r9636 9 9 10 10 /** 11 * Initializes functionality.11 * Constructor. 12 12 * 13 13 * @access public 14 14 */ 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' ] ); 15 public function __construct() { 16 add_action( 'admin_notices', array( $this, 'show_new_handbook_message' ) ); 19 17 } 20 18 … … 26 24 * @access public 27 25 */ 28 public staticfunction show_new_handbook_message() {26 public function show_new_handbook_message() { 29 27 global $wp_query; 30 28 … … 33 31 // Only show message in listing of handbook posts when no posts are present yet. 34 32 if ( 35 $current_screen36 &&37 33 'edit' === $current_screen->base 38 34 && … … 40 36 && 41 37 0 === $wp_query->post_count 42 &&43 ( empty( $wp_query->query_vars['post_status'] ) || 'publish' === $wp_query->query_vars['post_status'] )44 38 ) { 45 39 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 55 40 printf( 56 41 /* translators: 1: example landing page title that includes post type name, 2: comma-separated list of acceptable post slugs */ 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' ),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' ), 58 43 WPorg_Handbook::get_name( $current_screen->post_type ), 59 implode( ', ', $suggested_slugs )44 '<code>' . str_replace( '-handbook', '', $current_screen->post_type ) . '</code>, <code>welcome</code>, <code>' . $current_screen->post_type . '</code>, <code>handbook</code>' 60 45 ); 61 46 echo "</p></div>\n"; … … 63 48 } 64 49 65 /**66 * Outputs admin notice indicating the handbook is an imported handbook, if applicable.67 *68 * @access public69 */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_screen83 &&84 'edit' === $current_screen->base85 &&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_display107 );108 echo "</p></div>\n";109 }110 }111 112 /**113 * Outputs admin error notice(s) for any misconfigured imported handbooks.114 *115 * @access public116 */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_screen130 &&131 'edit' === $current_screen->base132 &&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_display157 );158 echo "</p></div>\n";159 }160 }161 50 } 162 51 163 add_action( 'plugins_loaded', [ 'WPorg_Handbook_Admin_Notices', 'init' ]);52 $admin_notices = new WPorg_Handbook_Admin_Notices();
Note: See TracChangeset
for help on using the changeset viewer.