| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | namespace WP_Stream; |
| 3 | 4 | |
| 4 | 5 | use DateTime; |
| 5 | 6 | use DateTimeZone; |
| @@ -7,8 +8,9 @@ | ||
| 7 | 8 | use \WP_CLI; |
| 8 | 9 | use \WP_Roles; |
| 9 | 10 | |
| 10 | 11 | class Admin { |
| 12 | + | |
| 11 | 13 | /** |
| 12 | 14 | * Hold Plugin class |
| 13 | 15 | * |
| 14 | 16 | * @var Plugin |
| @@ -124,9 +126,9 @@ | ||
| 124 | 126 | add_action( 'init', array( $this, 'init' ) ); |
| 125 | 127 | |
| 126 | 128 | // Ensure function used in various methods is pre-loaded. |
| 127 | 129 | if ( ! function_exists( 'is_plugin_active_for_network' ) ) { |
| 128 | - require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); | |
| 130 | + require_once ABSPATH . '/wp-admin/includes/plugin.php'; | |
| 129 | 131 | } |
| 130 | 132 | |
| 131 | 133 | // User and role caps. |
| 132 | 134 | add_filter( 'user_has_cap', array( $this, 'filter_user_caps' ), 10, 4 ); |
| @@ -131,9 +133,9 @@ | ||
| 131 | 133 | // User and role caps. |
| 132 | 134 | add_filter( 'user_has_cap', array( $this, 'filter_user_caps' ), 10, 4 ); |
| 133 | 135 | add_filter( 'role_has_cap', array( $this, 'filter_role_caps' ), 10, 3 ); |
| 134 | 136 | |
| 135 | - if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) && ! is_network_admin() ) { | |
| 137 | + if ( is_multisite() && $plugin->is_network_activated() && ! is_network_admin() ) { | |
| 136 | 138 | $options = (array) get_site_option( 'wp_stream_network', array() ); |
| 137 | 139 | $option = isset( $options['general_site_access'] ) ? absint( $options['general_site_access'] ) : 1; |
| 138 | 140 | |
| 139 | 141 | $this->disable_access = ( $option ) ? false : true; |
| @@ -151,27 +153,58 @@ | ||
| 151 | 153 | // Add admin body class. |
| 152 | 154 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
| 153 | 155 | |
| 154 | 156 | // Plugin action links. |
| 155 | - add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 ); | |
| 157 | + add_filter( | |
| 158 | + 'plugin_action_links', | |
| 159 | + array( | |
| 160 | + $this, | |
| 161 | + 'plugin_action_links', | |
| 162 | + ), | |
| 163 | + 10, | |
| 164 | + 2 | |
| 165 | + ); | |
| 156 | 166 | |
| 157 | 167 | // Load admin scripts and styles. |
| 158 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); | |
| 168 | + add_action( | |
| 169 | + 'admin_enqueue_scripts', | |
| 170 | + array( | |
| 171 | + $this, | |
| 172 | + 'admin_enqueue_scripts', | |
| 173 | + ) | |
| 174 | + ); | |
| 159 | 175 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_menu_css' ) ); |
| 160 | 176 | |
| 161 | 177 | // Reset Streams database. |
| 162 | - add_action( 'wp_ajax_wp_stream_reset', array( $this, 'wp_ajax_reset' ) ); | |
| 178 | + add_action( | |
| 179 | + 'wp_ajax_wp_stream_reset', | |
| 180 | + array( | |
| 181 | + $this, | |
| 182 | + 'wp_ajax_reset', | |
| 183 | + ) | |
| 184 | + ); | |
| 163 | 185 | |
| 164 | 186 | // Uninstall Streams and Deactivate plugin. |
| 165 | - $uninstall = new Uninstall( $this->plugin ); | |
| 166 | - add_action( 'wp_ajax_wp_stream_uninstall', array( $uninstall, 'uninstall' ) ); | |
| 187 | + $uninstall = $this->plugin->db->driver->purge_storage( $this->plugin ); | |
| 167 | 188 | |
| 168 | 189 | // Auto purge setup. |
| 169 | 190 | add_action( 'wp_loaded', array( $this, 'purge_schedule_setup' ) ); |
| 170 | - add_action( 'wp_stream_auto_purge', array( $this, 'purge_scheduled_action' ) ); | |
| 191 | + add_action( | |
| 192 | + 'wp_stream_auto_purge', | |
| 193 | + array( | |
| 194 | + $this, | |
| 195 | + 'purge_scheduled_action', | |
| 196 | + ) | |
| 197 | + ); | |
| 171 | 198 | |
| 172 | 199 | // Ajax users list. |
| 173 | - add_action( 'wp_ajax_wp_stream_filters', array( $this, 'ajax_filters' ) ); | |
| 200 | + add_action( | |
| 201 | + 'wp_ajax_wp_stream_filters', | |
| 202 | + array( | |
| 203 | + $this, | |
| 204 | + 'ajax_filters', | |
| 205 | + ) | |
| 206 | + ); | |
| 174 | 207 | } |
| 175 | 208 | |
| 176 | 209 | /** |
| 177 | 210 | * Load admin classes |
| @@ -299,8 +332,16 @@ | ||
| 299 | 332 | $main_menu_position |
| 300 | 333 | ); |
| 301 | 334 | |
| 302 | 335 | /** |
| 336 | + * Fires before submenu items are added to the Stream menu | |
| 337 | + * allowing plugins to add menu items before Settings | |
| 338 | + * | |
| 339 | + * @return void | |
| 340 | + */ | |
| 341 | + do_action( 'wp_stream_admin_menu' ); | |
| 342 | + | |
| 343 | + /** | |
| 303 | 344 | * Filter the Settings admin page title |
| 304 | 345 | * |
| 305 | 346 | * @return string |
| 306 | 347 | */ |
| @@ -323,9 +364,15 @@ | ||
| 323 | 364 | */ |
| 324 | 365 | do_action( 'wp_stream_admin_menu_screens' ); |
| 325 | 366 | |
| 326 | 367 | // Register the list table early, so it associates the column headers with 'Screen settings'. |
| 327 | - add_action( 'load-' . $this->screen_id['main'], array( $this, 'register_list_table' ) ); | |
| 368 | + add_action( | |
| 369 | + 'load-' . $this->screen_id['main'], | |
| 370 | + array( | |
| 371 | + $this, | |
| 372 | + 'register_list_table', | |
| 373 | + ) | |
| 374 | + ); | |
| 328 | 375 | } |
| 329 | 376 | } |
| 330 | 377 | |
| 331 | 378 | /** |
| @@ -337,10 +384,10 @@ | ||
| 337 | 384 | * |
| 338 | 385 | * @return void |
| 339 | 386 | */ |
| 340 | 387 | public function admin_enqueue_scripts( $hook ) { |
| 341 | - wp_register_script( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/js/select2.js', array( 'jquery' ), '3.5.2', true ); | |
| 342 | - wp_register_style( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/css/select2.css', array(), '3.5.2' ); | |
| 388 | + wp_register_script( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/js/select2.full.min.js', array( 'jquery' ), '3.5.2', true ); | |
| 389 | + wp_register_style( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/css/select2.min.css', array(), '3.5.2' ); | |
| 343 | 390 | wp_register_script( 'wp-stream-timeago', $this->plugin->locations['url'] . 'ui/lib/timeago/jquery.timeago.js', array(), '1.4.1', true ); |
| 344 | 391 | |
| 345 | 392 | $locale = strtolower( substr( get_locale(), 0, 2 ) ); |
| 346 | 393 | $file_tmpl = 'ui/lib/timeago/locales/jquery.timeago.%s.js'; |
| @@ -350,9 +397,10 @@ | ||
| 350 | 397 | } else { |
| 351 | 398 | wp_register_script( 'wp-stream-timeago-locale', $this->plugin->locations['url'] . sprintf( $file_tmpl, 'en' ), array( 'wp-stream-timeago' ), '1' ); |
| 352 | 399 | } |
| 353 | 400 | |
| 354 | - wp_enqueue_style( 'wp-stream-admin', $this->plugin->locations['url'] . 'ui/css/admin.css', array(), $this->plugin->get_version() ); | |
| 401 | + $min = wp_stream_min_suffix(); | |
| 402 | + wp_enqueue_style( 'wp-stream-admin', $this->plugin->locations['url'] . 'ui/css/admin.' . $min . 'css', array(), $this->plugin->get_version() ); | |
| 355 | 403 | |
| 356 | 404 | $script_screens = array( 'plugins.php' ); |
| 357 | 405 | |
| 358 | 406 | if ( in_array( $hook, $this->screen_id, true ) || in_array( $hook, $script_screens, true ) ) { |
| @@ -361,11 +409,35 @@ | ||
| 361 | 409 | |
| 362 | 410 | wp_enqueue_script( 'wp-stream-timeago' ); |
| 363 | 411 | wp_enqueue_script( 'wp-stream-timeago-locale' ); |
| 364 | 412 | |
| 365 | - wp_enqueue_script( 'wp-stream-admin', $this->plugin->locations['url'] . 'ui/js/admin.js', array( 'jquery', 'wp-stream-select2' ), $this->plugin->get_version() ); | |
| 366 | - wp_enqueue_script( 'wp-stream-admin-exclude', $this->plugin->locations['url'] . 'ui/js/exclude.js', array( 'jquery', 'wp-stream-select2' ), $this->plugin->get_version() ); | |
| 367 | - wp_enqueue_script( 'wp-stream-live-updates', $this->plugin->locations['url'] . 'ui/js/live-updates.js', array( 'jquery', 'heartbeat' ), $this->plugin->get_version() ); | |
| 413 | + wp_enqueue_script( | |
| 414 | + 'wp-stream-admin', | |
| 415 | + $this->plugin->locations['url'] . 'ui/js/admin.' . $min . 'js', | |
| 416 | + array( | |
| 417 | + 'jquery', | |
| 418 | + 'wp-stream-select2', | |
| 419 | + ), | |
| 420 | + $this->plugin->get_version() | |
| 421 | + ); | |
| 422 | + wp_enqueue_script( | |
| 423 | + 'wp-stream-admin-exclude', | |
| 424 | + $this->plugin->locations['url'] . 'ui/js/exclude.' . $min . 'js', | |
| 425 | + array( | |
| 426 | + 'jquery', | |
| 427 | + 'wp-stream-select2', | |
| 428 | + ), | |
| 429 | + $this->plugin->get_version() | |
| 430 | + ); | |
| 431 | + wp_enqueue_script( | |
| 432 | + 'wp-stream-live-updates', | |
| 433 | + $this->plugin->locations['url'] . 'ui/js/live-updates.' . $min . 'js', | |
| 434 | + array( | |
| 435 | + 'jquery', | |
| 436 | + 'heartbeat', | |
| 437 | + ), | |
| 438 | + $this->plugin->get_version() | |
| 439 | + ); | |
| 368 | 440 | |
| 369 | 441 | wp_localize_script( |
| 370 | 442 | 'wp-stream-admin', |
| 371 | 443 | 'wp_stream', |
| @@ -384,12 +456,16 @@ | ||
| 384 | 456 | 'wp-stream-live-updates', |
| 385 | 457 | 'wp_stream_live_updates', |
| 386 | 458 | array( |
| 387 | 459 | 'current_screen' => $hook, |
| 388 | - 'current_page' => isset( $_GET['paged'] ) ? esc_js( $_GET['paged'] ) : '1', // input var okay | |
| 389 | - 'current_order' => isset( $_GET['order'] ) ? esc_js( $_GET['order'] ) : 'desc', // input var okay | |
| 390 | - 'current_query' => wp_stream_json_encode( $_GET ), // input var okay | |
| 391 | - 'current_query_count' => count( $_GET ), // input var okay | |
| 460 | + 'current_page' => isset( $_GET['paged'] ) ? esc_js( $_GET['paged'] ) : '1', // WPCS: CSRF ok. | |
| 461 | + // input var okay, CSRF okay | |
| 462 | + 'current_order' => isset( $_GET['order'] ) ? esc_js( $_GET['order'] ) : 'desc', // WPCS: CSRF ok. | |
| 463 | + // input var okay, CSRF okay | |
| 464 | + 'current_query' => wp_stream_json_encode( $_GET ), // WPCS: CSRF ok. | |
| 465 | + // input var okay, CSRF okay | |
| 466 | + 'current_query_count' => count( $_GET ), // WPCS: CSRF ok. | |
| 467 | + // input var okay, CSRF okay | |
| 392 | 468 | ) |
| 393 | 469 | ); |
| 394 | 470 | } |
| 395 | 471 | |
| @@ -406,15 +482,16 @@ | ||
| 406 | 482 | * @return int |
| 407 | 483 | */ |
| 408 | 484 | $bulk_actions_threshold = apply_filters( 'wp_stream_bulk_actions_threshold', 100 ); |
| 409 | 485 | |
| 410 | - wp_enqueue_script( 'wp-stream-global', $this->plugin->locations['url'] . 'ui/js/global.js', array( 'jquery' ), $this->plugin->get_version() ); | |
| 486 | + wp_enqueue_script( 'wp-stream-global', $this->plugin->locations['url'] . 'ui/js/global.' . $min . 'js', array( 'jquery' ), $this->plugin->get_version() ); | |
| 411 | 487 | wp_localize_script( |
| 412 | 488 | 'wp-stream-global', |
| 413 | 489 | 'wp_stream_global', |
| 414 | 490 | array( |
| 415 | - 'bulk_actions' => array( | |
| 416 | - 'i18n' => array( | |
| 491 | + 'bulk_actions' => array( | |
| 492 | + 'i18n' => array( | |
| 493 | + // translators: Placeholder refers to a number of items (e.g. "1,742") | |
| 417 | 494 | '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 ) ) ), |
| 418 | 495 | ), |
| 419 | 496 | 'threshold' => absint( $bulk_actions_threshold ), |
| 420 | 497 | ), |
| @@ -432,8 +509,13 @@ | ||
| 432 | 509 | if ( is_admin() && false !== strpos( wp_stream_filter_input( INPUT_GET, 'page' ), $this->records_page_slug ) ) { |
| 433 | 510 | return true; |
| 434 | 511 | } |
| 435 | 512 | |
| 513 | + $screen = get_current_screen(); | |
| 514 | + if ( is_admin() && Alerts::POST_TYPE === $screen->post_type ) { | |
| 515 | + return true; | |
| 516 | + } | |
| 517 | + | |
| 436 | 518 | return false; |
| 437 | 519 | } |
| 438 | 520 | |
| 439 | 521 | /** |
| @@ -450,10 +532,10 @@ | ||
| 450 | 532 | |
| 451 | 533 | if ( $this->is_stream_screen() ) { |
| 452 | 534 | $stream_classes[] = $this->admin_body_class; |
| 453 | 535 | |
| 454 | - if ( isset( $_GET['page'] ) ) { | |
| 455 | - $stream_classes[] = sanitize_key( $_GET['page'] ); // input var okay | |
| 536 | + if ( isset( $_GET['page'] ) ) { // CSRF okay | |
| 537 | + $stream_classes[] = sanitize_key( $_GET['page'] ); // input var okay, CSRF okay | |
| 456 | 538 | } |
| 457 | 539 | } |
| 458 | 540 | |
| 459 | 541 | /** |
| @@ -474,9 +556,10 @@ | ||
| 474 | 556 | * |
| 475 | 557 | * @action admin_enqueue_scripts |
| 476 | 558 | */ |
| 477 | 559 | public function admin_menu_css() { |
| 478 | - wp_register_style( 'wp-stream-datepicker', $this->plugin->locations['url'] . 'ui/css/datepicker.css', array(), $this->plugin->get_version() ); | |
| 560 | + $min = wp_stream_min_suffix(); | |
| 561 | + wp_register_style( 'wp-stream-datepicker', $this->plugin->locations['url'] . 'ui/css/datepicker.' . $min . 'css', array(), $this->plugin->get_version() ); | |
| 479 | 562 | wp_register_style( 'wp-stream-icons', $this->plugin->locations['url'] . 'ui/stream-icons/style.css', array(), $this->plugin->get_version() ); |
| 480 | 563 | |
| 481 | 564 | // Make sure we're working off a clean version |
| 482 | 565 | if ( ! file_exists( ABSPATH . WPINC . '/version.php' ) ) { |
| @@ -481,9 +564,9 @@ | ||
| 481 | 564 | // Make sure we're working off a clean version |
| 482 | 565 | if ( ! file_exists( ABSPATH . WPINC . '/version.php' ) ) { |
| 483 | 566 | return; |
| 484 | 567 | } |
| 485 | - include( ABSPATH . WPINC . '/version.php' ); | |
| 568 | + include ABSPATH . WPINC . '/version.php'; | |
| 486 | 569 | |
| 487 | 570 | if ( ! isset( $wp_version ) ) { |
| 488 | 571 | return; |
| 489 | 572 | } |
| @@ -542,10 +625,15 @@ | ||
| 542 | 625 | |
| 543 | 626 | \wp_add_inline_style( 'wp-admin', $css ); |
| 544 | 627 | } |
| 545 | 628 | |
| 629 | + /** | |
| 630 | + * Handle the reset AJAX request to reset logs. | |
| 631 | + * | |
| 632 | + * @return bool | |
| 633 | + */ | |
| 546 | 634 | public function wp_ajax_reset() { |
| 547 | - check_ajax_referer( 'stream_nonce', 'wp_stream_nonce' ); | |
| 635 | + check_ajax_referer( 'stream_nonce_reset', 'wp_stream_nonce_reset' ); | |
| 548 | 636 | |
| 549 | 637 | if ( ! current_user_can( $this->settings_cap ) ) { |
| 550 | 638 | wp_die( |
| 551 | 639 | esc_html__( "You don't have sufficient privileges to do this action.", 'stream' ) |
| @@ -575,9 +663,9 @@ | ||
| 575 | 663 | global $wpdb; |
| 576 | 664 | |
| 577 | 665 | $where = ''; |
| 578 | 666 | |
| 579 | - if ( is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) { | |
| 667 | + if ( is_multisite() && ! $this->plugin->is_network_activated() ) { | |
| 580 | 668 | $where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() ); |
| 581 | 669 | } |
| 582 | 670 | |
| 583 | 671 | $wpdb->query( |
| @@ -603,25 +691,26 @@ | ||
| 603 | 691 | is_multisite() |
| 604 | 692 | && |
| 605 | 693 | is_network_admin() |
| 606 | 694 | && |
| 607 | - ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) | |
| 695 | + ! $this->plugin->is_network_activated() | |
| 608 | 696 | ) { |
| 609 | 697 | return; |
| 610 | 698 | } |
| 611 | 699 | |
| 612 | - if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) { | |
| 700 | + if ( is_multisite() && $this->plugin->is_network_activated() ) { | |
| 613 | 701 | $options = (array) get_site_option( 'wp_stream_network', array() ); |
| 614 | 702 | } else { |
| 615 | 703 | $options = (array) get_option( 'wp_stream', array() ); |
| 616 | 704 | } |
| 617 | 705 | |
| 618 | - if ( isset( $options['general_keep_records_indefinitely'] ) || ! isset( $options['general_records_ttl'] ) ) { | |
| 706 | + if ( ! empty( $options['general_keep_records_indefinitely'] ) || ! isset( $options['general_records_ttl'] ) ) { | |
| 619 | 707 | return; |
| 620 | 708 | } |
| 621 | 709 | |
| 622 | - $days = $options['general_records_ttl']; | |
| 623 | - $date = new DateTime( 'now', $timezone = new DateTimeZone( 'UTC' ) ); | |
| 710 | + $days = $options['general_records_ttl']; | |
| 711 | + $timezone = new DateTimeZone( 'UTC' ); | |
| 712 | + $date = new DateTime( 'now', $timezone ); | |
| 624 | 713 | |
| 625 | 714 | $date->sub( DateInterval::createFromDateString( "$days days" ) ); |
| 626 | 715 | |
| 627 | 716 | $where = $wpdb->prepare( ' AND `stream`.`created` < %s', $date->format( 'Y-m-d H:i:s' ) ); |
| @@ -626,9 +715,9 @@ | ||
| 626 | 715 | |
| 627 | 716 | $where = $wpdb->prepare( ' AND `stream`.`created` < %s', $date->format( 'Y-m-d H:i:s' ) ); |
| 628 | 717 | |
| 629 | 718 | // Multisite but NOT network activated, only purge the current blog |
| 630 | - if ( is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) { | |
| 719 | + if ( is_multisite() && ! $this->plugin->is_network_activated() ) { | |
| 631 | 720 | $where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() ); |
| 632 | 721 | } |
| 633 | 722 | |
| 634 | 723 | $wpdb->query( |
| @@ -640,9 +729,9 @@ | ||
| 640 | 729 | ); |
| 641 | 730 | } |
| 642 | 731 | |
| 643 | 732 | /** |
| 644 | - * @param array $links | |
| 733 | + * @param array $links | |
| 645 | 734 | * @param string $file |
| 646 | 735 | * |
| 647 | 736 | * @filter plugin_action_links |
| 648 | 737 | * |
| @@ -653,29 +742,41 @@ | ||
| 653 | 742 | return $links; |
| 654 | 743 | } |
| 655 | 744 | |
| 656 | 745 | // Also don't show links in Network Admin if Stream isn't network enabled |
| 657 | - if ( is_network_admin() && is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) { | |
| 746 | + if ( is_network_admin() && is_multisite() && ! $this->plugin->is_network_activated() ) { | |
| 658 | 747 | return $links; |
| 659 | 748 | } |
| 660 | 749 | |
| 661 | 750 | if ( is_network_admin() ) { |
| 662 | - $admin_page_url = add_query_arg( array( 'page' => $this->network->network_settings_page_slug ), network_admin_url( $this->admin_parent_page ) ); | |
| 751 | + $admin_page_url = add_query_arg( | |
| 752 | + array( | |
| 753 | + 'page' => $this->network->network_settings_page_slug, | |
| 754 | + ), | |
| 755 | + network_admin_url( $this->admin_parent_page ) | |
| 756 | + ); | |
| 663 | 757 | } else { |
| 664 | - $admin_page_url = add_query_arg( array( 'page' => $this->settings_page_slug ), admin_url( $this->admin_parent_page ) ); | |
| 758 | + $admin_page_url = add_query_arg( | |
| 759 | + array( | |
| 760 | + 'page' => $this->settings_page_slug, | |
| 761 | + ), | |
| 762 | + admin_url( $this->admin_parent_page ) | |
| 763 | + ); | |
| 665 | 764 | } |
| 666 | 765 | |
| 667 | 766 | $links[] = sprintf( '<a href="%s">%s</a>', esc_url( $admin_page_url ), esc_html__( 'Settings', 'default' ) ); |
| 668 | 767 | |
| 669 | - $url = add_query_arg( | |
| 670 | - array( | |
| 671 | - 'action' => 'wp_stream_uninstall', | |
| 672 | - 'wp_stream_nonce' => wp_create_nonce( 'stream_nonce' ), | |
| 673 | - ), | |
| 674 | - admin_url( 'admin-ajax.php' ) | |
| 675 | - ); | |
| 768 | + if ( ! defined( 'DISALLOW_FILE_MODS' ) || false === DISALLOW_FILE_MODS ) { | |
| 769 | + $url = add_query_arg( | |
| 770 | + array( | |
| 771 | + 'action' => 'wp_stream_uninstall', | |
| 772 | + 'wp_stream_nonce' => wp_create_nonce( 'stream_nonce' ), | |
| 773 | + ), | |
| 774 | + admin_url( 'admin-ajax.php' ) | |
| 775 | + ); | |
| 676 | 776 | |
| 677 | - $links[] = sprintf( '<span id="wp_stream_uninstall" class="delete"><a href="%s">%s</a></span>', esc_url( $url ), esc_html__( 'Uninstall', 'stream' ) ); | |
| 777 | + $links[] = sprintf( '<span id="wp_stream_uninstall" class="delete"><a href="%s">%s</a></span>', esc_url( $url ), esc_html__( 'Uninstall', 'stream' ) ); | |
| 778 | + } | |
| 678 | 779 | |
| 679 | 780 | return $links; |
| 680 | 781 | } |
| 681 | 782 | |
| @@ -685,12 +786,12 @@ | ||
| 685 | 786 | public function render_list_table() { |
| 686 | 787 | $this->list_table->prepare_items(); |
| 687 | 788 | ?> |
| 688 | 789 | <div class="wrap"> |
| 689 | - <h1><?php echo esc_html( get_admin_page_title() ) ?></h1> | |
| 690 | - <?php $this->list_table->display() ?> | |
| 790 | + <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> | |
| 791 | + <?php $this->list_table->display(); ?> | |
| 691 | 792 | </div> |
| 692 | - <?php | |
| 793 | + <?php | |
| 693 | 794 | } |
| 694 | 795 | |
| 695 | 796 | /** |
| 696 | 797 | * Render settings page |
| @@ -702,28 +803,28 @@ | ||
| 702 | 803 | $page_description = apply_filters( 'wp_stream_settings_form_description', '' ); |
| 703 | 804 | |
| 704 | 805 | $sections = $this->plugin->settings->get_fields(); |
| 705 | 806 | $active_tab = wp_stream_filter_input( INPUT_GET, 'tab' ); |
| 706 | - | |
| 707 | - wp_enqueue_script( 'wp-stream-settings', $this->plugin->locations['url'] . 'ui/js/settings.js', array( 'jquery' ), $this->plugin->get_version(), true ); | |
| 807 | + $min = wp_stream_min_suffix(); | |
| 808 | + wp_enqueue_script( 'wp-stream-settings', $this->plugin->locations['url'] . 'ui/js/settings.' . $min . 'js', array( 'jquery' ), $this->plugin->get_version(), true ); | |
| 708 | 809 | ?> |
| 709 | 810 | <div class="wrap"> |
| 710 | - <h1><?php echo esc_html( get_admin_page_title() ) ?></h1> | |
| 811 | + <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> | |
| 711 | 812 | |
| 712 | 813 | <?php if ( ! empty( $page_description ) ) : ?> |
| 713 | - <p><?php echo esc_html( $page_description ) ?></p> | |
| 814 | + <p><?php echo esc_html( $page_description ); ?></p> | |
| 714 | 815 | <?php endif; ?> |
| 715 | 816 | |
| 716 | - <?php settings_errors() ?> | |
| 817 | + <?php settings_errors(); ?> | |
| 717 | 818 | |
| 718 | 819 | <?php if ( count( $sections ) > 1 ) : ?> |
| 719 | 820 | <h2 class="nav-tab-wrapper"> |
| 720 | - <?php $i = 0 ?> | |
| 821 | + <?php $i = 0; ?> | |
| 721 | 822 | <?php foreach ( $sections as $section => $data ) : ?> |
| 722 | - <?php $i ++ ?> | |
| 723 | - <?php $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section ) ?> | |
| 724 | - <a href="<?php echo esc_url( add_query_arg( 'tab', $section ) ) ?>" class="nav-tab<?php if ( $is_active ) { echo esc_attr( ' nav-tab-active' ); } ?>"> | |
| 725 | - <?php echo esc_html( $data['title'] ) ?> | |
| 823 | + <?php $i++; ?> | |
| 824 | + <?php $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section ); ?> | |
| 825 | + <a href="<?php echo esc_url( add_query_arg( 'tab', $section ) ); ?>" class="nav-tab <?php echo $is_active ? esc_attr( ' nav-tab-active' ) : ''; ?>"> | |
| 826 | + <?php echo esc_html( $data['title'] ); ?> | |
| 726 | 827 | </a> |
| 727 | 828 | <?php endforeach; ?> |
| 728 | 829 | </h2> |
| 729 | 830 | <?php endif; ?> |
| @@ -728,29 +829,29 @@ | ||
| 728 | 829 | </h2> |
| 729 | 830 | <?php endif; ?> |
| 730 | 831 | |
| 731 | 832 | <div class="nav-tab-content" id="tab-content-settings"> |
| 732 | - <form method="post" action="<?php echo esc_attr( $form_action ) ?>" enctype="multipart/form-data"> | |
| 833 | + <form method="post" action="<?php echo esc_attr( $form_action ); ?>" enctype="multipart/form-data"> | |
| 733 | 834 | <div class="settings-sections"> |
| 734 | - <?php | |
| 735 | - $i = 0; | |
| 736 | - foreach ( $sections as $section => $data ) { | |
| 737 | - $i++; | |
| 835 | + <?php | |
| 836 | + $i = 0; | |
| 837 | + foreach ( $sections as $section => $data ) { | |
| 838 | + $i++; | |
| 738 | 839 | |
| 739 | - $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section ); | |
| 840 | + $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section ); | |
| 740 | 841 | |
| 741 | - if ( $is_active ) { | |
| 742 | - settings_fields( $option_key ); | |
| 743 | - do_settings_sections( $option_key ); | |
| 744 | - } | |
| 745 | - } | |
| 746 | - ?> | |
| 842 | + if ( $is_active ) { | |
| 843 | + settings_fields( $option_key ); | |
| 844 | + do_settings_sections( $option_key ); | |
| 845 | + } | |
| 846 | + } | |
| 847 | + ?> | |
| 747 | 848 | </div> |
| 748 | - <?php submit_button() ?> | |
| 849 | + <?php submit_button(); ?> | |
| 749 | 850 | </form> |
| 750 | 851 | </div> |
| 751 | 852 | </div> |
| 752 | - <?php | |
| 853 | + <?php | |
| 753 | 854 | } |
| 754 | 855 | |
| 755 | 856 | /** |
| 756 | 857 | * Instantiate the list table |
| @@ -755,9 +856,14 @@ | ||
| 755 | 856 | /** |
| 756 | 857 | * Instantiate the list table |
| 757 | 858 | */ |
| 758 | 859 | public function register_list_table() { |
| 759 | - $this->list_table = new List_Table( $this->plugin, array( 'screen' => $this->screen_id['main'] ) ); | |
| 860 | + $this->list_table = new List_Table( | |
| 861 | + $this->plugin, | |
| 862 | + array( | |
| 863 | + 'screen' => $this->screen_id['main'], | |
| 864 | + ) | |
| 865 | + ); | |
| 760 | 866 | } |
| 761 | 867 | |
| 762 | 868 | /** |
| 763 | 869 | * Check if a particular role has access |
| @@ -855,9 +961,13 @@ | ||
| 855 | 961 | |
| 856 | 962 | switch ( wp_stream_filter_input( INPUT_GET, 'filter' ) ) { |
| 857 | 963 | case 'user_id': |
| 858 | 964 | $users = array_merge( |
| 859 | - array( 0 => (object) array( 'display_name' => 'WP-CLI' ) ), | |
| 965 | + array( | |
| 966 | + 0 => (object) array( | |
| 967 | + 'display_name' => 'WP-CLI', | |
| 968 | + ), | |
| 969 | + ), | |
| 860 | 970 | get_users() |
| 861 | 971 | ); |
| 862 | 972 | |
| 863 | 973 | $search = wp_stream_filter_input( INPUT_GET, 'q' ); |
| @@ -864,9 +974,9 @@ | ||
| 864 | 974 | if ( $search ) { |
| 865 | 975 | // `search` arg for get_users() is not enough |
| 866 | 976 | $users = array_filter( |
| 867 | 977 | $users, |
| 868 | - function( $user ) use ( $search ) { | |
| 978 | + function ( $user ) use ( $search ) { | |
| 869 | 979 | return false !== mb_strpos( mb_strtolower( $user->display_name ), mb_strtolower( $search ) ); |
| 870 | 980 | } |
| 871 | 981 | ); |
| 872 | 982 | } |
| @@ -894,13 +1004,13 @@ | ||
| 894 | 1004 | foreach ( $authors as $user_id => $args ) { |
| 895 | 1005 | $author = new Author( $args->ID ); |
| 896 | 1006 | |
| 897 | 1007 | $authors_records[ $user_id ] = array( |
| 898 | - 'text' => $author->get_display_name(), | |
| 899 | - 'id' => $author->id, | |
| 900 | - 'label' => $author->get_display_name(), | |
| 901 | - 'icon' => $author->get_avatar_src( 32 ), | |
| 902 | - 'title' => '', | |
| 1008 | + 'text' => $author->get_display_name(), | |
| 1009 | + 'id' => $author->id, | |
| 1010 | + 'label' => $author->get_display_name(), | |
| 1011 | + 'icon' => $author->get_avatar_src( 32 ), | |
| 1012 | + 'title' => '', | |
| 903 | 1013 | ); |
| 904 | 1014 | } |
| 905 | 1015 | |
| 906 | 1016 | return $authors_records; |
| @@ -908,18 +1018,19 @@ | ||
| 908 | 1018 | |
| 909 | 1019 | /** |
| 910 | 1020 | * Get user meta in a way that is also safe for VIP |
| 911 | 1021 | * |
| 912 | - * @param int $user_id | |
| 1022 | + * @param int $user_id | |
| 913 | 1023 | * @param string $meta_key |
| 914 | - * @param bool $single (optional) | |
| 1024 | + * @param bool $single (optional) | |
| 915 | 1025 | * |
| 916 | 1026 | * @return mixed |
| 917 | 1027 | */ |
| 918 | - function get_user_meta( $user_id, $meta_key, $single = true ) { | |
| 1028 | + public function get_user_meta( $user_id, $meta_key, $single = true ) { | |
| 919 | 1029 | if ( wp_stream_is_vip() && function_exists( 'get_user_attribute' ) ) { |
| 920 | 1030 | return get_user_attribute( $user_id, $meta_key ); |
| 921 | 1031 | } |
| 1032 | + | |
| 922 | 1033 | return get_user_meta( $user_id, $meta_key, $single ); |
| 923 | 1034 | } |
| 924 | 1035 | |
| 925 | 1036 | /** |
| @@ -924,19 +1035,20 @@ | ||
| 924 | 1035 | |
| 925 | 1036 | /** |
| 926 | 1037 | * Update user meta in a way that is also safe for VIP |
| 927 | 1038 | * |
| 928 | - * @param int $user_id | |
| 1039 | + * @param int $user_id | |
| 929 | 1040 | * @param string $meta_key |
| 930 | 1041 | * @param mixed $meta_value |
| 931 | - * @param mixed $prev_value (optional) | |
| 1042 | + * @param mixed $prev_value (optional) | |
| 932 | 1043 | * |
| 933 | 1044 | * @return int|bool |
| 934 | 1045 | */ |
| 935 | - function update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) { | |
| 1046 | + public function update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) { | |
| 936 | 1047 | if ( wp_stream_is_vip() && function_exists( 'update_user_attribute' ) ) { |
| 937 | 1048 | return update_user_attribute( $user_id, $meta_key, $meta_value ); |
| 938 | 1049 | } |
| 1050 | + | |
| 939 | 1051 | return update_user_meta( $user_id, $meta_key, $meta_value, $prev_value ); |
| 940 | 1052 | } |
| 941 | 1053 | |
| 942 | 1054 | /** |
| @@ -941,17 +1053,18 @@ | ||
| 941 | 1053 | |
| 942 | 1054 | /** |
| 943 | 1055 | * Delete user meta in a way that is also safe for VIP |
| 944 | 1056 | * |
| 945 | - * @param int $user_id | |
| 1057 | + * @param int $user_id | |
| 946 | 1058 | * @param string $meta_key |
| 947 | - * @param mixed $meta_value (optional) | |
| 1059 | + * @param mixed $meta_value (optional) | |
| 948 | 1060 | * |
| 949 | 1061 | * @return bool |
| 950 | 1062 | */ |
| 951 | - function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) { | |
| 1063 | + public function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) { | |
| 952 | 1064 | if ( wp_stream_is_vip() && function_exists( 'delete_user_attribute' ) ) { |
| 953 | 1065 | return delete_user_attribute( $user_id, $meta_key, $meta_value ); |
| 954 | 1066 | } |
| 1067 | + | |
| 955 | 1068 | return delete_user_meta( $user_id, $meta_key, $meta_value ); |
| 956 | 1069 | } |
| 957 | 1070 | } |