| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | namespace WP_Stream; |
| 3 | 4 | |
| 4 | 5 | use DateTime; |
| 5 | 6 | use DateTimeZone; |
| @@ -7,25 +8,38 @@ | ||
| 7 | 8 | use \WP_CLI; |
| 8 | 9 | use \WP_Roles; |
| 9 | 10 | |
| 10 | 11 | class Admin { |
| 12 | + | |
| 11 | 13 | /** |
| 12 | 14 | * Hold Plugin class |
| 15 | + * | |
| 13 | 16 | * @var Plugin |
| 14 | 17 | */ |
| 15 | 18 | public $plugin; |
| 16 | 19 | |
| 17 | 20 | /** |
| 21 | + * Holds Network class | |
| 22 | + * | |
| 18 | 23 | * @var Network |
| 19 | 24 | */ |
| 20 | 25 | public $network; |
| 21 | 26 | |
| 22 | 27 | /** |
| 28 | + * Holds Live Update class | |
| 29 | + * | |
| 23 | 30 | * @var Live_Update |
| 24 | 31 | */ |
| 25 | 32 | public $live_update; |
| 26 | 33 | |
| 27 | 34 | /** |
| 35 | + * Holds Export class | |
| 36 | + * | |
| 37 | + * @var Export | |
| 38 | + */ | |
| 39 | + public $export; | |
| 40 | + | |
| 41 | + /** | |
| 28 | 42 | * Menu page screen id |
| 29 | 43 | * |
| 30 | 44 | * @var string |
| 31 | 45 | */ |
| @@ -110,18 +124,18 @@ | ||
| 110 | 124 | $this->plugin = $plugin; |
| 111 | 125 | |
| 112 | 126 | add_action( 'init', array( $this, 'init' ) ); |
| 113 | 127 | |
| 114 | - // Ensure function used in various methods is pre-loaded | |
| 128 | + // Ensure function used in various methods is pre-loaded. | |
| 115 | 129 | if ( ! function_exists( 'is_plugin_active_for_network' ) ) { |
| 116 | - require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); | |
| 130 | + require_once ABSPATH . '/wp-admin/includes/plugin.php'; | |
| 117 | 131 | } |
| 118 | 132 | |
| 119 | - // User and role caps | |
| 133 | + // User and role caps. | |
| 120 | 134 | add_filter( 'user_has_cap', array( $this, 'filter_user_caps' ), 10, 4 ); |
| 121 | 135 | add_filter( 'role_has_cap', array( $this, 'filter_role_caps' ), 10, 3 ); |
| 122 | 136 | |
| 123 | - 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() ) { | |
| 124 | 138 | $options = (array) get_site_option( 'wp_stream_network', array() ); |
| 125 | 139 | $option = isset( $options['general_site_access'] ) ? absint( $options['general_site_access'] ) : 1; |
| 126 | 140 | |
| 127 | 141 | $this->disable_access = ( $option ) ? false : true; |
| @@ -126,49 +140,71 @@ | ||
| 126 | 140 | |
| 127 | 141 | $this->disable_access = ( $option ) ? false : true; |
| 128 | 142 | } |
| 129 | 143 | |
| 130 | - // Register settings page | |
| 144 | + // Register settings page. | |
| 131 | 145 | if ( ! $this->disable_access ) { |
| 132 | 146 | add_action( 'admin_menu', array( $this, 'register_menu' ) ); |
| 133 | 147 | } |
| 134 | 148 | |
| 135 | - // Admin notices | |
| 149 | + // Admin notices. | |
| 136 | 150 | add_action( 'admin_notices', array( $this, 'prepare_admin_notices' ) ); |
| 137 | 151 | add_action( 'shutdown', array( $this, 'admin_notices' ) ); |
| 138 | 152 | |
| 139 | - // Add admin body class | |
| 153 | + // Add admin body class. | |
| 140 | 154 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
| 141 | 155 | |
| 142 | - // Plugin action links | |
| 143 | - add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 ); | |
| 156 | + // Plugin action links. | |
| 157 | + add_filter( | |
| 158 | + 'plugin_action_links', | |
| 159 | + array( | |
| 160 | + $this, | |
| 161 | + 'plugin_action_links', | |
| 162 | + ), | |
| 163 | + 10, | |
| 164 | + 2 | |
| 165 | + ); | |
| 144 | 166 | |
| 145 | - // Load admin scripts and styles | |
| 146 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); | |
| 167 | + // Load admin scripts and styles. | |
| 168 | + add_action( | |
| 169 | + 'admin_enqueue_scripts', | |
| 170 | + array( | |
| 171 | + $this, | |
| 172 | + 'admin_enqueue_scripts', | |
| 173 | + ) | |
| 174 | + ); | |
| 147 | 175 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_menu_css' ) ); |
| 148 | 176 | |
| 149 | - // Reset Streams database | |
| 150 | - add_action( 'wp_ajax_wp_stream_reset', array( $this, 'wp_ajax_reset' ) ); | |
| 177 | + // Reset Streams database. | |
| 178 | + add_action( | |
| 179 | + 'wp_ajax_wp_stream_reset', | |
| 180 | + array( | |
| 181 | + $this, | |
| 182 | + 'wp_ajax_reset', | |
| 183 | + ) | |
| 184 | + ); | |
| 151 | 185 | |
| 152 | - // Uninstall Streams and Deactivate plugin | |
| 153 | - $uninstall = new Uninstall( $this->plugin ); | |
| 154 | - add_action( 'wp_ajax_wp_stream_uninstall', array( $uninstall, 'uninstall' ) ); | |
| 186 | + // Uninstall Streams and Deactivate plugin. | |
| 187 | + $uninstall = $this->plugin->db->driver->purge_storage( $this->plugin ); | |
| 155 | 188 | |
| 156 | - // Auto purge setup | |
| 189 | + // Auto purge setup. | |
| 157 | 190 | add_action( 'wp_loaded', array( $this, 'purge_schedule_setup' ) ); |
| 158 | - 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 | + ); | |
| 159 | 198 | |
| 160 | - // Ajax users list | |
| 161 | - add_action( 'wp_ajax_wp_stream_filters', array( $this, 'ajax_filters' ) ); | |
| 162 | - | |
| 163 | - // Ajax user's name by ID | |
| 164 | - add_action( 'wp_ajax_wp_stream_get_filter_value_by_id', array( $this, 'get_filter_value_by_id' ) ); | |
| 165 | - | |
| 166 | - // Ajax users list | |
| 167 | - add_action( 'wp_ajax_wp_stream_filters', array( $this, 'ajax_filters' ) ); | |
| 168 | - | |
| 169 | - // Ajax user's name by ID | |
| 170 | - add_action( 'wp_ajax_wp_stream_get_filter_value_by_id', array( $this, 'get_filter_value_by_id' ) ); | |
| 199 | + // Ajax users list. | |
| 200 | + add_action( | |
| 201 | + 'wp_ajax_wp_stream_filters', | |
| 202 | + array( | |
| 203 | + $this, | |
| 204 | + 'ajax_filters', | |
| 205 | + ) | |
| 206 | + ); | |
| 171 | 207 | } |
| 172 | 208 | |
| 173 | 209 | /** |
| 174 | 210 | * Load admin classes |
| @@ -177,16 +213,17 @@ | ||
| 177 | 213 | */ |
| 178 | 214 | public function init() { |
| 179 | 215 | $this->network = new Network( $this->plugin ); |
| 180 | 216 | $this->live_update = new Live_Update( $this->plugin ); |
| 217 | + $this->export = new Export( $this->plugin ); | |
| 181 | 218 | } |
| 182 | 219 | |
| 183 | 220 | /** |
| 184 | - * Output specific updates passed as URL parameters | |
| 221 | + * Output specific updates passed as URL parameters. | |
| 185 | 222 | * |
| 186 | 223 | * @action admin_notices |
| 187 | 224 | * |
| 188 | - * @return string | |
| 225 | + * @return void | |
| 189 | 226 | */ |
| 190 | 227 | public function prepare_admin_notices() { |
| 191 | 228 | $message = wp_stream_filter_input( INPUT_GET, 'message' ); |
| 192 | 229 | |
| @@ -199,10 +236,10 @@ | ||
| 199 | 236 | |
| 200 | 237 | /** |
| 201 | 238 | * Handle notice messages according to the appropriate context (WP-CLI or the WP Admin) |
| 202 | 239 | * |
| 203 | - * @param string $message | |
| 204 | - * @param bool $is_error | |
| 240 | + * @param string $message Message to output. | |
| 241 | + * @param bool $is_error If the message is error_level (true) or warning (false). | |
| 205 | 242 | */ |
| 206 | 243 | public function notice( $message, $is_error = true ) { |
| 207 | 244 | if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 208 | 245 | $message = strip_tags( $message ); |
| @@ -212,14 +249,14 @@ | ||
| 212 | 249 | } else { |
| 213 | 250 | WP_CLI::success( $message ); |
| 214 | 251 | } |
| 215 | 252 | } else { |
| 216 | - // Trigger admin notices late, so that any notices which occur during page load are displayed | |
| 253 | + // Trigger admin notices late, so that any notices which occur during page load are displayed. | |
| 217 | 254 | add_action( 'shutdown', array( $this, 'admin_notices' ) ); |
| 218 | 255 | |
| 219 | 256 | $notice = compact( 'message', 'is_error' ); |
| 220 | 257 | |
| 221 | - if ( ! in_array( $notice, $this->notices ) ) { | |
| 258 | + if ( ! in_array( $notice, $this->notices, true ) ) { | |
| 222 | 259 | $this->notices[] = $notice; |
| 223 | 260 | } |
| 224 | 261 | } |
| 225 | 262 | } |
| @@ -258,9 +295,9 @@ | ||
| 258 | 295 | * Register menu page |
| 259 | 296 | * |
| 260 | 297 | * @action admin_menu |
| 261 | 298 | * |
| 262 | - * @return bool|void | |
| 299 | + * @return void | |
| 263 | 300 | */ |
| 264 | 301 | public function register_menu() { |
| 265 | 302 | /** |
| 266 | 303 | * Filter the main admin menu title |
| @@ -295,8 +332,16 @@ | ||
| 295 | 332 | $main_menu_position |
| 296 | 333 | ); |
| 297 | 334 | |
| 298 | 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 | + /** | |
| 299 | 344 | * Filter the Settings admin page title |
| 300 | 345 | * |
| 301 | 346 | * @return string |
| 302 | 347 | */ |
| @@ -318,10 +363,16 @@ | ||
| 318 | 363 | * @return void |
| 319 | 364 | */ |
| 320 | 365 | do_action( 'wp_stream_admin_menu_screens' ); |
| 321 | 366 | |
| 322 | - // Register the list table early, so it associates the column headers with 'Screen settings' | |
| 323 | - add_action( 'load-' . $this->screen_id['main'], array( $this, 'register_list_table' ) ); | |
| 367 | + // Register the list table early, so it associates the column headers with 'Screen settings'. | |
| 368 | + add_action( | |
| 369 | + 'load-' . $this->screen_id['main'], | |
| 370 | + array( | |
| 371 | + $this, | |
| 372 | + 'register_list_table', | |
| 373 | + ) | |
| 374 | + ); | |
| 324 | 375 | } |
| 325 | 376 | } |
| 326 | 377 | |
| 327 | 378 | /** |
| @@ -333,34 +384,60 @@ | ||
| 333 | 384 | * |
| 334 | 385 | * @return void |
| 335 | 386 | */ |
| 336 | 387 | public function admin_enqueue_scripts( $hook ) { |
| 337 | - wp_register_script( 'select2', $this->plugin->locations['url'] . 'ui/lib/select2/select2.js', array( 'jquery' ), '3.5.2', true ); | |
| 338 | - wp_register_style( 'select2', $this->plugin->locations['url'] . 'ui/lib/select2/select2.css', array(), '3.5.2' ); | |
| 339 | - wp_register_script( 'timeago', $this->plugin->locations['url'] . 'ui/lib/timeago/jquery.timeago.js', array(), '1.4.1', true ); | |
| 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' ); | |
| 390 | + wp_register_script( 'wp-stream-timeago', $this->plugin->locations['url'] . 'ui/lib/timeago/jquery.timeago.js', array(), '1.4.1', true ); | |
| 340 | 391 | |
| 341 | 392 | $locale = strtolower( substr( get_locale(), 0, 2 ) ); |
| 342 | 393 | $file_tmpl = 'ui/lib/timeago/locales/jquery.timeago.%s.js'; |
| 343 | 394 | |
| 344 | 395 | if ( file_exists( $this->plugin->locations['dir'] . sprintf( $file_tmpl, $locale ) ) ) { |
| 345 | - wp_register_script( 'timeago-locale', $this->plugin->locations['url'] . sprintf( $file_tmpl, $locale ), array( 'timeago' ), '1' ); | |
| 396 | + wp_register_script( 'wp-stream-timeago-locale', $this->plugin->locations['url'] . sprintf( $file_tmpl, $locale ), array( 'wp-stream-timeago' ), '1' ); | |
| 346 | 397 | } else { |
| 347 | - wp_register_script( 'timeago-locale', $this->plugin->locations['url'] . sprintf( $file_tmpl, 'en' ), array( 'timeago' ), '1' ); | |
| 398 | + wp_register_script( 'wp-stream-timeago-locale', $this->plugin->locations['url'] . sprintf( $file_tmpl, 'en' ), array( 'wp-stream-timeago' ), '1' ); | |
| 348 | 399 | } |
| 349 | 400 | |
| 350 | - 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() ); | |
| 351 | 403 | |
| 352 | - $script_screens = array( 'plugins.php', 'user-edit.php', 'user-new.php', 'profile.php' ); | |
| 404 | + $script_screens = array( 'plugins.php' ); | |
| 353 | 405 | |
| 354 | - if ( in_array( $hook, $this->screen_id ) || in_array( $hook, $script_screens ) ) { | |
| 355 | - wp_enqueue_script( 'select2' ); | |
| 356 | - wp_enqueue_style( 'select2' ); | |
| 406 | + if ( in_array( $hook, $this->screen_id, true ) || in_array( $hook, $script_screens, true ) ) { | |
| 407 | + wp_enqueue_script( 'wp-stream-select2' ); | |
| 408 | + wp_enqueue_style( 'wp-stream-select2' ); | |
| 357 | 409 | |
| 358 | - wp_enqueue_script( 'timeago' ); | |
| 359 | - wp_enqueue_script( 'timeago-locale' ); | |
| 410 | + wp_enqueue_script( 'wp-stream-timeago' ); | |
| 411 | + wp_enqueue_script( 'wp-stream-timeago-locale' ); | |
| 360 | 412 | |
| 361 | - wp_enqueue_script( 'wp-stream-admin', $this->plugin->locations['url'] . 'ui/js/admin.js', array( 'jquery', 'select2' ), $this->plugin->get_version() ); | |
| 362 | - 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 | + ); | |
| 363 | 440 | |
| 364 | 441 | wp_localize_script( |
| 365 | 442 | 'wp-stream-admin', |
| 366 | 443 | 'wp_stream', |
| @@ -379,12 +456,16 @@ | ||
| 379 | 456 | 'wp-stream-live-updates', |
| 380 | 457 | 'wp_stream_live_updates', |
| 381 | 458 | array( |
| 382 | 459 | 'current_screen' => $hook, |
| 383 | - 'current_page' => isset( $_GET['paged'] ) ? esc_js( $_GET['paged'] ) : '1', // input var okay | |
| 384 | - 'current_order' => isset( $_GET['order'] ) ? esc_js( $_GET['order'] ) : 'desc', // input var okay | |
| 385 | - 'current_query' => wp_stream_json_encode( $_GET ), // input var okay | |
| 386 | - '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 | |
| 387 | 468 | ) |
| 388 | 469 | ); |
| 389 | 470 | } |
| 390 | 471 | |
| @@ -401,15 +482,16 @@ | ||
| 401 | 482 | * @return int |
| 402 | 483 | */ |
| 403 | 484 | $bulk_actions_threshold = apply_filters( 'wp_stream_bulk_actions_threshold', 100 ); |
| 404 | 485 | |
| 405 | - 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() ); | |
| 406 | 487 | wp_localize_script( |
| 407 | 488 | 'wp-stream-global', |
| 408 | 489 | 'wp_stream_global', |
| 409 | 490 | array( |
| 410 | - 'bulk_actions' => array( | |
| 411 | - 'i18n' => array( | |
| 491 | + 'bulk_actions' => array( | |
| 492 | + 'i18n' => array( | |
| 493 | + // translators: Placeholder refers to a number of items (e.g. "1,742") | |
| 412 | 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 ) ) ), |
| 413 | 495 | ), |
| 414 | 496 | 'threshold' => absint( $bulk_actions_threshold ), |
| 415 | 497 | ), |
| @@ -427,8 +509,13 @@ | ||
| 427 | 509 | if ( is_admin() && false !== strpos( wp_stream_filter_input( INPUT_GET, 'page' ), $this->records_page_slug ) ) { |
| 428 | 510 | return true; |
| 429 | 511 | } |
| 430 | 512 | |
| 513 | + $screen = get_current_screen(); | |
| 514 | + if ( is_admin() && Alerts::POST_TYPE === $screen->post_type ) { | |
| 515 | + return true; | |
| 516 | + } | |
| 517 | + | |
| 431 | 518 | return false; |
| 432 | 519 | } |
| 433 | 520 | |
| 434 | 521 | /** |
| @@ -433,9 +520,9 @@ | ||
| 433 | 520 | |
| 434 | 521 | /** |
| 435 | 522 | * Add a specific body class to all Stream admin screens |
| 436 | 523 | * |
| 437 | - * @param string $classes | |
| 524 | + * @param string $classes CSS classes to output to body | |
| 438 | 525 | * |
| 439 | 526 | * @filter admin_body_class |
| 440 | 527 | * |
| 441 | 528 | * @return string |
| @@ -445,10 +532,10 @@ | ||
| 445 | 532 | |
| 446 | 533 | if ( $this->is_stream_screen() ) { |
| 447 | 534 | $stream_classes[] = $this->admin_body_class; |
| 448 | 535 | |
| 449 | - if ( isset( $_GET['page'] ) ) { | |
| 450 | - $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 | |
| 451 | 538 | } |
| 452 | 539 | } |
| 453 | 540 | |
| 454 | 541 | /** |
| @@ -469,9 +556,10 @@ | ||
| 469 | 556 | * |
| 470 | 557 | * @action admin_enqueue_scripts |
| 471 | 558 | */ |
| 472 | 559 | public function admin_menu_css() { |
| 473 | - 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() ); | |
| 474 | 562 | wp_register_style( 'wp-stream-icons', $this->plugin->locations['url'] . 'ui/stream-icons/style.css', array(), $this->plugin->get_version() ); |
| 475 | 563 | |
| 476 | 564 | // Make sure we're working off a clean version |
| 477 | 565 | if ( ! file_exists( ABSPATH . WPINC . '/version.php' ) ) { |
| @@ -476,9 +564,9 @@ | ||
| 476 | 564 | // Make sure we're working off a clean version |
| 477 | 565 | if ( ! file_exists( ABSPATH . WPINC . '/version.php' ) ) { |
| 478 | 566 | return; |
| 479 | 567 | } |
| 480 | - include( ABSPATH . WPINC . '/version.php' ); | |
| 568 | + include ABSPATH . WPINC . '/version.php'; | |
| 481 | 569 | |
| 482 | 570 | if ( ! isset( $wp_version ) ) { |
| 483 | 571 | return; |
| 484 | 572 | } |
| @@ -537,10 +625,15 @@ | ||
| 537 | 625 | |
| 538 | 626 | \wp_add_inline_style( 'wp-admin', $css ); |
| 539 | 627 | } |
| 540 | 628 | |
| 629 | + /** | |
| 630 | + * Handle the reset AJAX request to reset logs. | |
| 631 | + * | |
| 632 | + * @return bool | |
| 633 | + */ | |
| 541 | 634 | public function wp_ajax_reset() { |
| 542 | - check_ajax_referer( 'stream_nonce', 'wp_stream_nonce' ); | |
| 635 | + check_ajax_referer( 'stream_nonce_reset', 'wp_stream_nonce_reset' ); | |
| 543 | 636 | |
| 544 | 637 | if ( ! current_user_can( $this->settings_cap ) ) { |
| 545 | 638 | wp_die( |
| 546 | 639 | esc_html__( "You don't have sufficient privileges to do this action.", 'stream' ) |
| @@ -570,9 +663,9 @@ | ||
| 570 | 663 | global $wpdb; |
| 571 | 664 | |
| 572 | 665 | $where = ''; |
| 573 | 666 | |
| 574 | - if ( is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) { | |
| 667 | + if ( is_multisite() && ! $this->plugin->is_network_activated() ) { | |
| 575 | 668 | $where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() ); |
| 576 | 669 | } |
| 577 | 670 | |
| 578 | 671 | $wpdb->query( |
| @@ -579,9 +672,9 @@ | ||
| 579 | 672 | "DELETE `stream`, `meta` |
| 580 | 673 | FROM {$wpdb->stream} AS `stream` |
| 581 | 674 | LEFT JOIN {$wpdb->streammeta} AS `meta` |
| 582 | 675 | ON `meta`.`record_id` = `stream`.`ID` |
| 583 | - WHERE 1=1 {$where};" | |
| 676 | + WHERE 1=1 {$where};" // @codingStandardsIgnoreLine $where already prepared | |
| 584 | 677 | ); |
| 585 | 678 | } |
| 586 | 679 | |
| 587 | 680 | public function purge_schedule_setup() { |
| @@ -598,25 +691,26 @@ | ||
| 598 | 691 | is_multisite() |
| 599 | 692 | && |
| 600 | 693 | is_network_admin() |
| 601 | 694 | && |
| 602 | - ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) | |
| 695 | + ! $this->plugin->is_network_activated() | |
| 603 | 696 | ) { |
| 604 | 697 | return; |
| 605 | 698 | } |
| 606 | 699 | |
| 607 | - if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) { | |
| 700 | + if ( is_multisite() && $this->plugin->is_network_activated() ) { | |
| 608 | 701 | $options = (array) get_site_option( 'wp_stream_network', array() ); |
| 609 | 702 | } else { |
| 610 | 703 | $options = (array) get_option( 'wp_stream', array() ); |
| 611 | 704 | } |
| 612 | 705 | |
| 613 | - 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'] ) ) { | |
| 614 | 707 | return; |
| 615 | 708 | } |
| 616 | 709 | |
| 617 | - $days = $options['general_records_ttl']; | |
| 618 | - $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 ); | |
| 619 | 713 | |
| 620 | 714 | $date->sub( DateInterval::createFromDateString( "$days days" ) ); |
| 621 | 715 | |
| 622 | 716 | $where = $wpdb->prepare( ' AND `stream`.`created` < %s', $date->format( 'Y-m-d H:i:s' ) ); |
| @@ -621,9 +715,9 @@ | ||
| 621 | 715 | |
| 622 | 716 | $where = $wpdb->prepare( ' AND `stream`.`created` < %s', $date->format( 'Y-m-d H:i:s' ) ); |
| 623 | 717 | |
| 624 | 718 | // Multisite but NOT network activated, only purge the current blog |
| 625 | - if ( is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) { | |
| 719 | + if ( is_multisite() && ! $this->plugin->is_network_activated() ) { | |
| 626 | 720 | $where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() ); |
| 627 | 721 | } |
| 628 | 722 | |
| 629 | 723 | $wpdb->query( |
| @@ -630,14 +724,14 @@ | ||
| 630 | 724 | "DELETE `stream`, `meta` |
| 631 | 725 | FROM {$wpdb->stream} AS `stream` |
| 632 | 726 | LEFT JOIN {$wpdb->streammeta} AS `meta` |
| 633 | 727 | ON `meta`.`record_id` = `stream`.`ID` |
| 634 | - WHERE 1=1 {$where};" | |
| 728 | + WHERE 1=1 {$where};" // @codingStandardsIgnoreLine $where already prepared | |
| 635 | 729 | ); |
| 636 | 730 | } |
| 637 | 731 | |
| 638 | 732 | /** |
| 639 | - * @param array $links | |
| 733 | + * @param array $links | |
| 640 | 734 | * @param string $file |
| 641 | 735 | * |
| 642 | 736 | * @filter plugin_action_links |
| 643 | 737 | * |
| @@ -648,29 +742,41 @@ | ||
| 648 | 742 | return $links; |
| 649 | 743 | } |
| 650 | 744 | |
| 651 | 745 | // Also don't show links in Network Admin if Stream isn't network enabled |
| 652 | - 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() ) { | |
| 653 | 747 | return $links; |
| 654 | 748 | } |
| 655 | 749 | |
| 656 | 750 | if ( is_network_admin() ) { |
| 657 | - $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 | + ); | |
| 658 | 757 | } else { |
| 659 | - $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 | + ); | |
| 660 | 764 | } |
| 661 | 765 | |
| 662 | 766 | $links[] = sprintf( '<a href="%s">%s</a>', esc_url( $admin_page_url ), esc_html__( 'Settings', 'default' ) ); |
| 663 | 767 | |
| 664 | - $url = add_query_arg( | |
| 665 | - array( | |
| 666 | - 'action' => 'wp_stream_uninstall', | |
| 667 | - 'wp_stream_nonce' => wp_create_nonce( 'stream_nonce' ), | |
| 668 | - ), | |
| 669 | - admin_url( 'admin-ajax.php' ) | |
| 670 | - ); | |
| 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 | + ); | |
| 671 | 776 | |
| 672 | - $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 | + } | |
| 673 | 779 | |
| 674 | 780 | return $links; |
| 675 | 781 | } |
| 676 | 782 | |
| @@ -680,12 +786,12 @@ | ||
| 680 | 786 | public function render_list_table() { |
| 681 | 787 | $this->list_table->prepare_items(); |
| 682 | 788 | ?> |
| 683 | 789 | <div class="wrap"> |
| 684 | - <h1><?php echo esc_html( get_admin_page_title() ) ?></h1> | |
| 685 | - <?php $this->list_table->display() ?> | |
| 790 | + <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> | |
| 791 | + <?php $this->list_table->display(); ?> | |
| 686 | 792 | </div> |
| 687 | - <?php | |
| 793 | + <?php | |
| 688 | 794 | } |
| 689 | 795 | |
| 690 | 796 | /** |
| 691 | 797 | * Render settings page |
| @@ -697,28 +803,28 @@ | ||
| 697 | 803 | $page_description = apply_filters( 'wp_stream_settings_form_description', '' ); |
| 698 | 804 | |
| 699 | 805 | $sections = $this->plugin->settings->get_fields(); |
| 700 | 806 | $active_tab = wp_stream_filter_input( INPUT_GET, 'tab' ); |
| 701 | - | |
| 702 | - 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 ); | |
| 703 | 809 | ?> |
| 704 | 810 | <div class="wrap"> |
| 705 | - <h1><?php echo esc_html( get_admin_page_title() ) ?></h1> | |
| 811 | + <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> | |
| 706 | 812 | |
| 707 | 813 | <?php if ( ! empty( $page_description ) ) : ?> |
| 708 | - <p><?php echo esc_html( $page_description ) ?></p> | |
| 814 | + <p><?php echo esc_html( $page_description ); ?></p> | |
| 709 | 815 | <?php endif; ?> |
| 710 | 816 | |
| 711 | - <?php settings_errors() ?> | |
| 817 | + <?php settings_errors(); ?> | |
| 712 | 818 | |
| 713 | 819 | <?php if ( count( $sections ) > 1 ) : ?> |
| 714 | 820 | <h2 class="nav-tab-wrapper"> |
| 715 | - <?php $i = 0 ?> | |
| 821 | + <?php $i = 0; ?> | |
| 716 | 822 | <?php foreach ( $sections as $section => $data ) : ?> |
| 717 | - <?php $i ++ ?> | |
| 718 | - <?php $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section ) ?> | |
| 719 | - <a href="<?php echo esc_url( add_query_arg( 'tab', $section ) ) ?>" class="nav-tab<?php if ( $is_active ) { echo esc_attr( ' nav-tab-active' ); } ?>"> | |
| 720 | - <?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'] ); ?> | |
| 721 | 827 | </a> |
| 722 | 828 | <?php endforeach; ?> |
| 723 | 829 | </h2> |
| 724 | 830 | <?php endif; ?> |
| @@ -723,29 +829,29 @@ | ||
| 723 | 829 | </h2> |
| 724 | 830 | <?php endif; ?> |
| 725 | 831 | |
| 726 | 832 | <div class="nav-tab-content" id="tab-content-settings"> |
| 727 | - <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"> | |
| 728 | 834 | <div class="settings-sections"> |
| 729 | - <?php | |
| 730 | - $i = 0; | |
| 731 | - foreach ( $sections as $section => $data ) { | |
| 732 | - $i++; | |
| 835 | + <?php | |
| 836 | + $i = 0; | |
| 837 | + foreach ( $sections as $section => $data ) { | |
| 838 | + $i++; | |
| 733 | 839 | |
| 734 | - $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section ); | |
| 840 | + $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section ); | |
| 735 | 841 | |
| 736 | - if ( $is_active ) { | |
| 737 | - settings_fields( $option_key ); | |
| 738 | - do_settings_sections( $option_key ); | |
| 739 | - } | |
| 740 | - } | |
| 741 | - ?> | |
| 842 | + if ( $is_active ) { | |
| 843 | + settings_fields( $option_key ); | |
| 844 | + do_settings_sections( $option_key ); | |
| 845 | + } | |
| 846 | + } | |
| 847 | + ?> | |
| 742 | 848 | </div> |
| 743 | - <?php submit_button() ?> | |
| 849 | + <?php submit_button(); ?> | |
| 744 | 850 | </form> |
| 745 | 851 | </div> |
| 746 | 852 | </div> |
| 747 | - <?php | |
| 853 | + <?php | |
| 748 | 854 | } |
| 749 | 855 | |
| 750 | 856 | /** |
| 751 | 857 | * Instantiate the list table |
| @@ -750,9 +856,14 @@ | ||
| 750 | 856 | /** |
| 751 | 857 | * Instantiate the list table |
| 752 | 858 | */ |
| 753 | 859 | public function register_list_table() { |
| 754 | - $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 | + ); | |
| 755 | 866 | } |
| 756 | 867 | |
| 757 | 868 | /** |
| 758 | 869 | * Check if a particular role has access |
| @@ -761,9 +872,9 @@ | ||
| 761 | 872 | * |
| 762 | 873 | * @return bool |
| 763 | 874 | */ |
| 764 | 875 | private function role_can_view( $role ) { |
| 765 | - if ( in_array( $role, $this->plugin->settings->options['general_role_access'] ) ) { | |
| 876 | + if ( in_array( $role, $this->plugin->settings->options['general_role_access'], true ) ) { | |
| 766 | 877 | return true; |
| 767 | 878 | } |
| 768 | 879 | |
| 769 | 880 | return false; |
| @@ -802,9 +913,9 @@ | ||
| 802 | 913 | |
| 803 | 914 | $stream_view_caps = array( $this->view_cap ); |
| 804 | 915 | |
| 805 | 916 | foreach ( $caps as $cap ) { |
| 806 | - if ( in_array( $cap, $stream_view_caps ) ) { | |
| 917 | + if ( in_array( $cap, $stream_view_caps, true ) ) { | |
| 807 | 918 | foreach ( $roles as $role ) { |
| 808 | 919 | if ( $this->role_can_view( $role ) ) { |
| 809 | 920 | $allcaps[ $cap ] = true; |
| 810 | 921 | |
| @@ -830,9 +941,9 @@ | ||
| 830 | 941 | */ |
| 831 | 942 | public function filter_role_caps( $allcaps, $cap, $role ) { |
| 832 | 943 | $stream_view_caps = array( $this->view_cap ); |
| 833 | 944 | |
| 834 | - if ( in_array( $cap, $stream_view_caps ) && $this->role_can_view( $role ) ) { | |
| 945 | + if ( in_array( $cap, $stream_view_caps, true ) && $this->role_can_view( $role ) ) { | |
| 835 | 946 | $allcaps[ $cap ] = true; |
| 836 | 947 | } |
| 837 | 948 | |
| 838 | 949 | return $allcaps; |
| @@ -841,12 +952,22 @@ | ||
| 841 | 952 | /** |
| 842 | 953 | * @action wp_ajax_wp_stream_filters |
| 843 | 954 | */ |
| 844 | 955 | public function ajax_filters() { |
| 956 | + if ( ! defined( 'DOING_AJAX' ) || ! current_user_can( $this->plugin->admin->settings_cap ) ) { | |
| 957 | + wp_die( '-1' ); | |
| 958 | + } | |
| 959 | + | |
| 960 | + check_ajax_referer( 'stream_filters_user_search_nonce', 'nonce' ); | |
| 961 | + | |
| 845 | 962 | switch ( wp_stream_filter_input( INPUT_GET, 'filter' ) ) { |
| 846 | 963 | case 'user_id': |
| 847 | 964 | $users = array_merge( |
| 848 | - array( 0 => (object) array( 'display_name' => 'WP-CLI' ) ), | |
| 965 | + array( | |
| 966 | + 0 => (object) array( | |
| 967 | + 'display_name' => 'WP-CLI', | |
| 968 | + ), | |
| 969 | + ), | |
| 849 | 970 | get_users() |
| 850 | 971 | ); |
| 851 | 972 | |
| 852 | 973 | $search = wp_stream_filter_input( INPUT_GET, 'q' ); |
| @@ -853,9 +974,9 @@ | ||
| 853 | 974 | if ( $search ) { |
| 854 | 975 | // `search` arg for get_users() is not enough |
| 855 | 976 | $users = array_filter( |
| 856 | 977 | $users, |
| 857 | - function( $user ) use ( $search ) { | |
| 978 | + function ( $user ) use ( $search ) { | |
| 858 | 979 | return false !== mb_strpos( mb_strtolower( $user->display_name ), mb_strtolower( $search ) ); |
| 859 | 980 | } |
| 860 | 981 | ); |
| 861 | 982 | } |
| @@ -870,68 +991,26 @@ | ||
| 870 | 991 | break; |
| 871 | 992 | } |
| 872 | 993 | |
| 873 | 994 | if ( isset( $results ) ) { |
| 874 | - echo wp_stream_json_encode( array_values( $results ) ); // xss ok | |
| 995 | + echo wp_stream_json_encode( $results ); // xss ok | |
| 875 | 996 | } |
| 876 | 997 | |
| 877 | - if ( defined( 'WP_STREAM_TESTS' ) && WP_STREAM_TESTS ) { | |
| 878 | - return; | |
| 879 | - } | |
| 880 | - | |
| 881 | 998 | die(); |
| 882 | 999 | } |
| 883 | 1000 | |
| 884 | - /** | |
| 885 | - * @action wp_ajax_wp_stream_get_filter_value_by_id | |
| 886 | - */ | |
| 887 | - public function get_filter_value_by_id() { | |
| 888 | - $filter = wp_stream_filter_input( INPUT_POST, 'filter' ); | |
| 889 | - | |
| 890 | - switch ( $filter ) { | |
| 891 | - case 'user_id': | |
| 892 | - $id = wp_stream_filter_input( INPUT_POST, 'id' ); | |
| 893 | - | |
| 894 | - if ( '0' === $id ) { | |
| 895 | - $value = 'WP-CLI'; | |
| 896 | - | |
| 897 | - break; | |
| 898 | - } | |
| 899 | - | |
| 900 | - $user = get_userdata( $id ); | |
| 901 | - | |
| 902 | - if ( ! $user || is_wp_error( $user ) ) { | |
| 903 | - $value = ''; | |
| 904 | - } else { | |
| 905 | - $value = $user->display_name; | |
| 906 | - } | |
| 907 | - | |
| 908 | - break; | |
| 909 | - default: | |
| 910 | - $value = ''; | |
| 911 | - } | |
| 912 | - | |
| 913 | - echo wp_stream_json_encode( $value ); // xss ok | |
| 914 | - | |
| 915 | - if ( defined( 'WP_STREAM_TESTS' ) && WP_STREAM_TESTS ) { | |
| 916 | - return; | |
| 917 | - } | |
| 918 | - | |
| 919 | - die(); | |
| 920 | - } | |
| 921 | - | |
| 922 | 1001 | public function get_users_record_meta( $authors ) { |
| 923 | 1002 | $authors_records = array(); |
| 924 | 1003 | |
| 925 | 1004 | foreach ( $authors as $user_id => $args ) { |
| 926 | - $author = new Author( $user_id ); | |
| 1005 | + $author = new Author( $args->ID ); | |
| 927 | 1006 | |
| 928 | 1007 | $authors_records[ $user_id ] = array( |
| 929 | - 'text' => $author->get_display_name(), | |
| 930 | - 'id' => $user_id, | |
| 931 | - 'label' => $author->get_display_name(), | |
| 932 | - 'icon' => $author->get_avatar_src( 32 ), | |
| 933 | - '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' => '', | |
| 934 | 1013 | ); |
| 935 | 1014 | } |
| 936 | 1015 | |
| 937 | 1016 | return $authors_records; |
| @@ -939,18 +1018,19 @@ | ||
| 939 | 1018 | |
| 940 | 1019 | /** |
| 941 | 1020 | * Get user meta in a way that is also safe for VIP |
| 942 | 1021 | * |
| 943 | - * @param int $user_id | |
| 1022 | + * @param int $user_id | |
| 944 | 1023 | * @param string $meta_key |
| 945 | - * @param bool $single (optional) | |
| 1024 | + * @param bool $single (optional) | |
| 946 | 1025 | * |
| 947 | 1026 | * @return mixed |
| 948 | 1027 | */ |
| 949 | - function get_user_meta( $user_id, $meta_key, $single = true ) { | |
| 1028 | + public function get_user_meta( $user_id, $meta_key, $single = true ) { | |
| 950 | 1029 | if ( wp_stream_is_vip() && function_exists( 'get_user_attribute' ) ) { |
| 951 | 1030 | return get_user_attribute( $user_id, $meta_key ); |
| 952 | 1031 | } |
| 1032 | + | |
| 953 | 1033 | return get_user_meta( $user_id, $meta_key, $single ); |
| 954 | 1034 | } |
| 955 | 1035 | |
| 956 | 1036 | /** |
| @@ -955,19 +1035,20 @@ | ||
| 955 | 1035 | |
| 956 | 1036 | /** |
| 957 | 1037 | * Update user meta in a way that is also safe for VIP |
| 958 | 1038 | * |
| 959 | - * @param int $user_id | |
| 1039 | + * @param int $user_id | |
| 960 | 1040 | * @param string $meta_key |
| 961 | 1041 | * @param mixed $meta_value |
| 962 | - * @param mixed $prev_value (optional) | |
| 1042 | + * @param mixed $prev_value (optional) | |
| 963 | 1043 | * |
| 964 | 1044 | * @return int|bool |
| 965 | 1045 | */ |
| 966 | - 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 = '' ) { | |
| 967 | 1047 | if ( wp_stream_is_vip() && function_exists( 'update_user_attribute' ) ) { |
| 968 | 1048 | return update_user_attribute( $user_id, $meta_key, $meta_value ); |
| 969 | 1049 | } |
| 1050 | + | |
| 970 | 1051 | return update_user_meta( $user_id, $meta_key, $meta_value, $prev_value ); |
| 971 | 1052 | } |
| 972 | 1053 | |
| 973 | 1054 | /** |
| @@ -972,17 +1053,18 @@ | ||
| 972 | 1053 | |
| 973 | 1054 | /** |
| 974 | 1055 | * Delete user meta in a way that is also safe for VIP |
| 975 | 1056 | * |
| 976 | - * @param int $user_id | |
| 1057 | + * @param int $user_id | |
| 977 | 1058 | * @param string $meta_key |
| 978 | - * @param mixed $meta_value (optional) | |
| 1059 | + * @param mixed $meta_value (optional) | |
| 979 | 1060 | * |
| 980 | 1061 | * @return bool |
| 981 | 1062 | */ |
| 982 | - function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) { | |
| 1063 | + public function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) { | |
| 983 | 1064 | if ( wp_stream_is_vip() && function_exists( 'delete_user_attribute' ) ) { |
| 984 | 1065 | return delete_user_attribute( $user_id, $meta_key, $meta_value ); |
| 985 | 1066 | } |
| 1067 | + | |
| 986 | 1068 | return delete_user_meta( $user_id, $meta_key, $meta_value ); |
| 987 | 1069 | } |
| 988 | 1070 | } |