Changeset 5440
- Timestamp:
- 07/09/2014 11:58:59 PM (11 years ago)
- Location:
- trunk/src/includes/admin
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/actions.php
r5314 r5440 106 106 107 107 // Bail if plugin is not network activated 108 if ( ! is_plugin_active_for_network( bbpress()->basename ) ) 108 if ( ! is_plugin_active_for_network( bbpress()->basename ) ) { 109 109 return; 110 } 110 111 111 112 // Switch to the new blog -
trunk/src/includes/admin/admin.php
r5399 r5440 132 132 133 133 // Bail to prevent interfering with the deactivation process 134 if ( bbp_is_deactivation() ) 134 if ( bbp_is_deactivation() ) { 135 135 return; 136 } 136 137 137 138 /** General Actions ***************************************************/ … … 274 275 275 276 // Bail if plugin is not network activated 276 if ( ! is_plugin_active_for_network( bbpress()->basename ) ) 277 if ( ! is_plugin_active_for_network( bbpress()->basename ) ) { 277 278 return; 279 } 278 280 279 281 add_submenu_page( … … 296 298 297 299 // Bail if plugin is not network activated 298 if ( ! is_plugin_active_for_network( bbpress()->basename ) ) 300 if ( ! is_plugin_active_for_network( bbpress()->basename ) ) { 299 301 return; 302 } 300 303 301 304 add_submenu_page( … … 316 319 */ 317 320 public static function new_install() { 318 if ( !bbp_is_install() ) 321 if ( !bbp_is_install() ) { 319 322 return; 323 } 320 324 321 325 bbp_create_initial_content(); … … 336 340 // Bail if no sections available 337 341 $sections = bbp_admin_get_settings_sections(); 338 if ( empty( $sections ) ) 342 if ( empty( $sections ) ) { 339 343 return false; 344 } 340 345 341 346 // Are we using settings integration? … … 346 351 347 352 // Only proceed if current user can see this section 348 if ( ! current_user_can( $section_id ) ) 353 if ( ! current_user_can( $section_id ) ) { 349 354 continue; 355 } 350 356 351 357 // Only add section and fields if section has fields 352 358 $fields = bbp_admin_get_settings_fields_for_section( $section_id ); 353 if ( empty( $fields ) ) 359 if ( empty( $fields ) ) { 354 360 continue; 361 } 355 362 356 363 // Toggle the section if core integration is on … … 450 457 451 458 // Leave if we're not in the import section 452 if ( !defined( 'WP_LOAD_IMPORTERS' ) ) 459 if ( !defined( 'WP_LOAD_IMPORTERS' ) ) { 453 460 return; 461 } 454 462 455 463 // Load Importer API … … 656 664 */ 657 665 public function hide_theme_compat_packages( $sections = array() ) { 658 if ( count( bbpress()->theme_compat->packages ) <= 1 ) 666 if ( count( bbpress()->theme_compat->packages ) <= 1 ) { 659 667 unset( $sections['bbp_settings_theme_compat'] ); 668 } 660 669 661 670 return $sections; … … 1016 1025 1017 1026 // Site errored out, no response? 1018 if ( is_wp_error( $response ) ) 1027 if ( is_wp_error( $response ) ) { 1019 1028 wp_die( sprintf( __( 'Warning! Problem updating %1$s. Your server may not be able to connect to sites running on it. Error message: <em>%2$s</em>', 'bbpress' ), $siteurl, $response->get_error_message() ) ); 1029 } 1020 1030 1021 1031 // Switch to the new blog -
trunk/src/includes/admin/converter.php
r5428 r5440 28 28 29 29 // "I wonder where I'll float next." 30 if ( empty( $_SERVER['REQUEST_METHOD'] ) ) 30 if ( empty( $_SERVER['REQUEST_METHOD'] ) ) { 31 31 return; 32 } 32 33 33 34 // Bail if request is not correct … … 36 37 // Converter is converting 37 38 case 'POST' : 38 if ( ( empty( $_POST['action'] ) || ( 'bbconverter_process' != $_POST['action'] ) ) ) 39 if ( ( empty( $_POST['action'] ) || ( 'bbconverter_process' != $_POST['action'] ) ) ) { 39 40 return; 41 } 40 42 41 43 break; … … 43 45 // Some other admin page 44 46 case 'GET' : 45 if ( ( empty( $_GET['page'] ) || ( 'bbp-converter' != $_GET['page'] ) ) ) 47 if ( ( empty( $_GET['page'] ) || ( 'bbp-converter' != $_GET['page'] ) ) ) { 46 48 return; 49 } 47 50 48 51 break; … … 216 219 217 220 function bbconverter_start() { 218 if( false == bbconverter_is_running ) {221 if( false === bbconverter_is_running ) { 219 222 bbconverter_is_running = true; 220 223 jQuery('#bbp-converter-start').hide(); … … 246 249 bbconverter_log(response); 247 250 248 if ( response == '<p class="loading"><?php esc_html_e( 'Conversion Complete', 'bbpress' ); ?></p>' || response.indexOf('error') > -1 ) {251 if ( response === '<p class="loading"><?php esc_html_e( 'Conversion Complete', 'bbpress' ); ?></p>' || response.indexOf('error') > -1 ) { 249 252 bbconverter_log('<p>Repair any missing information: <a href="<?php echo admin_url(); ?>tools.php?page=bbp-repair">Continue</a></p>'); 250 253 bbconverter_stop(); … … 259 262 260 263 function bbconverter_log(text) { 261 if ( jQuery('#bbp-converter-message').css('display') == 'none' ) {264 if ( jQuery('#bbp-converter-message').css('display') === 'none' ) { 262 265 jQuery('#bbp-converter-message').show(); 263 266 } … … 287 290 $query = get_option( '_bbp_converter_query' ); 288 291 289 if ( ! empty( $query ) ) 292 if ( ! empty( $query ) ) { 290 293 $before = '<p class="loading" title="' . esc_attr( $query ) . '">'; 294 } 291 295 292 296 echo $before . $output . $after; … … 324 328 // Bail if platform did not get saved 325 329 $platform = !empty( $_POST['_bbp_converter_platform' ] ) ? $_POST['_bbp_converter_platform' ] : get_option( '_bbp_converter_platform' ); 326 if ( empty( $platform ) ) 330 if ( empty( $platform ) ) { 327 331 return; 332 } 328 333 329 334 // Include the appropriate converter. … … 548 553 549 554 $table_name = $wpdb->prefix . 'bbp_converter_translator'; 550 if ( ! empty( $drop ) && $wpdb->get_var( "SHOW TABLES LIKE '{$table_name}'" ) == $table_name ) 555 if ( ! empty( $drop ) && $wpdb->get_var( "SHOW TABLES LIKE '{$table_name}'" ) == $table_name ) { 551 556 $wpdb->query( "DROP TABLE {$table_name}" ); 557 } 552 558 553 559 require_once( ABSPATH . '/wp-admin/includes/upgrade.php' ); -
trunk/src/includes/admin/forums.php
r5353 r5440 92 92 */ 93 93 private function bail() { 94 if ( !isset( get_current_screen()->post_type ) || ( $this->post_type != get_current_screen()->post_type ) ) 94 if ( !isset( get_current_screen()->post_type ) || ( $this->post_type != get_current_screen()->post_type ) ) { 95 95 return true; 96 } 96 97 97 98 return false; … … 118 119 public function edit_help() { 119 120 120 if ( $this->bail() ) return; 121 if ( $this->bail() ) { 122 return; 123 } 121 124 122 125 // Overview … … 179 182 public function new_help() { 180 183 181 if ( $this->bail() ) return; 184 if ( $this->bail() ) { 185 return; 186 } 182 187 183 188 $customize_display = '<p>' . __( 'The title field and the big forum editing Area are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Excerpt, Send Trackbacks, Custom Fields, Discussion, Slug, Author) or to choose a 1- or 2-column layout for this screen.', 'bbpress' ) . '</p>'; … … 241 246 public function attributes_metabox() { 242 247 243 if ( $this->bail() ) return; 248 if ( $this->bail() ) { 249 return; 250 } 244 251 245 252 add_meta_box ( … … 279 286 public function attributes_metabox_save( $forum_id ) { 280 287 281 if ( $this->bail() ) return $forum_id; 288 if ( $this->bail() ) { 289 return $forum_id; 290 } 282 291 283 292 // Bail if doing an autosave 284 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 293 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 285 294 return $forum_id; 295 } 286 296 287 297 // Bail if not a post request 288 if ( ! bbp_is_post_request() ) 298 if ( ! bbp_is_post_request() ) { 289 299 return $forum_id; 300 } 290 301 291 302 // Nonce check 292 if ( empty( $_POST['bbp_forum_metabox'] ) || !wp_verify_nonce( $_POST['bbp_forum_metabox'], 'bbp_forum_metabox_save' ) ) 303 if ( empty( $_POST['bbp_forum_metabox'] ) || !wp_verify_nonce( $_POST['bbp_forum_metabox'], 'bbp_forum_metabox_save' ) ) { 293 304 return $forum_id; 305 } 294 306 295 307 // Only save for forum post-types 296 if ( ! bbp_is_forum( $forum_id ) ) 308 if ( ! bbp_is_forum( $forum_id ) ) { 297 309 return $forum_id; 310 } 298 311 299 312 // Bail if current user cannot edit this forum 300 if ( !current_user_can( 'edit_forum', $forum_id ) ) 313 if ( !current_user_can( 'edit_forum', $forum_id ) ) { 301 314 return $forum_id; 315 } 302 316 303 317 // Parent ID … … 328 342 public function admin_head() { 329 343 330 if ( $this->bail() ) return;331 332 ?>344 if ( $this->bail() ) { 345 return; 346 } ?> 333 347 334 348 <style type="text/css" media="screen"> … … 445 459 446 460 $is_open = bbp_is_forum_open( $forum_id ); 447 $message = true === $is_open ? 'closed' : 'opened'; 448 $success = true === $is_open ? bbp_close_forum( $forum_id ) : bbp_open_forum( $forum_id ); 461 $message = ( true === $is_open ) 462 ? 'closed' 463 : 'opened'; 464 $success = ( true === $is_open ) 465 ? bbp_close_forum( $forum_id ) 466 : bbp_open_forum( $forum_id ); 449 467 450 468 break; … … 510 528 switch ( $notice ) { 511 529 case 'opened' : 512 if ( $message = $is_failure ) { 513 $message = sprintf( __( 'There was a problem opening the forum "%1$s".', 'bbpress' ), $forum_title ); 514 } else { 515 $message = sprintf( __( 'Forum "%1$s" successfully opened.', 'bbpress' ), $forum_title ); 516 } 530 $message = ( $is_failure === true ) 531 ? sprintf( __( 'There was a problem opening the forum "%1$s".', 'bbpress' ), $forum_title ) 532 : sprintf( __( 'Forum "%1$s" successfully opened.', 'bbpress' ), $forum_title ); 517 533 break; 518 534 519 535 case 'closed' : 520 if ( $message = $is_failure ) { 521 $message = sprintf( __( 'There was a problem closing the forum "%1$s".', 'bbpress' ), $forum_title ); 522 } else { 523 $message = sprintf( __( 'Forum "%1$s" successfully closed.', 'bbpress' ), $forum_title ); 524 } 536 $message = ( $is_failure === true ) 537 ? sprintf( __( 'There was a problem closing the forum "%1$s".', 'bbpress' ), $forum_title ) 538 : sprintf( __( 'Forum "%1$s" successfully closed.', 'bbpress' ), $forum_title ); 525 539 break; 526 540 } … … 551 565 public function column_headers( $columns ) { 552 566 553 if ( $this->bail() ) return $columns; 567 if ( $this->bail() ) { 568 return $columns; 569 } 554 570 555 571 $columns = array ( … … 585 601 public function column_data( $column, $forum_id ) { 586 602 587 if ( $this->bail() ) return; 603 if ( $this->bail() ) { 604 return; 605 } 588 606 589 607 switch ( $column ) { … … 606 624 case 'bbp_forum_freshness' : 607 625 $last_active = bbp_get_forum_last_active_time( $forum_id, false ); 608 if ( !empty( $last_active ) ) 626 if ( !empty( $last_active ) ) { 609 627 echo esc_html( $last_active ); 610 else628 } else { 611 629 esc_html_e( 'No Topics', 'bbpress' ); 630 } 612 631 613 632 break; … … 684 703 global $post_ID; 685 704 686 if ( $this->bail() ) return $messages; 705 if ( $this->bail() ) { 706 return $messages; 707 } 687 708 688 709 // URL for the current forum -
trunk/src/includes/admin/functions.php
r5401 r5440 54 54 */ 55 55 function bbp_admin_custom_menu_order( $menu_order = false ) { 56 if ( false === bbpress()->admin->show_separator ) 56 if ( false === bbpress()->admin->show_separator ) { 57 57 return $menu_order; 58 } 58 59 59 60 return true; … … 72 73 73 74 // Bail if user cannot see any top level bbPress menus 74 if ( empty( $menu_order ) || ( false === bbpress()->admin->show_separator ) ) 75 if ( empty( $menu_order ) || ( false === bbpress()->admin->show_separator ) ) { 75 76 return $menu_order; 77 } 76 78 77 79 // Initialize our custom order array … … 131 133 132 134 // Bail if not on an admin page and not getting a sample permalink 133 if ( !empty( $sample ) && is_admin() && bbp_is_custom_post_type() ) 135 if ( !empty( $sample ) && is_admin() && bbp_is_custom_post_type() ) { 134 136 return urldecode( $post_link ); 137 } 135 138 136 139 // Return post link … … 175 178 */ 176 179 function bbp_do_uninstall( $site_id = 0 ) { 177 if ( empty( $site_id ) ) 180 if ( empty( $site_id ) ) { 178 181 $site_id = get_current_blog_id(); 182 } 179 183 180 184 switch_to_blog( $site_id ); … … 241 245 242 246 // This tweaks the Tools subnav menu to only show one bbPress menu item 243 if ( ! in_array( $plugin_page, array( 'bbp-settings' ) ) ) 247 if ( ! in_array( $plugin_page, array( 'bbp-settings' ) ) ) { 244 248 $submenu_file = 'bbp-repair'; 249 } 245 250 } 246 251 -
trunk/src/includes/admin/replies.php
r5300 r5440 99 99 */ 100 100 private function bail() { 101 if ( !isset( get_current_screen()->post_type ) || ( $this->post_type !== get_current_screen()->post_type ) ) 101 if ( !isset( get_current_screen()->post_type ) || ( $this->post_type !== get_current_screen()->post_type ) ) { 102 102 return true; 103 } 103 104 104 105 return false; … … 125 126 public function edit_help() { 126 127 127 if ( $this->bail() ) return; 128 if ( $this->bail() ) { 129 return; 130 } 128 131 129 132 // Overview … … 189 192 public function new_help() { 190 193 191 if ( $this->bail() ) return; 194 if ( $this->bail() ) { 195 return; 196 } 192 197 193 198 $customize_display = '<p>' . __( 'The title field and the big reply editing Area are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Excerpt, Send Trackbacks, Custom Fields, Discussion, Slug, Author) or to choose a 1- or 2-column layout for this screen.', 'bbpress' ) . '</p>'; … … 249 254 public function attributes_metabox() { 250 255 251 if ( $this->bail() ) return; 256 if ( $this->bail() ) { 257 return; 258 } 252 259 253 260 add_meta_box ( … … 277 284 public function attributes_metabox_save( $reply_id ) { 278 285 279 if ( $this->bail() ) return $reply_id; 286 if ( $this->bail() ) { 287 return $reply_id; 288 } 280 289 281 290 // Bail if doing an autosave 282 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 291 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 283 292 return $reply_id; 293 } 284 294 285 295 // Bail if not a post request 286 if ( ! bbp_is_post_request() ) 296 if ( ! bbp_is_post_request() ) { 287 297 return $reply_id; 298 } 288 299 289 300 // Check action exists 290 if ( empty( $_POST['action'] ) ) 301 if ( empty( $_POST['action'] ) ) { 291 302 return $reply_id; 303 } 292 304 293 305 // Nonce check 294 if ( empty( $_POST['bbp_reply_metabox'] ) || !wp_verify_nonce( $_POST['bbp_reply_metabox'], 'bbp_reply_metabox_save' ) ) 306 if ( empty( $_POST['bbp_reply_metabox'] ) || !wp_verify_nonce( $_POST['bbp_reply_metabox'], 'bbp_reply_metabox_save' ) ) { 295 307 return $reply_id; 308 } 296 309 297 310 // Current user cannot edit this reply 298 if ( !current_user_can( 'edit_reply', $reply_id ) ) 311 if ( !current_user_can( 'edit_reply', $reply_id ) ) { 299 312 return $reply_id; 313 } 300 314 301 315 // Get the reply meta post values … … 336 350 public function author_metabox() { 337 351 338 if ( $this->bail() ) return; 352 if ( $this->bail() ) { 353 return; 354 } 339 355 340 356 // Bail if post_type is not a reply 341 if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) 357 if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) { 342 358 return; 359 } 343 360 344 361 // Add the metabox … … 368 385 public function admin_head() { 369 386 370 if ( $this->bail() ) return;371 372 ?>387 if ( $this->bail() ) { 388 return; 389 } ?> 373 390 374 391 <style type="text/css" media="screen"> … … 447 464 public function toggle_reply() { 448 465 449 if ( $this->bail() ) return; 466 if ( $this->bail() ) { 467 return; 468 } 450 469 451 470 // Only proceed if GET is a reply toggle action … … 458 477 // Get reply and die if empty 459 478 $reply = bbp_get_reply( $reply_id ); 460 if ( empty( $reply ) ) // Which reply?479 if ( empty( $reply ) ) { 461 480 wp_die( __( 'The reply was not found!', 'bbpress' ) ); 462 463 if ( !current_user_can( 'moderate', $reply->ID ) ) // What is the user doing here? 481 } 482 483 // What is the user doing here? 484 if ( !current_user_can( 'moderate', $reply->ID ) ) { 464 485 wp_die( __( 'You do not have the permission to do that!', 'bbpress' ) ); 486 } 465 487 466 488 switch ( $action ) { … … 478 500 $message = array( 'bbp_reply_toggle_notice' => $message, 'reply_id' => $reply->ID ); 479 501 480 if ( false === $success || is_wp_error( $success ) ) 502 if ( false === $success || is_wp_error( $success ) ) { 481 503 $message['failed'] = '1'; 504 } 482 505 483 506 // Do additional reply toggle actions (admin side) … … 518 541 519 542 // Empty? No reply? 520 if ( empty( $notice ) || empty( $reply_id ) ) 543 if ( empty( $notice ) || empty( $reply_id ) ) { 521 544 return; 545 } 522 546 523 547 // Get reply and bail if empty 524 548 $reply = bbp_get_reply( $reply_id ); 525 if ( empty( $reply ) ) 549 if ( empty( $reply ) ) { 526 550 return; 551 } 527 552 528 553 $reply_title = bbp_get_reply_title( $reply->ID ); … … 530 555 switch ( $notice ) { 531 556 case 'spammed' : 532 $message = $is_failure === true ? sprintf( __( 'There was a problem marking the reply "%1$s" as spam.', 'bbpress' ), $reply_title ) : sprintf( __( 'Reply "%1$s" successfully marked as spam.', 'bbpress' ), $reply_title ); 557 $message = ( $is_failure === true ) 558 ? sprintf( __( 'There was a problem marking the reply "%1$s" as spam.', 'bbpress' ), $reply_title ) 559 : sprintf( __( 'Reply "%1$s" successfully marked as spam.', 'bbpress' ), $reply_title ); 533 560 break; 534 561 535 562 case 'unspammed' : 536 $message = $is_failure === true ? sprintf( __( 'There was a problem unmarking the reply "%1$s" as spam.', 'bbpress' ), $reply_title ) : sprintf( __( 'Reply "%1$s" successfully unmarked as spam.', 'bbpress' ), $reply_title ); 563 $message = ( $is_failure === true ) 564 ? sprintf( __( 'There was a problem unmarking the reply "%1$s" as spam.', 'bbpress' ), $reply_title ) 565 : sprintf( __( 'Reply "%1$s" successfully unmarked as spam.', 'bbpress' ), $reply_title ); 537 566 break; 538 567 } … … 563 592 public function column_headers( $columns ) { 564 593 565 if ( $this->bail() ) return $columns; 594 if ( $this->bail() ) { 595 return $columns; 596 } 566 597 567 598 $columns = array( … … 607 638 public function column_data( $column, $reply_id ) { 608 639 609 if ( $this->bail() ) return; 640 if ( $this->bail() ) { 641 return; 642 } 610 643 611 644 // Get topic ID … … 719 752 public function row_actions( $actions, $reply ) { 720 753 721 if ( $this->bail() ) return $actions; 754 if ( $this->bail() ) { 755 return $actions; 756 } 722 757 723 758 unset( $actions['inline hide-if-no-js'] ); … … 727 762 728 763 // User cannot view replies in trash 729 if ( ( bbp_get_trash_status_id() === $reply->post_status ) && !current_user_can( 'view_trash' ) ) 764 if ( ( bbp_get_trash_status_id() === $reply->post_status ) && !current_user_can( 'view_trash' ) ) { 730 765 unset( $actions['view'] ); 766 } 731 767 732 768 // Only show the actions if the user is capable of viewing them … … 773 809 public function filter_dropdown() { 774 810 775 if ( $this->bail() ) return; 811 if ( $this->bail() ) { 812 return; 813 } 776 814 777 815 // Add Empty Spam button … … 805 843 public function filter_post_rows( $query_vars ) { 806 844 807 if ( $this->bail() ) return $query_vars; 845 if ( $this->bail() ) { 846 return $query_vars; 847 } 808 848 809 849 // Add post_parent query_var if one is present … … 836 876 global $post_ID; 837 877 838 if ( $this->bail() ) return $messages; 878 if ( $this->bail() ) { 879 return $messages; 880 } 839 881 840 882 // URL for the current topic -
trunk/src/includes/admin/settings.php
r5365 r5440 429 429 430 430 // Bail if section is empty 431 if ( empty( $section_id ) ) 431 if ( empty( $section_id ) ) { 432 432 return false; 433 } 433 434 434 435 $fields = bbp_admin_get_settings_fields(); … … 855 856 856 857 // Flush rewrite rules when this section is saved 857 if ( isset( $_GET['settings-updated'] ) && isset( $_GET['page'] ) ) 858 flush_rewrite_rules(); ?> 858 if ( isset( $_GET['settings-updated'] ) && isset( $_GET['page'] ) ) { 859 flush_rewrite_rules(); 860 } ?> 859 861 860 862 <p><?php esc_html_e( 'Customize your Forums root. Partner with a WordPress Page and use Shortcodes for more flexibility.', 'bbpress' ); ?></p> … … 873 875 ?> 874 876 875 877 <input name="_bbp_root_slug" id="_bbp_root_slug" type="text" class="regular-text code" value="<?php bbp_form_option( '_bbp_root_slug', 'forums', true ); ?>"<?php bbp_maybe_admin_setting_disabled( '_bbp_root_slug' ); ?> /> 876 878 877 879 <?php … … 1297 1299 1298 1300 // Bail if no directory was found (how did this happen?) 1299 if ( empty( $curdir ) ) 1301 if ( empty( $curdir ) ) { 1300 1302 return; 1303 } 1301 1304 1302 1305 // Loop through files in the converters folder and assemble some options … … 1535 1538 1536 1539 // Bail if current screen could not be found 1537 if ( empty( $current_screen ) ) 1540 if ( empty( $current_screen ) ) { 1538 1541 return; 1542 } 1539 1543 1540 1544 // Overview … … 1647 1651 1648 1652 // Fallback to default 1649 if ( empty( $value ) ) 1653 if ( empty( $value ) ) { 1650 1654 $value = $default; 1655 } 1651 1656 1652 1657 // Allow plugins to further filter the output -
trunk/src/includes/admin/tools.php
r5429 r5440 77 77 function bbp_admin_repair_handler() { 78 78 79 if ( ! bbp_is_post_request() ) 79 if ( ! bbp_is_post_request() ) { 80 80 return; 81 } 81 82 82 83 check_admin_referer( 'bbpress-do-counts' ); … … 249 250 case 0: 250 251 return false; 251 break;252 252 253 253 case 1: … … 382 382 383 383 $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` = '_bbp_voice_count';"; 384 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) 384 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) { 385 385 return array( 1, sprintf( $statement, $result ) ); 386 } 386 387 387 388 // Post types and status … … 402 403 GROUP BY `postmeta`.`meta_value`);"; 403 404 404 if ( is_wp_error( $wpdb->query( $sql ) ) ) 405 if ( is_wp_error( $wpdb->query( $sql ) ) ) { 405 406 return array( 2, sprintf( $statement, $result ) ); 407 } 406 408 407 409 return array( 0, sprintf( $statement, __( 'Complete!', 'bbpress' ) ) ); … … 427 429 428 430 $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` = '_bbp_reply_count_hidden';"; 429 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) 431 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) { 430 432 return array( 1, sprintf( $statement, $result ) ); 433 } 431 434 432 435 // Post types and status … … 436 439 437 440 $sql = "INSERT INTO `{$wpdb->postmeta}` (`post_id`, `meta_key`, `meta_value`) (SELECT `post_parent`, '_bbp_reply_count_hidden', COUNT(`post_status`) as `meta_value` FROM `{$wpdb->posts}` WHERE `post_type` = '{$rpt}' AND `post_status` IN ( '{$tps}', '{$sps}' ) GROUP BY `post_parent`);"; 438 if ( is_wp_error( $wpdb->query( $sql ) ) ) 441 if ( is_wp_error( $wpdb->query( $sql ) ) ) { 439 442 return array( 2, sprintf( $statement, $result ) ); 443 } 440 444 441 445 return array( 0, sprintf( $statement, __( 'Complete!', 'bbpress' ) ) ); … … 474 478 475 479 // Bail if forum IDs returned an error 476 if ( is_wp_error( $forum_ids ) || empty( $wpdb->last_result ) ) 480 if ( is_wp_error( $forum_ids ) || empty( $wpdb->last_result ) ) { 477 481 return array( 2, sprintf( $statement, __( 'Failed!', 'bbpress' ) ) ); 482 } 478 483 479 484 // Stash the last results … … 484 489 485 490 // Only update if is a converted forum 486 if ( ! isset( $group_forums->meta_value ) ) 491 if ( ! isset( $group_forums->meta_value ) ) { 487 492 continue; 493 } 488 494 489 495 // Attempt to update group meta … … 596 602 597 603 $sql_delete = "DELETE FROM {$wpdb->postmeta} WHERE meta_key IN ( '_bbp_topic_count', '_bbp_total_topic_count' );"; 598 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) 604 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) { 599 605 return array( 1, sprintf( $statement, $result ) ); 606 } 600 607 601 608 $forums = get_posts( array( 'post_type' => bbp_get_forum_post_type(), 'numberposts' => -1 ) ); … … 675 682 $insert_rows = $wpdb->get_results( $sql_select ); 676 683 677 if ( is_wp_error( $insert_rows ) ) 684 if ( is_wp_error( $insert_rows ) ) { 678 685 return array( 1, sprintf( $statement, $result ) ); 686 } 679 687 680 688 $key = $wpdb->prefix . '_bbp_topic_count'; 681 689 $insert_values = array(); 682 foreach ( $insert_rows as $insert_row ) 690 foreach ( $insert_rows as $insert_row ) { 683 691 $insert_values[] = "('{$insert_row->post_author}', '{$key}', '{$insert_row->_count}')"; 684 685 if ( !count( $insert_values ) ) 692 } 693 694 if ( !count( $insert_values ) ) { 686 695 return array( 2, sprintf( $statement, $result ) ); 696 } 687 697 688 698 $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';"; 689 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) 699 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) { 690 700 return array( 3, sprintf( $statement, $result ) ); 701 } 691 702 692 703 foreach ( array_chunk( $insert_values, 10000 ) as $chunk ) { … … 721 732 $insert_rows = $wpdb->get_results( $sql_select ); 722 733 723 if ( is_wp_error( $insert_rows ) ) 734 if ( is_wp_error( $insert_rows ) ) { 724 735 return array( 1, sprintf( $statement, $result ) ); 736 } 725 737 726 738 $key = $wpdb->prefix . '_bbp_reply_count'; 727 739 $insert_values = array(); 728 foreach ( $insert_rows as $insert_row ) 740 foreach ( $insert_rows as $insert_row ) { 729 741 $insert_values[] = "('{$insert_row->post_author}', '{$key}', '{$insert_row->_count}')"; 730 731 if ( !count( $insert_values ) ) 742 } 743 744 if ( !count( $insert_values ) ) { 732 745 return array( 2, sprintf( $statement, $result ) ); 746 } 733 747 734 748 $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';"; 735 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) 749 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) { 736 750 return array( 3, sprintf( $statement, $result ) ); 751 } 737 752 738 753 foreach ( array_chunk( $insert_values, 10000 ) as $chunk ) { … … 767 782 $users = $wpdb->get_results( "SELECT `user_id`, `meta_value` AS `favorites` FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';" ); 768 783 769 if ( is_wp_error( $users ) ) 784 if ( is_wp_error( $users ) ) { 770 785 return array( 1, sprintf( $statement, $result ) ); 786 } 771 787 772 788 $topics = $wpdb->get_col( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "';" ); 773 789 774 if ( is_wp_error( $topics ) ) 790 if ( is_wp_error( $topics ) ) { 775 791 return array( 2, sprintf( $statement, $result ) ); 792 } 776 793 777 794 $values = array(); 778 795 foreach ( $users as $user ) { 779 if ( empty( $user->favorites ) || !is_string( $user->favorites ) ) 796 if ( empty( $user->favorites ) || !is_string( $user->favorites ) ) { 780 797 continue; 798 } 781 799 782 800 $favorites = array_intersect( $topics, explode( ',', $user->favorites ) ); 783 if ( empty( $favorites ) || !is_array( $favorites ) ) 801 if ( empty( $favorites ) || !is_array( $favorites ) ) { 784 802 continue; 803 } 785 804 786 805 $favorites_joined = implode( ',', $favorites ); … … 797 816 798 817 $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';"; 799 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) 818 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) { 800 819 return array( 4, sprintf( $statement, $result ) ); 820 } 801 821 802 822 foreach ( array_chunk( $values, 10000 ) as $chunk ) { … … 830 850 $users = $wpdb->get_results( "SELECT `user_id`, `meta_value` AS `subscriptions` FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';" ); 831 851 832 if ( is_wp_error( $users ) ) 852 if ( is_wp_error( $users ) ) { 833 853 return array( 1, sprintf( $statement, $result ) ); 854 } 834 855 835 856 $topics = $wpdb->get_col( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "';" ); 836 if ( is_wp_error( $topics ) ) 857 if ( is_wp_error( $topics ) ) { 837 858 return array( 2, sprintf( $statement, $result ) ); 859 } 838 860 839 861 $values = array(); 840 862 foreach ( $users as $user ) { 841 if ( empty( $user->subscriptions ) || !is_string( $user->subscriptions ) ) 863 if ( empty( $user->subscriptions ) || !is_string( $user->subscriptions ) ) { 842 864 continue; 865 } 843 866 844 867 $subscriptions = array_intersect( $topics, explode( ',', $user->subscriptions ) ); 845 if ( empty( $subscriptions ) || !is_array( $subscriptions ) ) 868 if ( empty( $subscriptions ) || !is_array( $subscriptions ) ) { 846 869 continue; 870 } 847 871 848 872 $subscriptions_joined = implode( ',', $subscriptions ); … … 859 883 860 884 $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';"; 861 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) 885 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) { 862 886 return array( 4, sprintf( $statement, $result ) ); 887 } 863 888 864 889 foreach ( array_chunk( $values, 10000 ) as $chunk ) { … … 892 917 $users = $wpdb->get_results( "SELECT `user_id`, `meta_value` AS `subscriptions` FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';" ); 893 918 894 if ( is_wp_error( $users ) ) 919 if ( is_wp_error( $users ) ) { 895 920 return array( 1, sprintf( $statement, $result ) ); 921 } 896 922 897 923 $forums = $wpdb->get_col( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_forum_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "';" ); 898 if ( is_wp_error( $forums ) ) 924 if ( is_wp_error( $forums ) ) { 899 925 return array( 2, sprintf( $statement, $result ) ); 926 } 900 927 901 928 $values = array(); 902 929 foreach ( $users as $user ) { 903 if ( empty( $user->subscriptions ) || !is_string( $user->subscriptions ) ) 930 if ( empty( $user->subscriptions ) || !is_string( $user->subscriptions ) ) { 904 931 continue; 932 } 905 933 906 934 $subscriptions = array_intersect( $forums, explode( ',', $user->subscriptions ) ); 907 if ( empty( $subscriptions ) || !is_array( $subscriptions ) ) 935 if ( empty( $subscriptions ) || !is_array( $subscriptions ) ) { 908 936 continue; 937 } 909 938 910 939 $subscriptions_joined = implode( ',', $subscriptions ); … … 921 950 922 951 $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';"; 923 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) 952 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) { 924 953 return array( 4, sprintf( $statement, $result ) ); 954 } 925 955 926 956 foreach ( array_chunk( $values, 10000 ) as $chunk ) { … … 956 986 957 987 // Bail if no role map exists 958 if ( empty( $role_map ) ) 988 if ( empty( $role_map ) ) { 959 989 return array( 1, sprintf( $statement, __( 'Failed!', 'bbpress' ) ) ); 990 } 960 991 961 992 // Iterate through each role... … … 1014 1045 1015 1046 // First, delete everything. 1016 if ( is_wp_error( $wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` IN ( '_bbp_last_reply_id', '_bbp_last_topic_id', '_bbp_last_active_id', '_bbp_last_active_time' );" ) ) ) 1047 if ( is_wp_error( $wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` IN ( '_bbp_last_reply_id', '_bbp_last_topic_id', '_bbp_last_active_id', '_bbp_last_active_time' );" ) ) ) { 1017 1048 return array( 1, sprintf( $statement, $result ) ); 1049 } 1018 1050 1019 1051 // Post types and status … … 1028 1060 FROM `$wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` 1029 1061 WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}' 1030 GROUP BY `topic`.`ID` );" ) ) ) 1062 GROUP BY `topic`.`ID` );" ) ) ) { 1031 1063 return array( 2, sprintf( $statement, $result ) ); 1064 } 1032 1065 1033 1066 // For any remaining topics, give a reply ID of 0. … … 1036 1069 FROM `$wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply` 1037 1070 ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_reply_id' 1038 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) 1071 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) { 1039 1072 return array( 3, sprintf( $statement, $result ) ); 1073 } 1040 1074 1041 1075 // Now we give all the forums with topics the ID their last topic. … … 1044 1078 FROM `$wpdb->posts` AS `forum` INNER JOIN `$wpdb->posts` AS `topic` ON `forum`.`ID` = `topic`.`post_parent` 1045 1079 WHERE `topic`.`post_status` = '{$pps}' AND `forum`.`post_type` = '{$fpt}' AND `topic`.`post_type` = '{$tpt}' 1046 GROUP BY `forum`.`ID` );" ) ) ) 1080 GROUP BY `forum`.`ID` );" ) ) ) { 1047 1081 return array( 4, sprintf( $statement, $result ) ); 1082 } 1048 1083 1049 1084 // For any remaining forums, give a topic ID of 0. … … 1052 1087 FROM `$wpdb->posts` AS `forum` LEFT JOIN `$wpdb->postmeta` AS `topic` 1053 1088 ON `forum`.`ID` = `topic`.`post_id` AND `topic`.`meta_key` = '_bbp_last_topic_id' 1054 WHERE `topic`.`meta_id` IS NULL AND `forum`.`post_type` = '{$fpt}' );" ) ) ) 1089 WHERE `topic`.`meta_id` IS NULL AND `forum`.`post_type` = '{$fpt}' );" ) ) ) { 1055 1090 return array( 5, sprintf( $statement, $result ) ); 1091 } 1056 1092 1057 1093 // After that, we give all the topics with replies the ID their last reply (again, this time for a different reason). … … 1060 1096 FROM `$wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` 1061 1097 WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}' 1062 GROUP BY `topic`.`ID` );" ) ) ) 1098 GROUP BY `topic`.`ID` );" ) ) ) { 1063 1099 return array( 6, sprintf( $statement, $result ) ); 1100 } 1064 1101 1065 1102 // For any remaining topics, give a reply ID of themself. … … 1068 1105 FROM `$wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply` 1069 1106 ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_id' 1070 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) 1107 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) { 1071 1108 return array( 7, sprintf( $statement, $result ) ); 1109 } 1072 1110 1073 1111 // Give topics with replies their last update time. … … 1076 1114 FROM `$wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` 1077 1115 WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}' 1078 GROUP BY `topic`.`ID` );" ) ) ) 1116 GROUP BY `topic`.`ID` );" ) ) ) { 1079 1117 return array( 8, sprintf( $statement, $result ) ); 1118 } 1080 1119 1081 1120 // Give topics without replies their last update time. … … 1084 1123 FROM `$wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply` 1085 1124 ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_time' 1086 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) 1125 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) { 1087 1126 return array( 9, sprintf( $statement, $result ) ); 1127 } 1088 1128 1089 1129 // Forums need to know what their last active item is as well. Now it gets a bit more complex to do in the database. 1090 1130 $forums = $wpdb->get_col( "SELECT `ID` FROM `$wpdb->posts` WHERE `post_type` = '{$fpt}' and `post_status` != 'auto-draft';" ); 1091 if ( is_wp_error( $forums ) ) 1131 if ( is_wp_error( $forums ) ) { 1092 1132 return array( 10, sprintf( $statement, $result ) ); 1133 } 1093 1134 1094 1135 // Loop through forums … … 1132 1173 1133 1174 // Bail if no forums found 1134 if ( empty( $forums ) || is_wp_error( $forums ) ) 1175 if ( empty( $forums ) || is_wp_error( $forums ) ) { 1135 1176 return array( 1, sprintf( $statement, $result ) ); 1177 } 1136 1178 1137 1179 // Loop through forums and get their sticky topics … … 1212 1254 1213 1255 // First, delete everything. 1214 if ( is_wp_error( $wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` = '_bbp_forum_id';" ) ) ) 1256 if ( is_wp_error( $wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` = '_bbp_forum_id';" ) ) ) { 1215 1257 return array( 1, sprintf( $statement, $result ) ); 1258 } 1216 1259 1217 1260 // Post types and status … … 1226 1269 AS `forum` 1227 1270 WHERE `forum`.`post_type` = '{$fpt}' 1228 GROUP BY `forum`.`ID` );" ) ) ) 1271 GROUP BY `forum`.`ID` );" ) ) ) { 1229 1272 return array( 2, sprintf( $statement, $result ) ); 1273 } 1230 1274 1231 1275 // Next, give all the topics with replies the ID their last reply. … … 1235 1279 AS `topic` 1236 1280 WHERE `topic`.`post_type` = '{$tpt}' 1237 GROUP BY `topic`.`ID` );" ) ) ) 1281 GROUP BY `topic`.`ID` );" ) ) ) { 1238 1282 return array( 3, sprintf( $statement, $result ) ); 1283 } 1239 1284 1240 1285 // Next, give all the topics with replies the ID their last reply. … … 1248 1293 WHERE `topic`.`post_type` = '{$tpt}' 1249 1294 AND `reply`.`post_type` = '{$rpt}' 1250 GROUP BY `reply`.`ID` );" ) ) ) 1295 GROUP BY `reply`.`ID` );" ) ) ) { 1251 1296 return array( 4, sprintf( $statement, $result ) ); 1297 } 1252 1298 1253 1299 // Complete results … … 1273 1319 1274 1320 // First, delete everything. 1275 if ( is_wp_error( $wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` = '_bbp_topic_id';" ) ) ) 1321 if ( is_wp_error( $wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` = '_bbp_topic_id';" ) ) ) { 1276 1322 return array( 1, sprintf( $statement, $result ) ); 1323 } 1277 1324 1278 1325 // Post types and status … … 1286 1333 AS `topic` 1287 1334 WHERE `topic`.`post_type` = '{$tpt}' 1288 GROUP BY `topic`.`ID` );" ) ) ) 1335 GROUP BY `topic`.`ID` );" ) ) ) { 1289 1336 return array( 3, sprintf( $statement, $result ) ); 1337 } 1290 1338 1291 1339 // Next, give all the topics with replies the ID their last reply. … … 1299 1347 WHERE `topic`.`post_type` = '{$tpt}' 1300 1348 AND `reply`.`post_type` = '{$rpt}' 1301 GROUP BY `reply`.`ID` );" ) ) ) 1349 GROUP BY `reply`.`ID` );" ) ) ) { 1302 1350 return array( 4, sprintf( $statement, $result ) ); 1351 } 1303 1352 1304 1353 // Complete results … … 1446 1495 1447 1496 // Bail if not resetting 1448 if ( ! bbp_is_post_request() || empty( $_POST['bbpress-are-you-sure'] ) ) 1497 if ( ! bbp_is_post_request() || empty( $_POST['bbpress-are-you-sure'] ) ) { 1449 1498 return; 1499 } 1450 1500 1451 1501 // Only keymasters can proceed 1452 if ( ! bbp_is_user_keymaster() ) 1502 if ( ! bbp_is_user_keymaster() ) { 1453 1503 return; 1504 } 1454 1505 1455 1506 check_admin_referer( 'bbpress-reset' ); -
trunk/src/includes/admin/topics.php
r5300 r5440 99 99 */ 100 100 private function bail() { 101 if ( !isset( get_current_screen()->post_type ) || ( $this->post_type !== get_current_screen()->post_type ) ) 101 if ( !isset( get_current_screen()->post_type ) || ( $this->post_type !== get_current_screen()->post_type ) ) { 102 102 return true; 103 } 103 104 104 105 return false; … … 125 126 public function edit_help() { 126 127 127 if ( $this->bail() ) return; 128 if ( $this->bail() ) { 129 return; 130 } 128 131 129 132 // Overview … … 190 193 public function new_help() { 191 194 192 if ( $this->bail() ) return; 195 if ( $this->bail() ) { 196 return; 197 } 193 198 194 199 $customize_display = '<p>' . __( 'The title field and the big topic editing Area are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Excerpt, Send Trackbacks, Custom Fields, Discussion, Slug, Author) or to choose a 1- or 2-column layout for this screen.', 'bbpress' ) . '</p>'; … … 249 254 public function attributes_metabox() { 250 255 251 if ( $this->bail() ) return; 256 if ( $this->bail() ) { 257 return; 258 } 252 259 253 260 add_meta_box ( … … 277 284 public function attributes_metabox_save( $topic_id ) { 278 285 279 if ( $this->bail() ) return $topic_id; 286 if ( $this->bail() ) { 287 return $topic_id; 288 } 280 289 281 290 // Bail if doing an autosave 282 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 291 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 283 292 return $topic_id; 293 } 284 294 285 295 // Bail if not a post request 286 if ( ! bbp_is_post_request() ) 296 if ( ! bbp_is_post_request() ) { 287 297 return $topic_id; 298 } 288 299 289 300 // Nonce check 290 if ( empty( $_POST['bbp_topic_metabox'] ) || !wp_verify_nonce( $_POST['bbp_topic_metabox'], 'bbp_topic_metabox_save' ) ) 301 if ( empty( $_POST['bbp_topic_metabox'] ) || !wp_verify_nonce( $_POST['bbp_topic_metabox'], 'bbp_topic_metabox_save' ) ) { 291 302 return $topic_id; 303 } 292 304 293 305 // Bail if current user cannot edit this topic 294 if ( !current_user_can( 'edit_topic', $topic_id ) ) 306 if ( !current_user_can( 'edit_topic', $topic_id ) ) { 295 307 return $topic_id; 308 } 296 309 297 310 // Get the forum ID … … 352 365 public function author_metabox() { 353 366 354 if ( $this->bail() ) return; 367 if ( $this->bail() ) { 368 return; 369 } 355 370 356 371 // Bail if post_type is not a topic 357 if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) 372 if ( empty( $_GET['action'] ) || ( 'edit' !== $_GET['action'] ) ) { 358 373 return; 374 } 359 375 360 376 // Add the metabox … … 384 400 public function admin_head() { 385 401 386 if ( $this->bail() ) return;387 388 ?>402 if ( $this->bail() ) { 403 return; 404 } ?> 389 405 390 406 <style type="text/css" media="screen"> … … 471 487 public function toggle_topic() { 472 488 473 if ( $this->bail() ) return; 489 if ( $this->bail() ) { 490 return; 491 } 474 492 475 493 // Only proceed if GET is a topic toggle action … … 482 500 483 501 // Bail if topic is missing 484 if ( empty( $topic ) ) 502 if ( empty( $topic ) ) { 485 503 wp_die( __( 'The topic was not found!', 'bbpress' ) ); 486 487 if ( !current_user_can( 'moderate', $topic->ID ) ) // What is the user doing here? 504 } 505 506 // What is the user doing here? 507 if ( !current_user_can( 'moderate', $topic->ID ) ) { 488 508 wp_die( __( 'You do not have the permission to do that!', 'bbpress' ) ); 509 } 489 510 490 511 switch ( $action ) { … … 493 514 494 515 $is_open = bbp_is_topic_open( $topic_id ); 495 $message = true === $is_open ? 'closed' : 'opened'; 496 $success = true === $is_open ? bbp_close_topic( $topic_id ) : bbp_open_topic( $topic_id ); 516 $message = ( true === $is_open ) 517 ? 'closed' 518 : 'opened'; 519 $success = ( true === $is_open ) 520 ? bbp_close_topic( $topic_id ) 521 : bbp_open_topic( $topic_id ); 497 522 498 523 break; … … 502 527 503 528 $is_sticky = bbp_is_topic_sticky( $topic_id ); 504 $is_super = false === $is_sticky && !empty( $_GET['super'] ) && ( "1" === $_GET['super'] ) ? true : false; 505 $message = true === $is_sticky ? 'unsticked' : 'sticked'; 506 $message = true === $is_super ? 'super_sticked' : $message; 507 $success = true === $is_sticky ? bbp_unstick_topic( $topic_id ) : bbp_stick_topic( $topic_id, $is_super ); 529 $is_super = ( false === $is_sticky ) && !empty( $_GET['super'] ) && ( "1" === $_GET['super'] ) 530 ? true 531 : false; 532 $message = ( true === $is_sticky ) 533 ? 'unsticked' 534 : 'sticked'; 535 $message = ( true === $is_super ) 536 ? 'super_sticked' 537 : $message; 538 $success = ( true === $is_sticky ) 539 ? bbp_unstick_topic( $topic_id ) 540 : bbp_stick_topic( $topic_id, $is_super ); 508 541 509 542 break; … … 513 546 514 547 $is_spam = bbp_is_topic_spam( $topic_id ); 515 $message = true === $is_spam ? 'unspammed' : 'spammed'; 516 $success = true === $is_spam ? bbp_unspam_topic( $topic_id ) : bbp_spam_topic( $topic_id ); 548 $message = ( true === $is_spam ) 549 ? 'unspammed' 550 : 'spammed'; 551 $success = ( true === $is_spam ) 552 ? bbp_unspam_topic( $topic_id ) 553 : bbp_spam_topic( $topic_id ); 517 554 518 555 break; … … 521 558 $message = array( 'bbp_topic_toggle_notice' => $message, 'topic_id' => $topic->ID ); 522 559 523 if ( false === $success || is_wp_error( $success ) ) 560 if ( false === $success || is_wp_error( $success ) ) { 524 561 $message['failed'] = '1'; 562 } 525 563 526 564 // Do additional topic toggle actions (admin side) … … 552 590 public function toggle_topic_notice() { 553 591 554 if ( $this->bail() ) return; 592 if ( $this->bail() ) { 593 return; 594 } 555 595 556 596 // Only proceed if GET is a topic toggle action … … 561 601 562 602 // Bais if no topic_id or notice 563 if ( empty( $notice ) || empty( $topic_id ) ) 603 if ( empty( $notice ) || empty( $topic_id ) ) { 564 604 return; 605 } 565 606 566 607 // Bail if topic is missing 567 608 $topic = bbp_get_topic( $topic_id ); 568 if ( empty( $topic ) ) 609 if ( empty( $topic ) ) { 569 610 return; 611 } 570 612 571 613 $topic_title = bbp_get_topic_title( $topic->ID ); … … 573 615 switch ( $notice ) { 574 616 case 'opened' : 575 $message = $is_failure === true ? sprintf( __( 'There was a problem opening the topic "%1$s".', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully opened.', 'bbpress' ), $topic_title ); 617 $message = ( $is_failure === true ) 618 ? sprintf( __( 'There was a problem opening the topic "%1$s".', 'bbpress' ), $topic_title ) 619 : sprintf( __( 'Topic "%1$s" successfully opened.', 'bbpress' ), $topic_title ); 576 620 break; 577 621 578 622 case 'closed' : 579 $message = $is_failure === true ? sprintf( __( 'There was a problem closing the topic "%1$s".', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully closed.', 'bbpress' ), $topic_title ); 623 $message = ( $is_failure === true ) 624 ? sprintf( __( 'There was a problem closing the topic "%1$s".', 'bbpress' ), $topic_title ) 625 : sprintf( __( 'Topic "%1$s" successfully closed.', 'bbpress' ), $topic_title ); 580 626 break; 581 627 582 628 case 'super_sticked' : 583 $message = $is_failure === true ? sprintf( __( 'There was a problem sticking the topic "%1$s" to front.', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully sticked to front.', 'bbpress' ), $topic_title ); 629 $message = ( $is_failure === true ) 630 ? sprintf( __( 'There was a problem sticking the topic "%1$s" to front.', 'bbpress' ), $topic_title ) 631 : sprintf( __( 'Topic "%1$s" successfully sticked to front.', 'bbpress' ), $topic_title ); 584 632 break; 585 633 586 634 case 'sticked' : 587 $message = $is_failure === true ? sprintf( __( 'There was a problem sticking the topic "%1$s".', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully sticked.', 'bbpress' ), $topic_title ); 635 $message = ( $is_failure === true ) 636 ? sprintf( __( 'There was a problem sticking the topic "%1$s".', 'bbpress' ), $topic_title ) 637 : sprintf( __( 'Topic "%1$s" successfully sticked.', 'bbpress' ), $topic_title ); 588 638 break; 589 639 590 640 case 'unsticked' : 591 $message = $is_failure === true ? sprintf( __( 'There was a problem unsticking the topic "%1$s".', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully unsticked.', 'bbpress' ), $topic_title ); 641 $message = ( $is_failure === true ) 642 ? sprintf( __( 'There was a problem unsticking the topic "%1$s".', 'bbpress' ), $topic_title ) 643 : sprintf( __( 'Topic "%1$s" successfully unsticked.', 'bbpress' ), $topic_title ); 592 644 break; 593 645 594 646 case 'spammed' : 595 $message = $is_failure === true ? sprintf( __( 'There was a problem marking the topic "%1$s" as spam.', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully marked as spam.', 'bbpress' ), $topic_title ); 647 $message = ( $is_failure === true ) 648 ? sprintf( __( 'There was a problem marking the topic "%1$s" as spam.', 'bbpress' ), $topic_title ) 649 : sprintf( __( 'Topic "%1$s" successfully marked as spam.', 'bbpress' ), $topic_title ); 596 650 break; 597 651 598 652 case 'unspammed' : 599 $message = $is_failure === true ? sprintf( __( 'There was a problem unmarking the topic "%1$s" as spam.', 'bbpress' ), $topic_title ) : sprintf( __( 'Topic "%1$s" successfully unmarked as spam.', 'bbpress' ), $topic_title ); 653 $message = ( $is_failure === true ) 654 ? sprintf( __( 'There was a problem unmarking the topic "%1$s" as spam.', 'bbpress' ), $topic_title ) 655 : sprintf( __( 'Topic "%1$s" successfully unmarked as spam.', 'bbpress' ), $topic_title ); 600 656 break; 601 657 } … … 606 662 ?> 607 663 608 <div id="message" class="<?php echo $is_failure === true? 'error' : 'updated'; ?> fade">664 <div id="message" class="<?php echo ( $is_failure === true ) ? 'error' : 'updated'; ?> fade"> 609 665 <p style="line-height: 150%"><?php echo esc_html( $message ); ?></p> 610 666 </div> … … 626 682 public function column_headers( $columns ) { 627 683 628 if ( $this->bail() ) return $columns; 684 if ( $this->bail() ) { 685 return $columns; 686 } 629 687 630 688 $columns = array( … … 669 727 public function column_data( $column, $topic_id ) { 670 728 671 if ( $this->bail() ) return; 729 if ( $this->bail() ) { 730 return; 731 } 672 732 673 733 // Get topic forum ID … … 769 829 public function row_actions( $actions, $topic ) { 770 830 771 if ( $this->bail() ) return $actions; 831 if ( $this->bail() ) { 832 return $actions; 833 } 772 834 773 835 unset( $actions['inline hide-if-no-js'] ); 774 836 775 837 // Show view link if it's not set, the topic is trashed and the user can view trashed topics 776 if ( empty( $actions['view'] ) && ( bbp_get_trash_status_id() === $topic->post_status ) && current_user_can( 'view_trash' ) ) 838 if ( empty( $actions['view'] ) && ( bbp_get_trash_status_id() === $topic->post_status ) && current_user_can( 'view_trash' ) ) { 777 839 $actions['view'] = '<a href="' . esc_url( bbp_get_topic_permalink( $topic->ID ) ) . '" title="' . esc_attr( sprintf( __( 'View “%s”', 'bbpress' ), bbp_get_topic_title( $topic->ID ) ) ) . '" rel="permalink">' . esc_html__( 'View', 'bbpress' ) . '</a>'; 840 } 778 841 779 842 // Only show the actions if the user is capable of viewing them :) … … 784 847 if ( in_array( $topic->post_status, array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ) ) { 785 848 $close_uri = wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_close' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'close-topic_' . $topic->ID ); 786 if ( bbp_is_topic_open( $topic->ID ) ) 849 if ( bbp_is_topic_open( $topic->ID ) ) { 787 850 $actions['closed'] = '<a href="' . esc_url( $close_uri ) . '" title="' . esc_attr__( 'Close this topic', 'bbpress' ) . '">' . _x( 'Close', 'Close a Topic', 'bbpress' ) . '</a>'; 788 else851 } else { 789 852 $actions['closed'] = '<a href="' . esc_url( $close_uri ) . '" title="' . esc_attr__( 'Open this topic', 'bbpress' ) . '">' . _x( 'Open', 'Open a Topic', 'bbpress' ) . '</a>'; 853 } 790 854 } 791 855 … … 805 869 // Spam 806 870 $spam_uri = wp_nonce_url( add_query_arg( array( 'topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_spam' ), remove_query_arg( array( 'bbp_topic_toggle_notice', 'topic_id', 'failed', 'super' ) ) ), 'spam-topic_' . $topic->ID ); 807 if ( bbp_is_topic_spam( $topic->ID ) ) 871 if ( bbp_is_topic_spam( $topic->ID ) ) { 808 872 $actions['spam'] = '<a href="' . esc_url( $spam_uri ) . '" title="' . esc_attr__( 'Mark the topic as not spam', 'bbpress' ) . '">' . esc_html__( 'Not spam', 'bbpress' ) . '</a>'; 809 else873 } else { 810 874 $actions['spam'] = '<a href="' . esc_url( $spam_uri ) . '" title="' . esc_attr__( 'Mark this topic as spam', 'bbpress' ) . '">' . esc_html__( 'Spam', 'bbpress' ) . '</a>'; 811 875 } 812 876 } 813 877 … … 843 907 public function filter_dropdown() { 844 908 845 if ( $this->bail() ) return; 909 if ( $this->bail() ) { 910 return; 911 } 846 912 847 913 // Add Empty Spam button … … 875 941 function filter_post_rows( $query_vars ) { 876 942 877 if ( $this->bail() ) return $query_vars; 943 if ( $this->bail() ) { 944 return $query_vars; 945 } 878 946 879 947 // Add post_parent query_var if one is present … … 906 974 global $post_ID; 907 975 908 if ( $this->bail() ) return $messages; 976 if ( $this->bail() ) { 977 return $messages; 978 } 909 979 910 980 // URL for the current topic -
trunk/src/includes/admin/users.php
r4995 r5440 44 44 45 45 // Bail if in network admin 46 if ( is_network_admin() ) 47 return; 46 if ( is_network_admin() ) { 47 return; 48 } 48 49 49 50 // User profile edit/display actions … … 70 71 71 72 // Bail if current user cannot edit users 72 if ( ! current_user_can( 'edit_user', $profileuser->ID ) ) 73 return; 73 if ( ! current_user_can( 'edit_user', $profileuser->ID ) ) { 74 return; 75 } 74 76 75 77 // Get the roles … … 77 79 78 80 // Only keymasters can set other keymasters 79 if ( ! bbp_is_user_keymaster() ) 80 unset( $dynamic_roles[ bbp_get_keymaster_role() ] ); ?> 81 if ( ! bbp_is_user_keymaster() ) { 82 unset( $dynamic_roles[ bbp_get_keymaster_role() ] ); 83 } ?> 81 84 82 85 <h3><?php esc_html_e( 'Forums', 'bbpress' ); ?></h3> … … 126 129 127 130 // Bail if current user cannot promote users 128 if ( !current_user_can( 'promote_users' ) ) 129 return; 131 if ( !current_user_can( 'promote_users' ) ) { 132 return; 133 } 130 134 131 135 // Get the roles … … 133 137 134 138 // Only keymasters can set other keymasters 135 if ( ! bbp_is_user_keymaster() ) 136 unset( $dynamic_roles[ bbp_get_keymaster_role() ] ); ?> 139 if ( ! bbp_is_user_keymaster() ) { 140 unset( $dynamic_roles[ bbp_get_keymaster_role() ] ); 141 } ?> 137 142 138 143 <label class="screen-reader-text" for="bbp-new-role"><?php esc_html_e( 'Change forum role to…', 'bbpress' ) ?></label> … … 158 163 159 164 // Bail if current user cannot promote users 160 if ( !current_user_can( 'promote_users' ) ) 161 return; 165 if ( !current_user_can( 'promote_users' ) ) { 166 return; 167 } 162 168 163 169 // Bail if no users specified 164 if ( empty( $_REQUEST['users'] ) ) 165 return; 170 if ( empty( $_REQUEST['users'] ) ) { 171 return; 172 } 166 173 167 174 // Bail if this isn't a bbPress action 168 if ( empty( $_REQUEST['bbp-new-role'] ) || empty( $_REQUEST['bbp-change-role'] ) ) 169 return; 175 if ( empty( $_REQUEST['bbp-new-role'] ) || empty( $_REQUEST['bbp-change-role'] ) ) { 176 return; 177 } 170 178 171 179 // Check that the new role exists 172 180 $dynamic_roles = bbp_get_dynamic_roles(); 173 if ( empty( $dynamic_roles[ $_REQUEST['bbp-new-role'] ] ) ) 174 return; 181 if ( empty( $dynamic_roles[ $_REQUEST['bbp-new-role'] ] ) ) { 182 return; 183 } 175 184 176 185 // Get the current user ID … … 182 191 183 192 // Don't let a user change their own role 184 if ( $user_id === $current_user_id ) 193 if ( $user_id === $current_user_id ) { 185 194 continue; 195 } 186 196 187 197 // Set up user and role data … … 190 200 191 201 // Only keymasters can set other keymasters 192 if ( in_array( bbp_get_keymaster_role(), array( $user_role, $new_role ) ) && ! bbp_is_user_keymaster() ) 202 if ( in_array( bbp_get_keymaster_role(), array( $user_role, $new_role ) ) && ! bbp_is_user_keymaster() ) { 193 203 continue; 204 } 194 205 195 206 // Set the new forums role
Note: See TracChangeset
for help on using the changeset viewer.