| @@ -1,5 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * Centralized manager for WordPress backend functionality. | |
| 4 | + * | |
| 5 | + * @package WP_Stream | |
| 6 | + */ | |
| 2 | 7 | |
| 3 | 8 | namespace WP_Stream; |
| 4 | 9 | |
| 5 | 10 | use DateTime; |
| @@ -7,12 +12,15 @@ | ||
| 7 | 12 | use DateInterval; |
| 8 | 13 | use \WP_CLI; |
| 9 | 14 | use \WP_Roles; |
| 10 | 15 | |
| 16 | +/** | |
| 17 | + * Class - Admin | |
| 18 | + */ | |
| 11 | 19 | class Admin { |
| 12 | 20 | |
| 13 | 21 | /** |
| 14 | - * Hold Plugin class | |
| 22 | + * Holds Instance of plugin object | |
| 15 | 23 | * |
| 16 | 24 | * @var Plugin |
| 17 | 25 | */ |
| 18 | 26 | public $plugin; |
| @@ -117,9 +125,9 @@ | ||
| 117 | 125 | |
| 118 | 126 | /** |
| 119 | 127 | * Class constructor. |
| 120 | 128 | * |
| 121 | - * @param Plugin $plugin The main Plugin class. | |
| 129 | + * @param Plugin $plugin Instance of plugin object. | |
| 122 | 130 | */ |
| 123 | 131 | public function __construct( $plugin ) { |
| 124 | 132 | $this->plugin = $plugin; |
| 125 | 133 | |
| @@ -133,9 +141,9 @@ | ||
| 133 | 141 | // User and role caps. |
| 134 | 142 | add_filter( 'user_has_cap', array( $this, 'filter_user_caps' ), 10, 4 ); |
| 135 | 143 | add_filter( 'role_has_cap', array( $this, 'filter_role_caps' ), 10, 3 ); |
| 136 | 144 | |
| 137 | - if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) && ! is_network_admin() ) { | |
| 145 | + if ( is_multisite() && $plugin->is_network_activated() && ! is_network_admin() ) { | |
| 138 | 146 | $options = (array) get_site_option( 'wp_stream_network', array() ); |
| 139 | 147 | $option = isset( $options['general_site_access'] ) ? absint( $options['general_site_access'] ) : 1; |
| 140 | 148 | |
| 141 | 149 | $this->disable_access = ( $option ) ? false : true; |
| @@ -154,17 +162,21 @@ | ||
| 154 | 162 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
| 155 | 163 | |
| 156 | 164 | // Plugin action links. |
| 157 | 165 | add_filter( |
| 158 | - 'plugin_action_links', array( | |
| 166 | + 'plugin_action_links', | |
| 167 | + array( | |
| 159 | 168 | $this, |
| 160 | 169 | 'plugin_action_links', |
| 161 | - ), 10, 2 | |
| 170 | + ), | |
| 171 | + 10, | |
| 172 | + 2 | |
| 162 | 173 | ); |
| 163 | 174 | |
| 164 | 175 | // Load admin scripts and styles. |
| 165 | 176 | add_action( |
| 166 | - 'admin_enqueue_scripts', array( | |
| 177 | + 'admin_enqueue_scripts', | |
| 178 | + array( | |
| 167 | 179 | $this, |
| 168 | 180 | 'admin_enqueue_scripts', |
| 169 | 181 | ) |
| 170 | 182 | ); |
| @@ -171,21 +183,27 @@ | ||
| 171 | 183 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_menu_css' ) ); |
| 172 | 184 | |
| 173 | 185 | // Reset Streams database. |
| 174 | 186 | add_action( |
| 175 | - 'wp_ajax_wp_stream_reset', array( | |
| 187 | + 'wp_ajax_wp_stream_reset', | |
| 188 | + array( | |
| 176 | 189 | $this, |
| 177 | 190 | 'wp_ajax_reset', |
| 178 | 191 | ) |
| 179 | 192 | ); |
| 180 | 193 | |
| 181 | - // Uninstall Streams and Deactivate plugin. | |
| 194 | + /** | |
| 195 | + * Uninstall Streams and Deactivate plugin. | |
| 196 | + * | |
| 197 | + * @todo Confirm if variable assignment is necessary. | |
| 198 | + */ | |
| 182 | 199 | $uninstall = $this->plugin->db->driver->purge_storage( $this->plugin ); |
| 183 | 200 | |
| 184 | 201 | // Auto purge setup. |
| 185 | 202 | add_action( 'wp_loaded', array( $this, 'purge_schedule_setup' ) ); |
| 186 | 203 | add_action( |
| 187 | - 'wp_stream_auto_purge', array( | |
| 204 | + 'wp_stream_auto_purge', | |
| 205 | + array( | |
| 188 | 206 | $this, |
| 189 | 207 | 'purge_scheduled_action', |
| 190 | 208 | ) |
| 191 | 209 | ); |
| @@ -191,9 +209,10 @@ | ||
| 191 | 209 | ); |
| 192 | 210 | |
| 193 | 211 | // Ajax users list. |
| 194 | 212 | add_action( |
| 195 | - 'wp_ajax_wp_stream_filters', array( | |
| 213 | + 'wp_ajax_wp_stream_filters', | |
| 214 | + array( | |
| 196 | 215 | $this, |
| 197 | 216 | 'ajax_filters', |
| 198 | 217 | ) |
| 199 | 218 | ); |
| @@ -234,9 +253,9 @@ | ||
| 234 | 253 | * @param bool $is_error If the message is error_level (true) or warning (false). |
| 235 | 254 | */ |
| 236 | 255 | public function notice( $message, $is_error = true ) { |
| 237 | 256 | if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 238 | - $message = strip_tags( $message ); | |
| 257 | + $message = wp_strip_all_tags( $message ); | |
| 239 | 258 | |
| 240 | 259 | if ( $is_error ) { |
| 241 | 260 | WP_CLI::warning( $message ); |
| 242 | 261 | } else { |
| @@ -358,9 +377,10 @@ | ||
| 358 | 377 | do_action( 'wp_stream_admin_menu_screens' ); |
| 359 | 378 | |
| 360 | 379 | // Register the list table early, so it associates the column headers with 'Screen settings'. |
| 361 | 380 | add_action( |
| 362 | - 'load-' . $this->screen_id['main'], array( | |
| 381 | + 'load-' . $this->screen_id['main'], | |
| 382 | + array( | |
| 363 | 383 | $this, |
| 364 | 384 | 'register_list_table', |
| 365 | 385 | ) |
| 366 | 386 | ); |
| @@ -371,9 +391,9 @@ | ||
| 371 | 391 | * Enqueue scripts/styles for admin screen |
| 372 | 392 | * |
| 373 | 393 | * @action admin_enqueue_scripts |
| 374 | 394 | * |
| 375 | - * @param string $hook | |
| 395 | + * @param string $hook Current hook. | |
| 376 | 396 | * |
| 377 | 397 | * @return void |
| 378 | 398 | */ |
| 379 | 399 | public function admin_enqueue_scripts( $hook ) { |
| @@ -384,11 +404,23 @@ | ||
| 384 | 404 | $locale = strtolower( substr( get_locale(), 0, 2 ) ); |
| 385 | 405 | $file_tmpl = 'ui/lib/timeago/locales/jquery.timeago.%s.js'; |
| 386 | 406 | |
| 387 | 407 | if ( file_exists( $this->plugin->locations['dir'] . sprintf( $file_tmpl, $locale ) ) ) { |
| 388 | - wp_register_script( 'wp-stream-timeago-locale', $this->plugin->locations['url'] . sprintf( $file_tmpl, $locale ), array( 'wp-stream-timeago' ), '1' ); | |
| 408 | + wp_register_script( | |
| 409 | + 'wp-stream-timeago-locale', | |
| 410 | + $this->plugin->locations['url'] . sprintf( $file_tmpl, $locale ), | |
| 411 | + array( 'wp-stream-timeago' ), | |
| 412 | + '1', | |
| 413 | + false | |
| 414 | + ); | |
| 389 | 415 | } else { |
| 390 | - wp_register_script( 'wp-stream-timeago-locale', $this->plugin->locations['url'] . sprintf( $file_tmpl, 'en' ), array( 'wp-stream-timeago' ), '1' ); | |
| 416 | + wp_register_script( | |
| 417 | + 'wp-stream-timeago-locale', | |
| 418 | + $this->plugin->locations['url'] . sprintf( $file_tmpl, 'en' ), | |
| 419 | + array( 'wp-stream-timeago' ), | |
| 420 | + '1', | |
| 421 | + false | |
| 422 | + ); | |
| 391 | 423 | } |
| 392 | 424 | |
| 393 | 425 | $min = wp_stream_min_suffix(); |
| 394 | 426 | wp_enqueue_style( 'wp-stream-admin', $this->plugin->locations['url'] . 'ui/css/admin.' . $min . 'css', array(), $this->plugin->get_version() ); |
| @@ -402,24 +434,36 @@ | ||
| 402 | 434 | wp_enqueue_script( 'wp-stream-timeago' ); |
| 403 | 435 | wp_enqueue_script( 'wp-stream-timeago-locale' ); |
| 404 | 436 | |
| 405 | 437 | wp_enqueue_script( |
| 406 | - 'wp-stream-admin', $this->plugin->locations['url'] . 'ui/js/admin.' . $min . 'js', array( | |
| 438 | + 'wp-stream-admin', | |
| 439 | + $this->plugin->locations['url'] . 'ui/js/admin.' . $min . 'js', | |
| 440 | + array( | |
| 407 | 441 | 'jquery', |
| 408 | 442 | 'wp-stream-select2', |
| 409 | - ), $this->plugin->get_version() | |
| 443 | + ), | |
| 444 | + $this->plugin->get_version(), | |
| 445 | + false | |
| 410 | 446 | ); |
| 411 | 447 | wp_enqueue_script( |
| 412 | - 'wp-stream-admin-exclude', $this->plugin->locations['url'] . 'ui/js/exclude.' . $min . 'js', array( | |
| 448 | + 'wp-stream-admin-exclude', | |
| 449 | + $this->plugin->locations['url'] . 'ui/js/exclude.' . $min . 'js', | |
| 450 | + array( | |
| 413 | 451 | 'jquery', |
| 414 | 452 | 'wp-stream-select2', |
| 415 | - ), $this->plugin->get_version() | |
| 453 | + ), | |
| 454 | + $this->plugin->get_version(), | |
| 455 | + false | |
| 416 | 456 | ); |
| 417 | 457 | wp_enqueue_script( |
| 418 | - 'wp-stream-live-updates', $this->plugin->locations['url'] . 'ui/js/live-updates.' . $min . 'js', array( | |
| 458 | + 'wp-stream-live-updates', | |
| 459 | + $this->plugin->locations['url'] . 'ui/js/live-updates.' . $min . 'js', | |
| 460 | + array( | |
| 419 | 461 | 'jquery', |
| 420 | 462 | 'heartbeat', |
| 421 | - ), $this->plugin->get_version() | |
| 463 | + ), | |
| 464 | + $this->plugin->get_version(), | |
| 465 | + false | |
| 422 | 466 | ); |
| 423 | 467 | |
| 424 | 468 | wp_localize_script( |
| 425 | 469 | 'wp-stream-admin', |
| @@ -434,21 +478,21 @@ | ||
| 434 | 478 | 'gmt_offset' => get_option( 'gmt_offset' ), |
| 435 | 479 | ) |
| 436 | 480 | ); |
| 437 | 481 | |
| 482 | + $order_types = array( 'asc', 'desc' ); | |
| 483 | + | |
| 438 | 484 | wp_localize_script( |
| 439 | 485 | 'wp-stream-live-updates', |
| 440 | 486 | 'wp_stream_live_updates', |
| 441 | 487 | array( |
| 442 | 488 | 'current_screen' => $hook, |
| 443 | - 'current_page' => isset( $_GET['paged'] ) ? esc_js( $_GET['paged'] ) : '1', // WPCS: CSRF ok. | |
| 444 | - // input var okay, CSRF okay | |
| 445 | - 'current_order' => isset( $_GET['order'] ) ? esc_js( $_GET['order'] ) : 'desc', // WPCS: CSRF ok. | |
| 446 | - // input var okay, CSRF okay | |
| 447 | - 'current_query' => wp_stream_json_encode( $_GET ), // WPCS: CSRF ok. | |
| 448 | - // input var okay, CSRF okay | |
| 449 | - 'current_query_count' => count( $_GET ), // WPCS: CSRF ok. | |
| 450 | - // input var okay, CSRF okay | |
| 489 | + 'current_page' => isset( $_GET['paged'] ) ? absint( wp_unslash( $_GET['paged'] ) ) : '1', // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 490 | + 'current_order' => isset( $_GET['order'] ) && in_array( strtolower( $_GET['order'] ), $order_types, true ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 491 | + ? esc_js( $_GET['order'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 492 | + : 'desc', | |
| 493 | + 'current_query' => wp_stream_json_encode( $_GET ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 494 | + 'current_query_count' => count( $_GET ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 451 | 495 | ) |
| 452 | 496 | ); |
| 453 | 497 | } |
| 454 | 498 | |
| @@ -465,9 +509,16 @@ | ||
| 465 | 509 | * @return int |
| 466 | 510 | */ |
| 467 | 511 | $bulk_actions_threshold = apply_filters( 'wp_stream_bulk_actions_threshold', 100 ); |
| 468 | 512 | |
| 469 | - wp_enqueue_script( 'wp-stream-global', $this->plugin->locations['url'] . 'ui/js/global.' . $min . 'js', array( 'jquery' ), $this->plugin->get_version() ); | |
| 513 | + wp_enqueue_script( | |
| 514 | + 'wp-stream-global', | |
| 515 | + $this->plugin->locations['url'] . 'ui/js/global.' . $min . 'js', | |
| 516 | + array( 'jquery' ), | |
| 517 | + $this->plugin->get_version(), | |
| 518 | + false | |
| 519 | + ); | |
| 520 | + | |
| 470 | 521 | wp_localize_script( |
| 471 | 522 | 'wp-stream-global', |
| 472 | 523 | 'wp_stream_global', |
| 473 | 524 | array( |
| @@ -472,9 +523,9 @@ | ||
| 472 | 523 | 'wp_stream_global', |
| 473 | 524 | array( |
| 474 | 525 | 'bulk_actions' => array( |
| 475 | 526 | 'i18n' => array( |
| 476 | - // translators: Placeholder refers to a number of items (e.g. "1,742") | |
| 527 | + /* translators: %s: a number of items (e.g. "1,742") */ | |
| 477 | 528 | 'confirm_action' => sprintf( esc_html__( 'Are you sure you want to perform bulk actions on over %s items? This process could take a while to complete.', 'stream' ), number_format( absint( $bulk_actions_threshold ) ) ), |
| 478 | 529 | ), |
| 479 | 530 | 'threshold' => absint( $bulk_actions_threshold ), |
| 480 | 531 | ), |
| @@ -503,9 +554,9 @@ | ||
| 503 | 554 | |
| 504 | 555 | /** |
| 505 | 556 | * Add a specific body class to all Stream admin screens |
| 506 | 557 | * |
| 507 | - * @param string $classes CSS classes to output to body | |
| 558 | + * @param string $classes CSS classes to output to body. | |
| 508 | 559 | * |
| 509 | 560 | * @filter admin_body_class |
| 510 | 561 | * |
| 511 | 562 | * @return string |
| @@ -515,10 +566,10 @@ | ||
| 515 | 566 | |
| 516 | 567 | if ( $this->is_stream_screen() ) { |
| 517 | 568 | $stream_classes[] = $this->admin_body_class; |
| 518 | 569 | |
| 519 | - if ( isset( $_GET['page'] ) ) { // CSRF okay | |
| 520 | - $stream_classes[] = sanitize_key( $_GET['page'] ); // input var okay, CSRF okay | |
| 570 | + if ( isset( $_GET['page'] ) ) { // // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 571 | + $stream_classes[] = sanitize_key( $_GET['page'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 521 | 572 | } |
| 522 | 573 | } |
| 523 | 574 | |
| 524 | 575 | /** |
| @@ -543,9 +594,9 @@ | ||
| 543 | 594 | $min = wp_stream_min_suffix(); |
| 544 | 595 | wp_register_style( 'wp-stream-datepicker', $this->plugin->locations['url'] . 'ui/css/datepicker.' . $min . 'css', array(), $this->plugin->get_version() ); |
| 545 | 596 | wp_register_style( 'wp-stream-icons', $this->plugin->locations['url'] . 'ui/stream-icons/style.css', array(), $this->plugin->get_version() ); |
| 546 | 597 | |
| 547 | - // Make sure we're working off a clean version | |
| 598 | + // Make sure we're working off a clean version. | |
| 548 | 599 | if ( ! file_exists( ABSPATH . WPINC . '/version.php' ) ) { |
| 549 | 600 | return; |
| 550 | 601 | } |
| 551 | 602 | include ABSPATH . WPINC . '/version.php'; |
| @@ -628,9 +679,9 @@ | ||
| 628 | 679 | if ( defined( 'WP_STREAM_TESTS' ) && WP_STREAM_TESTS ) { |
| 629 | 680 | return true; |
| 630 | 681 | } |
| 631 | 682 | |
| 632 | - wp_redirect( | |
| 683 | + wp_safe_redirect( | |
| 633 | 684 | add_query_arg( |
| 634 | 685 | array( |
| 635 | 686 | 'page' => is_network_admin() ? $this->network->network_settings_page_slug : $this->settings_page_slug, |
| 636 | 687 | 'message' => 'data_erased', |
| @@ -641,14 +692,19 @@ | ||
| 641 | 692 | |
| 642 | 693 | exit; |
| 643 | 694 | } |
| 644 | 695 | |
| 696 | + /** | |
| 697 | + * Clears stream records from the database. | |
| 698 | + * | |
| 699 | + * @return void | |
| 700 | + */ | |
| 645 | 701 | private function erase_stream_records() { |
| 646 | 702 | global $wpdb; |
| 647 | 703 | |
| 648 | 704 | $where = ''; |
| 649 | 705 | |
| 650 | - if ( is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) { | |
| 706 | + if ( is_multisite() && ! $this->plugin->is_network_activated() ) { | |
| 651 | 707 | $where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() ); |
| 652 | 708 | } |
| 653 | 709 | |
| 654 | 710 | $wpdb->query( |
| @@ -659,8 +715,13 @@ | ||
| 659 | 715 | WHERE 1=1 {$where};" // @codingStandardsIgnoreLine $where already prepared |
| 660 | 716 | ); |
| 661 | 717 | } |
| 662 | 718 | |
| 719 | + /** | |
| 720 | + * Schedules a purge of records. | |
| 721 | + * | |
| 722 | + * @return void | |
| 723 | + */ | |
| 663 | 724 | public function purge_schedule_setup() { |
| 664 | 725 | if ( ! wp_next_scheduled( 'wp_stream_auto_purge' ) ) { |
| 665 | 726 | wp_schedule_event( time(), 'twicedaily', 'wp_stream_auto_purge' ); |
| 666 | 727 | } |
| @@ -665,26 +726,32 @@ | ||
| 665 | 726 | wp_schedule_event( time(), 'twicedaily', 'wp_stream_auto_purge' ); |
| 666 | 727 | } |
| 667 | 728 | } |
| 668 | 729 | |
| 730 | + /** | |
| 731 | + * Executes a scheduled purge | |
| 732 | + * | |
| 733 | + * @return void | |
| 734 | + */ | |
| 669 | 735 | public function purge_scheduled_action() { |
| 670 | 736 | global $wpdb; |
| 671 | 737 | |
| 672 | - // Don't purge when in Network Admin unless Stream is network activated | |
| 738 | + // Don't purge when in Network Admin unless Stream is network activated. | |
| 673 | 739 | if ( |
| 674 | 740 | is_multisite() |
| 675 | 741 | && |
| 676 | 742 | is_network_admin() |
| 677 | 743 | && |
| 678 | - ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) | |
| 744 | + ! $this->plugin->is_network_activated() | |
| 679 | 745 | ) { |
| 680 | 746 | return; |
| 681 | 747 | } |
| 682 | 748 | |
| 683 | - if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) { | |
| 684 | - $options = (array) get_site_option( 'wp_stream_network', array() ); | |
| 749 | + $defaults = $this->plugin->settings->get_defaults(); | |
| 750 | + if ( is_multisite() && $this->plugin->is_network_activated() ) { | |
| 751 | + $options = (array) get_site_option( 'wp_stream_network', $defaults ); | |
| 685 | 752 | } else { |
| 686 | - $options = (array) get_option( 'wp_stream', array() ); | |
| 753 | + $options = (array) get_option( 'wp_stream', $defaults ); | |
| 687 | 754 | } |
| 688 | 755 | |
| 689 | 756 | if ( ! empty( $options['general_keep_records_indefinitely'] ) || ! isset( $options['general_records_ttl'] ) ) { |
| 690 | 757 | return; |
| @@ -697,10 +764,10 @@ | ||
| 697 | 764 | $date->sub( DateInterval::createFromDateString( "$days days" ) ); |
| 698 | 765 | |
| 699 | 766 | $where = $wpdb->prepare( ' AND `stream`.`created` < %s', $date->format( 'Y-m-d H:i:s' ) ); |
| 700 | 767 | |
| 701 | - // Multisite but NOT network activated, only purge the current blog | |
| 702 | - if ( is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) { | |
| 768 | + // Multisite but NOT network activated, only purge the current blog. | |
| 769 | + if ( is_multisite() && ! $this->plugin->is_network_activated() ) { | |
| 703 | 770 | $where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() ); |
| 704 | 771 | } |
| 705 | 772 | |
| 706 | 773 | $wpdb->query( |
| @@ -712,13 +779,15 @@ | ||
| 712 | 779 | ); |
| 713 | 780 | } |
| 714 | 781 | |
| 715 | 782 | /** |
| 716 | - * @param array $links | |
| 717 | - * @param string $file | |
| 783 | + * Returns the admin action links. | |
| 718 | 784 | * |
| 719 | 785 | * @filter plugin_action_links |
| 720 | 786 | * |
| 787 | + * @param array $links Action links. | |
| 788 | + * @param string $file Plugin file. | |
| 789 | + * | |
| 721 | 790 | * @return array |
| 722 | 791 | */ |
| 723 | 792 | public function plugin_action_links( $links, $file ) { |
| 724 | 793 | if ( plugin_basename( $this->plugin->locations['dir'] . 'stream.php' ) !== $file ) { |
| @@ -724,10 +793,10 @@ | ||
| 724 | 793 | if ( plugin_basename( $this->plugin->locations['dir'] . 'stream.php' ) !== $file ) { |
| 725 | 794 | return $links; |
| 726 | 795 | } |
| 727 | 796 | |
| 728 | - // Also don't show links in Network Admin if Stream isn't network enabled | |
| 729 | - if ( is_network_admin() && is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) { | |
| 797 | + // Also don't show links in Network Admin if Stream isn't network enabled. | |
| 798 | + if ( is_network_admin() && is_multisite() && ! $this->plugin->is_network_activated() ) { | |
| 730 | 799 | return $links; |
| 731 | 800 | } |
| 732 | 801 | |
| 733 | 802 | if ( is_network_admin() ) { |
| @@ -733,29 +802,33 @@ | ||
| 733 | 802 | if ( is_network_admin() ) { |
| 734 | 803 | $admin_page_url = add_query_arg( |
| 735 | 804 | array( |
| 736 | 805 | 'page' => $this->network->network_settings_page_slug, |
| 737 | - ), network_admin_url( $this->admin_parent_page ) | |
| 806 | + ), | |
| 807 | + network_admin_url( $this->admin_parent_page ) | |
| 738 | 808 | ); |
| 739 | 809 | } else { |
| 740 | 810 | $admin_page_url = add_query_arg( |
| 741 | 811 | array( |
| 742 | 812 | 'page' => $this->settings_page_slug, |
| 743 | - ), admin_url( $this->admin_parent_page ) | |
| 813 | + ), | |
| 814 | + admin_url( $this->admin_parent_page ) | |
| 744 | 815 | ); |
| 745 | 816 | } |
| 746 | 817 | |
| 747 | 818 | $links[] = sprintf( '<a href="%s">%s</a>', esc_url( $admin_page_url ), esc_html__( 'Settings', 'default' ) ); |
| 748 | 819 | |
| 749 | - $url = add_query_arg( | |
| 750 | - array( | |
| 751 | - 'action' => 'wp_stream_uninstall', | |
| 752 | - 'wp_stream_nonce' => wp_create_nonce( 'stream_nonce' ), | |
| 753 | - ), | |
| 754 | - admin_url( 'admin-ajax.php' ) | |
| 755 | - ); | |
| 820 | + if ( ! defined( 'DISALLOW_FILE_MODS' ) || false === DISALLOW_FILE_MODS ) { | |
| 821 | + $url = add_query_arg( | |
| 822 | + array( | |
| 823 | + 'action' => 'wp_stream_uninstall', | |
| 824 | + 'wp_stream_nonce' => wp_create_nonce( 'stream_nonce' ), | |
| 825 | + ), | |
| 826 | + admin_url( 'admin-ajax.php' ) | |
| 827 | + ); | |
| 756 | 828 | |
| 757 | - $links[] = sprintf( '<span id="wp_stream_uninstall" class="delete"><a href="%s">%s</a></span>', esc_url( $url ), esc_html__( 'Uninstall', 'stream' ) ); | |
| 829 | + $links[] = sprintf( '<span id="wp_stream_uninstall" class="delete"><a href="%s">%s</a></span>', esc_url( $url ), esc_html__( 'Uninstall', 'stream' ) ); | |
| 830 | + } | |
| 758 | 831 | |
| 759 | 832 | return $links; |
| 760 | 833 | } |
| 761 | 834 | |
| @@ -836,9 +909,10 @@ | ||
| 836 | 909 | * Instantiate the list table |
| 837 | 910 | */ |
| 838 | 911 | public function register_list_table() { |
| 839 | 912 | $this->list_table = new List_Table( |
| 840 | - $this->plugin, array( | |
| 913 | + $this->plugin, | |
| 914 | + array( | |
| 841 | 915 | 'screen' => $this->screen_id['main'], |
| 842 | 916 | ) |
| 843 | 917 | ); |
| 844 | 918 | } |
| @@ -845,9 +919,9 @@ | ||
| 845 | 919 | |
| 846 | 920 | /** |
| 847 | 921 | * Check if a particular role has access |
| 848 | 922 | * |
| 849 | - * @param string $role | |
| 923 | + * @param string $role User role. | |
| 850 | 924 | * |
| 851 | 925 | * @return bool |
| 852 | 926 | */ |
| 853 | 927 | private function role_can_view( $role ) { |
| @@ -860,12 +934,12 @@ | ||
| 860 | 934 | |
| 861 | 935 | /** |
| 862 | 936 | * Filter user caps to dynamically grant our view cap based on allowed roles |
| 863 | 937 | * |
| 864 | - * @param $allcaps | |
| 865 | - * @param $caps | |
| 866 | - * @param $args | |
| 867 | - * @param $user | |
| 938 | + * @param array $allcaps All capabilities. | |
| 939 | + * @param array $caps Required caps. | |
| 940 | + * @param array $args Unused. | |
| 941 | + * @param WP_User $user User. | |
| 868 | 942 | * |
| 869 | 943 | * @filter user_has_cap |
| 870 | 944 | * |
| 871 | 945 | * @return array |
| @@ -910,11 +984,11 @@ | ||
| 910 | 984 | * Filter role caps to dynamically grant our view cap based on allowed roles |
| 911 | 985 | * |
| 912 | 986 | * @filter role_has_cap |
| 913 | 987 | * |
| 914 | - * @param $allcaps | |
| 915 | - * @param $cap | |
| 916 | - * @param $role | |
| 988 | + * @param array $allcaps All capabilities. | |
| 989 | + * @param string $cap Require cap. | |
| 990 | + * @param string $role User role. | |
| 917 | 991 | * |
| 918 | 992 | * @return array |
| 919 | 993 | */ |
| 920 | 994 | public function filter_role_caps( $allcaps, $cap, $role ) { |
| @@ -927,8 +1001,10 @@ | ||
| 927 | 1001 | return $allcaps; |
| 928 | 1002 | } |
| 929 | 1003 | |
| 930 | 1004 | /** |
| 1005 | + * Ajax callback for return a user list. | |
| 1006 | + * | |
| 931 | 1007 | * @action wp_ajax_wp_stream_filters |
| 932 | 1008 | */ |
| 933 | 1009 | public function ajax_filters() { |
| 934 | 1010 | if ( ! defined( 'DOING_AJAX' ) || ! current_user_can( $this->plugin->admin->settings_cap ) ) { |
| @@ -962,9 +1038,9 @@ | ||
| 962 | 1038 | if ( count( $users ) > $this->preload_users_max ) { |
| 963 | 1039 | $users = array_slice( $users, 0, $this->preload_users_max ); |
| 964 | 1040 | } |
| 965 | 1041 | |
| 966 | - // Get gravatar / roles for final result set | |
| 1042 | + // Get gravatar / roles for final result set. | |
| 967 | 1043 | $results = $this->get_users_record_meta( $users ); |
| 968 | 1044 | |
| 969 | 1045 | break; |
| 970 | 1046 | } |
| @@ -969,14 +1045,20 @@ | ||
| 969 | 1045 | break; |
| 970 | 1046 | } |
| 971 | 1047 | |
| 972 | 1048 | if ( isset( $results ) ) { |
| 973 | - echo wp_stream_json_encode( $results ); // xss ok | |
| 1049 | + echo wp_stream_json_encode( $results ); // xss ok. | |
| 974 | 1050 | } |
| 975 | 1051 | |
| 976 | 1052 | die(); |
| 977 | 1053 | } |
| 978 | 1054 | |
| 1055 | + /** | |
| 1056 | + * Return relevant user meta data. | |
| 1057 | + * | |
| 1058 | + * @param array $authors Author data. | |
| 1059 | + * @return array | |
| 1060 | + */ | |
| 979 | 1061 | public function get_users_record_meta( $authors ) { |
| 980 | 1062 | $authors_records = array(); |
| 981 | 1063 | |
| 982 | 1064 | foreach ( $authors as $user_id => $args ) { |
| @@ -996,11 +1078,11 @@ | ||
| 996 | 1078 | |
| 997 | 1079 | /** |
| 998 | 1080 | * Get user meta in a way that is also safe for VIP |
| 999 | 1081 | * |
| 1000 | - * @param int $user_id | |
| 1001 | - * @param string $meta_key | |
| 1002 | - * @param bool $single (optional) | |
| 1082 | + * @param int $user_id User ID. | |
| 1083 | + * @param string $meta_key Meta key. | |
| 1084 | + * @param bool $single Return first found meta value connected to the meta key (optional). | |
| 1003 | 1085 | * |
| 1004 | 1086 | * @return mixed |
| 1005 | 1087 | */ |
| 1006 | 1088 | public function get_user_meta( $user_id, $meta_key, $single = true ) { |
| @@ -1013,12 +1095,12 @@ | ||
| 1013 | 1095 | |
| 1014 | 1096 | /** |
| 1015 | 1097 | * Update user meta in a way that is also safe for VIP |
| 1016 | 1098 | * |
| 1017 | - * @param int $user_id | |
| 1018 | - * @param string $meta_key | |
| 1019 | - * @param mixed $meta_value | |
| 1020 | - * @param mixed $prev_value (optional) | |
| 1099 | + * @param int $user_id User ID. | |
| 1100 | + * @param string $meta_key Meta key. | |
| 1101 | + * @param mixed $meta_value Meta value. | |
| 1102 | + * @param mixed $prev_value Previous meta value being overwritten (optional). | |
| 1021 | 1103 | * |
| 1022 | 1104 | * @return int|bool |
| 1023 | 1105 | */ |
| 1024 | 1106 | public function update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) { |
| @@ -1031,11 +1113,11 @@ | ||
| 1031 | 1113 | |
| 1032 | 1114 | /** |
| 1033 | 1115 | * Delete user meta in a way that is also safe for VIP |
| 1034 | 1116 | * |
| 1035 | - * @param int $user_id | |
| 1036 | - * @param string $meta_key | |
| 1037 | - * @param mixed $meta_value (optional) | |
| 1117 | + * @param int $user_id User ID. | |
| 1118 | + * @param string $meta_key Meta key. | |
| 1119 | + * @param mixed $meta_value Meta value (optional). | |
| 1038 | 1120 | * |
| 1039 | 1121 | * @return bool |
| 1040 | 1122 | */ |
| 1041 | 1123 | public function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) { |