Changeset 6771
- Timestamp:
- 01/23/2018 10:24:15 PM (7 years ago)
- Location:
- trunk/src/includes/admin
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/classes/class-bbp-admin.php
r6734 r6771 76 76 public $tools = array(); 77 77 78 /** Notices ***************************************************************/ 79 80 /** 81 * @var array Array of notices to output on 'bbp_admin_notices' action 82 */ 83 public $notices = array(); 84 78 85 /** Functions *************************************************************/ 79 86 … … 150 157 /** General Actions ***************************************************/ 151 158 152 add_action( 'bbp_admin_init', array( $this, 'setup_notices' ) ); 153 add_action( 'bbp_admin_init', array( $this, 'hide_notices' ) ); 159 add_action( 'bbp_activation', array( $this, 'new_install' ) ); // Add menu item to settings menu 154 160 add_action( 'bbp_admin_menu', array( $this, 'admin_menus' ) ); // Add menu item to settings menu 155 add_action( 'bbp_admin_head', array( $this, 'admin_head' ) ); // Add some general styling to the admin area 156 add_action( 'bbp_admin_notices', array( $this, 'activation_notice' ) ); // Add notice if not using a bbPress theme 161 add_action( 'bbp_admin_head', array( $this, 'admin_head' ) ); // Add general styling to the admin area 157 162 add_action( 'bbp_register_admin_style', array( $this, 'register_admin_style' ) ); // Add green admin style 158 163 add_action( 'bbp_register_admin_settings', array( $this, 'register_admin_settings' ) ); // Add settings 159 add_action( 'bbp_activation', array( $this, 'new_install' ) ); // Add menu item to settings menu160 164 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) ); // Add enqueued CSS 161 165 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); // Add enqueued JS 166 167 /** Notices ***********************************************************/ 168 169 add_action( 'bbp_admin_init', array( $this, 'setup_notices' ) ); 170 add_action( 'bbp_admin_init', array( $this, 'hide_notices' ) ); 171 add_action( 'bbp_admin_notices', array( $this, 'output_notices' ) ); 162 172 163 173 /** Ajax **************************************************************/ … … 215 225 216 226 // Add tools feedback 217 bbp_admin_tools_feedback( $message, 'notice-bbpress', false );227 $this->add_notice( $message, 'notice-bbpress', false ); 218 228 } 219 229 } … … 228 238 // Bail if not hiding a notice 229 239 if ( empty( $_GET['bbp-hide-notice'] ) ) { 240 return; 241 } 242 243 // Bail if user cannot visit upgrade page (cannot clear notice either!) 244 if ( current_user_can( 'bbp_tools_upgrade_page' ) ) { 230 245 return; 231 246 } … … 242 257 break; 243 258 } 259 } 260 261 /** 262 * Output all admin area notices 263 * 264 * @since 2.6.0 bbPress (r6771) 265 */ 266 public function output_notices() { 267 268 // Bail if no notices 269 if ( empty( $this->notices ) || ! is_array( $this->notices ) ) { 270 return; 271 } 272 273 // Start an output buffer 274 ob_start(); 275 276 // Loop through notices, and add them to buffer 277 foreach ( $this->notices as $notice ) { 278 echo $notice; 279 } 280 281 // Output the current buffer 282 echo ob_get_clean(); 283 } 284 285 /** 286 * Add a notice to the notices array 287 * 288 * @since 2.6.0 bbPress (r6771) 289 * 290 * @param string|WP_Error $message A message to be displayed or {@link WP_Error} 291 * @param string $class Optional. A class to be added to the message div 292 * @param bool $is_dismissible Optional. True to dismiss, false to persist 293 * 294 * @return void 295 */ 296 public function add_notice( $message, $class = false, $is_dismissible = true ) { 297 298 // One message as string 299 if ( is_string( $message ) ) { 300 $message = '<p>' . $message . '</p>'; 301 $default_class ='updated'; 302 303 // Messages as objects 304 } elseif ( is_wp_error( $message ) ) { 305 $errors = $message->get_error_messages(); 306 307 switch ( count( $errors ) ) { 308 case 0: 309 return false; 310 311 case 1: 312 $message = '<p>' . $errors[0] . '</p>'; 313 break; 314 315 default: 316 $message = '<ul>' . "\n\t" . '<li>' . implode( '</li>' . "\n\t" . '<li>', $errors ) . '</li>' . "\n" . '</ul>'; 317 break; 318 } 319 320 $default_class = 'is-error'; 321 322 // Message is an unknown format, so bail 323 } else { 324 return false; 325 } 326 327 // CSS Classes 328 $classes = ! empty( $class ) 329 ? array( $class ) 330 : array( $default_class ); 331 332 // Add dismissible class 333 if ( ! empty( $is_dismissible ) ) { 334 array_push( $classes, 'is-dismissible' ); 335 } 336 337 // Assemble the message 338 $message = '<div id="message" class="notice ' . implode( ' ', array_map( 'esc_attr', $classes ) ) . '">' . $message . '</div>'; 339 $message = str_replace( "'", "\'", $message ); 340 341 // Avoid malformed notices variable 342 if ( ! is_array( $this->notices ) ) { 343 $this->notices = array(); 344 } 345 346 // Add notice to notices array 347 $this->notices[] = $message; 244 348 } 245 349 … … 363 467 * @since 2.1.0 bbPress (r3767) 364 468 * 365 * @return type469 * @return void 366 470 */ 367 471 public static function new_install() { 472 473 // Bail if not a new install 368 474 if ( ! bbp_is_install() ) { 369 475 return; … … 528 634 } 529 635 } 530 }531 532 /**533 * Admin area activation notice534 *535 * Shows a nag message in admin area about the theme not supporting bbPress536 *537 * @since 2.0.0 bbPress (r2743)538 */539 public function activation_notice() {540 // @todo - something fun541 636 } 542 637 -
trunk/src/includes/admin/forums.php
r6573 r6771 67 67 68 68 // Check if there are any bbp_toggle_forum_* requests on admin_init, also have a message displayed 69 add_action( 'load-edit.php', array( $this, 'toggle_forum' ) );70 add_action( ' admin_notices',array( $this, 'toggle_forum_notice' ) );69 add_action( 'load-edit.php', array( $this, 'toggle_forum' ) ); 70 add_action( 'bbp_admin_notices', array( $this, 'toggle_forum_notice' ) ); 71 71 72 72 // Contextual Help -
trunk/src/includes/admin/replies.php
r6697 r6771 74 74 75 75 // Check if there are any bbp_toggle_reply_* requests on admin_init, also have a message displayed 76 add_action( 'load-edit.php', array( $this, 'toggle_reply' ) );77 add_action( ' admin_notices',array( $this, 'toggle_reply_notice' ) );76 add_action( 'load-edit.php', array( $this, 'toggle_reply' ) ); 77 add_action( 'bbp_admin_notices', array( $this, 'toggle_reply_notice' ) ); 78 78 79 79 // Add ability to filter topics and replies per forum -
trunk/src/includes/admin/tools/common.php
r6704 r6771 62 62 */ 63 63 function bbp_admin_tools_feedback( $message, $class = false, $is_dismissible = true ) { 64 65 // One message as string 66 if ( is_string( $message ) ) { 67 $message = '<p>' . $message . '</p>'; 68 $default_class ='updated'; 69 70 // Messages as objects 71 } elseif ( is_wp_error( $message ) ) { 72 $errors = $message->get_error_messages(); 73 74 switch ( count( $errors ) ) { 75 case 0: 76 return false; 77 78 case 1: 79 $message = '<p>' . $errors[0] . '</p>'; 80 break; 81 82 default: 83 $message = '<ul>' . "\n\t" . '<li>' . implode( '</li>' . "\n\t" . '<li>', $errors ) . '</li>' . "\n" . '</ul>'; 84 break; 85 } 86 87 $default_class = 'is-error'; 88 89 // Message is an unknown format, so bail 90 } else { 91 return false; 92 } 93 94 // CSS Classes 95 $classes = ! empty( $class ) 96 ? array( $class ) 97 : array( $default_class ); 98 99 // Add dismissible class 100 if ( ! empty( $is_dismissible ) ) { 101 array_push( $classes, 'is-dismissible' ); 102 } 103 104 // Assemble the message 105 $message = '<div id="message" class="notice ' . implode( ' ', array_map( 'esc_attr', $classes ) ) . '">' . $message . '</div>'; 106 $message = str_replace( "'", "\'", $message ); 107 108 // Ugh 109 $lambda = create_function( '', "echo '$message';" ); 110 add_action( 'admin_notices', $lambda ); 111 112 return $lambda; 64 return bbp_admin()->add_notice( $message, $class, $is_dismissible ); 113 65 } 114 66 -
trunk/src/includes/admin/topics.php
r6697 r6771 78 78 79 79 // Check if there are any bbp_toggle_topic_* requests on admin_init, also have a message displayed 80 add_action( 'load-edit.php', array( $this, 'toggle_topic' ) );81 add_action( ' admin_notices',array( $this, 'toggle_topic_notice' ) );80 add_action( 'load-edit.php', array( $this, 'toggle_topic' ) ); 81 add_action( 'bbp_admin_notices', array( $this, 'toggle_topic_notice' ) ); 82 82 83 83 // Add ability to filter topics and replies per forum
Note: See TracChangeset
for help on using the changeset viewer.