Version Description
July 8, 2020 =
Fix: Stream records now show the correct timestamp instead of dates like
-0001/11/30
#1091, props @kidunot89.Fix: Searching Stream records is now more performant as we throttle the amount of search requests #1081, props @oscarssanchez.
Tweak: Inline PHP documentation updates and WordPress coding standard fixes, props @kidunot89.
Download this release
Release Info
Developer | kasparsd |
Plugin | Stream |
Version | 3.5.0 |
Comparing to | |
See all releases |
Code changes from version 3.4.3 to 3.5.0
- alerts/class-alert-type-ifttt.php +2 -2
- alerts/js/alert-type-highlight.js +6 -6
- alerts/js/alert-type-highlight.min.js +1 -1
- classes/class-admin.php +109 -50
- classes/class-alert-trigger.php +2 -2
- classes/class-alert-type.php +4 -4
- classes/class-alert.php +16 -8
- classes/class-alerts-list.php +3 -3
- classes/class-alerts.php +10 -10
- classes/class-author.php +44 -22
- classes/class-cli.php +14 -9
- classes/class-connector.php +32 -22
- classes/class-connectors.php +42 -17
- classes/class-date-interval.php +20 -9
- classes/class-db-driver-wpdb.php +16 -7
- classes/class-db-driver.php +14 -4
- classes/class-db.php +30 -21
- classes/class-export.php +15 -4
- classes/class-exporter.php +9 -0
- classes/class-filter-input.php +59 -11
- classes/class-form-generator.php +9 -0
- classes/class-install.php +26 -13
- classes/class-list-table.php +178 -33
- classes/class-live-update.php +23 -14
- classes/class-log.php +11 -3
- classes/class-network.php +60 -29
- classes/class-plugin.php +43 -20
- classes/class-preview-list-table.php +8 -0
- classes/class-query.php +16 -7
- classes/class-record.php +120 -7
- classes/class-settings.php +38 -27
- classes/class-uninstall.php +40 -24
- connectors/class-connector-acf.php +46 -37
- connectors/class-connector-bbpress.php +31 -13
- connectors/class-connector-blogs.php +40 -31
- connectors/class-connector-buddypress.php +315 -47
- connectors/class-connector-comments.php +42 -33
- connectors/class-connector-edd.php +175 -24
- connectors/class-connector-editor.php +23 -9
- connectors/class-connector-gravityforms.php +203 -73
- connectors/class-connector-installer.php +80 -26
- connectors/class-connector-jetpack.php +129 -37
- connectors/class-connector-media.php +36 -16
- connectors/class-connector-menus.php +31 -19
- connectors/class-connector-mercator.php +20 -12
- connectors/class-connector-posts.php +39 -30
- connectors/class-connector-settings.php +78 -53
- connectors/class-connector-taxonomies.php +39 -20
- connectors/class-connector-user-switching.php +20 -7
- connectors/class-connector-users.php +41 -30
- connectors/class-connector-widgets.php +113 -94
- connectors/class-connector-woocommerce.php +112 -58
- connectors/class-connector-wordpress-seo.php +210 -125
- contributing.md +1 -1
- exporters/class-exporter-csv.php +9 -0
- exporters/class-exporter-json.php +9 -0
- includes/db-updates.php +13 -7
- includes/feeds/atom.php +7 -1
- includes/feeds/json.php +8 -2
- includes/feeds/rss-2.0.php +7 -1
- includes/functions.php +16 -15
- includes/lib/Carbon.php +7 -7
- readme.md +1 -0
- readme.txt +19 -9
- stream.php +3 -1
- ui/js/admin.js +1 -0
- ui/js/admin.min.js +1 -1
- ui/js/alerts.min.js +1 -1
- ui/js/exclude.min.js +1 -1
- ui/js/global.min.js +1 -1
- ui/js/live-updates.min.js +1 -1
- ui/js/settings.min.js +1 -1
alerts/class-alert-type-ifttt.php
CHANGED
@@ -208,7 +208,7 @@ class Alert_Type_IFTTT extends Alert_Type {
|
|
208 |
Â
$record_data = wp_parse_args(
|
209 |
Â
$recordarr,
|
210 |
Â
array(
|
211 |
-
|
212 |
Â
'summary' => sprintf( __( 'The event %s was triggered' ), $alert->alert_meta['event_name'] ),
|
213 |
Â
'user_id' => get_current_user_id(),
|
214 |
Â
'created' => current_time( 'Y-m-d H:i:s' ),
|
@@ -242,7 +242,7 @@ class Alert_Type_IFTTT extends Alert_Type {
|
|
242 |
Â
* @return string
|
243 |
Â
*/
|
244 |
Â
$date_format = apply_filters( 'wp_stream_alert_ifttt_date_format', 'Y-m-d H:i:s', $alert, $recordarr );
|
245 |
-
$date =
|
246 |
Â
|
247 |
Â
$url = 'https://maker.ifttt.com/trigger/' . $alert->alert_meta['event_name'] . '/with/key/' . $alert->alert_meta['maker_key'];
|
248 |
Â
|
208 |
Â
$record_data = wp_parse_args(
|
209 |
Â
$recordarr,
|
210 |
Â
array(
|
211 |
+
/* translators: %s: the Event Name of the Alert (e.g. "Update a post") */
|
212 |
Â
'summary' => sprintf( __( 'The event %s was triggered' ), $alert->alert_meta['event_name'] ),
|
213 |
Â
'user_id' => get_current_user_id(),
|
214 |
Â
'created' => current_time( 'Y-m-d H:i:s' ),
|
242 |
Â
* @return string
|
243 |
Â
*/
|
244 |
Â
$date_format = apply_filters( 'wp_stream_alert_ifttt_date_format', 'Y-m-d H:i:s', $alert, $recordarr );
|
245 |
+
$date = gmdate( $date_format, strtotime( $created ) );
|
246 |
Â
|
247 |
Â
$url = 'https://maker.ifttt.com/trigger/' . $alert->alert_meta['event_name'] . '/with/key/' . $alert->alert_meta['maker_key'];
|
248 |
Â
|
alerts/js/alert-type-highlight.js
CHANGED
@@ -25,10 +25,10 @@ var streamAlertTypeHighlight = ( function( $ ) {
|
|
25 |
Â
var actionLink = $( this );
|
26 |
Â
|
27 |
Â
/**
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
Â
actionLink.click(
|
33 |
Â
function( e ) {
|
34 |
Â
var recordId, data;
|
@@ -51,8 +51,8 @@ var streamAlertTypeHighlight = ( function( $ ) {
|
|
51 |
Â
);
|
52 |
Â
|
53 |
Â
/**
|
54 |
-
|
55 |
-
|
56 |
Â
function ajaxDone() {
|
57 |
Â
var row = actionLink.parents( '.alert-highlight' ),
|
58 |
Â
odd = $( '.striped > tbody > :nth-child( odd )' );
|
25 |
Â
var actionLink = $( this );
|
26 |
Â
|
27 |
Â
/**
|
28 |
+
* Ajax call to remove the highlight.
|
29 |
+
*
|
30 |
+
* @return void.
|
31 |
+
*/
|
32 |
Â
actionLink.click(
|
33 |
Â
function( e ) {
|
34 |
Â
var recordId, data;
|
51 |
Â
);
|
52 |
Â
|
53 |
Â
/**
|
54 |
+
* Fires when Ajax complete.
|
55 |
+
*/
|
56 |
Â
function ajaxDone() {
|
57 |
Â
var row = actionLink.parents( '.alert-highlight' ),
|
58 |
Â
odd = $( '.striped > tbody > :nth-child( odd )' );
|
alerts/js/alert-type-highlight.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
var streamAlertTypeHighlight=function(
|
1 |
+
var streamAlertTypeHighlight=function(n){var a={ajaxUrl:"",removeAction:"",security:""};return"undefined"!=typeof _streamAlertTypeHighlightExports&&n.extend(a,_streamAlertTypeHighlightExports),a.init=function(){n(document).ready(function(){n('.alert-highlight .action-link[href="#"]').each(function(){var i=n(this);i.click(function(t){var e,r;t.preventDefault(),e=(e=i.parents(".alert-highlight").attr("class").match(/record\-id\-[\w-]*\b/))[0].replace("record-id-",""),r={action:a.removeAction,security:a.security,recordId:e},n.post(a.ajaxUrl,r,function(t){!0===t.success&&function(){var t=i.parents(".alert-highlight"),e=n(".striped > tbody > :nth-child( odd )");t.is(e)?t.animate({backgroundColor:"#f9f9f9"},300,function(){t.removeClass("alert-highlight")}):t.animate({backgroundColor:""},300,function(){t.removeClass("alert-highlight")});i.remove()}()})})})})},a}(jQuery);
|
classes/class-admin.php
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
|
3 |
Â
namespace WP_Stream;
|
4 |
Â
|
@@ -8,10 +13,13 @@ use DateInterval;
|
|
8 |
Â
use \WP_CLI;
|
9 |
Â
use \WP_Roles;
|
10 |
Â
|
Â
|
|
Â
|
|
Â
|
|
11 |
Â
class Admin {
|
12 |
Â
|
13 |
Â
/**
|
14 |
-
*
|
15 |
Â
*
|
16 |
Â
* @var Plugin
|
17 |
Â
*/
|
@@ -118,7 +126,7 @@ class Admin {
|
|
118 |
Â
/**
|
119 |
Â
* Class constructor.
|
120 |
Â
*
|
121 |
-
* @param Plugin $plugin
|
122 |
Â
*/
|
123 |
Â
public function __construct( $plugin ) {
|
124 |
Â
$this->plugin = $plugin;
|
@@ -183,7 +191,11 @@ class Admin {
|
|
183 |
Â
)
|
184 |
Â
);
|
185 |
Â
|
186 |
-
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
187 |
Â
$uninstall = $this->plugin->db->driver->purge_storage( $this->plugin );
|
188 |
Â
|
189 |
Â
// Auto purge setup.
|
@@ -242,7 +254,7 @@ class Admin {
|
|
242 |
Â
*/
|
243 |
Â
public function notice( $message, $is_error = true ) {
|
244 |
Â
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
245 |
-
$message =
|
246 |
Â
|
247 |
Â
if ( $is_error ) {
|
248 |
Â
WP_CLI::warning( $message );
|
@@ -380,7 +392,7 @@ class Admin {
|
|
380 |
Â
*
|
381 |
Â
* @action admin_enqueue_scripts
|
382 |
Â
*
|
383 |
-
* @param string $hook
|
384 |
Â
*
|
385 |
Â
* @return void
|
386 |
Â
*/
|
@@ -393,9 +405,21 @@ class Admin {
|
|
393 |
Â
$file_tmpl = 'ui/lib/timeago/locales/jquery.timeago.%s.js';
|
394 |
Â
|
395 |
Â
if ( file_exists( $this->plugin->locations['dir'] . sprintf( $file_tmpl, $locale ) ) ) {
|
396 |
-
wp_register_script(
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
397 |
Â
} else {
|
398 |
-
wp_register_script(
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
399 |
Â
}
|
400 |
Â
|
401 |
Â
$min = wp_stream_min_suffix();
|
@@ -417,7 +441,8 @@ class Admin {
|
|
417 |
Â
'jquery',
|
418 |
Â
'wp-stream-select2',
|
419 |
Â
),
|
420 |
-
$this->plugin->get_version()
|
Â
|
|
421 |
Â
);
|
422 |
Â
wp_enqueue_script(
|
423 |
Â
'wp-stream-admin-exclude',
|
@@ -426,7 +451,8 @@ class Admin {
|
|
426 |
Â
'jquery',
|
427 |
Â
'wp-stream-select2',
|
428 |
Â
),
|
429 |
-
$this->plugin->get_version()
|
Â
|
|
430 |
Â
);
|
431 |
Â
wp_enqueue_script(
|
432 |
Â
'wp-stream-live-updates',
|
@@ -435,7 +461,8 @@ class Admin {
|
|
435 |
Â
'jquery',
|
436 |
Â
'heartbeat',
|
437 |
Â
),
|
438 |
-
$this->plugin->get_version()
|
Â
|
|
439 |
Â
);
|
440 |
Â
|
441 |
Â
wp_localize_script(
|
@@ -452,19 +479,19 @@ class Admin {
|
|
452 |
Â
)
|
453 |
Â
);
|
454 |
Â
|
Â
|
|
Â
|
|
455 |
Â
wp_localize_script(
|
456 |
Â
'wp-stream-live-updates',
|
457 |
Â
'wp_stream_live_updates',
|
458 |
Â
array(
|
459 |
Â
'current_screen' => $hook,
|
460 |
-
'current_page' => isset( $_GET['paged'] ) ?
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
'current_query' => wp_stream_json_encode( $_GET ), //
|
465 |
-
|
466 |
-
'current_query_count' => count( $_GET ), // WPCS: CSRF ok.
|
467 |
-
// input var okay, CSRF okay
|
468 |
Â
)
|
469 |
Â
);
|
470 |
Â
}
|
@@ -483,14 +510,21 @@ class Admin {
|
|
483 |
Â
*/
|
484 |
Â
$bulk_actions_threshold = apply_filters( 'wp_stream_bulk_actions_threshold', 100 );
|
485 |
Â
|
486 |
-
wp_enqueue_script(
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
487 |
Â
wp_localize_script(
|
488 |
Â
'wp-stream-global',
|
489 |
Â
'wp_stream_global',
|
490 |
Â
array(
|
491 |
Â
'bulk_actions' => array(
|
492 |
Â
'i18n' => array(
|
493 |
-
|
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 ) ) ),
|
495 |
Â
),
|
496 |
Â
'threshold' => absint( $bulk_actions_threshold ),
|
@@ -521,7 +555,7 @@ class Admin {
|
|
521 |
Â
/**
|
522 |
Â
* Add a specific body class to all Stream admin screens
|
523 |
Â
*
|
524 |
-
* @param string $classes
|
525 |
Â
*
|
526 |
Â
* @filter admin_body_class
|
527 |
Â
*
|
@@ -533,8 +567,8 @@ class Admin {
|
|
533 |
Â
if ( $this->is_stream_screen() ) {
|
534 |
Â
$stream_classes[] = $this->admin_body_class;
|
535 |
Â
|
536 |
-
if ( isset( $_GET['page'] ) ) { //
|
537 |
-
$stream_classes[] = sanitize_key( $_GET['page'] ); //
|
538 |
Â
}
|
539 |
Â
}
|
540 |
Â
|
@@ -561,7 +595,7 @@ class Admin {
|
|
561 |
Â
wp_register_style( 'wp-stream-datepicker', $this->plugin->locations['url'] . 'ui/css/datepicker.' . $min . 'css', array(), $this->plugin->get_version() );
|
562 |
Â
wp_register_style( 'wp-stream-icons', $this->plugin->locations['url'] . 'ui/stream-icons/style.css', array(), $this->plugin->get_version() );
|
563 |
Â
|
564 |
-
// Make sure we're working off a clean version
|
565 |
Â
if ( ! file_exists( ABSPATH . WPINC . '/version.php' ) ) {
|
566 |
Â
return;
|
567 |
Â
}
|
@@ -646,7 +680,7 @@ class Admin {
|
|
646 |
Â
return true;
|
647 |
Â
}
|
648 |
Â
|
649 |
-
|
650 |
Â
add_query_arg(
|
651 |
Â
array(
|
652 |
Â
'page' => is_network_admin() ? $this->network->network_settings_page_slug : $this->settings_page_slug,
|
@@ -659,6 +693,11 @@ class Admin {
|
|
659 |
Â
exit;
|
660 |
Â
}
|
661 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
662 |
Â
private function erase_stream_records() {
|
663 |
Â
global $wpdb;
|
664 |
Â
|
@@ -677,16 +716,26 @@ class Admin {
|
|
677 |
Â
);
|
678 |
Â
}
|
679 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
680 |
Â
public function purge_schedule_setup() {
|
681 |
Â
if ( ! wp_next_scheduled( 'wp_stream_auto_purge' ) ) {
|
682 |
Â
wp_schedule_event( time(), 'twicedaily', 'wp_stream_auto_purge' );
|
683 |
Â
}
|
684 |
Â
}
|
685 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
686 |
Â
public function purge_scheduled_action() {
|
687 |
Â
global $wpdb;
|
688 |
Â
|
689 |
-
// Don't purge when in Network Admin unless Stream is network activated
|
690 |
Â
if (
|
691 |
Â
is_multisite()
|
692 |
Â
&&
|
@@ -715,7 +764,7 @@ class Admin {
|
|
715 |
Â
|
716 |
Â
$where = $wpdb->prepare( ' AND `stream`.`created` < %s', $date->format( 'Y-m-d H:i:s' ) );
|
717 |
Â
|
718 |
-
// Multisite but NOT network activated, only purge the current blog
|
719 |
Â
if ( is_multisite() && ! $this->plugin->is_network_activated() ) {
|
720 |
Â
$where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() );
|
721 |
Â
}
|
@@ -730,11 +779,13 @@ class Admin {
|
|
730 |
Â
}
|
731 |
Â
|
732 |
Â
/**
|
733 |
-
*
|
734 |
-
* @param string $file
|
735 |
Â
*
|
736 |
Â
* @filter plugin_action_links
|
737 |
Â
*
|
Â
|
|
Â
|
|
Â
|
|
738 |
Â
* @return array
|
739 |
Â
*/
|
740 |
Â
public function plugin_action_links( $links, $file ) {
|
@@ -742,7 +793,7 @@ class Admin {
|
|
742 |
Â
return $links;
|
743 |
Â
}
|
744 |
Â
|
745 |
-
// Also don't show links in Network Admin if Stream isn't network enabled
|
746 |
Â
if ( is_network_admin() && is_multisite() && ! $this->plugin->is_network_activated() ) {
|
747 |
Â
return $links;
|
748 |
Â
}
|
@@ -868,7 +919,7 @@ class Admin {
|
|
868 |
Â
/**
|
869 |
Â
* Check if a particular role has access
|
870 |
Â
*
|
871 |
-
* @param string $role
|
872 |
Â
*
|
873 |
Â
* @return bool
|
874 |
Â
*/
|
@@ -883,10 +934,10 @@ class Admin {
|
|
883 |
Â
/**
|
884 |
Â
* Filter user caps to dynamically grant our view cap based on allowed roles
|
885 |
Â
*
|
886 |
-
* @param $allcaps
|
887 |
-
* @param $caps
|
888 |
-
* @param $args
|
889 |
-
* @param $user
|
890 |
Â
*
|
891 |
Â
* @filter user_has_cap
|
892 |
Â
*
|
@@ -933,9 +984,9 @@ class Admin {
|
|
933 |
Â
*
|
934 |
Â
* @filter role_has_cap
|
935 |
Â
*
|
936 |
-
* @param $allcaps
|
937 |
-
* @param $cap
|
938 |
-
* @param $role
|
939 |
Â
*
|
940 |
Â
* @return array
|
941 |
Â
*/
|
@@ -950,6 +1001,8 @@ class Admin {
|
|
950 |
Â
}
|
951 |
Â
|
952 |
Â
/**
|
Â
|
|
Â
|
|
953 |
Â
* @action wp_ajax_wp_stream_filters
|
954 |
Â
*/
|
955 |
Â
public function ajax_filters() {
|
@@ -985,19 +1038,25 @@ class Admin {
|
|
985 |
Â
$users = array_slice( $users, 0, $this->preload_users_max );
|
986 |
Â
}
|
987 |
Â
|
988 |
-
// Get gravatar / roles for final result set
|
989 |
Â
$results = $this->get_users_record_meta( $users );
|
990 |
Â
|
991 |
Â
break;
|
992 |
Â
}
|
993 |
Â
|
994 |
Â
if ( isset( $results ) ) {
|
995 |
-
echo wp_stream_json_encode( $results ); // xss ok
|
996 |
Â
}
|
997 |
Â
|
998 |
Â
die();
|
999 |
Â
}
|
1000 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
1001 |
Â
public function get_users_record_meta( $authors ) {
|
1002 |
Â
$authors_records = array();
|
1003 |
Â
|
@@ -1019,9 +1078,9 @@ class Admin {
|
|
1019 |
Â
/**
|
1020 |
Â
* Get user meta in a way that is also safe for VIP
|
1021 |
Â
*
|
1022 |
-
* @param int $user_id
|
1023 |
-
* @param string $meta_key
|
1024 |
-
* @param bool $single (optional)
|
1025 |
Â
*
|
1026 |
Â
* @return mixed
|
1027 |
Â
*/
|
@@ -1036,10 +1095,10 @@ class Admin {
|
|
1036 |
Â
/**
|
1037 |
Â
* Update user meta in a way that is also safe for VIP
|
1038 |
Â
*
|
1039 |
-
* @param int $user_id
|
1040 |
-
* @param string $meta_key
|
1041 |
-
* @param mixed $meta_value
|
1042 |
-
* @param mixed $prev_value (optional)
|
1043 |
Â
*
|
1044 |
Â
* @return int|bool
|
1045 |
Â
*/
|
@@ -1054,9 +1113,9 @@ class Admin {
|
|
1054 |
Â
/**
|
1055 |
Â
* Delete user meta in a way that is also safe for VIP
|
1056 |
Â
*
|
1057 |
-
* @param int $user_id
|
1058 |
-
* @param string $meta_key
|
1059 |
-
* @param mixed $meta_value (optional)
|
1060 |
Â
*
|
1061 |
Â
* @return bool
|
1062 |
Â
*/
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Centralized manager for WordPress backend functionality.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
Â
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
13 |
Â
use \WP_CLI;
|
14 |
Â
use \WP_Roles;
|
15 |
Â
|
16 |
+
/**
|
17 |
+
* Class - Admin
|
18 |
+
*/
|
19 |
Â
class Admin {
|
20 |
Â
|
21 |
Â
/**
|
22 |
+
* Holds Instance of plugin object
|
23 |
Â
*
|
24 |
Â
* @var Plugin
|
25 |
Â
*/
|
126 |
Â
/**
|
127 |
Â
* Class constructor.
|
128 |
Â
*
|
129 |
+
* @param Plugin $plugin Instance of plugin object.
|
130 |
Â
*/
|
131 |
Â
public function __construct( $plugin ) {
|
132 |
Â
$this->plugin = $plugin;
|
191 |
Â
)
|
192 |
Â
);
|
193 |
Â
|
194 |
+
/**
|
195 |
+
* Uninstall Streams and Deactivate plugin.
|
196 |
+
*
|
197 |
+
* @todo Confirm if variable assignment is necessary.
|
198 |
+
*/
|
199 |
Â
$uninstall = $this->plugin->db->driver->purge_storage( $this->plugin );
|
200 |
Â
|
201 |
Â
// Auto purge setup.
|
254 |
Â
*/
|
255 |
Â
public function notice( $message, $is_error = true ) {
|
256 |
Â
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
257 |
+
$message = wp_strip_all_tags( $message );
|
258 |
Â
|
259 |
Â
if ( $is_error ) {
|
260 |
Â
WP_CLI::warning( $message );
|
392 |
Â
*
|
393 |
Â
* @action admin_enqueue_scripts
|
394 |
Â
*
|
395 |
+
* @param string $hook Current hook.
|
396 |
Â
*
|
397 |
Â
* @return void
|
398 |
Â
*/
|
405 |
Â
$file_tmpl = 'ui/lib/timeago/locales/jquery.timeago.%s.js';
|
406 |
Â
|
407 |
Â
if ( file_exists( $this->plugin->locations['dir'] . sprintf( $file_tmpl, $locale ) ) ) {
|
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 |
+
);
|
415 |
Â
} else {
|
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 |
+
);
|
423 |
Â
}
|
424 |
Â
|
425 |
Â
$min = wp_stream_min_suffix();
|
441 |
Â
'jquery',
|
442 |
Â
'wp-stream-select2',
|
443 |
Â
),
|
444 |
+
$this->plugin->get_version(),
|
445 |
+
false
|
446 |
Â
);
|
447 |
Â
wp_enqueue_script(
|
448 |
Â
'wp-stream-admin-exclude',
|
451 |
Â
'jquery',
|
452 |
Â
'wp-stream-select2',
|
453 |
Â
),
|
454 |
+
$this->plugin->get_version(),
|
455 |
+
false
|
456 |
Â
);
|
457 |
Â
wp_enqueue_script(
|
458 |
Â
'wp-stream-live-updates',
|
461 |
Â
'jquery',
|
462 |
Â
'heartbeat',
|
463 |
Â
),
|
464 |
+
$this->plugin->get_version(),
|
465 |
+
false
|
466 |
Â
);
|
467 |
Â
|
468 |
Â
wp_localize_script(
|
479 |
Â
)
|
480 |
Â
);
|
481 |
Â
|
482 |
+
$order_types = array( 'asc', 'desc' );
|
483 |
+
|
484 |
Â
wp_localize_script(
|
485 |
Â
'wp-stream-live-updates',
|
486 |
Â
'wp_stream_live_updates',
|
487 |
Â
array(
|
488 |
Â
'current_screen' => $hook,
|
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
|
Â
|
|
Â
|
|
495 |
Â
)
|
496 |
Â
);
|
497 |
Â
}
|
510 |
Â
*/
|
511 |
Â
$bulk_actions_threshold = apply_filters( 'wp_stream_bulk_actions_threshold', 100 );
|
512 |
Â
|
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 |
+
|
521 |
Â
wp_localize_script(
|
522 |
Â
'wp-stream-global',
|
523 |
Â
'wp_stream_global',
|
524 |
Â
array(
|
525 |
Â
'bulk_actions' => array(
|
526 |
Â
'i18n' => array(
|
527 |
+
/* translators: %s: a number of items (e.g. "1,742") */
|
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 ) ) ),
|
529 |
Â
),
|
530 |
Â
'threshold' => absint( $bulk_actions_threshold ),
|
555 |
Â
/**
|
556 |
Â
* Add a specific body class to all Stream admin screens
|
557 |
Â
*
|
558 |
+
* @param string $classes CSS classes to output to body.
|
559 |
Â
*
|
560 |
Â
* @filter admin_body_class
|
561 |
Â
*
|
567 |
Â
if ( $this->is_stream_screen() ) {
|
568 |
Â
$stream_classes[] = $this->admin_body_class;
|
569 |
Â
|
570 |
+
if ( isset( $_GET['page'] ) ) { // // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
571 |
+
$stream_classes[] = sanitize_key( $_GET['page'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
572 |
Â
}
|
573 |
Â
}
|
574 |
Â
|
595 |
Â
wp_register_style( 'wp-stream-datepicker', $this->plugin->locations['url'] . 'ui/css/datepicker.' . $min . 'css', array(), $this->plugin->get_version() );
|
596 |
Â
wp_register_style( 'wp-stream-icons', $this->plugin->locations['url'] . 'ui/stream-icons/style.css', array(), $this->plugin->get_version() );
|
597 |
Â
|
598 |
+
// Make sure we're working off a clean version.
|
599 |
Â
if ( ! file_exists( ABSPATH . WPINC . '/version.php' ) ) {
|
600 |
Â
return;
|
601 |
Â
}
|
680 |
Â
return true;
|
681 |
Â
}
|
682 |
Â
|
683 |
+
wp_safe_redirect(
|
684 |
Â
add_query_arg(
|
685 |
Â
array(
|
686 |
Â
'page' => is_network_admin() ? $this->network->network_settings_page_slug : $this->settings_page_slug,
|
693 |
Â
exit;
|
694 |
Â
}
|
695 |
Â
|
696 |
+
/**
|
697 |
+
* Clears stream records from the database.
|
698 |
+
*
|
699 |
+
* @return void
|
700 |
+
*/
|
701 |
Â
private function erase_stream_records() {
|
702 |
Â
global $wpdb;
|
703 |
Â
|
716 |
Â
);
|
717 |
Â
}
|
718 |
Â
|
719 |
+
/**
|
720 |
+
* Schedules a purge of records.
|
721 |
+
*
|
722 |
+
* @return void
|
723 |
+
*/
|
724 |
Â
public function purge_schedule_setup() {
|
725 |
Â
if ( ! wp_next_scheduled( 'wp_stream_auto_purge' ) ) {
|
726 |
Â
wp_schedule_event( time(), 'twicedaily', 'wp_stream_auto_purge' );
|
727 |
Â
}
|
728 |
Â
}
|
729 |
Â
|
730 |
+
/**
|
731 |
+
* Executes a scheduled purge
|
732 |
+
*
|
733 |
+
* @return void
|
734 |
+
*/
|
735 |
Â
public function purge_scheduled_action() {
|
736 |
Â
global $wpdb;
|
737 |
Â
|
738 |
+
// Don't purge when in Network Admin unless Stream is network activated.
|
739 |
Â
if (
|
740 |
Â
is_multisite()
|
741 |
Â
&&
|
764 |
Â
|
765 |
Â
$where = $wpdb->prepare( ' AND `stream`.`created` < %s', $date->format( 'Y-m-d H:i:s' ) );
|
766 |
Â
|
767 |
+
// Multisite but NOT network activated, only purge the current blog.
|
768 |
Â
if ( is_multisite() && ! $this->plugin->is_network_activated() ) {
|
769 |
Â
$where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() );
|
770 |
Â
}
|
779 |
Â
}
|
780 |
Â
|
781 |
Â
/**
|
782 |
+
* Returns the admin action links.
|
Â
|
|
783 |
Â
*
|
784 |
Â
* @filter plugin_action_links
|
785 |
Â
*
|
786 |
+
* @param array $links Action links.
|
787 |
+
* @param string $file Plugin file.
|
788 |
+
*
|
789 |
Â
* @return array
|
790 |
Â
*/
|
791 |
Â
public function plugin_action_links( $links, $file ) {
|
793 |
Â
return $links;
|
794 |
Â
}
|
795 |
Â
|
796 |
+
// Also don't show links in Network Admin if Stream isn't network enabled.
|
797 |
Â
if ( is_network_admin() && is_multisite() && ! $this->plugin->is_network_activated() ) {
|
798 |
Â
return $links;
|
799 |
Â
}
|
919 |
Â
/**
|
920 |
Â
* Check if a particular role has access
|
921 |
Â
*
|
922 |
+
* @param string $role User role.
|
923 |
Â
*
|
924 |
Â
* @return bool
|
925 |
Â
*/
|
934 |
Â
/**
|
935 |
Â
* Filter user caps to dynamically grant our view cap based on allowed roles
|
936 |
Â
*
|
937 |
+
* @param array $allcaps All capabilities.
|
938 |
+
* @param array $caps Required caps.
|
939 |
+
* @param array $args Unused.
|
940 |
+
* @param WP_User $user User.
|
941 |
Â
*
|
942 |
Â
* @filter user_has_cap
|
943 |
Â
*
|
984 |
Â
*
|
985 |
Â
* @filter role_has_cap
|
986 |
Â
*
|
987 |
+
* @param array $allcaps All capabilities.
|
988 |
+
* @param string $cap Require cap.
|
989 |
+
* @param string $role User role.
|
990 |
Â
*
|
991 |
Â
* @return array
|
992 |
Â
*/
|
1001 |
Â
}
|
1002 |
Â
|
1003 |
Â
/**
|
1004 |
+
* Ajax callback for return a user list.
|
1005 |
+
*
|
1006 |
Â
* @action wp_ajax_wp_stream_filters
|
1007 |
Â
*/
|
1008 |
Â
public function ajax_filters() {
|
1038 |
Â
$users = array_slice( $users, 0, $this->preload_users_max );
|
1039 |
Â
}
|
1040 |
Â
|
1041 |
+
// Get gravatar / roles for final result set.
|
1042 |
Â
$results = $this->get_users_record_meta( $users );
|
1043 |
Â
|
1044 |
Â
break;
|
1045 |
Â
}
|
1046 |
Â
|
1047 |
Â
if ( isset( $results ) ) {
|
1048 |
+
echo wp_stream_json_encode( $results ); // xss ok.
|
1049 |
Â
}
|
1050 |
Â
|
1051 |
Â
die();
|
1052 |
Â
}
|
1053 |
Â
|
1054 |
+
/**
|
1055 |
+
* Return relevant user meta data.
|
1056 |
+
*
|
1057 |
+
* @param array $authors Author data.
|
1058 |
+
* @return array
|
1059 |
+
*/
|
1060 |
Â
public function get_users_record_meta( $authors ) {
|
1061 |
Â
$authors_records = array();
|
1062 |
Â
|
1078 |
Â
/**
|
1079 |
Â
* Get user meta in a way that is also safe for VIP
|
1080 |
Â
*
|
1081 |
+
* @param int $user_id User ID.
|
1082 |
+
* @param string $meta_key Meta key.
|
1083 |
+
* @param bool $single Return first found meta value connected to the meta key (optional).
|
1084 |
Â
*
|
1085 |
Â
* @return mixed
|
1086 |
Â
*/
|
1095 |
Â
/**
|
1096 |
Â
* Update user meta in a way that is also safe for VIP
|
1097 |
Â
*
|
1098 |
+
* @param int $user_id User ID.
|
1099 |
+
* @param string $meta_key Meta key.
|
1100 |
+
* @param mixed $meta_value Meta value.
|
1101 |
+
* @param mixed $prev_value Previous meta value being overwritten (optional).
|
1102 |
Â
*
|
1103 |
Â
* @return int|bool
|
1104 |
Â
*/
|
1113 |
Â
/**
|
1114 |
Â
* Delete user meta in a way that is also safe for VIP
|
1115 |
Â
*
|
1116 |
+
* @param int $user_id User ID.
|
1117 |
+
* @param string $meta_key Meta key.
|
1118 |
+
* @param mixed $meta_value Meta value (optional).
|
1119 |
Â
*
|
1120 |
Â
* @return bool
|
1121 |
Â
*/
|
classes/class-alert-trigger.php
CHANGED
@@ -15,7 +15,7 @@ namespace WP_Stream;
|
|
15 |
Â
abstract class Alert_Trigger {
|
16 |
Â
|
17 |
Â
/**
|
18 |
-
*
|
19 |
Â
*
|
20 |
Â
* @var Plugin
|
21 |
Â
*/
|
@@ -31,7 +31,7 @@ abstract class Alert_Trigger {
|
|
31 |
Â
/**
|
32 |
Â
* Class constructor
|
33 |
Â
*
|
34 |
-
* @param Plugin $plugin
|
35 |
Â
*/
|
36 |
Â
public function __construct( $plugin ) {
|
37 |
Â
$this->plugin = $plugin;
|
15 |
Â
abstract class Alert_Trigger {
|
16 |
Â
|
17 |
Â
/**
|
18 |
+
* Holds instance of plugin object
|
19 |
Â
*
|
20 |
Â
* @var Plugin
|
21 |
Â
*/
|
31 |
Â
/**
|
32 |
Â
* Class constructor
|
33 |
Â
*
|
34 |
+
* @param Plugin $plugin Instance of plugin object.
|
35 |
Â
*/
|
36 |
Â
public function __construct( $plugin ) {
|
37 |
Â
$this->plugin = $plugin;
|
classes/class-alert-type.php
CHANGED
@@ -17,7 +17,7 @@ namespace WP_Stream;
|
|
17 |
Â
abstract class Alert_Type {
|
18 |
Â
|
19 |
Â
/**
|
20 |
-
*
|
21 |
Â
*
|
22 |
Â
* @var Plugin
|
23 |
Â
*/
|
@@ -54,7 +54,7 @@ abstract class Alert_Type {
|
|
54 |
Â
* @param Alert $alert Alert currently being worked on.
|
55 |
Â
*/
|
56 |
Â
public function display_fields( $alert ) {
|
57 |
-
// Implementation optional, but recommended
|
58 |
Â
}
|
59 |
Â
|
60 |
Â
/**
|
@@ -63,7 +63,7 @@ abstract class Alert_Type {
|
|
63 |
Â
* @param Alert $alert Alert currently being worked on.
|
64 |
Â
*/
|
65 |
Â
public function save_fields( $alert ) {
|
66 |
-
// Implementation optional, but recommended
|
67 |
Â
}
|
68 |
Â
|
69 |
Â
/**
|
@@ -72,7 +72,7 @@ abstract class Alert_Type {
|
|
72 |
Â
* @return bool
|
73 |
Â
*/
|
74 |
Â
public function is_dependency_satisfied() {
|
75 |
-
// Implementation optional, but recommended
|
76 |
Â
return true;
|
77 |
Â
}
|
78 |
Â
}
|
17 |
Â
abstract class Alert_Type {
|
18 |
Â
|
19 |
Â
/**
|
20 |
+
* Holds instance of plugin object
|
21 |
Â
*
|
22 |
Â
* @var Plugin
|
23 |
Â
*/
|
54 |
Â
* @param Alert $alert Alert currently being worked on.
|
55 |
Â
*/
|
56 |
Â
public function display_fields( $alert ) {
|
57 |
+
// Implementation optional, but recommended.
|
58 |
Â
}
|
59 |
Â
|
60 |
Â
/**
|
63 |
Â
* @param Alert $alert Alert currently being worked on.
|
64 |
Â
*/
|
65 |
Â
public function save_fields( $alert ) {
|
66 |
+
// Implementation optional, but recommended.
|
67 |
Â
}
|
68 |
Â
|
69 |
Â
/**
|
72 |
Â
* @return bool
|
73 |
Â
*/
|
74 |
Â
public function is_dependency_satisfied() {
|
75 |
+
// Implementation optional, but recommended.
|
76 |
Â
return true;
|
77 |
Â
}
|
78 |
Â
}
|
classes/class-alert.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
Â
<?php
|
2 |
Â
/**
|
3 |
-
*
|
4 |
Â
*
|
5 |
Â
* @package WP_Stream
|
6 |
Â
*/
|
@@ -57,7 +57,7 @@ class Alert {
|
|
57 |
Â
public $alert_meta;
|
58 |
Â
|
59 |
Â
/**
|
60 |
-
*
|
61 |
Â
*
|
62 |
Â
* @var Plugin
|
63 |
Â
*/
|
@@ -67,7 +67,7 @@ class Alert {
|
|
67 |
Â
* Class constructor
|
68 |
Â
*
|
69 |
Â
* @param object $item Alert data.
|
70 |
-
* @param Plugin $plugin
|
71 |
Â
* @return void
|
72 |
Â
*/
|
73 |
Â
public function __construct( $item, $plugin ) {
|
@@ -83,8 +83,9 @@ class Alert {
|
|
83 |
Â
}
|
84 |
Â
|
85 |
Â
/**
|
86 |
-
*
|
87 |
Â
*
|
Â
|
|
88 |
Â
* @return int The Post ID of the alert.
|
89 |
Â
*/
|
90 |
Â
public function save() {
|
@@ -99,15 +100,18 @@ class Alert {
|
|
99 |
Â
'post_type' => Alerts::POST_TYPE,
|
100 |
Â
);
|
101 |
Â
|
Â
|
|
102 |
Â
if ( empty( $args['ID'] ) ) {
|
103 |
Â
unset( $args['ID'] );
|
104 |
Â
}
|
105 |
Â
|
Â
|
|
106 |
Â
$post_id = wp_insert_post( $args );
|
107 |
Â
if ( empty( $args['ID'] ) ) {
|
108 |
Â
$this->ID = $post_id;
|
109 |
Â
}
|
110 |
Â
|
Â
|
|
111 |
Â
$meta = array(
|
112 |
Â
'alert_type' => $this->alert_type,
|
113 |
Â
'alert_meta' => $this->alert_meta,
|
@@ -123,6 +127,8 @@ class Alert {
|
|
123 |
Â
/**
|
124 |
Â
* Process settings form data
|
125 |
Â
*
|
Â
|
|
Â
|
|
126 |
Â
* @param array $data Processed post object data.
|
127 |
Â
* @return array New post object data.
|
128 |
Â
*/
|
@@ -201,7 +207,7 @@ class Alert {
|
|
201 |
Â
}
|
202 |
Â
|
203 |
Â
/**
|
204 |
-
*
|
205 |
Â
*
|
206 |
Â
* @return Alert_Type
|
207 |
Â
*/
|
@@ -230,7 +236,6 @@ class Alert {
|
|
230 |
Â
*
|
231 |
Â
* @param int $record_id Record ID.
|
232 |
Â
* @param int $recordarr Record Data.
|
233 |
-
* @return void
|
234 |
Â
*/
|
235 |
Â
public function send_alert( $record_id, $recordarr ) {
|
236 |
Â
$this->get_alert_type_obj()->alert( $record_id, $recordarr, $this );
|
@@ -319,8 +324,11 @@ class Alert {
|
|
319 |
Â
return false;
|
320 |
Â
}
|
321 |
Â
|
322 |
-
|
323 |
-
|
Â
|
|
Â
|
|
Â
|
|
324 |
Â
if ( is_array( $values ) ) {
|
325 |
Â
$post_id = $values[0];
|
326 |
Â
} else {
|
1 |
Â
<?php
|
2 |
Â
/**
|
3 |
+
* Manages a single alert, acting as a model.
|
4 |
Â
*
|
5 |
Â
* @package WP_Stream
|
6 |
Â
*/
|
57 |
Â
public $alert_meta;
|
58 |
Â
|
59 |
Â
/**
|
60 |
+
* Holds instance of plugin object
|
61 |
Â
*
|
62 |
Â
* @var Plugin
|
63 |
Â
*/
|
67 |
Â
* Class constructor
|
68 |
Â
*
|
69 |
Â
* @param object $item Alert data.
|
70 |
+
* @param Plugin $plugin Instance of plugin object.
|
71 |
Â
* @return void
|
72 |
Â
*/
|
73 |
Â
public function __construct( $item, $plugin ) {
|
83 |
Â
}
|
84 |
Â
|
85 |
Â
/**
|
86 |
+
* Saves alert state.
|
87 |
Â
*
|
88 |
+
* @todo Clean up/Remove unnecessary conditional statements.
|
89 |
Â
* @return int The Post ID of the alert.
|
90 |
Â
*/
|
91 |
Â
public function save() {
|
100 |
Â
'post_type' => Alerts::POST_TYPE,
|
101 |
Â
);
|
102 |
Â
|
103 |
+
// Remove empty "ID" field, if new post.
|
104 |
Â
if ( empty( $args['ID'] ) ) {
|
105 |
Â
unset( $args['ID'] );
|
106 |
Â
}
|
107 |
Â
|
108 |
+
// Create or update alert and assign the ID.
|
109 |
Â
$post_id = wp_insert_post( $args );
|
110 |
Â
if ( empty( $args['ID'] ) ) {
|
111 |
Â
$this->ID = $post_id;
|
112 |
Â
}
|
113 |
Â
|
114 |
+
// Save alert type and meta.
|
115 |
Â
$meta = array(
|
116 |
Â
'alert_type' => $this->alert_type,
|
117 |
Â
'alert_meta' => $this->alert_meta,
|
127 |
Â
/**
|
128 |
Â
* Process settings form data
|
129 |
Â
*
|
130 |
+
* @todo Confirm if the function is necessary, it's currently unreference
|
131 |
+
* anywhere else in the plugin.
|
132 |
Â
* @param array $data Processed post object data.
|
133 |
Â
* @return array New post object data.
|
134 |
Â
*/
|
207 |
Â
}
|
208 |
Â
|
209 |
Â
/**
|
210 |
+
* Retreive current alert type object
|
211 |
Â
*
|
212 |
Â
* @return Alert_Type
|
213 |
Â
*/
|
236 |
Â
*
|
237 |
Â
* @param int $record_id Record ID.
|
238 |
Â
* @param int $recordarr Record Data.
|
Â
|
|
239 |
Â
*/
|
240 |
Â
public function send_alert( $record_id, $recordarr ) {
|
241 |
Â
$this->get_alert_type_obj()->alert( $record_id, $recordarr, $this );
|
324 |
Â
return false;
|
325 |
Â
}
|
326 |
Â
|
327 |
+
/**
|
328 |
+
* Grab an Alert post ID.
|
329 |
+
*
|
330 |
+
* @todo Determine which Alert post takes priority.
|
331 |
+
*/
|
332 |
Â
if ( is_array( $values ) ) {
|
333 |
Â
$post_id = $values[0];
|
334 |
Â
} else {
|
classes/class-alerts-list.php
CHANGED
@@ -14,7 +14,7 @@ namespace WP_Stream;
|
|
14 |
Â
*/
|
15 |
Â
class Alerts_List {
|
16 |
Â
/**
|
17 |
-
*
|
18 |
Â
*
|
19 |
Â
* @var Plugin
|
20 |
Â
*/
|
@@ -23,7 +23,7 @@ class Alerts_List {
|
|
23 |
Â
/**
|
24 |
Â
* Class constructor.
|
25 |
Â
*
|
26 |
-
* @param Plugin $plugin
|
27 |
Â
*/
|
28 |
Â
public function __construct( $plugin ) {
|
29 |
Â
$this->plugin = $plugin;
|
@@ -356,7 +356,7 @@ class Alerts_List {
|
|
356 |
Â
wp_register_style(
|
357 |
Â
'wp-stream-alerts-list-css',
|
358 |
Â
$this->plugin->locations['url'] . 'ui/css/alerts-list.' . $min . 'css',
|
359 |
-
|
360 |
Â
$this->plugin->get_version()
|
361 |
Â
);
|
362 |
Â
|
14 |
Â
*/
|
15 |
Â
class Alerts_List {
|
16 |
Â
/**
|
17 |
+
* Holds instance of plugin object
|
18 |
Â
*
|
19 |
Â
* @var Plugin
|
20 |
Â
*/
|
23 |
Â
/**
|
24 |
Â
* Class constructor.
|
25 |
Â
*
|
26 |
+
* @param Plugin $plugin Instance of plugin object.
|
27 |
Â
*/
|
28 |
Â
public function __construct( $plugin ) {
|
29 |
Â
$this->plugin = $plugin;
|
356 |
Â
wp_register_style(
|
357 |
Â
'wp-stream-alerts-list-css',
|
358 |
Â
$this->plugin->locations['url'] . 'ui/css/alerts-list.' . $min . 'css',
|
359 |
+
array(),
|
360 |
Â
$this->plugin->get_version()
|
361 |
Â
);
|
362 |
Â
|
classes/class-alerts.php
CHANGED
@@ -25,7 +25,7 @@ class Alerts {
|
|
25 |
Â
const ALERTS_TRIGGERED_META_KEY = 'wp_stream_alerts_triggered';
|
26 |
Â
|
27 |
Â
/**
|
28 |
-
*
|
29 |
Â
*
|
30 |
Â
* @var Plugin
|
31 |
Â
*/
|
@@ -55,7 +55,7 @@ class Alerts {
|
|
55 |
Â
/**
|
56 |
Â
* Class constructor.
|
57 |
Â
*
|
58 |
-
* @param Plugin $plugin
|
59 |
Â
*/
|
60 |
Â
public function __construct( $plugin ) {
|
61 |
Â
$this->plugin = $plugin;
|
@@ -381,7 +381,7 @@ class Alerts {
|
|
381 |
Â
'public' => false,
|
382 |
Â
'show_in_admin_all_list' => true,
|
383 |
Â
'show_in_admin_status_list' => true,
|
384 |
-
|
385 |
Â
'label_count' => _n_noop( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', 'stream' ),
|
386 |
Â
);
|
387 |
Â
|
@@ -393,7 +393,7 @@ class Alerts {
|
|
393 |
Â
'internal' => false,
|
394 |
Â
'show_in_admin_all_list' => true,
|
395 |
Â
'show_in_admin_status_list' => true,
|
396 |
-
|
397 |
Â
'label_count' => _n_noop( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', 'stream' ),
|
398 |
Â
);
|
399 |
Â
|
@@ -493,7 +493,7 @@ class Alerts {
|
|
493 |
Â
// Set correct URL for the menu item.
|
494 |
Â
if ( $page === $value[2] ) {
|
495 |
Â
// This hack is not kosher, see the docblock for an explanation.
|
496 |
-
$submenu[ $parent ][ $key ][2] = $new_url; //
|
497 |
Â
break;
|
498 |
Â
}
|
499 |
Â
}
|
@@ -755,7 +755,7 @@ class Alerts {
|
|
755 |
Â
$alert_type = wp_stream_filter_input( INPUT_POST, 'wp_stream_alert_type' );
|
756 |
Â
$alert_status = wp_stream_filter_input( INPUT_POST, 'wp_stream_alert_status' );
|
757 |
Â
|
758 |
-
// Insert the post into the database
|
759 |
Â
$item = (object) array(
|
760 |
Â
'alert_type' => $alert_type,
|
761 |
Â
'alert_meta' => array(
|
@@ -796,7 +796,7 @@ class Alerts {
|
|
796 |
Â
}
|
797 |
Â
|
798 |
Â
/**
|
799 |
-
*
|
800 |
Â
*/
|
801 |
Â
public function get_new_alert_triggers_notifications() {
|
802 |
Â
ob_start();
|
@@ -826,8 +826,8 @@ class Alerts {
|
|
826 |
Â
*
|
827 |
Â
* @filter wp_stream_action_links_{connector}
|
828 |
Â
*
|
829 |
-
* @param array $links
|
830 |
-
* @param Record $record
|
831 |
Â
*
|
832 |
Â
* @return array Action links
|
833 |
Â
*/
|
@@ -839,7 +839,7 @@ class Alerts {
|
|
839 |
Â
$connector_posts = new \WP_Stream\Connector_Posts();
|
840 |
Â
$post_type_name = $connector_posts->get_post_type_name( get_post_type( $post->ID ) );
|
841 |
Â
|
842 |
-
|
843 |
Â
$links[ sprintf( esc_html_x( 'Edit %s', 'Post type singular name', 'stream' ), $post_type_name ) ] = admin_url( 'edit.php?post_type=wp_stream_alerts#post-' . $post->ID );
|
844 |
Â
unset( $links[ esc_html__( 'View', 'stream' ) ] );
|
845 |
Â
}
|
25 |
Â
const ALERTS_TRIGGERED_META_KEY = 'wp_stream_alerts_triggered';
|
26 |
Â
|
27 |
Â
/**
|
28 |
+
* Holds Instance of plugin object
|
29 |
Â
*
|
30 |
Â
* @var Plugin
|
31 |
Â
*/
|
55 |
Â
/**
|
56 |
Â
* Class constructor.
|
57 |
Â
*
|
58 |
+
* @param Plugin $plugin Instance of plugin object.
|
59 |
Â
*/
|
60 |
Â
public function __construct( $plugin ) {
|
61 |
Â
$this->plugin = $plugin;
|
381 |
Â
'public' => false,
|
382 |
Â
'show_in_admin_all_list' => true,
|
383 |
Â
'show_in_admin_status_list' => true,
|
384 |
+
/* translators: %s: a number of items (e.g. "42") */
|
385 |
Â
'label_count' => _n_noop( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', 'stream' ),
|
386 |
Â
);
|
387 |
Â
|
393 |
Â
'internal' => false,
|
394 |
Â
'show_in_admin_all_list' => true,
|
395 |
Â
'show_in_admin_status_list' => true,
|
396 |
+
/* translators: %s: a number of items (e.g. "42") */
|
397 |
Â
'label_count' => _n_noop( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', 'stream' ),
|
398 |
Â
);
|
399 |
Â
|
493 |
Â
// Set correct URL for the menu item.
|
494 |
Â
if ( $page === $value[2] ) {
|
495 |
Â
// This hack is not kosher, see the docblock for an explanation.
|
496 |
+
$submenu[ $parent ][ $key ][2] = $new_url; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
497 |
Â
break;
|
498 |
Â
}
|
499 |
Â
}
|
755 |
Â
$alert_type = wp_stream_filter_input( INPUT_POST, 'wp_stream_alert_type' );
|
756 |
Â
$alert_status = wp_stream_filter_input( INPUT_POST, 'wp_stream_alert_status' );
|
757 |
Â
|
758 |
+
// Insert the post into the database.
|
759 |
Â
$item = (object) array(
|
760 |
Â
'alert_type' => $alert_type,
|
761 |
Â
'alert_meta' => array(
|
796 |
Â
}
|
797 |
Â
|
798 |
Â
/**
|
799 |
+
* Return HTML string of the Alert page controls.
|
800 |
Â
*/
|
801 |
Â
public function get_new_alert_triggers_notifications() {
|
802 |
Â
ob_start();
|
826 |
Â
*
|
827 |
Â
* @filter wp_stream_action_links_{connector}
|
828 |
Â
*
|
829 |
+
* @param array $links Previous links registered.
|
830 |
+
* @param Record $record Stream record.
|
831 |
Â
*
|
832 |
Â
* @return array Action links
|
833 |
Â
*/
|
839 |
Â
$connector_posts = new \WP_Stream\Connector_Posts();
|
840 |
Â
$post_type_name = $connector_posts->get_post_type_name( get_post_type( $post->ID ) );
|
841 |
Â
|
842 |
+
/* translators: %s: the post type singular name (e.g. "Post") */
|
843 |
Â
$links[ sprintf( esc_html_x( 'Edit %s', 'Post type singular name', 'stream' ), $post_type_name ) ] = admin_url( 'edit.php?post_type=wp_stream_alerts#post-' . $post->ID );
|
844 |
Â
unset( $links[ esc_html__( 'View', 'stream' ) ] );
|
845 |
Â
}
|
classes/class-author.php
CHANGED
@@ -1,18 +1,33 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Author {
|
5 |
Â
/**
|
Â
|
|
Â
|
|
6 |
Â
* @var int
|
7 |
Â
*/
|
8 |
Â
public $id;
|
9 |
Â
|
10 |
Â
/**
|
Â
|
|
Â
|
|
11 |
Â
* @var array
|
12 |
Â
*/
|
13 |
Â
public $meta = array();
|
14 |
Â
|
15 |
Â
/**
|
Â
|
|
Â
|
|
16 |
Â
* @var \WP_User
|
17 |
Â
*/
|
18 |
Â
protected $user;
|
@@ -35,31 +50,38 @@ class Author {
|
|
35 |
Â
/**
|
36 |
Â
* Get various user meta data
|
37 |
Â
*
|
38 |
-
* @
|
Â
|
|
Â
|
|
39 |
Â
*
|
40 |
-
* @throws \Exception
|
41 |
Â
*
|
42 |
Â
* @return string
|
43 |
Â
*/
|
44 |
Â
public function __get( $name ) {
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
Â
|
|
Â
|
|
Â
|
|
59 |
Â
}
|
60 |
Â
}
|
61 |
Â
|
62 |
Â
/**
|
Â
|
|
Â
|
|
63 |
Â
* @return string
|
64 |
Â
*/
|
65 |
Â
public function __toString() {
|
@@ -76,7 +98,7 @@ class Author {
|
|
76 |
Â
if ( isset( $this->meta['system_user_name'] ) ) {
|
77 |
Â
return esc_html( $this->meta['system_user_name'] );
|
78 |
Â
} elseif ( 'wp_cli' === $this->get_current_agent() ) {
|
79 |
-
return 'WP-CLI'; // No translation needed
|
80 |
Â
}
|
81 |
Â
return esc_html__( 'N/A', 'stream' );
|
82 |
Â
} else {
|
@@ -107,7 +129,7 @@ class Author {
|
|
107 |
Â
if ( ! empty( $this->meta['agent'] ) ) {
|
108 |
Â
$agent = $this->meta['agent'];
|
109 |
Â
} elseif ( ! empty( $this->meta['is_wp_cli'] ) ) {
|
110 |
-
$agent = 'wp_cli'; // legacy
|
111 |
Â
}
|
112 |
Â
|
113 |
Â
return $agent;
|
@@ -118,7 +140,7 @@ class Author {
|
|
118 |
Â
*
|
119 |
Â
* This function will not return an avatar if "Show Avatars" is unchecked in Settings > Discussion.
|
120 |
Â
*
|
121 |
-
* @param int $size (optional) Size of Gravatar to return (in pixels), max is 512, default is 80
|
122 |
Â
*
|
123 |
Â
* @return string|bool An img HTML element, or false if avatars are disabled
|
124 |
Â
*/
|
@@ -146,7 +168,7 @@ class Author {
|
|
146 |
Â
/**
|
147 |
Â
* Return the URL of a Gravatar image.
|
148 |
Â
*
|
149 |
-
* @param int $size (optional) Size of Gravatar to return (in pixels), max is 512, default is 80
|
150 |
Â
*
|
151 |
Â
* @return string|bool Gravatar image URL, or false on failure
|
152 |
Â
*/
|
@@ -263,7 +285,7 @@ class Author {
|
|
263 |
Â
/**
|
264 |
Â
* Get the agent label
|
265 |
Â
*
|
266 |
-
* @param string $agent
|
267 |
Â
*
|
268 |
Â
* @return string
|
269 |
Â
*/
|
@@ -279,7 +301,7 @@ class Author {
|
|
279 |
Â
/**
|
280 |
Â
* Filter agent labels
|
281 |
Â
*
|
282 |
-
* @param string $agent
|
283 |
Â
*
|
284 |
Â
* @return string
|
285 |
Â
*/
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Manages a single user, acting as a model.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Author
|
12 |
+
*/
|
13 |
Â
class Author {
|
14 |
Â
/**
|
15 |
+
* Holds User ID.
|
16 |
+
*
|
17 |
Â
* @var int
|
18 |
Â
*/
|
19 |
Â
public $id;
|
20 |
Â
|
21 |
Â
/**
|
22 |
+
* Holds User meta data.
|
23 |
+
*
|
24 |
Â
* @var array
|
25 |
Â
*/
|
26 |
Â
public $meta = array();
|
27 |
Â
|
28 |
Â
/**
|
29 |
+
* Holds WP user object connected to "$this" instance.
|
30 |
+
*
|
31 |
Â
* @var \WP_User
|
32 |
Â
*/
|
33 |
Â
protected $user;
|
50 |
Â
/**
|
51 |
Â
* Get various user meta data
|
52 |
Â
*
|
53 |
+
* @todo Make sure this is being covered in the unit tests.
|
54 |
+
*
|
55 |
+
* @param string $name User meta key.
|
56 |
Â
*
|
57 |
+
* @throws \Exception Meta not found | User not found.
|
58 |
Â
*
|
59 |
Â
* @return string
|
60 |
Â
*/
|
61 |
Â
public function __get( $name ) {
|
62 |
+
switch ( $name ) {
|
63 |
+
case 'display_name':
|
64 |
+
case 'avatar_img':
|
65 |
+
case 'avatar_src':
|
66 |
+
case 'role':
|
67 |
+
case 'agent':
|
68 |
+
$getter = "get_{$name}";
|
69 |
+
return $this->$getter();
|
70 |
+
default:
|
71 |
+
if ( ! empty( $this->user ) && 0 !== $this->user->ID ) {
|
72 |
+
if ( is_null( $this->user->$name ) ) {
|
73 |
+
throw new \Exception( "Unrecognized magic '$name'" );
|
74 |
+
}
|
75 |
+
return $this->user->$name;
|
76 |
+
}
|
77 |
+
|
78 |
+
throw new \Exception( 'User not found.' );
|
79 |
Â
}
|
80 |
Â
}
|
81 |
Â
|
82 |
Â
/**
|
83 |
+
* Returns string representation of this object
|
84 |
+
*
|
85 |
Â
* @return string
|
86 |
Â
*/
|
87 |
Â
public function __toString() {
|
98 |
Â
if ( isset( $this->meta['system_user_name'] ) ) {
|
99 |
Â
return esc_html( $this->meta['system_user_name'] );
|
100 |
Â
} elseif ( 'wp_cli' === $this->get_current_agent() ) {
|
101 |
+
return 'WP-CLI'; // No translation needed.
|
102 |
Â
}
|
103 |
Â
return esc_html__( 'N/A', 'stream' );
|
104 |
Â
} else {
|
129 |
Â
if ( ! empty( $this->meta['agent'] ) ) {
|
130 |
Â
$agent = $this->meta['agent'];
|
131 |
Â
} elseif ( ! empty( $this->meta['is_wp_cli'] ) ) {
|
132 |
+
$agent = 'wp_cli'; // legacy.
|
133 |
Â
}
|
134 |
Â
|
135 |
Â
return $agent;
|
140 |
Â
*
|
141 |
Â
* This function will not return an avatar if "Show Avatars" is unchecked in Settings > Discussion.
|
142 |
Â
*
|
143 |
+
* @param int $size (optional) Size of Gravatar to return (in pixels), max is 512, default is 80.
|
144 |
Â
*
|
145 |
Â
* @return string|bool An img HTML element, or false if avatars are disabled
|
146 |
Â
*/
|
168 |
Â
/**
|
169 |
Â
* Return the URL of a Gravatar image.
|
170 |
Â
*
|
171 |
+
* @param int $size (optional) Size of Gravatar to return (in pixels), max is 512, default is 80.
|
172 |
Â
*
|
173 |
Â
* @return string|bool Gravatar image URL, or false on failure
|
174 |
Â
*/
|
285 |
Â
/**
|
286 |
Â
* Get the agent label
|
287 |
Â
*
|
288 |
+
* @param string $agent Key representing agent.
|
289 |
Â
*
|
290 |
Â
* @return string
|
291 |
Â
*/
|
301 |
Â
/**
|
302 |
Â
* Filter agent labels
|
303 |
Â
*
|
304 |
+
* @param string $agent Key representing agent.
|
305 |
Â
*
|
306 |
Â
* @return string
|
307 |
Â
*/
|
classes/class-cli.php
CHANGED
@@ -3,10 +3,14 @@
|
|
3 |
Â
* Stream command for WP-CLI
|
4 |
Â
*
|
5 |
Â
* @see https://github.com/wp-cli/wp-cli
|
Â
|
|
6 |
Â
*/
|
7 |
Â
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
Â
|
|
Â
|
|
Â
|
|
10 |
Â
class CLI extends \WP_CLI_Command {
|
11 |
Â
|
12 |
Â
/**
|
@@ -88,6 +92,9 @@ class CLI extends \WP_CLI_Command {
|
|
88 |
Â
* @see WP_Stream_Query
|
89 |
Â
* @see https://github.com/wp-stream/stream/wiki/WP-CLI-Command
|
90 |
Â
* @see https://github.com/wp-stream/stream/wiki/Query-Reference
|
Â
|
|
Â
|
|
Â
|
|
91 |
Â
*/
|
92 |
Â
public function query( $args, $assoc_args ) {
|
93 |
Â
unset( $args );
|
@@ -121,11 +128,11 @@ class CLI extends \WP_CLI_Command {
|
|
121 |
Â
|
122 |
Â
$records = wp_stream_get_instance()->db->query( $query_args );
|
123 |
Â
|
124 |
-
// Make structure Formatter compatible
|
125 |
Â
foreach ( (array) $records as $key => $record ) {
|
126 |
Â
$formatted_records[ $key ] = array();
|
127 |
Â
|
128 |
-
// Catch any fields missing in records
|
129 |
Â
foreach ( $fields as $field ) {
|
130 |
Â
if ( ! array_key_exists( $field, $record ) ) {
|
131 |
Â
$record->$field = null;
|
@@ -152,9 +159,9 @@ class CLI extends \WP_CLI_Command {
|
|
152 |
Â
|
153 |
Â
if ( 'json_pretty' === $assoc_args['format'] ) {
|
154 |
Â
if ( version_compare( PHP_VERSION, '5.4', '<' ) ) {
|
155 |
-
\WP_CLI::line( wp_stream_json_encode( $formatted_records ) ); // xss ok
|
156 |
Â
} else {
|
157 |
-
\WP_CLI::line( wp_stream_json_encode( $formatted_records, JSON_PRETTY_PRINT ) ); // xss ok
|
158 |
Â
}
|
159 |
Â
}
|
160 |
Â
|
@@ -176,8 +183,8 @@ class CLI extends \WP_CLI_Command {
|
|
176 |
Â
/**
|
177 |
Â
* Convert any field to a flat array.
|
178 |
Â
*
|
179 |
-
* @param string $name
|
180 |
-
* @param mixed $object Any value to be converted to an array
|
181 |
Â
*
|
182 |
Â
* @return array The flat array
|
183 |
Â
*/
|
@@ -200,9 +207,7 @@ class CLI extends \WP_CLI_Command {
|
|
200 |
Â
/**
|
201 |
Â
* Convert an array of flat records to CSV
|
202 |
Â
*
|
203 |
-
* @param array $array
|
204 |
-
*
|
205 |
-
* @return string The CSV output
|
206 |
Â
*/
|
207 |
Â
private function csv_format( $array ) {
|
208 |
Â
$output = fopen( 'php://output', 'w' ); // @codingStandardsIgnoreLine Clever output for WP CLI using php://output
|
3 |
Â
* Stream command for WP-CLI
|
4 |
Â
*
|
5 |
Â
* @see https://github.com/wp-cli/wp-cli
|
6 |
+
* @package WP_Stream
|
7 |
Â
*/
|
8 |
Â
|
9 |
Â
namespace WP_Stream;
|
10 |
Â
|
11 |
+
/**
|
12 |
+
* Class - CLI
|
13 |
+
*/
|
14 |
Â
class CLI extends \WP_CLI_Command {
|
15 |
Â
|
16 |
Â
/**
|
92 |
Â
* @see WP_Stream_Query
|
93 |
Â
* @see https://github.com/wp-stream/stream/wiki/WP-CLI-Command
|
94 |
Â
* @see https://github.com/wp-stream/stream/wiki/Query-Reference
|
95 |
+
*
|
96 |
+
* @param array $args Unused.
|
97 |
+
* @param array $assoc_args Fields to return data for.
|
98 |
Â
*/
|
99 |
Â
public function query( $args, $assoc_args ) {
|
100 |
Â
unset( $args );
|
128 |
Â
|
129 |
Â
$records = wp_stream_get_instance()->db->query( $query_args );
|
130 |
Â
|
131 |
+
// Make structure Formatter compatible.
|
132 |
Â
foreach ( (array) $records as $key => $record ) {
|
133 |
Â
$formatted_records[ $key ] = array();
|
134 |
Â
|
135 |
+
// Catch any fields missing in records.
|
136 |
Â
foreach ( $fields as $field ) {
|
137 |
Â
if ( ! array_key_exists( $field, $record ) ) {
|
138 |
Â
$record->$field = null;
|
159 |
Â
|
160 |
Â
if ( 'json_pretty' === $assoc_args['format'] ) {
|
161 |
Â
if ( version_compare( PHP_VERSION, '5.4', '<' ) ) {
|
162 |
+
\WP_CLI::line( wp_stream_json_encode( $formatted_records ) ); // xss ok.
|
163 |
Â
} else {
|
164 |
+
\WP_CLI::line( wp_stream_json_encode( $formatted_records, JSON_PRETTY_PRINT ) ); // xss ok.
|
165 |
Â
}
|
166 |
Â
}
|
167 |
Â
|
183 |
Â
/**
|
184 |
Â
* Convert any field to a flat array.
|
185 |
Â
*
|
186 |
+
* @param string $name The output array element name.
|
187 |
+
* @param mixed $object Any value to be converted to an array.
|
188 |
Â
*
|
189 |
Â
* @return array The flat array
|
190 |
Â
*/
|
207 |
Â
/**
|
208 |
Â
* Convert an array of flat records to CSV
|
209 |
Â
*
|
210 |
+
* @param array $array The input array of records.
|
Â
|
|
Â
|
|
211 |
Â
*/
|
212 |
Â
private function csv_format( $array ) {
|
213 |
Â
$output = fopen( 'php://output', 'w' ); // @codingStandardsIgnoreLine Clever output for WP CLI using php://output
|
classes/class-connector.php
CHANGED
@@ -1,6 +1,16 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
abstract class Connector {
|
5 |
Â
/**
|
6 |
Â
* Connector slug
|
@@ -63,7 +73,7 @@ abstract class Connector {
|
|
63 |
Â
$action = current_filter();
|
64 |
Â
$callback = array( $this, 'callback_' . preg_replace( '/[^a-z0-9_\-]/', '_', $action ) );
|
65 |
Â
|
66 |
-
// For the sake of testing, trigger an action with the name of the callback
|
67 |
Â
if ( defined( 'WP_STREAM_TESTS' ) && WP_STREAM_TESTS ) {
|
68 |
Â
/**
|
69 |
Â
* Action fires during testing to test the current callback
|
@@ -73,7 +83,7 @@ abstract class Connector {
|
|
73 |
Â
do_action( 'wp_stream_test_' . $callback[1] );
|
74 |
Â
}
|
75 |
Â
|
76 |
-
// Call the real function
|
77 |
Â
if ( is_callable( $callback ) ) {
|
78 |
Â
return call_user_func_array( $callback, func_get_args() );
|
79 |
Â
}
|
@@ -82,8 +92,8 @@ abstract class Connector {
|
|
82 |
Â
/**
|
83 |
Â
* Add action links to Stream drop row in admin list screen
|
84 |
Â
*
|
85 |
-
* @param array $links
|
86 |
-
* @param object $record Stream record
|
87 |
Â
*
|
88 |
Â
* @filter wp_stream_action_links_{connector}
|
89 |
Â
*
|
@@ -97,12 +107,12 @@ abstract class Connector {
|
|
97 |
Â
/**
|
98 |
Â
* Log handler
|
99 |
Â
*
|
100 |
-
* @param string $message
|
101 |
-
* @param array $args
|
102 |
-
* @param int $object_id
|
103 |
-
* @param string $context
|
104 |
-
* @param string $action
|
105 |
-
* @param int $user_id
|
106 |
Â
*
|
107 |
Â
* @return bool
|
108 |
Â
*/
|
@@ -132,7 +142,7 @@ abstract class Connector {
|
|
132 |
Â
/**
|
133 |
Â
* Save log data till shutdown, so other callbacks would be able to override
|
134 |
Â
*
|
135 |
-
* @param string $handle Special slug to be shared with other actions
|
136 |
Â
* @note param mixed $arg1 Extra arguments to sent to log()
|
137 |
Â
* @note param param mixed $arg2, etc..
|
138 |
Â
*/
|
@@ -158,9 +168,9 @@ abstract class Connector {
|
|
158 |
Â
/**
|
159 |
Â
* Compare two values and return changed keys if they are arrays
|
160 |
Â
*
|
161 |
-
* @param mixed $old_value Value before change
|
162 |
-
* @param mixed $new_value Value after change
|
163 |
-
* @param bool|int $deep
|
164 |
Â
*
|
165 |
Â
* @return array
|
166 |
Â
*/
|
@@ -181,21 +191,21 @@ abstract class Connector {
|
|
181 |
Â
$old_value,
|
182 |
Â
$new_value,
|
183 |
Â
function( $value1, $value2 ) {
|
184 |
-
// Compare potentially complex nested arrays
|
185 |
Â
return wp_json_encode( $value1 ) !== wp_json_encode( $value2 );
|
186 |
Â
}
|
187 |
Â
);
|
188 |
Â
|
189 |
Â
$result = array_keys( $diff );
|
190 |
Â
|
191 |
-
//
|
192 |
Â
$common_keys = array_keys( array_intersect_key( $old_value, $new_value ) );
|
193 |
Â
$unique_keys_old = array_values( array_diff( array_keys( $old_value ), $common_keys ) );
|
194 |
Â
$unique_keys_new = array_values( array_diff( array_keys( $new_value ), $common_keys ) );
|
195 |
Â
|
196 |
Â
$result = array_merge( $result, $unique_keys_old, $unique_keys_new );
|
197 |
Â
|
198 |
-
//
|
199 |
Â
$result = array_filter(
|
200 |
Â
$result,
|
201 |
Â
function( $value ) {
|
@@ -209,17 +219,17 @@ abstract class Connector {
|
|
209 |
Â
$result = array_values( array_unique( $result ) );
|
210 |
Â
|
211 |
Â
if ( false === $deep ) {
|
212 |
-
return $result; // Return an numerical based array with changed TOP PARENT keys only
|
213 |
Â
}
|
214 |
Â
|
215 |
Â
$result = array_fill_keys( $result, null );
|
216 |
Â
|
217 |
Â
foreach ( $result as $key => $val ) {
|
218 |
Â
if ( in_array( $key, $unique_keys_old, true ) ) {
|
219 |
-
$result[ $key ] = false; // Removed
|
220 |
Â
} elseif ( in_array( $key, $unique_keys_new, true ) ) {
|
221 |
-
$result[ $key ] = true; // Added
|
222 |
-
} elseif ( $deep ) { // Changed, find what changed, only if we're allowed to explore a new level
|
223 |
Â
if ( is_array( $old_value[ $key ] ) && is_array( $new_value[ $key ] ) ) {
|
224 |
Â
$inner = array();
|
225 |
Â
$parent = $key;
|
@@ -228,7 +238,7 @@ abstract class Connector {
|
|
228 |
Â
foreach ( $changed as $child => $change ) {
|
229 |
Â
$inner[ $parent . '::' . $child ] = $change;
|
230 |
Â
}
|
231 |
-
$result[ $key ] = 0; // Changed parent which has a changed children
|
232 |
Â
$result = array_merge( $result, $inner );
|
233 |
Â
}
|
234 |
Â
}
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Abstract class serving as the parent for all logger classes AKA "Connectors".
|
4 |
+
* Common functionality for registering log events are defined here.
|
5 |
+
*
|
6 |
+
* @package WP_Stream;
|
7 |
+
*/
|
8 |
+
|
9 |
Â
namespace WP_Stream;
|
10 |
Â
|
11 |
+
/**
|
12 |
+
* Class - Connector
|
13 |
+
*/
|
14 |
Â
abstract class Connector {
|
15 |
Â
/**
|
16 |
Â
* Connector slug
|
73 |
Â
$action = current_filter();
|
74 |
Â
$callback = array( $this, 'callback_' . preg_replace( '/[^a-z0-9_\-]/', '_', $action ) );
|
75 |
Â
|
76 |
+
// For the sake of testing, trigger an action with the name of the callback.
|
77 |
Â
if ( defined( 'WP_STREAM_TESTS' ) && WP_STREAM_TESTS ) {
|
78 |
Â
/**
|
79 |
Â
* Action fires during testing to test the current callback
|
83 |
Â
do_action( 'wp_stream_test_' . $callback[1] );
|
84 |
Â
}
|
85 |
Â
|
86 |
+
// Call the real function.
|
87 |
Â
if ( is_callable( $callback ) ) {
|
88 |
Â
return call_user_func_array( $callback, func_get_args() );
|
89 |
Â
}
|
92 |
Â
/**
|
93 |
Â
* Add action links to Stream drop row in admin list screen
|
94 |
Â
*
|
95 |
+
* @param array $links Previous links registered.
|
96 |
+
* @param object $record Stream record.
|
97 |
Â
*
|
98 |
Â
* @filter wp_stream_action_links_{connector}
|
99 |
Â
*
|
107 |
Â
/**
|
108 |
Â
* Log handler
|
109 |
Â
*
|
110 |
+
* @param string $message sprintf-ready error message string.
|
111 |
+
* @param array $args sprintf (and extra) arguments to use.
|
112 |
+
* @param int $object_id Target object id.
|
113 |
+
* @param string $context Context of the event.
|
114 |
+
* @param string $action Action of the event.
|
115 |
+
* @param int $user_id User responsible for the event.
|
116 |
Â
*
|
117 |
Â
* @return bool
|
118 |
Â
*/
|
142 |
Â
/**
|
143 |
Â
* Save log data till shutdown, so other callbacks would be able to override
|
144 |
Â
*
|
145 |
+
* @param string $handle Special slug to be shared with other actions.
|
146 |
Â
* @note param mixed $arg1 Extra arguments to sent to log()
|
147 |
Â
* @note param param mixed $arg2, etc..
|
148 |
Â
*/
|
168 |
Â
/**
|
169 |
Â
* Compare two values and return changed keys if they are arrays
|
170 |
Â
*
|
171 |
+
* @param mixed $old_value Value before change.
|
172 |
+
* @param mixed $new_value Value after change.
|
173 |
+
* @param bool|int $deep Get array children changes keys as well, not just parents.
|
174 |
Â
*
|
175 |
Â
* @return array
|
176 |
Â
*/
|
191 |
Â
$old_value,
|
192 |
Â
$new_value,
|
193 |
Â
function( $value1, $value2 ) {
|
194 |
+
// Compare potentially complex nested arrays.
|
195 |
Â
return wp_json_encode( $value1 ) !== wp_json_encode( $value2 );
|
196 |
Â
}
|
197 |
Â
);
|
198 |
Â
|
199 |
Â
$result = array_keys( $diff );
|
200 |
Â
|
201 |
+
// Find unexisting keys in old or new value.
|
202 |
Â
$common_keys = array_keys( array_intersect_key( $old_value, $new_value ) );
|
203 |
Â
$unique_keys_old = array_values( array_diff( array_keys( $old_value ), $common_keys ) );
|
204 |
Â
$unique_keys_new = array_values( array_diff( array_keys( $new_value ), $common_keys ) );
|
205 |
Â
|
206 |
Â
$result = array_merge( $result, $unique_keys_old, $unique_keys_new );
|
207 |
Â
|
208 |
+
// Remove numeric indexes.
|
209 |
Â
$result = array_filter(
|
210 |
Â
$result,
|
211 |
Â
function( $value ) {
|
219 |
Â
$result = array_values( array_unique( $result ) );
|
220 |
Â
|
221 |
Â
if ( false === $deep ) {
|
222 |
+
return $result; // Return an numerical based array with changed TOP PARENT keys only.
|
223 |
Â
}
|
224 |
Â
|
225 |
Â
$result = array_fill_keys( $result, null );
|
226 |
Â
|
227 |
Â
foreach ( $result as $key => $val ) {
|
228 |
Â
if ( in_array( $key, $unique_keys_old, true ) ) {
|
229 |
+
$result[ $key ] = false; // Removed.
|
230 |
Â
} elseif ( in_array( $key, $unique_keys_new, true ) ) {
|
231 |
+
$result[ $key ] = true; // Added.
|
232 |
+
} elseif ( $deep ) { // Changed, find what changed, only if we're allowed to explore a new level.
|
233 |
Â
if ( is_array( $old_value[ $key ] ) && is_array( $new_value[ $key ] ) ) {
|
234 |
Â
$inner = array();
|
235 |
Â
$parent = $key;
|
238 |
Â
foreach ( $changed as $child => $change ) {
|
239 |
Â
$inner[ $parent . '::' . $child ] = $change;
|
240 |
Â
}
|
241 |
+
$result[ $key ] = 0; // Changed parent which has a changed children.
|
242 |
Â
$result = array_merge( $result, $inner );
|
243 |
Â
}
|
244 |
Â
}
|
classes/class-connectors.php
CHANGED
@@ -1,16 +1,26 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connectors {
|
5 |
Â
/**
|
6 |
-
*
|
7 |
Â
*
|
8 |
Â
* @var Plugin
|
9 |
Â
*/
|
10 |
Â
public $plugin;
|
11 |
Â
|
12 |
Â
/**
|
13 |
-
*
|
14 |
Â
*
|
15 |
Â
* @var array
|
16 |
Â
*/
|
@@ -25,6 +35,7 @@ class Connectors {
|
|
25 |
Â
|
26 |
Â
/**
|
27 |
Â
* Action taxonomy terms
|
Â
|
|
28 |
Â
* Holds slug to localized label association
|
29 |
Â
*
|
30 |
Â
* @var array
|
@@ -45,7 +56,7 @@ class Connectors {
|
|
45 |
Â
/**
|
46 |
Â
* Class constructor.
|
47 |
Â
*
|
48 |
-
* @param Plugin $plugin
|
49 |
Â
*/
|
50 |
Â
public function __construct( $plugin ) {
|
51 |
Â
$this->plugin = $plugin;
|
@@ -57,7 +68,9 @@ class Connectors {
|
|
57 |
Â
*/
|
58 |
Â
public function load_connectors() {
|
59 |
Â
$connectors = array(
|
60 |
-
|
Â
|
|
Â
|
|
61 |
Â
'blogs',
|
62 |
Â
'comments',
|
63 |
Â
'editor',
|
@@ -70,7 +83,9 @@ class Connectors {
|
|
70 |
Â
'users',
|
71 |
Â
'widgets',
|
72 |
Â
|
73 |
-
|
Â
|
|
Â
|
|
74 |
Â
'acf',
|
75 |
Â
'bbpress',
|
76 |
Â
'buddypress',
|
@@ -85,28 +100,36 @@ class Connectors {
|
|
85 |
Â
|
86 |
Â
$classes = array();
|
87 |
Â
foreach ( $connectors as $connector ) {
|
Â
|
|
88 |
Â
include_once $this->plugin->locations['dir'] . '/connectors/class-connector-' . $connector . '.php';
|
Â
|
|
Â
|
|
89 |
Â
$class_name = sprintf( '\WP_Stream\Connector_%s', str_replace( '-', '_', $connector ) );
|
Â
|
|
Â
|
|
90 |
Â
if ( ! class_exists( $class_name ) ) {
|
91 |
Â
continue;
|
92 |
Â
}
|
Â
|
|
Â
|
|
93 |
Â
$class = new $class_name( $this->plugin->log );
|
94 |
Â
|
95 |
-
// Check if the
|
96 |
Â
if ( ! is_subclass_of( $class, 'WP_Stream\Connector' ) ) {
|
97 |
Â
continue;
|
98 |
Â
}
|
99 |
Â
|
100 |
-
// Check if the
|
101 |
Â
if ( is_admin() && ! $class->register_admin ) {
|
102 |
Â
continue;
|
103 |
Â
}
|
104 |
Â
|
105 |
-
// Check if the
|
106 |
Â
if ( ! is_admin() && ! $class->register_frontend ) {
|
107 |
Â
continue;
|
108 |
Â
}
|
109 |
Â
|
Â
|
|
110 |
Â
if ( $class->is_dependency_satisfied() ) {
|
111 |
Â
$classes[ $class->name ] = $class;
|
112 |
Â
}
|
@@ -130,39 +153,41 @@ class Connectors {
|
|
130 |
Â
$this->term_labels['stream_connector'][ $connector->name ] = $connector->get_label();
|
131 |
Â
}
|
132 |
Â
|
133 |
-
// Get excluded connectors
|
134 |
Â
$excluded_connectors = array();
|
135 |
Â
|
136 |
Â
foreach ( $this->connectors as $connector ) {
|
Â
|
|
Â
|
|
137 |
Â
if ( ! method_exists( $connector, 'get_label' ) ) {
|
138 |
-
|
139 |
Â
$this->plugin->admin->notice( sprintf( __( '%s class wasn\'t loaded because it doesn\'t implement the get_label method.', 'stream' ), $connector->name, 'Connector' ), true );
|
140 |
Â
continue;
|
141 |
Â
}
|
142 |
Â
if ( ! method_exists( $connector, 'register' ) ) {
|
143 |
-
|
144 |
Â
$this->plugin->admin->notice( sprintf( __( '%s class wasn\'t loaded because it doesn\'t implement the register method.', 'stream' ), $connector->name, 'Connector' ), true );
|
145 |
Â
continue;
|
146 |
Â
}
|
147 |
Â
if ( ! method_exists( $connector, 'get_context_labels' ) ) {
|
148 |
-
|
149 |
Â
$this->plugin->admin->notice( sprintf( __( '%s class wasn\'t loaded because it doesn\'t implement the get_context_labels method.', 'stream' ), $connector->name, 'Connector' ), true );
|
150 |
Â
continue;
|
151 |
Â
}
|
152 |
Â
if ( ! method_exists( $connector, 'get_action_labels' ) ) {
|
153 |
-
|
154 |
Â
$this->plugin->admin->notice( sprintf( __( '%s class wasn\'t loaded because it doesn\'t implement the get_action_labels method.', 'stream' ), $connector->name, 'Connector' ), true );
|
155 |
Â
continue;
|
156 |
Â
}
|
157 |
Â
|
158 |
Â
// Check if the connectors extends the Connector class, if not skip it.
|
159 |
Â
if ( ! is_subclass_of( $connector, '\WP_Stream\Connector' ) ) {
|
160 |
-
|
161 |
Â
$this->plugin->admin->notice( sprintf( __( '%1$s class wasn\'t loaded because it doesn\'t extends the %2$s class.', 'stream' ), $connector->name, 'Connector' ), true );
|
162 |
Â
continue;
|
163 |
Â
}
|
164 |
Â
|
165 |
-
// Store connector label
|
166 |
Â
if ( ! in_array( $connector->name, $this->term_labels['stream_connector'], true ) ) {
|
167 |
Â
$this->term_labels['stream_connector'][ $connector->name ] = $connector->get_label();
|
168 |
Â
}
|
@@ -185,10 +210,10 @@ class Connectors {
|
|
185 |
Â
|
186 |
Â
$connector->register();
|
187 |
Â
|
188 |
-
// Link context labels to their connector
|
189 |
Â
$this->contexts[ $connector->name ] = $connector->get_context_labels();
|
190 |
Â
|
191 |
-
// Add new terms to our label lookup array
|
192 |
Â
$this->term_labels['stream_action'] = array_merge(
|
193 |
Â
$this->term_labels['stream_action'],
|
194 |
Â
$connector->get_action_labels()
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Validates and loads core connectors, integrated connectors, and
|
4 |
+
* connectors registered using the "wp_stream_connectors" hook.
|
5 |
+
*
|
6 |
+
* @package WP_Stream
|
7 |
+
*/
|
8 |
+
|
9 |
Â
namespace WP_Stream;
|
10 |
Â
|
11 |
+
/**
|
12 |
+
* Class - Connectors
|
13 |
+
*/
|
14 |
Â
class Connectors {
|
15 |
Â
/**
|
16 |
+
* Holds instance of plugin object
|
17 |
Â
*
|
18 |
Â
* @var Plugin
|
19 |
Â
*/
|
20 |
Â
public $plugin;
|
21 |
Â
|
22 |
Â
/**
|
23 |
+
* Registered connectors.
|
24 |
Â
*
|
25 |
Â
* @var array
|
26 |
Â
*/
|
35 |
Â
|
36 |
Â
/**
|
37 |
Â
* Action taxonomy terms
|
38 |
+
*
|
39 |
Â
* Holds slug to localized label association
|
40 |
Â
*
|
41 |
Â
* @var array
|
56 |
Â
/**
|
57 |
Â
* Class constructor.
|
58 |
Â
*
|
59 |
+
* @param Plugin $plugin Instance of plugin object.
|
60 |
Â
*/
|
61 |
Â
public function __construct( $plugin ) {
|
62 |
Â
$this->plugin = $plugin;
|
68 |
Â
*/
|
69 |
Â
public function load_connectors() {
|
70 |
Â
$connectors = array(
|
71 |
+
/**
|
72 |
+
* Core Connectors
|
73 |
+
*/
|
74 |
Â
'blogs',
|
75 |
Â
'comments',
|
76 |
Â
'editor',
|
83 |
Â
'users',
|
84 |
Â
'widgets',
|
85 |
Â
|
86 |
+
/**
|
87 |
+
* Integrated Connectors
|
88 |
+
*/
|
89 |
Â
'acf',
|
90 |
Â
'bbpress',
|
91 |
Â
'buddypress',
|
100 |
Â
|
101 |
Â
$classes = array();
|
102 |
Â
foreach ( $connectors as $connector ) {
|
103 |
+
// Load connector class file.
|
104 |
Â
include_once $this->plugin->locations['dir'] . '/connectors/class-connector-' . $connector . '.php';
|
105 |
+
|
106 |
+
// Set fully qualified class name.
|
107 |
Â
$class_name = sprintf( '\WP_Stream\Connector_%s', str_replace( '-', '_', $connector ) );
|
108 |
+
|
109 |
+
// Bail if no class loaded.
|
110 |
Â
if ( ! class_exists( $class_name ) ) {
|
111 |
Â
continue;
|
112 |
Â
}
|
113 |
+
|
114 |
+
// Initialize connector.
|
115 |
Â
$class = new $class_name( $this->plugin->log );
|
116 |
Â
|
117 |
+
// Check if the connector class extends WP_Stream\Connector.
|
118 |
Â
if ( ! is_subclass_of( $class, 'WP_Stream\Connector' ) ) {
|
119 |
Â
continue;
|
120 |
Â
}
|
121 |
Â
|
122 |
+
// Check if the connector events are allowed to be registered in the WP Admin.
|
123 |
Â
if ( is_admin() && ! $class->register_admin ) {
|
124 |
Â
continue;
|
125 |
Â
}
|
126 |
Â
|
127 |
+
// Check if the connector events are allowed to be registered in the WP Frontend.
|
128 |
Â
if ( ! is_admin() && ! $class->register_frontend ) {
|
129 |
Â
continue;
|
130 |
Â
}
|
131 |
Â
|
132 |
+
// Run any final validations the connector may have before used.
|
133 |
Â
if ( $class->is_dependency_satisfied() ) {
|
134 |
Â
$classes[ $class->name ] = $class;
|
135 |
Â
}
|
153 |
Â
$this->term_labels['stream_connector'][ $connector->name ] = $connector->get_label();
|
154 |
Â
}
|
155 |
Â
|
156 |
+
// Get excluded connectors.
|
157 |
Â
$excluded_connectors = array();
|
158 |
Â
|
159 |
Â
foreach ( $this->connectors as $connector ) {
|
160 |
+
|
161 |
+
// Register error for invalid any connector class.
|
162 |
Â
if ( ! method_exists( $connector, 'get_label' ) ) {
|
163 |
+
/* translators: %s: connector class name, intended to provide help to developers (e.g. "Connector_BuddyPress") */
|
164 |
Â
$this->plugin->admin->notice( sprintf( __( '%s class wasn\'t loaded because it doesn\'t implement the get_label method.', 'stream' ), $connector->name, 'Connector' ), true );
|
165 |
Â
continue;
|
166 |
Â
}
|
167 |
Â
if ( ! method_exists( $connector, 'register' ) ) {
|
168 |
+
/* translators: %s: connector class name, intended to provide help to developers (e.g. "Connector_BuddyPress") */
|
169 |
Â
$this->plugin->admin->notice( sprintf( __( '%s class wasn\'t loaded because it doesn\'t implement the register method.', 'stream' ), $connector->name, 'Connector' ), true );
|
170 |
Â
continue;
|
171 |
Â
}
|
172 |
Â
if ( ! method_exists( $connector, 'get_context_labels' ) ) {
|
173 |
+
/* translators: %s: connector class name, intended to provide help to developers (e.g. "Connector_BuddyPress") */
|
174 |
Â
$this->plugin->admin->notice( sprintf( __( '%s class wasn\'t loaded because it doesn\'t implement the get_context_labels method.', 'stream' ), $connector->name, 'Connector' ), true );
|
175 |
Â
continue;
|
176 |
Â
}
|
177 |
Â
if ( ! method_exists( $connector, 'get_action_labels' ) ) {
|
178 |
+
/* translators: %s: connector class name, intended to provide help to developers (e.g. "Connector_BuddyPress") */
|
179 |
Â
$this->plugin->admin->notice( sprintf( __( '%s class wasn\'t loaded because it doesn\'t implement the get_action_labels method.', 'stream' ), $connector->name, 'Connector' ), true );
|
180 |
Â
continue;
|
181 |
Â
}
|
182 |
Â
|
183 |
Â
// Check if the connectors extends the Connector class, if not skip it.
|
184 |
Â
if ( ! is_subclass_of( $connector, '\WP_Stream\Connector' ) ) {
|
185 |
+
/* translators: %s: connector class name, intended to provide help to developers (e.g. "Connector_BuddyPress") */
|
186 |
Â
$this->plugin->admin->notice( sprintf( __( '%1$s class wasn\'t loaded because it doesn\'t extends the %2$s class.', 'stream' ), $connector->name, 'Connector' ), true );
|
187 |
Â
continue;
|
188 |
Â
}
|
189 |
Â
|
190 |
+
// Store connector label.
|
191 |
Â
if ( ! in_array( $connector->name, $this->term_labels['stream_connector'], true ) ) {
|
192 |
Â
$this->term_labels['stream_connector'][ $connector->name ] = $connector->get_label();
|
193 |
Â
}
|
210 |
Â
|
211 |
Â
$connector->register();
|
212 |
Â
|
213 |
+
// Link context labels to their connector.
|
214 |
Â
$this->contexts[ $connector->name ] = $connector->get_context_labels();
|
215 |
Â
|
216 |
+
// Add new terms to our label lookup array.
|
217 |
Â
$this->term_labels['stream_action'] = array_merge(
|
218 |
Â
$this->term_labels['stream_action'],
|
219 |
Â
$connector->get_action_labels()
|
classes/class-date-interval.php
CHANGED
@@ -1,13 +1,21 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
4 |
-
// Load Carbon to Handle dates much easier
|
5 |
Â
if ( ! class_exists( 'Carbon\Carbon' ) ) {
|
6 |
Â
require_once wp_stream_get_instance()->locations['inc_dir'] . 'lib/Carbon.php';
|
7 |
Â
}
|
8 |
-
|
9 |
Â
use Carbon\Carbon;
|
10 |
Â
|
Â
|
|
Â
|
|
Â
|
|
11 |
Â
class Date_Interval {
|
12 |
Â
/**
|
13 |
Â
* Contains an array of all available intervals
|
@@ -20,11 +28,14 @@ class Date_Interval {
|
|
20 |
Â
* Class constructor
|
21 |
Â
*/
|
22 |
Â
public function __construct() {
|
23 |
-
// Get all default intervals
|
24 |
Â
$this->intervals = $this->get_predefined_intervals();
|
25 |
Â
}
|
26 |
Â
|
27 |
Â
/**
|
Â
|
|
Â
|
|
Â
|
|
28 |
Â
* @return mixed
|
29 |
Â
*/
|
30 |
Â
public function get_predefined_intervals() {
|
@@ -55,19 +66,19 @@ class Date_Interval {
|
|
55 |
Â
'end' => Carbon::today( $timezone )->startOfDay()->subSecond(),
|
56 |
Â
),
|
57 |
Â
'last-7-days' => array(
|
58 |
-
|
59 |
Â
'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 7 ),
|
60 |
Â
'start' => Carbon::today( $timezone )->subDays( 7 ),
|
61 |
Â
'end' => Carbon::today( $timezone ),
|
62 |
Â
),
|
63 |
Â
'last-14-days' => array(
|
64 |
-
|
65 |
Â
'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 14 ),
|
66 |
Â
'start' => Carbon::today( $timezone )->subDays( 14 ),
|
67 |
Â
'end' => Carbon::today( $timezone ),
|
68 |
Â
),
|
69 |
Â
'last-30-days' => array(
|
70 |
-
|
71 |
Â
'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 30 ),
|
72 |
Â
'start' => Carbon::today( $timezone )->subDays( 30 ),
|
73 |
Â
'end' => Carbon::today( $timezone ),
|
@@ -83,19 +94,19 @@ class Date_Interval {
|
|
83 |
Â
'end' => Carbon::today( $timezone )->startOfMonth()->subSecond(),
|
84 |
Â
),
|
85 |
Â
'last-3-months' => array(
|
86 |
-
|
87 |
Â
'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 3 ),
|
88 |
Â
'start' => Carbon::today( $timezone )->subMonths( 3 ),
|
89 |
Â
'end' => Carbon::today( $timezone ),
|
90 |
Â
),
|
91 |
Â
'last-6-months' => array(
|
92 |
-
|
93 |
Â
'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 6 ),
|
94 |
Â
'start' => Carbon::today( $timezone )->subMonths( 6 ),
|
95 |
Â
'end' => Carbon::today( $timezone ),
|
96 |
Â
),
|
97 |
Â
'last-12-months' => array(
|
98 |
-
|
99 |
Â
'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 12 ),
|
100 |
Â
'start' => Carbon::today( $timezone )->subMonths( 12 ),
|
101 |
Â
'end' => Carbon::today( $timezone ),
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Calculate date intervals for a specific timezone.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
// Load Carbon to Handle dates much easier.
|
11 |
Â
if ( ! class_exists( 'Carbon\Carbon' ) ) {
|
12 |
Â
require_once wp_stream_get_instance()->locations['inc_dir'] . 'lib/Carbon.php';
|
13 |
Â
}
|
Â
|
|
14 |
Â
use Carbon\Carbon;
|
15 |
Â
|
16 |
+
/**
|
17 |
+
* Class - Date_Interval
|
18 |
+
*/
|
19 |
Â
class Date_Interval {
|
20 |
Â
/**
|
21 |
Â
* Contains an array of all available intervals
|
28 |
Â
* Class constructor
|
29 |
Â
*/
|
30 |
Â
public function __construct() {
|
31 |
+
// Get all default intervals.
|
32 |
Â
$this->intervals = $this->get_predefined_intervals();
|
33 |
Â
}
|
34 |
Â
|
35 |
Â
/**
|
36 |
+
* Returns date interval data based upon "Timezone" site setting.
|
37 |
+
*
|
38 |
+
* @todo add better inline comments
|
39 |
Â
* @return mixed
|
40 |
Â
*/
|
41 |
Â
public function get_predefined_intervals() {
|
66 |
Â
'end' => Carbon::today( $timezone )->startOfDay()->subSecond(),
|
67 |
Â
),
|
68 |
Â
'last-7-days' => array(
|
69 |
+
/* translators: %d: number of days (e.g. "7") */
|
70 |
Â
'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 7 ),
|
71 |
Â
'start' => Carbon::today( $timezone )->subDays( 7 ),
|
72 |
Â
'end' => Carbon::today( $timezone ),
|
73 |
Â
),
|
74 |
Â
'last-14-days' => array(
|
75 |
+
/* translators: %d: number of days (e.g. "7") */
|
76 |
Â
'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 14 ),
|
77 |
Â
'start' => Carbon::today( $timezone )->subDays( 14 ),
|
78 |
Â
'end' => Carbon::today( $timezone ),
|
79 |
Â
),
|
80 |
Â
'last-30-days' => array(
|
81 |
+
/* translators: %d: number of days (e.g. "7") */
|
82 |
Â
'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 30 ),
|
83 |
Â
'start' => Carbon::today( $timezone )->subDays( 30 ),
|
84 |
Â
'end' => Carbon::today( $timezone ),
|
94 |
Â
'end' => Carbon::today( $timezone )->startOfMonth()->subSecond(),
|
95 |
Â
),
|
96 |
Â
'last-3-months' => array(
|
97 |
+
/* translators: %d: number of months (e.g. "3") */
|
98 |
Â
'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 3 ),
|
99 |
Â
'start' => Carbon::today( $timezone )->subMonths( 3 ),
|
100 |
Â
'end' => Carbon::today( $timezone ),
|
101 |
Â
),
|
102 |
Â
'last-6-months' => array(
|
103 |
+
/* translators: %d: number of months (e.g. "3") */
|
104 |
Â
'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 6 ),
|
105 |
Â
'start' => Carbon::today( $timezone )->subMonths( 6 ),
|
106 |
Â
'end' => Carbon::today( $timezone ),
|
107 |
Â
),
|
108 |
Â
'last-12-months' => array(
|
109 |
+
/* translators: %d: number of months (e.g. "3") */
|
110 |
Â
'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 12 ),
|
111 |
Â
'start' => Carbon::today( $timezone )->subMonths( 12 ),
|
112 |
Â
'end' => Carbon::today( $timezone ),
|
classes/class-db-driver-wpdb.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class DB_Driver_WPDB implements DB_Driver {
|
5 |
Â
/**
|
6 |
Â
* Holds Query class
|
@@ -38,7 +47,7 @@ class DB_Driver_WPDB implements DB_Driver {
|
|
38 |
Â
$wpdb->stream = $this->table;
|
39 |
Â
$wpdb->streammeta = $this->table_meta;
|
40 |
Â
|
41 |
-
// Hack for get_metadata
|
42 |
Â
$wpdb->recordmeta = $this->table_meta;
|
43 |
Â
}
|
44 |
Â
|
@@ -66,7 +75,7 @@ class DB_Driver_WPDB implements DB_Driver {
|
|
66 |
Â
|
67 |
Â
$record_id = $wpdb->insert_id;
|
68 |
Â
|
69 |
-
// Insert record meta
|
70 |
Â
foreach ( (array) $meta as $key => $vals ) {
|
71 |
Â
foreach ( (array) $vals as $val ) {
|
72 |
Â
$this->insert_meta( $record_id, $key, $val );
|
@@ -79,9 +88,9 @@ class DB_Driver_WPDB implements DB_Driver {
|
|
79 |
Â
/**
|
80 |
Â
* Insert record meta
|
81 |
Â
*
|
82 |
-
* @param int $record_id
|
83 |
-
* @param string $key
|
84 |
-
* @param string $val
|
85 |
Â
*
|
86 |
Â
* @return array
|
87 |
Â
*/
|
@@ -103,7 +112,7 @@ class DB_Driver_WPDB implements DB_Driver {
|
|
103 |
Â
/**
|
104 |
Â
* Retrieve records
|
105 |
Â
*
|
106 |
-
* @param array $args
|
107 |
Â
*
|
108 |
Â
* @return array
|
109 |
Â
*/
|
@@ -118,7 +127,7 @@ class DB_Driver_WPDB implements DB_Driver {
|
|
118 |
Â
* GROUP BY allows query to find just the first occurrence of each value in the column,
|
119 |
Â
* increasing the efficiency of the query.
|
120 |
Â
*
|
121 |
-
* @param string $column
|
122 |
Â
*
|
123 |
Â
* @return array
|
124 |
Â
*/
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Database Driver class for "stream" table responsible for holding records.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - DB_Driver_WPDB
|
12 |
+
*/
|
13 |
Â
class DB_Driver_WPDB implements DB_Driver {
|
14 |
Â
/**
|
15 |
Â
* Holds Query class
|
47 |
Â
$wpdb->stream = $this->table;
|
48 |
Â
$wpdb->streammeta = $this->table_meta;
|
49 |
Â
|
50 |
+
// Hack for get_metadata.
|
51 |
Â
$wpdb->recordmeta = $this->table_meta;
|
52 |
Â
}
|
53 |
Â
|
75 |
Â
|
76 |
Â
$record_id = $wpdb->insert_id;
|
77 |
Â
|
78 |
+
// Insert record meta.
|
79 |
Â
foreach ( (array) $meta as $key => $vals ) {
|
80 |
Â
foreach ( (array) $vals as $val ) {
|
81 |
Â
$this->insert_meta( $record_id, $key, $val );
|
88 |
Â
/**
|
89 |
Â
* Insert record meta
|
90 |
Â
*
|
91 |
+
* @param int $record_id Record ID.
|
92 |
+
* @param string $key Meta Key.
|
93 |
+
* @param string $val Meta Data.
|
94 |
Â
*
|
95 |
Â
* @return array
|
96 |
Â
*/
|
112 |
Â
/**
|
113 |
Â
* Retrieve records
|
114 |
Â
*
|
115 |
+
* @param array $args Query arguments.
|
116 |
Â
*
|
117 |
Â
* @return array
|
118 |
Â
*/
|
127 |
Â
* GROUP BY allows query to find just the first occurrence of each value in the column,
|
128 |
Â
* increasing the efficiency of the query.
|
129 |
Â
*
|
130 |
+
* @param string $column Column being filtered.
|
131 |
Â
*
|
132 |
Â
* @return array
|
133 |
Â
*/
|
classes/class-db-driver.php
CHANGED
@@ -1,11 +1,21 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
interface DB_Driver {
|
5 |
Â
/**
|
6 |
Â
* Insert a record
|
7 |
Â
*
|
8 |
-
* @param array $data
|
9 |
Â
*
|
10 |
Â
* @return int
|
11 |
Â
*/
|
@@ -14,7 +24,7 @@ interface DB_Driver {
|
|
14 |
Â
/**
|
15 |
Â
* Retrieve records
|
16 |
Â
*
|
17 |
-
* @param array $args
|
18 |
Â
*
|
19 |
Â
* @return array
|
20 |
Â
*/
|
@@ -24,14 +34,14 @@ interface DB_Driver {
|
|
24 |
Â
* Returns array of existing values for requested column.
|
25 |
Â
* Used to fill search filters with only used items, instead of all items.
|
26 |
Â
*
|
27 |
-
* @param string $column
|
28 |
Â
*
|
29 |
Â
* @return array
|
30 |
Â
*/
|
31 |
Â
public function get_column_values( $column );
|
32 |
Â
|
33 |
Â
/**
|
34 |
-
* Public getter to return
|
35 |
Â
*
|
36 |
Â
* @return array
|
37 |
Â
*/
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Interface for a Database Driver.
|
4 |
+
*
|
5 |
+
* @todo Review. Heavy refactor maybe needed.
|
6 |
+
* @package WP_Stream
|
7 |
+
*/
|
8 |
+
|
9 |
Â
namespace WP_Stream;
|
10 |
Â
|
11 |
+
/**
|
12 |
+
* Interface - DB_Driver
|
13 |
+
*/
|
14 |
Â
interface DB_Driver {
|
15 |
Â
/**
|
16 |
Â
* Insert a record
|
17 |
Â
*
|
18 |
+
* @param array $data Data to be insert into the database.
|
19 |
Â
*
|
20 |
Â
* @return int
|
21 |
Â
*/
|
24 |
Â
/**
|
25 |
Â
* Retrieve records
|
26 |
Â
*
|
27 |
+
* @param array $args Argument to filter the result by.
|
28 |
Â
*
|
29 |
Â
* @return array
|
30 |
Â
*/
|
34 |
Â
* Returns array of existing values for requested column.
|
35 |
Â
* Used to fill search filters with only used items, instead of all items.
|
36 |
Â
*
|
37 |
+
* @param string $column Column to pull data from.
|
38 |
Â
*
|
39 |
Â
* @return array
|
40 |
Â
*/
|
41 |
Â
public function get_column_values( $column );
|
42 |
Â
|
43 |
Â
/**
|
44 |
+
* Public getter to return the names of the tables this driver manages.
|
45 |
Â
*
|
46 |
Â
* @return array
|
47 |
Â
*/
|
classes/class-db.php
CHANGED
@@ -1,9 +1,18 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class DB {
|
5 |
Â
/**
|
6 |
-
*
|
7 |
Â
*
|
8 |
Â
* @var DB_Driver
|
9 |
Â
*/
|
@@ -28,7 +37,7 @@ class DB {
|
|
28 |
Â
/**
|
29 |
Â
* Insert a record
|
30 |
Â
*
|
31 |
-
* @param array $record
|
32 |
Â
*
|
33 |
Â
* @return int
|
34 |
Â
*/
|
@@ -50,7 +59,7 @@ class DB {
|
|
50 |
Â
$record,
|
51 |
Â
function( &$value, &$key ) {
|
52 |
Â
if ( ! is_array( $value ) ) {
|
53 |
-
$value =
|
54 |
Â
}
|
55 |
Â
}
|
56 |
Â
);
|
@@ -97,12 +106,12 @@ class DB {
|
|
97 |
Â
* @see assemble_records
|
98 |
Â
* @since 1.0.4
|
99 |
Â
*
|
100 |
-
* @param string $column
|
101 |
Â
*
|
102 |
Â
* @return array
|
103 |
Â
*/
|
104 |
Â
public function existing_records( $column ) {
|
105 |
-
// Sanitize column
|
106 |
Â
$allowed_columns = array( 'ID', 'site_id', 'blog_id', 'object_id', 'user_id', 'user_role', 'created', 'summary', 'connector', 'context', 'action', 'ip' );
|
107 |
Â
if ( ! in_array( $column, $allowed_columns, true ) ) {
|
108 |
Â
return array();
|
@@ -131,37 +140,37 @@ class DB {
|
|
131 |
Â
/**
|
132 |
Â
* Get stream records
|
133 |
Â
*
|
134 |
-
* @param array
|
135 |
Â
*
|
136 |
Â
* @return array Stream Records
|
137 |
Â
*/
|
138 |
Â
public function get_records( $args ) {
|
139 |
Â
$defaults = array(
|
140 |
-
// Search param
|
141 |
Â
'search' => null,
|
142 |
Â
'search_field' => 'summary',
|
143 |
Â
'record_after' => null, // Deprecated, use date_after instead
|
144 |
-
// Date-based filters
|
145 |
-
'date' => null, // Ex: 2015-07-01
|
146 |
-
'date_from' => null, // Ex: 2015-07-01
|
147 |
-
'date_to' => null, // Ex: 2015-07-01
|
148 |
-
'date_after' => null, // Ex: 2015-07-01T15:19:21+00:00
|
149 |
-
'date_before' => null, // Ex: 2015-07-01T15:19:21+00:00
|
150 |
-
// Record ID filters
|
151 |
Â
'record' => null,
|
152 |
Â
'record__in' => array(),
|
153 |
Â
'record__not_in' => array(),
|
154 |
-
// Pagination params
|
155 |
Â
'records_per_page' => get_option( 'posts_per_page', 20 ),
|
156 |
Â
'paged' => 1,
|
157 |
-
// Order
|
158 |
Â
'order' => 'desc',
|
159 |
Â
'orderby' => 'date',
|
160 |
-
// Fields selection
|
161 |
Â
'fields' => array(),
|
162 |
Â
);
|
163 |
Â
|
164 |
-
// Additional property fields
|
165 |
Â
$properties = array(
|
166 |
Â
'user_id' => null,
|
167 |
Â
'user_role' => null,
|
@@ -181,7 +190,7 @@ class DB {
|
|
181 |
Â
*/
|
182 |
Â
$properties = apply_filters( 'wp_stream_query_properties', $properties );
|
183 |
Â
|
184 |
-
// Add property fields to defaults, including their __in/__not_in variations
|
185 |
Â
foreach ( $properties as $property => $default ) {
|
186 |
Â
if ( ! isset( $defaults[ $property ] ) ) {
|
187 |
Â
$defaults[ $property ] = $default;
|
@@ -209,7 +218,7 @@ class DB {
|
|
209 |
Â
/**
|
210 |
Â
* Helper function, backwards compatibility
|
211 |
Â
*
|
212 |
-
* @param array $args
|
213 |
Â
*
|
214 |
Â
* @return array Stream Records
|
215 |
Â
*/
|
@@ -220,7 +229,7 @@ class DB {
|
|
220 |
Â
/**
|
221 |
Â
* Return the number of records found in last request
|
222 |
Â
*
|
223 |
-
* return int
|
224 |
Â
*/
|
225 |
Â
public function get_found_records_count() {
|
226 |
Â
return $this->found_records_count;
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Manage DB connections using a provided DB driver.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - DB
|
12 |
+
*/
|
13 |
Â
class DB {
|
14 |
Â
/**
|
15 |
+
* Holds the driver instance
|
16 |
Â
*
|
17 |
Â
* @var DB_Driver
|
18 |
Â
*/
|
37 |
Â
/**
|
38 |
Â
* Insert a record
|
39 |
Â
*
|
40 |
+
* @param array $record New record.
|
41 |
Â
*
|
42 |
Â
* @return int
|
43 |
Â
*/
|
59 |
Â
$record,
|
60 |
Â
function( &$value, &$key ) {
|
61 |
Â
if ( ! is_array( $value ) ) {
|
62 |
+
$value = wp_strip_all_tags( $value );
|
63 |
Â
}
|
64 |
Â
}
|
65 |
Â
);
|
106 |
Â
* @see assemble_records
|
107 |
Â
* @since 1.0.4
|
108 |
Â
*
|
109 |
+
* @param string $column Table column to pull data from.
|
110 |
Â
*
|
111 |
Â
* @return array
|
112 |
Â
*/
|
113 |
Â
public function existing_records( $column ) {
|
114 |
+
// Sanitize column.
|
115 |
Â
$allowed_columns = array( 'ID', 'site_id', 'blog_id', 'object_id', 'user_id', 'user_role', 'created', 'summary', 'connector', 'context', 'action', 'ip' );
|
116 |
Â
if ( ! in_array( $column, $allowed_columns, true ) ) {
|
117 |
Â
return array();
|
140 |
Â
/**
|
141 |
Â
* Get stream records
|
142 |
Â
*
|
143 |
+
* @param array $args Arguments to filter result by.
|
144 |
Â
*
|
145 |
Â
* @return array Stream Records
|
146 |
Â
*/
|
147 |
Â
public function get_records( $args ) {
|
148 |
Â
$defaults = array(
|
149 |
+
// Search param.
|
150 |
Â
'search' => null,
|
151 |
Â
'search_field' => 'summary',
|
152 |
Â
'record_after' => null, // Deprecated, use date_after instead
|
153 |
+
// Date-based filters.
|
154 |
+
'date' => null, // Ex: 2015-07-01.
|
155 |
+
'date_from' => null, // Ex: 2015-07-01.
|
156 |
+
'date_to' => null, // Ex: 2015-07-01.
|
157 |
+
'date_after' => null, // Ex: 2015-07-01T15:19:21+00:00.
|
158 |
+
'date_before' => null, // Ex: 2015-07-01T15:19:21+00:00.
|
159 |
+
// Record ID filters.
|
160 |
Â
'record' => null,
|
161 |
Â
'record__in' => array(),
|
162 |
Â
'record__not_in' => array(),
|
163 |
+
// Pagination params.
|
164 |
Â
'records_per_page' => get_option( 'posts_per_page', 20 ),
|
165 |
Â
'paged' => 1,
|
166 |
+
// Order.
|
167 |
Â
'order' => 'desc',
|
168 |
Â
'orderby' => 'date',
|
169 |
+
// Fields selection.
|
170 |
Â
'fields' => array(),
|
171 |
Â
);
|
172 |
Â
|
173 |
+
// Additional property fields.
|
174 |
Â
$properties = array(
|
175 |
Â
'user_id' => null,
|
176 |
Â
'user_role' => null,
|
190 |
Â
*/
|
191 |
Â
$properties = apply_filters( 'wp_stream_query_properties', $properties );
|
192 |
Â
|
193 |
+
// Add property fields to defaults, including their __in/__not_in variations.
|
194 |
Â
foreach ( $properties as $property => $default ) {
|
195 |
Â
if ( ! isset( $defaults[ $property ] ) ) {
|
196 |
Â
$defaults[ $property ] = $default;
|
218 |
Â
/**
|
219 |
Â
* Helper function, backwards compatibility
|
220 |
Â
*
|
221 |
+
* @param array $args Argument to filter result by.
|
222 |
Â
*
|
223 |
Â
* @return array Stream Records
|
224 |
Â
*/
|
229 |
Â
/**
|
230 |
Â
* Return the number of records found in last request
|
231 |
Â
*
|
232 |
+
* @return int
|
233 |
Â
*/
|
234 |
Â
public function get_found_records_count() {
|
235 |
Â
return $this->found_records_count;
|
classes/class-export.php
CHANGED
@@ -1,9 +1,18 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Export {
|
5 |
Â
/**
|
6 |
-
*
|
7 |
Â
*
|
8 |
Â
* @var Plugin
|
9 |
Â
*/
|
@@ -73,12 +82,14 @@ class Export {
|
|
73 |
Â
/**
|
74 |
Â
* Add Export options to record actions menu
|
75 |
Â
*
|
Â
|
|
Â
|
|
76 |
Â
* @return array
|
77 |
Â
*/
|
78 |
Â
public function actions_menu_export_items( $action_menu_items ) {
|
79 |
Â
foreach ( $this->get_exporters() as $exporter ) {
|
80 |
Â
$action = 'export-' . $exporter->slug;
|
81 |
-
|
82 |
Â
$action_menu_items[ $action ] = sprintf( __( 'Export as %s', 'stream' ), $exporter->name );
|
83 |
Â
}
|
84 |
Â
|
@@ -99,7 +110,7 @@ class Export {
|
|
99 |
Â
foreach ( array_keys( $columns ) as $column_name ) {
|
100 |
Â
switch ( $column_name ) {
|
101 |
Â
case 'date':
|
102 |
-
$created =
|
103 |
Â
$row_out[ $column_name ] = get_date_from_gmt( $created, 'Y/m/d h:i:s A' );
|
104 |
Â
break;
|
105 |
Â
|
@@ -203,7 +214,7 @@ class Export {
|
|
203 |
Â
*/
|
204 |
Â
$this->exporters = apply_filters( 'wp_stream_exporters', $classes );
|
205 |
Â
|
206 |
-
// Ensure that all exporters extend Exporter
|
207 |
Â
foreach ( $this->exporters as $key => $exporter ) {
|
208 |
Â
if ( ! $this->is_valid_exporter( $exporter ) ) {
|
209 |
Â
unset( $this->exporters[ $key ] );
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Loads & Manages exporter classes.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Export
|
12 |
+
*/
|
13 |
Â
class Export {
|
14 |
Â
/**
|
15 |
+
* Holds instance of plugin object
|
16 |
Â
*
|
17 |
Â
* @var Plugin
|
18 |
Â
*/
|
82 |
Â
/**
|
83 |
Â
* Add Export options to record actions menu
|
84 |
Â
*
|
85 |
+
* @param array $action_menu_items Export types.
|
86 |
+
*
|
87 |
Â
* @return array
|
88 |
Â
*/
|
89 |
Â
public function actions_menu_export_items( $action_menu_items ) {
|
90 |
Â
foreach ( $this->get_exporters() as $exporter ) {
|
91 |
Â
$action = 'export-' . $exporter->slug;
|
92 |
+
/* translators: %s: an export format (e.g. "CSV") */
|
93 |
Â
$action_menu_items[ $action ] = sprintf( __( 'Export as %s', 'stream' ), $exporter->name );
|
94 |
Â
}
|
95 |
Â
|
110 |
Â
foreach ( array_keys( $columns ) as $column_name ) {
|
111 |
Â
switch ( $column_name ) {
|
112 |
Â
case 'date':
|
113 |
+
$created = gmdate( 'Y-m-d H:i:s', strtotime( $record->created ) );
|
114 |
Â
$row_out[ $column_name ] = get_date_from_gmt( $created, 'Y/m/d h:i:s A' );
|
115 |
Â
break;
|
116 |
Â
|
214 |
Â
*/
|
215 |
Â
$this->exporters = apply_filters( 'wp_stream_exporters', $classes );
|
216 |
Â
|
217 |
+
// Ensure that all exporters extend Exporter.
|
218 |
Â
foreach ( $this->exporters as $key => $exporter ) {
|
219 |
Â
if ( ! $this->is_valid_exporter( $exporter ) ) {
|
220 |
Â
unset( $this->exporters[ $key ] );
|
classes/class-exporter.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
abstract class Exporter {
|
5 |
Â
/**
|
6 |
Â
* Exporter name
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Abstract class for record exporters
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Exporter
|
12 |
+
*/
|
13 |
Â
abstract class Exporter {
|
14 |
Â
/**
|
15 |
Â
* Exporter name
|
classes/class-filter-input.php
CHANGED
@@ -1,10 +1,25 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Filter_Input {
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
5 |
Â
public static $filter_callbacks = array(
|
6 |
Â
FILTER_DEFAULT => null,
|
7 |
-
// Validate
|
8 |
Â
FILTER_VALIDATE_BOOLEAN => 'is_bool',
|
9 |
Â
FILTER_VALIDATE_EMAIL => 'is_email',
|
10 |
Â
FILTER_VALIDATE_FLOAT => 'is_float',
|
@@ -12,7 +27,7 @@ class Filter_Input {
|
|
12 |
Â
FILTER_VALIDATE_IP => array( __CLASS__, 'is_ip_address' ),
|
13 |
Â
FILTER_VALIDATE_REGEXP => array( __CLASS__, 'is_regex' ),
|
14 |
Â
FILTER_VALIDATE_URL => 'wp_http_validate_url',
|
15 |
-
// Sanitize
|
16 |
Â
FILTER_SANITIZE_EMAIL => 'sanitize_email',
|
17 |
Â
FILTER_SANITIZE_ENCODED => 'esc_url_raw',
|
18 |
Â
FILTER_SANITIZE_NUMBER_FLOAT => 'floatval',
|
@@ -20,10 +35,20 @@ class Filter_Input {
|
|
20 |
Â
FILTER_SANITIZE_SPECIAL_CHARS => 'htmlspecialchars',
|
21 |
Â
FILTER_SANITIZE_STRING => 'sanitize_text_field',
|
22 |
Â
FILTER_SANITIZE_URL => 'esc_url_raw',
|
23 |
-
// Other
|
24 |
Â
FILTER_UNSAFE_RAW => null,
|
25 |
Â
);
|
26 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
27 |
Â
public static function super( $type, $variable_name, $filter = null, $options = array() ) {
|
28 |
Â
$super = null;
|
29 |
Â
|
@@ -57,11 +82,20 @@ class Filter_Input {
|
|
57 |
Â
return $var;
|
58 |
Â
}
|
59 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
60 |
Â
public static function filter( $var, $filter = null, $options = array() ) {
|
61 |
-
// Default filter is a sanitizer, not validator
|
62 |
Â
$filter_type = 'sanitizer';
|
63 |
Â
|
64 |
-
// Only filter value if it is not null
|
65 |
Â
if ( isset( $var ) && $filter && FILTER_DEFAULT !== $filter ) {
|
66 |
Â
if ( ! isset( self::$filter_callbacks[ $filter ] ) ) {
|
67 |
Â
throw new \Exception( esc_html__( 'Filter not supported.', 'stream' ) );
|
@@ -70,20 +104,22 @@ class Filter_Input {
|
|
70 |
Â
$filter_callback = self::$filter_callbacks[ $filter ];
|
71 |
Â
$result = call_user_func( $filter_callback, $var );
|
72 |
Â
|
73 |
-
|
74 |
-
|
75 |
-
|
Â
|
|
Â
|
|
76 |
Â
$filter_type = ( $filter < 500 ) ? 'validator' : 'sanitizer';
|
77 |
-
if ( 'validator' === $filter_type ) { // Validation functions
|
78 |
Â
if ( ! $result ) {
|
79 |
Â
$var = false;
|
80 |
Â
}
|
81 |
-
} else { // Santization functions
|
82 |
Â
$var = $result;
|
83 |
Â
}
|
84 |
Â
}
|
85 |
Â
|
86 |
-
// Detect FILTER_REQUIRE_ARRAY flag
|
87 |
Â
if ( isset( $var ) && is_int( $options ) && FILTER_REQUIRE_ARRAY === $options ) {
|
88 |
Â
if ( ! is_array( $var ) ) {
|
89 |
Â
$var = ( 'validator' === $filter_type ) ? false : null;
|
@@ -102,6 +138,12 @@ class Filter_Input {
|
|
102 |
Â
return $var;
|
103 |
Â
}
|
104 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
105 |
Â
public static function is_regex( $var ) {
|
106 |
Â
// @codingStandardsIgnoreStart
|
107 |
Â
$test = @preg_match( $var, '' );
|
@@ -110,6 +152,12 @@ class Filter_Input {
|
|
110 |
Â
return false !== $test;
|
111 |
Â
}
|
112 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
113 |
Â
public static function is_ip_address( $var ) {
|
114 |
Â
return false !== \WP_Http::is_ip_address( $var );
|
115 |
Â
}
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Processes form input
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Filter_Input
|
12 |
+
*/
|
13 |
Â
class Filter_Input {
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Callbacks to be used for input validation/sanitation.
|
17 |
+
*
|
18 |
+
* @var array
|
19 |
+
*/
|
20 |
Â
public static $filter_callbacks = array(
|
21 |
Â
FILTER_DEFAULT => null,
|
22 |
+
// Validate.
|
23 |
Â
FILTER_VALIDATE_BOOLEAN => 'is_bool',
|
24 |
Â
FILTER_VALIDATE_EMAIL => 'is_email',
|
25 |
Â
FILTER_VALIDATE_FLOAT => 'is_float',
|
27 |
Â
FILTER_VALIDATE_IP => array( __CLASS__, 'is_ip_address' ),
|
28 |
Â
FILTER_VALIDATE_REGEXP => array( __CLASS__, 'is_regex' ),
|
29 |
Â
FILTER_VALIDATE_URL => 'wp_http_validate_url',
|
30 |
+
// Sanitize.
|
31 |
Â
FILTER_SANITIZE_EMAIL => 'sanitize_email',
|
32 |
Â
FILTER_SANITIZE_ENCODED => 'esc_url_raw',
|
33 |
Â
FILTER_SANITIZE_NUMBER_FLOAT => 'floatval',
|
35 |
Â
FILTER_SANITIZE_SPECIAL_CHARS => 'htmlspecialchars',
|
36 |
Â
FILTER_SANITIZE_STRING => 'sanitize_text_field',
|
37 |
Â
FILTER_SANITIZE_URL => 'esc_url_raw',
|
38 |
+
// Other.
|
39 |
Â
FILTER_UNSAFE_RAW => null,
|
40 |
Â
);
|
41 |
Â
|
42 |
+
/**
|
43 |
+
* Returns input variable
|
44 |
+
*
|
45 |
+
* @param int $type Input type.
|
46 |
+
* @param string $variable_name Variable key.
|
47 |
+
* @param int $filter Filter callback.
|
48 |
+
* @param array $options Filter callback parameters.
|
49 |
+
* @throws \Exception Invalid input type provided.
|
50 |
+
* @return mixed
|
51 |
+
*/
|
52 |
Â
public static function super( $type, $variable_name, $filter = null, $options = array() ) {
|
53 |
Â
$super = null;
|
54 |
Â
|
82 |
Â
return $var;
|
83 |
Â
}
|
84 |
Â
|
85 |
+
/**
|
86 |
+
* Sanitize or validate input.
|
87 |
+
*
|
88 |
+
* @param mixed $var Raw input.
|
89 |
+
* @param int $filter Filter callback.
|
90 |
+
* @param array $options Filter callback parameters.
|
91 |
+
* @throws \Exception Unsupported filter provided.
|
92 |
+
* @return mixed
|
93 |
+
*/
|
94 |
Â
public static function filter( $var, $filter = null, $options = array() ) {
|
95 |
+
// Default filter is a sanitizer, not validator.
|
96 |
Â
$filter_type = 'sanitizer';
|
97 |
Â
|
98 |
+
// Only filter value if it is not null.
|
99 |
Â
if ( isset( $var ) && $filter && FILTER_DEFAULT !== $filter ) {
|
100 |
Â
if ( ! isset( self::$filter_callbacks[ $filter ] ) ) {
|
101 |
Â
throw new \Exception( esc_html__( 'Filter not supported.', 'stream' ) );
|
104 |
Â
$filter_callback = self::$filter_callbacks[ $filter ];
|
105 |
Â
$result = call_user_func( $filter_callback, $var );
|
106 |
Â
|
107 |
+
/**
|
108 |
+
* "filter_var / filter_input" treats validation/sanitization filters the same
|
109 |
+
* they both return output and change the var value, this shouldn't be the case here.
|
110 |
+
* We'll do a boolean check on validation function, and let sanitizers change the value
|
111 |
+
*/
|
112 |
Â
$filter_type = ( $filter < 500 ) ? 'validator' : 'sanitizer';
|
113 |
+
if ( 'validator' === $filter_type ) { // Validation functions.
|
114 |
Â
if ( ! $result ) {
|
115 |
Â
$var = false;
|
116 |
Â
}
|
117 |
+
} else { // Santization functions.
|
118 |
Â
$var = $result;
|
119 |
Â
}
|
120 |
Â
}
|
121 |
Â
|
122 |
+
// Detect FILTER_REQUIRE_ARRAY flag.
|
123 |
Â
if ( isset( $var ) && is_int( $options ) && FILTER_REQUIRE_ARRAY === $options ) {
|
124 |
Â
if ( ! is_array( $var ) ) {
|
125 |
Â
$var = ( 'validator' === $filter_type ) ? false : null;
|
138 |
Â
return $var;
|
139 |
Â
}
|
140 |
Â
|
141 |
+
/**
|
142 |
+
* Returns whether the variable is a Regular Expression or not?
|
143 |
+
*
|
144 |
+
* @param string $var Raw input.
|
145 |
+
* @return boolean
|
146 |
+
*/
|
147 |
Â
public static function is_regex( $var ) {
|
148 |
Â
// @codingStandardsIgnoreStart
|
149 |
Â
$test = @preg_match( $var, '' );
|
152 |
Â
return false !== $test;
|
153 |
Â
}
|
154 |
Â
|
155 |
+
/**
|
156 |
+
* Returns whether the variable is an IP address or not?
|
157 |
+
*
|
158 |
+
* @param string $var Raw input.
|
159 |
+
* @return boolean
|
160 |
+
*/
|
161 |
Â
public static function is_ip_address( $var ) {
|
162 |
Â
return false !== \WP_Http::is_ip_address( $var );
|
163 |
Â
}
|
classes/class-form-generator.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Form_Generator {
|
5 |
Â
|
6 |
Â
/**
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Generates an WP Admin form.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Form_Generator
|
12 |
+
*/
|
13 |
Â
class Form_Generator {
|
14 |
Â
|
15 |
Â
/**
|
classes/class-install.php
CHANGED
@@ -1,9 +1,18 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Install {
|
5 |
Â
/**
|
6 |
-
*
|
7 |
Â
*
|
8 |
Â
* @var Plugin
|
9 |
Â
*/
|
@@ -53,6 +62,8 @@ class Install {
|
|
53 |
Â
|
54 |
Â
/**
|
55 |
Â
* Class constructor
|
Â
|
|
Â
|
|
56 |
Â
*/
|
57 |
Â
public function __construct( $plugin ) {
|
58 |
Â
$this->plugin = $plugin;
|
@@ -60,10 +71,10 @@ class Install {
|
|
60 |
Â
$this->db_version = $this->get_db_version();
|
61 |
Â
$this->stream_url = self_admin_url( $this->plugin->admin->admin_parent_page . '&page=' . $this->plugin->admin->settings_page_slug );
|
62 |
Â
|
63 |
-
// Check DB and display an admin notice if there are tables missing
|
64 |
Â
add_action( 'init', array( $this, 'verify_db' ) );
|
65 |
Â
|
66 |
-
// Install the plugin
|
67 |
Â
add_action( 'wp_stream_before_db_notices', array( $this, 'check' ) );
|
68 |
Â
|
69 |
Â
register_activation_hook( $this->plugin->locations['plugin'], array( $this, 'check' ) );
|
@@ -157,7 +168,7 @@ class Install {
|
|
157 |
Â
$database_message = '';
|
158 |
Â
$uninstall_message = '';
|
159 |
Â
|
160 |
-
// Check if all needed DB is present
|
161 |
Â
$missing_tables = array();
|
162 |
Â
|
163 |
Â
foreach ( $this->plugin->db->get_table_names() as $table_name ) {
|
@@ -184,14 +195,14 @@ class Install {
|
|
184 |
Â
|
185 |
Â
if ( $this->plugin->is_network_activated() && current_user_can( 'manage_network_plugins' ) ) {
|
186 |
Â
$uninstall_message = sprintf(
|
187 |
-
|
188 |
Â
__( 'Please %1$suninstall%2$s the Stream plugin and activate it again.', 'stream' ),
|
189 |
Â
'<a href="' . network_admin_url( 'plugins.php#stream' ) . '">',
|
190 |
Â
'</a>'
|
191 |
Â
);
|
192 |
Â
} elseif ( current_user_can( 'activate_plugins' ) ) {
|
193 |
Â
$uninstall_message = sprintf(
|
194 |
-
|
195 |
Â
__( 'Please %1$suninstall%2$s the Stream plugin and activate it again.', 'stream' ),
|
196 |
Â
'<a href="' . admin_url( 'plugins.php#stream' ) . '">',
|
197 |
Â
'</a>'
|
@@ -211,7 +222,7 @@ class Install {
|
|
211 |
Â
* Register a routine to be called when stream or a stream connector has been updated
|
212 |
Â
* It works by comparing the current version with the version previously stored in the database.
|
213 |
Â
*
|
214 |
-
* @param string $file A reference to the main plugin file
|
215 |
Â
* @param string $callback The function to run when the hook is called.
|
216 |
Â
* @param string $version The version to which the plugin is updating.
|
217 |
Â
*
|
@@ -248,6 +259,8 @@ class Install {
|
|
248 |
Â
}
|
249 |
Â
|
250 |
Â
/**
|
Â
|
|
Â
|
|
251 |
Â
* @return string
|
252 |
Â
*/
|
253 |
Â
public function get_db_version() {
|
@@ -255,7 +268,7 @@ class Install {
|
|
255 |
Â
}
|
256 |
Â
|
257 |
Â
/**
|
258 |
-
*
|
259 |
Â
*/
|
260 |
Â
public function update_db_option() {
|
261 |
Â
if ( $this->success_db ) {
|
@@ -344,7 +357,7 @@ class Install {
|
|
344 |
Â
<p>
|
345 |
Â
<?php
|
346 |
Â
printf(
|
347 |
-
|
348 |
Â
esc_html__( 'Your Stream database has been successfully updated from %1$s to %2$s!', 'stream' ),
|
349 |
Â
esc_html( $this->db_version ),
|
350 |
Â
esc_html( $this->plugin->get_version() )
|
@@ -387,9 +400,9 @@ class Install {
|
|
387 |
Â
/**
|
388 |
Â
* Database user controlled update routine
|
389 |
Â
*
|
390 |
-
* @param int $db_version
|
391 |
-
* @param int $current_version
|
392 |
-
* @param array $update_args
|
393 |
Â
*
|
394 |
Â
* @return mixed Version number on success, true on no update needed, mysql error message on error
|
395 |
Â
*/
|
@@ -419,7 +432,7 @@ class Install {
|
|
419 |
Â
/**
|
420 |
Â
* Initial database install routine
|
421 |
Â
*
|
422 |
-
* @param string $current_version
|
423 |
Â
*
|
424 |
Â
* @return string
|
425 |
Â
*/
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Handles database migrations
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Install
|
12 |
+
*/
|
13 |
Â
class Install {
|
14 |
Â
/**
|
15 |
+
* Holds Instance of plugin object
|
16 |
Â
*
|
17 |
Â
* @var Plugin
|
18 |
Â
*/
|
62 |
Â
|
63 |
Â
/**
|
64 |
Â
* Class constructor
|
65 |
+
*
|
66 |
+
* @param Plugin $plugin Instance of plugin object.
|
67 |
Â
*/
|
68 |
Â
public function __construct( $plugin ) {
|
69 |
Â
$this->plugin = $plugin;
|
71 |
Â
$this->db_version = $this->get_db_version();
|
72 |
Â
$this->stream_url = self_admin_url( $this->plugin->admin->admin_parent_page . '&page=' . $this->plugin->admin->settings_page_slug );
|
73 |
Â
|
74 |
+
// Check DB and display an admin notice if there are tables missing.
|
75 |
Â
add_action( 'init', array( $this, 'verify_db' ) );
|
76 |
Â
|
77 |
+
// Install the plugin.
|
78 |
Â
add_action( 'wp_stream_before_db_notices', array( $this, 'check' ) );
|
79 |
Â
|
80 |
Â
register_activation_hook( $this->plugin->locations['plugin'], array( $this, 'check' ) );
|
168 |
Â
$database_message = '';
|
169 |
Â
$uninstall_message = '';
|
170 |
Â
|
171 |
+
// Check if all needed DB is present.
|
172 |
Â
$missing_tables = array();
|
173 |
Â
|
174 |
Â
foreach ( $this->plugin->db->get_table_names() as $table_name ) {
|
195 |
Â
|
196 |
Â
if ( $this->plugin->is_network_activated() && current_user_can( 'manage_network_plugins' ) ) {
|
197 |
Â
$uninstall_message = sprintf(
|
198 |
+
/* translators: %#$s: HTML Link tags (e.g. "<a href="https://foo.com/wp-admin/">") */
|
199 |
Â
__( 'Please %1$suninstall%2$s the Stream plugin and activate it again.', 'stream' ),
|
200 |
Â
'<a href="' . network_admin_url( 'plugins.php#stream' ) . '">',
|
201 |
Â
'</a>'
|
202 |
Â
);
|
203 |
Â
} elseif ( current_user_can( 'activate_plugins' ) ) {
|
204 |
Â
$uninstall_message = sprintf(
|
205 |
+
/* translators: %#$s: HTML Link tags (e.g. "<a href="https://foo.com/wp-admin/">") */
|
206 |
Â
__( 'Please %1$suninstall%2$s the Stream plugin and activate it again.', 'stream' ),
|
207 |
Â
'<a href="' . admin_url( 'plugins.php#stream' ) . '">',
|
208 |
Â
'</a>'
|
222 |
Â
* Register a routine to be called when stream or a stream connector has been updated
|
223 |
Â
* It works by comparing the current version with the version previously stored in the database.
|
224 |
Â
*
|
225 |
+
* @param string $file A reference to the main plugin file.
|
226 |
Â
* @param string $callback The function to run when the hook is called.
|
227 |
Â
* @param string $version The version to which the plugin is updating.
|
228 |
Â
*
|
259 |
Â
}
|
260 |
Â
|
261 |
Â
/**
|
262 |
+
* Returns the database version.
|
263 |
+
*
|
264 |
Â
* @return string
|
265 |
Â
*/
|
266 |
Â
public function get_db_version() {
|
268 |
Â
}
|
269 |
Â
|
270 |
Â
/**
|
271 |
+
* Checks if migration was successful.
|
272 |
Â
*/
|
273 |
Â
public function update_db_option() {
|
274 |
Â
if ( $this->success_db ) {
|
357 |
Â
<p>
|
358 |
Â
<?php
|
359 |
Â
printf(
|
360 |
+
/* translators: %1$s: old version, %2$s: new version (e.g. "4.2") */
|
361 |
Â
esc_html__( 'Your Stream database has been successfully updated from %1$s to %2$s!', 'stream' ),
|
362 |
Â
esc_html( $this->db_version ),
|
363 |
Â
esc_html( $this->plugin->get_version() )
|
400 |
Â
/**
|
401 |
Â
* Database user controlled update routine
|
402 |
Â
*
|
403 |
+
* @param int $db_version Next database version.
|
404 |
+
* @param int $current_version Current database version.
|
405 |
+
* @param array $update_args Update options.
|
406 |
Â
*
|
407 |
Â
* @return mixed Version number on success, true on no update needed, mysql error message on error
|
408 |
Â
*/
|
432 |
Â
/**
|
433 |
Â
* Initial database install routine
|
434 |
Â
*
|
435 |
+
* @param string $current_version Current database version.
|
436 |
Â
*
|
437 |
Â
* @return string
|
438 |
Â
*/
|
classes/class-list-table.php
CHANGED
@@ -1,11 +1,19 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
|
3 |
Â
namespace WP_Stream;
|
4 |
Â
|
Â
|
|
Â
|
|
Â
|
|
5 |
Â
class List_Table extends \WP_List_Table {
|
6 |
Â
|
7 |
Â
/**
|
8 |
-
*
|
9 |
Â
*
|
10 |
Â
* @var Plugin
|
11 |
Â
*/
|
@@ -14,8 +22,8 @@ class List_Table extends \WP_List_Table {
|
|
14 |
Â
/**
|
15 |
Â
* Class constructor.
|
16 |
Â
*
|
17 |
-
* @param Plugin $plugin
|
18 |
-
* @param array $args
|
19 |
Â
*/
|
20 |
Â
public function __construct( $plugin, $args = array() ) {
|
21 |
Â
$this->plugin = $plugin;
|
@@ -46,7 +54,7 @@ class List_Table extends \WP_List_Table {
|
|
46 |
Â
)
|
47 |
Â
);
|
48 |
Â
|
49 |
-
// Check for default hidden columns
|
50 |
Â
$this->get_hidden_columns();
|
51 |
Â
|
52 |
Â
add_filter(
|
@@ -71,12 +79,23 @@ class List_Table extends \WP_List_Table {
|
|
71 |
Â
set_screen_options();
|
72 |
Â
}
|
73 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
74 |
Â
public function extra_tablenav( $which ) {
|
75 |
Â
if ( 'top' === $which ) {
|
76 |
-
echo $this->filters_form(); // xss ok
|
77 |
Â
}
|
78 |
Â
}
|
79 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
80 |
Â
public function no_items() {
|
81 |
Â
?>
|
82 |
Â
<div class="stream-list-table-no-items">
|
@@ -85,6 +104,11 @@ class List_Table extends \WP_List_Table {
|
|
85 |
Â
<?php
|
86 |
Â
}
|
87 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
88 |
Â
public function get_columns() {
|
89 |
Â
/**
|
90 |
Â
* Allows devs to add new columns to table
|
@@ -104,22 +128,32 @@ class List_Table extends \WP_List_Table {
|
|
104 |
Â
);
|
105 |
Â
}
|
106 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
107 |
Â
public function get_sortable_columns() {
|
108 |
Â
return array(
|
109 |
Â
'date' => array( 'date', false ),
|
110 |
Â
);
|
111 |
Â
}
|
112 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
113 |
Â
public function get_hidden_columns() {
|
114 |
Â
$user = wp_get_current_user();
|
115 |
Â
if ( ! $user ) {
|
116 |
Â
return array();
|
117 |
Â
}
|
118 |
Â
|
119 |
-
// Directly checking the user meta; to check whether user has changed screen option or not
|
120 |
Â
$hidden = $this->plugin->admin->get_user_meta( $user->ID, 'manage' . $this->screen->id . 'columnshidden', true );
|
121 |
Â
|
122 |
-
// If user meta is not found; add the default hidden column 'id'
|
123 |
Â
if ( ! $hidden ) {
|
124 |
Â
$hidden = array( 'id' );
|
125 |
Â
$this->plugin->admin->update_user_meta( $user->ID, 'manage' . $this->screen->id . 'columnshidden', $hidden );
|
@@ -128,6 +162,11 @@ class List_Table extends \WP_List_Table {
|
|
128 |
Â
return $hidden;
|
129 |
Â
}
|
130 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
131 |
Â
public function prepare_items() {
|
132 |
Â
$columns = $this->get_columns();
|
133 |
Â
$sortable = $this->get_sortable_columns();
|
@@ -153,10 +192,15 @@ class List_Table extends \WP_List_Table {
|
|
153 |
Â
);
|
154 |
Â
}
|
155 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
156 |
Â
public function get_records() {
|
157 |
Â
$args = array();
|
158 |
Â
|
159 |
-
// Parse sorting params
|
160 |
Â
$order = wp_stream_filter_input( INPUT_GET, 'order' );
|
161 |
Â
if ( $order ) {
|
162 |
Â
$args['order'] = $order;
|
@@ -184,7 +228,7 @@ class List_Table extends \WP_List_Table {
|
|
184 |
Â
}
|
185 |
Â
}
|
186 |
Â
|
187 |
-
// Additional filter properties
|
188 |
Â
$properties = array(
|
189 |
Â
'record',
|
190 |
Â
'site_id',
|
@@ -198,11 +242,11 @@ class List_Table extends \WP_List_Table {
|
|
198 |
Â
'action',
|
199 |
Â
);
|
200 |
Â
|
201 |
-
// Add property fields to defaults, including their __in/__not_in variations
|
202 |
Â
foreach ( $properties as $property ) {
|
203 |
Â
$value = wp_stream_filter_input( INPUT_GET, $property );
|
204 |
Â
|
205 |
-
// Allow 0 values
|
206 |
Â
if ( isset( $value ) && '' !== $value && false !== $value ) {
|
207 |
Â
$args[ $property ] = $value;
|
208 |
Â
}
|
@@ -246,13 +290,20 @@ class List_Table extends \WP_List_Table {
|
|
246 |
Â
return $this->plugin->db->get_found_records_count();
|
247 |
Â
}
|
248 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
249 |
Â
public function column_default( $item, $column_name ) {
|
250 |
Â
$out = '';
|
251 |
Â
$record = new Record( $item );
|
252 |
Â
|
253 |
Â
switch ( $column_name ) {
|
254 |
Â
case 'date':
|
255 |
-
$created =
|
256 |
Â
$date_string = sprintf(
|
257 |
Â
'<time datetime="%s" class="relative-time record-created">%s</time>',
|
258 |
Â
wp_stream_get_iso_8601_extended_date( strtotime( $record->created ) ),
|
@@ -266,7 +317,7 @@ class List_Table extends \WP_List_Table {
|
|
266 |
Â
case 'summary':
|
267 |
Â
$out = $record->summary;
|
268 |
Â
$object_title = $record->get_object_title();
|
269 |
-
|
270 |
Â
$view_all_text = $object_title ? sprintf( esc_html__( 'View all activity for "%s"', 'stream' ), esc_attr( $object_title ) ) : esc_html__( 'View all activity for this object', 'stream' );
|
271 |
Â
|
272 |
Â
if ( $record->object_id ) {
|
@@ -381,6 +432,12 @@ class List_Table extends \WP_List_Table {
|
|
381 |
Â
echo wp_kses( $out, $allowed_tags );
|
382 |
Â
}
|
383 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
384 |
Â
public function get_action_links( $record ) {
|
385 |
Â
$out = '';
|
386 |
Â
|
@@ -434,6 +491,15 @@ class List_Table extends \WP_List_Table {
|
|
434 |
Â
return $out;
|
435 |
Â
}
|
436 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
437 |
Â
public function column_link( $display, $key, $value = null, $title = null ) {
|
438 |
Â
$url = add_query_arg(
|
439 |
Â
array(
|
@@ -458,6 +524,13 @@ class List_Table extends \WP_List_Table {
|
|
458 |
Â
);
|
459 |
Â
}
|
460 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
461 |
Â
public function get_term_title( $term, $type ) {
|
462 |
Â
if ( ! isset( $this->plugin->connectors->term_labels[ 'stream_' . $type ][ $term ] ) ) {
|
463 |
Â
return $term;
|
@@ -473,7 +546,7 @@ class List_Table extends \WP_List_Table {
|
|
473 |
Â
* results of existing records. All items that do not exist in records
|
474 |
Â
* get assigned a disabled value of "true".
|
475 |
Â
*
|
476 |
-
* @param string $column
|
477 |
Â
*
|
478 |
Â
* @return array Options to be displayed in search filters
|
479 |
Â
*/
|
@@ -482,7 +555,7 @@ class List_Table extends \WP_List_Table {
|
|
482 |
Â
if ( 'user_id' === $column ) {
|
483 |
Â
$all_records = array();
|
484 |
Â
|
485 |
-
// If the number of users exceeds the max users constant value then return an empty array and use AJAX instead
|
486 |
Â
$user_count = count_users();
|
487 |
Â
$total_users = $user_count['total_users'];
|
488 |
Â
|
@@ -555,7 +628,7 @@ class List_Table extends \WP_List_Table {
|
|
555 |
Â
}
|
556 |
Â
}
|
557 |
Â
|
558 |
-
// Remove WP-CLI pseudo user if no records with user=0 exist
|
559 |
Â
if ( isset( $disabled_records[0] ) ) {
|
560 |
Â
unset( $disabled_records[0] );
|
561 |
Â
}
|
@@ -574,12 +647,17 @@ class List_Table extends \WP_List_Table {
|
|
574 |
Â
uasort( $active_records, $sort );
|
575 |
Â
uasort( $disabled_records, $sort );
|
576 |
Â
|
577 |
-
// Not using array_merge() in order to preserve the array index for the users dropdown which uses the user_id as the key
|
578 |
Â
$all_records = $active_records + $disabled_records;
|
579 |
Â
|
580 |
Â
return $all_records;
|
581 |
Â
}
|
582 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
583 |
Â
public function get_filters() {
|
584 |
Â
$filters = array();
|
585 |
Â
|
@@ -620,6 +698,11 @@ class List_Table extends \WP_List_Table {
|
|
620 |
Â
return apply_filters( 'wp_stream_list_table_filters', $filters );
|
621 |
Â
}
|
622 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
623 |
Â
public function filters_form() {
|
624 |
Â
$filters = $this->get_filters();
|
625 |
Â
|
@@ -641,7 +724,7 @@ class List_Table extends \WP_List_Table {
|
|
641 |
Â
$filters_string .= $this->filter_date( $data['items'] );
|
642 |
Â
} else {
|
643 |
Â
if ( 'context' === $name ) {
|
644 |
-
// Add Connectors as parents, and apply the Contexts as children
|
645 |
Â
$connectors = $this->assemble_records( 'connector' );
|
646 |
Â
$context_items = array();
|
647 |
Â
|
@@ -657,7 +740,7 @@ class List_Table extends \WP_List_Table {
|
|
657 |
Â
if ( isset( $context_items[ $connector ]['children'] ) ) {
|
658 |
Â
$labels = wp_list_pluck( $context_items[ $connector ]['children'], 'label' );
|
659 |
Â
|
660 |
-
// Sort child items by label
|
661 |
Â
array_multisort( $labels, SORT_ASC, $context_items[ $connector ]['children'] );
|
662 |
Â
}
|
663 |
Â
}
|
@@ -672,10 +755,10 @@ class List_Table extends \WP_List_Table {
|
|
672 |
Â
|
673 |
Â
$labels = wp_list_pluck( $data['items'], 'label' );
|
674 |
Â
|
675 |
-
// Sort top-level items by label
|
676 |
Â
array_multisort( $labels, SORT_ASC, $data['items'] );
|
677 |
Â
|
678 |
-
// Output a hidden input to handle the connector value
|
679 |
Â
$filters_string .= sprintf(
|
680 |
Â
'<input type="hidden" name="connector" class="record-filter-connector" value="%s" />',
|
681 |
Â
esc_attr( wp_stream_filter_input( INPUT_GET, 'connector' ) )
|
@@ -688,14 +771,14 @@ class List_Table extends \WP_List_Table {
|
|
688 |
Â
|
689 |
Â
$filters_string .= sprintf( '<input type="submit" id="record-query-submit" class="button" value="%s" />', __( 'Filter', 'stream' ) );
|
690 |
Â
|
691 |
-
// Parse all query vars into an array
|
692 |
Â
$query_vars = array();
|
693 |
Â
|
694 |
Â
if ( isset( $_SERVER['QUERY_STRING'] ) ) {
|
695 |
Â
parse_str( urldecode( $_SERVER['QUERY_STRING'] ), $query_vars );
|
696 |
Â
}
|
697 |
Â
|
698 |
-
// Ignore certain query vars and query vars that are empty
|
699 |
Â
foreach ( $query_vars as $query_var => $value ) {
|
700 |
Â
if ( '' === $value || 'page' === $query_var || 'paged' === $query_var ) {
|
701 |
Â
unset( $query_vars[ $query_var ] );
|
@@ -709,14 +792,23 @@ class List_Table extends \WP_List_Table {
|
|
709 |
Â
self_admin_url( $this->plugin->admin->admin_parent_page )
|
710 |
Â
);
|
711 |
Â
|
712 |
-
// Display reset action if records are being filtered
|
713 |
Â
if ( ! empty( $query_vars ) ) {
|
714 |
Â
$filters_string .= sprintf( '<a href="%s" id="record-query-reset"><span class="dashicons dashicons-dismiss"></span> <span class="record-query-reset-text">%s</span></a>', esc_url( $url ), __( 'Reset filters', 'stream' ) );
|
715 |
Â
}
|
716 |
Â
|
717 |
-
return sprintf( '<div class="alignleft actions">%s</div>', $filters_string ); // xss ok
|
718 |
Â
}
|
719 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
720 |
Â
public function filter_select( $name, $title, $items, $ajax = false ) {
|
721 |
Â
$options = array( '<option value=""></option>' );
|
722 |
Â
$selected = wp_stream_filter_input( INPUT_GET, $name );
|
@@ -754,7 +846,7 @@ class List_Table extends \WP_List_Table {
|
|
754 |
Â
$out = sprintf(
|
755 |
Â
'<select name="%s" class="chosen-select" data-placeholder="%s">%s</select>',
|
756 |
Â
esc_attr( $name ),
|
757 |
-
|
758 |
Â
sprintf( esc_attr__( 'Show all %s', 'stream' ), $title ),
|
759 |
Â
implode( '', $options )
|
760 |
Â
);
|
@@ -762,6 +854,12 @@ class List_Table extends \WP_List_Table {
|
|
762 |
Â
return $out;
|
763 |
Â
}
|
764 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
765 |
Â
public function filter_option( $args ) {
|
766 |
Â
$defaults = array(
|
767 |
Â
'value' => null,
|
@@ -788,10 +886,15 @@ class List_Table extends \WP_List_Table {
|
|
788 |
Â
);
|
789 |
Â
}
|
790 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
791 |
Â
public function filter_search() {
|
792 |
Â
$search = null;
|
793 |
-
if ( isset( $_GET['search'] ) ) { //
|
794 |
-
$search =
|
795 |
Â
}
|
796 |
Â
$out = sprintf(
|
797 |
Â
'<p class="search-box">
|
@@ -806,6 +909,12 @@ class List_Table extends \WP_List_Table {
|
|
806 |
Â
return $out;
|
807 |
Â
}
|
808 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
809 |
Â
public function filter_date( $items ) {
|
810 |
Â
wp_enqueue_style( 'jquery-ui' );
|
811 |
Â
wp_enqueue_style( 'wp-stream-datepicker' );
|
@@ -903,19 +1012,27 @@ class List_Table extends \WP_List_Table {
|
|
903 |
Â
return ob_get_clean();
|
904 |
Â
}
|
905 |
Â
|
Â
|
|
Â
|
|
Â
|
|
906 |
Â
public function display() {
|
907 |
Â
$url = self_admin_url( $this->plugin->admin->admin_parent_page );
|
908 |
Â
|
909 |
Â
echo '<form method="get" action="' . esc_url( $url ) . '" id="record-filter-form">';
|
910 |
-
echo $this->filter_search(); // xss ok
|
911 |
Â
parent::display();
|
912 |
Â
echo '</form>';
|
913 |
Â
|
914 |
Â
echo '<form method="get" action="' . esc_url( $url ) . '" id="record-actions-form">';
|
915 |
-
echo $this->record_actions_form(); // xss ok
|
916 |
Â
echo '</form>';
|
917 |
Â
}
|
918 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
919 |
Â
public function single_row( $item ) {
|
920 |
Â
$classes = apply_filters( 'wp_stream_record_classes', array(), $item );
|
921 |
Â
$class_string = '';
|
@@ -923,11 +1040,16 @@ class List_Table extends \WP_List_Table {
|
|
923 |
Â
$class_string = ' class="' . esc_attr( join( ' ', $classes ) ) . '"';
|
924 |
Â
}
|
925 |
Â
|
926 |
-
echo sprintf( '<tr%s>', $class_string ); // xss ok
|
927 |
Â
$this->single_row_columns( $item );
|
928 |
Â
echo '</tr>';
|
929 |
Â
}
|
930 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
931 |
Â
public function display_tablenav( $which ) {
|
932 |
Â
if ( 'top' === $which ) :
|
933 |
Â
?>
|
@@ -956,6 +1078,14 @@ class List_Table extends \WP_List_Table {
|
|
956 |
Â
endif;
|
957 |
Â
}
|
958 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
959 |
Â
public function set_screen_option( $dummy, $option, $value ) {
|
960 |
Â
if ( 'edit_stream_per_page' === $option ) {
|
961 |
Â
return $value;
|
@@ -964,6 +1094,14 @@ class List_Table extends \WP_List_Table {
|
|
964 |
Â
}
|
965 |
Â
}
|
966 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
967 |
Â
public function set_live_update_option( $dummy, $option, $value ) {
|
968 |
Â
unset( $value );
|
969 |
Â
|
@@ -983,6 +1121,13 @@ class List_Table extends \WP_List_Table {
|
|
983 |
Â
return $dummy;
|
984 |
Â
}
|
985 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
986 |
Â
public function screen_controls( $status, $args ) {
|
987 |
Â
unset( $status );
|
988 |
Â
unset( $args );
|
@@ -1025,7 +1170,7 @@ class List_Table extends \WP_List_Table {
|
|
1025 |
Â
/**
|
1026 |
Â
* This function is use to map List table column name with excluded setting keys
|
1027 |
Â
*
|
1028 |
-
* @param string $column
|
1029 |
Â
*
|
1030 |
Â
* @return string setting name for that column
|
1031 |
Â
*/
|
@@ -1056,7 +1201,7 @@ class List_Table extends \WP_List_Table {
|
|
1056 |
Â
/**
|
1057 |
Â
* Get users as dropdown items
|
1058 |
Â
*
|
1059 |
-
* @param array $users
|
1060 |
Â
*
|
1061 |
Â
* @return array
|
1062 |
Â
*/
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Generates a filterable list of provided records to be displayed HTML Table.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
Â
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - List_Table
|
12 |
+
*/
|
13 |
Â
class List_Table extends \WP_List_Table {
|
14 |
Â
|
15 |
Â
/**
|
16 |
+
* Holds Instance of plugin object
|
17 |
Â
*
|
18 |
Â
* @var Plugin
|
19 |
Â
*/
|
22 |
Â
/**
|
23 |
Â
* Class constructor.
|
24 |
Â
*
|
25 |
+
* @param Plugin $plugin Instance of plugin object.
|
26 |
+
* @param array $args Argument to filter rows by.
|
27 |
Â
*/
|
28 |
Â
public function __construct( $plugin, $args = array() ) {
|
29 |
Â
$this->plugin = $plugin;
|
54 |
Â
)
|
55 |
Â
);
|
56 |
Â
|
57 |
+
// Check for default hidden columns.
|
58 |
Â
$this->get_hidden_columns();
|
59 |
Â
|
60 |
Â
add_filter(
|
79 |
Â
set_screen_options();
|
80 |
Â
}
|
81 |
Â
|
82 |
+
/**
|
83 |
+
* Renders extra from navigation options.
|
84 |
+
*
|
85 |
+
* @param string $which Page location.
|
86 |
+
* @return void
|
87 |
+
*/
|
88 |
Â
public function extra_tablenav( $which ) {
|
89 |
Â
if ( 'top' === $which ) {
|
90 |
+
echo $this->filters_form(); // xss ok.
|
91 |
Â
}
|
92 |
Â
}
|
93 |
Â
|
94 |
+
/**
|
95 |
+
* Renders "No items found" message.
|
96 |
+
*
|
97 |
+
* @return void
|
98 |
+
*/
|
99 |
Â
public function no_items() {
|
100 |
Â
?>
|
101 |
Â
<div class="stream-list-table-no-items">
|
104 |
Â
<?php
|
105 |
Â
}
|
106 |
Â
|
107 |
+
/**
|
108 |
+
* Returns the table columns to be rendered.
|
109 |
+
*
|
110 |
+
* @return array
|
111 |
+
*/
|
112 |
Â
public function get_columns() {
|
113 |
Â
/**
|
114 |
Â
* Allows devs to add new columns to table
|
128 |
Â
);
|
129 |
Â
}
|
130 |
Â
|
131 |
+
/**
|
132 |
+
* Returns the columns the items can be sort by.
|
133 |
+
*
|
134 |
+
* @return array
|
135 |
+
*/
|
136 |
Â
public function get_sortable_columns() {
|
137 |
Â
return array(
|
138 |
Â
'date' => array( 'date', false ),
|
139 |
Â
);
|
140 |
Â
}
|
141 |
Â
|
142 |
+
/**
|
143 |
+
* Returns columns hidden from all except specific users.
|
144 |
+
*
|
145 |
+
* @return array|bool
|
146 |
+
*/
|
147 |
Â
public function get_hidden_columns() {
|
148 |
Â
$user = wp_get_current_user();
|
149 |
Â
if ( ! $user ) {
|
150 |
Â
return array();
|
151 |
Â
}
|
152 |
Â
|
153 |
+
// Directly checking the user meta; to check whether user has changed screen option or not.
|
154 |
Â
$hidden = $this->plugin->admin->get_user_meta( $user->ID, 'manage' . $this->screen->id . 'columnshidden', true );
|
155 |
Â
|
156 |
+
// If user meta is not found; add the default hidden column 'id'.
|
157 |
Â
if ( ! $hidden ) {
|
158 |
Â
$hidden = array( 'id' );
|
159 |
Â
$this->plugin->admin->update_user_meta( $user->ID, 'manage' . $this->screen->id . 'columnshidden', $hidden );
|
162 |
Â
return $hidden;
|
163 |
Â
}
|
164 |
Â
|
165 |
+
/**
|
166 |
+
* Prepares table columns and data for render
|
167 |
+
*
|
168 |
+
* @return void
|
169 |
+
*/
|
170 |
Â
public function prepare_items() {
|
171 |
Â
$columns = $this->get_columns();
|
172 |
Â
$sortable = $this->get_sortable_columns();
|
192 |
Â
);
|
193 |
Â
}
|
194 |
Â
|
195 |
+
/**
|
196 |
+
* Returns records to be displayed
|
197 |
+
*
|
198 |
+
* @return array
|
199 |
+
*/
|
200 |
Â
public function get_records() {
|
201 |
Â
$args = array();
|
202 |
Â
|
203 |
+
// Parse sorting params.
|
204 |
Â
$order = wp_stream_filter_input( INPUT_GET, 'order' );
|
205 |
Â
if ( $order ) {
|
206 |
Â
$args['order'] = $order;
|
228 |
Â
}
|
229 |
Â
}
|
230 |
Â
|
231 |
+
// Additional filter properties.
|
232 |
Â
$properties = array(
|
233 |
Â
'record',
|
234 |
Â
'site_id',
|
242 |
Â
'action',
|
243 |
Â
);
|
244 |
Â
|
245 |
+
// Add property fields to defaults, including their __in/__not_in variations.
|
246 |
Â
foreach ( $properties as $property ) {
|
247 |
Â
$value = wp_stream_filter_input( INPUT_GET, $property );
|
248 |
Â
|
249 |
+
// Allow 0 values.
|
250 |
Â
if ( isset( $value ) && '' !== $value && false !== $value ) {
|
251 |
Â
$args[ $property ] = $value;
|
252 |
Â
}
|
290 |
Â
return $this->plugin->db->get_found_records_count();
|
291 |
Â
}
|
292 |
Â
|
293 |
+
/**
|
294 |
+
* Returns the column content for the provided item and column.
|
295 |
+
*
|
296 |
+
* @param array $item Record data.
|
297 |
+
* @param string $column_name Column name.
|
298 |
+
* @return void
|
299 |
+
*/
|
300 |
Â
public function column_default( $item, $column_name ) {
|
301 |
Â
$out = '';
|
302 |
Â
$record = new Record( $item );
|
303 |
Â
|
304 |
Â
switch ( $column_name ) {
|
305 |
Â
case 'date':
|
306 |
+
$created = gmdate( 'Y-m-d H:i:s', strtotime( $record->created ) );
|
307 |
Â
$date_string = sprintf(
|
308 |
Â
'<time datetime="%s" class="relative-time record-created">%s</time>',
|
309 |
Â
wp_stream_get_iso_8601_extended_date( strtotime( $record->created ) ),
|
317 |
Â
case 'summary':
|
318 |
Â
$out = $record->summary;
|
319 |
Â
$object_title = $record->get_object_title();
|
320 |
+
/* translators: %s: the title of any object, like a Post (e.g. "Hello World") */
|
321 |
Â
$view_all_text = $object_title ? sprintf( esc_html__( 'View all activity for "%s"', 'stream' ), esc_attr( $object_title ) ) : esc_html__( 'View all activity for this object', 'stream' );
|
322 |
Â
|
323 |
Â
if ( $record->object_id ) {
|
432 |
Â
echo wp_kses( $out, $allowed_tags );
|
433 |
Â
}
|
434 |
Â
|
435 |
+
/**
|
436 |
+
* Returns the actions links for the provided record. (Eg. Edit, View)
|
437 |
+
*
|
438 |
+
* @param Record $record Record.
|
439 |
+
* @return string
|
440 |
+
*/
|
441 |
Â
public function get_action_links( $record ) {
|
442 |
Â
$out = '';
|
443 |
Â
|
491 |
Â
return $out;
|
492 |
Â
}
|
493 |
Â
|
494 |
+
/**
|
495 |
+
* Returns a link to be display in the table.
|
496 |
+
*
|
497 |
+
* @param string $display Text to be displayed in link.
|
498 |
+
* @param string|array $key Query string variable(s).
|
499 |
+
* @param string $value Single query string value.
|
500 |
+
* @param string $title Tooltip value.
|
501 |
+
* @return string
|
502 |
+
*/
|
503 |
Â
public function column_link( $display, $key, $value = null, $title = null ) {
|
504 |
Â
$url = add_query_arg(
|
505 |
Â
array(
|
524 |
Â
);
|
525 |
Â
}
|
526 |
Â
|
527 |
+
/**
|
528 |
+
* Returns the label for a connector term.
|
529 |
+
*
|
530 |
+
* @param string $term Connector label type.
|
531 |
+
* @param string $type Connector term.
|
532 |
+
* @return string
|
533 |
+
*/
|
534 |
Â
public function get_term_title( $term, $type ) {
|
535 |
Â
if ( ! isset( $this->plugin->connectors->term_labels[ 'stream_' . $type ][ $term ] ) ) {
|
536 |
Â
return $term;
|
546 |
Â
* results of existing records. All items that do not exist in records
|
547 |
Â
* get assigned a disabled value of "true".
|
548 |
Â
*
|
549 |
+
* @param string $column List table column name.
|
550 |
Â
*
|
551 |
Â
* @return array Options to be displayed in search filters
|
552 |
Â
*/
|
555 |
Â
if ( 'user_id' === $column ) {
|
556 |
Â
$all_records = array();
|
557 |
Â
|
558 |
+
// If the number of users exceeds the max users constant value then return an empty array and use AJAX instead.
|
559 |
Â
$user_count = count_users();
|
560 |
Â
$total_users = $user_count['total_users'];
|
561 |
Â
|
628 |
Â
}
|
629 |
Â
}
|
630 |
Â
|
631 |
+
// Remove WP-CLI pseudo user if no records with user=0 exist.
|
632 |
Â
if ( isset( $disabled_records[0] ) ) {
|
633 |
Â
unset( $disabled_records[0] );
|
634 |
Â
}
|
647 |
Â
uasort( $active_records, $sort );
|
648 |
Â
uasort( $disabled_records, $sort );
|
649 |
Â
|
650 |
+
// Not using array_merge() in order to preserve the array index for the users dropdown which uses the user_id as the key.
|
651 |
Â
$all_records = $active_records + $disabled_records;
|
652 |
Â
|
653 |
Â
return $all_records;
|
654 |
Â
}
|
655 |
Â
|
656 |
+
/**
|
657 |
+
* Returns list filters.
|
658 |
+
*
|
659 |
+
* @return array
|
660 |
+
*/
|
661 |
Â
public function get_filters() {
|
662 |
Â
$filters = array();
|
663 |
Â
|
698 |
Â
return apply_filters( 'wp_stream_list_table_filters', $filters );
|
699 |
Â
}
|
700 |
Â
|
701 |
+
/**
|
702 |
+
* Returns table filters form.
|
703 |
+
*
|
704 |
+
* @return string
|
705 |
+
*/
|
706 |
Â
public function filters_form() {
|
707 |
Â
$filters = $this->get_filters();
|
708 |
Â
|
724 |
Â
$filters_string .= $this->filter_date( $data['items'] );
|
725 |
Â
} else {
|
726 |
Â
if ( 'context' === $name ) {
|
727 |
+
// Add Connectors as parents, and apply the Contexts as children.
|
728 |
Â
$connectors = $this->assemble_records( 'connector' );
|
729 |
Â
$context_items = array();
|
730 |
Â
|
740 |
Â
if ( isset( $context_items[ $connector ]['children'] ) ) {
|
741 |
Â
$labels = wp_list_pluck( $context_items[ $connector ]['children'], 'label' );
|
742 |
Â
|
743 |
+
// Sort child items by label.
|
744 |
Â
array_multisort( $labels, SORT_ASC, $context_items[ $connector ]['children'] );
|
745 |
Â
}
|
746 |
Â
}
|
755 |
Â
|
756 |
Â
$labels = wp_list_pluck( $data['items'], 'label' );
|
757 |
Â
|
758 |
+
// Sort top-level items by label.
|
759 |
Â
array_multisort( $labels, SORT_ASC, $data['items'] );
|
760 |
Â
|
761 |
+
// Output a hidden input to handle the connector value.
|
762 |
Â
$filters_string .= sprintf(
|
763 |
Â
'<input type="hidden" name="connector" class="record-filter-connector" value="%s" />',
|
764 |
Â
esc_attr( wp_stream_filter_input( INPUT_GET, 'connector' ) )
|
771 |
Â
|
772 |
Â
$filters_string .= sprintf( '<input type="submit" id="record-query-submit" class="button" value="%s" />', __( 'Filter', 'stream' ) );
|
773 |
Â
|
774 |
+
// Parse all query vars into an array.
|
775 |
Â
$query_vars = array();
|
776 |
Â
|
777 |
Â
if ( isset( $_SERVER['QUERY_STRING'] ) ) {
|
778 |
Â
parse_str( urldecode( $_SERVER['QUERY_STRING'] ), $query_vars );
|
779 |
Â
}
|
780 |
Â
|
781 |
+
// Ignore certain query vars and query vars that are empty.
|
782 |
Â
foreach ( $query_vars as $query_var => $value ) {
|
783 |
Â
if ( '' === $value || 'page' === $query_var || 'paged' === $query_var ) {
|
784 |
Â
unset( $query_vars[ $query_var ] );
|
792 |
Â
self_admin_url( $this->plugin->admin->admin_parent_page )
|
793 |
Â
);
|
794 |
Â
|
795 |
+
// Display reset action if records are being filtered.
|
796 |
Â
if ( ! empty( $query_vars ) ) {
|
797 |
Â
$filters_string .= sprintf( '<a href="%s" id="record-query-reset"><span class="dashicons dashicons-dismiss"></span> <span class="record-query-reset-text">%s</span></a>', esc_url( $url ), __( 'Reset filters', 'stream' ) );
|
798 |
Â
}
|
799 |
Â
|
800 |
+
return sprintf( '<div class="alignleft actions">%s</div>', $filters_string ); // xss ok.
|
801 |
Â
}
|
802 |
Â
|
803 |
+
/**
|
804 |
+
* Returns HTML string of filterable select control with filtered items.
|
805 |
+
*
|
806 |
+
* @param string $name Search input.
|
807 |
+
* @param string $title Name of the control.
|
808 |
+
* @param array $items Items to be filtered.
|
809 |
+
* @param boolean $ajax Whether is an ajax request or not.
|
810 |
+
* @return string
|
811 |
+
*/
|
812 |
Â
public function filter_select( $name, $title, $items, $ajax = false ) {
|
813 |
Â
$options = array( '<option value=""></option>' );
|
814 |
Â
$selected = wp_stream_filter_input( INPUT_GET, $name );
|
846 |
Â
$out = sprintf(
|
847 |
Â
'<select name="%s" class="chosen-select" data-placeholder="%s">%s</select>',
|
848 |
Â
esc_attr( $name ),
|
849 |
+
/* translators: %s: the title of the dropdown menu (e.g. "users") */
|
850 |
Â
sprintf( esc_attr__( 'Show all %s', 'stream' ), $title ),
|
851 |
Â
implode( '', $options )
|
852 |
Â
);
|
854 |
Â
return $out;
|
855 |
Â
}
|
856 |
Â
|
857 |
+
/**
|
858 |
+
* Return HTML string of a filterable select option.
|
859 |
+
*
|
860 |
+
* @param array $args Option attributes.
|
861 |
+
* @return string
|
862 |
+
*/
|
863 |
Â
public function filter_option( $args ) {
|
864 |
Â
$defaults = array(
|
865 |
Â
'value' => null,
|
886 |
Â
);
|
887 |
Â
}
|
888 |
Â
|
889 |
+
/**
|
890 |
+
* Return HTML string of a filter search box.
|
891 |
+
*
|
892 |
+
* @return string
|
893 |
+
*/
|
894 |
Â
public function filter_search() {
|
895 |
Â
$search = null;
|
896 |
+
if ( isset( $_GET['search'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
897 |
+
$search = sanitize_key( wp_unslash( $_GET['search'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
898 |
Â
}
|
899 |
Â
$out = sprintf(
|
900 |
Â
'<p class="search-box">
|
909 |
Â
return $out;
|
910 |
Â
}
|
911 |
Â
|
912 |
+
/**
|
913 |
+
* Return HTML string of a filter select box based upon date.
|
914 |
+
*
|
915 |
+
* @param array $items Records.
|
916 |
+
* @return string
|
917 |
+
*/
|
918 |
Â
public function filter_date( $items ) {
|
919 |
Â
wp_enqueue_style( 'jquery-ui' );
|
920 |
Â
wp_enqueue_style( 'wp-stream-datepicker' );
|
1012 |
Â
return ob_get_clean();
|
1013 |
Â
}
|
1014 |
Â
|
1015 |
+
/**
|
1016 |
+
* Renders record filter forms.
|
1017 |
+
*/
|
1018 |
Â
public function display() {
|
1019 |
Â
$url = self_admin_url( $this->plugin->admin->admin_parent_page );
|
1020 |
Â
|
1021 |
Â
echo '<form method="get" action="' . esc_url( $url ) . '" id="record-filter-form">';
|
1022 |
+
echo $this->filter_search(); // xss ok.
|
1023 |
Â
parent::display();
|
1024 |
Â
echo '</form>';
|
1025 |
Â
|
1026 |
Â
echo '<form method="get" action="' . esc_url( $url ) . '" id="record-actions-form">';
|
1027 |
+
echo $this->record_actions_form(); // xss ok.
|
1028 |
Â
echo '</form>';
|
1029 |
Â
}
|
1030 |
Â
|
1031 |
+
/**
|
1032 |
+
* Renders a single record
|
1033 |
+
*
|
1034 |
+
* @param array $item Record data.
|
1035 |
+
*/
|
1036 |
Â
public function single_row( $item ) {
|
1037 |
Â
$classes = apply_filters( 'wp_stream_record_classes', array(), $item );
|
1038 |
Â
$class_string = '';
|
1040 |
Â
$class_string = ' class="' . esc_attr( join( ' ', $classes ) ) . '"';
|
1041 |
Â
}
|
1042 |
Â
|
1043 |
+
echo sprintf( '<tr%s>', $class_string ); // xss ok.
|
1044 |
Â
$this->single_row_columns( $item );
|
1045 |
Â
echo '</tr>';
|
1046 |
Â
}
|
1047 |
Â
|
1048 |
+
/**
|
1049 |
+
* Renders table navigation controls
|
1050 |
+
*
|
1051 |
+
* @param string $which Location controls.
|
1052 |
+
*/
|
1053 |
Â
public function display_tablenav( $which ) {
|
1054 |
Â
if ( 'top' === $which ) :
|
1055 |
Â
?>
|
1078 |
Â
endif;
|
1079 |
Â
}
|
1080 |
Â
|
1081 |
+
/**
|
1082 |
+
* Sets the screen options.
|
1083 |
+
*
|
1084 |
+
* @param string $dummy Unused.
|
1085 |
+
* @param string $option Screen option name.
|
1086 |
+
* @param string $value Screen option value.
|
1087 |
+
* @return string
|
1088 |
+
*/
|
1089 |
Â
public function set_screen_option( $dummy, $option, $value ) {
|
1090 |
Â
if ( 'edit_stream_per_page' === $option ) {
|
1091 |
Â
return $value;
|
1094 |
Â
}
|
1095 |
Â
}
|
1096 |
Â
|
1097 |
+
/**
|
1098 |
+
* Sets the live update options.
|
1099 |
+
*
|
1100 |
+
* @param string $dummy Unused.
|
1101 |
+
* @param string $option Screen option name.
|
1102 |
+
* @param string $value Screen option value.
|
1103 |
+
* @return string
|
1104 |
+
*/
|
1105 |
Â
public function set_live_update_option( $dummy, $option, $value ) {
|
1106 |
Â
unset( $value );
|
1107 |
Â
|
1121 |
Â
return $dummy;
|
1122 |
Â
}
|
1123 |
Â
|
1124 |
+
/**
|
1125 |
+
* Return HTML string of the "Live updates" screen option.
|
1126 |
+
*
|
1127 |
+
* @param string $status Unused.
|
1128 |
+
* @param array $args Unused.
|
1129 |
+
* @return string
|
1130 |
+
*/
|
1131 |
Â
public function screen_controls( $status, $args ) {
|
1132 |
Â
unset( $status );
|
1133 |
Â
unset( $args );
|
1170 |
Â
/**
|
1171 |
Â
* This function is use to map List table column name with excluded setting keys
|
1172 |
Â
*
|
1173 |
+
* @param string $column List table column name.
|
1174 |
Â
*
|
1175 |
Â
* @return string setting name for that column
|
1176 |
Â
*/
|
1201 |
Â
/**
|
1202 |
Â
* Get users as dropdown items
|
1203 |
Â
*
|
1204 |
+
* @param array $users Users.
|
1205 |
Â
*
|
1206 |
Â
* @return array
|
1207 |
Â
*/
|
classes/class-live-update.php
CHANGED
@@ -1,9 +1,18 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Live_Update {
|
5 |
Â
/**
|
6 |
-
*
|
7 |
Â
*
|
8 |
Â
* @var Plugin
|
9 |
Â
*/
|
@@ -26,15 +35,15 @@ class Live_Update {
|
|
26 |
Â
/**
|
27 |
Â
* Class constructor.
|
28 |
Â
*
|
29 |
-
* @param Plugin $plugin
|
30 |
Â
*/
|
31 |
Â
public function __construct( $plugin ) {
|
32 |
Â
$this->plugin = $plugin;
|
33 |
Â
|
34 |
-
// Heartbeat live update
|
35 |
Â
add_filter( 'heartbeat_received', array( $this, 'heartbeat_received' ), 10, 2 );
|
36 |
Â
|
37 |
-
// Enable / Disable live update per user
|
38 |
Â
add_action( 'wp_ajax_stream_enable_live_update', array( $this, 'enable_live_update' ) );
|
39 |
Â
}
|
40 |
Â
|
@@ -87,8 +96,8 @@ class Live_Update {
|
|
87 |
Â
* @uses gather_updated_items
|
88 |
Â
* @uses generate_row
|
89 |
Â
*
|
90 |
-
* @param array $response Response to heartbeat
|
91 |
-
* @param array $data Data from heartbeat
|
92 |
Â
*
|
93 |
Â
* @return array Data sent to heartbeat
|
94 |
Â
*/
|
@@ -106,7 +115,7 @@ class Live_Update {
|
|
106 |
Â
$query = array();
|
107 |
Â
}
|
108 |
Â
|
109 |
-
// Decode the query
|
110 |
Â
$query = json_decode( wp_kses_stripslashes( $query ) );
|
111 |
Â
|
112 |
Â
$updated_items = $this->gather_updated_items( $last_time, (array) $query );
|
@@ -129,8 +138,8 @@ class Live_Update {
|
|
129 |
Â
/**
|
130 |
Â
* Sends Updated Actions to the List Table View
|
131 |
Â
*
|
132 |
-
* @param int $last_time Timestamp of last update
|
133 |
-
* @param array $args
|
134 |
Â
*
|
135 |
Â
* @return array Array of recently updated items
|
136 |
Â
*/
|
@@ -163,20 +172,20 @@ class Live_Update {
|
|
163 |
Â
*
|
164 |
Â
* @action heartbeat_recieved
|
165 |
Â
*
|
166 |
-
* @param array $response Response to be sent to heartbeat tick
|
167 |
-
* @param array $data Data from heartbeat send
|
168 |
Â
*
|
169 |
Â
* @return array Data sent to heartbeat tick
|
170 |
Â
*/
|
171 |
Â
public function heartbeat_received( $response, $data ) {
|
172 |
-
// Only fire when Stream is requesting a live update
|
173 |
Â
if ( ! isset( $data['wp-stream-heartbeat'] ) ) {
|
174 |
Â
return $response;
|
175 |
Â
}
|
176 |
Â
|
177 |
Â
$enable_stream_update = ( 'off' !== $this->plugin->admin->get_user_meta( get_current_user_id(), $this->user_meta_key ) );
|
178 |
Â
|
179 |
-
// Register list table
|
180 |
Â
$this->list_table = new List_Table(
|
181 |
Â
$this->plugin,
|
182 |
Â
array(
|
@@ -190,7 +199,7 @@ class Live_Update {
|
|
190 |
Â
|
191 |
Â
if ( isset( $data['wp-stream-heartbeat'] ) && isset( $total_items ) ) {
|
192 |
Â
$response['total_items'] = $total_items;
|
193 |
-
|
194 |
Â
$response['total_items_i18n'] = sprintf( _n( '%d item', '%d items', $total_items ), number_format_i18n( $total_items ) );
|
195 |
Â
}
|
196 |
Â
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Processes update calls from the Stream Records page.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Live_Update
|
12 |
+
*/
|
13 |
Â
class Live_Update {
|
14 |
Â
/**
|
15 |
+
* Holds instance of plugin object
|
16 |
Â
*
|
17 |
Â
* @var Plugin
|
18 |
Â
*/
|
35 |
Â
/**
|
36 |
Â
* Class constructor.
|
37 |
Â
*
|
38 |
+
* @param Plugin $plugin Instance of plugin object.
|
39 |
Â
*/
|
40 |
Â
public function __construct( $plugin ) {
|
41 |
Â
$this->plugin = $plugin;
|
42 |
Â
|
43 |
+
// Heartbeat live update.
|
44 |
Â
add_filter( 'heartbeat_received', array( $this, 'heartbeat_received' ), 10, 2 );
|
45 |
Â
|
46 |
+
// Enable / Disable live update per user.
|
47 |
Â
add_action( 'wp_ajax_stream_enable_live_update', array( $this, 'enable_live_update' ) );
|
48 |
Â
}
|
49 |
Â
|
96 |
Â
* @uses gather_updated_items
|
97 |
Â
* @uses generate_row
|
98 |
Â
*
|
99 |
+
* @param array $response Response to heartbeat.
|
100 |
+
* @param array $data Data from heartbeat.
|
101 |
Â
*
|
102 |
Â
* @return array Data sent to heartbeat
|
103 |
Â
*/
|
115 |
Â
$query = array();
|
116 |
Â
}
|
117 |
Â
|
118 |
+
// Decode the query.
|
119 |
Â
$query = json_decode( wp_kses_stripslashes( $query ) );
|
120 |
Â
|
121 |
Â
$updated_items = $this->gather_updated_items( $last_time, (array) $query );
|
138 |
Â
/**
|
139 |
Â
* Sends Updated Actions to the List Table View
|
140 |
Â
*
|
141 |
+
* @param int $last_time Timestamp of last update.
|
142 |
+
* @param array $args Query args.
|
143 |
Â
*
|
144 |
Â
* @return array Array of recently updated items
|
145 |
Â
*/
|
172 |
Â
*
|
173 |
Â
* @action heartbeat_recieved
|
174 |
Â
*
|
175 |
+
* @param array $response Response to be sent to heartbeat tick.
|
176 |
+
* @param array $data Data from heartbeat send.
|
177 |
Â
*
|
178 |
Â
* @return array Data sent to heartbeat tick
|
179 |
Â
*/
|
180 |
Â
public function heartbeat_received( $response, $data ) {
|
181 |
+
// Only fire when Stream is requesting a live update.
|
182 |
Â
if ( ! isset( $data['wp-stream-heartbeat'] ) ) {
|
183 |
Â
return $response;
|
184 |
Â
}
|
185 |
Â
|
186 |
Â
$enable_stream_update = ( 'off' !== $this->plugin->admin->get_user_meta( get_current_user_id(), $this->user_meta_key ) );
|
187 |
Â
|
188 |
+
// Register list table.
|
189 |
Â
$this->list_table = new List_Table(
|
190 |
Â
$this->plugin,
|
191 |
Â
array(
|
199 |
Â
|
200 |
Â
if ( isset( $data['wp-stream-heartbeat'] ) && isset( $total_items ) ) {
|
201 |
Â
$response['total_items'] = $total_items;
|
202 |
+
/* translators: %d: number of items (e.g. "42") */
|
203 |
Â
$response['total_items_i18n'] = sprintf( _n( '%d item', '%d items', $total_items ), number_format_i18n( $total_items ) );
|
204 |
Â
}
|
205 |
Â
|
classes/class-log.php
CHANGED
@@ -1,11 +1,19 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
|
3 |
Â
namespace WP_Stream;
|
4 |
Â
|
Â
|
|
Â
|
|
Â
|
|
5 |
Â
class Log {
|
6 |
Â
|
7 |
Â
/**
|
8 |
-
*
|
9 |
Â
*
|
10 |
Â
* @var Plugin
|
11 |
Â
*/
|
@@ -29,7 +37,7 @@ class Log {
|
|
29 |
Â
/**
|
30 |
Â
* Class constructor.
|
31 |
Â
*
|
32 |
-
* @param Plugin $plugin
|
33 |
Â
*/
|
34 |
Â
public function __construct( $plugin ) {
|
35 |
Â
$this->plugin = $plugin;
|
@@ -146,7 +154,7 @@ class Log {
|
|
146 |
Â
$result = $this->plugin->db->insert( $recordarr );
|
147 |
Â
|
148 |
Â
// This is helpful in development environments:
|
149 |
-
// error_log( $this->debug_backtrace( $recordarr ) )
|
150 |
Â
|
151 |
Â
return $result;
|
152 |
Â
}
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Handles top-level record keeping functionality.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
Â
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Log
|
12 |
+
*/
|
13 |
Â
class Log {
|
14 |
Â
|
15 |
Â
/**
|
16 |
+
* Holds Instance of plugin object
|
17 |
Â
*
|
18 |
Â
* @var Plugin
|
19 |
Â
*/
|
37 |
Â
/**
|
38 |
Â
* Class constructor.
|
39 |
Â
*
|
40 |
+
* @param Plugin $plugin Instance of plugin object.
|
41 |
Â
*/
|
42 |
Â
public function __construct( $plugin ) {
|
43 |
Â
$this->plugin = $plugin;
|
154 |
Â
$result = $this->plugin->db->insert( $recordarr );
|
155 |
Â
|
156 |
Â
// This is helpful in development environments:
|
157 |
+
// error_log( $this->debug_backtrace( $recordarr ) );.
|
158 |
Â
|
159 |
Â
return $result;
|
160 |
Â
}
|
classes/class-network.php
CHANGED
@@ -1,32 +1,57 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Network {
|
5 |
Â
/**
|
6 |
-
*
|
7 |
Â
*
|
8 |
Â
* @var Plugin
|
9 |
Â
*/
|
10 |
Â
public $plugin;
|
11 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
12 |
Â
public $network_settings_page_slug = 'wp_stream_network_settings';
|
13 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
14 |
Â
public $default_settings_page_slug = 'wp_stream_default_settings';
|
15 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
16 |
Â
public function __construct( $plugin ) {
|
17 |
Â
$this->plugin = $plugin;
|
18 |
Â
|
19 |
-
// Always add default site_id/blog_id params when multisite
|
20 |
Â
if ( is_multisite() ) {
|
21 |
Â
add_filter( 'wp_stream_query_args', array( $this, 'network_query_args' ) );
|
22 |
Â
}
|
23 |
Â
|
24 |
-
// Bail early if not network-activated
|
25 |
Â
if ( ! $this->is_network_activated() ) {
|
26 |
Â
return;
|
27 |
Â
}
|
28 |
Â
|
29 |
-
// Actions
|
30 |
Â
add_action( 'init', array( $this, 'ajax_network_admin' ) );
|
31 |
Â
add_action( 'network_admin_menu', array( $this->plugin->admin, 'register_menu' ) );
|
32 |
Â
add_action( 'network_admin_menu', array( $this, 'admin_menu_screens' ) );
|
@@ -36,7 +61,7 @@ class Network {
|
|
36 |
Â
add_action( 'wpmuadminedit', array( $this, 'network_options_action' ) );
|
37 |
Â
add_action( 'update_site_option_' . $this->plugin->settings->network_options_key, array( $this, 'updated_option_ttl_remove_records' ), 10, 3 );
|
38 |
Â
|
39 |
-
// Filters
|
40 |
Â
add_filter( 'wp_stream_blog_id_logged', array( $this, 'blog_id_logged' ) );
|
41 |
Â
add_filter( 'wp_stream_admin_page_title', array( $this, 'network_admin_page_title' ) );
|
42 |
Â
add_filter( 'wp_stream_list_table_screen_id', array( $this, 'list_table_screen_id' ) );
|
@@ -101,7 +126,7 @@ class Network {
|
|
101 |
Â
*
|
102 |
Â
* @action admin_bar_menu
|
103 |
Â
*
|
104 |
-
* @param object $admin_bar
|
105 |
Â
*
|
106 |
Â
* @return void
|
107 |
Â
*/
|
@@ -128,7 +153,7 @@ class Network {
|
|
128 |
Â
}
|
129 |
Â
|
130 |
Â
/**
|
131 |
-
* Add Network Settings and Default Settings menu
|
132 |
Â
*
|
133 |
Â
* @return array
|
134 |
Â
*/
|
@@ -153,9 +178,9 @@ class Network {
|
|
153 |
Â
/**
|
154 |
Â
* Remove records when records TTL is shortened
|
155 |
Â
*
|
156 |
-
* @param string $option_key
|
157 |
-
* @param array $
|
158 |
-
* @param array $
|
159 |
Â
*
|
160 |
Â
* @action update_option_wp_stream
|
161 |
Â
* @return void
|
@@ -168,7 +193,7 @@ class Network {
|
|
168 |
Â
/**
|
169 |
Â
* Adjust the action of the settings form when in the Network Admin
|
170 |
Â
*
|
171 |
-
* @param $action
|
172 |
Â
*
|
173 |
Â
* @return string
|
174 |
Â
*/
|
@@ -189,7 +214,7 @@ class Network {
|
|
189 |
Â
/**
|
190 |
Â
* Add a description to each of the Settings pages in the Network Admin
|
191 |
Â
*
|
192 |
-
* @param $description
|
193 |
Â
*
|
194 |
Â
* @return string
|
195 |
Â
*/
|
@@ -215,7 +240,7 @@ class Network {
|
|
215 |
Â
/**
|
216 |
Â
* Adjusts the settings fields displayed in various network admin screens
|
217 |
Â
*
|
218 |
-
* @param $fields
|
219 |
Â
*
|
220 |
Â
* @return mixed
|
221 |
Â
*/
|
@@ -254,7 +279,7 @@ class Network {
|
|
254 |
Â
)
|
255 |
Â
);
|
256 |
Â
|
257 |
-
// Remove settings based on context
|
258 |
Â
if ( $this->plugin->settings->network_options_key === $this->plugin->settings->option_key ) {
|
259 |
Â
$hidden_options = $network_hidden_options;
|
260 |
Â
} else {
|
@@ -273,7 +298,7 @@ class Network {
|
|
273 |
Â
}
|
274 |
Â
}
|
275 |
Â
|
276 |
-
// Add settings based on context
|
277 |
Â
if ( $this->plugin->settings->network_options_key === $this->plugin->settings->option_key ) {
|
278 |
Â
$new_fields['general']['fields'][] = array(
|
279 |
Â
'name' => 'site_access',
|
@@ -287,7 +312,7 @@ class Network {
|
|
287 |
Â
$fields = array_merge_recursive( $new_fields, $fields );
|
288 |
Â
}
|
289 |
Â
|
290 |
-
// Remove empty settings sections
|
291 |
Â
foreach ( $fields as $section_key => $section ) {
|
292 |
Â
if ( empty( $section['fields'] ) ) {
|
293 |
Â
unset( $fields[ $section_key ] );
|
@@ -302,6 +327,8 @@ class Network {
|
|
302 |
Â
*
|
303 |
Â
* @filter wp_stream_serialized_labels
|
304 |
Â
*
|
Â
|
|
Â
|
|
305 |
Â
* @return array Multidimensional array of fields
|
306 |
Â
*/
|
307 |
Â
public function get_settings_translations( $labels ) {
|
@@ -329,11 +356,13 @@ class Network {
|
|
329 |
Â
$this->default_settings_page_slug,
|
330 |
Â
);
|
331 |
Â
|
332 |
-
|
Â
|
|
333 |
Â
return;
|
334 |
Â
}
|
335 |
Â
|
336 |
-
|
Â
|
|
337 |
Â
|
338 |
Â
if ( $options ) {
|
339 |
Â
|
@@ -372,7 +401,7 @@ class Network {
|
|
372 |
Â
|
373 |
Â
$go_back = add_query_arg( 'settings-updated', 'true', wp_get_referer() );
|
374 |
Â
|
375 |
-
|
376 |
Â
|
377 |
Â
exit;
|
378 |
Â
}
|
@@ -382,7 +411,7 @@ class Network {
|
|
382 |
Â
*
|
383 |
Â
* @filter wp_stream_list_table_filters
|
384 |
Â
*
|
385 |
-
* @param $filters
|
386 |
Â
*
|
387 |
Â
* @return array
|
388 |
Â
*/
|
@@ -393,7 +422,7 @@ class Network {
|
|
393 |
Â
|
394 |
Â
$blogs = array();
|
395 |
Â
|
396 |
-
// Display network blog as the first option
|
397 |
Â
$network_blog = $this->get_network_blog();
|
398 |
Â
|
399 |
Â
$blogs[ $network_blog->blog_id ] = array(
|
@@ -401,7 +430,7 @@ class Network {
|
|
401 |
Â
'disabled' => '',
|
402 |
Â
);
|
403 |
Â
|
404 |
-
//
|
405 |
Â
foreach ( wp_stream_get_sites() as $blog ) {
|
406 |
Â
$blog_data = get_blog_details( $blog->blog_id );
|
407 |
Â
|
@@ -422,7 +451,7 @@ class Network {
|
|
422 |
Â
/**
|
423 |
Â
* Add the Site toggle to screen options in network admin
|
424 |
Â
*
|
425 |
-
* @param $filters
|
426 |
Â
*
|
427 |
Â
* @return array
|
428 |
Â
*/
|
@@ -437,7 +466,7 @@ class Network {
|
|
437 |
Â
/**
|
438 |
Â
* Add the network suffix to the $screen_id when in the network admin
|
439 |
Â
*
|
440 |
-
* @param $screen_id
|
441 |
Â
*
|
442 |
Â
* @return string
|
443 |
Â
*/
|
@@ -454,6 +483,8 @@ class Network {
|
|
454 |
Â
/**
|
455 |
Â
* Set blog_id for network admin activity
|
456 |
Â
*
|
Â
|
|
Â
|
|
457 |
Â
* @return int
|
458 |
Â
*/
|
459 |
Â
public function blog_id_logged( $blog_id ) {
|
@@ -465,7 +496,7 @@ class Network {
|
|
465 |
Â
*
|
466 |
Â
* @filter wp_stream_query_args
|
467 |
Â
*
|
468 |
-
* @param array $args
|
469 |
Â
*
|
470 |
Â
* @return array
|
471 |
Â
*/
|
@@ -481,13 +512,13 @@ class Network {
|
|
481 |
Â
*
|
482 |
Â
* @filter wp_stream_admin_page_title
|
483 |
Â
*
|
484 |
-
* @param string $page_title
|
485 |
Â
*
|
486 |
Â
* @return string
|
487 |
Â
*/
|
488 |
Â
public function network_admin_page_title( $page_title ) {
|
489 |
Â
if ( is_network_admin() ) {
|
490 |
-
|
491 |
Â
$site_count = sprintf( _n( '%d site', '%d sites', get_blog_count(), 'stream' ), number_format( get_blog_count() ) );
|
492 |
Â
$page_title = sprintf( '%s (%s)', $page_title, $site_count );
|
493 |
Â
}
|
@@ -498,7 +529,7 @@ class Network {
|
|
498 |
Â
/**
|
499 |
Â
* Add the Site column to the network stream records
|
500 |
Â
*
|
501 |
-
* @param $columns
|
502 |
Â
*
|
503 |
Â
* @return mixed
|
504 |
Â
*/
|
@@ -519,7 +550,7 @@ class Network {
|
|
519 |
Â
/**
|
520 |
Â
* Prevent the Blogs connector from loading when not in Network Admin
|
521 |
Â
*
|
522 |
-
* @param $connectors
|
523 |
Â
*
|
524 |
Â
* @return mixed
|
525 |
Â
*/
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Manages functionality for the Stream Admin pages on both
|
4 |
+
* single and multi-sites.
|
5 |
+
*
|
6 |
+
* @package WP_Stream
|
7 |
+
*/
|
8 |
+
|
9 |
Â
namespace WP_Stream;
|
10 |
Â
|
11 |
+
/**
|
12 |
+
* Class - Network
|
13 |
+
*/
|
14 |
Â
class Network {
|
15 |
Â
/**
|
16 |
+
* Holds instance of plugin object
|
17 |
Â
*
|
18 |
Â
* @var Plugin
|
19 |
Â
*/
|
20 |
Â
public $plugin;
|
21 |
Â
|
22 |
+
/**
|
23 |
+
* Network page slug
|
24 |
+
*
|
25 |
+
* @var string
|
26 |
+
*/
|
27 |
Â
public $network_settings_page_slug = 'wp_stream_network_settings';
|
28 |
Â
|
29 |
+
/**
|
30 |
+
* Default setting page slug
|
31 |
+
*
|
32 |
+
* @var string
|
33 |
+
*/
|
34 |
Â
public $default_settings_page_slug = 'wp_stream_default_settings';
|
35 |
Â
|
36 |
+
/**
|
37 |
+
* Class constructor
|
38 |
+
*
|
39 |
+
* @param Plugin $plugin Instance of plugin object.
|
40 |
+
*/
|
41 |
Â
public function __construct( $plugin ) {
|
42 |
Â
$this->plugin = $plugin;
|
43 |
Â
|
44 |
+
// Always add default site_id/blog_id params when multisite.
|
45 |
Â
if ( is_multisite() ) {
|
46 |
Â
add_filter( 'wp_stream_query_args', array( $this, 'network_query_args' ) );
|
47 |
Â
}
|
48 |
Â
|
49 |
+
// Bail early if not network-activated.
|
50 |
Â
if ( ! $this->is_network_activated() ) {
|
51 |
Â
return;
|
52 |
Â
}
|
53 |
Â
|
54 |
+
// Actions.
|
55 |
Â
add_action( 'init', array( $this, 'ajax_network_admin' ) );
|
56 |
Â
add_action( 'network_admin_menu', array( $this->plugin->admin, 'register_menu' ) );
|
57 |
Â
add_action( 'network_admin_menu', array( $this, 'admin_menu_screens' ) );
|
61 |
Â
add_action( 'wpmuadminedit', array( $this, 'network_options_action' ) );
|
62 |
Â
add_action( 'update_site_option_' . $this->plugin->settings->network_options_key, array( $this, 'updated_option_ttl_remove_records' ), 10, 3 );
|
63 |
Â
|
64 |
+
// Filters.
|
65 |
Â
add_filter( 'wp_stream_blog_id_logged', array( $this, 'blog_id_logged' ) );
|
66 |
Â
add_filter( 'wp_stream_admin_page_title', array( $this, 'network_admin_page_title' ) );
|
67 |
Â
add_filter( 'wp_stream_list_table_screen_id', array( $this, 'list_table_screen_id' ) );
|
126 |
Â
*
|
127 |
Â
* @action admin_bar_menu
|
128 |
Â
*
|
129 |
+
* @param object $admin_bar Admin bar object.
|
130 |
Â
*
|
131 |
Â
* @return void
|
132 |
Â
*/
|
153 |
Â
}
|
154 |
Â
|
155 |
Â
/**
|
156 |
+
* Add Network Settings and Default Settings menu pages
|
157 |
Â
*
|
158 |
Â
* @return array
|
159 |
Â
*/
|
178 |
Â
/**
|
179 |
Â
* Remove records when records TTL is shortened
|
180 |
Â
*
|
181 |
+
* @param string $option_key Unused.
|
182 |
+
* @param array $new_value New value.
|
183 |
+
* @param array $old_value Old value.
|
184 |
Â
*
|
185 |
Â
* @action update_option_wp_stream
|
186 |
Â
* @return void
|
193 |
Â
/**
|
194 |
Â
* Adjust the action of the settings form when in the Network Admin
|
195 |
Â
*
|
196 |
+
* @param string $action Query string.
|
197 |
Â
*
|
198 |
Â
* @return string
|
199 |
Â
*/
|
214 |
Â
/**
|
215 |
Â
* Add a description to each of the Settings pages in the Network Admin
|
216 |
Â
*
|
217 |
+
* @param string $description Description of the current page.
|
218 |
Â
*
|
219 |
Â
* @return string
|
220 |
Â
*/
|
240 |
Â
/**
|
241 |
Â
* Adjusts the settings fields displayed in various network admin screens
|
242 |
Â
*
|
243 |
+
* @param array $fields Page settings fields.
|
244 |
Â
*
|
245 |
Â
* @return mixed
|
246 |
Â
*/
|
279 |
Â
)
|
280 |
Â
);
|
281 |
Â
|
282 |
+
// Remove settings based on context.
|
283 |
Â
if ( $this->plugin->settings->network_options_key === $this->plugin->settings->option_key ) {
|
284 |
Â
$hidden_options = $network_hidden_options;
|
285 |
Â
} else {
|
298 |
Â
}
|
299 |
Â
}
|
300 |
Â
|
301 |
+
// Add settings based on context.
|
302 |
Â
if ( $this->plugin->settings->network_options_key === $this->plugin->settings->option_key ) {
|
303 |
Â
$new_fields['general']['fields'][] = array(
|
304 |
Â
'name' => 'site_access',
|
312 |
Â
$fields = array_merge_recursive( $new_fields, $fields );
|
313 |
Â
}
|
314 |
Â
|
315 |
+
// Remove empty settings sections.
|
316 |
Â
foreach ( $fields as $section_key => $section ) {
|
317 |
Â
if ( empty( $section['fields'] ) ) {
|
318 |
Â
unset( $fields[ $section_key ] );
|
327 |
Â
*
|
328 |
Â
* @filter wp_stream_serialized_labels
|
329 |
Â
*
|
330 |
+
* @param array $labels Setting labels.
|
331 |
+
*
|
332 |
Â
* @return array Multidimensional array of fields
|
333 |
Â
*/
|
334 |
Â
public function get_settings_translations( $labels ) {
|
356 |
Â
$this->default_settings_page_slug,
|
357 |
Â
);
|
358 |
Â
|
359 |
+
// @codingStandardsIgnoreLine
|
360 |
+
if ( ! isset( $_GET['action'] ) || ! in_array( $_GET['action'], $allowed_referers, true ) ) {
|
361 |
Â
return;
|
362 |
Â
}
|
363 |
Â
|
364 |
+
// @codingStandardsIgnoreLine
|
365 |
+
$options = isset( $_POST['option_page'] ) ? explode( ',', stripslashes( $_POST['option_page'] ) ) : null;
|
366 |
Â
|
367 |
Â
if ( $options ) {
|
368 |
Â
|
401 |
Â
|
402 |
Â
$go_back = add_query_arg( 'settings-updated', 'true', wp_get_referer() );
|
403 |
Â
|
404 |
+
wp_safe_redirect( $go_back );
|
405 |
Â
|
406 |
Â
exit;
|
407 |
Â
}
|
411 |
Â
*
|
412 |
Â
* @filter wp_stream_list_table_filters
|
413 |
Â
*
|
414 |
+
* @param array $filters Filters.
|
415 |
Â
*
|
416 |
Â
* @return array
|
417 |
Â
*/
|
422 |
Â
|
423 |
Â
$blogs = array();
|
424 |
Â
|
425 |
+
// Display network blog as the first option.
|
426 |
Â
$network_blog = $this->get_network_blog();
|
427 |
Â
|
428 |
Â
$blogs[ $network_blog->blog_id ] = array(
|
430 |
Â
'disabled' => '',
|
431 |
Â
);
|
432 |
Â
|
433 |
+
// Add all sites.
|
434 |
Â
foreach ( wp_stream_get_sites() as $blog ) {
|
435 |
Â
$blog_data = get_blog_details( $blog->blog_id );
|
436 |
Â
|
451 |
Â
/**
|
452 |
Â
* Add the Site toggle to screen options in network admin
|
453 |
Â
*
|
454 |
+
* @param array $filters Filters.
|
455 |
Â
*
|
456 |
Â
* @return array
|
457 |
Â
*/
|
466 |
Â
/**
|
467 |
Â
* Add the network suffix to the $screen_id when in the network admin
|
468 |
Â
*
|
469 |
+
* @param int $screen_id Screen ID.
|
470 |
Â
*
|
471 |
Â
* @return string
|
472 |
Â
*/
|
483 |
Â
/**
|
484 |
Â
* Set blog_id for network admin activity
|
485 |
Â
*
|
486 |
+
* @param int $blog_id Blog ID.
|
487 |
+
*
|
488 |
Â
* @return int
|
489 |
Â
*/
|
490 |
Â
public function blog_id_logged( $blog_id ) {
|
496 |
Â
*
|
497 |
Â
* @filter wp_stream_query_args
|
498 |
Â
*
|
499 |
+
* @param array $args Site arguments.
|
500 |
Â
*
|
501 |
Â
* @return array
|
502 |
Â
*/
|
512 |
Â
*
|
513 |
Â
* @filter wp_stream_admin_page_title
|
514 |
Â
*
|
515 |
+
* @param string $page_title Page title.
|
516 |
Â
*
|
517 |
Â
* @return string
|
518 |
Â
*/
|
519 |
Â
public function network_admin_page_title( $page_title ) {
|
520 |
Â
if ( is_network_admin() ) {
|
521 |
+
/* translators: %d: number of sites on the network (e.g. "42") */
|
522 |
Â
$site_count = sprintf( _n( '%d site', '%d sites', get_blog_count(), 'stream' ), number_format( get_blog_count() ) );
|
523 |
Â
$page_title = sprintf( '%s (%s)', $page_title, $site_count );
|
524 |
Â
}
|
529 |
Â
/**
|
530 |
Â
* Add the Site column to the network stream records
|
531 |
Â
*
|
532 |
+
* @param array $columns Columns data.
|
533 |
Â
*
|
534 |
Â
* @return mixed
|
535 |
Â
*/
|
550 |
Â
/**
|
551 |
Â
* Prevent the Blogs connector from loading when not in Network Admin
|
552 |
Â
*
|
553 |
+
* @param array $connectors Connectors.
|
554 |
Â
*
|
555 |
Â
* @return mixed
|
556 |
Â
*/
|
classes/class-plugin.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Plugin {
|
5 |
Â
/**
|
6 |
Â
* Plugin version number.
|
@@ -9,7 +18,7 @@ class Plugin {
|
|
9 |
Â
*
|
10 |
Â
* @const string
|
11 |
Â
*/
|
12 |
-
const VERSION = '3.
|
13 |
Â
|
14 |
Â
/**
|
15 |
Â
* WP-CLI command
|
@@ -19,41 +28,57 @@ class Plugin {
|
|
19 |
Â
const WP_CLI_COMMAND = 'stream';
|
20 |
Â
|
21 |
Â
/**
|
Â
|
|
Â
|
|
22 |
Â
* @var Admin
|
23 |
Â
*/
|
24 |
Â
public $admin;
|
25 |
Â
|
26 |
Â
/**
|
Â
|
|
Â
|
|
27 |
Â
* @var Alerts
|
28 |
Â
*/
|
29 |
Â
public $alerts;
|
30 |
Â
|
31 |
Â
/**
|
Â
|
|
Â
|
|
32 |
Â
* @var Alerts_List
|
33 |
Â
*/
|
34 |
Â
public $alerts_list;
|
35 |
Â
|
36 |
Â
/**
|
Â
|
|
Â
|
|
37 |
Â
* @var Connectors
|
38 |
Â
*/
|
39 |
Â
public $connectors;
|
40 |
Â
|
41 |
Â
/**
|
Â
|
|
Â
|
|
42 |
Â
* @var DB
|
43 |
Â
*/
|
44 |
Â
public $db;
|
45 |
Â
|
46 |
Â
/**
|
Â
|
|
Â
|
|
47 |
Â
* @var Log
|
48 |
Â
*/
|
49 |
Â
public $log;
|
50 |
Â
|
51 |
Â
/**
|
Â
|
|
Â
|
|
52 |
Â
* @var Settings
|
53 |
Â
*/
|
54 |
Â
public $settings;
|
55 |
Â
|
56 |
Â
/**
|
Â
|
|
Â
|
|
57 |
Â
* @var Install
|
58 |
Â
*/
|
59 |
Â
public $install;
|
@@ -81,10 +106,10 @@ class Plugin {
|
|
81 |
Â
|
82 |
Â
spl_autoload_register( array( $this, 'autoload' ) );
|
83 |
Â
|
84 |
-
// Load helper functions
|
85 |
Â
require_once $this->locations['inc_dir'] . 'functions.php';
|
86 |
Â
|
87 |
-
// Load DB helper interface/class
|
88 |
Â
$driver_class = apply_filters( 'wp_stream_db_driver', '\WP_Stream\DB_Driver_WPDB' );
|
89 |
Â
$driver = null;
|
90 |
Â
|
@@ -107,22 +132,22 @@ class Plugin {
|
|
107 |
Â
);
|
108 |
Â
}
|
109 |
Â
|
110 |
-
// Load languages
|
111 |
Â
add_action( 'plugins_loaded', array( $this, 'i18n' ) );
|
112 |
Â
|
113 |
-
// Load logger class
|
114 |
Â
$this->log = apply_filters( 'wp_stream_log_handler', new Log( $this ) );
|
115 |
Â
|
116 |
-
// Load settings and connectors after widgets_init and before the default init priority
|
117 |
Â
add_action( 'init', array( $this, 'init' ), 9 );
|
118 |
Â
|
119 |
-
// Add frontend indicator
|
120 |
Â
add_action( 'wp_head', array( $this, 'frontend_indicator' ) );
|
121 |
Â
|
122 |
-
// Change DB driver after plugin loaded if any add-ons want to replace
|
123 |
Â
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 20 );
|
124 |
Â
|
125 |
-
// Load admin area classes
|
126 |
Â
if ( is_admin() || ( defined( 'WP_STREAM_DEV_DEBUG' ) && WP_STREAM_DEV_DEBUG ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
|
127 |
Â
$this->admin = new Admin( $this );
|
128 |
Â
$this->install = $driver->setup_storage( $this );
|
@@ -130,7 +155,7 @@ class Plugin {
|
|
130 |
Â
$this->admin = new Admin( $this, $driver );
|
131 |
Â
}
|
132 |
Â
|
133 |
-
// Load WP-CLI command
|
134 |
Â
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
135 |
Â
\WP_CLI::add_command( self::WP_CLI_COMMAND, 'WP_Stream\CLI' );
|
136 |
Â
}
|
@@ -139,7 +164,7 @@ class Plugin {
|
|
139 |
Â
/**
|
140 |
Â
* Autoloader for classes
|
141 |
Â
*
|
142 |
-
* @param string $class
|
143 |
Â
*/
|
144 |
Â
public function autoload( $class ) {
|
145 |
Â
if ( ! preg_match( '/^(?P<namespace>.+)\\\\(?P<autoload>[^\\\\]+)$/', $class, $matches ) ) {
|
@@ -174,7 +199,7 @@ class Plugin {
|
|
174 |
Â
load_plugin_textdomain( 'stream', false, dirname( $this->locations['plugin'] ) . '/languages/' );
|
175 |
Â
}
|
176 |
Â
|
177 |
-
|
178 |
Â
* Load Settings, Notifications, and Connectors
|
179 |
Â
*
|
180 |
Â
* @action init
|
@@ -196,7 +221,8 @@ class Plugin {
|
|
196 |
Â
* @return string|void An HTML comment, or nothing if the value is filtered out.
|
197 |
Â
*/
|
198 |
Â
public function frontend_indicator() {
|
199 |
-
|
Â
|
|
200 |
Â
|
201 |
Â
/**
|
202 |
Â
* Filter allows the HTML output of the frontend indicator comment
|
@@ -207,7 +233,7 @@ class Plugin {
|
|
207 |
Â
$comment = apply_filters( 'wp_stream_frontend_indicator', $comment );
|
208 |
Â
|
209 |
Â
if ( ! empty( $comment ) ) {
|
210 |
-
echo sprintf( "<!-- %s -->\n", esc_html( $comment ) ); // xss ok
|
211 |
Â
}
|
212 |
Â
}
|
213 |
Â
|
@@ -215,8 +241,6 @@ class Plugin {
|
|
215 |
Â
* Version of plugin_dir_url() which works for plugins installed in the plugins directory,
|
216 |
Â
* and for plugins bundled with themes.
|
217 |
Â
*
|
218 |
-
* @throws \Exception
|
219 |
-
*
|
220 |
Â
* @return array
|
221 |
Â
*/
|
222 |
Â
private function locate_plugin() {
|
@@ -241,7 +265,7 @@ class Plugin {
|
|
241 |
Â
* Change plugin database driver in case driver plugin loaded after stream
|
242 |
Â
*/
|
243 |
Â
public function plugins_loaded() {
|
244 |
-
// Load DB helper interface/class
|
245 |
Â
$driver_class = apply_filters( 'wp_stream_db_driver', '\WP_Stream\DB_Driver_WPDB' );
|
246 |
Â
|
247 |
Â
if ( class_exists( $driver_class ) ) {
|
@@ -271,8 +295,8 @@ class Plugin {
|
|
271 |
Â
/**
|
272 |
Â
* Filter allows the network activated detection to be overridden.
|
273 |
Â
*
|
274 |
-
* @param string
|
275 |
-
* @param WP_Stream\Plugin $plugin
|
276 |
Â
*/
|
277 |
Â
return apply_filters( 'wp_stream_is_network_activated', $is_network_activated, $this );
|
278 |
Â
}
|
@@ -283,7 +307,6 @@ class Plugin {
|
|
283 |
Â
* @return bool
|
284 |
Â
*/
|
285 |
Â
public function is_mustuse() {
|
286 |
-
|
287 |
Â
$stream_php = trailingslashit( WPMU_PLUGIN_DIR ) . $this->locations['plugin'];
|
288 |
Â
|
289 |
Â
if ( file_exists( $stream_php ) && class_exists( 'WP_Stream\Plugin' ) ) {
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Initializes plugin
|
4 |
+
*
|
5 |
+
* @package WP_Stream;
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class Plugin
|
12 |
+
*/
|
13 |
Â
class Plugin {
|
14 |
Â
/**
|
15 |
Â
* Plugin version number.
|
18 |
Â
*
|
19 |
Â
* @const string
|
20 |
Â
*/
|
21 |
+
const VERSION = '3.5.0';
|
22 |
Â
|
23 |
Â
/**
|
24 |
Â
* WP-CLI command
|
28 |
Â
const WP_CLI_COMMAND = 'stream';
|
29 |
Â
|
30 |
Â
/**
|
31 |
+
* Holds and manages WordPress Admin configurations.
|
32 |
+
*
|
33 |
Â
* @var Admin
|
34 |
Â
*/
|
35 |
Â
public $admin;
|
36 |
Â
|
37 |
Â
/**
|
38 |
+
* Holds and manages alerts.
|
39 |
+
*
|
40 |
Â
* @var Alerts
|
41 |
Â
*/
|
42 |
Â
public $alerts;
|
43 |
Â
|
44 |
Â
/**
|
45 |
+
* Holds and manages alerts lists.
|
46 |
+
*
|
47 |
Â
* @var Alerts_List
|
48 |
Â
*/
|
49 |
Â
public $alerts_list;
|
50 |
Â
|
51 |
Â
/**
|
52 |
+
* Holds and manages connectors
|
53 |
+
*
|
54 |
Â
* @var Connectors
|
55 |
Â
*/
|
56 |
Â
public $connectors;
|
57 |
Â
|
58 |
Â
/**
|
59 |
+
* Holds and manages DB connections.
|
60 |
+
*
|
61 |
Â
* @var DB
|
62 |
Â
*/
|
63 |
Â
public $db;
|
64 |
Â
|
65 |
Â
/**
|
66 |
+
* Holds and manages records.
|
67 |
+
*
|
68 |
Â
* @var Log
|
69 |
Â
*/
|
70 |
Â
public $log;
|
71 |
Â
|
72 |
Â
/**
|
73 |
+
* Stores and manages WordPress settings.
|
74 |
+
*
|
75 |
Â
* @var Settings
|
76 |
Â
*/
|
77 |
Â
public $settings;
|
78 |
Â
|
79 |
Â
/**
|
80 |
+
* Process DB migrations.
|
81 |
+
*
|
82 |
Â
* @var Install
|
83 |
Â
*/
|
84 |
Â
public $install;
|
106 |
Â
|
107 |
Â
spl_autoload_register( array( $this, 'autoload' ) );
|
108 |
Â
|
109 |
+
// Load helper functions.
|
110 |
Â
require_once $this->locations['inc_dir'] . 'functions.php';
|
111 |
Â
|
112 |
+
// Load DB helper interface/class.
|
113 |
Â
$driver_class = apply_filters( 'wp_stream_db_driver', '\WP_Stream\DB_Driver_WPDB' );
|
114 |
Â
$driver = null;
|
115 |
Â
|
132 |
Â
);
|
133 |
Â
}
|
134 |
Â
|
135 |
+
// Load languages.
|
136 |
Â
add_action( 'plugins_loaded', array( $this, 'i18n' ) );
|
137 |
Â
|
138 |
+
// Load logger class.
|
139 |
Â
$this->log = apply_filters( 'wp_stream_log_handler', new Log( $this ) );
|
140 |
Â
|
141 |
+
// Load settings and connectors after widgets_init and before the default init priority.
|
142 |
Â
add_action( 'init', array( $this, 'init' ), 9 );
|
143 |
Â
|
144 |
+
// Add frontend indicator.
|
145 |
Â
add_action( 'wp_head', array( $this, 'frontend_indicator' ) );
|
146 |
Â
|
147 |
+
// Change DB driver after plugin loaded if any add-ons want to replace.
|
148 |
Â
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 20 );
|
149 |
Â
|
150 |
+
// Load admin area classes.
|
151 |
Â
if ( is_admin() || ( defined( 'WP_STREAM_DEV_DEBUG' ) && WP_STREAM_DEV_DEBUG ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
|
152 |
Â
$this->admin = new Admin( $this );
|
153 |
Â
$this->install = $driver->setup_storage( $this );
|
155 |
Â
$this->admin = new Admin( $this, $driver );
|
156 |
Â
}
|
157 |
Â
|
158 |
+
// Load WP-CLI command.
|
159 |
Â
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
160 |
Â
\WP_CLI::add_command( self::WP_CLI_COMMAND, 'WP_Stream\CLI' );
|
161 |
Â
}
|
164 |
Â
/**
|
165 |
Â
* Autoloader for classes
|
166 |
Â
*
|
167 |
+
* @param string $class Fully qualified classname to be loaded.
|
168 |
Â
*/
|
169 |
Â
public function autoload( $class ) {
|
170 |
Â
if ( ! preg_match( '/^(?P<namespace>.+)\\\\(?P<autoload>[^\\\\]+)$/', $class, $matches ) ) {
|
199 |
Â
load_plugin_textdomain( 'stream', false, dirname( $this->locations['plugin'] ) . '/languages/' );
|
200 |
Â
}
|
201 |
Â
|
202 |
+
/**
|
203 |
Â
* Load Settings, Notifications, and Connectors
|
204 |
Â
*
|
205 |
Â
* @action init
|
221 |
Â
* @return string|void An HTML comment, or nothing if the value is filtered out.
|
222 |
Â
*/
|
223 |
Â
public function frontend_indicator() {
|
224 |
+
/* translators: Localization not needed */
|
225 |
+
$comment = sprintf( 'Stream WordPress user activity plugin v%s', esc_html( $this->get_version() ) );
|
226 |
Â
|
227 |
Â
/**
|
228 |
Â
* Filter allows the HTML output of the frontend indicator comment
|
233 |
Â
$comment = apply_filters( 'wp_stream_frontend_indicator', $comment );
|
234 |
Â
|
235 |
Â
if ( ! empty( $comment ) ) {
|
236 |
+
echo sprintf( "<!-- %s -->\n", esc_html( $comment ) ); // xss ok.
|
237 |
Â
}
|
238 |
Â
}
|
239 |
Â
|
241 |
Â
* Version of plugin_dir_url() which works for plugins installed in the plugins directory,
|
242 |
Â
* and for plugins bundled with themes.
|
243 |
Â
*
|
Â
|
|
Â
|
|
244 |
Â
* @return array
|
245 |
Â
*/
|
246 |
Â
private function locate_plugin() {
|
265 |
Â
* Change plugin database driver in case driver plugin loaded after stream
|
266 |
Â
*/
|
267 |
Â
public function plugins_loaded() {
|
268 |
+
// Load DB helper interface/class.
|
269 |
Â
$driver_class = apply_filters( 'wp_stream_db_driver', '\WP_Stream\DB_Driver_WPDB' );
|
270 |
Â
|
271 |
Â
if ( class_exists( $driver_class ) ) {
|
295 |
Â
/**
|
296 |
Â
* Filter allows the network activated detection to be overridden.
|
297 |
Â
*
|
298 |
+
* @param string $is_network_activated Whether the plugin is network activated.
|
299 |
+
* @param WP_Stream\Plugin $plugin The stream plugin object.
|
300 |
Â
*/
|
301 |
Â
return apply_filters( 'wp_stream_is_network_activated', $is_network_activated, $this );
|
302 |
Â
}
|
307 |
Â
* @return bool
|
308 |
Â
*/
|
309 |
Â
public function is_mustuse() {
|
Â
|
|
310 |
Â
$stream_php = trailingslashit( WPMU_PLUGIN_DIR ) . $this->locations['plugin'];
|
311 |
Â
|
312 |
Â
if ( file_exists( $stream_php ) && class_exists( 'WP_Stream\Plugin' ) ) {
|
classes/class-preview-list-table.php
CHANGED
@@ -1,7 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
|
3 |
Â
namespace WP_Stream;
|
4 |
Â
|
Â
|
|
Â
|
|
Â
|
|
5 |
Â
class Preview_List_Table extends List_Table {
|
6 |
Â
|
7 |
Â
/**
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Displays a list of provided records in a HTML Table
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
Â
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Preview_List_Table
|
12 |
+
*/
|
13 |
Â
class Preview_List_Table extends List_Table {
|
14 |
Â
|
15 |
Â
/**
|
classes/class-query.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Query {
|
5 |
Â
/**
|
6 |
Â
* Hold the number of records found
|
@@ -12,7 +21,7 @@ class Query {
|
|
12 |
Â
/**
|
13 |
Â
* Query records
|
14 |
Â
*
|
15 |
-
* @param array
|
16 |
Â
*
|
17 |
Â
* @return array Stream Records
|
18 |
Â
*/
|
@@ -48,7 +57,7 @@ class Query {
|
|
48 |
Â
if ( ! empty( $args['search'] ) ) {
|
49 |
Â
$field = ! empty( $args['search_field'] ) ? $args['search_field'] : 'summary';
|
50 |
Â
|
51 |
-
// Sanitize field
|
52 |
Â
$allowed_fields = array( 'ID', 'site_id', 'blog_id', 'object_id', 'user_id', 'user_role', 'created', 'summary', 'connector', 'context', 'action', 'ip' );
|
53 |
Â
if ( in_array( $field, $allowed_fields, true ) ) {
|
54 |
Â
$where .= $wpdb->prepare( " AND $wpdb->stream.{$field} LIKE %s", "%{$args['search']}%" ); // @codingStandardsIgnoreLine can't prepare column name
|
@@ -80,22 +89,22 @@ class Query {
|
|
80 |
Â
}
|
81 |
Â
|
82 |
Â
if ( ! empty( $args['date_from'] ) ) {
|
83 |
-
$date = get_gmt_from_date(
|
84 |
Â
$where .= $wpdb->prepare( " AND DATE($wpdb->stream.created) >= %s", $date );
|
85 |
Â
}
|
86 |
Â
|
87 |
Â
if ( ! empty( $args['date_to'] ) ) {
|
88 |
-
$date = get_gmt_from_date(
|
89 |
Â
$where .= $wpdb->prepare( " AND DATE($wpdb->stream.created) <= %s", $date );
|
90 |
Â
}
|
91 |
Â
|
92 |
Â
if ( ! empty( $args['date_after'] ) ) {
|
93 |
-
$date = get_gmt_from_date(
|
94 |
Â
$where .= $wpdb->prepare( " AND DATE($wpdb->stream.created) > %s", $date );
|
95 |
Â
}
|
96 |
Â
|
97 |
Â
if ( ! empty( $args['date_before'] ) ) {
|
98 |
-
$date = get_gmt_from_date(
|
99 |
Â
$where .= $wpdb->prepare( " AND DATE($wpdb->stream.created) < %s", $date );
|
100 |
Â
}
|
101 |
Â
|
@@ -194,7 +203,7 @@ class Query {
|
|
194 |
Â
|
195 |
Â
if ( ! empty( $fields ) ) {
|
196 |
Â
foreach ( $fields as $field ) {
|
197 |
-
// We'll query the meta table later
|
198 |
Â
if ( 'meta' === $field ) {
|
199 |
Â
continue;
|
200 |
Â
}
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Queries the database for stream records.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Query
|
12 |
+
*/
|
13 |
Â
class Query {
|
14 |
Â
/**
|
15 |
Â
* Hold the number of records found
|
21 |
Â
/**
|
22 |
Â
* Query records
|
23 |
Â
*
|
24 |
+
* @param array $args Arguments to filter the records by.
|
25 |
Â
*
|
26 |
Â
* @return array Stream Records
|
27 |
Â
*/
|
57 |
Â
if ( ! empty( $args['search'] ) ) {
|
58 |
Â
$field = ! empty( $args['search_field'] ) ? $args['search_field'] : 'summary';
|
59 |
Â
|
60 |
+
// Sanitize field.
|
61 |
Â
$allowed_fields = array( 'ID', 'site_id', 'blog_id', 'object_id', 'user_id', 'user_role', 'created', 'summary', 'connector', 'context', 'action', 'ip' );
|
62 |
Â
if ( in_array( $field, $allowed_fields, true ) ) {
|
63 |
Â
$where .= $wpdb->prepare( " AND $wpdb->stream.{$field} LIKE %s", "%{$args['search']}%" ); // @codingStandardsIgnoreLine can't prepare column name
|
89 |
Â
}
|
90 |
Â
|
91 |
Â
if ( ! empty( $args['date_from'] ) ) {
|
92 |
+
$date = get_gmt_from_date( gmdate( 'Y-m-d H:i:s', strtotime( $args['date_from'] . ' 00:00:00' ) ) );
|
93 |
Â
$where .= $wpdb->prepare( " AND DATE($wpdb->stream.created) >= %s", $date );
|
94 |
Â
}
|
95 |
Â
|
96 |
Â
if ( ! empty( $args['date_to'] ) ) {
|
97 |
+
$date = get_gmt_from_date( gmdate( 'Y-m-d H:i:s', strtotime( $args['date_to'] . ' 23:59:59' ) ) );
|
98 |
Â
$where .= $wpdb->prepare( " AND DATE($wpdb->stream.created) <= %s", $date );
|
99 |
Â
}
|
100 |
Â
|
101 |
Â
if ( ! empty( $args['date_after'] ) ) {
|
102 |
+
$date = get_gmt_from_date( gmdate( 'Y-m-d H:i:s', strtotime( $args['date_after'] ) ) );
|
103 |
Â
$where .= $wpdb->prepare( " AND DATE($wpdb->stream.created) > %s", $date );
|
104 |
Â
}
|
105 |
Â
|
106 |
Â
if ( ! empty( $args['date_before'] ) ) {
|
107 |
+
$date = get_gmt_from_date( gmdate( 'Y-m-d H:i:s', strtotime( $args['date_before'] ) ) );
|
108 |
Â
$where .= $wpdb->prepare( " AND DATE($wpdb->stream.created) < %s", $date );
|
109 |
Â
}
|
110 |
Â
|
203 |
Â
|
204 |
Â
if ( ! empty( $fields ) ) {
|
205 |
Â
foreach ( $fields as $field ) {
|
206 |
+
// We'll query the meta table later.
|
207 |
Â
if ( 'meta' === $field ) {
|
208 |
Â
continue;
|
209 |
Â
}
|
classes/class-record.php
CHANGED
@@ -1,22 +1,119 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Record {
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
5 |
Â
public $ID;
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
6 |
Â
public $created;
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
7 |
Â
public $site_id;
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
8 |
Â
public $blog_id;
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
9 |
Â
public $object_id;
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
10 |
Â
public $user_id;
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
11 |
Â
public $user_role;
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
12 |
Â
public $user_meta;
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
13 |
Â
public $summary;
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
14 |
Â
public $connector;
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
15 |
Â
public $context;
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
16 |
Â
public $action;
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
17 |
Â
public $ip;
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
18 |
Â
public $meta;
|
19 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
20 |
Â
public function __construct( $item ) {
|
21 |
Â
$this->ID = isset( $item->ID ) ? $item->ID : null;
|
22 |
Â
$this->created = isset( $item->created ) ? $item->created : null;
|
@@ -38,6 +135,11 @@ class Record {
|
|
38 |
Â
}
|
39 |
Â
}
|
40 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
41 |
Â
public function save() {
|
42 |
Â
if ( ! $this->validate() ) {
|
43 |
Â
return new \WP_Error( 'validation-error', esc_html__( 'Could not validate record data.', 'stream' ) );
|
@@ -46,6 +148,11 @@ class Record {
|
|
46 |
Â
return wp_stream_get_instance()->db->insert( (array) $this );
|
47 |
Â
}
|
48 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
49 |
Â
public function populate( array $raw ) {
|
50 |
Â
$keys = get_class_vars( $this );
|
51 |
Â
$data = array_intersect_key( $raw, $keys );
|
@@ -54,6 +161,13 @@ class Record {
|
|
54 |
Â
}
|
55 |
Â
}
|
56 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
57 |
Â
public function validate() {
|
58 |
Â
return true;
|
59 |
Â
}
|
@@ -61,8 +175,8 @@ class Record {
|
|
61 |
Â
/**
|
62 |
Â
* Query record meta
|
63 |
Â
*
|
64 |
-
* @param string $meta_key (optional)
|
65 |
-
* @param bool $single (optional)
|
66 |
Â
*
|
67 |
Â
* @return array
|
68 |
Â
*/
|
@@ -73,9 +187,9 @@ class Record {
|
|
73 |
Â
/**
|
74 |
Â
* Update record meta
|
75 |
Â
*
|
76 |
-
* @param string $meta_key
|
77 |
-
* @param mixed $meta_value
|
78 |
-
* @param mixed $prev_value (optional)
|
79 |
Â
*
|
80 |
Â
* @return bool
|
81 |
Â
*/
|
@@ -86,8 +200,7 @@ class Record {
|
|
86 |
Â
/**
|
87 |
Â
* Determine the title of an object that a record is for.
|
88 |
Â
*
|
89 |
-
* @
|
90 |
-
* @return mixed The title of the object as a string, otherwise false
|
91 |
Â
*/
|
92 |
Â
public function get_object_title() {
|
93 |
Â
if ( ! isset( $this->object_id ) || empty( $this->object_id ) ) {
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Manages the state of a single record
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Record
|
12 |
+
*/
|
13 |
Â
class Record {
|
14 |
+
/**
|
15 |
+
* Record ID
|
16 |
+
*
|
17 |
+
* @var int
|
18 |
+
*/
|
19 |
Â
public $ID;
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Date record created
|
23 |
+
*
|
24 |
+
* @var string
|
25 |
+
*/
|
26 |
Â
public $created;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Site ID of the site where the record was created
|
30 |
+
*
|
31 |
+
* @var int
|
32 |
+
*/
|
33 |
Â
public $site_id;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Blog ID of the site where the record was created
|
37 |
+
*
|
38 |
+
* @var int
|
39 |
+
*/
|
40 |
Â
public $blog_id;
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Record Object ID
|
44 |
+
*
|
45 |
+
* @var int
|
46 |
+
*/
|
47 |
Â
public $object_id;
|
48 |
+
|
49 |
+
/**
|
50 |
+
* User ID of the record creator
|
51 |
+
*
|
52 |
+
* @var int
|
53 |
+
*/
|
54 |
Â
public $user_id;
|
55 |
+
|
56 |
+
/**
|
57 |
+
* User role of the record creator
|
58 |
+
*
|
59 |
+
* @var string
|
60 |
+
*/
|
61 |
Â
public $user_role;
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Record user meta data.
|
65 |
+
*
|
66 |
+
* @var string
|
67 |
+
*/
|
68 |
Â
public $user_meta;
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Record summary
|
72 |
+
*
|
73 |
+
* @var string
|
74 |
+
*/
|
75 |
Â
public $summary;
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Record connector
|
79 |
+
*
|
80 |
+
* @var string
|
81 |
+
*/
|
82 |
Â
public $connector;
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Context record was made in.
|
86 |
+
*
|
87 |
+
* @var string
|
88 |
+
*/
|
89 |
Â
public $context;
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Record action
|
93 |
+
*
|
94 |
+
* @var string
|
95 |
+
*/
|
96 |
Â
public $action;
|
97 |
+
|
98 |
+
/**
|
99 |
+
* IP of event requestee
|
100 |
+
*
|
101 |
+
* @var string
|
102 |
+
*/
|
103 |
Â
public $ip;
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Record meta data
|
107 |
+
*
|
108 |
+
* @var array
|
109 |
+
*/
|
110 |
Â
public $meta;
|
111 |
Â
|
112 |
+
/**
|
113 |
+
* Class constructor
|
114 |
+
*
|
115 |
+
* @param object $item Record data object.
|
116 |
+
*/
|
117 |
Â
public function __construct( $item ) {
|
118 |
Â
$this->ID = isset( $item->ID ) ? $item->ID : null;
|
119 |
Â
$this->created = isset( $item->created ) ? $item->created : null;
|
135 |
Â
}
|
136 |
Â
}
|
137 |
Â
|
138 |
+
/**
|
139 |
+
* Save record.
|
140 |
+
*
|
141 |
+
* @return int|WP_Error
|
142 |
+
*/
|
143 |
Â
public function save() {
|
144 |
Â
if ( ! $this->validate() ) {
|
145 |
Â
return new \WP_Error( 'validation-error', esc_html__( 'Could not validate record data.', 'stream' ) );
|
148 |
Â
return wp_stream_get_instance()->db->insert( (array) $this );
|
149 |
Â
}
|
150 |
Â
|
151 |
+
/**
|
152 |
+
* Populate "$this" object with provided data.
|
153 |
+
*
|
154 |
+
* @param array $raw Data to be used to populate $this object.
|
155 |
+
*/
|
156 |
Â
public function populate( array $raw ) {
|
157 |
Â
$keys = get_class_vars( $this );
|
158 |
Â
$data = array_intersect_key( $raw, $keys );
|
161 |
Â
}
|
162 |
Â
}
|
163 |
Â
|
164 |
+
/**
|
165 |
+
* Validates this record
|
166 |
+
*
|
167 |
+
* @todo Add actual validation measures.
|
168 |
+
*
|
169 |
+
* @return bool
|
170 |
+
*/
|
171 |
Â
public function validate() {
|
172 |
Â
return true;
|
173 |
Â
}
|
175 |
Â
/**
|
176 |
Â
* Query record meta
|
177 |
Â
*
|
178 |
+
* @param string $meta_key Meta key (optional).
|
179 |
+
* @param bool $single Return only first found (optional).
|
180 |
Â
*
|
181 |
Â
* @return array
|
182 |
Â
*/
|
187 |
Â
/**
|
188 |
Â
* Update record meta
|
189 |
Â
*
|
190 |
+
* @param string $meta_key Meta key.
|
191 |
+
* @param mixed $meta_value New meta value.
|
192 |
+
* @param mixed $prev_value Old meta value (optional).
|
193 |
Â
*
|
194 |
Â
* @return bool
|
195 |
Â
*/
|
200 |
Â
/**
|
201 |
Â
* Determine the title of an object that a record is for.
|
202 |
Â
*
|
203 |
+
* @return mixed The title of the object as a string, otherwise false
|
Â
|
|
204 |
Â
*/
|
205 |
Â
public function get_object_title() {
|
206 |
Â
if ( ! isset( $this->object_id ) || empty( $this->object_id ) ) {
|
classes/class-settings.php
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
|
3 |
Â
namespace WP_Stream;
|
4 |
Â
|
@@ -6,10 +11,13 @@ use \WP_Roles;
|
|
6 |
Â
use \WP_User;
|
7 |
Â
use \WP_User_Query;
|
8 |
Â
|
Â
|
|
Â
|
|
Â
|
|
9 |
Â
class Settings {
|
10 |
Â
|
11 |
Â
/**
|
12 |
-
*
|
13 |
Â
*
|
14 |
Â
* @var Plugin
|
15 |
Â
*/
|
@@ -46,7 +54,7 @@ class Settings {
|
|
46 |
Â
/**
|
47 |
Â
* Class constructor.
|
48 |
Â
*
|
49 |
-
* @param Plugin $plugin
|
50 |
Â
*/
|
51 |
Â
public function __construct( $plugin ) {
|
52 |
Â
$this->plugin = $plugin;
|
@@ -54,10 +62,10 @@ class Settings {
|
|
54 |
Â
$this->option_key = $this->get_option_key();
|
55 |
Â
$this->options = $this->get_options();
|
56 |
Â
|
57 |
-
// Register settings, and fields
|
58 |
Â
add_action( 'admin_init', array( $this, 'register_settings' ) );
|
59 |
Â
|
60 |
-
// Remove records when records TTL is shortened
|
61 |
Â
add_action(
|
62 |
Â
'update_option_' . $this->option_key,
|
63 |
Â
array(
|
@@ -68,7 +76,7 @@ class Settings {
|
|
68 |
Â
2
|
69 |
Â
);
|
70 |
Â
|
71 |
-
// Apply label translations for settings
|
72 |
Â
add_filter(
|
73 |
Â
'wp_stream_serialized_labels',
|
74 |
Â
array(
|
@@ -77,10 +85,10 @@ class Settings {
|
|
77 |
Â
)
|
78 |
Â
);
|
79 |
Â
|
80 |
-
// Ajax callback function to search users
|
81 |
Â
add_action( 'wp_ajax_stream_get_users', array( $this, 'get_users' ) );
|
82 |
Â
|
83 |
-
// Ajax callback function to search IPs
|
84 |
Â
add_action( 'wp_ajax_stream_get_ips', array( $this, 'get_ips' ) );
|
85 |
Â
}
|
86 |
Â
|
@@ -165,7 +173,7 @@ class Settings {
|
|
165 |
Â
$users_added_to_response = array();
|
166 |
Â
|
167 |
Â
foreach ( $users_array as $key => $user ) {
|
168 |
-
// exclude duplications
|
169 |
Â
if ( array_key_exists( $user->ID, $users_added_to_response ) ) {
|
170 |
Â
continue;
|
171 |
Â
} else {
|
@@ -181,7 +189,7 @@ class Settings {
|
|
181 |
Â
|
182 |
Â
$args['tooltip'] = esc_attr(
|
183 |
Â
sprintf(
|
184 |
-
|
185 |
Â
__( 'ID: %1$d\nUser: %2$s\nEmail: %3$s\nRole: %4$s', 'stream' ),
|
186 |
Â
$author->id,
|
187 |
Â
$author->user_login,
|
@@ -367,7 +375,7 @@ class Settings {
|
|
367 |
Â
),
|
368 |
Â
);
|
369 |
Â
|
370 |
-
// If Akismet is active, allow Admins to opt-in to Akismet tracking
|
371 |
Â
if ( class_exists( 'Akismet' ) ) {
|
372 |
Â
$akismet_tracking = array(
|
373 |
Â
'name' => 'akismet_tracking',
|
@@ -399,7 +407,7 @@ class Settings {
|
|
399 |
Â
*/
|
400 |
Â
$this->fields = apply_filters( 'wp_stream_settings_option_fields', $fields );
|
401 |
Â
|
402 |
-
// Sort option fields in each tab by title ASC
|
403 |
Â
foreach ( $this->fields as $tab => $options ) {
|
404 |
Â
$titles = array();
|
405 |
Â
|
@@ -489,7 +497,8 @@ class Settings {
|
|
489 |
Â
);
|
490 |
Â
|
491 |
Â
foreach ( $section['fields'] as $field_idx => $field ) {
|
492 |
-
|
Â
|
|
493 |
Â
continue;
|
494 |
Â
}
|
495 |
Â
|
@@ -505,7 +514,7 @@ class Settings {
|
|
505 |
Â
$field + array(
|
506 |
Â
'section' => $section_name,
|
507 |
Â
'label_for' => sprintf( '%s_%s_%s', $this->option_key, $section_name, $field['name'] ),
|
508 |
-
// xss ok
|
509 |
Â
)
|
510 |
Â
);
|
511 |
Â
}
|
@@ -515,7 +524,7 @@ class Settings {
|
|
515 |
Â
/**
|
516 |
Â
* Sanitization callback for settings field values before save
|
517 |
Â
*
|
518 |
-
* @param array $input
|
519 |
Â
*
|
520 |
Â
* @return array
|
521 |
Â
*/
|
@@ -568,7 +577,7 @@ class Settings {
|
|
568 |
Â
/**
|
569 |
Â
* Compile HTML needed for displaying the field
|
570 |
Â
*
|
571 |
-
* @param array $field Field settings
|
572 |
Â
*
|
573 |
Â
* @return string HTML to be displayed
|
574 |
Â
*/
|
@@ -797,7 +806,7 @@ class Settings {
|
|
797 |
Â
esc_attr( wp_stream_json_encode( $data_values ) ),
|
798 |
Â
esc_attr( $current_value ),
|
799 |
Â
esc_attr( $class ),
|
800 |
-
|
801 |
Â
sprintf( esc_html__( 'Any %s', 'stream' ), $title )
|
802 |
Â
);
|
803 |
Â
|
@@ -858,7 +867,7 @@ class Settings {
|
|
858 |
Â
$action = isset( $current_value['action'][ $key ] ) ? $current_value['action'][ $key ] : '';
|
859 |
Â
$ip_address = isset( $current_value['ip_address'][ $key ] ) ? $current_value['ip_address'][ $key ] : '';
|
860 |
Â
|
861 |
-
// Author or Role dropdown menu
|
862 |
Â
$author_or_role_values = array();
|
863 |
Â
$author_or_role_selected = array();
|
864 |
Â
|
@@ -870,7 +879,7 @@ class Settings {
|
|
870 |
Â
$count = isset( $users['avail_roles'][ $role_id ] ) ? $users['avail_roles'][ $role_id ] : 0;
|
871 |
Â
|
872 |
Â
if ( ! empty( $count ) ) {
|
873 |
-
|
874 |
Â
$args['user_count'] = sprintf( _n( '%d user', '%d users', absint( $count ), 'stream' ), absint( $count ) );
|
875 |
Â
}
|
876 |
Â
|
@@ -907,7 +916,7 @@ class Settings {
|
|
907 |
Â
)
|
908 |
Â
);
|
909 |
Â
|
910 |
-
// Context dropdown menu
|
911 |
Â
$context_values = array();
|
912 |
Â
|
913 |
Â
foreach ( $this->get_terms_labels( 'context' ) as $context_id => $context_data ) {
|
@@ -969,7 +978,7 @@ class Settings {
|
|
969 |
Â
)
|
970 |
Â
);
|
971 |
Â
|
972 |
-
// Action dropdown menu
|
973 |
Â
$action_values = array();
|
974 |
Â
|
975 |
Â
foreach ( $this->get_terms_labels( 'action' ) as $action_id => $action_data ) {
|
@@ -992,7 +1001,7 @@ class Settings {
|
|
992 |
Â
)
|
993 |
Â
);
|
994 |
Â
|
995 |
-
// IP Address input
|
996 |
Â
$ip_address_input = $form->render_field(
|
997 |
Â
'select2',
|
998 |
Â
array(
|
@@ -1007,7 +1016,7 @@ class Settings {
|
|
1007 |
Â
)
|
1008 |
Â
);
|
1009 |
Â
|
1010 |
-
// Hidden helper input
|
1011 |
Â
$helper_input = sprintf(
|
1012 |
Â
'<input type="hidden" name="%1$s[%2$s_%3$s][%4$s][]" value="" />',
|
1013 |
Â
esc_attr( $option_key ),
|
@@ -1062,7 +1071,7 @@ class Settings {
|
|
1062 |
Â
/**
|
1063 |
Â
* Render Callback for post_types field
|
1064 |
Â
*
|
1065 |
-
* @param array $field
|
1066 |
Â
*
|
1067 |
Â
* @return string
|
1068 |
Â
*/
|
@@ -1075,7 +1084,7 @@ class Settings {
|
|
1075 |
Â
|
1076 |
Â
$output = $this->render_field( $field );
|
1077 |
Â
|
1078 |
-
echo $output; // xss ok
|
1079 |
Â
}
|
1080 |
Â
|
1081 |
Â
/**
|
@@ -1097,7 +1106,7 @@ class Settings {
|
|
1097 |
Â
/**
|
1098 |
Â
* Function will return all terms labels of given column
|
1099 |
Â
*
|
1100 |
-
* @param string $column
|
1101 |
Â
*
|
1102 |
Â
* @return array
|
1103 |
Â
*/
|
@@ -1132,8 +1141,8 @@ class Settings {
|
|
1132 |
Â
*
|
1133 |
Â
* @action update_option_wp_stream
|
1134 |
Â
*
|
1135 |
-
* @param array $old_value
|
1136 |
-
* @param array $new_value
|
1137 |
Â
*/
|
1138 |
Â
public function updated_option_ttl_remove_records( $old_value, $new_value ) {
|
1139 |
Â
$ttl_before = isset( $old_value['general_records_ttl'] ) ? (int) $old_value['general_records_ttl'] : - 1;
|
@@ -1152,6 +1161,8 @@ class Settings {
|
|
1152 |
Â
*
|
1153 |
Â
* @filter wp_stream_serialized_labels
|
1154 |
Â
*
|
Â
|
|
Â
|
|
1155 |
Â
* @return array Multidimensional array of fields
|
1156 |
Â
*/
|
1157 |
Â
public function get_settings_translations( $labels ) {
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Renders and manages the plugin Settings page.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
Â
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
11 |
Â
use \WP_User;
|
12 |
Â
use \WP_User_Query;
|
13 |
Â
|
14 |
+
/**
|
15 |
+
* Class - Settings
|
16 |
+
*/
|
17 |
Â
class Settings {
|
18 |
Â
|
19 |
Â
/**
|
20 |
+
* Holds instance of plugin object
|
21 |
Â
*
|
22 |
Â
* @var Plugin
|
23 |
Â
*/
|
54 |
Â
/**
|
55 |
Â
* Class constructor.
|
56 |
Â
*
|
57 |
+
* @param Plugin $plugin Instance of plugin object.
|
58 |
Â
*/
|
59 |
Â
public function __construct( $plugin ) {
|
60 |
Â
$this->plugin = $plugin;
|
62 |
Â
$this->option_key = $this->get_option_key();
|
63 |
Â
$this->options = $this->get_options();
|
64 |
Â
|
65 |
+
// Register settings, and fields.
|
66 |
Â
add_action( 'admin_init', array( $this, 'register_settings' ) );
|
67 |
Â
|
68 |
+
// Remove records when records TTL is shortened.
|
69 |
Â
add_action(
|
70 |
Â
'update_option_' . $this->option_key,
|
71 |
Â
array(
|
76 |
Â
2
|
77 |
Â
);
|
78 |
Â
|
79 |
+
// Apply label translations for settings.
|
80 |
Â
add_filter(
|
81 |
Â
'wp_stream_serialized_labels',
|
82 |
Â
array(
|
85 |
Â
)
|
86 |
Â
);
|
87 |
Â
|
88 |
+
// Ajax callback function to search users.
|
89 |
Â
add_action( 'wp_ajax_stream_get_users', array( $this, 'get_users' ) );
|
90 |
Â
|
91 |
+
// Ajax callback function to search IPs.
|
92 |
Â
add_action( 'wp_ajax_stream_get_ips', array( $this, 'get_ips' ) );
|
93 |
Â
}
|
94 |
Â
|
173 |
Â
$users_added_to_response = array();
|
174 |
Â
|
175 |
Â
foreach ( $users_array as $key => $user ) {
|
176 |
+
// exclude duplications.
|
177 |
Â
if ( array_key_exists( $user->ID, $users_added_to_response ) ) {
|
178 |
Â
continue;
|
179 |
Â
} else {
|
189 |
Â
|
190 |
Â
$args['tooltip'] = esc_attr(
|
191 |
Â
sprintf(
|
192 |
+
/* translators: %1$d: user ID, %2$s: username, %3$s: email, %4$s: user role (e.g. "42", "administrator", "foo@bar.com", "subscriber") */
|
193 |
Â
__( 'ID: %1$d\nUser: %2$s\nEmail: %3$s\nRole: %4$s', 'stream' ),
|
194 |
Â
$author->id,
|
195 |
Â
$author->user_login,
|
375 |
Â
),
|
376 |
Â
);
|
377 |
Â
|
378 |
+
// If Akismet is active, allow Admins to opt-in to Akismet tracking.
|
379 |
Â
if ( class_exists( 'Akismet' ) ) {
|
380 |
Â
$akismet_tracking = array(
|
381 |
Â
'name' => 'akismet_tracking',
|
407 |
Â
*/
|
408 |
Â
$this->fields = apply_filters( 'wp_stream_settings_option_fields', $fields );
|
409 |
Â
|
410 |
+
// Sort option fields in each tab by title ASC.
|
411 |
Â
foreach ( $this->fields as $tab => $options ) {
|
412 |
Â
$titles = array();
|
413 |
Â
|
497 |
Â
);
|
498 |
Â
|
499 |
Â
foreach ( $section['fields'] as $field_idx => $field ) {
|
500 |
+
// No field type associated, skip, no GUI.
|
501 |
+
if ( ! isset( $field['type'] ) ) {
|
502 |
Â
continue;
|
503 |
Â
}
|
504 |
Â
|
514 |
Â
$field + array(
|
515 |
Â
'section' => $section_name,
|
516 |
Â
'label_for' => sprintf( '%s_%s_%s', $this->option_key, $section_name, $field['name'] ),
|
517 |
+
// xss ok.
|
518 |
Â
)
|
519 |
Â
);
|
520 |
Â
}
|
524 |
Â
/**
|
525 |
Â
* Sanitization callback for settings field values before save
|
526 |
Â
*
|
527 |
+
* @param array $input Raw input.
|
528 |
Â
*
|
529 |
Â
* @return array
|
530 |
Â
*/
|
577 |
Â
/**
|
578 |
Â
* Compile HTML needed for displaying the field
|
579 |
Â
*
|
580 |
+
* @param array $field Field settings.
|
581 |
Â
*
|
582 |
Â
* @return string HTML to be displayed
|
583 |
Â
*/
|
806 |
Â
esc_attr( wp_stream_json_encode( $data_values ) ),
|
807 |
Â
esc_attr( $current_value ),
|
808 |
Â
esc_attr( $class ),
|
809 |
+
/* translators: %s: the title of the dropdown menu (e.g. "users") */
|
810 |
Â
sprintf( esc_html__( 'Any %s', 'stream' ), $title )
|
811 |
Â
);
|
812 |
Â
|
867 |
Â
$action = isset( $current_value['action'][ $key ] ) ? $current_value['action'][ $key ] : '';
|
868 |
Â
$ip_address = isset( $current_value['ip_address'][ $key ] ) ? $current_value['ip_address'][ $key ] : '';
|
869 |
Â
|
870 |
+
// Author or Role dropdown menu.
|
871 |
Â
$author_or_role_values = array();
|
872 |
Â
$author_or_role_selected = array();
|
873 |
Â
|
879 |
Â
$count = isset( $users['avail_roles'][ $role_id ] ) ? $users['avail_roles'][ $role_id ] : 0;
|
880 |
Â
|
881 |
Â
if ( ! empty( $count ) ) {
|
882 |
+
/* translators: %d: a number of users (e.g. "42") */
|
883 |
Â
$args['user_count'] = sprintf( _n( '%d user', '%d users', absint( $count ), 'stream' ), absint( $count ) );
|
884 |
Â
}
|
885 |
Â
|
916 |
Â
)
|
917 |
Â
);
|
918 |
Â
|
919 |
+
// Context dropdown menu.
|
920 |
Â
$context_values = array();
|
921 |
Â
|
922 |
Â
foreach ( $this->get_terms_labels( 'context' ) as $context_id => $context_data ) {
|
978 |
Â
)
|
979 |
Â
);
|
980 |
Â
|
981 |
+
// Action dropdown menu.
|
982 |
Â
$action_values = array();
|
983 |
Â
|
984 |
Â
foreach ( $this->get_terms_labels( 'action' ) as $action_id => $action_data ) {
|
1001 |
Â
)
|
1002 |
Â
);
|
1003 |
Â
|
1004 |
+
// IP Address input.
|
1005 |
Â
$ip_address_input = $form->render_field(
|
1006 |
Â
'select2',
|
1007 |
Â
array(
|
1016 |
Â
)
|
1017 |
Â
);
|
1018 |
Â
|
1019 |
+
// Hidden helper input.
|
1020 |
Â
$helper_input = sprintf(
|
1021 |
Â
'<input type="hidden" name="%1$s[%2$s_%3$s][%4$s][]" value="" />',
|
1022 |
Â
esc_attr( $option_key ),
|
1071 |
Â
/**
|
1072 |
Â
* Render Callback for post_types field
|
1073 |
Â
*
|
1074 |
+
* @param array $field Field to be rendered.
|
1075 |
Â
*
|
1076 |
Â
* @return string
|
1077 |
Â
*/
|
1084 |
Â
|
1085 |
Â
$output = $this->render_field( $field );
|
1086 |
Â
|
1087 |
+
echo $output; // xss ok.
|
1088 |
Â
}
|
1089 |
Â
|
1090 |
Â
/**
|
1106 |
Â
/**
|
1107 |
Â
* Function will return all terms labels of given column
|
1108 |
Â
*
|
1109 |
+
* @param string $column Name of the column.
|
1110 |
Â
*
|
1111 |
Â
* @return array
|
1112 |
Â
*/
|
1141 |
Â
*
|
1142 |
Â
* @action update_option_wp_stream
|
1143 |
Â
*
|
1144 |
+
* @param array $old_value Old value.
|
1145 |
+
* @param array $new_value New value.
|
1146 |
Â
*/
|
1147 |
Â
public function updated_option_ttl_remove_records( $old_value, $new_value ) {
|
1148 |
Â
$ttl_before = isset( $old_value['general_records_ttl'] ) ? (int) $old_value['general_records_ttl'] : - 1;
|
1161 |
Â
*
|
1162 |
Â
* @filter wp_stream_serialized_labels
|
1163 |
Â
*
|
1164 |
+
* @param array $labels Setting labels.
|
1165 |
+
*
|
1166 |
Â
* @return array Multidimensional array of fields
|
1167 |
Â
*/
|
1168 |
Â
public function get_settings_translations( $labels ) {
|
classes/class-uninstall.php
CHANGED
@@ -1,9 +1,18 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Uninstall {
|
5 |
Â
/**
|
6 |
-
*
|
7 |
Â
*
|
8 |
Â
* @var Plugin
|
9 |
Â
*/
|
@@ -23,14 +32,19 @@ class Uninstall {
|
|
23 |
Â
*/
|
24 |
Â
public $user_meta;
|
25 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
26 |
Â
public function __construct( $plugin ) {
|
27 |
Â
$this->plugin = $plugin;
|
28 |
Â
|
29 |
Â
$this->user_meta = array(
|
30 |
Â
'edit_stream_per_page',
|
31 |
-
'stream_last_read', // Deprecated
|
32 |
-
'stream_unread_count', // Deprecated
|
33 |
-
'stream_user_feed_key', // Deprecated
|
34 |
Â
);
|
35 |
Â
}
|
36 |
Â
|
@@ -44,7 +58,7 @@ class Uninstall {
|
|
44 |
Â
$this->plugin->settings->network_options_key,
|
45 |
Â
);
|
46 |
Â
|
47 |
-
// Verify current user's permissions before proceeding
|
48 |
Â
if ( ! current_user_can( $this->plugin->admin->settings_cap ) ) {
|
49 |
Â
wp_die(
|
50 |
Â
esc_html__( "You don't have sufficient privileges to do this action.", 'stream' )
|
@@ -57,16 +71,18 @@ class Uninstall {
|
|
57 |
Â
);
|
58 |
Â
}
|
59 |
Â
|
60 |
-
// Prevent this action from firing
|
61 |
Â
remove_action( 'deactivate_plugin', array( 'Connector_Installer', 'callback' ), null );
|
62 |
Â
|
63 |
-
// Just in case
|
64 |
Â
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
|
65 |
Â
require_once ABSPATH . '/wp-admin/includes/plugin.php';
|
66 |
Â
}
|
67 |
Â
|
68 |
-
|
69 |
-
|
Â
|
|
Â
|
|
70 |
Â
if ( ! is_multisite() || $this->plugin->is_network_activated() ) {
|
71 |
Â
$this->delete_all_records();
|
72 |
Â
$this->delete_all_options();
|
@@ -97,7 +113,7 @@ class Uninstall {
|
|
97 |
Â
/**
|
98 |
Â
* Delete records and record meta from a specific blog
|
99 |
Â
*
|
100 |
-
* @param int $blog_id (optional)
|
101 |
Â
*/
|
102 |
Â
private function delete_blog_records( $blog_id = 1 ) {
|
103 |
Â
if ( empty( $blog_id ) || ! is_int( $blog_id ) ) {
|
@@ -124,23 +140,23 @@ class Uninstall {
|
|
124 |
Â
private function delete_all_options() {
|
125 |
Â
global $wpdb;
|
126 |
Â
|
127 |
-
// Wildcard matches
|
128 |
Â
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '%wp_stream%';" );
|
129 |
Â
|
130 |
-
// Specific options
|
131 |
Â
foreach ( $this->options as $option ) {
|
132 |
-
delete_site_option( $option ); // Supports both multisite and single site installs
|
133 |
Â
}
|
134 |
Â
|
135 |
-
// Single site installs can stop here
|
136 |
Â
if ( ! is_multisite() ) {
|
137 |
Â
return;
|
138 |
Â
}
|
139 |
Â
|
140 |
-
// Wildcard matches on network options
|
141 |
Â
$wpdb->query( "DELETE FROM {$wpdb->sitemeta} WHERE meta_key LIKE '%wp_stream%';" );
|
142 |
Â
|
143 |
-
// Delete options from each blog on network
|
144 |
Â
foreach ( wp_stream_get_sites() as $blog ) {
|
145 |
Â
$this->delete_blog_options( absint( $blog->blog_id ) );
|
146 |
Â
}
|
@@ -149,7 +165,7 @@ class Uninstall {
|
|
149 |
Â
/**
|
150 |
Â
* Delete options from a specific blog
|
151 |
Â
*
|
152 |
-
* @param int $blog_id (optional)
|
153 |
Â
*/
|
154 |
Â
private function delete_blog_options( $blog_id = 1 ) {
|
155 |
Â
if ( empty( $blog_id ) || ! is_int( $blog_id ) ) {
|
@@ -158,10 +174,10 @@ class Uninstall {
|
|
158 |
Â
|
159 |
Â
global $wpdb;
|
160 |
Â
|
161 |
-
// Wildcard matches
|
162 |
Â
$wpdb->query( "DELETE FROM {$wpdb->prefix}options WHERE option_name LIKE '%wp_stream%';" );
|
163 |
Â
|
164 |
-
// Specific options
|
165 |
Â
foreach ( $this->options as $option ) {
|
166 |
Â
delete_blog_option( $blog_id, $option );
|
167 |
Â
}
|
@@ -173,10 +189,10 @@ class Uninstall {
|
|
173 |
Â
private function delete_all_user_meta() {
|
174 |
Â
global $wpdb;
|
175 |
Â
|
176 |
-
// Wildcard matches
|
177 |
Â
$wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%wp_stream%';" );
|
178 |
Â
|
179 |
-
// Specific user meta
|
180 |
Â
foreach ( $this->user_meta as $meta_key ) {
|
181 |
Â
$wpdb->query(
|
182 |
Â
$wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = %s;", $meta_key )
|
@@ -187,7 +203,7 @@ class Uninstall {
|
|
187 |
Â
/**
|
188 |
Â
* Delete user meta from a specific blog
|
189 |
Â
*
|
190 |
-
* @param int $blog_id (optional)
|
191 |
Â
*/
|
192 |
Â
private function delete_blog_user_meta( $blog_id = 1 ) {
|
193 |
Â
if ( empty( $blog_id ) || ! is_int( $blog_id ) ) {
|
@@ -196,10 +212,10 @@ class Uninstall {
|
|
196 |
Â
|
197 |
Â
global $wpdb;
|
198 |
Â
|
199 |
-
// Wildcard matches
|
200 |
Â
$wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '{$wpdb->prefix}%wp_stream%';" );
|
201 |
Â
|
202 |
-
// Specific user meta
|
203 |
Â
foreach ( $this->user_meta as $meta_key ) {
|
204 |
Â
$wpdb->query(
|
205 |
Â
$wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = {$wpdb->prefix}%s;", $meta_key )
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Manages the uninstallation of the plugin.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Uninstall
|
12 |
+
*/
|
13 |
Â
class Uninstall {
|
14 |
Â
/**
|
15 |
+
* Holds Instance of plugin object
|
16 |
Â
*
|
17 |
Â
* @var Plugin
|
18 |
Â
*/
|
32 |
Â
*/
|
33 |
Â
public $user_meta;
|
34 |
Â
|
35 |
+
/**
|
36 |
+
* Class constructor
|
37 |
+
*
|
38 |
+
* @param Plugin $plugin Instance of plugin object.
|
39 |
+
*/
|
40 |
Â
public function __construct( $plugin ) {
|
41 |
Â
$this->plugin = $plugin;
|
42 |
Â
|
43 |
Â
$this->user_meta = array(
|
44 |
Â
'edit_stream_per_page',
|
45 |
+
'stream_last_read', // Deprecated.
|
46 |
+
'stream_unread_count', // Deprecated.
|
47 |
+
'stream_user_feed_key', // Deprecated.
|
48 |
Â
);
|
49 |
Â
}
|
50 |
Â
|
58 |
Â
$this->plugin->settings->network_options_key,
|
59 |
Â
);
|
60 |
Â
|
61 |
+
// Verify current user's permissions before proceeding.
|
62 |
Â
if ( ! current_user_can( $this->plugin->admin->settings_cap ) ) {
|
63 |
Â
wp_die(
|
64 |
Â
esc_html__( "You don't have sufficient privileges to do this action.", 'stream' )
|
71 |
Â
);
|
72 |
Â
}
|
73 |
Â
|
74 |
+
// Prevent this action from firing.
|
75 |
Â
remove_action( 'deactivate_plugin', array( 'Connector_Installer', 'callback' ), null );
|
76 |
Â
|
77 |
+
// Just in case.
|
78 |
Â
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
|
79 |
Â
require_once ABSPATH . '/wp-admin/includes/plugin.php';
|
80 |
Â
}
|
81 |
Â
|
82 |
+
/**
|
83 |
+
* Drop everything on single site installs or when network activated
|
84 |
+
* Otherwise only delete data relative to the current blog.
|
85 |
+
*/
|
86 |
Â
if ( ! is_multisite() || $this->plugin->is_network_activated() ) {
|
87 |
Â
$this->delete_all_records();
|
88 |
Â
$this->delete_all_options();
|
113 |
Â
/**
|
114 |
Â
* Delete records and record meta from a specific blog
|
115 |
Â
*
|
116 |
+
* @param int $blog_id Blog ID (optional).
|
117 |
Â
*/
|
118 |
Â
private function delete_blog_records( $blog_id = 1 ) {
|
119 |
Â
if ( empty( $blog_id ) || ! is_int( $blog_id ) ) {
|
140 |
Â
private function delete_all_options() {
|
141 |
Â
global $wpdb;
|
142 |
Â
|
143 |
+
// Wildcard matches.
|
144 |
Â
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '%wp_stream%';" );
|
145 |
Â
|
146 |
+
// Specific options.
|
147 |
Â
foreach ( $this->options as $option ) {
|
148 |
+
delete_site_option( $option ); // Supports both multisite and single site installs.
|
149 |
Â
}
|
150 |
Â
|
151 |
+
// Single site installs can stop here.
|
152 |
Â
if ( ! is_multisite() ) {
|
153 |
Â
return;
|
154 |
Â
}
|
155 |
Â
|
156 |
+
// Wildcard matches on network options.
|
157 |
Â
$wpdb->query( "DELETE FROM {$wpdb->sitemeta} WHERE meta_key LIKE '%wp_stream%';" );
|
158 |
Â
|
159 |
+
// Delete options from each blog on network.
|
160 |
Â
foreach ( wp_stream_get_sites() as $blog ) {
|
161 |
Â
$this->delete_blog_options( absint( $blog->blog_id ) );
|
162 |
Â
}
|
165 |
Â
/**
|
166 |
Â
* Delete options from a specific blog
|
167 |
Â
*
|
168 |
+
* @param int $blog_id Blog ID (optional).
|
169 |
Â
*/
|
170 |
Â
private function delete_blog_options( $blog_id = 1 ) {
|
171 |
Â
if ( empty( $blog_id ) || ! is_int( $blog_id ) ) {
|
174 |
Â
|
175 |
Â
global $wpdb;
|
176 |
Â
|
177 |
+
// Wildcard matches.
|
178 |
Â
$wpdb->query( "DELETE FROM {$wpdb->prefix}options WHERE option_name LIKE '%wp_stream%';" );
|
179 |
Â
|
180 |
+
// Specific options.
|
181 |
Â
foreach ( $this->options as $option ) {
|
182 |
Â
delete_blog_option( $blog_id, $option );
|
183 |
Â
}
|
189 |
Â
private function delete_all_user_meta() {
|
190 |
Â
global $wpdb;
|
191 |
Â
|
192 |
+
// Wildcard matches.
|
193 |
Â
$wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%wp_stream%';" );
|
194 |
Â
|
195 |
+
// Specific user meta.
|
196 |
Â
foreach ( $this->user_meta as $meta_key ) {
|
197 |
Â
$wpdb->query(
|
198 |
Â
$wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = %s;", $meta_key )
|
203 |
Â
/**
|
204 |
Â
* Delete user meta from a specific blog
|
205 |
Â
*
|
206 |
+
* @param int $blog_id Blog ID (optional).
|
207 |
Â
*/
|
208 |
Â
private function delete_blog_user_meta( $blog_id = 1 ) {
|
209 |
Â
if ( empty( $blog_id ) || ! is_int( $blog_id ) ) {
|
212 |
Â
|
213 |
Â
global $wpdb;
|
214 |
Â
|
215 |
+
// Wildcard matches.
|
216 |
Â
$wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '{$wpdb->prefix}%wp_stream%';" );
|
217 |
Â
|
218 |
+
// Specific user meta.
|
219 |
Â
foreach ( $this->user_meta as $meta_key ) {
|
220 |
Â
$wpdb->query(
|
221 |
Â
$wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = {$wpdb->prefix}%s;", $meta_key )
|
connectors/class-connector-acf.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_ACF extends Connector {
|
5 |
Â
/**
|
6 |
Â
* Connector slug
|
@@ -126,8 +135,8 @@ class Connector_ACF extends Connector {
|
|
126 |
Â
*
|
127 |
Â
* @filter wp_stream_action_links_{connector}
|
128 |
Â
*
|
129 |
-
* @param array $links
|
130 |
-
* @param object $record Stream record
|
131 |
Â
*
|
132 |
Â
* @return array Action links
|
133 |
Â
*/
|
@@ -201,12 +210,12 @@ class Connector_ACF extends Connector {
|
|
201 |
Â
/**
|
202 |
Â
* Track addition of post/user meta
|
203 |
Â
*
|
204 |
-
* @param string $type Type of object, post or user
|
205 |
-
* @param string $action Added, updated, deleted
|
206 |
-
* @param integer $meta_id
|
207 |
-
* @param integer $object_id
|
208 |
-
* @param string $meta_key
|
209 |
-
* @param mixed|null $meta_value
|
210 |
Â
*/
|
211 |
Â
public function check_meta( $type, $action, $meta_id, $object_id, $meta_key, $meta_value = null ) {
|
212 |
Â
$post = get_post( $object_id );
|
@@ -217,14 +226,14 @@ class Connector_ACF extends Connector {
|
|
217 |
Â
|
218 |
Â
$action_labels = $this->get_action_labels();
|
219 |
Â
|
220 |
-
// Fields
|
221 |
Â
if ( 0 === strpos( $meta_key, 'field_' ) ) {
|
222 |
Â
if ( 'deleted' === $action ) {
|
223 |
Â
$meta_value = get_post_meta( $object_id, $meta_key, true );
|
224 |
Â
}
|
225 |
Â
|
226 |
Â
$this->log(
|
227 |
-
|
228 |
Â
esc_html_x( '"%1$s" field in "%2$s" %3$s', 'acf', 'stream' ),
|
229 |
Â
array(
|
230 |
Â
'label' => $meta_value['label'],
|
@@ -255,7 +264,7 @@ class Connector_ACF extends Connector {
|
|
255 |
Â
);
|
256 |
Â
|
257 |
Â
$this->log(
|
258 |
-
|
259 |
Â
esc_html_x( 'Position of "%1$s" updated to "%2$s"', 'acf', 'stream' ),
|
260 |
Â
array(
|
261 |
Â
'title' => $post->post_title,
|
@@ -278,7 +287,7 @@ class Connector_ACF extends Connector {
|
|
278 |
Â
);
|
279 |
Â
|
280 |
Â
$this->log(
|
281 |
-
|
282 |
Â
esc_html_x( 'Style of "%1$s" updated to "%2$s"', 'acf', 'stream' ),
|
283 |
Â
array(
|
284 |
Â
'title' => $post->post_title,
|
@@ -321,7 +330,7 @@ class Connector_ACF extends Connector {
|
|
321 |
Â
}
|
322 |
Â
|
323 |
Â
$this->log(
|
324 |
-
|
325 |
Â
esc_html_x( '"%1$s" set to display on "%2$s"', 'acf', 'stream' ),
|
326 |
Â
array(
|
327 |
Â
'title' => $post->post_title,
|
@@ -339,12 +348,12 @@ class Connector_ACF extends Connector {
|
|
339 |
Â
/**
|
340 |
Â
* Track changes to ACF values within rendered post meta forms
|
341 |
Â
*
|
342 |
-
* @param string $type Type of object, post or user
|
343 |
-
* @param string $action Added, updated, deleted
|
344 |
-
* @param integer $meta_id
|
345 |
-
* @param integer $object_id
|
346 |
-
* @param string $key
|
347 |
-
* @param mixed|null $value
|
348 |
Â
*
|
349 |
Â
* @return bool
|
350 |
Â
*/
|
@@ -361,7 +370,7 @@ class Connector_ACF extends Connector {
|
|
361 |
Â
if ( 'user' === $type ) {
|
362 |
Â
$object_key = 'user_' . $object_id;
|
363 |
Â
} elseif ( 'taxonomy' === $type ) {
|
364 |
-
if ( 0 === strpos( $key, '_' ) ) { // Ignore the 'revision' stuff
|
365 |
Â
return false;
|
366 |
Â
}
|
367 |
Â
|
@@ -369,7 +378,7 @@ class Connector_ACF extends Connector {
|
|
369 |
Â
return false;
|
370 |
Â
}
|
371 |
Â
|
372 |
-
list( , $taxonomy, $term_id, $key ) = $matches; // Skips 0 index
|
373 |
Â
|
374 |
Â
$object_key = $taxonomy . '_' . $term_id;
|
375 |
Â
} elseif ( 'option' === $type ) {
|
@@ -403,7 +412,7 @@ class Connector_ACF extends Connector {
|
|
403 |
Â
$cache = $this->cached_field_values_updates[ $object_key ][ $key ];
|
404 |
Â
|
405 |
Â
$this->log(
|
406 |
-
|
407 |
Â
esc_html_x( '"%1$s" of "%2$s" %3$s updated', 'acf', 'stream' ),
|
408 |
Â
array(
|
409 |
Â
'field_label' => $cache['field']['label'],
|
@@ -442,7 +451,7 @@ class Connector_ACF extends Connector {
|
|
442 |
Â
$deleted = array_diff( $old, $new );
|
443 |
Â
|
444 |
Â
$this->log(
|
445 |
-
|
446 |
Â
esc_html_x( 'Updated rules of "%1$s" (%2$d added, %3$d deleted)', 'acf', 'stream' ),
|
447 |
Â
array(
|
448 |
Â
'title' => $post->post_title,
|
@@ -461,7 +470,7 @@ class Connector_ACF extends Connector {
|
|
461 |
Â
/**
|
462 |
Â
* Override connector log for our own Settings / Actions
|
463 |
Â
*
|
464 |
-
* @param array $data
|
465 |
Â
*
|
466 |
Â
* @return array|bool
|
467 |
Â
*/
|
@@ -483,9 +492,9 @@ class Connector_ACF extends Connector {
|
|
483 |
Â
* Track changes to custom field values updates, saves filtered values to be
|
484 |
Â
* processed by callback_updated_post_meta
|
485 |
Â
*
|
486 |
-
* @param string $value
|
487 |
-
* @param int $post_id
|
488 |
-
* @param string $field
|
489 |
Â
*
|
490 |
Â
* @return string
|
491 |
Â
*/
|
@@ -497,8 +506,8 @@ class Connector_ACF extends Connector {
|
|
497 |
Â
/**
|
498 |
Â
* Track changes to post main attributes, ie: Order No.
|
499 |
Â
*
|
500 |
-
* @param int $post_id
|
501 |
-
* @param array $data
|
502 |
Â
*/
|
503 |
Â
public function callback_pre_post_update( $post_id, $data ) {
|
504 |
Â
$post = get_post( $post_id );
|
@@ -510,7 +519,7 @@ class Connector_ACF extends Connector {
|
|
510 |
Â
// menu_order, aka Order No.
|
511 |
Â
if ( $data['menu_order'] !== $post->menu_order ) {
|
512 |
Â
$this->log(
|
513 |
-
|
514 |
Â
esc_html_x( '"%1$s" reordered from %2$d to %3$d', 'acf', 'stream' ),
|
515 |
Â
array(
|
516 |
Â
'title' => $post->post_title,
|
@@ -527,8 +536,8 @@ class Connector_ACF extends Connector {
|
|
527 |
Â
/**
|
528 |
Â
* Track addition of new options
|
529 |
Â
*
|
530 |
-
* @param string $key Option name
|
531 |
-
* @param string $value Option value
|
532 |
Â
*/
|
533 |
Â
public function callback_added_option( $key, $value ) {
|
534 |
Â
$this->check_meta_values( self::get_saved_option_type( $key ), 'added', null, null, $key, $value );
|
@@ -537,9 +546,9 @@ class Connector_ACF extends Connector {
|
|
537 |
Â
/**
|
538 |
Â
* Track addition of new options
|
539 |
Â
*
|
540 |
-
* @param $key
|
541 |
-
* @param $old
|
542 |
-
* @param $value
|
543 |
Â
*/
|
544 |
Â
public function callback_updated_option( $key, $old, $value ) {
|
545 |
Â
unset( $old );
|
@@ -549,7 +558,7 @@ class Connector_ACF extends Connector {
|
|
549 |
Â
/**
|
550 |
Â
* Track addition of new options
|
551 |
Â
*
|
552 |
-
* @param $key
|
553 |
Â
*/
|
554 |
Â
public function callback_deleted_option( $key ) {
|
555 |
Â
$this->check_meta_values( self::get_saved_option_type( $key ), 'deleted', null, null, $key, null );
|
@@ -558,7 +567,7 @@ class Connector_ACF extends Connector {
|
|
558 |
Â
/**
|
559 |
Â
* Determines the type of option that is saved
|
560 |
Â
*
|
561 |
-
* @param $key
|
562 |
Â
* @return string
|
563 |
Â
*/
|
564 |
Â
private function get_saved_option_type( $key ) {
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector - Advanced Custom Fields
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_ACF
|
12 |
+
*/
|
13 |
Â
class Connector_ACF extends Connector {
|
14 |
Â
/**
|
15 |
Â
* Connector slug
|
135 |
Â
*
|
136 |
Â
* @filter wp_stream_action_links_{connector}
|
137 |
Â
*
|
138 |
+
* @param array $links Previous links registered.
|
139 |
+
* @param object $record Stream record.
|
140 |
Â
*
|
141 |
Â
* @return array Action links
|
142 |
Â
*/
|
210 |
Â
/**
|
211 |
Â
* Track addition of post/user meta
|
212 |
Â
*
|
213 |
+
* @param string $type Type of object, post or user.
|
214 |
+
* @param string $action Added, updated, deleted.
|
215 |
+
* @param integer $meta_id Meta ID.
|
216 |
+
* @param integer $object_id Object ID.
|
217 |
+
* @param string $meta_key Meta Key.
|
218 |
+
* @param mixed|null $meta_value Value being stored in meta.
|
219 |
Â
*/
|
220 |
Â
public function check_meta( $type, $action, $meta_id, $object_id, $meta_key, $meta_value = null ) {
|
221 |
Â
$post = get_post( $object_id );
|
226 |
Â
|
227 |
Â
$action_labels = $this->get_action_labels();
|
228 |
Â
|
229 |
+
// Fields.
|
230 |
Â
if ( 0 === strpos( $meta_key, 'field_' ) ) {
|
231 |
Â
if ( 'deleted' === $action ) {
|
232 |
Â
$meta_value = get_post_meta( $object_id, $meta_key, true );
|
233 |
Â
}
|
234 |
Â
|
235 |
Â
$this->log(
|
236 |
+
/* translators: %1$s: field label, %2$s: form title, %3$s: action (e.g. "Message", "Contact", "Created") */
|
237 |
Â
esc_html_x( '"%1$s" field in "%2$s" %3$s', 'acf', 'stream' ),
|
238 |
Â
array(
|
239 |
Â
'label' => $meta_value['label'],
|
264 |
Â
);
|
265 |
Â
|
266 |
Â
$this->log(
|
267 |
+
/* translators: %1$s: form title, %2$s a position (e.g. "Contact", "Side") */
|
268 |
Â
esc_html_x( 'Position of "%1$s" updated to "%2$s"', 'acf', 'stream' ),
|
269 |
Â
array(
|
270 |
Â
'title' => $post->post_title,
|
287 |
Â
);
|
288 |
Â
|
289 |
Â
$this->log(
|
290 |
+
/* translators: %1$s: form title, %2$s a layout (e.g. "Contact", "Seamless") */
|
291 |
Â
esc_html_x( 'Style of "%1$s" updated to "%2$s"', 'acf', 'stream' ),
|
292 |
Â
array(
|
293 |
Â
'title' => $post->post_title,
|
330 |
Â
}
|
331 |
Â
|
332 |
Â
$this->log(
|
333 |
+
/* translators: %1$s: a form title, %2$s: a display option (e.g. "Contact", "All screens") */
|
334 |
Â
esc_html_x( '"%1$s" set to display on "%2$s"', 'acf', 'stream' ),
|
335 |
Â
array(
|
336 |
Â
'title' => $post->post_title,
|
348 |
Â
/**
|
349 |
Â
* Track changes to ACF values within rendered post meta forms
|
350 |
Â
*
|
351 |
+
* @param string $type Type of object, post or user.
|
352 |
+
* @param string $action Added, updated, deleted.
|
353 |
+
* @param integer $meta_id Meta ID.
|
354 |
+
* @param integer $object_id Object ID.
|
355 |
+
* @param string $key Meta Key.
|
356 |
+
* @param mixed|null $value Value being stored in meta.
|
357 |
Â
*
|
358 |
Â
* @return bool
|
359 |
Â
*/
|
370 |
Â
if ( 'user' === $type ) {
|
371 |
Â
$object_key = 'user_' . $object_id;
|
372 |
Â
} elseif ( 'taxonomy' === $type ) {
|
373 |
+
if ( 0 === strpos( $key, '_' ) ) { // Ignore the 'revision' stuff!.
|
374 |
Â
return false;
|
375 |
Â
}
|
376 |
Â
|
378 |
Â
return false;
|
379 |
Â
}
|
380 |
Â
|
381 |
+
list( , $taxonomy, $term_id, $key ) = $matches; // Skips 0 index.
|
382 |
Â
|
383 |
Â
$object_key = $taxonomy . '_' . $term_id;
|
384 |
Â
} elseif ( 'option' === $type ) {
|
412 |
Â
$cache = $this->cached_field_values_updates[ $object_key ][ $key ];
|
413 |
Â
|
414 |
Â
$this->log(
|
415 |
+
/* translators: %1$s: a field label, %2$s: an object title, %3$s: an object type (e.g. "Message", "Hello World", "post") */
|
416 |
Â
esc_html_x( '"%1$s" of "%2$s" %3$s updated', 'acf', 'stream' ),
|
417 |
Â
array(
|
418 |
Â
'field_label' => $cache['field']['label'],
|
451 |
Â
$deleted = array_diff( $old, $new );
|
452 |
Â
|
453 |
Â
$this->log(
|
454 |
+
/* translators: %1$s: a form title, %2$d: the number of rules added, %3$d: the number of rules deleted (e.g. "Contact", "42", "7") */
|
455 |
Â
esc_html_x( 'Updated rules of "%1$s" (%2$d added, %3$d deleted)', 'acf', 'stream' ),
|
456 |
Â
array(
|
457 |
Â
'title' => $post->post_title,
|
470 |
Â
/**
|
471 |
Â
* Override connector log for our own Settings / Actions
|
472 |
Â
*
|
473 |
+
* @param array $data Record data.
|
474 |
Â
*
|
475 |
Â
* @return array|bool
|
476 |
Â
*/
|
492 |
Â
* Track changes to custom field values updates, saves filtered values to be
|
493 |
Â
* processed by callback_updated_post_meta
|
494 |
Â
*
|
495 |
+
* @param string $value Field value.
|
496 |
+
* @param int $post_id Field post ID.
|
497 |
+
* @param string $field Field name.
|
498 |
Â
*
|
499 |
Â
* @return string
|
500 |
Â
*/
|
506 |
Â
/**
|
507 |
Â
* Track changes to post main attributes, ie: Order No.
|
508 |
Â
*
|
509 |
+
* @param int $post_id Field post ID.
|
510 |
+
* @param array $data Array with the updated post data.
|
511 |
Â
*/
|
512 |
Â
public function callback_pre_post_update( $post_id, $data ) {
|
513 |
Â
$post = get_post( $post_id );
|
519 |
Â
// menu_order, aka Order No.
|
520 |
Â
if ( $data['menu_order'] !== $post->menu_order ) {
|
521 |
Â
$this->log(
|
522 |
+
/* translators: %1$s: a form title, %2$d: a numeric position, %3$d: numeric position (e.g. "Contact", "42", "7") */
|
523 |
Â
esc_html_x( '"%1$s" reordered from %2$d to %3$d', 'acf', 'stream' ),
|
524 |
Â
array(
|
525 |
Â
'title' => $post->post_title,
|
536 |
Â
/**
|
537 |
Â
* Track addition of new options
|
538 |
Â
*
|
539 |
+
* @param string $key Option name.
|
540 |
+
* @param string $value Option value.
|
541 |
Â
*/
|
542 |
Â
public function callback_added_option( $key, $value ) {
|
543 |
Â
$this->check_meta_values( self::get_saved_option_type( $key ), 'added', null, null, $key, $value );
|
546 |
Â
/**
|
547 |
Â
* Track addition of new options
|
548 |
Â
*
|
549 |
+
* @param string $key Option key.
|
550 |
+
* @param string $old Old value.
|
551 |
+
* @param string $value New value.
|
552 |
Â
*/
|
553 |
Â
public function callback_updated_option( $key, $old, $value ) {
|
554 |
Â
unset( $old );
|
558 |
Â
/**
|
559 |
Â
* Track addition of new options
|
560 |
Â
*
|
561 |
+
* @param string $key Option key.
|
562 |
Â
*/
|
563 |
Â
public function callback_deleted_option( $key ) {
|
564 |
Â
$this->check_meta_values( self::get_saved_option_type( $key ), 'deleted', null, null, $key, null );
|
567 |
Â
/**
|
568 |
Â
* Determines the type of option that is saved
|
569 |
Â
*
|
570 |
+
* @param string $key Option key.
|
571 |
Â
* @return string
|
572 |
Â
*/
|
573 |
Â
private function get_saved_option_type( $key ) {
|
connectors/class-connector-bbpress.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_BbPress extends Connector {
|
5 |
Â
/**
|
6 |
Â
* Connector slug
|
@@ -42,16 +51,22 @@ class Connector_BbPress extends Connector {
|
|
42 |
Â
public $is_update = false;
|
43 |
Â
|
44 |
Â
/**
|
Â
|
|
Â
|
|
45 |
Â
* @var bool
|
46 |
Â
*/
|
47 |
-
public $
|
48 |
Â
|
49 |
Â
/**
|
Â
|
|
Â
|
|
50 |
Â
* @var array
|
51 |
Â
*/
|
52 |
-
public $
|
53 |
Â
|
54 |
Â
/**
|
Â
|
|
Â
|
|
55 |
Â
* @var bool
|
56 |
Â
*/
|
57 |
Â
public $ignore_activity_bulk_deletion = false;
|
@@ -120,8 +135,8 @@ class Connector_BbPress extends Connector {
|
|
120 |
Â
*
|
121 |
Â
* @filter wp_stream_action_links_{connector}
|
122 |
Â
*
|
123 |
-
* @param array $links
|
124 |
-
* @param object $record
|
125 |
Â
*
|
126 |
Â
* @return array Action links
|
127 |
Â
*/
|
@@ -140,6 +155,9 @@ class Connector_BbPress extends Connector {
|
|
140 |
Â
return $links;
|
141 |
Â
}
|
142 |
Â
|
Â
|
|
Â
|
|
Â
|
|
143 |
Â
public function register() {
|
144 |
Â
parent::register();
|
145 |
Â
|
@@ -149,7 +167,7 @@ class Connector_BbPress extends Connector {
|
|
149 |
Â
/**
|
150 |
Â
* Override connector log for our own Settings / Actions
|
151 |
Â
*
|
152 |
-
* @param array $data
|
153 |
Â
*
|
154 |
Â
* @return array|bool
|
155 |
Â
*/
|
@@ -184,12 +202,12 @@ class Connector_BbPress extends Connector {
|
|
184 |
Â
} elseif ( 'posts' === $data['connector'] && in_array( $data['context'], array( 'forum', 'topic', 'reply' ), true ) ) {
|
185 |
Â
if ( 'reply' === $data['context'] ) {
|
186 |
Â
if ( 'updated' === $data['action'] ) {
|
187 |
-
|
188 |
-
$data['message'] = esc_html__( 'Replied on "%
|
189 |
Â
$data['args']['post_title'] = get_post( wp_get_post_parent_id( $data['object_id'] ) )->post_title;
|
190 |
Â
}
|
191 |
Â
$data['args']['post_title'] = sprintf(
|
192 |
-
|
193 |
Â
__( 'Reply to: %s', 'stream' ),
|
194 |
Â
get_post( wp_get_post_parent_id( $data['object_id'] ) )->post_title
|
195 |
Â
);
|
@@ -206,10 +224,10 @@ class Connector_BbPress extends Connector {
|
|
206 |
Â
/**
|
207 |
Â
* Tracks togging the forum topics
|
208 |
Â
*
|
209 |
-
* @param bool $success
|
210 |
-
* @param \WP_Post $post_data
|
211 |
-
* @param string $action
|
212 |
-
* @param string $message
|
213 |
Â
*
|
214 |
Â
* @return array|bool
|
215 |
Â
*/
|
@@ -232,7 +250,7 @@ class Connector_BbPress extends Connector {
|
|
232 |
Â
$topic = get_post( $message['topic_id'] );
|
233 |
Â
|
234 |
Â
$this->log(
|
235 |
-
|
236 |
Â
_x( '%1$s "%2$s" topic', '1: Action, 2: Topic title', 'stream' ),
|
237 |
Â
array(
|
238 |
Â
'action_title' => $actions[ $action ],
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for bbPress
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_BbPress
|
12 |
+
*/
|
13 |
Â
class Connector_BbPress extends Connector {
|
14 |
Â
/**
|
15 |
Â
* Connector slug
|
51 |
Â
public $is_update = false;
|
52 |
Â
|
53 |
Â
/**
|
54 |
+
* Stores an activity to be deleted for use across multiple callbacks.
|
55 |
+
*
|
56 |
Â
* @var bool
|
57 |
Â
*/
|
58 |
+
public $deleted_activity = false;
|
59 |
Â
|
60 |
Â
/**
|
61 |
+
* Stores post data of an activity to be deleted for use across multiple callbacks.
|
62 |
+
*
|
63 |
Â
* @var array
|
64 |
Â
*/
|
65 |
+
public $delete_activity_args = array();
|
66 |
Â
|
67 |
Â
/**
|
68 |
+
* Flag for ignoring irrelevant activity deletions.
|
69 |
+
*
|
70 |
Â
* @var bool
|
71 |
Â
*/
|
72 |
Â
public $ignore_activity_bulk_deletion = false;
|
135 |
Â
*
|
136 |
Â
* @filter wp_stream_action_links_{connector}
|
137 |
Â
*
|
138 |
+
* @param array $links Previous links registered.
|
139 |
+
* @param object $record Stream record.
|
140 |
Â
*
|
141 |
Â
* @return array Action links
|
142 |
Â
*/
|
155 |
Â
return $links;
|
156 |
Â
}
|
157 |
Â
|
158 |
+
/**
|
159 |
+
* Register the connector
|
160 |
+
*/
|
161 |
Â
public function register() {
|
162 |
Â
parent::register();
|
163 |
Â
|
167 |
Â
/**
|
168 |
Â
* Override connector log for our own Settings / Actions
|
169 |
Â
*
|
170 |
+
* @param array $data Record data.
|
171 |
Â
*
|
172 |
Â
* @return array|bool
|
173 |
Â
*/
|
202 |
Â
} elseif ( 'posts' === $data['connector'] && in_array( $data['context'], array( 'forum', 'topic', 'reply' ), true ) ) {
|
203 |
Â
if ( 'reply' === $data['context'] ) {
|
204 |
Â
if ( 'updated' === $data['action'] ) {
|
205 |
+
/* translators: %s: a post title (e.g. "Hello World") */
|
206 |
+
$data['message'] = esc_html__( 'Replied on "%s"', 'stream' );
|
207 |
Â
$data['args']['post_title'] = get_post( wp_get_post_parent_id( $data['object_id'] ) )->post_title;
|
208 |
Â
}
|
209 |
Â
$data['args']['post_title'] = sprintf(
|
210 |
+
/* translators: %s a post title (e.g. "Hello World") */
|
211 |
Â
__( 'Reply to: %s', 'stream' ),
|
212 |
Â
get_post( wp_get_post_parent_id( $data['object_id'] ) )->post_title
|
213 |
Â
);
|
224 |
Â
/**
|
225 |
Â
* Tracks togging the forum topics
|
226 |
Â
*
|
227 |
+
* @param bool $success If action success.
|
228 |
+
* @param \WP_Post $post_data Post data.
|
229 |
+
* @param string $action Record action.
|
230 |
+
* @param string $message Message status data.
|
231 |
Â
*
|
232 |
Â
* @return array|bool
|
233 |
Â
*/
|
250 |
Â
$topic = get_post( $message['topic_id'] );
|
251 |
Â
|
252 |
Â
$this->log(
|
253 |
+
/* translators: %1$s: an action, %2$s: a topic title (e.g. "Created", "Read this first") */
|
254 |
Â
_x( '%1$s "%2$s" topic', '1: Action, 2: Topic title', 'stream' ),
|
255 |
Â
array(
|
256 |
Â
'action_title' => $actions[ $action ],
|
connectors/class-connector-blogs.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_Blogs extends Connector {
|
5 |
Â
/**
|
6 |
Â
* Connector slug
|
@@ -74,7 +83,7 @@ class Connector_Blogs extends Connector {
|
|
74 |
Â
|
75 |
Â
foreach ( $blogs as $blog ) {
|
76 |
Â
$blog_details = get_blog_details( $blog->blog_id );
|
77 |
-
$key =
|
78 |
Â
$labels[ $key ] = $blog_details->blogname;
|
79 |
Â
}
|
80 |
Â
}
|
@@ -87,8 +96,8 @@ class Connector_Blogs extends Connector {
|
|
87 |
Â
*
|
88 |
Â
* @filter wp_stream_action_links_{connector}
|
89 |
Â
*
|
90 |
-
* @param
|
91 |
-
* @param
|
92 |
Â
*
|
93 |
Â
* @return array
|
94 |
Â
*/
|
@@ -122,15 +131,15 @@ class Connector_Blogs extends Connector {
|
|
122 |
Â
*
|
123 |
Â
* @action wpmu_new_blog
|
124 |
Â
*
|
125 |
-
* @param int $blog_id
|
126 |
Â
*/
|
127 |
Â
public function callback_wpmu_new_blog( $blog_id ) {
|
128 |
Â
$blog = get_blog_details( $blog_id );
|
129 |
Â
|
130 |
Â
$this->log(
|
131 |
-
|
132 |
Â
_x(
|
133 |
-
'"%
|
134 |
Â
'1. Site name',
|
135 |
Â
'stream'
|
136 |
Â
),
|
@@ -148,16 +157,16 @@ class Connector_Blogs extends Connector {
|
|
148 |
Â
*
|
149 |
Â
* @action wpmu_activate_blog
|
150 |
Â
*
|
151 |
-
* @param int $blog_id
|
152 |
-
* @param int $user_id
|
153 |
Â
*/
|
154 |
Â
public function callback_wpmu_activate_blog( $blog_id, $user_id ) {
|
155 |
Â
$blog = get_blog_details( $blog_id );
|
156 |
Â
|
157 |
Â
$this->log(
|
158 |
-
|
159 |
Â
_x(
|
160 |
-
'"%
|
161 |
Â
'1. Site name',
|
162 |
Â
'stream'
|
163 |
Â
),
|
@@ -176,9 +185,9 @@ class Connector_Blogs extends Connector {
|
|
176 |
Â
*
|
177 |
Â
* @action add_user_to_blog
|
178 |
Â
*
|
179 |
-
* @param int $user_id
|
180 |
-
* @param string $role
|
181 |
-
* @param int $blog_id
|
182 |
Â
*/
|
183 |
Â
public function callback_add_user_to_blog( $user_id, $role, $blog_id ) {
|
184 |
Â
$blog = get_blog_details( $blog_id );
|
@@ -189,7 +198,7 @@ class Connector_Blogs extends Connector {
|
|
189 |
Â
}
|
190 |
Â
|
191 |
Â
$this->log(
|
192 |
-
|
193 |
Â
_x(
|
194 |
Â
'%1$s was added to the "%2$s" site with %3$s capabilities',
|
195 |
Â
'1. User\'s name, 2. Site name, 3. Role',
|
@@ -211,8 +220,8 @@ class Connector_Blogs extends Connector {
|
|
211 |
Â
*
|
212 |
Â
* @action remove_user_from_blog
|
213 |
Â
*
|
214 |
-
* @param int $user_id
|
215 |
-
* @param int $blog_id
|
216 |
Â
*/
|
217 |
Â
public function callback_remove_user_from_blog( $user_id, $blog_id ) {
|
218 |
Â
$blog = get_blog_details( $blog_id );
|
@@ -223,7 +232,7 @@ class Connector_Blogs extends Connector {
|
|
223 |
Â
}
|
224 |
Â
|
225 |
Â
$this->log(
|
226 |
-
|
227 |
Â
_x(
|
228 |
Â
'%1$s was removed from the "%2$s" site',
|
229 |
Â
'1. User\'s name, 2. Site name',
|
@@ -244,7 +253,7 @@ class Connector_Blogs extends Connector {
|
|
244 |
Â
*
|
245 |
Â
* @action make_spam_blog
|
246 |
Â
*
|
247 |
-
* @param int $blog_id
|
248 |
Â
*/
|
249 |
Â
public function callback_make_spam_blog( $blog_id ) {
|
250 |
Â
$this->callback_update_blog_status( $blog_id, esc_html__( 'marked as spam', 'stream' ), 'updated' );
|
@@ -255,7 +264,7 @@ class Connector_Blogs extends Connector {
|
|
255 |
Â
*
|
256 |
Â
* @action make_ham_blog
|
257 |
Â
*
|
258 |
-
* @param int $blog_id
|
259 |
Â
*/
|
260 |
Â
public function callback_make_ham_blog( $blog_id ) {
|
261 |
Â
$this->callback_update_blog_status( $blog_id, esc_html__( 'marked as not spam', 'stream' ), 'updated' );
|
@@ -266,7 +275,7 @@ class Connector_Blogs extends Connector {
|
|
266 |
Â
*
|
267 |
Â
* @action mature_blog
|
268 |
Â
*
|
269 |
-
* @param int $blog_id
|
270 |
Â
*/
|
271 |
Â
public function callback_mature_blog( $blog_id ) {
|
272 |
Â
$this->callback_update_blog_status( $blog_id, esc_html__( 'marked as mature', 'stream' ), 'updated' );
|
@@ -277,7 +286,7 @@ class Connector_Blogs extends Connector {
|
|
277 |
Â
*
|
278 |
Â
* @action unmature_blog
|
279 |
Â
*
|
280 |
-
* @param int $blog_id
|
281 |
Â
*/
|
282 |
Â
public function callback_unmature_blog( $blog_id ) {
|
283 |
Â
$this->callback_update_blog_status( $blog_id, esc_html__( 'marked as not mature', 'stream' ), 'updated' );
|
@@ -288,7 +297,7 @@ class Connector_Blogs extends Connector {
|
|
288 |
Â
*
|
289 |
Â
* @action archive_blog
|
290 |
Â
*
|
291 |
-
* @param int $blog_id
|
292 |
Â
*/
|
293 |
Â
public function callback_archive_blog( $blog_id ) {
|
294 |
Â
$this->callback_update_blog_status( $blog_id, esc_html__( 'archived', 'stream' ), 'archive_blog' );
|
@@ -299,7 +308,7 @@ class Connector_Blogs extends Connector {
|
|
299 |
Â
*
|
300 |
Â
* @action unarchive_blog
|
301 |
Â
*
|
302 |
-
* @param int $blog_id
|
303 |
Â
*/
|
304 |
Â
public function callback_unarchive_blog( $blog_id ) {
|
305 |
Â
$this->callback_update_blog_status( $blog_id, esc_html__( 'restored from archive', 'stream' ), 'updated' );
|
@@ -310,7 +319,7 @@ class Connector_Blogs extends Connector {
|
|
310 |
Â
*
|
311 |
Â
* @action make_delete_blog
|
312 |
Â
*
|
313 |
-
* @param int $blog_id
|
314 |
Â
*/
|
315 |
Â
public function callback_make_delete_blog( $blog_id ) {
|
316 |
Â
$this->callback_update_blog_status( $blog_id, esc_html__( 'deleted', 'stream' ), 'deleted' );
|
@@ -321,7 +330,7 @@ class Connector_Blogs extends Connector {
|
|
321 |
Â
*
|
322 |
Â
* @action undelete_blog
|
323 |
Â
*
|
324 |
-
* @param int $blog_id
|
325 |
Â
*/
|
326 |
Â
public function callback_make_undelete_blog( $blog_id ) {
|
327 |
Â
$this->callback_update_blog_status( $blog_id, esc_html__( 'restored', 'stream' ), 'updated' );
|
@@ -332,8 +341,8 @@ class Connector_Blogs extends Connector {
|
|
332 |
Â
*
|
333 |
Â
* @action update_blog_public
|
334 |
Â
*
|
335 |
-
* @param int $blog_id
|
336 |
-
* @param string $value
|
337 |
Â
*/
|
338 |
Â
public function callback_update_blog_public( $blog_id, $value ) {
|
339 |
Â
if ( $value ) {
|
@@ -350,15 +359,15 @@ class Connector_Blogs extends Connector {
|
|
350 |
Â
*
|
351 |
Â
* @action update_blog_status
|
352 |
Â
*
|
353 |
-
* @param int $blog_id
|
354 |
-
* @param string $status
|
355 |
-
* @param string $action
|
356 |
Â
*/
|
357 |
Â
public function callback_update_blog_status( $blog_id, $status, $action ) {
|
358 |
Â
$blog = get_blog_details( $blog_id );
|
359 |
Â
|
360 |
Â
$this->log(
|
361 |
-
|
362 |
Â
_x(
|
363 |
Â
'"%1$s" site was %2$s',
|
364 |
Â
'1. Site name, 2. Status',
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for Blog actions.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_Blogs
|
12 |
+
*/
|
13 |
Â
class Connector_Blogs extends Connector {
|
14 |
Â
/**
|
15 |
Â
* Connector slug
|
83 |
Â
|
84 |
Â
foreach ( $blogs as $blog ) {
|
85 |
Â
$blog_details = get_blog_details( $blog->blog_id );
|
86 |
+
$key = sprintf( 'blog-%d', $blog->blog_id );
|
87 |
Â
$labels[ $key ] = $blog_details->blogname;
|
88 |
Â
}
|
89 |
Â
}
|
96 |
Â
*
|
97 |
Â
* @filter wp_stream_action_links_{connector}
|
98 |
Â
*
|
99 |
+
* @param array $links Previous links registered.
|
100 |
+
* @param object $record Stream record.
|
101 |
Â
*
|
102 |
Â
* @return array
|
103 |
Â
*/
|
131 |
Â
*
|
132 |
Â
* @action wpmu_new_blog
|
133 |
Â
*
|
134 |
+
* @param int $blog_id Blog ID.
|
135 |
Â
*/
|
136 |
Â
public function callback_wpmu_new_blog( $blog_id ) {
|
137 |
Â
$blog = get_blog_details( $blog_id );
|
138 |
Â
|
139 |
Â
$this->log(
|
140 |
+
/* translators: %s: site name (e.g. "FooBar Blog") */
|
141 |
Â
_x(
|
142 |
+
'"%s" site was created',
|
143 |
Â
'1. Site name',
|
144 |
Â
'stream'
|
145 |
Â
),
|
157 |
Â
*
|
158 |
Â
* @action wpmu_activate_blog
|
159 |
Â
*
|
160 |
+
* @param int $blog_id Blog ID.
|
161 |
+
* @param int $user_id User ID.
|
162 |
Â
*/
|
163 |
Â
public function callback_wpmu_activate_blog( $blog_id, $user_id ) {
|
164 |
Â
$blog = get_blog_details( $blog_id );
|
165 |
Â
|
166 |
Â
$this->log(
|
167 |
+
/* translators: %s: site name (e.g. "FooBar Blog") */
|
168 |
Â
_x(
|
169 |
+
'"%s" site was registered',
|
170 |
Â
'1. Site name',
|
171 |
Â
'stream'
|
172 |
Â
),
|
185 |
Â
*
|
186 |
Â
* @action add_user_to_blog
|
187 |
Â
*
|
188 |
+
* @param int $user_id User ID.
|
189 |
+
* @param string $role User role.
|
190 |
+
* @param int $blog_id Blog ID.
|
191 |
Â
*/
|
192 |
Â
public function callback_add_user_to_blog( $user_id, $role, $blog_id ) {
|
193 |
Â
$blog = get_blog_details( $blog_id );
|
198 |
Â
}
|
199 |
Â
|
200 |
Â
$this->log(
|
201 |
+
/* translators: %1$s: a user's display name, %2$s: a site name, %3$s: a user role (e.g. "Jane Doe", "FooBar Blog", "subscriber") */
|
202 |
Â
_x(
|
203 |
Â
'%1$s was added to the "%2$s" site with %3$s capabilities',
|
204 |
Â
'1. User\'s name, 2. Site name, 3. Role',
|
220 |
Â
*
|
221 |
Â
* @action remove_user_from_blog
|
222 |
Â
*
|
223 |
+
* @param int $user_id User ID.
|
224 |
+
* @param int $blog_id Blog ID.
|
225 |
Â
*/
|
226 |
Â
public function callback_remove_user_from_blog( $user_id, $blog_id ) {
|
227 |
Â
$blog = get_blog_details( $blog_id );
|
232 |
Â
}
|
233 |
Â
|
234 |
Â
$this->log(
|
235 |
+
/* translators: %1$s: a user's display name, %2$s: a site name (e.g. "Jane Doe", "FooBar Blog") */
|
236 |
Â
_x(
|
237 |
Â
'%1$s was removed from the "%2$s" site',
|
238 |
Â
'1. User\'s name, 2. Site name',
|
253 |
Â
*
|
254 |
Â
* @action make_spam_blog
|
255 |
Â
*
|
256 |
+
* @param int $blog_id Blog ID.
|
257 |
Â
*/
|
258 |
Â
public function callback_make_spam_blog( $blog_id ) {
|
259 |
Â
$this->callback_update_blog_status( $blog_id, esc_html__( 'marked as spam', 'stream' ), 'updated' );
|
264 |
Â
*
|
265 |
Â
* @action make_ham_blog
|
266 |
Â
*
|
267 |
+
* @param int $blog_id Blog ID.
|
268 |
Â
*/
|
269 |
Â
public function callback_make_ham_blog( $blog_id ) {
|
270 |
Â
$this->callback_update_blog_status( $blog_id, esc_html__( 'marked as not spam', 'stream' ), 'updated' );
|
275 |
Â
*
|
276 |
Â
* @action mature_blog
|
277 |
Â
*
|
278 |
+
* @param int $blog_id Blog ID.
|
279 |
Â
*/
|
280 |
Â
public function callback_mature_blog( $blog_id ) {
|
281 |
Â
$this->callback_update_blog_status( $blog_id, esc_html__( 'marked as mature', 'stream' ), 'updated' );
|
286 |
Â
*
|
287 |
Â
* @action unmature_blog
|
288 |
Â
*
|
289 |
+
* @param int $blog_id Blog ID.
|
290 |
Â
*/
|
291 |
Â
public function callback_unmature_blog( $blog_id ) {
|
292 |
Â
$this->callback_update_blog_status( $blog_id, esc_html__( 'marked as not mature', 'stream' ), 'updated' );
|
297 |
Â
*
|
298 |
Â
* @action archive_blog
|
299 |
Â
*
|
300 |
+
* @param int $blog_id Blog ID.
|
301 |
Â
*/
|
302 |
Â
public function callback_archive_blog( $blog_id ) {
|
303 |
Â
$this->callback_update_blog_status( $blog_id, esc_html__( 'archived', 'stream' ), 'archive_blog' );
|
308 |
Â
*
|
309 |
Â
* @action unarchive_blog
|
310 |
Â
*
|
311 |
+
* @param int $blog_id Blog ID.
|
312 |
Â
*/
|
313 |
Â
public function callback_unarchive_blog( $blog_id ) {
|
314 |
Â
$this->callback_update_blog_status( $blog_id, esc_html__( 'restored from archive', 'stream' ), 'updated' );
|
319 |
Â
*
|
320 |
Â
* @action make_delete_blog
|
321 |
Â
*
|
322 |
+
* @param int $blog_id Blog ID.
|
323 |
Â
*/
|
324 |
Â
public function callback_make_delete_blog( $blog_id ) {
|
325 |
Â
$this->callback_update_blog_status( $blog_id, esc_html__( 'deleted', 'stream' ), 'deleted' );
|
330 |
Â
*
|
331 |
Â
* @action undelete_blog
|
332 |
Â
*
|
333 |
+
* @param int $blog_id Blog ID.
|
334 |
Â
*/
|
335 |
Â
public function callback_make_undelete_blog( $blog_id ) {
|
336 |
Â
$this->callback_update_blog_status( $blog_id, esc_html__( 'restored', 'stream' ), 'updated' );
|
341 |
Â
*
|
342 |
Â
* @action update_blog_public
|
343 |
Â
*
|
344 |
+
* @param int $blog_id Blog ID.
|
345 |
+
* @param string $value Status flag.
|
346 |
Â
*/
|
347 |
Â
public function callback_update_blog_public( $blog_id, $value ) {
|
348 |
Â
if ( $value ) {
|
359 |
Â
*
|
360 |
Â
* @action update_blog_status
|
361 |
Â
*
|
362 |
+
* @param int $blog_id Blog ID.
|
363 |
+
* @param string $status Blog Status.
|
364 |
+
* @param string $action Action.
|
365 |
Â
*/
|
366 |
Â
public function callback_update_blog_status( $blog_id, $status, $action ) {
|
367 |
Â
$blog = get_blog_details( $blog_id );
|
368 |
Â
|
369 |
Â
$this->log(
|
370 |
+
/* translators: %1$s: a site name, %2$s: a blog status (e.g. "FooBar Blog", "archived") */
|
371 |
Â
_x(
|
372 |
Â
'"%1$s" site was %2$s',
|
373 |
Â
'1. Site name, 2. Status',
|
connectors/class-connector-buddypress.php
CHANGED
@@ -1,7 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
|
3 |
Â
namespace WP_Stream;
|
4 |
Â
|
Â
|
|
Â
|
|
Â
|
|
5 |
Â
class Connector_BuddyPress extends Connector {
|
6 |
Â
|
7 |
Â
/**
|
@@ -79,16 +87,22 @@ class Connector_BuddyPress extends Connector {
|
|
79 |
Â
public $is_update = false;
|
80 |
Â
|
81 |
Â
/**
|
Â
|
|
Â
|
|
82 |
Â
* @var bool
|
83 |
Â
*/
|
84 |
-
public $
|
85 |
Â
|
86 |
Â
/**
|
Â
|
|
Â
|
|
87 |
Â
* @var array
|
88 |
Â
*/
|
89 |
-
public $
|
90 |
Â
|
91 |
Â
/**
|
Â
|
|
Â
|
|
92 |
Â
* @var bool
|
93 |
Â
*/
|
94 |
Â
public $ignore_activity_bulk_deletion = false;
|
@@ -153,8 +167,8 @@ class Connector_BuddyPress extends Connector {
|
|
153 |
Â
*
|
154 |
Â
* @filter wp_stream_action_links_{connector}
|
155 |
Â
*
|
156 |
-
* @param array $links
|
157 |
-
* @param object $record
|
158 |
Â
*
|
159 |
Â
* @return array Action links
|
160 |
Â
*/
|
@@ -200,7 +214,7 @@ class Connector_BuddyPress extends Connector {
|
|
200 |
Â
);
|
201 |
Â
|
202 |
Â
if ( $group ) {
|
203 |
-
// Build actions URLs
|
204 |
Â
$base_url = \bp_get_admin_url( 'admin.php?page=bp-groups&gid=' . $group_id );
|
205 |
Â
$delete_url = wp_nonce_url( $base_url . '&action=delete', 'bp-groups-delete' );
|
206 |
Â
$edit_url = $base_url . '&action=edit';
|
@@ -240,7 +254,7 @@ class Connector_BuddyPress extends Connector {
|
|
240 |
Â
$field_id = $record->get_meta( 'field_id', true );
|
241 |
Â
$group_id = $record->get_meta( 'group_id', true );
|
242 |
Â
|
243 |
-
if ( empty( $field_id ) ) { // is a group action
|
244 |
Â
$links[ esc_html__( 'Edit', 'stream' ) ] = add_query_arg(
|
245 |
Â
array(
|
246 |
Â
'page' => 'bp-profile-setup',
|
@@ -285,6 +299,9 @@ class Connector_BuddyPress extends Connector {
|
|
285 |
Â
return $links;
|
286 |
Â
}
|
287 |
Â
|
Â
|
|
Â
|
|
Â
|
|
288 |
Â
public function register() {
|
289 |
Â
parent::register();
|
290 |
Â
|
@@ -335,30 +352,73 @@ class Connector_BuddyPress extends Connector {
|
|
335 |
Â
);
|
336 |
Â
}
|
337 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
338 |
Â
public function callback_update_option( $option, $old, $new ) {
|
339 |
Â
$this->check( $option, $old, $new );
|
340 |
Â
}
|
341 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
342 |
Â
public function callback_add_option( $option, $val ) {
|
343 |
Â
$this->check( $option, null, $val );
|
344 |
Â
}
|
345 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
346 |
Â
public function callback_delete_option( $option ) {
|
347 |
Â
$this->check( $option, null, null );
|
348 |
Â
}
|
349 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
350 |
Â
public function callback_update_site_option( $option, $old, $new ) {
|
351 |
Â
$this->check( $option, $old, $new );
|
352 |
Â
}
|
353 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
354 |
Â
public function callback_add_site_option( $option, $val ) {
|
355 |
Â
$this->check( $option, null, $val );
|
356 |
Â
}
|
357 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
358 |
Â
public function callback_delete_site_option( $option ) {
|
359 |
Â
$this->check( $option, null, null );
|
360 |
Â
}
|
361 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
362 |
Â
public function check( $option, $old_value, $new_value ) {
|
363 |
Â
if ( ! array_key_exists( $option, $this->options ) ) {
|
364 |
Â
return;
|
@@ -382,7 +442,7 @@ class Connector_BuddyPress extends Connector {
|
|
382 |
Â
$page = isset( $data['page'] ) ? $data['page'] : null;
|
383 |
Â
|
384 |
Â
$this->log(
|
385 |
-
|
386 |
Â
__( '"%s" setting updated', 'stream' ),
|
387 |
Â
compact( 'option_title', 'option', 'old_value', 'new_value', 'page' ),
|
388 |
Â
null,
|
@@ -392,6 +452,12 @@ class Connector_BuddyPress extends Connector {
|
|
392 |
Â
}
|
393 |
Â
}
|
394 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
395 |
Â
public function check_bp_active_components( $old_value, $new_value ) {
|
396 |
Â
$options = array();
|
397 |
Â
|
@@ -417,7 +483,7 @@ class Connector_BuddyPress extends Connector {
|
|
417 |
Â
|
418 |
Â
$this->log(
|
419 |
Â
sprintf(
|
420 |
-
|
421 |
Â
__( '"%1$s" component %2$s', 'stream' ),
|
422 |
Â
$components[ $option ]['title'],
|
423 |
Â
$actions[ $option_value ]
|
@@ -435,6 +501,12 @@ class Connector_BuddyPress extends Connector {
|
|
435 |
Â
}
|
436 |
Â
}
|
437 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
438 |
Â
public function check_bp_pages( $old_value, $new_value ) {
|
439 |
Â
$options = array();
|
440 |
Â
|
@@ -463,7 +535,7 @@ class Connector_BuddyPress extends Connector {
|
|
463 |
Â
|
464 |
Â
$this->log(
|
465 |
Â
sprintf(
|
466 |
-
|
467 |
Â
__( '"%1$s" page set to "%2$s"', 'stream' ),
|
468 |
Â
$pages[ $option ],
|
469 |
Â
$page
|
@@ -482,26 +554,40 @@ class Connector_BuddyPress extends Connector {
|
|
482 |
Â
}
|
483 |
Â
}
|
484 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
485 |
Â
public function callback_bp_before_activity_delete( $args ) {
|
486 |
-
if ( empty( $args['id'] ) ) { // Bail if we're deleting in bulk
|
487 |
-
$this->
|
488 |
Â
|
489 |
Â
return;
|
490 |
Â
}
|
491 |
Â
|
492 |
Â
$activity = new \BP_Activity_Activity( $args['id'] );
|
493 |
Â
|
494 |
-
$this->
|
495 |
Â
}
|
496 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
497 |
Â
public function callback_bp_activity_deleted_activities( $activities_ids ) {
|
498 |
-
if ( 1 === count( $activities_ids ) && isset( $this->
|
499 |
-
$activity = $this->
|
500 |
Â
$this->log(
|
501 |
Â
sprintf(
|
502 |
-
|
503 |
Â
__( '"%s" activity deleted', 'stream' ),
|
504 |
-
|
505 |
Â
),
|
506 |
Â
array(
|
507 |
Â
'id' => $activity->id,
|
@@ -513,9 +599,12 @@ class Connector_BuddyPress extends Connector {
|
|
513 |
Â
$activity->component,
|
514 |
Â
'deleted'
|
515 |
Â
);
|
516 |
-
} else {
|
517 |
-
|
518 |
-
|
Â
|
|
Â
|
|
Â
|
|
519 |
Â
if ( $this->ignore_activity_bulk_deletion ) {
|
520 |
Â
$this->ignore_activity_bulk_deletion = false;
|
521 |
Â
|
@@ -523,13 +612,13 @@ class Connector_BuddyPress extends Connector {
|
|
523 |
Â
}
|
524 |
Â
$this->log(
|
525 |
Â
sprintf(
|
526 |
-
|
527 |
Â
__( '"%s" activities were deleted', 'stream' ),
|
528 |
Â
count( $activities_ids )
|
529 |
Â
),
|
530 |
Â
array(
|
531 |
Â
'count' => count( $activities_ids ),
|
532 |
-
'args' => $this->
|
533 |
Â
'ids' => $activities_ids,
|
534 |
Â
),
|
535 |
Â
null,
|
@@ -539,14 +628,22 @@ class Connector_BuddyPress extends Connector {
|
|
539 |
Â
}
|
540 |
Â
}
|
541 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
542 |
Â
public function callback_bp_activity_mark_as_spam( $activity, $by ) {
|
543 |
Â
unset( $by );
|
544 |
Â
|
545 |
Â
$this->log(
|
546 |
Â
sprintf(
|
547 |
-
|
548 |
Â
__( 'Marked activity "%s" as spam', 'stream' ),
|
549 |
-
|
550 |
Â
),
|
551 |
Â
array(
|
552 |
Â
'id' => $activity->id,
|
@@ -560,14 +657,22 @@ class Connector_BuddyPress extends Connector {
|
|
560 |
Â
);
|
561 |
Â
}
|
562 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
563 |
Â
public function callback_bp_activity_mark_as_ham( $activity, $by ) {
|
564 |
Â
unset( $by );
|
565 |
Â
|
566 |
Â
$this->log(
|
567 |
Â
sprintf(
|
568 |
-
|
569 |
Â
__( 'Unmarked activity "%s" as spam', 'stream' ),
|
570 |
-
|
571 |
Â
),
|
572 |
Â
array(
|
573 |
Â
'id' => $activity->id,
|
@@ -581,14 +686,22 @@ class Connector_BuddyPress extends Connector {
|
|
581 |
Â
);
|
582 |
Â
}
|
583 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
584 |
Â
public function callback_bp_activity_admin_edit_after( $activity, $error ) {
|
585 |
Â
unset( $error );
|
586 |
Â
|
587 |
Â
$this->log(
|
588 |
Â
sprintf(
|
589 |
-
|
590 |
Â
__( '"%s" activity updated', 'stream' ),
|
591 |
-
|
592 |
Â
),
|
593 |
Â
array(
|
594 |
Â
'id' => $activity->id,
|
@@ -602,6 +715,14 @@ class Connector_BuddyPress extends Connector {
|
|
602 |
Â
);
|
603 |
Â
}
|
604 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
605 |
Â
public function group_action( $group, $action, $meta = array(), $message = null ) {
|
606 |
Â
if ( is_numeric( $group ) ) {
|
607 |
Â
$group = \groups_get_group(
|
@@ -617,30 +738,30 @@ class Connector_BuddyPress extends Connector {
|
|
617 |
Â
|
618 |
Â
if ( ! $message ) {
|
619 |
Â
if ( 'created' === $action ) {
|
620 |
-
|
621 |
Â
$message = esc_html__( '"%s" group created', 'stream' );
|
622 |
Â
} elseif ( 'updated' === $action ) {
|
623 |
-
|
624 |
Â
$message = esc_html__( '"%s" group updated', 'stream' );
|
625 |
Â
} elseif ( 'deleted' === $action ) {
|
626 |
-
|
627 |
Â
$message = esc_html__( '"%s" group deleted', 'stream' );
|
628 |
Â
} elseif ( 'joined' === $action ) {
|
629 |
-
|
630 |
Â
$message = esc_html__( 'Joined group "%s"', 'stream' );
|
631 |
Â
} elseif ( 'left' === $action ) {
|
632 |
-
|
633 |
Â
$message = esc_html__( 'Left group "%s"', 'stream' );
|
634 |
Â
} elseif ( 'banned' === $action ) {
|
635 |
-
|
636 |
Â
$message = esc_html__( 'Banned "%2$s" from "%1$s"', 'stream' );
|
637 |
Â
$replacements[] = get_user_by( 'id', $meta['user_id'] )->display_name;
|
638 |
Â
} elseif ( 'unbanned' === $action ) {
|
639 |
-
|
640 |
Â
$message = esc_html__( 'Unbanned "%2$s" from "%1$s"', 'stream' );
|
641 |
Â
$replacements[] = get_user_by( 'id', $meta['user_id'] )->display_name;
|
642 |
Â
} elseif ( 'removed' === $action ) {
|
643 |
-
|
644 |
Â
$message = esc_html__( 'Removed "%2$s" from "%1$s"', 'stream' );
|
645 |
Â
$replacements[] = get_user_by( 'id', $meta['user_id'] )->display_name;
|
646 |
Â
} else {
|
@@ -667,6 +788,15 @@ class Connector_BuddyPress extends Connector {
|
|
667 |
Â
);
|
668 |
Â
}
|
669 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
670 |
Â
public function callback_groups_create_group( $group_id, $member, $group ) {
|
671 |
Â
unset( $group_id );
|
672 |
Â
unset( $member );
|
@@ -674,22 +804,51 @@ class Connector_BuddyPress extends Connector {
|
|
674 |
Â
$this->group_action( $group, 'created' );
|
675 |
Â
}
|
676 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
677 |
Â
public function callback_groups_update_group( $group_id, $group ) {
|
678 |
Â
unset( $group_id );
|
679 |
Â
|
680 |
Â
$this->group_action( $group, 'updated' );
|
681 |
Â
}
|
682 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
683 |
Â
public function callback_groups_before_delete_group( $group_id ) {
|
684 |
Â
$this->ignore_activity_bulk_deletion = true;
|
685 |
Â
$this->group_action( $group_id, 'deleted' );
|
686 |
Â
}
|
687 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
688 |
Â
public function callback_groups_details_updated( $group_id ) {
|
689 |
Â
$this->is_update = true;
|
690 |
Â
$this->group_action( $group_id, 'updated' );
|
691 |
Â
}
|
692 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
693 |
Â
public function callback_groups_settings_updated( $group_id ) {
|
694 |
Â
if ( $this->is_update ) {
|
695 |
Â
return;
|
@@ -697,14 +856,39 @@ class Connector_BuddyPress extends Connector {
|
|
697 |
Â
$this->group_action( $group_id, 'updated' );
|
698 |
Â
}
|
699 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
700 |
Â
public function callback_groups_leave_group( $group_id, $user_id ) {
|
701 |
Â
$this->group_action( $group_id, 'left', compact( 'user_id' ) );
|
702 |
Â
}
|
703 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
704 |
Â
public function callback_groups_join_group( $group_id, $user_id ) {
|
705 |
Â
$this->group_action( $group_id, 'joined', compact( 'user_id' ) );
|
706 |
Â
}
|
707 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
708 |
Â
public function callback_groups_promote_member( $group_id, $user_id, $status ) {
|
709 |
Â
$group = \groups_get_group(
|
710 |
Â
array(
|
@@ -717,7 +901,7 @@ class Connector_BuddyPress extends Connector {
|
|
717 |
Â
'mod' => esc_html_x( 'Moderator', 'buddypress', 'stream' ),
|
718 |
Â
);
|
719 |
Â
$message = sprintf(
|
720 |
-
|
721 |
Â
__( 'Promoted "%1$s" to "%2$s" in "%3$s"', 'stream' ),
|
722 |
Â
$user->display_name,
|
723 |
Â
$roles[ $status ],
|
@@ -726,6 +910,14 @@ class Connector_BuddyPress extends Connector {
|
|
726 |
Â
$this->group_action( $group_id, 'promoted', compact( 'user_id', 'status' ), $message );
|
727 |
Â
}
|
728 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
729 |
Â
public function callback_groups_demote_member( $group_id, $user_id ) {
|
730 |
Â
$group = \groups_get_group(
|
731 |
Â
array(
|
@@ -734,7 +926,7 @@ class Connector_BuddyPress extends Connector {
|
|
734 |
Â
);
|
735 |
Â
$user = new \WP_User( $user_id );
|
736 |
Â
$message = sprintf(
|
737 |
-
|
738 |
Â
__( 'Demoted "%1$s" to "%2$s" in "%3$s"', 'stream' ),
|
739 |
Â
$user->display_name,
|
740 |
Â
_x( 'Member', 'buddypress', 'stream' ),
|
@@ -743,18 +935,50 @@ class Connector_BuddyPress extends Connector {
|
|
743 |
Â
$this->group_action( $group_id, 'demoted', compact( 'user_id' ), $message );
|
744 |
Â
}
|
745 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
746 |
Â
public function callback_groups_ban_member( $group_id, $user_id ) {
|
747 |
Â
$this->group_action( $group_id, 'banned', compact( 'user_id' ) );
|
748 |
Â
}
|
749 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
750 |
Â
public function callback_groups_unban_member( $group_id, $user_id ) {
|
751 |
Â
$this->group_action( $group_id, 'unbanned', compact( 'user_id' ) );
|
752 |
Â
}
|
753 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
754 |
Â
public function callback_groups_remove_member( $group_id, $user_id ) {
|
755 |
Â
$this->group_action( $group_id, 'removed', compact( 'user_id' ) );
|
756 |
Â
}
|
757 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
758 |
Â
public function field_action( $field, $action, $meta = array(), $message = null ) {
|
759 |
Â
$replacements = array(
|
760 |
Â
$field->name,
|
@@ -762,13 +986,13 @@ class Connector_BuddyPress extends Connector {
|
|
762 |
Â
|
763 |
Â
if ( ! $message ) {
|
764 |
Â
if ( 'created' === $action ) {
|
765 |
-
|
766 |
Â
$message = esc_html__( 'Created profile field "%s"', 'stream' );
|
767 |
Â
} elseif ( 'updated' === $action ) {
|
768 |
-
|
769 |
Â
$message = esc_html__( 'Updated profile field "%s"', 'stream' );
|
770 |
Â
} elseif ( 'deleted' === $action ) {
|
771 |
-
|
772 |
Â
$message = esc_html__( 'Deleted profile field "%s"', 'stream' );
|
773 |
Â
} else {
|
774 |
Â
return;
|
@@ -794,15 +1018,37 @@ class Connector_BuddyPress extends Connector {
|
|
794 |
Â
);
|
795 |
Â
}
|
796 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
797 |
Â
public function callback_xprofile_field_after_save( $field ) {
|
798 |
Â
$action = isset( $field->id ) ? 'updated' : 'created';
|
799 |
Â
$this->field_action( $field, $action );
|
800 |
Â
}
|
801 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
802 |
Â
public function callback_xprofile_fields_deleted_field( $field ) {
|
803 |
Â
$this->field_action( $field, 'deleted' );
|
804 |
Â
}
|
805 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
806 |
Â
public function field_group_action( $group, $action, $meta = array(), $message = null ) {
|
807 |
Â
$replacements = array(
|
808 |
Â
$group->name,
|
@@ -810,13 +1056,13 @@ class Connector_BuddyPress extends Connector {
|
|
810 |
Â
|
811 |
Â
if ( ! $message ) {
|
812 |
Â
if ( 'created' === $action ) {
|
813 |
-
|
814 |
Â
$message = esc_html__( 'Created profile field group "%s"', 'stream' );
|
815 |
Â
} elseif ( 'updated' === $action ) {
|
816 |
-
|
817 |
Â
$message = esc_html__( 'Updated profile field group "%s"', 'stream' );
|
818 |
Â
} elseif ( 'deleted' === $action ) {
|
819 |
-
|
820 |
Â
$message = esc_html__( 'Deleted profile field group "%s"', 'stream' );
|
821 |
Â
} else {
|
822 |
Â
return;
|
@@ -841,27 +1087,49 @@ class Connector_BuddyPress extends Connector {
|
|
841 |
Â
);
|
842 |
Â
}
|
843 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
844 |
Â
public function callback_xprofile_group_after_save( $group ) {
|
845 |
Â
global $wpdb;
|
846 |
-
|
Â
|
|
Â
|
|
Â
|
|
847 |
Â
$action = ( $group->id === $wpdb->insert_id ) ? 'created' : 'updated';
|
848 |
Â
$this->field_group_action( $group, $action );
|
849 |
Â
}
|
850 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
851 |
Â
public function callback_xprofile_groups_deleted_group( $group ) {
|
852 |
Â
$this->field_group_action( $group, 'deleted' );
|
853 |
Â
}
|
854 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
855 |
Â
private function bp_get_directory_pages() {
|
856 |
Â
$bp = \buddypress();
|
857 |
Â
$directory_pages = array();
|
858 |
Â
|
859 |
-
// Loop through loaded components and collect directories
|
860 |
Â
if ( is_array( $bp->loaded_components ) ) {
|
861 |
Â
foreach ( $bp->loaded_components as $component_slug => $component_id ) {
|
862 |
-
// Only components that need directories should be listed here
|
863 |
Â
if ( isset( $bp->{$component_id} ) && ! empty( $bp->{$component_id}->has_directory ) ) {
|
864 |
-
// component->name was introduced in BP 1.5, so we must provide a fallback
|
865 |
Â
$directory_pages[ $component_id ] = ! empty( $bp->{$component_id}->name ) ? $bp->{$component_id}->name : ucwords( $component_id );
|
866 |
Â
}
|
867 |
Â
}
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for BuddyPress
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
Â
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_BuddyPress
|
12 |
+
*/
|
13 |
Â
class Connector_BuddyPress extends Connector {
|
14 |
Â
|
15 |
Â
/**
|
87 |
Â
public $is_update = false;
|
88 |
Â
|
89 |
Â
/**
|
90 |
+
* Stores an activity to be deleted for use across multiple callbacks.
|
91 |
+
*
|
92 |
Â
* @var bool
|
93 |
Â
*/
|
94 |
+
public $deleted_activity = false;
|
95 |
Â
|
96 |
Â
/**
|
97 |
+
* Stores post data of an activity to be deleted for use across multiple callbacks.
|
98 |
+
*
|
99 |
Â
* @var array
|
100 |
Â
*/
|
101 |
+
public $delete_activity_args = array();
|
102 |
Â
|
103 |
Â
/**
|
104 |
+
* Flag for ignoring irrelevant activity deletions.
|
105 |
+
*
|
106 |
Â
* @var bool
|
107 |
Â
*/
|
108 |
Â
public $ignore_activity_bulk_deletion = false;
|
167 |
Â
*
|
168 |
Â
* @filter wp_stream_action_links_{connector}
|
169 |
Â
*
|
170 |
+
* @param array $links Previous links registered.
|
171 |
+
* @param object $record Stream record.
|
172 |
Â
*
|
173 |
Â
* @return array Action links
|
174 |
Â
*/
|
214 |
Â
);
|
215 |
Â
|
216 |
Â
if ( $group ) {
|
217 |
+
// Build actions URLs.
|
218 |
Â
$base_url = \bp_get_admin_url( 'admin.php?page=bp-groups&gid=' . $group_id );
|
219 |
Â
$delete_url = wp_nonce_url( $base_url . '&action=delete', 'bp-groups-delete' );
|
220 |
Â
$edit_url = $base_url . '&action=edit';
|
254 |
Â
$field_id = $record->get_meta( 'field_id', true );
|
255 |
Â
$group_id = $record->get_meta( 'group_id', true );
|
256 |
Â
|
257 |
+
if ( empty( $field_id ) ) { // is a group action.
|
258 |
Â
$links[ esc_html__( 'Edit', 'stream' ) ] = add_query_arg(
|
259 |
Â
array(
|
260 |
Â
'page' => 'bp-profile-setup',
|
299 |
Â
return $links;
|
300 |
Â
}
|
301 |
Â
|
302 |
+
/**
|
303 |
+
* Register the connector
|
304 |
+
*/
|
305 |
Â
public function register() {
|
306 |
Â
parent::register();
|
307 |
Â
|
352 |
Â
);
|
353 |
Â
}
|
354 |
Â
|
355 |
+
/**
|
356 |
+
* Track buddyPress-specific option changes.
|
357 |
+
*
|
358 |
+
* @param string $option Option key.
|
359 |
+
* @param string $old Old value.
|
360 |
+
* @param string $new New value.
|
361 |
+
*/
|
362 |
Â
public function callback_update_option( $option, $old, $new ) {
|
363 |
Â
$this->check( $option, $old, $new );
|
364 |
Â
}
|
365 |
Â
|
366 |
+
/**
|
367 |
+
* Track buddyPress-specific option creations.
|
368 |
+
*
|
369 |
+
* @param string $option Option key.
|
370 |
+
* @param string $val Value.
|
371 |
+
*/
|
372 |
Â
public function callback_add_option( $option, $val ) {
|
373 |
Â
$this->check( $option, null, $val );
|
374 |
Â
}
|
375 |
Â
|
376 |
+
/**
|
377 |
+
* Track buddyPress-specific option deletions.
|
378 |
+
*
|
379 |
+
* @param string $option Option key.
|
380 |
+
*/
|
381 |
Â
public function callback_delete_option( $option ) {
|
382 |
Â
$this->check( $option, null, null );
|
383 |
Â
}
|
384 |
Â
|
385 |
+
/**
|
386 |
+
* Track buddyPress-specific site option changes
|
387 |
+
*
|
388 |
+
* @param string $option Option key.
|
389 |
+
* @param string $old Old value.
|
390 |
+
* @param string $new New value.
|
391 |
+
*/
|
392 |
Â
public function callback_update_site_option( $option, $old, $new ) {
|
393 |
Â
$this->check( $option, $old, $new );
|
394 |
Â
}
|
395 |
Â
|
396 |
+
/**
|
397 |
+
* Track buddyPress-specific site option creations.
|
398 |
+
*
|
399 |
+
* @param string $option Option key.
|
400 |
+
* @param string $val Value.
|
401 |
+
*/
|
402 |
Â
public function callback_add_site_option( $option, $val ) {
|
403 |
Â
$this->check( $option, null, $val );
|
404 |
Â
}
|
405 |
Â
|
406 |
+
/**
|
407 |
+
* Track buddyPress-specific site option deletions.
|
408 |
+
*
|
409 |
+
* @param string $option Option key.
|
410 |
+
*/
|
411 |
Â
public function callback_delete_site_option( $option ) {
|
412 |
Â
$this->check( $option, null, null );
|
413 |
Â
}
|
414 |
Â
|
415 |
+
/**
|
416 |
+
* Logs buddyPress-specific (site) option action.
|
417 |
+
*
|
418 |
+
* @param string $option Option key.
|
419 |
+
* @param string $old_value Old value.
|
420 |
+
* @param string $new_value New value.
|
421 |
+
*/
|
422 |
Â
public function check( $option, $old_value, $new_value ) {
|
423 |
Â
if ( ! array_key_exists( $option, $this->options ) ) {
|
424 |
Â
return;
|
442 |
Â
$page = isset( $data['page'] ) ? $data['page'] : null;
|
443 |
Â
|
444 |
Â
$this->log(
|
445 |
+
/* translators: %s: setting name (e.g. "Group Creation") */
|
446 |
Â
__( '"%s" setting updated', 'stream' ),
|
447 |
Â
compact( 'option_title', 'option', 'old_value', 'new_value', 'page' ),
|
448 |
Â
null,
|
452 |
Â
}
|
453 |
Â
}
|
454 |
Â
|
455 |
+
/**
|
456 |
+
* Log buddyPress' components' state.
|
457 |
+
*
|
458 |
+
* @param array $old_value Old value.
|
459 |
+
* @param array $new_value New value.
|
460 |
+
*/
|
461 |
Â
public function check_bp_active_components( $old_value, $new_value ) {
|
462 |
Â
$options = array();
|
463 |
Â
|
483 |
Â
|
484 |
Â
$this->log(
|
485 |
Â
sprintf(
|
486 |
+
/* translators: %1$s: component title, %2$s: component action (e.g. "Members component deactivated") */
|
487 |
Â
__( '"%1$s" component %2$s', 'stream' ),
|
488 |
Â
$components[ $option ]['title'],
|
489 |
Â
$actions[ $option_value ]
|
501 |
Â
}
|
502 |
Â
}
|
503 |
Â
|
504 |
+
/**
|
505 |
+
* Log buddyPress' page assignment.
|
506 |
+
*
|
507 |
+
* @param array $old_value Old value.
|
508 |
+
* @param array $new_value New value.
|
509 |
+
*/
|
510 |
Â
public function check_bp_pages( $old_value, $new_value ) {
|
511 |
Â
$options = array();
|
512 |
Â
|
535 |
Â
|
536 |
Â
$this->log(
|
537 |
Â
sprintf(
|
538 |
+
/* translators: %1$s: a directory page, %2$s: a page title (e.g. "Register", "Registration" ) */
|
539 |
Â
__( '"%1$s" page set to "%2$s"', 'stream' ),
|
540 |
Â
$pages[ $option ],
|
541 |
Â
$page
|
554 |
Â
}
|
555 |
Â
}
|
556 |
Â
|
557 |
+
/**
|
558 |
+
* Logs activity deletions
|
559 |
+
*
|
560 |
+
* @action bp_before_activity_delete
|
561 |
+
*
|
562 |
+
* @param array $args Target activity data.
|
563 |
+
*/
|
564 |
Â
public function callback_bp_before_activity_delete( $args ) {
|
565 |
+
if ( empty( $args['id'] ) ) { // Bail if we're deleting in bulk.
|
566 |
+
$this->delete_activity_args = $args;
|
567 |
Â
|
568 |
Â
return;
|
569 |
Â
}
|
570 |
Â
|
571 |
Â
$activity = new \BP_Activity_Activity( $args['id'] );
|
572 |
Â
|
573 |
+
$this->deleted_activity = $activity;
|
574 |
Â
}
|
575 |
Â
|
576 |
+
/**
|
577 |
+
* Logs activity bulk deletions.
|
578 |
+
*
|
579 |
+
* @action bp_activity_deleted_activities
|
580 |
+
*
|
581 |
+
* @param array $activities_ids Activity IDs of deleted activities.
|
582 |
+
*/
|
583 |
Â
public function callback_bp_activity_deleted_activities( $activities_ids ) {
|
584 |
+
if ( 1 === count( $activities_ids ) && isset( $this->deleted_activity ) ) { // Single activity deletion.
|
585 |
+
$activity = $this->deleted_activity;
|
586 |
Â
$this->log(
|
587 |
Â
sprintf(
|
588 |
+
/* translators: %s: an activity title (e.g. "Update") */
|
589 |
Â
__( '"%s" activity deleted', 'stream' ),
|
590 |
+
wp_strip_all_tags( $activity->action )
|
591 |
Â
),
|
592 |
Â
array(
|
593 |
Â
'id' => $activity->id,
|
599 |
Â
$activity->component,
|
600 |
Â
'deleted'
|
601 |
Â
);
|
602 |
+
} else {
|
603 |
+
/**
|
604 |
+
* Bulk deletion
|
605 |
+
* Sometimes some objects removal are followed by deleting relevant
|
606 |
+
* activities, so we probably don't need to track those
|
607 |
+
*/
|
608 |
Â
if ( $this->ignore_activity_bulk_deletion ) {
|
609 |
Â
$this->ignore_activity_bulk_deletion = false;
|
610 |
Â
|
612 |
Â
}
|
613 |
Â
$this->log(
|
614 |
Â
sprintf(
|
615 |
+
/* translators: %s: an activity title (e.g. "Update") */
|
616 |
Â
__( '"%s" activities were deleted', 'stream' ),
|
617 |
Â
count( $activities_ids )
|
618 |
Â
),
|
619 |
Â
array(
|
620 |
Â
'count' => count( $activities_ids ),
|
621 |
+
'args' => $this->delete_activity_args,
|
622 |
Â
'ids' => $activities_ids,
|
623 |
Â
),
|
624 |
Â
null,
|
628 |
Â
}
|
629 |
Â
}
|
630 |
Â
|
631 |
+
/**
|
632 |
+
* Logs activates marked as spam
|
633 |
+
*
|
634 |
+
* @action bp_activity_mark_as_spam
|
635 |
+
*
|
636 |
+
* @param array $activity Activity.
|
637 |
+
* @param mixed $by Marker.
|
638 |
+
*/
|
639 |
Â
public function callback_bp_activity_mark_as_spam( $activity, $by ) {
|
640 |
Â
unset( $by );
|
641 |
Â
|
642 |
Â
$this->log(
|
643 |
Â
sprintf(
|
644 |
+
/* translators: %s an activity title (e.g. "Update") */
|
645 |
Â
__( 'Marked activity "%s" as spam', 'stream' ),
|
646 |
+
wp_strip_all_tags( $activity->action )
|
647 |
Â
),
|
648 |
Â
array(
|
649 |
Â
'id' => $activity->id,
|
657 |
Â
);
|
658 |
Â
}
|
659 |
Â
|
660 |
+
/**
|
661 |
+
* Log activities marked as ham
|
662 |
+
*
|
663 |
+
* @action bp_activity_mark_as_ham
|
664 |
+
*
|
665 |
+
* @param array $activity Activity.
|
666 |
+
* @param mixed $by Marker.
|
667 |
+
*/
|
668 |
Â
public function callback_bp_activity_mark_as_ham( $activity, $by ) {
|
669 |
Â
unset( $by );
|
670 |
Â
|
671 |
Â
$this->log(
|
672 |
Â
sprintf(
|
673 |
+
/* translators: %s: an activity title (e.g. "Update") */
|
674 |
Â
__( 'Unmarked activity "%s" as spam', 'stream' ),
|
675 |
+
wp_strip_all_tags( $activity->action )
|
676 |
Â
),
|
677 |
Â
array(
|
678 |
Â
'id' => $activity->id,
|
686 |
Â
);
|
687 |
Â
}
|
688 |
Â
|
689 |
+
/**
|
690 |
+
* Log activity changes made in the WP Admin.
|
691 |
+
*
|
692 |
+
* @action bp_activity_admin_edit_after
|
693 |
+
*
|
694 |
+
* @param array $activity Activity.
|
695 |
+
* @param mixed $error Any errors.
|
696 |
+
*/
|
697 |
Â
public function callback_bp_activity_admin_edit_after( $activity, $error ) {
|
698 |
Â
unset( $error );
|
699 |
Â
|
700 |
Â
$this->log(
|
701 |
Â
sprintf(
|
702 |
+
/* translators: %s: an activity title (e.g. "Update") */
|
703 |
Â
__( '"%s" activity updated', 'stream' ),
|
704 |
+
wp_strip_all_tags( $activity->action )
|
705 |
Â
),
|
706 |
Â
array(
|
707 |
Â
'id' => $activity->id,
|
715 |
Â
);
|
716 |
Â
}
|
717 |
Â
|
718 |
+
/**
|
719 |
+
* Logs group actions
|
720 |
+
*
|
721 |
+
* @param int|object $group Group object or group ID.
|
722 |
+
* @param string $action Action.
|
723 |
+
* @param array $meta Meta data.
|
724 |
+
* @param string $message Message.
|
725 |
+
*/
|
726 |
Â
public function group_action( $group, $action, $meta = array(), $message = null ) {
|
727 |
Â
if ( is_numeric( $group ) ) {
|
728 |
Â
$group = \groups_get_group(
|
738 |
Â
|
739 |
Â
if ( ! $message ) {
|
740 |
Â
if ( 'created' === $action ) {
|
741 |
+
/* translators: %s: a group name (e.g. "Favourites") */
|
742 |
Â
$message = esc_html__( '"%s" group created', 'stream' );
|
743 |
Â
} elseif ( 'updated' === $action ) {
|
744 |
+
/* translators: %s: a group name (e.g. "Favourites") */
|
745 |
Â
$message = esc_html__( '"%s" group updated', 'stream' );
|
746 |
Â
} elseif ( 'deleted' === $action ) {
|
747 |
+
/* translators: %s: a group name (e.g. "Favourites") */
|
748 |
Â
$message = esc_html__( '"%s" group deleted', 'stream' );
|
749 |
Â
} elseif ( 'joined' === $action ) {
|
750 |
+
/* translators: %s: a group name (e.g. "Favourites") */
|
751 |
Â
$message = esc_html__( 'Joined group "%s"', 'stream' );
|
752 |
Â
} elseif ( 'left' === $action ) {
|
753 |
+
/* translators: %s: a group name (e.g. "Favourites") */
|
754 |
Â
$message = esc_html__( 'Left group "%s"', 'stream' );
|
755 |
Â
} elseif ( 'banned' === $action ) {
|
756 |
+
/* translators: %1$s: a user display name, %2$s: a group name (e.g. "Jane Doe", "Favourites") */
|
757 |
Â
$message = esc_html__( 'Banned "%2$s" from "%1$s"', 'stream' );
|
758 |
Â
$replacements[] = get_user_by( 'id', $meta['user_id'] )->display_name;
|
759 |
Â
} elseif ( 'unbanned' === $action ) {
|
760 |
+
/* translators: %1$s: a user display name, %2$s: a group name (e.g. "Jane Doe", "Favourites") */
|
761 |
Â
$message = esc_html__( 'Unbanned "%2$s" from "%1$s"', 'stream' );
|
762 |
Â
$replacements[] = get_user_by( 'id', $meta['user_id'] )->display_name;
|
763 |
Â
} elseif ( 'removed' === $action ) {
|
764 |
+
/* translators: %1$s: a user display name, %2$s: a group name (e.g. "Jane Doe", "Favourites") */
|
765 |
Â
$message = esc_html__( 'Removed "%2$s" from "%1$s"', 'stream' );
|
766 |
Â
$replacements[] = get_user_by( 'id', $meta['user_id'] )->display_name;
|
767 |
Â
} else {
|
788 |
Â
);
|
789 |
Â
}
|
790 |
Â
|
791 |
+
/**
|
792 |
+
* Log creation of new group.
|
793 |
+
*
|
794 |
+
* @action groups_create_group
|
795 |
+
*
|
796 |
+
* @param int $group_id Group ID.
|
797 |
+
* @param object $member Group founder user object.
|
798 |
+
* @param object $group Group object.
|
799 |
+
*/
|
800 |
Â
public function callback_groups_create_group( $group_id, $member, $group ) {
|
801 |
Â
unset( $group_id );
|
802 |
Â
unset( $member );
|
804 |
Â
$this->group_action( $group, 'created' );
|
805 |
Â
}
|
806 |
Â
|
807 |
+
/**
|
808 |
+
* Log update to existing group.
|
809 |
+
*
|
810 |
+
* @action groups_update_group
|
811 |
+
*
|
812 |
+
* @param int $group_id Group ID.
|
813 |
+
* @param object $group Group object.
|
814 |
+
*/
|
815 |
Â
public function callback_groups_update_group( $group_id, $group ) {
|
816 |
Â
unset( $group_id );
|
817 |
Â
|
818 |
Â
$this->group_action( $group, 'updated' );
|
819 |
Â
}
|
820 |
Â
|
821 |
+
/**
|
822 |
+
* Log group deletion
|
823 |
+
*
|
824 |
+
* @action groups_before_delete_group
|
825 |
+
*
|
826 |
+
* @param int $group_id Group ID.
|
827 |
+
*/
|
828 |
Â
public function callback_groups_before_delete_group( $group_id ) {
|
829 |
Â
$this->ignore_activity_bulk_deletion = true;
|
830 |
Â
$this->group_action( $group_id, 'deleted' );
|
831 |
Â
}
|
832 |
Â
|
833 |
+
/**
|
834 |
+
* Log change to group details
|
835 |
+
*
|
836 |
+
* @action groups_details_updated
|
837 |
+
*
|
838 |
+
* @param int $group_id Group ID.
|
839 |
+
*/
|
840 |
Â
public function callback_groups_details_updated( $group_id ) {
|
841 |
Â
$this->is_update = true;
|
842 |
Â
$this->group_action( $group_id, 'updated' );
|
843 |
Â
}
|
844 |
Â
|
845 |
+
/**
|
846 |
+
* Log change to group settings
|
847 |
+
*
|
848 |
+
* @action groups_settings_updated
|
849 |
+
*
|
850 |
+
* @param int $group_id Group ID.
|
851 |
+
*/
|
852 |
Â
public function callback_groups_settings_updated( $group_id ) {
|
853 |
Â
if ( $this->is_update ) {
|
854 |
Â
return;
|
856 |
Â
$this->group_action( $group_id, 'updated' );
|
857 |
Â
}
|
858 |
Â
|
859 |
+
/**
|
860 |
+
* Logs user leaving group
|
861 |
+
*
|
862 |
+
* @action groups_leave_group
|
863 |
+
*
|
864 |
+
* @param int $group_id Group ID.
|
865 |
+
* @param int $user_id User ID of member.
|
866 |
+
*/
|
867 |
Â
public function callback_groups_leave_group( $group_id, $user_id ) {
|
868 |
Â
$this->group_action( $group_id, 'left', compact( 'user_id' ) );
|
869 |
Â
}
|
870 |
Â
|
871 |
+
/**
|
872 |
+
* Logs user joining group
|
873 |
+
*
|
874 |
+
* @action groups_join_group
|
875 |
+
*
|
876 |
+
* @param int $group_id Group ID.
|
877 |
+
* @param int $user_id User ID of member.
|
878 |
+
*/
|
879 |
Â
public function callback_groups_join_group( $group_id, $user_id ) {
|
880 |
Â
$this->group_action( $group_id, 'joined', compact( 'user_id' ) );
|
881 |
Â
}
|
882 |
Â
|
883 |
+
/**
|
884 |
+
* Logs group member promotion.
|
885 |
+
*
|
886 |
+
* @action groups_promote_member
|
887 |
+
*
|
888 |
+
* @param int $group_id Group ID.
|
889 |
+
* @param int $user_id User ID of member.
|
890 |
+
* @param string $status Member's new user role.
|
891 |
+
*/
|
892 |
Â
public function callback_groups_promote_member( $group_id, $user_id, $status ) {
|
893 |
Â
$group = \groups_get_group(
|
894 |
Â
array(
|
901 |
Â
'mod' => esc_html_x( 'Moderator', 'buddypress', 'stream' ),
|
902 |
Â
);
|
903 |
Â
$message = sprintf(
|
904 |
+
/* translators: %1$s: a user's display name, %2$s: a user role, %3$s: a group name (e.g. "Jane Doe", "subscriber", "Favourites") */
|
905 |
Â
__( 'Promoted "%1$s" to "%2$s" in "%3$s"', 'stream' ),
|
906 |
Â
$user->display_name,
|
907 |
Â
$roles[ $status ],
|
910 |
Â
$this->group_action( $group_id, 'promoted', compact( 'user_id', 'status' ), $message );
|
911 |
Â
}
|
912 |
Â
|
913 |
+
/**
|
914 |
+
* Log group member demotion
|
915 |
+
*
|
916 |
+
* @action groups_demote_member
|
917 |
+
*
|
918 |
+
* @param int $group_id Group ID.
|
919 |
+
* @param int $user_id User ID of member.
|
920 |
+
*/
|
921 |
Â
public function callback_groups_demote_member( $group_id, $user_id ) {
|
922 |
Â
$group = \groups_get_group(
|
923 |
Â
array(
|
926 |
Â
);
|
927 |
Â
$user = new \WP_User( $user_id );
|
928 |
Â
$message = sprintf(
|
929 |
+
/* translators: %1$s: a user's display name, %2$s: a user role, %3$s: a group name (e.g. "Jane Doe", "Member", "Favourites") */
|
930 |
Â
__( 'Demoted "%1$s" to "%2$s" in "%3$s"', 'stream' ),
|
931 |
Â
$user->display_name,
|
932 |
Â
_x( 'Member', 'buddypress', 'stream' ),
|
935 |
Â
$this->group_action( $group_id, 'demoted', compact( 'user_id' ), $message );
|
936 |
Â
}
|
937 |
Â
|
938 |
+
/**
|
939 |
+
* Log member banning
|
940 |
+
*
|
941 |
+
* @action groups_ban_member
|
942 |
+
*
|
943 |
+
* @param int $group_id Group ID.
|
944 |
+
* @param int $user_id User ID of banned member.
|
945 |
+
*/
|
946 |
Â
public function callback_groups_ban_member( $group_id, $user_id ) {
|
947 |
Â
$this->group_action( $group_id, 'banned', compact( 'user_id' ) );
|
948 |
Â
}
|
949 |
Â
|
950 |
+
/**
|
951 |
+
* Log member reinstatement
|
952 |
+
*
|
953 |
+
* @action groups_unban_member
|
954 |
+
*
|
955 |
+
* @param int $group_id Group ID.
|
956 |
+
* @param int $user_id User ID of reinstated member.
|
957 |
+
*/
|
958 |
Â
public function callback_groups_unban_member( $group_id, $user_id ) {
|
959 |
Â
$this->group_action( $group_id, 'unbanned', compact( 'user_id' ) );
|
960 |
Â
}
|
961 |
Â
|
962 |
+
/**
|
963 |
+
* Log member removal.
|
964 |
+
*
|
965 |
+
* @action groups_remove_member
|
966 |
+
*
|
967 |
+
* @param int $group_id Group ID.
|
968 |
+
* @param int $user_id User ID of removed member.
|
969 |
+
*/
|
970 |
Â
public function callback_groups_remove_member( $group_id, $user_id ) {
|
971 |
Â
$this->group_action( $group_id, 'removed', compact( 'user_id' ) );
|
972 |
Â
}
|
973 |
Â
|
974 |
+
/**
|
975 |
+
* Logs user profile field actions
|
976 |
+
*
|
977 |
+
* @param object $field Field object.
|
978 |
+
* @param string $action Action.
|
979 |
+
* @param array $meta Meta.
|
980 |
+
* @param string $message Message.
|
981 |
+
*/
|
982 |
Â
public function field_action( $field, $action, $meta = array(), $message = null ) {
|
983 |
Â
$replacements = array(
|
984 |
Â
$field->name,
|
986 |
Â
|
987 |
Â
if ( ! $message ) {
|
988 |
Â
if ( 'created' === $action ) {
|
989 |
+
/* translators: %s: a user profile field (e.g. "Job Title") */
|
990 |
Â
$message = esc_html__( 'Created profile field "%s"', 'stream' );
|
991 |
Â
} elseif ( 'updated' === $action ) {
|
992 |
+
/* translators: %s: a user profile field (e.g. "Job Title") */
|
993 |
Â
$message = esc_html__( 'Updated profile field "%s"', 'stream' );
|
994 |
Â
} elseif ( 'deleted' === $action ) {
|
995 |
+
/* translators: %s: a user profile field (e.g. "Job Title") */
|
996 |
Â
$message = esc_html__( 'Deleted profile field "%s"', 'stream' );
|
997 |
Â
} else {
|
998 |
Â
return;
|
1018 |
Â
);
|
1019 |
Â
}
|
1020 |
Â
|
1021 |
+
/**
|
1022 |
+
* Logs field writes
|
1023 |
+
*
|
1024 |
+
* @action xprofile_field_after_save
|
1025 |
+
*
|
1026 |
+
* @param object $field Field object.
|
1027 |
+
*/
|
1028 |
Â
public function callback_xprofile_field_after_save( $field ) {
|
1029 |
Â
$action = isset( $field->id ) ? 'updated' : 'created';
|
1030 |
Â
$this->field_action( $field, $action );
|
1031 |
Â
}
|
1032 |
Â
|
1033 |
+
/**
|
1034 |
+
* Logs field deletions
|
1035 |
+
*
|
1036 |
+
* @action xprofile_fields_deleted_field
|
1037 |
+
*
|
1038 |
+
* @param object $field Field object.
|
1039 |
+
*/
|
1040 |
Â
public function callback_xprofile_fields_deleted_field( $field ) {
|
1041 |
Â
$this->field_action( $field, 'deleted' );
|
1042 |
Â
}
|
1043 |
Â
|
1044 |
+
/**
|
1045 |
+
* Logs user profile field group actions
|
1046 |
+
*
|
1047 |
+
* @param int $group Field group object.
|
1048 |
+
* @param string $action Action.
|
1049 |
+
* @param array $meta Meta.
|
1050 |
+
* @param string $message Message.
|
1051 |
+
*/
|
1052 |
Â
public function field_group_action( $group, $action, $meta = array(), $message = null ) {
|
1053 |
Â
$replacements = array(
|
1054 |
Â
$group->name,
|
1056 |
Â
|
1057 |
Â
if ( ! $message ) {
|
1058 |
Â
if ( 'created' === $action ) {
|
1059 |
+
/* translators: %s: a user profile field group (e.g. "Appearance") */
|
1060 |
Â
$message = esc_html__( 'Created profile field group "%s"', 'stream' );
|
1061 |
Â
} elseif ( 'updated' === $action ) {
|
1062 |
+
/* translators: %s: a user profile field group (e.g. "Appearance") */
|
1063 |
Â
$message = esc_html__( 'Updated profile field group "%s"', 'stream' );
|
1064 |
Â
} elseif ( 'deleted' === $action ) {
|
1065 |
+
/* translators: %s: a user profile field group (e.g. "Appearance") */
|
1066 |
Â
$message = esc_html__( 'Deleted profile field group "%s"', 'stream' );
|
1067 |
Â
} else {
|
1068 |
Â
return;
|
1087 |
Â
);
|
1088 |
Â
}
|
1089 |
Â
|
1090 |
+
/**
|
1091 |
+
* Logs field group writes
|
1092 |
+
*
|
1093 |
+
* @action xprofile_group_after_save
|
1094 |
+
*
|
1095 |
+
* @param object $group Field group.
|
1096 |
+
*/
|
1097 |
Â
public function callback_xprofile_group_after_save( $group ) {
|
1098 |
Â
global $wpdb;
|
1099 |
+
/**
|
1100 |
+
* A bit hacky, due to inconsistency with BP action scheme,
|
1101 |
+
* see callback_xprofile_field_after_save for correct behavior.
|
1102 |
+
*/
|
1103 |
Â
$action = ( $group->id === $wpdb->insert_id ) ? 'created' : 'updated';
|
1104 |
Â
$this->field_group_action( $group, $action );
|
1105 |
Â
}
|
1106 |
Â
|
1107 |
+
/**
|
1108 |
+
* Logs field group deletions
|
1109 |
+
*
|
1110 |
+
* @action xprofile_groups_deleted_group
|
1111 |
+
*
|
1112 |
+
* @param object $group Field group object.
|
1113 |
+
*/
|
1114 |
Â
public function callback_xprofile_groups_deleted_group( $group ) {
|
1115 |
Â
$this->field_group_action( $group, 'deleted' );
|
1116 |
Â
}
|
1117 |
Â
|
1118 |
+
/**
|
1119 |
+
* Returns the directory pages
|
1120 |
+
*
|
1121 |
+
* @return array
|
1122 |
+
*/
|
1123 |
Â
private function bp_get_directory_pages() {
|
1124 |
Â
$bp = \buddypress();
|
1125 |
Â
$directory_pages = array();
|
1126 |
Â
|
1127 |
+
// Loop through loaded components and collect directories.
|
1128 |
Â
if ( is_array( $bp->loaded_components ) ) {
|
1129 |
Â
foreach ( $bp->loaded_components as $component_slug => $component_id ) {
|
1130 |
+
// Only components that need directories should be listed here.
|
1131 |
Â
if ( isset( $bp->{$component_id} ) && ! empty( $bp->{$component_id}->has_directory ) ) {
|
1132 |
+
// component->name was introduced in BP 1.5, so we must provide a fallback.
|
1133 |
Â
$directory_pages[ $component_id ] = ! empty( $bp->{$component_id}->name ) ? $bp->{$component_id}->name : ucwords( $component_id );
|
1134 |
Â
}
|
1135 |
Â
}
|
connectors/class-connector-comments.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_Comments extends Connector {
|
5 |
Â
/**
|
6 |
Â
* Connector slug
|
@@ -97,7 +106,7 @@ class Connector_Comments extends Connector {
|
|
97 |
Â
/**
|
98 |
Â
* Return the comment type label for a given comment ID
|
99 |
Â
*
|
100 |
-
* @param int $comment_id ID of the comment
|
101 |
Â
*
|
102 |
Â
* @return string The comment type label
|
103 |
Â
*/
|
@@ -120,8 +129,8 @@ class Connector_Comments extends Connector {
|
|
120 |
Â
*
|
121 |
Â
* @filter wp_stream_action_links_{connector}
|
122 |
Â
*
|
123 |
-
* @param array $links Previous links registered
|
124 |
-
* @param object $record
|
125 |
Â
*
|
126 |
Â
* @return array Action links
|
127 |
Â
*/
|
@@ -163,8 +172,8 @@ class Connector_Comments extends Connector {
|
|
163 |
Â
* name and e-mail or that users be logged in to comment. In either case it
|
164 |
Â
* will try to see if the e-mail provided does belong to a registered user.
|
165 |
Â
*
|
166 |
-
* @param object|int $comment
|
167 |
-
* @param string $field
|
168 |
Â
*
|
169 |
Â
* @return int|string $output User ID or user display name
|
170 |
Â
*/
|
@@ -205,8 +214,8 @@ class Connector_Comments extends Connector {
|
|
205 |
Â
*
|
206 |
Â
* @action comment_flood_trigger
|
207 |
Â
*
|
208 |
-
* @param string $time_lastcomment
|
209 |
-
* @param string $time_newcomment
|
210 |
Â
*/
|
211 |
Â
public function callback_comment_flood_trigger( $time_lastcomment, $time_newcomment ) {
|
212 |
Â
$options = wp_stream_get_instance()->settings->options;
|
@@ -227,7 +236,7 @@ class Connector_Comments extends Connector {
|
|
227 |
Â
}
|
228 |
Â
|
229 |
Â
$this->log(
|
230 |
-
|
231 |
Â
__( 'Comment flooding by %s detected and prevented', 'stream' ),
|
232 |
Â
compact( 'user_name', 'user_id', 'time_lastcomment', 'time_newcomment' ),
|
233 |
Â
null,
|
@@ -241,8 +250,8 @@ class Connector_Comments extends Connector {
|
|
241 |
Â
*
|
242 |
Â
* @action wp_insert_comment
|
243 |
Â
*
|
244 |
-
* @param int
|
245 |
-
* @param
|
246 |
Â
*/
|
247 |
Â
public function callback_wp_insert_comment( $comment_id, $comment ) {
|
248 |
Â
if ( in_array( $comment->comment_type, $this->get_ignored_comment_types(), true ) ) {
|
@@ -258,7 +267,7 @@ class Connector_Comments extends Connector {
|
|
258 |
Â
$comment_status = ( 1 === $comment->comment_approved ) ? esc_html__( 'approved automatically', 'stream' ) : esc_html__( 'pending approval', 'stream' );
|
259 |
Â
$is_spam = false;
|
260 |
Â
|
261 |
-
// Auto-marked spam comments
|
262 |
Â
$options = wp_stream_get_instance()->settings->options;
|
263 |
Â
$ak_tracking = isset( $options['advanced_akismet_tracking'] ) ? $options['advanced_akismet_tracking'] : false;
|
264 |
Â
|
@@ -276,7 +285,7 @@ class Connector_Comments extends Connector {
|
|
276 |
Â
$parent_user_name = get_comment_author( $comment->comment_parent );
|
277 |
Â
|
278 |
Â
$this->log(
|
279 |
-
|
280 |
Â
_x(
|
281 |
Â
'Reply to %1$s\'s %5$s by %2$s on %3$s %4$s',
|
282 |
Â
"1: Parent comment's author, 2: Comment author, 3: Post title, 4: Comment status, 5: Comment type",
|
@@ -290,7 +299,7 @@ class Connector_Comments extends Connector {
|
|
290 |
Â
);
|
291 |
Â
} else {
|
292 |
Â
$this->log(
|
293 |
-
|
294 |
Â
_x(
|
295 |
Â
'New %4$s by %1$s on %2$s %3$s',
|
296 |
Â
'1: Comment author, 2: Post title 3: Comment status, 4: Comment type',
|
@@ -310,7 +319,7 @@ class Connector_Comments extends Connector {
|
|
310 |
Â
*
|
311 |
Â
* @action edit_comment
|
312 |
Â
*
|
313 |
-
* @param int $comment_id
|
314 |
Â
*/
|
315 |
Â
public function callback_edit_comment( $comment_id ) {
|
316 |
Â
$comment = get_comment( $comment_id );
|
@@ -328,7 +337,7 @@ class Connector_Comments extends Connector {
|
|
328 |
Â
$comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
|
329 |
Â
|
330 |
Â
$this->log(
|
331 |
-
|
332 |
Â
_x(
|
333 |
Â
'%1$s\'s %3$s on %2$s edited',
|
334 |
Â
'1: Comment author, 2: Post title, 3: Comment type',
|
@@ -346,7 +355,7 @@ class Connector_Comments extends Connector {
|
|
346 |
Â
*
|
347 |
Â
* @action before_delete_post
|
348 |
Â
*
|
349 |
-
* @param int $post_id
|
350 |
Â
*/
|
351 |
Â
public function callback_before_delete_post( $post_id ) {
|
352 |
Â
if ( wp_is_post_revision( $post_id ) ) {
|
@@ -361,7 +370,7 @@ class Connector_Comments extends Connector {
|
|
361 |
Â
*
|
362 |
Â
* @action deleted_post
|
363 |
Â
*
|
364 |
-
* @param int $post_id
|
365 |
Â
*/
|
366 |
Â
public function callback_deleted_post( $post_id ) {
|
367 |
Â
if ( wp_is_post_revision( $post_id ) ) {
|
@@ -376,7 +385,7 @@ class Connector_Comments extends Connector {
|
|
376 |
Â
*
|
377 |
Â
* @action delete_comment
|
378 |
Â
*
|
379 |
-
* @param int $comment_id
|
380 |
Â
*/
|
381 |
Â
public function callback_delete_comment( $comment_id ) {
|
382 |
Â
$comment = get_comment( $comment_id );
|
@@ -398,7 +407,7 @@ class Connector_Comments extends Connector {
|
|
398 |
Â
}
|
399 |
Â
|
400 |
Â
$this->log(
|
401 |
-
|
402 |
Â
_x(
|
403 |
Â
'%1$s\'s %3$s on %2$s deleted permanently',
|
404 |
Â
'1: Comment author, 2: Post title, 3: Comment type',
|
@@ -416,7 +425,7 @@ class Connector_Comments extends Connector {
|
|
416 |
Â
*
|
417 |
Â
* @action trash_comment
|
418 |
Â
*
|
419 |
-
* @param int $comment_id
|
420 |
Â
*/
|
421 |
Â
public function callback_trash_comment( $comment_id ) {
|
422 |
Â
$comment = get_comment( $comment_id );
|
@@ -434,7 +443,7 @@ class Connector_Comments extends Connector {
|
|
434 |
Â
$comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
|
435 |
Â
|
436 |
Â
$this->log(
|
437 |
-
|
438 |
Â
_x(
|
439 |
Â
'%1$s\'s %3$s on %2$s trashed',
|
440 |
Â
'1: Comment author, 2: Post title, 3: Comment type',
|
@@ -452,7 +461,7 @@ class Connector_Comments extends Connector {
|
|
452 |
Â
*
|
453 |
Â
* @action untrash_comment
|
454 |
Â
*
|
455 |
-
* @param int $comment_id
|
456 |
Â
*/
|
457 |
Â
public function callback_untrash_comment( $comment_id ) {
|
458 |
Â
$comment = get_comment( $comment_id );
|
@@ -470,7 +479,7 @@ class Connector_Comments extends Connector {
|
|
470 |
Â
$comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
|
471 |
Â
|
472 |
Â
$this->log(
|
473 |
-
|
474 |
Â
_x(
|
475 |
Â
'%1$s\'s %3$s on %2$s restored',
|
476 |
Â
'1: Comment author, 2: Post title, 3: Comment type',
|
@@ -488,7 +497,7 @@ class Connector_Comments extends Connector {
|
|
488 |
Â
*
|
489 |
Â
* @action spam_comment
|
490 |
Â
*
|
491 |
-
* @param int $comment_id
|
492 |
Â
*/
|
493 |
Â
public function callback_spam_comment( $comment_id ) {
|
494 |
Â
$comment = get_comment( $comment_id );
|
@@ -506,7 +515,7 @@ class Connector_Comments extends Connector {
|
|
506 |
Â
$comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
|
507 |
Â
|
508 |
Â
$this->log(
|
509 |
-
|
510 |
Â
_x(
|
511 |
Â
'%1$s\'s %3$s on %2$s marked as spam',
|
512 |
Â
'1: Comment author, 2: Post title, 3: Comment type',
|
@@ -524,7 +533,7 @@ class Connector_Comments extends Connector {
|
|
524 |
Â
*
|
525 |
Â
* @action unspam_comment
|
526 |
Â
*
|
527 |
-
* @param int $comment_id
|
528 |
Â
*/
|
529 |
Â
public function callback_unspam_comment( $comment_id ) {
|
530 |
Â
$comment = get_comment( $comment_id );
|
@@ -542,7 +551,7 @@ class Connector_Comments extends Connector {
|
|
542 |
Â
$comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
|
543 |
Â
|
544 |
Â
$this->log(
|
545 |
-
|
546 |
Â
_x(
|
547 |
Â
'%1$s\'s %3$s on %2$s unmarked as spam',
|
548 |
Â
'1: Comment author, 2: Post title, 3: Comment type',
|
@@ -560,9 +569,9 @@ class Connector_Comments extends Connector {
|
|
560 |
Â
*
|
561 |
Â
* @action transition_comment_status
|
562 |
Â
*
|
563 |
-
* @param string
|
564 |
-
* @param string
|
565 |
-
* @param
|
566 |
Â
*/
|
567 |
Â
public function callback_transition_comment_status( $new_status, $old_status, $comment ) {
|
568 |
Â
if ( in_array( $comment->comment_type, $this->get_ignored_comment_types(), true ) ) {
|
@@ -582,7 +591,7 @@ class Connector_Comments extends Connector {
|
|
582 |
Â
$comment_type = get_comment_type( $comment->comment_ID );
|
583 |
Â
|
584 |
Â
$this->log(
|
585 |
-
|
586 |
Â
_x(
|
587 |
Â
'%1$s\'s %3$s %2$s',
|
588 |
Â
'Comment status transition. 1: Comment author, 2: Post title, 3: Comment type',
|
@@ -600,7 +609,7 @@ class Connector_Comments extends Connector {
|
|
600 |
Â
*
|
601 |
Â
* @action comment_duplicate_trigger
|
602 |
Â
*
|
603 |
-
* @param array $comment_data
|
604 |
Â
*/
|
605 |
Â
public function callback_comment_duplicate_trigger( $comment_data ) {
|
606 |
Â
global $wpdb;
|
@@ -622,7 +631,7 @@ class Connector_Comments extends Connector {
|
|
622 |
Â
$comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
|
623 |
Â
|
624 |
Â
$this->log(
|
625 |
-
|
626 |
Â
_x(
|
627 |
Â
'Duplicate %3$s by %1$s prevented on %2$s',
|
628 |
Â
'1: Comment author, 2: Post title, 3: Comment type',
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for Comments
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_Comments
|
12 |
+
*/
|
13 |
Â
class Connector_Comments extends Connector {
|
14 |
Â
/**
|
15 |
Â
* Connector slug
|
106 |
Â
/**
|
107 |
Â
* Return the comment type label for a given comment ID
|
108 |
Â
*
|
109 |
+
* @param int $comment_id ID of the comment.
|
110 |
Â
*
|
111 |
Â
* @return string The comment type label
|
112 |
Â
*/
|
129 |
Â
*
|
130 |
Â
* @filter wp_stream_action_links_{connector}
|
131 |
Â
*
|
132 |
+
* @param array $links Previous links registered.
|
133 |
+
* @param object $record Stream record.
|
134 |
Â
*
|
135 |
Â
* @return array Action links
|
136 |
Â
*/
|
172 |
Â
* name and e-mail or that users be logged in to comment. In either case it
|
173 |
Â
* will try to see if the e-mail provided does belong to a registered user.
|
174 |
Â
*
|
175 |
+
* @param object|int $comment A comment object or comment ID.
|
176 |
+
* @param string $field What field you want to return.
|
177 |
Â
*
|
178 |
Â
* @return int|string $output User ID or user display name
|
179 |
Â
*/
|
214 |
Â
*
|
215 |
Â
* @action comment_flood_trigger
|
216 |
Â
*
|
217 |
+
* @param string $time_lastcomment Time of last comment before block.
|
218 |
+
* @param string $time_newcomment Time of first comment after block.
|
219 |
Â
*/
|
220 |
Â
public function callback_comment_flood_trigger( $time_lastcomment, $time_newcomment ) {
|
221 |
Â
$options = wp_stream_get_instance()->settings->options;
|
236 |
Â
}
|
237 |
Â
|
238 |
Â
$this->log(
|
239 |
+
/* translators: %s: a username (e.g. "administrator") */
|
240 |
Â
__( 'Comment flooding by %s detected and prevented', 'stream' ),
|
241 |
Â
compact( 'user_name', 'user_id', 'time_lastcomment', 'time_newcomment' ),
|
242 |
Â
null,
|
250 |
Â
*
|
251 |
Â
* @action wp_insert_comment
|
252 |
Â
*
|
253 |
+
* @param int $comment_id Comment ID.
|
254 |
+
* @param WP_Comment $comment Comment object.
|
255 |
Â
*/
|
256 |
Â
public function callback_wp_insert_comment( $comment_id, $comment ) {
|
257 |
Â
if ( in_array( $comment->comment_type, $this->get_ignored_comment_types(), true ) ) {
|
267 |
Â
$comment_status = ( 1 === $comment->comment_approved ) ? esc_html__( 'approved automatically', 'stream' ) : esc_html__( 'pending approval', 'stream' );
|
268 |
Â
$is_spam = false;
|
269 |
Â
|
270 |
+
// Auto-marked spam comments.
|
271 |
Â
$options = wp_stream_get_instance()->settings->options;
|
272 |
Â
$ak_tracking = isset( $options['advanced_akismet_tracking'] ) ? $options['advanced_akismet_tracking'] : false;
|
273 |
Â
|
285 |
Â
$parent_user_name = get_comment_author( $comment->comment_parent );
|
286 |
Â
|
287 |
Â
$this->log(
|
288 |
+
/* translators: %1$s: a parent comment's author, %2$s: a comment author, %3$s: a post title, %4$s: a comment status, %5$s: a comment type */
|
289 |
Â
_x(
|
290 |
Â
'Reply to %1$s\'s %5$s by %2$s on %3$s %4$s',
|
291 |
Â
"1: Parent comment's author, 2: Comment author, 3: Post title, 4: Comment status, 5: Comment type",
|
299 |
Â
);
|
300 |
Â
} else {
|
301 |
Â
$this->log(
|
302 |
+
/* translators: %1$s: a comment author, %2$s: a post title, %3$s: a comment status, %4$s: and a comment type */
|
303 |
Â
_x(
|
304 |
Â
'New %4$s by %1$s on %2$s %3$s',
|
305 |
Â
'1: Comment author, 2: Post title 3: Comment status, 4: Comment type',
|
319 |
Â
*
|
320 |
Â
* @action edit_comment
|
321 |
Â
*
|
322 |
+
* @param int $comment_id Comment ID.
|
323 |
Â
*/
|
324 |
Â
public function callback_edit_comment( $comment_id ) {
|
325 |
Â
$comment = get_comment( $comment_id );
|
337 |
Â
$comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
|
338 |
Â
|
339 |
Â
$this->log(
|
340 |
+
/* translators: %1$s: a comment author, %2$s: a post title, %3$s: a comment type */
|
341 |
Â
_x(
|
342 |
Â
'%1$s\'s %3$s on %2$s edited',
|
343 |
Â
'1: Comment author, 2: Post title, 3: Comment type',
|
355 |
Â
*
|
356 |
Â
* @action before_delete_post
|
357 |
Â
*
|
358 |
+
* @param int $post_id Post ID.
|
359 |
Â
*/
|
360 |
Â
public function callback_before_delete_post( $post_id ) {
|
361 |
Â
if ( wp_is_post_revision( $post_id ) ) {
|
370 |
Â
*
|
371 |
Â
* @action deleted_post
|
372 |
Â
*
|
373 |
+
* @param int $post_id Post ID.
|
374 |
Â
*/
|
375 |
Â
public function callback_deleted_post( $post_id ) {
|
376 |
Â
if ( wp_is_post_revision( $post_id ) ) {
|
385 |
Â
*
|
386 |
Â
* @action delete_comment
|
387 |
Â
*
|
388 |
+
* @param int $comment_id Comment ID.
|
389 |
Â
*/
|
390 |
Â
public function callback_delete_comment( $comment_id ) {
|
391 |
Â
$comment = get_comment( $comment_id );
|
407 |
Â
}
|
408 |
Â
|
409 |
Â
$this->log(
|
410 |
+
/* translators: %1$s: a comment author, %2$s: a post title, %3$s: a comment type */
|
411 |
Â
_x(
|
412 |
Â
'%1$s\'s %3$s on %2$s deleted permanently',
|
413 |
Â
'1: Comment author, 2: Post title, 3: Comment type',
|
425 |
Â
*
|
426 |
Â
* @action trash_comment
|
427 |
Â
*
|
428 |
+
* @param int $comment_id Comment ID.
|
429 |
Â
*/
|
430 |
Â
public function callback_trash_comment( $comment_id ) {
|
431 |
Â
$comment = get_comment( $comment_id );
|
443 |
Â
$comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
|
444 |
Â
|
445 |
Â
$this->log(
|
446 |
+
/* translators: %1$s: a comment author, %2$s a post title, %3$s a comment type */
|
447 |
Â
_x(
|
448 |
Â
'%1$s\'s %3$s on %2$s trashed',
|
449 |
Â
'1: Comment author, 2: Post title, 3: Comment type',
|
461 |
Â
*
|
462 |
Â
* @action untrash_comment
|
463 |
Â
*
|
464 |
+
* @param int $comment_id Comment ID.
|
465 |
Â
*/
|
466 |
Â
public function callback_untrash_comment( $comment_id ) {
|
467 |
Â
$comment = get_comment( $comment_id );
|
479 |
Â
$comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
|
480 |
Â
|
481 |
Â
$this->log(
|
482 |
+
/* translators: %1$s: a comment author, %2$s: a post title, %3$s: a comment type */
|
483 |
Â
_x(
|
484 |
Â
'%1$s\'s %3$s on %2$s restored',
|
485 |
Â
'1: Comment author, 2: Post title, 3: Comment type',
|
497 |
Â
*
|
498 |
Â
* @action spam_comment
|
499 |
Â
*
|
500 |
+
* @param int $comment_id Comment ID.
|
501 |
Â
*/
|
502 |
Â
public function callback_spam_comment( $comment_id ) {
|
503 |
Â
$comment = get_comment( $comment_id );
|
515 |
Â
$comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
|
516 |
Â
|
517 |
Â
$this->log(
|
518 |
+
/* translators: %1$s: a comment author, %2$s: a post title, %3$s: a comment type */
|
519 |
Â
_x(
|
520 |
Â
'%1$s\'s %3$s on %2$s marked as spam',
|
521 |
Â
'1: Comment author, 2: Post title, 3: Comment type',
|
533 |
Â
*
|
534 |
Â
* @action unspam_comment
|
535 |
Â
*
|
536 |
+
* @param int $comment_id Comment ID.
|
537 |
Â
*/
|
538 |
Â
public function callback_unspam_comment( $comment_id ) {
|
539 |
Â
$comment = get_comment( $comment_id );
|
551 |
Â
$comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
|
552 |
Â
|
553 |
Â
$this->log(
|
554 |
+
/* translators: %1$s: a comment author, %2$s: a post title, %3$s: a comment type */
|
555 |
Â
_x(
|
556 |
Â
'%1$s\'s %3$s on %2$s unmarked as spam',
|
557 |
Â
'1: Comment author, 2: Post title, 3: Comment type',
|
569 |
Â
*
|
570 |
Â
* @action transition_comment_status
|
571 |
Â
*
|
572 |
+
* @param string $new_status New comment status.
|
573 |
+
* @param string $old_status Old comment status.
|
574 |
+
* @param WP_Comment $comment Comment object.
|
575 |
Â
*/
|
576 |
Â
public function callback_transition_comment_status( $new_status, $old_status, $comment ) {
|
577 |
Â
if ( in_array( $comment->comment_type, $this->get_ignored_comment_types(), true ) ) {
|
591 |
Â
$comment_type = get_comment_type( $comment->comment_ID );
|
592 |
Â
|
593 |
Â
$this->log(
|
594 |
+
/* translators: %1$s: a comment author, %2$s: a post title, %3$s: a comment type */
|
595 |
Â
_x(
|
596 |
Â
'%1$s\'s %3$s %2$s',
|
597 |
Â
'Comment status transition. 1: Comment author, 2: Post title, 3: Comment type',
|
609 |
Â
*
|
610 |
Â
* @action comment_duplicate_trigger
|
611 |
Â
*
|
612 |
+
* @param array $comment_data Comment data.
|
613 |
Â
*/
|
614 |
Â
public function callback_comment_duplicate_trigger( $comment_data ) {
|
615 |
Â
global $wpdb;
|
631 |
Â
$comment_type = mb_strtolower( $this->get_comment_type_label( $comment_id ) );
|
632 |
Â
|
633 |
Â
$this->log(
|
634 |
+
/* translators: %1$s: a comment author, %2$s: a post title, %3$s: a comment type */
|
635 |
Â
_x(
|
636 |
Â
'Duplicate %3$s by %1$s prevented on %2$s',
|
637 |
Â
'1: Comment author, 2: Post title, 3: Comment type',
|
connectors/class-connector-edd.php
CHANGED
@@ -1,7 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
|
3 |
Â
namespace WP_Stream;
|
4 |
Â
|
Â
|
|
Â
|
|
Â
|
|
5 |
Â
class Connector_EDD extends Connector {
|
6 |
Â
|
7 |
Â
/**
|
@@ -135,7 +143,6 @@ class Connector_EDD extends Connector {
|
|
135 |
Â
'discounts' => esc_html_x( 'Discounts', 'edd', 'stream' ),
|
136 |
Â
'reports' => esc_html_x( 'Reports', 'edd', 'stream' ),
|
137 |
Â
'api_keys' => esc_html_x( 'API Keys', 'edd', 'stream' ),
|
138 |
-
// 'payments' => esc_html_x( 'Payments', 'edd', 'stream' ),
|
139 |
Â
);
|
140 |
Â
}
|
141 |
Â
|
@@ -144,8 +151,8 @@ class Connector_EDD extends Connector {
|
|
144 |
Â
*
|
145 |
Â
* @filter wp_stream_action_links_{connector}
|
146 |
Â
*
|
147 |
-
* @param array $links
|
148 |
-
* @param object $record
|
149 |
Â
*
|
150 |
Â
* @return array Action links
|
151 |
Â
*/
|
@@ -157,7 +164,7 @@ class Connector_EDD extends Connector {
|
|
157 |
Â
$post_type_label = get_post_type_labels( get_post_type_object( 'edd_discount' ) )->singular_name;
|
158 |
Â
$base = admin_url( 'edit.php?post_type=download&page=edd-discounts' );
|
159 |
Â
|
160 |
-
|
161 |
Â
$links[ sprintf( esc_html__( 'Edit %s', 'stream' ), $post_type_label ) ] = add_query_arg(
|
162 |
Â
array(
|
163 |
Â
'edd-action' => 'edit_discount',
|
@@ -167,7 +174,7 @@ class Connector_EDD extends Connector {
|
|
167 |
Â
);
|
168 |
Â
|
169 |
Â
if ( 'active' === get_post( $record->object_id )->post_status ) {
|
170 |
-
|
171 |
Â
$links[ sprintf( esc_html__( 'Deactivate %s', 'stream' ), $post_type_label ) ] = add_query_arg(
|
172 |
Â
array(
|
173 |
Â
'edd-action' => 'deactivate_discount',
|
@@ -176,7 +183,7 @@ class Connector_EDD extends Connector {
|
|
176 |
Â
$base
|
177 |
Â
);
|
178 |
Â
} else {
|
179 |
-
|
180 |
Â
$links[ sprintf( esc_html__( 'Activate %s', 'stream' ), $post_type_label ) ] = add_query_arg(
|
181 |
Â
array(
|
182 |
Â
'edd-action' => 'activate_discount',
|
@@ -194,7 +201,7 @@ class Connector_EDD extends Connector {
|
|
194 |
Â
true
|
195 |
Â
) ) {
|
196 |
Â
$tax_label = get_taxonomy_labels( get_taxonomy( $record->context ) )->singular_name;
|
197 |
-
|
198 |
Â
$links[ sprintf( esc_html__( 'Edit %s', 'stream' ), $tax_label ) ] = get_edit_term_link( $record->object_id, $record->get_meta( 'taxonomy', true ) );
|
199 |
Â
} elseif ( 'api_keys' === $record->context ) {
|
200 |
Â
$user = new \WP_User( $record->object_id );
|
@@ -235,6 +242,9 @@ class Connector_EDD extends Connector {
|
|
235 |
Â
return $links;
|
236 |
Â
}
|
237 |
Â
|
Â
|
|
Â
|
|
Â
|
|
238 |
Â
public function register() {
|
239 |
Â
parent::register();
|
240 |
Â
|
@@ -245,30 +255,73 @@ class Connector_EDD extends Connector {
|
|
245 |
Â
);
|
246 |
Â
}
|
247 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
248 |
Â
public function callback_update_option( $option, $old, $new ) {
|
249 |
Â
$this->check( $option, $old, $new );
|
250 |
Â
}
|
251 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
252 |
Â
public function callback_add_option( $option, $val ) {
|
253 |
Â
$this->check( $option, null, $val );
|
254 |
Â
}
|
255 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
256 |
Â
public function callback_delete_option( $option ) {
|
257 |
Â
$this->check( $option, null, null );
|
258 |
Â
}
|
259 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
260 |
Â
public function callback_update_site_option( $option, $old, $new ) {
|
261 |
Â
$this->check( $option, $old, $new );
|
262 |
Â
}
|
263 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
264 |
Â
public function callback_add_site_option( $option, $val ) {
|
265 |
Â
$this->check( $option, null, $val );
|
266 |
Â
}
|
267 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
268 |
Â
public function callback_delete_site_option( $option ) {
|
269 |
Â
$this->check( $option, null, null );
|
270 |
Â
}
|
271 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
272 |
Â
public function check( $option, $old_value, $new_value ) {
|
273 |
Â
if ( ! array_key_exists( $option, $this->options ) ) {
|
274 |
Â
return;
|
@@ -291,7 +344,7 @@ class Connector_EDD extends Connector {
|
|
291 |
Â
$context = isset( $data['context'] ) ? $data['context'] : 'settings';
|
292 |
Â
|
293 |
Â
$this->log(
|
294 |
-
|
295 |
Â
__( '"%s" setting updated', 'stream' ),
|
296 |
Â
compact( 'option_title', 'option', 'old_value', 'new_value' ),
|
297 |
Â
null,
|
@@ -301,6 +354,12 @@ class Connector_EDD extends Connector {
|
|
301 |
Â
}
|
302 |
Â
}
|
303 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
304 |
Â
public function check_edd_settings( $old_value, $new_value ) {
|
305 |
Â
$options = array();
|
306 |
Â
|
@@ -312,7 +371,7 @@ class Connector_EDD extends Connector {
|
|
312 |
Â
$options[ $field_key ] = $field_value;
|
313 |
Â
}
|
314 |
Â
|
315 |
-
// TODO: Check this exists first
|
316 |
Â
$settings = \edd_get_registered_settings();
|
317 |
Â
|
318 |
Â
foreach ( $options as $option => $option_value ) {
|
@@ -337,7 +396,7 @@ class Connector_EDD extends Connector {
|
|
337 |
Â
}
|
338 |
Â
|
339 |
Â
$this->log(
|
340 |
-
|
341 |
Â
__( '"%s" setting updated', 'stream' ),
|
342 |
Â
array(
|
343 |
Â
'option_title' => $field['name'],
|
@@ -356,7 +415,7 @@ class Connector_EDD extends Connector {
|
|
356 |
Â
/**
|
357 |
Â
* Override connector log for our own Settings / Actions
|
358 |
Â
*
|
359 |
-
* @param array $data
|
360 |
Â
*
|
361 |
Â
* @return array|bool
|
362 |
Â
*/
|
@@ -366,31 +425,31 @@ class Connector_EDD extends Connector {
|
|
366 |
Â
}
|
367 |
Â
|
368 |
Â
if ( 'posts' === $data['connector'] && 'download' === $data['context'] ) {
|
369 |
-
// Download posts operations
|
370 |
Â
$data['context'] = 'downloads';
|
371 |
Â
$data['connector'] = $this->name;
|
372 |
Â
} elseif ( 'posts' === $data['connector'] && 'edd_discount' === $data['context'] ) {
|
373 |
-
// Discount posts operations
|
374 |
Â
if ( $this->is_discount_status_change ) {
|
375 |
Â
return false;
|
376 |
Â
}
|
377 |
Â
|
378 |
Â
if ( 'deleted' === $data['action'] ) {
|
379 |
-
|
380 |
-
$data['message'] = esc_html__( '"%
|
381 |
Â
}
|
382 |
Â
|
383 |
Â
$data['context'] = 'discounts';
|
384 |
Â
$data['connector'] = $this->name;
|
385 |
Â
} elseif ( 'posts' === $data['connector'] && 'edd_payment' === $data['context'] ) {
|
386 |
-
// Payment posts operations
|
387 |
Â
return false; // Do not track payments, they're well logged!
|
388 |
Â
} elseif ( 'posts' === $data['connector'] && 'edd_log' === $data['context'] ) {
|
389 |
-
// Logging operations
|
390 |
-
return false; // Do not track notes, because they're basically logs
|
391 |
Â
} elseif ( 'comments' === $data['connector'] && 'edd_payment' === $data['context'] ) {
|
392 |
-
// Payment notes ( comments ) operations
|
393 |
-
return false; // Do not track notes, because they're basically logs
|
394 |
Â
} elseif ( 'taxonomies' === $data['connector'] && 'download_category' === $data['context'] ) {
|
395 |
Â
$data['connector'] = $this->name;
|
396 |
Â
} elseif ( 'taxonomies' === $data['connector'] && 'download_tag' === $data['context'] ) {
|
@@ -404,12 +463,21 @@ class Connector_EDD extends Connector {
|
|
404 |
Â
return $data;
|
405 |
Â
}
|
406 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
407 |
Â
public function callback_edd_pre_update_discount_status( $code_id, $new_status ) {
|
408 |
Â
$this->is_discount_status_change = true;
|
409 |
Â
|
410 |
Â
$this->log(
|
411 |
Â
sprintf(
|
412 |
-
|
413 |
Â
__( '"%1$s" discount %2$s', 'stream' ),
|
414 |
Â
get_post( $code_id )->post_title,
|
415 |
Â
'active' === $new_status ? esc_html__( 'activated', 'stream' ) : esc_html__( 'deactivated', 'stream' )
|
@@ -423,27 +491,56 @@ class Connector_EDD extends Connector {
|
|
423 |
Â
'updated'
|
424 |
Â
);
|
425 |
Â
}
|
426 |
-
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
427 |
Â
private function callback_edd_generate_pdf() {
|
428 |
Â
$this->report_generated( 'pdf' );
|
429 |
Â
}
|
430 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
431 |
Â
public function callback_edd_earnings_export() {
|
432 |
Â
$this->report_generated( 'earnings' );
|
433 |
Â
}
|
434 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
435 |
Â
public function callback_edd_payment_export() {
|
436 |
Â
$this->report_generated( 'payments' );
|
437 |
Â
}
|
438 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
439 |
Â
public function callback_edd_email_export() {
|
440 |
Â
$this->report_generated( 'emails' );
|
441 |
Â
}
|
442 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
443 |
Â
public function callback_edd_downloads_history_export() {
|
444 |
Â
$this->report_generated( 'download-history' );
|
445 |
Â
}
|
446 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
447 |
Â
private function report_generated( $type ) {
|
448 |
Â
$label = '';
|
449 |
Â
|
@@ -461,7 +558,7 @@ class Connector_EDD extends Connector {
|
|
461 |
Â
|
462 |
Â
$this->log(
|
463 |
Â
sprintf(
|
464 |
-
|
465 |
Â
__( 'Generated %s report', 'stream' ),
|
466 |
Â
$label
|
467 |
Â
),
|
@@ -474,6 +571,11 @@ class Connector_EDD extends Connector {
|
|
474 |
Â
);
|
475 |
Â
}
|
476 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
477 |
Â
public function callback_edd_export_settings() {
|
478 |
Â
$this->log(
|
479 |
Â
__( 'Exported Settings', 'stream' ),
|
@@ -484,6 +586,11 @@ class Connector_EDD extends Connector {
|
|
484 |
Â
);
|
485 |
Â
}
|
486 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
487 |
Â
public function callback_edd_import_settings() {
|
488 |
Â
$this->log(
|
489 |
Â
__( 'Imported Settings', 'stream' ),
|
@@ -494,19 +601,56 @@ class Connector_EDD extends Connector {
|
|
494 |
Â
);
|
495 |
Â
}
|
496 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
497 |
Â
public function callback_update_user_meta( $meta_id, $object_id, $meta_key, $_meta_value ) {
|
498 |
Â
unset( $meta_id );
|
499 |
Â
$this->meta( $object_id, $meta_key, $_meta_value );
|
500 |
Â
}
|
501 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
502 |
Â
public function callback_add_user_meta( $object_id, $meta_key, $_meta_value ) {
|
503 |
Â
$this->meta( $object_id, $meta_key, $_meta_value, true );
|
504 |
Â
}
|
505 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
506 |
Â
public function callback_delete_user_meta( $meta_id, $object_id, $meta_key, $_meta_value ) {
|
507 |
Â
$this->meta( $object_id, $meta_key, null );
|
508 |
Â
}
|
509 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
510 |
Â
public function meta( $object_id, $key, $value, $is_add = false ) {
|
511 |
Â
if ( ! in_array( $key, $this->user_meta, true ) ) {
|
512 |
Â
return false;
|
@@ -529,6 +673,13 @@ class Connector_EDD extends Connector {
|
|
529 |
Â
);
|
530 |
Â
}
|
531 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
532 |
Â
private function meta_edd_user_public_key( $user_id, $value, $is_add = false ) {
|
533 |
Â
if ( is_null( $value ) ) {
|
534 |
Â
$action = 'revoked';
|
@@ -543,7 +694,7 @@ class Connector_EDD extends Connector {
|
|
543 |
Â
|
544 |
Â
$this->log(
|
545 |
Â
sprintf(
|
546 |
-
|
547 |
Â
__( 'User API Key %s', 'stream' ),
|
548 |
Â
$action_title
|
549 |
Â
),
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for Easy Digital Downloads
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
Â
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_EDD
|
12 |
+
*/
|
13 |
Â
class Connector_EDD extends Connector {
|
14 |
Â
|
15 |
Â
/**
|
143 |
Â
'discounts' => esc_html_x( 'Discounts', 'edd', 'stream' ),
|
144 |
Â
'reports' => esc_html_x( 'Reports', 'edd', 'stream' ),
|
145 |
Â
'api_keys' => esc_html_x( 'API Keys', 'edd', 'stream' ),
|
Â
|
|
146 |
Â
);
|
147 |
Â
}
|
148 |
Â
|
151 |
Â
*
|
152 |
Â
* @filter wp_stream_action_links_{connector}
|
153 |
Â
*
|
154 |
+
* @param array $links Previous links registered.
|
155 |
+
* @param object $record Stream record.
|
156 |
Â
*
|
157 |
Â
* @return array Action links
|
158 |
Â
*/
|
164 |
Â
$post_type_label = get_post_type_labels( get_post_type_object( 'edd_discount' ) )->singular_name;
|
165 |
Â
$base = admin_url( 'edit.php?post_type=download&page=edd-discounts' );
|
166 |
Â
|
167 |
+
/* translators: %s: a post type (e.g. "Post") */
|
168 |
Â
$links[ sprintf( esc_html__( 'Edit %s', 'stream' ), $post_type_label ) ] = add_query_arg(
|
169 |
Â
array(
|
170 |
Â
'edd-action' => 'edit_discount',
|
174 |
Â
);
|
175 |
Â
|
176 |
Â
if ( 'active' === get_post( $record->object_id )->post_status ) {
|
177 |
+
/* translators: %s: a post type (e.g. "Post") */
|
178 |
Â
$links[ sprintf( esc_html__( 'Deactivate %s', 'stream' ), $post_type_label ) ] = add_query_arg(
|
179 |
Â
array(
|
180 |
Â
'edd-action' => 'deactivate_discount',
|
183 |
Â
$base
|
184 |
Â
);
|
185 |
Â
} else {
|
186 |
+
/* translators: %s a post type (e.g. "Post") */
|
187 |
Â
$links[ sprintf( esc_html__( 'Activate %s', 'stream' ), $post_type_label ) ] = add_query_arg(
|
188 |
Â
array(
|
189 |
Â
'edd-action' => 'activate_discount',
|
201 |
Â
true
|
202 |
Â
) ) {
|
203 |
Â
$tax_label = get_taxonomy_labels( get_taxonomy( $record->context ) )->singular_name;
|
204 |
+
/* translators: %s a taxonomy (e.g. "Category") */
|
205 |
Â
$links[ sprintf( esc_html__( 'Edit %s', 'stream' ), $tax_label ) ] = get_edit_term_link( $record->object_id, $record->get_meta( 'taxonomy', true ) );
|
206 |
Â
} elseif ( 'api_keys' === $record->context ) {
|
207 |
Â
$user = new \WP_User( $record->object_id );
|
242 |
Â
return $links;
|
243 |
Â
}
|
244 |
Â
|
245 |
+
/**
|
246 |
+
* Register the connector
|
247 |
+
*/
|
248 |
Â
public function register() {
|
249 |
Â
parent::register();
|
250 |
Â
|
255 |
Â
);
|
256 |
Â
}
|
257 |
Â
|
258 |
+
/**
|
259 |
+
* Track EDD-specific option changes.
|
260 |
+
*
|
261 |
+
* @param string $option Option key.
|
262 |
+
* @param string $old Old value.
|
263 |
+
* @param string $new New value.
|
264 |
+
*/
|
265 |
Â
public function callback_update_option( $option, $old, $new ) {
|
266 |
Â
$this->check( $option, $old, $new );
|
267 |
Â
}
|
268 |
Â
|
269 |
+
/**
|
270 |
+
* Track EDD-specific option creations.
|
271 |
+
*
|
272 |
+
* @param string $option Option key.
|
273 |
+
* @param string $val Value.
|
274 |
+
*/
|
275 |
Â
public function callback_add_option( $option, $val ) {
|
276 |
Â
$this->check( $option, null, $val );
|
277 |
Â
}
|
278 |
Â
|
279 |
+
/**
|
280 |
+
* Track EDD-specific option deletions.
|
281 |
+
*
|
282 |
+
* @param string $option Option key.
|
283 |
+
*/
|
284 |
Â
public function callback_delete_option( $option ) {
|
285 |
Â
$this->check( $option, null, null );
|
286 |
Â
}
|
287 |
Â
|
288 |
+
/**
|
289 |
+
* Track EDD-specific site option changes
|
290 |
+
*
|
291 |
+
* @param string $option Option key.
|
292 |
+
* @param string $old Old value.
|
293 |
+
* @param string $new New value.
|
294 |
+
*/
|
295 |
Â
public function callback_update_site_option( $option, $old, $new ) {
|
296 |
Â
$this->check( $option, $old, $new );
|
297 |
Â
}
|
298 |
Â
|
299 |
+
/**
|
300 |
+
* Track EDD-specific site option creations.
|
301 |
+
*
|
302 |
+
* @param string $option Option key.
|
303 |
+
* @param string $val Value.
|
304 |
+
*/
|
305 |
Â
public function callback_add_site_option( $option, $val ) {
|
306 |
Â
$this->check( $option, null, $val );
|
307 |
Â
}
|
308 |
Â
|
309 |
+
/**
|
310 |
+
* Track EDD-specific site option deletions.
|
311 |
+
*
|
312 |
+
* @param string $option Option key.
|
313 |
+
*/
|
314 |
Â
public function callback_delete_site_option( $option ) {
|
315 |
Â
$this->check( $option, null, null );
|
316 |
Â
}
|
317 |
Â
|
318 |
+
/**
|
319 |
+
* Logs EDD-specific (site) option action.
|
320 |
+
*
|
321 |
+
* @param string $option Option key.
|
322 |
+
* @param string $old_value Old value.
|
323 |
+
* @param string $new_value New value.
|
324 |
+
*/
|
325 |
Â
public function check( $option, $old_value, $new_value ) {
|
326 |
Â
if ( ! array_key_exists( $option, $this->options ) ) {
|
327 |
Â
return;
|
344 |
Â
$context = isset( $data['context'] ) ? $data['context'] : 'settings';
|
345 |
Â
|
346 |
Â
$this->log(
|
347 |
+
/* translators: %s: a setting title (e.g. "Language") */
|
348 |
Â
__( '"%s" setting updated', 'stream' ),
|
349 |
Â
compact( 'option_title', 'option', 'old_value', 'new_value' ),
|
350 |
Â
null,
|
354 |
Â
}
|
355 |
Â
}
|
356 |
Â
|
357 |
+
/**
|
358 |
+
* Logs EDD setting changes.
|
359 |
+
*
|
360 |
+
* @param string $old_value Old value.
|
361 |
+
* @param string $new_value New value.
|
362 |
+
*/
|
363 |
Â
public function check_edd_settings( $old_value, $new_value ) {
|
364 |
Â
$options = array();
|
365 |
Â
|
371 |
Â
$options[ $field_key ] = $field_value;
|
372 |
Â
}
|
373 |
Â
|
374 |
+
// TODO: Check this exists first.
|
375 |
Â
$settings = \edd_get_registered_settings();
|
376 |
Â
|
377 |
Â
foreach ( $options as $option => $option_value ) {
|
396 |
Â
}
|
397 |
Â
|
398 |
Â
$this->log(
|
399 |
+
/* translators: %s: a setting title (e.g. "Language") */
|
400 |
Â
__( '"%s" setting updated', 'stream' ),
|
401 |
Â
array(
|
402 |
Â
'option_title' => $field['name'],
|
415 |
Â
/**
|
416 |
Â
* Override connector log for our own Settings / Actions
|
417 |
Â
*
|
418 |
+
* @param array $data Record data.
|
419 |
Â
*
|
420 |
Â
* @return array|bool
|
421 |
Â
*/
|
425 |
Â
}
|
426 |
Â
|
427 |
Â
if ( 'posts' === $data['connector'] && 'download' === $data['context'] ) {
|
428 |
+
// Download posts operations.
|
429 |
Â
$data['context'] = 'downloads';
|
430 |
Â
$data['connector'] = $this->name;
|
431 |
Â
} elseif ( 'posts' === $data['connector'] && 'edd_discount' === $data['context'] ) {
|
432 |
+
// Discount posts operations.
|
433 |
Â
if ( $this->is_discount_status_change ) {
|
434 |
Â
return false;
|
435 |
Â
}
|
436 |
Â
|
437 |
Â
if ( 'deleted' === $data['action'] ) {
|
438 |
+
/* translators: %s: a discount title (e.g. "Mother's Day") */
|
439 |
+
$data['message'] = esc_html__( '"%s" discount deleted', 'stream' );
|
440 |
Â
}
|
441 |
Â
|
442 |
Â
$data['context'] = 'discounts';
|
443 |
Â
$data['connector'] = $this->name;
|
444 |
Â
} elseif ( 'posts' === $data['connector'] && 'edd_payment' === $data['context'] ) {
|
445 |
+
// Payment posts operations.
|
446 |
Â
return false; // Do not track payments, they're well logged!
|
447 |
Â
} elseif ( 'posts' === $data['connector'] && 'edd_log' === $data['context'] ) {
|
448 |
+
// Logging operations.
|
449 |
+
return false; // Do not track notes, because they're basically logs.
|
450 |
Â
} elseif ( 'comments' === $data['connector'] && 'edd_payment' === $data['context'] ) {
|
451 |
+
// Payment notes ( comments ) operations.
|
452 |
+
return false; // Do not track notes, because they're basically logs.
|
453 |
Â
} elseif ( 'taxonomies' === $data['connector'] && 'download_category' === $data['context'] ) {
|
454 |
Â
$data['connector'] = $this->name;
|
455 |
Â
} elseif ( 'taxonomies' === $data['connector'] && 'download_tag' === $data['context'] ) {
|
463 |
Â
return $data;
|
464 |
Â
}
|
465 |
Â
|
466 |
+
/**
|
467 |
+
* Undocumented function
|
468 |
+
*
|
469 |
+
* @action edd_pre_update_discount_status
|
470 |
+
*
|
471 |
+
* @param int $code_id Post ID.
|
472 |
+
* @param string $new_status Post status.
|
473 |
+
* @return void
|
474 |
+
*/
|
475 |
Â
public function callback_edd_pre_update_discount_status( $code_id, $new_status ) {
|
476 |
Â
$this->is_discount_status_change = true;
|
477 |
Â
|
478 |
Â
$this->log(
|
479 |
Â
sprintf(
|
480 |
+
/* translators: %1$s: a discount title, %2$s: a status (e.g. "Mother's Day", "activated") */
|
481 |
Â
__( '"%1$s" discount %2$s', 'stream' ),
|
482 |
Â
get_post( $code_id )->post_title,
|
483 |
Â
'active' === $new_status ? esc_html__( 'activated', 'stream' ) : esc_html__( 'deactivated', 'stream' )
|
491 |
Â
'updated'
|
492 |
Â
);
|
493 |
Â
}
|
494 |
+
/**
|
495 |
+
* Logs PDFs
|
496 |
+
*
|
497 |
+
* @action edd_generate_pdf
|
498 |
+
*/
|
499 |
Â
private function callback_edd_generate_pdf() {
|
500 |
Â
$this->report_generated( 'pdf' );
|
501 |
Â
}
|
502 |
Â
|
503 |
+
/**
|
504 |
+
* Logs earning reports.
|
505 |
+
*
|
506 |
+
* @action edd_earnings_export
|
507 |
+
*/
|
508 |
Â
public function callback_edd_earnings_export() {
|
509 |
Â
$this->report_generated( 'earnings' );
|
510 |
Â
}
|
511 |
Â
|
512 |
+
/**
|
513 |
+
* Logs payment reports.
|
514 |
+
*
|
515 |
+
* @action edd_payment_export
|
516 |
+
*/
|
517 |
Â
public function callback_edd_payment_export() {
|
518 |
Â
$this->report_generated( 'payments' );
|
519 |
Â
}
|
520 |
Â
|
521 |
+
/**
|
522 |
+
* Logs email reports.
|
523 |
+
*
|
524 |
+
* @action edd_email_export
|
525 |
+
*/
|
526 |
Â
public function callback_edd_email_export() {
|
527 |
Â
$this->report_generated( 'emails' );
|
528 |
Â
}
|
529 |
Â
|
530 |
+
/**
|
531 |
+
* Logs download history reports.
|
532 |
+
*
|
533 |
+
* @action edd_downloads_history_export
|
534 |
+
*/
|
535 |
Â
public function callback_edd_downloads_history_export() {
|
536 |
Â
$this->report_generated( 'download-history' );
|
537 |
Â
}
|
538 |
Â
|
539 |
+
/**
|
540 |
+
* Logs generated reports.
|
541 |
+
*
|
542 |
+
* @param string $type Report type.
|
543 |
+
*/
|
544 |
Â
private function report_generated( $type ) {
|
545 |
Â
$label = '';
|
546 |
Â
|
558 |
Â
|
559 |
Â
$this->log(
|
560 |
Â
sprintf(
|
561 |
+
/* translators: %s: a report title (e.g. "Sales and Earnings") */
|
562 |
Â
__( 'Generated %s report', 'stream' ),
|
563 |
Â
$label
|
564 |
Â
),
|
571 |
Â
);
|
572 |
Â
}
|
573 |
Â
|
574 |
+
/**
|
575 |
+
* Logs exported settings
|
576 |
+
*
|
577 |
+
* @action edd_export_settings
|
578 |
+
*/
|
579 |
Â
public function callback_edd_export_settings() {
|
580 |
Â
$this->log(
|
581 |
Â
__( 'Exported Settings', 'stream' ),
|
586 |
Â
);
|
587 |
Â
}
|
588 |
Â
|
589 |
+
/**
|
590 |
+
* Logs imported settings
|
591 |
+
*
|
592 |
+
* @action edd_import_settings
|
593 |
+
*/
|
594 |
Â
public function callback_edd_import_settings() {
|
595 |
Â
$this->log(
|
596 |
Â
__( 'Imported Settings', 'stream' ),
|
601 |
Â
);
|
602 |
Â
}
|
603 |
Â
|
604 |
+
/**
|
605 |
+
* Logs EDD-specific user meta changes.
|
606 |
+
*
|
607 |
+
* @action update_user_meta
|
608 |
+
*
|
609 |
+
* @param int $meta_id Meta ID.
|
610 |
+
* @param int $object_id Object ID.
|
611 |
+
* @param string $meta_key Meta key.
|
612 |
+
* @param string $_meta_value Meta value.
|
613 |
+
*/
|
614 |
Â
public function callback_update_user_meta( $meta_id, $object_id, $meta_key, $_meta_value ) {
|
615 |
Â
unset( $meta_id );
|
616 |
Â
$this->meta( $object_id, $meta_key, $_meta_value );
|
617 |
Â
}
|
618 |
Â
|
619 |
+
/**
|
620 |
+
* Logs EDD-specific user meta creations.
|
621 |
+
*
|
622 |
+
* @action add_user_meta
|
623 |
+
*
|
624 |
+
* @param int $object_id Object ID.
|
625 |
+
* @param string $meta_key Meta key.
|
626 |
+
* @param string $_meta_value Meta value.
|
627 |
+
*/
|
628 |
Â
public function callback_add_user_meta( $object_id, $meta_key, $_meta_value ) {
|
629 |
Â
$this->meta( $object_id, $meta_key, $_meta_value, true );
|
630 |
Â
}
|
631 |
Â
|
632 |
+
/**
|
633 |
+
* Logs EDD-specific user meta deletions.
|
634 |
+
*
|
635 |
+
* @action delete_user_meta
|
636 |
+
*
|
637 |
+
* @param int $meta_id Meta ID.
|
638 |
+
* @param int $object_id Object ID.
|
639 |
+
* @param string $meta_key Meta key.
|
640 |
+
* @param string $_meta_value Meta value.
|
641 |
+
*/
|
642 |
Â
public function callback_delete_user_meta( $meta_id, $object_id, $meta_key, $_meta_value ) {
|
643 |
Â
$this->meta( $object_id, $meta_key, null );
|
644 |
Â
}
|
645 |
Â
|
646 |
+
/**
|
647 |
+
* Logs EDD-specific user meta activity.
|
648 |
+
*
|
649 |
+
* @param int $object_id Object ID.
|
650 |
+
* @param string $key Meta key.
|
651 |
+
* @param string $value Meta value.
|
652 |
+
* @param bool $is_add Is this a new meta?.
|
653 |
+
*/
|
654 |
Â
public function meta( $object_id, $key, $value, $is_add = false ) {
|
655 |
Â
if ( ! in_array( $key, $this->user_meta, true ) ) {
|
656 |
Â
return false;
|
673 |
Â
);
|
674 |
Â
}
|
675 |
Â
|
676 |
+
/**
|
677 |
+
* Logs change to User API key
|
678 |
+
*
|
679 |
+
* @param int $user_id User ID.
|
680 |
+
* @param string $value API Key.
|
681 |
+
* @param bool $is_add Is this a new API key.
|
682 |
+
*/
|
683 |
Â
private function meta_edd_user_public_key( $user_id, $value, $is_add = false ) {
|
684 |
Â
if ( is_null( $value ) ) {
|
685 |
Â
$action = 'revoked';
|
694 |
Â
|
695 |
Â
$this->log(
|
696 |
Â
sprintf(
|
697 |
+
/* translators: %s: a status (e.g. "revoked") */
|
698 |
Â
__( 'User API Key %s', 'stream' ),
|
699 |
Â
$action_title
|
700 |
Â
),
|
connectors/class-connector-editor.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_Editor extends Connector {
|
5 |
Â
/**
|
6 |
Â
* Connector slug
|
@@ -85,8 +94,9 @@ class Connector_Editor extends Connector {
|
|
85 |
Â
/**
|
86 |
Â
* Get the context based on wp_redirect location
|
87 |
Â
*
|
88 |
-
* @param string $location The URL of the redirect
|
89 |
-
*
|
Â
|
|
90 |
Â
*/
|
91 |
Â
public function get_context( $location ) {
|
92 |
Â
$context = null;
|
@@ -115,7 +125,7 @@ class Connector_Editor extends Connector {
|
|
115 |
Â
* @return string Translated string
|
116 |
Â
*/
|
117 |
Â
public function get_message() {
|
118 |
-
|
119 |
Â
return _x(
|
120 |
Â
'"%1$s" in "%2$s" updated',
|
121 |
Â
'1: File name, 2: Theme/plugin name',
|
@@ -128,8 +138,8 @@ class Connector_Editor extends Connector {
|
|
128 |
Â
*
|
129 |
Â
* @filter wp_stream_action_links_{connector}
|
130 |
Â
*
|
131 |
-
* @param array $links
|
132 |
-
* @param object $record
|
133 |
Â
*
|
134 |
Â
* @return array Action links
|
135 |
Â
*/
|
@@ -209,7 +219,7 @@ class Connector_Editor extends Connector {
|
|
209 |
Â
/**
|
210 |
Â
* Retrieve theme data needed for the log message
|
211 |
Â
*
|
212 |
-
* @param string $slug
|
213 |
Â
*
|
214 |
Â
* @return mixed $output Compacted variables
|
215 |
Â
*/
|
@@ -251,8 +261,8 @@ class Connector_Editor extends Connector {
|
|
251 |
Â
/**
|
252 |
Â
* Retrieve plugin data needed for the log message
|
253 |
Â
*
|
254 |
-
* @param string $slug
|
255 |
-
* @return mixed $output
|
256 |
Â
*/
|
257 |
Â
public function get_plugin_data( $slug ) {
|
258 |
Â
$base = null;
|
@@ -286,11 +296,15 @@ class Connector_Editor extends Connector {
|
|
286 |
Â
}
|
287 |
Â
|
288 |
Â
/**
|
Â
|
|
Â
|
|
289 |
Â
* @filter wp_redirect
|
Â
|
|
Â
|
|
290 |
Â
*/
|
291 |
Â
public function log_changes( $location ) {
|
292 |
Â
if ( ! empty( $this->edited_file ) ) {
|
293 |
-
// TODO: phpcs fix
|
294 |
Â
if ( md5_file( $this->edited_file['file_path'] ) !== $this->edited_file['file_md5'] ) {
|
295 |
Â
$context = $this->get_context( $location );
|
296 |
Â
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for Editor
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_Editor
|
12 |
+
*/
|
13 |
Â
class Connector_Editor extends Connector {
|
14 |
Â
/**
|
15 |
Â
* Connector slug
|
94 |
Â
/**
|
95 |
Â
* Get the context based on wp_redirect location
|
96 |
Â
*
|
97 |
+
* @param string $location The URL of the redirect.
|
98 |
+
*
|
99 |
+
* @return string Context slug
|
100 |
Â
*/
|
101 |
Â
public function get_context( $location ) {
|
102 |
Â
$context = null;
|
125 |
Â
* @return string Translated string
|
126 |
Â
*/
|
127 |
Â
public function get_message() {
|
128 |
+
/* translators: %1$s: a file name, %2$s: a theme / plugin name (e.g. "index.php", "Stream") */
|
129 |
Â
return _x(
|
130 |
Â
'"%1$s" in "%2$s" updated',
|
131 |
Â
'1: File name, 2: Theme/plugin name',
|
138 |
Â
*
|
139 |
Â
* @filter wp_stream_action_links_{connector}
|
140 |
Â
*
|
141 |
+
* @param array $links Previous links registered.
|
142 |
+
* @param object $record Stream record.
|
143 |
Â
*
|
144 |
Â
* @return array Action links
|
145 |
Â
*/
|
219 |
Â
/**
|
220 |
Â
* Retrieve theme data needed for the log message
|
221 |
Â
*
|
222 |
+
* @param string $slug The theme slug (e.g. twentyfourteen).
|
223 |
Â
*
|
224 |
Â
* @return mixed $output Compacted variables
|
225 |
Â
*/
|
261 |
Â
/**
|
262 |
Â
* Retrieve plugin data needed for the log message
|
263 |
Â
*
|
264 |
+
* @param string $slug The plugin file base name (e.g. akismet/akismet.php).
|
265 |
+
* @return mixed $output Compacted variables.
|
266 |
Â
*/
|
267 |
Â
public function get_plugin_data( $slug ) {
|
268 |
Â
$base = null;
|
296 |
Â
}
|
297 |
Â
|
298 |
Â
/**
|
299 |
+
* Logs changes
|
300 |
+
*
|
301 |
Â
* @filter wp_redirect
|
302 |
+
*
|
303 |
+
* @param string $location Location.
|
304 |
Â
*/
|
305 |
Â
public function log_changes( $location ) {
|
306 |
Â
if ( ! empty( $this->edited_file ) ) {
|
307 |
+
// TODO: phpcs fix.
|
308 |
Â
if ( md5_file( $this->edited_file['file_path'] ) !== $this->edited_file['file_md5'] ) {
|
309 |
Â
$context = $this->get_context( $location );
|
310 |
Â
|
connectors/class-connector-gravityforms.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_GravityForms extends Connector {
|
5 |
Â
/**
|
6 |
Â
* Connector slug
|
@@ -130,8 +139,8 @@ class Connector_GravityForms extends Connector {
|
|
130 |
Â
*
|
131 |
Â
* @filter wp_stream_action_links_{connector}
|
132 |
Â
*
|
133 |
-
* @param array $links
|
134 |
-
* @param object $record
|
135 |
Â
*
|
136 |
Â
* @return array Action links
|
137 |
Â
*/
|
@@ -176,6 +185,9 @@ class Connector_GravityForms extends Connector {
|
|
176 |
Â
return $links;
|
177 |
Â
}
|
178 |
Â
|
Â
|
|
Â
|
|
Â
|
|
179 |
Â
public function register() {
|
180 |
Â
parent::register();
|
181 |
Â
|
@@ -205,9 +217,8 @@ class Connector_GravityForms extends Connector {
|
|
205 |
Â
/**
|
206 |
Â
* Track Create/Update actions on Forms
|
207 |
Â
*
|
208 |
-
* @param array $form
|
209 |
-
* @param bool $is_new
|
210 |
-
* @return void
|
211 |
Â
*/
|
212 |
Â
public function callback_gform_after_save_form( $form, $is_new ) {
|
213 |
Â
$title = $form['title'];
|
@@ -215,7 +226,7 @@ class Connector_GravityForms extends Connector {
|
|
215 |
Â
|
216 |
Â
$this->log(
|
217 |
Â
sprintf(
|
218 |
-
|
219 |
Â
__( '"%1$s" form %2$s', 'stream' ),
|
220 |
Â
$title,
|
221 |
Â
$is_new ? esc_html__( 'created', 'stream' ) : esc_html__( 'updated', 'stream' )
|
@@ -234,10 +245,9 @@ class Connector_GravityForms extends Connector {
|
|
234 |
Â
/**
|
235 |
Â
* Track saving form confirmations
|
236 |
Â
*
|
237 |
-
* @param array $confirmation
|
238 |
-
* @param array $form
|
239 |
-
* @param bool $is_new
|
240 |
-
* @return array
|
241 |
Â
*/
|
242 |
Â
public function callback_gform_pre_confirmation_save( $confirmation, $form, $is_new = true ) {
|
243 |
Â
if ( ! isset( $is_new ) ) {
|
@@ -246,7 +256,7 @@ class Connector_GravityForms extends Connector {
|
|
246 |
Â
|
247 |
Â
$this->log(
|
248 |
Â
sprintf(
|
249 |
-
|
250 |
Â
__( '"%1$s" confirmation %2$s for "%3$s"', 'stream' ),
|
251 |
Â
$confirmation['name'],
|
252 |
Â
$is_new ? esc_html__( 'created', 'stream' ) : esc_html__( 'updated', 'stream' ),
|
@@ -267,9 +277,9 @@ class Connector_GravityForms extends Connector {
|
|
267 |
Â
/**
|
268 |
Â
* Track saving form notifications
|
269 |
Â
*
|
270 |
-
* @param array $notification
|
271 |
-
* @param array $form
|
272 |
-
* @param bool $is_new
|
273 |
Â
* @return array
|
274 |
Â
*/
|
275 |
Â
public function callback_gform_pre_notification_save( $notification, $form, $is_new = true ) {
|
@@ -279,7 +289,7 @@ class Connector_GravityForms extends Connector {
|
|
279 |
Â
|
280 |
Â
$this->log(
|
281 |
Â
sprintf(
|
282 |
-
|
283 |
Â
__( '"%1$s" notification %2$s for "%3$s"', 'stream' ),
|
284 |
Â
$notification['name'],
|
285 |
Â
$is_new ? esc_html__( 'created', 'stream' ) : esc_html__( 'updated', 'stream' ),
|
@@ -300,14 +310,13 @@ class Connector_GravityForms extends Connector {
|
|
300 |
Â
/**
|
301 |
Â
* Track deletion of notifications
|
302 |
Â
*
|
303 |
-
* @param array $notification
|
304 |
-
* @param array $form
|
305 |
-
* @return void
|
306 |
Â
*/
|
307 |
Â
public function callback_gform_pre_notification_deleted( $notification, $form ) {
|
308 |
Â
$this->log(
|
309 |
Â
sprintf(
|
310 |
-
|
311 |
Â
__( '"%1$s" notification deleted from "%2$s"', 'stream' ),
|
312 |
Â
$notification['name'],
|
313 |
Â
$form['title']
|
@@ -325,14 +334,13 @@ class Connector_GravityForms extends Connector {
|
|
325 |
Â
/**
|
326 |
Â
* Track deletion of confirmations
|
327 |
Â
*
|
328 |
-
* @param array $confirmation
|
329 |
-
* @param array $form
|
330 |
-
* @return void
|
331 |
Â
*/
|
332 |
Â
public function callback_gform_pre_confirmation_deleted( $confirmation, $form ) {
|
333 |
Â
$this->log(
|
334 |
Â
sprintf(
|
335 |
-
|
336 |
Â
__( '"%1$s" confirmation deleted from "%2$s"', 'stream' ),
|
337 |
Â
$confirmation['name'],
|
338 |
Â
$form['title']
|
@@ -350,15 +358,14 @@ class Connector_GravityForms extends Connector {
|
|
350 |
Â
/**
|
351 |
Â
* Track status change of confirmations
|
352 |
Â
*
|
353 |
-
* @param array $confirmation
|
354 |
-
* @param array $form
|
355 |
-
* @param bool $is_active
|
356 |
-
* @return void
|
357 |
Â
*/
|
358 |
Â
public function callback_gform_confirmation_status( $confirmation, $form, $is_active ) {
|
359 |
Â
$this->log(
|
360 |
Â
sprintf(
|
361 |
-
|
362 |
Â
__( '"%1$s" confirmation %2$s from "%3$s"', 'stream' ),
|
363 |
Â
$confirmation['name'],
|
364 |
Â
$is_active ? esc_html__( 'activated', 'stream' ) : esc_html__( 'deactivated', 'stream' ),
|
@@ -378,15 +385,14 @@ class Connector_GravityForms extends Connector {
|
|
378 |
Â
/**
|
379 |
Â
* Track status change of notifications
|
380 |
Â
*
|
381 |
-
* @param array $notification
|
382 |
-
* @param array $form
|
383 |
-
* @param bool $is_active
|
384 |
-
* @return void
|
385 |
Â
*/
|
386 |
Â
public function callback_gform_notification_status( $notification, $form, $is_active ) {
|
387 |
Â
$this->log(
|
388 |
Â
sprintf(
|
389 |
-
|
390 |
Â
__( '"%1$s" notification %2$s from "%3$s"', 'stream' ),
|
391 |
Â
$notification['name'],
|
392 |
Â
$is_active ? esc_html__( 'activated', 'stream' ) : esc_html__( 'deactivated', 'stream' ),
|
@@ -403,30 +409,73 @@ class Connector_GravityForms extends Connector {
|
|
403 |
Â
);
|
404 |
Â
}
|
405 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
406 |
Â
public function callback_update_option( $option, $old, $new ) {
|
407 |
Â
$this->check( $option, $old, $new );
|
408 |
Â
}
|
409 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
410 |
Â
public function callback_add_option( $option, $val ) {
|
411 |
Â
$this->check( $option, null, $val );
|
412 |
Â
}
|
413 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
414 |
Â
public function callback_delete_option( $option ) {
|
415 |
Â
$this->check( $option, null, null );
|
416 |
Â
}
|
417 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
418 |
Â
public function callback_update_site_option( $option, $old, $new ) {
|
419 |
Â
$this->check( $option, $old, $new );
|
420 |
Â
}
|
421 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
422 |
Â
public function callback_add_site_option( $option, $val ) {
|
423 |
Â
$this->check( $option, null, $val );
|
424 |
Â
}
|
425 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
426 |
Â
public function callback_delete_site_option( $option ) {
|
427 |
Â
$this->check( $option, null, null );
|
428 |
Â
}
|
429 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
430 |
Â
public function check( $option, $old_value, $new_value ) {
|
431 |
Â
if ( ! array_key_exists( $option, $this->options ) ) {
|
432 |
Â
return;
|
@@ -440,7 +489,7 @@ class Connector_GravityForms extends Connector {
|
|
440 |
Â
$context = isset( $data['context'] ) ? $data['context'] : 'settings';
|
441 |
Â
|
442 |
Â
$this->log(
|
443 |
-
|
444 |
Â
__( '"%s" setting updated', 'stream' ),
|
445 |
Â
compact( 'option_title', 'option', 'old_value', 'new_value' ),
|
446 |
Â
null,
|
@@ -450,13 +499,20 @@ class Connector_GravityForms extends Connector {
|
|
450 |
Â
}
|
451 |
Â
}
|
452 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
453 |
Â
public function check_rg_gforms_key( $old_value, $new_value ) {
|
454 |
Â
$is_update = ( $new_value && strlen( $new_value ) );
|
455 |
Â
$option = 'rg_gforms_key';
|
456 |
Â
|
457 |
Â
$this->log(
|
458 |
Â
sprintf(
|
459 |
-
|
460 |
Â
__( 'Gravity Forms license key %s', 'stream' ),
|
461 |
Â
$is_update ? esc_html__( 'updated', 'stream' ) : esc_html__( 'deleted', 'stream' )
|
462 |
Â
),
|
@@ -467,10 +523,20 @@ class Connector_GravityForms extends Connector {
|
|
467 |
Â
);
|
468 |
Â
}
|
469 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
470 |
Â
public function callback_gform_post_export_entries( $form, $start_date, $end_date, $fields ) {
|
471 |
Â
unset( $fields );
|
472 |
Â
$this->log(
|
473 |
-
|
474 |
Â
__( '"%s" form entries exported', 'stream' ),
|
475 |
Â
array(
|
476 |
Â
'form_title' => $form['title'],
|
@@ -484,13 +550,20 @@ class Connector_GravityForms extends Connector {
|
|
484 |
Â
);
|
485 |
Â
}
|
486 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
487 |
Â
public function callback_gform_forms_post_import( $forms ) {
|
488 |
Â
$forms_total = count( $forms );
|
489 |
Â
$forms_ids = wp_list_pluck( $forms, 'id' );
|
490 |
Â
$forms_titles = wp_list_pluck( $forms, 'title' );
|
491 |
Â
|
492 |
Â
$this->log(
|
493 |
-
|
494 |
Â
_n( '%d form imported', '%d forms imported', $forms_total, 'stream' ),
|
495 |
Â
array(
|
496 |
Â
'count' => $forms_total,
|
@@ -503,11 +576,19 @@ class Connector_GravityForms extends Connector {
|
|
503 |
Â
);
|
504 |
Â
}
|
505 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
506 |
Â
public function callback_gform_export_separator( $dummy, $form_id ) {
|
507 |
Â
$form = $this->get_form( $form_id );
|
508 |
Â
|
509 |
Â
$this->log(
|
510 |
-
|
511 |
Â
__( '"%s" form exported', 'stream' ),
|
512 |
Â
array(
|
513 |
Â
'form_title' => $form['title'],
|
@@ -521,12 +602,18 @@ class Connector_GravityForms extends Connector {
|
|
521 |
Â
return $dummy;
|
522 |
Â
}
|
523 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
524 |
Â
public function callback_gform_export_options( $dummy, $forms ) {
|
525 |
Â
$ids = wp_list_pluck( $forms, 'id' );
|
526 |
Â
$titles = wp_list_pluck( $forms, 'title' );
|
527 |
Â
|
528 |
Â
$this->log(
|
529 |
-
|
530 |
Â
_n( 'Export process started for %d form', 'Export process started for %d forms', count( $forms ), 'stream' ),
|
531 |
Â
array(
|
532 |
Â
'count' => count( $forms ),
|
@@ -541,12 +628,20 @@ class Connector_GravityForms extends Connector {
|
|
541 |
Â
return $dummy;
|
542 |
Â
}
|
543 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
544 |
Â
public function callback_gform_delete_lead( $lead_id ) {
|
545 |
Â
$lead = $this->get_lead( $lead_id );
|
546 |
Â
$form = $this->get_form( $lead['form_id'] );
|
547 |
Â
|
548 |
Â
$this->log(
|
549 |
-
|
550 |
Â
__( 'Lead #%1$d from "%2$s" deleted', 'stream' ),
|
551 |
Â
array(
|
552 |
Â
'lead_id' => $lead_id,
|
@@ -559,6 +654,18 @@ class Connector_GravityForms extends Connector {
|
|
559 |
Â
);
|
560 |
Â
}
|
561 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
562 |
Â
public function callback_gform_post_note_added( $note_id, $lead_id, $user_id, $user_name, $note, $note_type ) {
|
563 |
Â
unset( $user_id );
|
564 |
Â
unset( $user_name );
|
@@ -569,7 +676,7 @@ class Connector_GravityForms extends Connector {
|
|
569 |
Â
$form = $this->get_form( $lead['form_id'] );
|
570 |
Â
|
571 |
Â
$this->log(
|
572 |
-
|
573 |
Â
__( 'Note #%1$d added to lead #%2$d on "%3$s" form', 'stream' ),
|
574 |
Â
array(
|
575 |
Â
'note_id' => $note_id,
|
@@ -583,12 +690,20 @@ class Connector_GravityForms extends Connector {
|
|
583 |
Â
);
|
584 |
Â
}
|
585 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
586 |
Â
public function callback_gform_pre_note_deleted( $note_id, $lead_id ) {
|
587 |
Â
$lead = $this->get_lead( $lead_id );
|
588 |
Â
$form = $this->get_form( $lead['form_id'] );
|
589 |
Â
|
590 |
Â
$this->log(
|
591 |
-
|
592 |
Â
__( 'Note #%1$d deleted from lead #%2$d on "%3$s" form', 'stream' ),
|
593 |
Â
array(
|
594 |
Â
'note_id' => $note_id,
|
@@ -602,6 +717,15 @@ class Connector_GravityForms extends Connector {
|
|
602 |
Â
);
|
603 |
Â
}
|
604 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
605 |
Â
public function callback_gform_update_status( $lead_id, $status, $prev = '' ) {
|
606 |
Â
$lead = $this->get_lead( $lead_id );
|
607 |
Â
$form = $this->get_form( $lead['form_id'] );
|
@@ -623,7 +747,7 @@ class Connector_GravityForms extends Connector {
|
|
623 |
Â
|
624 |
Â
$this->log(
|
625 |
Â
sprintf(
|
626 |
-
|
627 |
Â
__( 'Lead #%1$d %2$s on "%3$s" form', 'stream' ),
|
628 |
Â
$lead_id,
|
629 |
Â
$actions[ $status ],
|
@@ -645,9 +769,10 @@ class Connector_GravityForms extends Connector {
|
|
645 |
Â
/**
|
646 |
Â
* Callback fired when an entry is read/unread
|
647 |
Â
*
|
648 |
-
* @
|
649 |
-
*
|
650 |
-
* @
|
Â
|
|
651 |
Â
*/
|
652 |
Â
public function callback_gform_update_is_read( $lead_id, $status ) {
|
653 |
Â
$lead = $this->get_lead( $lead_id );
|
@@ -656,7 +781,7 @@ class Connector_GravityForms extends Connector {
|
|
656 |
Â
|
657 |
Â
$this->log(
|
658 |
Â
sprintf(
|
659 |
-
|
660 |
Â
__( 'Entry #%1$d marked as %2$s on form #%3$d ("%4$s")', 'stream' ),
|
661 |
Â
$lead_id,
|
662 |
Â
$status,
|
@@ -678,9 +803,10 @@ class Connector_GravityForms extends Connector {
|
|
678 |
Â
/**
|
679 |
Â
* Callback fired when an entry is starred/unstarred
|
680 |
Â
*
|
681 |
-
* @
|
682 |
-
*
|
683 |
-
* @
|
Â
|
|
684 |
Â
*/
|
685 |
Â
public function callback_gform_update_is_starred( $lead_id, $status ) {
|
686 |
Â
$lead = $this->get_lead( $lead_id );
|
@@ -690,7 +816,7 @@ class Connector_GravityForms extends Connector {
|
|
690 |
Â
|
691 |
Â
$this->log(
|
692 |
Â
sprintf(
|
693 |
-
|
694 |
Â
__( 'Entry #%1$d %2$s on form #%3$d ("%4$s")', 'stream' ),
|
695 |
Â
$lead_id,
|
696 |
Â
$status,
|
@@ -712,8 +838,9 @@ class Connector_GravityForms extends Connector {
|
|
712 |
Â
/**
|
713 |
Â
* Callback fired when a form is deleted
|
714 |
Â
*
|
715 |
-
* @
|
716 |
-
*
|
Â
|
|
717 |
Â
*/
|
718 |
Â
public function callback_gform_before_delete_form( $form_id ) {
|
719 |
Â
$this->log_form_action( $form_id, 'deleted' );
|
@@ -722,8 +849,9 @@ class Connector_GravityForms extends Connector {
|
|
722 |
Â
/**
|
723 |
Â
* Callback fired when a form is trashed
|
724 |
Â
*
|
725 |
-
* @
|
726 |
-
*
|
Â
|
|
727 |
Â
*/
|
728 |
Â
public function callback_gform_post_form_trashed( $form_id ) {
|
729 |
Â
$this->log_form_action( $form_id, 'trashed' );
|
@@ -732,8 +860,9 @@ class Connector_GravityForms extends Connector {
|
|
732 |
Â
/**
|
733 |
Â
* Callback fired when a form is restored
|
734 |
Â
*
|
735 |
-
* @
|
736 |
-
*
|
Â
|
|
737 |
Â
*/
|
738 |
Â
public function callback_gform_post_form_restored( $form_id ) {
|
739 |
Â
$this->log_form_action( $form_id, 'untrashed' );
|
@@ -742,8 +871,9 @@ class Connector_GravityForms extends Connector {
|
|
742 |
Â
/**
|
743 |
Â
* Callback fired when a form is activated
|
744 |
Â
*
|
745 |
-
* @
|
746 |
-
*
|
Â
|
|
747 |
Â
*/
|
748 |
Â
public function callback_gform_post_form_activated( $form_id ) {
|
749 |
Â
$this->log_form_action( $form_id, 'activated' );
|
@@ -752,8 +882,9 @@ class Connector_GravityForms extends Connector {
|
|
752 |
Â
/**
|
753 |
Â
* Callback fired when a form is deactivated
|
754 |
Â
*
|
755 |
-
* @
|
756 |
-
*
|
Â
|
|
757 |
Â
*/
|
758 |
Â
public function callback_gform_post_form_deactivated( $form_id ) {
|
759 |
Â
$this->log_form_action( $form_id, 'deactivated' );
|
@@ -762,8 +893,9 @@ class Connector_GravityForms extends Connector {
|
|
762 |
Â
/**
|
763 |
Â
* Callback fired when a form is duplicated
|
764 |
Â
*
|
765 |
-
* @
|
766 |
-
*
|
Â
|
|
767 |
Â
*/
|
768 |
Â
public function callback_gform_post_form_duplicated( $form_id ) {
|
769 |
Â
$this->log_form_action( $form_id, 'duplicated' );
|
@@ -772,8 +904,9 @@ class Connector_GravityForms extends Connector {
|
|
772 |
Â
/**
|
773 |
Â
* Callback fired when a form's views are reset
|
774 |
Â
*
|
775 |
-
* @
|
776 |
-
*
|
Â
|
|
777 |
Â
*/
|
778 |
Â
public function callback_gform_post_form_views_deleted( $form_id ) {
|
779 |
Â
$this->log_form_action( $form_id, 'views_deleted' );
|
@@ -782,9 +915,8 @@ class Connector_GravityForms extends Connector {
|
|
782 |
Â
/**
|
783 |
Â
* Track status change of forms
|
784 |
Â
*
|
785 |
-
* @param int $form_id
|
786 |
-
* @param string $action
|
787 |
-
* @return void
|
788 |
Â
*/
|
789 |
Â
public function log_form_action( $form_id, $action ) {
|
790 |
Â
$form = $this->get_form( $form_id );
|
@@ -805,7 +937,7 @@ class Connector_GravityForms extends Connector {
|
|
805 |
Â
|
806 |
Â
$this->log(
|
807 |
Â
sprintf(
|
808 |
-
|
809 |
Â
__( 'Form #%1$d ("%2$s") %3$s', 'stream' ),
|
810 |
Â
$form_id,
|
811 |
Â
$form['title'],
|
@@ -825,8 +957,7 @@ class Connector_GravityForms extends Connector {
|
|
825 |
Â
/**
|
826 |
Â
* Helper function to get a single entry
|
827 |
Â
*
|
828 |
-
* @param
|
829 |
-
* @return array
|
830 |
Â
*/
|
831 |
Â
private function get_lead( $lead_id ) {
|
832 |
Â
return \GFFormsModel::get_lead( $lead_id );
|
@@ -835,8 +966,7 @@ class Connector_GravityForms extends Connector {
|
|
835 |
Â
/**
|
836 |
Â
* Helper function to get a single form
|
837 |
Â
*
|
838 |
-
* @param
|
839 |
-
* @return array
|
840 |
Â
*/
|
841 |
Â
private function get_form( $form_id ) {
|
842 |
Â
return \GFFormsModel::get_form_meta( $form_id );
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for Gravity Forms
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_GravityForms
|
12 |
+
*/
|
13 |
Â
class Connector_GravityForms extends Connector {
|
14 |
Â
/**
|
15 |
Â
* Connector slug
|
139 |
Â
*
|
140 |
Â
* @filter wp_stream_action_links_{connector}
|
141 |
Â
*
|
142 |
+
* @param array $links Previous links registered.
|
143 |
+
* @param object $record Stream record.
|
144 |
Â
*
|
145 |
Â
* @return array Action links
|
146 |
Â
*/
|
185 |
Â
return $links;
|
186 |
Â
}
|
187 |
Â
|
188 |
+
/**
|
189 |
+
* Register all context hooks
|
190 |
+
*/
|
191 |
Â
public function register() {
|
192 |
Â
parent::register();
|
193 |
Â
|
217 |
Â
/**
|
218 |
Â
* Track Create/Update actions on Forms
|
219 |
Â
*
|
220 |
+
* @param array $form Form data.
|
221 |
+
* @param bool $is_new Is this a new form?.
|
Â
|
|
222 |
Â
*/
|
223 |
Â
public function callback_gform_after_save_form( $form, $is_new ) {
|
224 |
Â
$title = $form['title'];
|
226 |
Â
|
227 |
Â
$this->log(
|
228 |
Â
sprintf(
|
229 |
+
/* translators: %1$s a form title, %2$s a status (e.g. "Contact Form", "created") */
|
230 |
Â
__( '"%1$s" form %2$s', 'stream' ),
|
231 |
Â
$title,
|
232 |
Â
$is_new ? esc_html__( 'created', 'stream' ) : esc_html__( 'updated', 'stream' )
|
245 |
Â
/**
|
246 |
Â
* Track saving form confirmations
|
247 |
Â
*
|
248 |
+
* @param array $confirmation Confirmation data.
|
249 |
+
* @param array $form Form data.
|
250 |
+
* @param bool $is_new Is this a new form?.
|
Â
|
|
251 |
Â
*/
|
252 |
Â
public function callback_gform_pre_confirmation_save( $confirmation, $form, $is_new = true ) {
|
253 |
Â
if ( ! isset( $is_new ) ) {
|
256 |
Â
|
257 |
Â
$this->log(
|
258 |
Â
sprintf(
|
259 |
+
/* translators: %1$s: a confirmation name, %2$s: a status, %3$s: a form title (e.g. "Email", "created", "Contact Form") */
|
260 |
Â
__( '"%1$s" confirmation %2$s for "%3$s"', 'stream' ),
|
261 |
Â
$confirmation['name'],
|
262 |
Â
$is_new ? esc_html__( 'created', 'stream' ) : esc_html__( 'updated', 'stream' ),
|
277 |
Â
/**
|
278 |
Â
* Track saving form notifications
|
279 |
Â
*
|
280 |
+
* @param array $notification Notification data.
|
281 |
+
* @param array $form Form data.
|
282 |
+
* @param bool $is_new Is this a new form?.
|
283 |
Â
* @return array
|
284 |
Â
*/
|
285 |
Â
public function callback_gform_pre_notification_save( $notification, $form, $is_new = true ) {
|
289 |
Â
|
290 |
Â
$this->log(
|
291 |
Â
sprintf(
|
292 |
+
/* translators: %1$s: a notification name, %2$s: a status, %3$s: a form title (e.g. "Email", "created", "Contact Form") */
|
293 |
Â
__( '"%1$s" notification %2$s for "%3$s"', 'stream' ),
|
294 |
Â
$notification['name'],
|
295 |
Â
$is_new ? esc_html__( 'created', 'stream' ) : esc_html__( 'updated', 'stream' ),
|
310 |
Â
/**
|
311 |
Â
* Track deletion of notifications
|
312 |
Â
*
|
313 |
+
* @param array $notification Notification data.
|
314 |
+
* @param array $form Form data.
|
Â
|
|
315 |
Â
*/
|
316 |
Â
public function callback_gform_pre_notification_deleted( $notification, $form ) {
|
317 |
Â
$this->log(
|
318 |
Â
sprintf(
|
319 |
+
/* translators: %1$s: a notification name, %2$s: a form title (e.g. "Email", "Contact Form") */
|
320 |
Â
__( '"%1$s" notification deleted from "%2$s"', 'stream' ),
|
321 |
Â
$notification['name'],
|
322 |
Â
$form['title']
|
334 |
Â
/**
|
335 |
Â
* Track deletion of confirmations
|
336 |
Â
*
|
337 |
+
* @param array $confirmation Confirmation data.
|
338 |
+
* @param array $form Form data.
|
Â
|
|
339 |
Â
*/
|
340 |
Â
public function callback_gform_pre_confirmation_deleted( $confirmation, $form ) {
|
341 |
Â
$this->log(
|
342 |
Â
sprintf(
|
343 |
+
/* translators: %1$s: a confirmation name, %2$s: a form title (e.g. "Email", "Contact Form") */
|
344 |
Â
__( '"%1$s" confirmation deleted from "%2$s"', 'stream' ),
|
345 |
Â
$confirmation['name'],
|
346 |
Â
$form['title']
|
358 |
Â
/**
|
359 |
Â
* Track status change of confirmations
|
360 |
Â
*
|
361 |
+
* @param array $confirmation Confirmation data.
|
362 |
+
* @param array $form Form data.
|
363 |
+
* @param bool $is_active Is this form active?.
|
Â
|
|
364 |
Â
*/
|
365 |
Â
public function callback_gform_confirmation_status( $confirmation, $form, $is_active ) {
|
366 |
Â
$this->log(
|
367 |
Â
sprintf(
|
368 |
+
/* translators: %1$s: a confirmation name, %2$s: a status, %3$s: a form title (e.g. "Email", "activated", "Contact Form") */
|
369 |
Â
__( '"%1$s" confirmation %2$s from "%3$s"', 'stream' ),
|
370 |
Â
$confirmation['name'],
|
371 |
Â
$is_active ? esc_html__( 'activated', 'stream' ) : esc_html__( 'deactivated', 'stream' ),
|
385 |
Â
/**
|
386 |
Â
* Track status change of notifications
|
387 |
Â
*
|
388 |
+
* @param array $notification Notification data.
|
389 |
+
* @param array $form Form data.
|
390 |
+
* @param bool $is_active Is this form active?.
|
Â
|
|
391 |
Â
*/
|
392 |
Â
public function callback_gform_notification_status( $notification, $form, $is_active ) {
|
393 |
Â
$this->log(
|
394 |
Â
sprintf(
|
395 |
+
/* translators: %1$s: a notification name, %2$s: a status, %3$s: a form title (e.g. "Email", "activated", "Contact Form") */
|
396 |
Â
__( '"%1$s" notification %2$s from "%3$s"', 'stream' ),
|
397 |
Â
$notification['name'],
|
398 |
Â
$is_active ? esc_html__( 'activated', 'stream' ) : esc_html__( 'deactivated', 'stream' ),
|
409 |
Â
);
|
410 |
Â
}
|
411 |
Â
|
412 |
+
/**
|
413 |
+
* Track GravityForms-specific option changes.
|
414 |
+
*
|
415 |
+
* @param string $option Option key.
|
416 |
+
* @param string $old Old value.
|
417 |
+
* @param string $new New value.
|
418 |
+
*/
|
419 |
Â
public function callback_update_option( $option, $old, $new ) {
|
420 |
Â
$this->check( $option, $old, $new );
|
421 |
Â
}
|
422 |
Â
|
423 |
+
/**
|
424 |
+
* Track GravityForms-specific option creations.
|
425 |
+
*
|
426 |
+
* @param string $option Option key.
|
427 |
+
* @param string $val Value.
|
428 |
+
*/
|
429 |
Â
public function callback_add_option( $option, $val ) {
|
430 |
Â
$this->check( $option, null, $val );
|
431 |
Â
}
|
432 |
Â
|
433 |
+
/**
|
434 |
+
* Track GravityForms-specific option deletions.
|
435 |
+
*
|
436 |
+
* @param string $option Option key.
|
437 |
+
*/
|
438 |
Â
public function callback_delete_option( $option ) {
|
439 |
Â
$this->check( $option, null, null );
|
440 |
Â
}
|
441 |
Â
|
442 |
+
/**
|
443 |
+
* Track GravityForms-specific site option changes
|
444 |
+
*
|
445 |
+
* @param string $option Option key.
|
446 |
+
* @param string $old Old value.
|
447 |
+
* @param string $new New value.
|
448 |
+
*/
|
449 |
Â
public function callback_update_site_option( $option, $old, $new ) {
|
450 |
Â
$this->check( $option, $old, $new );
|
451 |
Â
}
|
452 |
Â
|
453 |
+
/**
|
454 |
+
* Track GravityForms-specific site option creations.
|
455 |
+
*
|
456 |
+
* @param string $option Option key.
|
457 |
+
* @param string $val Value.
|
458 |
+
*/
|
459 |
Â
public function callback_add_site_option( $option, $val ) {
|
460 |
Â
$this->check( $option, null, $val );
|
461 |
Â
}
|
462 |
Â
|
463 |
+
/**
|
464 |
+
* Track GravityForms-specific site option deletions.
|
465 |
+
*
|
466 |
+
* @param string $option Option key.
|
467 |
+
*/
|
468 |
Â
public function callback_delete_site_option( $option ) {
|
469 |
Â
$this->check( $option, null, null );
|
470 |
Â
}
|
471 |
Â
|
472 |
+
/**
|
473 |
+
* Logs GravityForms-specific (site) option activity.
|
474 |
+
*
|
475 |
+
* @param string $option Option key.
|
476 |
+
* @param string $old_value Old value.
|
477 |
+
* @param string $new_value New value.
|
478 |
+
*/
|
479 |
Â
public function check( $option, $old_value, $new_value ) {
|
480 |
Â
if ( ! array_key_exists( $option, $this->options ) ) {
|
481 |
Â
return;
|
489 |
Â
$context = isset( $data['context'] ) ? $data['context'] : 'settings';
|
490 |
Â
|
491 |
Â
$this->log(
|
492 |
+
/* translators: %s: a setting title (e.g. "Language") */
|
493 |
Â
__( '"%s" setting updated', 'stream' ),
|
494 |
Â
compact( 'option_title', 'option', 'old_value', 'new_value' ),
|
495 |
Â
null,
|
499 |
Â
}
|
500 |
Â
}
|
501 |
Â
|
502 |
+
/**
|
503 |
+
* Log GravityForm license key changes
|
504 |
+
*
|
505 |
+
* @param string $old_value Old license key.
|
506 |
+
* @param string $new_value New license key.
|
507 |
+
* @return void
|
508 |
+
*/
|
509 |
Â
public function check_rg_gforms_key( $old_value, $new_value ) {
|
510 |
Â
$is_update = ( $new_value && strlen( $new_value ) );
|
511 |
Â
$option = 'rg_gforms_key';
|
512 |
Â
|
513 |
Â
$this->log(
|
514 |
Â
sprintf(
|
515 |
+
/* translators: %s: a status (e.g. "updated") */
|
516 |
Â
__( 'Gravity Forms license key %s', 'stream' ),
|
517 |
Â
$is_update ? esc_html__( 'updated', 'stream' ) : esc_html__( 'deleted', 'stream' )
|
518 |
Â
),
|
523 |
Â
);
|
524 |
Â
}
|
525 |
Â
|
526 |
+
/**
|
527 |
+
* Logs form entry exports.
|
528 |
+
*
|
529 |
+
* @action gform_post_export_entries
|
530 |
+
*
|
531 |
+
* @param object $form Form data.
|
532 |
+
* @param string $start_date Form start date.
|
533 |
+
* @param string $end_date Form completion date.
|
534 |
+
* @param array $fields Form fields data.
|
535 |
+
*/
|
536 |
Â
public function callback_gform_post_export_entries( $form, $start_date, $end_date, $fields ) {
|
537 |
Â
unset( $fields );
|
538 |
Â
$this->log(
|
539 |
+
/* translators: %s: a form title (e.g. "Contact Form") */
|
540 |
Â
__( '"%s" form entries exported', 'stream' ),
|
541 |
Â
array(
|
542 |
Â
'form_title' => $form['title'],
|
550 |
Â
);
|
551 |
Â
}
|
552 |
Â
|
553 |
+
/**
|
554 |
+
* Logs form imports.
|
555 |
+
*
|
556 |
+
* @action gform_forms_post_import
|
557 |
+
*
|
558 |
+
* @param array $forms List of form data.
|
559 |
+
*/
|
560 |
Â
public function callback_gform_forms_post_import( $forms ) {
|
561 |
Â
$forms_total = count( $forms );
|
562 |
Â
$forms_ids = wp_list_pluck( $forms, 'id' );
|
563 |
Â
$forms_titles = wp_list_pluck( $forms, 'title' );
|
564 |
Â
|
565 |
Â
$this->log(
|
566 |
+
/* translators: %d: a number of forms (e.g. "42") */
|
567 |
Â
_n( '%d form imported', '%d forms imported', $forms_total, 'stream' ),
|
568 |
Â
array(
|
569 |
Â
'count' => $forms_total,
|
576 |
Â
);
|
577 |
Â
}
|
578 |
Â
|
579 |
+
/**
|
580 |
+
* Logs form exports
|
581 |
+
*
|
582 |
+
* @action gform_export_separator
|
583 |
+
*
|
584 |
+
* @param string $dummy Unused.
|
585 |
+
* @param int $form_id Form ID.
|
586 |
+
*/
|
587 |
Â
public function callback_gform_export_separator( $dummy, $form_id ) {
|
588 |
Â
$form = $this->get_form( $form_id );
|
589 |
Â
|
590 |
Â
$this->log(
|
591 |
+
/* translators: %s: a form title (e.g. "Contact Form") */
|
592 |
Â
__( '"%s" form exported', 'stream' ),
|
593 |
Â
array(
|
594 |
Â
'form_title' => $form['title'],
|
602 |
Â
return $dummy;
|
603 |
Â
}
|
604 |
Â
|
605 |
+
/**
|
606 |
+
* Log bulk form exports
|
607 |
+
*
|
608 |
+
* @param string $dummy Unused.
|
609 |
+
* @param array $forms Form data.
|
610 |
+
*/
|
611 |
Â
public function callback_gform_export_options( $dummy, $forms ) {
|
612 |
Â
$ids = wp_list_pluck( $forms, 'id' );
|
613 |
Â
$titles = wp_list_pluck( $forms, 'title' );
|
614 |
Â
|
615 |
Â
$this->log(
|
616 |
+
/* translators: %d: a number of forms (e.g. "42") */
|
617 |
Â
_n( 'Export process started for %d form', 'Export process started for %d forms', count( $forms ), 'stream' ),
|
618 |
Â
array(
|
619 |
Â
'count' => count( $forms ),
|
628 |
Â
return $dummy;
|
629 |
Â
}
|
630 |
Â
|
631 |
+
/**
|
632 |
+
* Logs lead deletions.
|
633 |
+
*
|
634 |
+
* @action gform_delete_lead
|
635 |
+
*
|
636 |
+
* @param int $lead_id Lead ID.
|
637 |
+
* @return void
|
638 |
+
*/
|
639 |
Â
public function callback_gform_delete_lead( $lead_id ) {
|
640 |
Â
$lead = $this->get_lead( $lead_id );
|
641 |
Â
$form = $this->get_form( $lead['form_id'] );
|
642 |
Â
|
643 |
Â
$this->log(
|
644 |
+
/* translators: %1$d: to an ID, %2$s: a form title (e.g. "42", "Contact Form") */
|
645 |
Â
__( 'Lead #%1$d from "%2$s" deleted', 'stream' ),
|
646 |
Â
array(
|
647 |
Â
'lead_id' => $lead_id,
|
654 |
Â
);
|
655 |
Â
}
|
656 |
Â
|
657 |
+
/**
|
658 |
+
* Logs note creation on lead.
|
659 |
+
*
|
660 |
+
* @action gform_post_note_added
|
661 |
+
*
|
662 |
+
* @param int $note_id Note ID.
|
663 |
+
* @param int $lead_id Lead ID.
|
664 |
+
* @param int $user_id User ID of note author.
|
665 |
+
* @param string $user_name Username of note author.
|
666 |
+
* @param string $note Note object.
|
667 |
+
* @param string $note_type Note type.
|
668 |
+
*/
|
669 |
Â
public function callback_gform_post_note_added( $note_id, $lead_id, $user_id, $user_name, $note, $note_type ) {
|
670 |
Â
unset( $user_id );
|
671 |
Â
unset( $user_name );
|
676 |
Â
$form = $this->get_form( $lead['form_id'] );
|
677 |
Â
|
678 |
Â
$this->log(
|
679 |
+
/* translators: %1$d: an ID, %2$d: another ID, %3$s: a form title (e.g. "42", "7", "Contact Form") */
|
680 |
Â
__( 'Note #%1$d added to lead #%2$d on "%3$s" form', 'stream' ),
|
681 |
Â
array(
|
682 |
Â
'note_id' => $note_id,
|
690 |
Â
);
|
691 |
Â
}
|
692 |
Â
|
693 |
+
/**
|
694 |
+
* Logs note deletion
|
695 |
+
*
|
696 |
+
* @action gform_pre_note_deleted
|
697 |
+
*
|
698 |
+
* @param int $note_id Note ID.
|
699 |
+
* @param int $lead_id Lead ID.
|
700 |
+
*/
|
701 |
Â
public function callback_gform_pre_note_deleted( $note_id, $lead_id ) {
|
702 |
Â
$lead = $this->get_lead( $lead_id );
|
703 |
Â
$form = $this->get_form( $lead['form_id'] );
|
704 |
Â
|
705 |
Â
$this->log(
|
706 |
+
/* translators: %2$d an ID, another ID, and a form title (e.g. "42", "7", "Contact Form") */
|
707 |
Â
__( 'Note #%1$d deleted from lead #%2$d on "%3$s" form', 'stream' ),
|
708 |
Â
array(
|
709 |
Â
'note_id' => $note_id,
|
717 |
Â
);
|
718 |
Â
}
|
719 |
Â
|
720 |
+
/**
|
721 |
+
* Logs form status updates.
|
722 |
+
*
|
723 |
+
* @action gform_update_status
|
724 |
+
*
|
725 |
+
* @param int $lead_id Lead ID.
|
726 |
+
* @param string $status New form status.
|
727 |
+
* @param string $prev Old form status.
|
728 |
+
*/
|
729 |
Â
public function callback_gform_update_status( $lead_id, $status, $prev = '' ) {
|
730 |
Â
$lead = $this->get_lead( $lead_id );
|
731 |
Â
$form = $this->get_form( $lead['form_id'] );
|
747 |
Â
|
748 |
Â
$this->log(
|
749 |
Â
sprintf(
|
750 |
+
/* translators: %1$d: an ID, %2$s: a status, %3$s: a form title (e.g. "42", "activated", "Contact Form") */
|
751 |
Â
__( 'Lead #%1$d %2$s on "%3$s" form', 'stream' ),
|
752 |
Â
$lead_id,
|
753 |
Â
$actions[ $status ],
|
769 |
Â
/**
|
770 |
Â
* Callback fired when an entry is read/unread
|
771 |
Â
*
|
772 |
+
* @action update_is_read
|
773 |
+
*
|
774 |
+
* @param int $lead_id Lead ID.
|
775 |
+
* @param string $status Status.
|
776 |
Â
*/
|
777 |
Â
public function callback_gform_update_is_read( $lead_id, $status ) {
|
778 |
Â
$lead = $this->get_lead( $lead_id );
|
781 |
Â
|
782 |
Â
$this->log(
|
783 |
Â
sprintf(
|
784 |
+
/* translators: %1$d: a lead ID, %2$s: a status, %3$s: a form ID, %4$s: a form title (e.g. "42", "unread", "Contact Form") */
|
785 |
Â
__( 'Entry #%1$d marked as %2$s on form #%3$d ("%4$s")', 'stream' ),
|
786 |
Â
$lead_id,
|
787 |
Â
$status,
|
803 |
Â
/**
|
804 |
Â
* Callback fired when an entry is starred/unstarred
|
805 |
Â
*
|
806 |
+
* @action gform_update_is_starred
|
807 |
+
*
|
808 |
+
* @param int $lead_id Lead ID.
|
809 |
+
* @param int $status Status.
|
810 |
Â
*/
|
811 |
Â
public function callback_gform_update_is_starred( $lead_id, $status ) {
|
812 |
Â
$lead = $this->get_lead( $lead_id );
|
816 |
Â
|
817 |
Â
$this->log(
|
818 |
Â
sprintf(
|
819 |
+
/* translators: %1$d: an ID, %2$s: a status, %3$d: a form title (e.g. "42", "starred", "Contact Form") */
|
820 |
Â
__( 'Entry #%1$d %2$s on form #%3$d ("%4$s")', 'stream' ),
|
821 |
Â
$lead_id,
|
822 |
Â
$status,
|
838 |
Â
/**
|
839 |
Â
* Callback fired when a form is deleted
|
840 |
Â
*
|
841 |
+
* @action gform_before_delete_form
|
842 |
+
*
|
843 |
+
* @param int $form_id Form ID.
|
844 |
Â
*/
|
845 |
Â
public function callback_gform_before_delete_form( $form_id ) {
|
846 |
Â
$this->log_form_action( $form_id, 'deleted' );
|
849 |
Â
/**
|
850 |
Â
* Callback fired when a form is trashed
|
851 |
Â
*
|
852 |
+
* @action gform_post_form_trashed
|
853 |
+
*
|
854 |
+
* @param int $form_id Form ID.
|
855 |
Â
*/
|
856 |
Â
public function callback_gform_post_form_trashed( $form_id ) {
|
857 |
Â
$this->log_form_action( $form_id, 'trashed' );
|
860 |
Â
/**
|
861 |
Â
* Callback fired when a form is restored
|
862 |
Â
*
|
863 |
+
* @action gform_post_form_restored
|
864 |
+
*
|
865 |
+
* @param int $form_id Form ID.
|
866 |
Â
*/
|
867 |
Â
public function callback_gform_post_form_restored( $form_id ) {
|
868 |
Â
$this->log_form_action( $form_id, 'untrashed' );
|
871 |
Â
/**
|
872 |
Â
* Callback fired when a form is activated
|
873 |
Â
*
|
874 |
+
* @action gform_post_form_activated
|
875 |
+
*
|
876 |
+
* @param int $form_id Form ID.
|
877 |
Â
*/
|
878 |
Â
public function callback_gform_post_form_activated( $form_id ) {
|
879 |
Â
$this->log_form_action( $form_id, 'activated' );
|
882 |
Â
/**
|
883 |
Â
* Callback fired when a form is deactivated
|
884 |
Â
*
|
885 |
+
* @action gform_post_form_deactivated
|
886 |
+
*
|
887 |
+
* @param int $form_id Form ID.
|
888 |
Â
*/
|
889 |
Â
public function callback_gform_post_form_deactivated( $form_id ) {
|
890 |
Â
$this->log_form_action( $form_id, 'deactivated' );
|
893 |
Â
/**
|
894 |
Â
* Callback fired when a form is duplicated
|
895 |
Â
*
|
896 |
+
* @action gform_post_form_duplicated
|
897 |
+
*
|
898 |
+
* @param int $form_id Form ID.
|
899 |
Â
*/
|
900 |
Â
public function callback_gform_post_form_duplicated( $form_id ) {
|
901 |
Â
$this->log_form_action( $form_id, 'duplicated' );
|
904 |
Â
/**
|
905 |
Â
* Callback fired when a form's views are reset
|
906 |
Â
*
|
907 |
+
* @action gform_post_form_views_deleted
|
908 |
+
*
|
909 |
+
* @param int $form_id Form ID.
|
910 |
Â
*/
|
911 |
Â
public function callback_gform_post_form_views_deleted( $form_id ) {
|
912 |
Â
$this->log_form_action( $form_id, 'views_deleted' );
|
915 |
Â
/**
|
916 |
Â
* Track status change of forms
|
917 |
Â
*
|
918 |
+
* @param int $form_id Form ID.
|
919 |
+
* @param string $action Action.
|
Â
|
|
920 |
Â
*/
|
921 |
Â
public function log_form_action( $form_id, $action ) {
|
922 |
Â
$form = $this->get_form( $form_id );
|
937 |
Â
|
938 |
Â
$this->log(
|
939 |
Â
sprintf(
|
940 |
+
/* translators: %1$d: an ID, %2$s: a form title, %3$s: a status (e.g. "42", "Contact Form", "Activated") */
|
941 |
Â
__( 'Form #%1$d ("%2$s") %3$s', 'stream' ),
|
942 |
Â
$form_id,
|
943 |
Â
$form['title'],
|
957 |
Â
/**
|
958 |
Â
* Helper function to get a single entry
|
959 |
Â
*
|
960 |
+
* @param int $lead_id Lead ID.
|
Â
|
|
961 |
Â
*/
|
962 |
Â
private function get_lead( $lead_id ) {
|
963 |
Â
return \GFFormsModel::get_lead( $lead_id );
|
966 |
Â
/**
|
967 |
Â
* Helper function to get a single form
|
968 |
Â
*
|
969 |
+
* @param int $form_id Form ID.
|
Â
|
|
970 |
Â
*/
|
971 |
Â
private function get_form( $form_id ) {
|
972 |
Â
return \GFFormsModel::get_form_meta( $form_id );
|
connectors/class-connector-installer.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_Installer extends Connector {
|
5 |
Â
|
6 |
Â
/**
|
@@ -16,12 +25,12 @@ class Connector_Installer extends Connector {
|
|
16 |
Â
* @var array
|
17 |
Â
*/
|
18 |
Â
public $actions = array(
|
19 |
-
'upgrader_process_complete', // plugins::installed | themes::installed
|
20 |
-
'activate_plugin', // plugins::activated
|
21 |
-
'deactivate_plugin', // plugins::deactivated
|
22 |
-
'switch_theme', // themes::activated
|
23 |
-
'delete_site_transient_update_themes', // themes::deleted
|
24 |
-
'pre_option_uninstall_plugins', // plugins::deleted
|
25 |
Â
'pre_set_site_transient_update_plugins',
|
26 |
Â
'_core_updated_successfully',
|
27 |
Â
);
|
@@ -75,8 +84,8 @@ class Connector_Installer extends Connector {
|
|
75 |
Â
*
|
76 |
Â
* @filter wp_stream_action_links_{connector}
|
77 |
Â
*
|
78 |
-
* @param array $links
|
79 |
-
* @param object $record
|
80 |
Â
*
|
81 |
Â
* @return array Action links
|
82 |
Â
*/
|
@@ -112,10 +121,10 @@ class Connector_Installer extends Connector {
|
|
112 |
Â
/**
|
113 |
Â
* Log plugin installations
|
114 |
Â
*
|
115 |
-
* @action
|
116 |
Â
*
|
117 |
-
* @param \WP_Upgrader $upgrader
|
118 |
-
* @param array $extra
|
119 |
Â
*
|
120 |
Â
* @return bool
|
121 |
Â
*/
|
@@ -130,7 +139,7 @@ class Connector_Installer extends Connector {
|
|
130 |
Â
list( $error ) = reset( $errors );
|
131 |
Â
}
|
132 |
Â
|
133 |
-
// This would have failed down the road anyway
|
134 |
Â
if ( ! isset( $extra['type'] ) ) {
|
135 |
Â
return false;
|
136 |
Â
}
|
@@ -154,7 +163,7 @@ class Connector_Installer extends Connector {
|
|
154 |
Â
$slug = $upgrader->result['destination_name'];
|
155 |
Â
$name = $data['Name'];
|
156 |
Â
$version = $data['Version'];
|
157 |
-
} else { // theme
|
158 |
Â
$slug = $upgrader->theme_info();
|
159 |
Â
|
160 |
Â
if ( ! $slug ) {
|
@@ -169,7 +178,7 @@ class Connector_Installer extends Connector {
|
|
169 |
Â
}
|
170 |
Â
|
171 |
Â
$action = 'installed';
|
172 |
-
|
173 |
Â
$message = _x(
|
174 |
Â
'Installed %1$s: %2$s %3$s',
|
175 |
Â
'Plugin/theme installation. 1: Type (plugin/theme), 2: Plugin/theme name, 3: Plugin/theme version',
|
@@ -179,7 +188,7 @@ class Connector_Installer extends Connector {
|
|
179 |
Â
$logs[] = compact( 'slug', 'name', 'version', 'message', 'action' );
|
180 |
Â
} elseif ( 'update' === $action ) {
|
181 |
Â
$action = 'updated';
|
182 |
-
|
183 |
Â
$message = _x(
|
184 |
Â
'Updated %1$s: %2$s %3$s',
|
185 |
Â
'Plugin/theme update. 1: Type (plugin/theme), 2: Plugin/theme name, 3: Plugin/theme version',
|
@@ -203,7 +212,7 @@ class Connector_Installer extends Connector {
|
|
203 |
Â
|
204 |
Â
$logs[] = compact( 'slug', 'name', 'old_version', 'version', 'message', 'action' );
|
205 |
Â
}
|
206 |
-
} else { // theme
|
207 |
Â
if ( isset( $extra['bulk'] ) && true === $extra['bulk'] ) {
|
208 |
Â
$slugs = $extra['themes'];
|
209 |
Â
} else {
|
@@ -252,13 +261,21 @@ class Connector_Installer extends Connector {
|
|
252 |
Â
return true;
|
253 |
Â
}
|
254 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
255 |
Â
public function callback_activate_plugin( $slug, $network_wide ) {
|
256 |
Â
$_plugins = $this->get_plugins();
|
257 |
Â
$name = $_plugins[ $slug ]['Name'];
|
258 |
Â
$network_wide = $network_wide ? esc_html__( 'network wide', 'stream' ) : null;
|
259 |
Â
|
260 |
Â
$this->log(
|
261 |
-
|
262 |
Â
_x(
|
263 |
Â
'"%1$s" plugin activated %2$s',
|
264 |
Â
'1: Plugin name, 2: Single site or network wide',
|
@@ -271,13 +288,21 @@ class Connector_Installer extends Connector {
|
|
271 |
Â
);
|
272 |
Â
}
|
273 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
274 |
Â
public function callback_deactivate_plugin( $slug, $network_wide ) {
|
275 |
Â
$_plugins = $this->get_plugins();
|
276 |
Â
$name = $_plugins[ $slug ]['Name'];
|
277 |
Â
$network_wide = $network_wide ? esc_html__( 'network wide', 'stream' ) : null;
|
278 |
Â
|
279 |
Â
$this->log(
|
280 |
-
|
281 |
Â
_x(
|
282 |
Â
'"%1$s" plugin deactivated %2$s',
|
283 |
Â
'1: Plugin name, 2: Single site or network wide',
|
@@ -290,10 +315,16 @@ class Connector_Installer extends Connector {
|
|
290 |
Â
);
|
291 |
Â
}
|
292 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
293 |
Â
public function callback_switch_theme( $name, $theme ) {
|
294 |
Â
unset( $theme );
|
295 |
Â
$this->log(
|
296 |
-
|
297 |
Â
__( '"%s" theme activated', 'stream' ),
|
298 |
Â
compact( 'name' ),
|
299 |
Â
null,
|
@@ -303,10 +334,17 @@ class Connector_Installer extends Connector {
|
|
303 |
Â
}
|
304 |
Â
|
305 |
Â
/**
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
306 |
Â
* @todo Core needs a delete_theme hook
|
307 |
Â
*/
|
308 |
Â
public function callback_delete_site_transient_update_themes() {
|
309 |
-
|
Â
|
|
Â
|
|
Â
|
|
310 |
Â
$delete_theme_call = null;
|
311 |
Â
|
312 |
Â
foreach ( $backtrace as $call ) {
|
@@ -321,10 +359,10 @@ class Connector_Installer extends Connector {
|
|
321 |
Â
}
|
322 |
Â
|
323 |
Â
$name = $delete_theme_call['args'][0];
|
324 |
-
// @todo Can we get the name of the theme? Or has it already been eliminated
|
325 |
Â
|
326 |
Â
$this->log(
|
327 |
-
|
328 |
Â
__( '"%s" theme deleted', 'stream' ),
|
329 |
Â
compact( 'name' ),
|
330 |
Â
null,
|
@@ -334,6 +372,10 @@ class Connector_Installer extends Connector {
|
|
334 |
Â
}
|
335 |
Â
|
336 |
Â
/**
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
337 |
Â
* @todo Core needs an uninstall_plugin hook
|
338 |
Â
* @todo This does not work in WP-CLI
|
339 |
Â
*/
|
@@ -365,7 +407,11 @@ class Connector_Installer extends Connector {
|
|
365 |
Â
}
|
366 |
Â
|
367 |
Â
/**
|
368 |
-
*
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
369 |
Â
*
|
370 |
Â
* @return mixed
|
371 |
Â
* @todo Core needs a delete_plugin hook
|
@@ -382,7 +428,7 @@ class Connector_Installer extends Connector {
|
|
382 |
Â
$network_wide = $data['Network'] ? esc_html__( 'network wide', 'stream' ) : '';
|
383 |
Â
|
384 |
Â
$this->log(
|
385 |
-
|
386 |
Â
__( '"%s" plugin deleted', 'stream' ),
|
387 |
Â
compact( 'name', 'plugin', 'network_wide' ),
|
388 |
Â
null,
|
@@ -396,6 +442,14 @@ class Connector_Installer extends Connector {
|
|
396 |
Â
return $value;
|
397 |
Â
}
|
398 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
399 |
Â
public function callback__core_updated_successfully( $new_version ) {
|
400 |
Â
global $pagenow, $wp_version;
|
401 |
Â
|
@@ -403,10 +457,10 @@ class Connector_Installer extends Connector {
|
|
403 |
Â
$auto_updated = ( 'update-core.php' !== $pagenow );
|
404 |
Â
|
405 |
Â
if ( $auto_updated ) {
|
406 |
-
|
407 |
Â
$message = esc_html__( 'WordPress auto-updated to %s', 'stream' );
|
408 |
Â
} else {
|
409 |
-
|
410 |
Â
$message = esc_html__( 'WordPress updated to %s', 'stream' );
|
411 |
Â
}
|
412 |
Â
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for installer
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_Installer
|
12 |
+
*/
|
13 |
Â
class Connector_Installer extends Connector {
|
14 |
Â
|
15 |
Â
/**
|
25 |
Â
* @var array
|
26 |
Â
*/
|
27 |
Â
public $actions = array(
|
28 |
+
'upgrader_process_complete', // plugins::installed | themes::installed.
|
29 |
+
'activate_plugin', // plugins::activated.
|
30 |
+
'deactivate_plugin', // plugins::deactivated.
|
31 |
+
'switch_theme', // themes::activated.
|
32 |
+
'delete_site_transient_update_themes', // themes::deleted.
|
33 |
+
'pre_option_uninstall_plugins', // plugins::deleted.
|
34 |
Â
'pre_set_site_transient_update_plugins',
|
35 |
Â
'_core_updated_successfully',
|
36 |
Â
);
|
84 |
Â
*
|
85 |
Â
* @filter wp_stream_action_links_{connector}
|
86 |
Â
*
|
87 |
+
* @param array $links Previous links registered.
|
88 |
+
* @param object $record Stream record.
|
89 |
Â
*
|
90 |
Â
* @return array Action links
|
91 |
Â
*/
|
121 |
Â
/**
|
122 |
Â
* Log plugin installations
|
123 |
Â
*
|
124 |
+
* @action upgrader_process_complete
|
125 |
Â
*
|
126 |
+
* @param \WP_Upgrader $upgrader Upgrader object.
|
127 |
+
* @param array $extra Extra plugin data.
|
128 |
Â
*
|
129 |
Â
* @return bool
|
130 |
Â
*/
|
139 |
Â
list( $error ) = reset( $errors );
|
140 |
Â
}
|
141 |
Â
|
142 |
+
// This would have failed down the road anyway.
|
143 |
Â
if ( ! isset( $extra['type'] ) ) {
|
144 |
Â
return false;
|
145 |
Â
}
|
163 |
Â
$slug = $upgrader->result['destination_name'];
|
164 |
Â
$name = $data['Name'];
|
165 |
Â
$version = $data['Version'];
|
166 |
+
} else { // theme.
|
167 |
Â
$slug = $upgrader->theme_info();
|
168 |
Â
|
169 |
Â
if ( ! $slug ) {
|
178 |
Â
}
|
179 |
Â
|
180 |
Â
$action = 'installed';
|
181 |
+
/* translators: %1$s: a plugin/theme type, %2$s: a plugin/theme name, %3$s: a plugin/theme version (e.g. "plugin", "Stream", "4.2") */
|
182 |
Â
$message = _x(
|
183 |
Â
'Installed %1$s: %2$s %3$s',
|
184 |
Â
'Plugin/theme installation. 1: Type (plugin/theme), 2: Plugin/theme name, 3: Plugin/theme version',
|
188 |
Â
$logs[] = compact( 'slug', 'name', 'version', 'message', 'action' );
|
189 |
Â
} elseif ( 'update' === $action ) {
|
190 |
Â
$action = 'updated';
|
191 |
+
/* translators: %1$s: a plugin/theme type, %2$s: a plugin/theme name, %3$s: a plugin/theme version (e.g. "plugin", "Stream", "4.2") */
|
192 |
Â
$message = _x(
|
193 |
Â
'Updated %1$s: %2$s %3$s',
|
194 |
Â
'Plugin/theme update. 1: Type (plugin/theme), 2: Plugin/theme name, 3: Plugin/theme version',
|
212 |
Â
|
213 |
Â
$logs[] = compact( 'slug', 'name', 'old_version', 'version', 'message', 'action' );
|
214 |
Â
}
|
215 |
+
} else { // theme.
|
216 |
Â
if ( isset( $extra['bulk'] ) && true === $extra['bulk'] ) {
|
217 |
Â
$slugs = $extra['themes'];
|
218 |
Â
} else {
|
261 |
Â
return true;
|
262 |
Â
}
|
263 |
Â
|
264 |
+
/**
|
265 |
+
* Logs plugin activations
|
266 |
+
*
|
267 |
+
* @action activate_plugin
|
268 |
+
*
|
269 |
+
* @param string $slug Plugin slug name.
|
270 |
+
* @param bool $network_wide Activated across the multi-site?.
|
271 |
+
*/
|
272 |
Â
public function callback_activate_plugin( $slug, $network_wide ) {
|
273 |
Â
$_plugins = $this->get_plugins();
|
274 |
Â
$name = $_plugins[ $slug ]['Name'];
|
275 |
Â
$network_wide = $network_wide ? esc_html__( 'network wide', 'stream' ) : null;
|
276 |
Â
|
277 |
Â
$this->log(
|
278 |
+
/* translators: %1$s: a plugin name, %2$s: whether it is on a single site or network wide (e.g. "Stream", "network wide") (a single site results in a blank string) */
|
279 |
Â
_x(
|
280 |
Â
'"%1$s" plugin activated %2$s',
|
281 |
Â
'1: Plugin name, 2: Single site or network wide',
|
288 |
Â
);
|
289 |
Â
}
|
290 |
Â
|
291 |
+
/**
|
292 |
+
* Logs plugin deactivations
|
293 |
+
*
|
294 |
+
* @action deactivate_plugin
|
295 |
+
*
|
296 |
+
* @param string $slug Plugin slug name.
|
297 |
+
* @param bool $network_wide Deactivated across the multi-site?.
|
298 |
+
*/
|
299 |
Â
public function callback_deactivate_plugin( $slug, $network_wide ) {
|
300 |
Â
$_plugins = $this->get_plugins();
|
301 |
Â
$name = $_plugins[ $slug ]['Name'];
|
302 |
Â
$network_wide = $network_wide ? esc_html__( 'network wide', 'stream' ) : null;
|
303 |
Â
|
304 |
Â
$this->log(
|
305 |
+
/* translators: %1$s: a plugin name, %2$s: whether it is on a single site or network wide (e.g. "Stream", "network wide") (a single site results in a blank string) */
|
306 |
Â
_x(
|
307 |
Â
'"%1$s" plugin deactivated %2$s',
|
308 |
Â
'1: Plugin name, 2: Single site or network wide',
|
315 |
Â
);
|
316 |
Â
}
|
317 |
Â
|
318 |
+
/**
|
319 |
+
* Logs theme activations.
|
320 |
+
*
|
321 |
+
* @param string $name Theme name.
|
322 |
+
* @param string $theme Unused.
|
323 |
+
*/
|
324 |
Â
public function callback_switch_theme( $name, $theme ) {
|
325 |
Â
unset( $theme );
|
326 |
Â
$this->log(
|
327 |
+
/* translators: %s: a theme name (e.g. "Twenty Seventeen") */
|
328 |
Â
__( '"%s" theme activated', 'stream' ),
|
329 |
Â
compact( 'name' ),
|
330 |
Â
null,
|
334 |
Â
}
|
335 |
Â
|
336 |
Â
/**
|
337 |
+
* Logs theme deletion.
|
338 |
+
*
|
339 |
+
* @action delete_site_transient_update_themes
|
340 |
+
*
|
341 |
Â
* @todo Core needs a delete_theme hook
|
342 |
Â
*/
|
343 |
Â
public function callback_delete_site_transient_update_themes() {
|
344 |
+
/**
|
345 |
+
* This is used as a hack to determine a theme was deleted.
|
346 |
+
*/
|
347 |
+
$backtrace = debug_backtrace(); // @codingStandardsIgnoreLine
|
348 |
Â
$delete_theme_call = null;
|
349 |
Â
|
350 |
Â
foreach ( $backtrace as $call ) {
|
359 |
Â
}
|
360 |
Â
|
361 |
Â
$name = $delete_theme_call['args'][0];
|
362 |
+
// @todo Can we get the name of the theme? Or has it already been eliminated.
|
363 |
Â
|
364 |
Â
$this->log(
|
365 |
+
/* translators: Placeholder refers to a theme name (e.g. "Twenty Seventeen") */
|
366 |
Â
__( '"%s" theme deleted', 'stream' ),
|
367 |
Â
compact( 'name' ),
|
368 |
Â
null,
|
372 |
Â
}
|
373 |
Â
|
374 |
Â
/**
|
375 |
+
* Logs plugins uninstallations.
|
376 |
+
*
|
377 |
+
* @action pre_option_uninstall_plugins
|
378 |
+
*
|
379 |
Â
* @todo Core needs an uninstall_plugin hook
|
380 |
Â
* @todo This does not work in WP-CLI
|
381 |
Â
*/
|
407 |
Â
}
|
408 |
Â
|
409 |
Â
/**
|
410 |
+
* Logs bulk plugin deletions.
|
411 |
+
*
|
412 |
+
* @filter pre_set_site_transient_update_plugins
|
413 |
+
*
|
414 |
+
* @param mixed $value Unused.
|
415 |
Â
*
|
416 |
Â
* @return mixed
|
417 |
Â
* @todo Core needs a delete_plugin hook
|
428 |
Â
$network_wide = $data['Network'] ? esc_html__( 'network wide', 'stream' ) : '';
|
429 |
Â
|
430 |
Â
$this->log(
|
431 |
+
/* translators: %s a plugin name (e.g. "Stream") */
|
432 |
Â
__( '"%s" plugin deleted', 'stream' ),
|
433 |
Â
compact( 'name', 'plugin', 'network_wide' ),
|
434 |
Â
null,
|
442 |
Â
return $value;
|
443 |
Â
}
|
444 |
Â
|
445 |
+
/**
|
446 |
+
* Logs WordPress core upgrades
|
447 |
+
*
|
448 |
+
* @action _core_updated_successfully
|
449 |
+
*
|
450 |
+
* @param string $new_version Version WordPress core has be upgraded to.
|
451 |
+
* @return void
|
452 |
+
*/
|
453 |
Â
public function callback__core_updated_successfully( $new_version ) {
|
454 |
Â
global $pagenow, $wp_version;
|
455 |
Â
|
457 |
Â
$auto_updated = ( 'update-core.php' !== $pagenow );
|
458 |
Â
|
459 |
Â
if ( $auto_updated ) {
|
460 |
+
/* translators: %s: a version number (e.g. "4.2") */
|
461 |
Â
$message = esc_html__( 'WordPress auto-updated to %s', 'stream' );
|
462 |
Â
} else {
|
463 |
+
/* translators: %s: a version number (e.g. "4.2") */
|
464 |
Â
$message = esc_html__( 'WordPress updated to %s', 'stream' );
|
465 |
Â
}
|
466 |
Â
|
connectors/class-connector-jetpack.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_Jetpack extends Connector {
|
5 |
Â
/**
|
6 |
Â
* Connector slug
|
@@ -133,8 +142,8 @@ class Connector_Jetpack extends Connector {
|
|
133 |
Â
*
|
134 |
Â
* @filter wp_stream_action_links_{connector}
|
135 |
Â
*
|
136 |
-
* @param array $links Previous links registered
|
137 |
-
* @param object $record
|
138 |
Â
*
|
139 |
Â
* @return array Action links
|
140 |
Â
*/
|
@@ -176,7 +185,7 @@ class Connector_Jetpack extends Connector {
|
|
176 |
Â
);
|
177 |
Â
}
|
178 |
Â
} elseif ( \Jetpack::is_module_active( str_replace( 'jetpack-', '', $record->context ) ) ) {
|
179 |
-
$slug = str_replace( 'jetpack-', '', $record->context ); // handling jetpack-comment anomaly
|
180 |
Â
|
181 |
Â
if ( apply_filters( 'jetpack_module_configurable_' . $slug, false ) ) {
|
182 |
Â
$links[ esc_html__( 'Configure module', 'stream' ) ] = \Jetpack::module_configuration_url( $slug );
|
@@ -187,6 +196,9 @@ class Connector_Jetpack extends Connector {
|
|
187 |
Â
return $links;
|
188 |
Â
}
|
189 |
Â
|
Â
|
|
Â
|
|
Â
|
|
190 |
Â
public function register() {
|
191 |
Â
parent::register();
|
192 |
Â
|
@@ -194,7 +206,7 @@ class Connector_Jetpack extends Connector {
|
|
194 |
Â
|
195 |
Â
$this->options = array(
|
196 |
Â
'jetpack_options' => null,
|
197 |
-
// Sharing module
|
198 |
Â
'hide_gplus' => null,
|
199 |
Â
'gplus_authors' => null,
|
200 |
Â
'sharing-options' => array(
|
@@ -206,22 +218,22 @@ class Connector_Jetpack extends Connector {
|
|
206 |
Â
'label' => esc_html__( 'Twitter site tag', 'stream' ),
|
207 |
Â
'context' => 'sharedaddy',
|
208 |
Â
),
|
209 |
-
// Stats module
|
210 |
Â
'stats_options' => array(
|
211 |
Â
'label' => esc_html__( 'WordPress.com Stats', 'stream' ),
|
212 |
Â
'context' => 'stats',
|
213 |
Â
),
|
214 |
-
// Comments
|
215 |
Â
'jetpack_comment_form_color_scheme' => array(
|
216 |
Â
'label' => esc_html__( 'Color Scheme', 'stream' ),
|
217 |
Â
'context' => 'jetpack-comments',
|
218 |
Â
),
|
219 |
-
// Likes
|
220 |
Â
'disabled_likes' => array(
|
221 |
Â
'label' => esc_html__( 'WP.com Site-wide Likes', 'stream' ),
|
222 |
Â
'context' => 'likes',
|
223 |
Â
),
|
224 |
-
// Mobile
|
225 |
Â
'wp_mobile_excerpt' => array(
|
226 |
Â
'label' => esc_html__( 'Excerpts appearance', 'stream' ),
|
227 |
Â
'context' => 'minileven',
|
@@ -233,7 +245,7 @@ class Connector_Jetpack extends Connector {
|
|
233 |
Â
);
|
234 |
Â
|
235 |
Â
$this->options_override = array(
|
236 |
-
// Carousel Module
|
237 |
Â
'carousel_background_color' => array(
|
238 |
Â
'label' => esc_html__( 'Background color', 'stream' ),
|
239 |
Â
'context' => 'carousel',
|
@@ -242,7 +254,7 @@ class Connector_Jetpack extends Connector {
|
|
242 |
Â
'label' => esc_html__( 'Metadata', 'stream' ),
|
243 |
Â
'context' => 'carousel',
|
244 |
Â
),
|
245 |
-
// Subscriptions
|
246 |
Â
'stb_enabled' => array(
|
247 |
Â
'label' => esc_html__( 'Follow blog comment form button', 'stream' ),
|
248 |
Â
'context' => 'subscriptions',
|
@@ -251,22 +263,22 @@ class Connector_Jetpack extends Connector {
|
|
251 |
Â
'label' => esc_html__( 'Follow comments form button', 'stream' ),
|
252 |
Â
'context' => 'subscriptions',
|
253 |
Â
),
|
254 |
-
// Jetpack comments
|
255 |
Â
'highlander_comment_form_prompt' => array(
|
256 |
Â
'label' => esc_html__( 'Greeting Text', 'stream' ),
|
257 |
Â
'context' => 'jetpack-comments',
|
258 |
Â
),
|
259 |
-
// Infinite Scroll
|
260 |
Â
'infinite_scroll_google_analytics' => array(
|
261 |
Â
'label' => esc_html__( 'Infinite Scroll Google Analytics', 'stream' ),
|
262 |
Â
'context' => 'infinite-scroll',
|
263 |
Â
),
|
264 |
-
// Protect
|
265 |
Â
'jetpack_protect_blocked_attempts' => array(
|
266 |
Â
'label' => esc_html__( 'Blocked Attempts', 'stream' ),
|
267 |
Â
'context' => 'protect',
|
268 |
Â
),
|
269 |
-
// SSO
|
270 |
Â
'jetpack_sso_require_two_step' => array(
|
271 |
Â
'label' => esc_html__( 'Require Two-Step Authentication', 'stream' ),
|
272 |
Â
'context' => 'sso',
|
@@ -275,7 +287,7 @@ class Connector_Jetpack extends Connector {
|
|
275 |
Â
'label' => esc_html__( 'Match by Email', 'stream' ),
|
276 |
Â
'context' => 'sso',
|
277 |
Â
),
|
278 |
-
// Related posts
|
279 |
Â
'jetpack_relatedposts' => array(
|
280 |
Â
'show_headline' => array(
|
281 |
Â
'label' => esc_html__( 'Show Related Posts Headline', 'stream' ),
|
@@ -286,7 +298,7 @@ class Connector_Jetpack extends Connector {
|
|
286 |
Â
'context' => 'related-posts',
|
287 |
Â
),
|
288 |
Â
),
|
289 |
-
// Site verification
|
290 |
Â
'verification_services_codes' => array(
|
291 |
Â
'google' => array(
|
292 |
Â
'label' => esc_html__( 'Google Webmaster Tools Token', 'stream' ),
|
@@ -301,7 +313,7 @@ class Connector_Jetpack extends Connector {
|
|
301 |
Â
'context' => 'verification-tools',
|
302 |
Â
),
|
303 |
Â
),
|
304 |
-
// Tiled galleries
|
305 |
Â
'tiled_galleries' => array(
|
306 |
Â
'label' => esc_html__( 'Tiled Galleries', 'stream' ),
|
307 |
Â
'context' => 'tiled-gallery',
|
@@ -316,7 +328,7 @@ class Connector_Jetpack extends Connector {
|
|
316 |
Â
* - Registration/Disconnection of blogs
|
317 |
Â
* - Authorization/unlinking of users
|
318 |
Â
*
|
319 |
-
* @param array $entry
|
320 |
Â
*/
|
321 |
Â
public function callback_jetpack_log_entry( array $entry ) {
|
322 |
Â
if ( isset( $entry['code'] ) ) {
|
@@ -343,7 +355,7 @@ class Connector_Jetpack extends Connector {
|
|
343 |
Â
$action = $method . 'd';
|
344 |
Â
$meta = compact( 'module_slug' );
|
345 |
Â
$message = sprintf(
|
346 |
-
|
347 |
Â
__( '%1$s module %2$s', 'stream' ),
|
348 |
Â
$module_name,
|
349 |
Â
( 'activated' === $action ) ? esc_html__( 'activated', 'stream' ) : esc_html__( 'deactivated', 'stream' )
|
@@ -362,7 +374,7 @@ class Connector_Jetpack extends Connector {
|
|
362 |
Â
$action = $method;
|
363 |
Â
$meta = compact( 'user_id', 'user_email', 'user_login' );
|
364 |
Â
$message = sprintf(
|
365 |
-
|
366 |
Â
__( '%1$s\'s account %2$s %3$s Jetpack', 'stream' ),
|
367 |
Â
$user->display_name,
|
368 |
Â
( 'unlink' === $action ) ? esc_html__( 'unlinked', 'stream' ) : esc_html__( 'linked', 'stream' ),
|
@@ -372,7 +384,8 @@ class Connector_Jetpack extends Connector {
|
|
372 |
Â
$context = 'blogs';
|
373 |
Â
$action = str_replace( 'subsite', '', $method );
|
374 |
Â
$is_multisite = ( 0 === strpos( $method, 'subsite' ) );
|
375 |
-
|
Â
|
|
376 |
Â
|
377 |
Â
if ( empty( $blog_id ) ) {
|
378 |
Â
return;
|
@@ -380,7 +393,7 @@ class Connector_Jetpack extends Connector {
|
|
380 |
Â
|
381 |
Â
if ( ! $is_multisite ) {
|
382 |
Â
$message = sprintf(
|
383 |
-
|
384 |
Â
__( 'Site %s Jetpack', 'stream' ),
|
385 |
Â
( 'register' === $action ) ? esc_html__( 'connected to', 'stream' ) : esc_html__( 'disconnected from', 'stream' )
|
386 |
Â
);
|
@@ -394,7 +407,7 @@ class Connector_Jetpack extends Connector {
|
|
394 |
Â
$meta += compact( 'blog_id', 'blog_name' );
|
395 |
Â
|
396 |
Â
$message = sprintf(
|
397 |
-
|
398 |
Â
__( '"%1$s" blog %2$s Jetpack', 'stream' ),
|
399 |
Â
$blog_name,
|
400 |
Â
( 'register' === $action ) ? esc_html__( 'connected to', 'stream' ) : esc_html__( 'disconnected from', 'stream' )
|
@@ -418,7 +431,7 @@ class Connector_Jetpack extends Connector {
|
|
418 |
Â
/**
|
419 |
Â
* Track visible/enabled sharing services ( buttons )
|
420 |
Â
*
|
421 |
-
* @param string $state
|
422 |
Â
*/
|
423 |
Â
public function callback_sharing_get_services_state( $state ) {
|
424 |
Â
$this->log(
|
@@ -430,14 +443,32 @@ class Connector_Jetpack extends Connector {
|
|
430 |
Â
);
|
431 |
Â
}
|
432 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
433 |
Â
public function callback_update_option( $option, $old, $new ) {
|
434 |
Â
$this->check( $option, $old, $new );
|
435 |
Â
}
|
436 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
437 |
Â
public function callback_add_option( $option, $val ) {
|
438 |
Â
$this->check( $option, null, $val );
|
439 |
Â
}
|
440 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
441 |
Â
public function callback_delete_option( $option ) {
|
442 |
Â
$this->check( $option, null, null );
|
443 |
Â
}
|
@@ -453,7 +484,7 @@ class Connector_Jetpack extends Connector {
|
|
453 |
Â
}
|
454 |
Â
|
455 |
Â
$this->log(
|
456 |
-
|
457 |
Â
__( 'Monitor notifications %s', 'stream' ),
|
458 |
Â
array(
|
459 |
Â
'status' => $active ? esc_html__( 'activated', 'stream' ) : esc_html__( 'deactivated', 'stream' ),
|
@@ -467,18 +498,39 @@ class Connector_Jetpack extends Connector {
|
|
467 |
Â
);
|
468 |
Â
}
|
469 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
470 |
Â
public function callback_wp_ajax_jetpack_post_by_email_enable() {
|
471 |
Â
$this->track_post_by_email( true );
|
472 |
Â
}
|
473 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
474 |
Â
public function callback_wp_ajax_jetpack_post_by_email_regenerate() {
|
475 |
Â
$this->track_post_by_email( null );
|
476 |
Â
}
|
477 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
478 |
Â
public function callback_wp_ajax_jetpack_post_by_email_disable() {
|
479 |
Â
$this->track_post_by_email( false );
|
480 |
Â
}
|
481 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
482 |
Â
public function track_post_by_email( $status ) {
|
483 |
Â
if ( true === $status ) {
|
484 |
Â
$action = esc_html__( 'enabled', 'stream' );
|
@@ -491,7 +543,7 @@ class Connector_Jetpack extends Connector {
|
|
491 |
Â
$user = wp_get_current_user();
|
492 |
Â
|
493 |
Â
$this->log(
|
494 |
-
|
495 |
Â
__( '%1$s %2$s Post by Email', 'stream' ),
|
496 |
Â
array(
|
497 |
Â
'user_displayname' => $user->display_name,
|
@@ -504,6 +556,13 @@ class Connector_Jetpack extends Connector {
|
|
504 |
Â
);
|
505 |
Â
}
|
506 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
507 |
Â
public function check( $option, $old_value, $new_value ) {
|
508 |
Â
if ( ! array_key_exists( $option, $this->options ) ) {
|
509 |
Â
return;
|
@@ -516,7 +575,7 @@ class Connector_Jetpack extends Connector {
|
|
516 |
Â
$option_title = $data['label'];
|
517 |
Â
|
518 |
Â
$this->log(
|
519 |
-
|
520 |
Â
__( '"%s" setting updated', 'stream' ),
|
521 |
Â
compact( 'option_title', 'option', 'old_value', 'new_value' ),
|
522 |
Â
null,
|
@@ -526,6 +585,12 @@ class Connector_Jetpack extends Connector {
|
|
526 |
Â
}
|
527 |
Â
}
|
528 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
529 |
Â
public function check_jetpack_options( $old_value, $new_value ) {
|
530 |
Â
$options = array();
|
531 |
Â
|
@@ -544,7 +609,7 @@ class Connector_Jetpack extends Connector {
|
|
544 |
Â
continue;
|
545 |
Â
}
|
546 |
Â
|
547 |
-
if ( 0 === $option_value ) { // Skip updated array with updated members, we'll be logging those instead
|
548 |
Â
continue;
|
549 |
Â
}
|
550 |
Â
|
@@ -564,6 +629,13 @@ class Connector_Jetpack extends Connector {
|
|
564 |
Â
}
|
565 |
Â
}
|
566 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
567 |
Â
public function check_hide_gplus( $old_value, $new_value ) {
|
568 |
Â
$status = ! is_null( $new_value );
|
569 |
Â
|
@@ -572,7 +644,7 @@ class Connector_Jetpack extends Connector {
|
|
572 |
Â
}
|
573 |
Â
|
574 |
Â
$this->log(
|
575 |
-
|
576 |
Â
__( 'G+ profile display %s', 'stream' ),
|
577 |
Â
array(
|
578 |
Â
'action' => $status ? esc_html__( 'enabled', 'stream' ) : esc_html__( 'disabled', 'stream' ),
|
@@ -583,6 +655,13 @@ class Connector_Jetpack extends Connector {
|
|
583 |
Â
);
|
584 |
Â
}
|
585 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
586 |
Â
public function check_gplus_authors( $old_value, $new_value ) {
|
587 |
Â
unset( $old_value );
|
588 |
Â
|
@@ -590,7 +669,7 @@ class Connector_Jetpack extends Connector {
|
|
590 |
Â
$connected = is_array( $new_value ) && array_key_exists( $user->ID, $new_value );
|
591 |
Â
|
592 |
Â
$this->log(
|
593 |
-
|
594 |
Â
__( '%1$s\'s Google+ account %2$s', 'stream' ),
|
595 |
Â
array(
|
596 |
Â
'display_name' => $user->display_name,
|
@@ -603,15 +682,22 @@ class Connector_Jetpack extends Connector {
|
|
603 |
Â
);
|
604 |
Â
}
|
605 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
606 |
Â
public function check_sharedaddy_disable_resources( $old_value, $new_value ) {
|
607 |
Â
if ( $old_value === $new_value ) {
|
608 |
Â
return;
|
609 |
Â
}
|
610 |
Â
|
611 |
-
$status = ! $new_value ? 'enabled' : 'disabled'; // disabled = 1
|
612 |
Â
|
613 |
Â
$this->log(
|
614 |
-
|
615 |
Â
__( 'Sharing CSS/JS %s', 'stream' ),
|
616 |
Â
compact( 'status', 'old_value', 'new_value' ),
|
617 |
Â
null,
|
@@ -623,7 +709,7 @@ class Connector_Jetpack extends Connector {
|
|
623 |
Â
/**
|
624 |
Â
* Override connector log for our own Settings / Actions
|
625 |
Â
*
|
626 |
-
* @param array $data
|
627 |
Â
*
|
628 |
Â
* @return array|bool
|
629 |
Â
*/
|
@@ -632,7 +718,7 @@ class Connector_Jetpack extends Connector {
|
|
632 |
Â
return $data;
|
633 |
Â
}
|
634 |
Â
|
635 |
-
// Handling our Settings
|
636 |
Â
if ( 'settings' === $data['connector'] && isset( $this->options_override[ $data['args']['option'] ] ) ) {
|
637 |
Â
if ( isset( $data['args']['option_key'] ) ) {
|
638 |
Â
$overrides = $this->options_override[ $data['args']['option'] ][ $data['args']['option_key'] ];
|
@@ -663,15 +749,21 @@ class Connector_Jetpack extends Connector {
|
|
663 |
Â
return $data;
|
664 |
Â
}
|
665 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
666 |
Â
private function get_settings_def( $key, $value = null ) {
|
667 |
-
// Sharing
|
668 |
Â
if ( 0 === strpos( $key, 'publicize_connections::' ) ) {
|
669 |
Â
global $publicize_ui;
|
670 |
Â
|
671 |
Â
$name = str_replace( 'publicize_connections::', '', $key );
|
672 |
Â
|
673 |
Â
return array(
|
674 |
-
|
675 |
Â
'message' => esc_html__( '%1$s connection %2$s', 'stream' ),
|
676 |
Â
'meta' => array(
|
677 |
Â
'connection' => $publicize_ui->publicize->get_service_label( $name ),
|
@@ -696,7 +788,7 @@ class Connector_Jetpack extends Connector {
|
|
696 |
Â
}
|
697 |
Â
|
698 |
Â
return array(
|
699 |
-
|
700 |
Â
'message' => esc_html__( '"%s" setting updated', 'stream' ),
|
701 |
Â
'meta' => array(
|
702 |
Â
'option_name' => $options[ $name ],
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for Jetpack
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_Jetpack
|
12 |
+
*/
|
13 |
Â
class Connector_Jetpack extends Connector {
|
14 |
Â
/**
|
15 |
Â
* Connector slug
|
142 |
Â
*
|
143 |
Â
* @filter wp_stream_action_links_{connector}
|
144 |
Â
*
|
145 |
+
* @param array $links Previous links registered.
|
146 |
+
* @param object $record Stream record.
|
147 |
Â
*
|
148 |
Â
* @return array Action links
|
149 |
Â
*/
|
185 |
Â
);
|
186 |
Â
}
|
187 |
Â
} elseif ( \Jetpack::is_module_active( str_replace( 'jetpack-', '', $record->context ) ) ) {
|
188 |
+
$slug = str_replace( 'jetpack-', '', $record->context ); // handling jetpack-comment anomaly.
|
189 |
Â
|
190 |
Â
if ( apply_filters( 'jetpack_module_configurable_' . $slug, false ) ) {
|
191 |
Â
$links[ esc_html__( 'Configure module', 'stream' ) ] = \Jetpack::module_configuration_url( $slug );
|
196 |
Â
return $links;
|
197 |
Â
}
|
198 |
Â
|
199 |
+
/**
|
200 |
+
* Register all context hooks
|
201 |
+
*/
|
202 |
Â
public function register() {
|
203 |
Â
parent::register();
|
204 |
Â
|
206 |
Â
|
207 |
Â
$this->options = array(
|
208 |
Â
'jetpack_options' => null,
|
209 |
+
// Sharing module.
|
210 |
Â
'hide_gplus' => null,
|
211 |
Â
'gplus_authors' => null,
|
212 |
Â
'sharing-options' => array(
|
218 |
Â
'label' => esc_html__( 'Twitter site tag', 'stream' ),
|
219 |
Â
'context' => 'sharedaddy',
|
220 |
Â
),
|
221 |
+
// Stats module.
|
222 |
Â
'stats_options' => array(
|
223 |
Â
'label' => esc_html__( 'WordPress.com Stats', 'stream' ),
|
224 |
Â
'context' => 'stats',
|
225 |
Â
),
|
226 |
+
// Comments.
|
227 |
Â
'jetpack_comment_form_color_scheme' => array(
|
228 |
Â
'label' => esc_html__( 'Color Scheme', 'stream' ),
|
229 |
Â
'context' => 'jetpack-comments',
|
230 |
Â
),
|
231 |
+
// Likes.
|
232 |
Â
'disabled_likes' => array(
|
233 |
Â
'label' => esc_html__( 'WP.com Site-wide Likes', 'stream' ),
|
234 |
Â
'context' => 'likes',
|
235 |
Â
),
|
236 |
+
// Mobile.
|
237 |
Â
'wp_mobile_excerpt' => array(
|
238 |
Â
'label' => esc_html__( 'Excerpts appearance', 'stream' ),
|
239 |
Â
'context' => 'minileven',
|
245 |
Â
);
|
246 |
Â
|
247 |
Â
$this->options_override = array(
|
248 |
+
// Carousel Module.
|
249 |
Â
'carousel_background_color' => array(
|
250 |
Â
'label' => esc_html__( 'Background color', 'stream' ),
|
251 |
Â
'context' => 'carousel',
|
254 |
Â
'label' => esc_html__( 'Metadata', 'stream' ),
|
255 |
Â
'context' => 'carousel',
|
256 |
Â
),
|
257 |
+
// Subscriptions.
|
258 |
Â
'stb_enabled' => array(
|
259 |
Â
'label' => esc_html__( 'Follow blog comment form button', 'stream' ),
|
260 |
Â
'context' => 'subscriptions',
|
263 |
Â
'label' => esc_html__( 'Follow comments form button', 'stream' ),
|
264 |
Â
'context' => 'subscriptions',
|
265 |
Â
),
|
266 |
+
// Jetpack comments.
|
267 |
Â
'highlander_comment_form_prompt' => array(
|
268 |
Â
'label' => esc_html__( 'Greeting Text', 'stream' ),
|
269 |
Â
'context' => 'jetpack-comments',
|
270 |
Â
),
|
271 |
+
// Infinite Scroll.
|
272 |
Â
'infinite_scroll_google_analytics' => array(
|
273 |
Â
'label' => esc_html__( 'Infinite Scroll Google Analytics', 'stream' ),
|
274 |
Â
'context' => 'infinite-scroll',
|
275 |
Â
),
|
276 |
+
// Protect.
|
277 |
Â
'jetpack_protect_blocked_attempts' => array(
|
278 |
Â
'label' => esc_html__( 'Blocked Attempts', 'stream' ),
|
279 |
Â
'context' => 'protect',
|
280 |
Â
),
|
281 |
+
// SSO.
|
282 |
Â
'jetpack_sso_require_two_step' => array(
|
283 |
Â
'label' => esc_html__( 'Require Two-Step Authentication', 'stream' ),
|
284 |
Â
'context' => 'sso',
|
287 |
Â
'label' => esc_html__( 'Match by Email', 'stream' ),
|
288 |
Â
'context' => 'sso',
|
289 |
Â
),
|
290 |
+
// Related posts.
|
291 |
Â
'jetpack_relatedposts' => array(
|
292 |
Â
'show_headline' => array(
|
293 |
Â
'label' => esc_html__( 'Show Related Posts Headline', 'stream' ),
|
298 |
Â
'context' => 'related-posts',
|
299 |
Â
),
|
300 |
Â
),
|
301 |
+
// Site verification.
|
302 |
Â
'verification_services_codes' => array(
|
303 |
Â
'google' => array(
|
304 |
Â
'label' => esc_html__( 'Google Webmaster Tools Token', 'stream' ),
|
313 |
Â
'context' => 'verification-tools',
|
314 |
Â
),
|
315 |
Â
),
|
316 |
+
// Tiled galleries.
|
317 |
Â
'tiled_galleries' => array(
|
318 |
Â
'label' => esc_html__( 'Tiled Galleries', 'stream' ),
|
319 |
Â
'context' => 'tiled-gallery',
|
328 |
Â
* - Registration/Disconnection of blogs
|
329 |
Â
* - Authorization/unlinking of users
|
330 |
Â
*
|
331 |
+
* @param array $entry Entry data.
|
332 |
Â
*/
|
333 |
Â
public function callback_jetpack_log_entry( array $entry ) {
|
334 |
Â
if ( isset( $entry['code'] ) ) {
|
355 |
Â
$action = $method . 'd';
|
356 |
Â
$meta = compact( 'module_slug' );
|
357 |
Â
$message = sprintf(
|
358 |
+
/* translators: %1$s: a module name, %2$s a status (e.g. "Photon", "activated") */
|
359 |
Â
__( '%1$s module %2$s', 'stream' ),
|
360 |
Â
$module_name,
|
361 |
Â
( 'activated' === $action ) ? esc_html__( 'activated', 'stream' ) : esc_html__( 'deactivated', 'stream' )
|
374 |
Â
$action = $method;
|
375 |
Â
$meta = compact( 'user_id', 'user_email', 'user_login' );
|
376 |
Â
$message = sprintf(
|
377 |
+
/* translators: %1$s: a user display name, %2$s: a status, %3$s: the connection either "from" or "to" (e.g. "Jane Doe", "unlinked", "from") */
|
378 |
Â
__( '%1$s\'s account %2$s %3$s Jetpack', 'stream' ),
|
379 |
Â
$user->display_name,
|
380 |
Â
( 'unlink' === $action ) ? esc_html__( 'unlinked', 'stream' ) : esc_html__( 'linked', 'stream' ),
|
384 |
Â
$context = 'blogs';
|
385 |
Â
$action = str_replace( 'subsite', '', $method );
|
386 |
Â
$is_multisite = ( 0 === strpos( $method, 'subsite' ) );
|
387 |
+
// @codingStandardsIgnoreLine
|
388 |
+
$blog_id = $is_multisite ? ( isset( $_GET['site_id'] ) ? intval( wp_unslash( $_GET['site_id'] ) ) : null ) : get_current_blog_id();
|
389 |
Â
|
390 |
Â
if ( empty( $blog_id ) ) {
|
391 |
Â
return;
|
393 |
Â
|
394 |
Â
if ( ! $is_multisite ) {
|
395 |
Â
$message = sprintf(
|
396 |
+
/* translators: %s: a connection status. Either "connected to" or "disconnected from". */
|
397 |
Â
__( 'Site %s Jetpack', 'stream' ),
|
398 |
Â
( 'register' === $action ) ? esc_html__( 'connected to', 'stream' ) : esc_html__( 'disconnected from', 'stream' )
|
399 |
Â
);
|
407 |
Â
$meta += compact( 'blog_id', 'blog_name' );
|
408 |
Â
|
409 |
Â
$message = sprintf(
|
410 |
+
/* translators: %1$s: Blog name, %2$s: a connection status. Either "connected to" or "disconnected from". */
|
411 |
Â
__( '"%1$s" blog %2$s Jetpack', 'stream' ),
|
412 |
Â
$blog_name,
|
413 |
Â
( 'register' === $action ) ? esc_html__( 'connected to', 'stream' ) : esc_html__( 'disconnected from', 'stream' )
|
431 |
Â
/**
|
432 |
Â
* Track visible/enabled sharing services ( buttons )
|
433 |
Â
*
|
434 |
+
* @param string $state Service state.
|
435 |
Â
*/
|
436 |
Â
public function callback_sharing_get_services_state( $state ) {
|
437 |
Â
$this->log(
|
443 |
Â
);
|
444 |
Â
}
|
445 |
Â
|
446 |
+
/**
|
447 |
+
* Track Jetpack-specific option changes.
|
448 |
+
*
|
449 |
+
* @param string $option Option key.
|
450 |
+
* @param string $old Old value.
|
451 |
+
* @param string $new New value.
|
452 |
+
*/
|
453 |
Â
public function callback_update_option( $option, $old, $new ) {
|
454 |
Â
$this->check( $option, $old, $new );
|
455 |
Â
}
|
456 |
Â
|
457 |
+
/**
|
458 |
+
* Track Jetpack-specific option creations.
|
459 |
+
*
|
460 |
+
* @param string $option Option key.
|
461 |
+
* @param string $val Value.
|
462 |
+
*/
|
463 |
Â
public function callback_add_option( $option, $val ) {
|
464 |
Â
$this->check( $option, null, $val );
|
465 |
Â
}
|
466 |
Â
|
467 |
+
/**
|
468 |
+
* Track Jetpack-specific option deletions.
|
469 |
+
*
|
470 |
+
* @param string $option Option key.
|
471 |
+
*/
|
472 |
Â
public function callback_delete_option( $option ) {
|
473 |
Â
$this->check( $option, null, null );
|
474 |
Â
}
|
484 |
Â
}
|
485 |
Â
|
486 |
Â
$this->log(
|
487 |
+
/* translators: %s: a status (e.g. "activated") */
|
488 |
Â
__( 'Monitor notifications %s', 'stream' ),
|
489 |
Â
array(
|
490 |
Â
'status' => $active ? esc_html__( 'activated', 'stream' ) : esc_html__( 'deactivated', 'stream' ),
|
498 |
Â
);
|
499 |
Â
}
|
500 |
Â
|
501 |
+
/**
|
502 |
+
* Logs when user enables "post_by_email"
|
503 |
+
*
|
504 |
+
* @action wp_ajax_jetpack_post_by_email_enable
|
505 |
+
*/
|
506 |
Â
public function callback_wp_ajax_jetpack_post_by_email_enable() {
|
507 |
Â
$this->track_post_by_email( true );
|
508 |
Â
}
|
509 |
Â
|
510 |
+
/**
|
511 |
+
* Logs when user regenerates "post_by_email"
|
512 |
+
*
|
513 |
+
* @action wp_ajax_jetpack_post_by_email_regenerate
|
514 |
+
*/
|
515 |
Â
public function callback_wp_ajax_jetpack_post_by_email_regenerate() {
|
516 |
Â
$this->track_post_by_email( null );
|
517 |
Â
}
|
518 |
Â
|
519 |
+
/**
|
520 |
+
* Logs when user disables "post_by_email"
|
521 |
+
*
|
522 |
+
* @action wp_ajax_jetpack_post_by_email_disable
|
523 |
+
*/
|
524 |
Â
public function callback_wp_ajax_jetpack_post_by_email_disable() {
|
525 |
Â
$this->track_post_by_email( false );
|
526 |
Â
}
|
527 |
Â
|
528 |
+
/**
|
529 |
+
* Tracks changes a user post by email status
|
530 |
+
*
|
531 |
+
* @param string $status Status.
|
532 |
+
* @return void
|
533 |
+
*/
|
534 |
Â
public function track_post_by_email( $status ) {
|
535 |
Â
if ( true === $status ) {
|
536 |
Â
$action = esc_html__( 'enabled', 'stream' );
|
543 |
Â
$user = wp_get_current_user();
|
544 |
Â
|
545 |
Â
$this->log(
|
546 |
+
/* translators: %1$s: a user display name, %2$s: a status (e.g. "Jane Doe", "enabled") */
|
547 |
Â
__( '%1$s %2$s Post by Email', 'stream' ),
|
548 |
Â
array(
|
549 |
Â
'user_displayname' => $user->display_name,
|
556 |
Â
);
|
557 |
Â
}
|
558 |
Â
|
559 |
+
/**
|
560 |
+
* Tracks Jetpack-specific option activity.
|
561 |
+
*
|
562 |
+
* @param string $option Option key.
|
563 |
+
* @param string $old_value Old value.
|
564 |
+
* @param string $new_value New value.
|
565 |
+
*/
|
566 |
Â
public function check( $option, $old_value, $new_value ) {
|
567 |
Â
if ( ! array_key_exists( $option, $this->options ) ) {
|
568 |
Â
return;
|
575 |
Â
$option_title = $data['label'];
|
576 |
Â
|
577 |
Â
$this->log(
|
578 |
+
/* translators: %s: a setting name (e.g. "Language") */
|
579 |
Â
__( '"%s" setting updated', 'stream' ),
|
580 |
Â
compact( 'option_title', 'option', 'old_value', 'new_value' ),
|
581 |
Â
null,
|
585 |
Â
}
|
586 |
Â
}
|
587 |
Â
|
588 |
+
/**
|
589 |
+
* Track Jetpack-specific option activity.
|
590 |
+
*
|
591 |
+
* @param string $old_value Old value.
|
592 |
+
* @param string $new_value New value.
|
593 |
+
*/
|
594 |
Â
public function check_jetpack_options( $old_value, $new_value ) {
|
595 |
Â
$options = array();
|
596 |
Â
|
609 |
Â
continue;
|
610 |
Â
}
|
611 |
Â
|
612 |
+
if ( 0 === $option_value ) { // Skip updated array with updated members, we'll be logging those instead.
|
613 |
Â
continue;
|
614 |
Â
}
|
615 |
Â
|
629 |
Â
}
|
630 |
Â
}
|
631 |
Â
|
632 |
+
/**
|
633 |
+
* Logs Google+ profile display status
|
634 |
+
*
|
635 |
+
* @param string $old_value Old status.
|
636 |
+
* @param string $new_value New status.
|
637 |
+
* @return null|bool
|
638 |
+
*/
|
639 |
Â
public function check_hide_gplus( $old_value, $new_value ) {
|
640 |
Â
$status = ! is_null( $new_value );
|
641 |
Â
|
644 |
Â
}
|
645 |
Â
|
646 |
Â
$this->log(
|
647 |
+
/* translators: Placeholder refers to a status (e.g. "enabled") */
|
648 |
Â
__( 'G+ profile display %s', 'stream' ),
|
649 |
Â
array(
|
650 |
Â
'action' => $status ? esc_html__( 'enabled', 'stream' ) : esc_html__( 'disabled', 'stream' ),
|
655 |
Â
);
|
656 |
Â
}
|
657 |
Â
|
658 |
+
/**
|
659 |
+
* Logs if current user's Google+ account connection status
|
660 |
+
*
|
661 |
+
* @param string $old_value Old status.
|
662 |
+
* @param string $new_value New status.
|
663 |
+
* @return void
|
664 |
+
*/
|
665 |
Â
public function check_gplus_authors( $old_value, $new_value ) {
|
666 |
Â
unset( $old_value );
|
667 |
Â
|
669 |
Â
$connected = is_array( $new_value ) && array_key_exists( $user->ID, $new_value );
|
670 |
Â
|
671 |
Â
$this->log(
|
672 |
+
/* translators: %1$s: a user display name, %2$s: a status (e.g. "Jane Doe", "connected") */
|
673 |
Â
__( '%1$s\'s Google+ account %2$s', 'stream' ),
|
674 |
Â
array(
|
675 |
Â
'display_name' => $user->display_name,
|
682 |
Â
);
|
683 |
Â
}
|
684 |
Â
|
685 |
+
/**
|
686 |
+
* Logs sharedaddy resource status.
|
687 |
+
*
|
688 |
+
* @param string $old_value Old status.
|
689 |
+
* @param string $new_value New status.
|
690 |
+
* @return void
|
691 |
+
*/
|
692 |
Â
public function check_sharedaddy_disable_resources( $old_value, $new_value ) {
|
693 |
Â
if ( $old_value === $new_value ) {
|
694 |
Â
return;
|
695 |
Â
}
|
696 |
Â
|
697 |
+
$status = ! $new_value ? 'enabled' : 'disabled'; // disabled = 1.
|
698 |
Â
|
699 |
Â
$this->log(
|
700 |
+
/* translators: %s: a status (e.g. "enabled") */
|
701 |
Â
__( 'Sharing CSS/JS %s', 'stream' ),
|
702 |
Â
compact( 'status', 'old_value', 'new_value' ),
|
703 |
Â
null,
|
709 |
Â
/**
|
710 |
Â
* Override connector log for our own Settings / Actions
|
711 |
Â
*
|
712 |
+
* @param array $data Record data.
|
713 |
Â
*
|
714 |
Â
* @return array|bool
|
715 |
Â
*/
|
718 |
Â
return $data;
|
719 |
Â
}
|
720 |
Â
|
721 |
+
// Handling our Settings.
|
722 |
Â
if ( 'settings' === $data['connector'] && isset( $this->options_override[ $data['args']['option'] ] ) ) {
|
723 |
Â
if ( isset( $data['args']['option_key'] ) ) {
|
724 |
Â
$overrides = $this->options_override[ $data['args']['option'] ][ $data['args']['option_key'] ];
|
749 |
Â
return $data;
|
750 |
Â
}
|
751 |
Â
|
752 |
+
/**
|
753 |
+
* Returns an option's status
|
754 |
+
*
|
755 |
+
* @param string $key Option key.
|
756 |
+
* @param string $value Option value.
|
757 |
+
*/
|
758 |
Â
private function get_settings_def( $key, $value = null ) {
|
759 |
+
// Sharing.
|
760 |
Â
if ( 0 === strpos( $key, 'publicize_connections::' ) ) {
|
761 |
Â
global $publicize_ui;
|
762 |
Â
|
763 |
Â
$name = str_replace( 'publicize_connections::', '', $key );
|
764 |
Â
|
765 |
Â
return array(
|
766 |
+
/* translators: %1$s: a service, %2$s: a status (e.g. "Facebook", "added") */
|
767 |
Â
'message' => esc_html__( '%1$s connection %2$s', 'stream' ),
|
768 |
Â
'meta' => array(
|
769 |
Â
'connection' => $publicize_ui->publicize->get_service_label( $name ),
|
788 |
Â
}
|
789 |
Â
|
790 |
Â
return array(
|
791 |
+
/* translators: %s: a setting name (e.g. "Language") */
|
792 |
Â
'message' => esc_html__( '"%s" setting updated', 'stream' ),
|
793 |
Â
'meta' => array(
|
794 |
Â
'option_name' => $options[ $name ],
|
connectors/class-connector-media.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_Media extends Connector {
|
5 |
Â
/**
|
6 |
Â
* Connector slug
|
@@ -71,7 +80,7 @@ class Connector_Media extends Connector {
|
|
71 |
Â
/**
|
72 |
Â
* Return the file type for an attachment which corresponds with a context label
|
73 |
Â
*
|
74 |
-
* @param object $file_uri
|
75 |
Â
*
|
76 |
Â
* @return string A file type which corresponds with a context label
|
77 |
Â
*/
|
@@ -97,8 +106,8 @@ class Connector_Media extends Connector {
|
|
97 |
Â
*
|
98 |
Â
* @filter wp_stream_action_links_{connector}
|
99 |
Â
*
|
100 |
-
* @param array $links
|
101 |
-
* @param object $record
|
102 |
Â
*
|
103 |
Â
* @return array Action links
|
104 |
Â
*/
|
@@ -122,19 +131,19 @@ class Connector_Media extends Connector {
|
|
122 |
Â
*
|
123 |
Â
* @action add_attachment
|
124 |
Â
*
|
125 |
-
* @param int $post_id
|
126 |
Â
*/
|
127 |
Â
public function callback_add_attachment( $post_id ) {
|
128 |
Â
$post = get_post( $post_id );
|
129 |
Â
if ( $post->post_parent ) {
|
130 |
-
|
131 |
Â
$message = _x(
|
132 |
Â
'Attached "%1$s" to "%2$s"',
|
133 |
Â
'1: Attachment title, 2: Parent post title',
|
134 |
Â
'stream'
|
135 |
Â
);
|
136 |
Â
} else {
|
137 |
-
|
138 |
Â
$message = esc_html__( 'Added "%s" to Media library', 'stream' );
|
139 |
Â
}
|
140 |
Â
|
@@ -159,14 +168,14 @@ class Connector_Media extends Connector {
|
|
159 |
Â
*
|
160 |
Â
* @action edit_attachment
|
161 |
Â
*
|
162 |
-
* @param int $post_id
|
163 |
Â
*/
|
164 |
Â
public function callback_edit_attachment( $post_id ) {
|
165 |
Â
$post = get_post( $post_id );
|
166 |
Â
$name = $post->post_title;
|
167 |
Â
$attachment_type = $this->get_attachment_type( $post->guid );
|
168 |
Â
|
169 |
-
|
170 |
Â
$message = esc_html__( 'Updated "%s"', 'stream' );
|
171 |
Â
|
172 |
Â
$this->log(
|
@@ -183,7 +192,7 @@ class Connector_Media extends Connector {
|
|
183 |
Â
*
|
184 |
Â
* @action delete_attachment
|
185 |
Â
*
|
186 |
-
* @param int $post_id
|
187 |
Â
*/
|
188 |
Â
public function callback_delete_attachment( $post_id ) {
|
189 |
Â
$post = get_post( $post_id );
|
@@ -193,7 +202,7 @@ class Connector_Media extends Connector {
|
|
193 |
Â
$url = $post->guid;
|
194 |
Â
$attachment_type = $this->get_attachment_type( $post->guid );
|
195 |
Â
|
196 |
-
|
197 |
Â
$message = esc_html__( 'Deleted "%s"', 'stream' );
|
198 |
Â
|
199 |
Â
$this->log(
|
@@ -210,11 +219,11 @@ class Connector_Media extends Connector {
|
|
210 |
Â
*
|
211 |
Â
* @action delete_attachment
|
212 |
Â
*
|
213 |
-
* @param string $dummy
|
214 |
-
* @param string $filename
|
215 |
-
* @param string $image
|
216 |
-
* @param string $mime_type
|
217 |
-
* @param int $post_id
|
218 |
Â
*/
|
219 |
Â
public function callback_wp_save_image_editor_file( $dummy, $filename, $image, $mime_type, $post_id ) {
|
220 |
Â
unset( $dummy );
|
@@ -227,7 +236,7 @@ class Connector_Media extends Connector {
|
|
227 |
Â
$attachment_type = $this->get_attachment_type( $post->guid );
|
228 |
Â
|
229 |
Â
$this->log(
|
230 |
-
|
231 |
Â
__( 'Edited image "%s"', 'stream' ),
|
232 |
Â
compact( 'name', 'filename', 'post_id' ),
|
233 |
Â
$post_id,
|
@@ -236,6 +245,17 @@ class Connector_Media extends Connector {
|
|
236 |
Â
);
|
237 |
Â
}
|
238 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
239 |
Â
public function callback_wp_save_image_file( $dummy, $filename, $image, $mime_type, $post_id ) {
|
240 |
Â
return $this->callback_wp_save_image_editor_file( $dummy, $filename, $image, $mime_type, $post_id );
|
241 |
Â
}
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for Media files
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_Media
|
12 |
+
*/
|
13 |
Â
class Connector_Media extends Connector {
|
14 |
Â
/**
|
15 |
Â
* Connector slug
|
80 |
Â
/**
|
81 |
Â
* Return the file type for an attachment which corresponds with a context label
|
82 |
Â
*
|
83 |
+
* @param object $file_uri URI of the attachment.
|
84 |
Â
*
|
85 |
Â
* @return string A file type which corresponds with a context label
|
86 |
Â
*/
|
106 |
Â
*
|
107 |
Â
* @filter wp_stream_action_links_{connector}
|
108 |
Â
*
|
109 |
+
* @param array $links Previous links registered.
|
110 |
+
* @param object $record Stream record.
|
111 |
Â
*
|
112 |
Â
* @return array Action links
|
113 |
Â
*/
|
131 |
Â
*
|
132 |
Â
* @action add_attachment
|
133 |
Â
*
|
134 |
+
* @param int $post_id Post ID.
|
135 |
Â
*/
|
136 |
Â
public function callback_add_attachment( $post_id ) {
|
137 |
Â
$post = get_post( $post_id );
|
138 |
Â
if ( $post->post_parent ) {
|
139 |
+
/* translators: %1$s: an attachment title, %2$s: a post title (e.g. "PIC001", "Hello World") */
|
140 |
Â
$message = _x(
|
141 |
Â
'Attached "%1$s" to "%2$s"',
|
142 |
Â
'1: Attachment title, 2: Parent post title',
|
143 |
Â
'stream'
|
144 |
Â
);
|
145 |
Â
} else {
|
146 |
+
/* translators: %s: an attachment title (e.g. "PIC001") */
|
147 |
Â
$message = esc_html__( 'Added "%s" to Media library', 'stream' );
|
148 |
Â
}
|
149 |
Â
|
168 |
Â
*
|
169 |
Â
* @action edit_attachment
|
170 |
Â
*
|
171 |
+
* @param int $post_id Post ID.
|
172 |
Â
*/
|
173 |
Â
public function callback_edit_attachment( $post_id ) {
|
174 |
Â
$post = get_post( $post_id );
|
175 |
Â
$name = $post->post_title;
|
176 |
Â
$attachment_type = $this->get_attachment_type( $post->guid );
|
177 |
Â
|
178 |
+
/* translators: %s: an attachment title (e.g. "PIC001") */
|
179 |
Â
$message = esc_html__( 'Updated "%s"', 'stream' );
|
180 |
Â
|
181 |
Â
$this->log(
|
192 |
Â
*
|
193 |
Â
* @action delete_attachment
|
194 |
Â
*
|
195 |
+
* @param int $post_id Post ID.
|
196 |
Â
*/
|
197 |
Â
public function callback_delete_attachment( $post_id ) {
|
198 |
Â
$post = get_post( $post_id );
|
202 |
Â
$url = $post->guid;
|
203 |
Â
$attachment_type = $this->get_attachment_type( $post->guid );
|
204 |
Â
|
205 |
+
/* translators: %s: an attachment title (e.g. "PIC001") */
|
206 |
Â
$message = esc_html__( 'Deleted "%s"', 'stream' );
|
207 |
Â
|
208 |
Â
$this->log(
|
219 |
Â
*
|
220 |
Â
* @action delete_attachment
|
221 |
Â
*
|
222 |
+
* @param string $dummy Unused.
|
223 |
+
* @param string $filename Filename.
|
224 |
+
* @param string $image Unused.
|
225 |
+
* @param string $mime_type Unused.
|
226 |
+
* @param int $post_id Post ID.
|
227 |
Â
*/
|
228 |
Â
public function callback_wp_save_image_editor_file( $dummy, $filename, $image, $mime_type, $post_id ) {
|
229 |
Â
unset( $dummy );
|
236 |
Â
$attachment_type = $this->get_attachment_type( $post->guid );
|
237 |
Â
|
238 |
Â
$this->log(
|
239 |
+
/* translators: Placeholder refers to an attachment title (e.g. "PIC001") */
|
240 |
Â
__( 'Edited image "%s"', 'stream' ),
|
241 |
Â
compact( 'name', 'filename', 'post_id' ),
|
242 |
Â
$post_id,
|
245 |
Â
);
|
246 |
Â
}
|
247 |
Â
|
248 |
+
/**
|
249 |
+
* Logs updates made in the image editor upon saving
|
250 |
+
*
|
251 |
+
* @action delete_attachment
|
252 |
+
*
|
253 |
+
* @param string $dummy Unused.
|
254 |
+
* @param string $filename Filename.
|
255 |
+
* @param string $image Unused.
|
256 |
+
* @param string $mime_type Unused.
|
257 |
+
* @param int $post_id Post ID.
|
258 |
+
*/
|
259 |
Â
public function callback_wp_save_image_file( $dummy, $filename, $image, $mime_type, $post_id ) {
|
260 |
Â
return $this->callback_wp_save_image_editor_file( $dummy, $filename, $image, $mime_type, $post_id );
|
261 |
Â
}
|
connectors/class-connector-menus.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_Menus extends Connector {
|
5 |
Â
/**
|
6 |
Â
* Connector slug
|
@@ -73,6 +82,9 @@ class Connector_Menus extends Connector {
|
|
73 |
Â
return $labels;
|
74 |
Â
}
|
75 |
Â
|
Â
|
|
Â
|
|
Â
|
|
76 |
Â
public function register() {
|
77 |
Â
parent::register();
|
78 |
Â
|
@@ -84,8 +96,8 @@ class Connector_Menus extends Connector {
|
|
84 |
Â
*
|
85 |
Â
* @filter wp_stream_action_links_{connector}
|
86 |
Â
*
|
87 |
-
* @param array $links
|
88 |
-
* @param object $record
|
89 |
Â
*
|
90 |
Â
* @return array Action links
|
91 |
Â
*/
|
@@ -107,14 +119,14 @@ class Connector_Menus extends Connector {
|
|
107 |
Â
*
|
108 |
Â
* @action wp_create_nav_menu
|
109 |
Â
*
|
110 |
-
* @param int $menu_id
|
111 |
-
* @param array $menu_data
|
112 |
Â
*/
|
113 |
Â
public function callback_wp_create_nav_menu( $menu_id, $menu_data ) {
|
114 |
Â
$name = $menu_data['menu-name'];
|
115 |
Â
|
116 |
Â
$this->log(
|
117 |
-
|
118 |
Â
__( 'Created new menu "%s"', 'stream' ),
|
119 |
Â
compact( 'name', 'menu_id' ),
|
120 |
Â
$menu_id,
|
@@ -128,8 +140,8 @@ class Connector_Menus extends Connector {
|
|
128 |
Â
*
|
129 |
Â
* @action wp_update_nav_menu
|
130 |
Â
*
|
131 |
-
* @param int $menu_id
|
132 |
-
* @param array $menu_data
|
133 |
Â
*/
|
134 |
Â
public function callback_wp_update_nav_menu( $menu_id, $menu_data = array() ) {
|
135 |
Â
if ( empty( $menu_data ) ) {
|
@@ -139,7 +151,7 @@ class Connector_Menus extends Connector {
|
|
139 |
Â
$name = $menu_data['menu-name'];
|
140 |
Â
|
141 |
Â
$this->log(
|
142 |
-
|
143 |
Â
_x( 'Updated menu "%s"', 'Menu name', 'stream' ),
|
144 |
Â
compact( 'name', 'menu_id', 'menu_data' ),
|
145 |
Â
$menu_id,
|
@@ -153,9 +165,9 @@ class Connector_Menus extends Connector {
|
|
153 |
Â
*
|
154 |
Â
* @action delete_nav_menu
|
155 |
Â
*
|
156 |
-
* @param object $term
|
157 |
-
* @param int $tt_id
|
158 |
-
* @param object $deleted_term
|
159 |
Â
*/
|
160 |
Â
public function callback_delete_nav_menu( $term, $tt_id, $deleted_term ) {
|
161 |
Â
unset( $tt_id );
|
@@ -164,7 +176,7 @@ class Connector_Menus extends Connector {
|
|
164 |
Â
$menu_id = $term->term_id;
|
165 |
Â
|
166 |
Â
$this->log(
|
167 |
-
|
168 |
Â
_x( 'Deleted "%s"', 'Menu name', 'stream' ),
|
169 |
Â
compact( 'name', 'menu_id' ),
|
170 |
Â
$menu_id,
|
@@ -178,11 +190,11 @@ class Connector_Menus extends Connector {
|
|
178 |
Â
*
|
179 |
Â
* @action update_option_theme_mods_{$stylesheet}
|
180 |
Â
*
|
181 |
-
* @param array $old
|
182 |
-
* @param array $new
|
183 |
Â
*/
|
184 |
Â
public function callback_update_option_theme_mods( $old, $new ) {
|
185 |
-
// Disable if we're switching themes
|
186 |
Â
if ( did_action( 'after_switch_theme' ) ) {
|
187 |
Â
return;
|
188 |
Â
}
|
@@ -190,7 +202,7 @@ class Connector_Menus extends Connector {
|
|
190 |
Â
$key = 'nav_menu_locations';
|
191 |
Â
|
192 |
Â
if ( ! isset( $new[ $key ] ) ) {
|
193 |
-
return; // Switching themes
|
194 |
Â
}
|
195 |
Â
|
196 |
Â
if ( $old[ $key ] === $new[ $key ] ) {
|
@@ -212,7 +224,7 @@ class Connector_Menus extends Connector {
|
|
212 |
Â
if ( empty( $new[ $key ][ $location_id ] ) ) {
|
213 |
Â
$action = 'unassigned';
|
214 |
Â
$menu_id = isset( $old[ $key ][ $location_id ] ) ? $old[ $key ][ $location_id ] : 0;
|
215 |
-
|
216 |
Â
$message = _x(
|
217 |
Â
'"%1$s" has been unassigned from "%2$s"',
|
218 |
Â
'1: Menu name, 2: Theme location',
|
@@ -221,7 +233,7 @@ class Connector_Menus extends Connector {
|
|
221 |
Â
} else {
|
222 |
Â
$action = 'assigned';
|
223 |
Â
$menu_id = isset( $new[ $key ][ $location_id ] ) ? $new[ $key ][ $location_id ] : 0;
|
224 |
-
|
225 |
Â
$message = _x(
|
226 |
Â
'"%1$s" has been assigned to "%2$s"',
|
227 |
Â
'1: Menu name, 2: Theme location',
|
@@ -232,7 +244,7 @@ class Connector_Menus extends Connector {
|
|
232 |
Â
$menu = get_term( $menu_id, 'nav_menu' );
|
233 |
Â
|
234 |
Â
if ( ! $menu || is_wp_error( $menu ) ) {
|
235 |
-
continue; // This is a deleted menu
|
236 |
Â
}
|
237 |
Â
|
238 |
Â
$name = $menu->name;
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for Menus
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_Menus
|
12 |
+
*/
|
13 |
Â
class Connector_Menus extends Connector {
|
14 |
Â
/**
|
15 |
Â
* Connector slug
|
82 |
Â
return $labels;
|
83 |
Â
}
|
84 |
Â
|
85 |
+
/**
|
86 |
+
* Registers connection.
|
87 |
+
*/
|
88 |
Â
public function register() {
|
89 |
Â
parent::register();
|
90 |
Â
|
96 |
Â
*
|
97 |
Â
* @filter wp_stream_action_links_{connector}
|
98 |
Â
*
|
99 |
+
* @param array $links Previous links registered.
|
100 |
+
* @param object $record Stream record.
|
101 |
Â
*
|
102 |
Â
* @return array Action links
|
103 |
Â
*/
|
119 |
Â
*
|
120 |
Â
* @action wp_create_nav_menu
|
121 |
Â
*
|
122 |
+
* @param int $menu_id Menu ID.
|
123 |
+
* @param array $menu_data Menu data.
|
124 |
Â
*/
|
125 |
Â
public function callback_wp_create_nav_menu( $menu_id, $menu_data ) {
|
126 |
Â
$name = $menu_data['menu-name'];
|
127 |
Â
|
128 |
Â
$this->log(
|
129 |
+
/* translators: %s: a menu name (e.g. "Primary Menu") */
|
130 |
Â
__( 'Created new menu "%s"', 'stream' ),
|
131 |
Â
compact( 'name', 'menu_id' ),
|
132 |
Â
$menu_id,
|
140 |
Â
*
|
141 |
Â
* @action wp_update_nav_menu
|
142 |
Â
*
|
143 |
+
* @param int $menu_id Menu ID.
|
144 |
+
* @param array $menu_data Menu data.
|
145 |
Â
*/
|
146 |
Â
public function callback_wp_update_nav_menu( $menu_id, $menu_data = array() ) {
|
147 |
Â
if ( empty( $menu_data ) ) {
|
151 |
Â
$name = $menu_data['menu-name'];
|
152 |
Â
|
153 |
Â
$this->log(
|
154 |
+
/* translators: %s: a menu name (e.g. "Primary Menu") */
|
155 |
Â
_x( 'Updated menu "%s"', 'Menu name', 'stream' ),
|
156 |
Â
compact( 'name', 'menu_id', 'menu_data' ),
|
157 |
Â
$menu_id,
|
165 |
Â
*
|
166 |
Â
* @action delete_nav_menu
|
167 |
Â
*
|
168 |
+
* @param object $term Term.
|
169 |
+
* @param int $tt_id Term ID.
|
170 |
+
* @param object $deleted_term Deleted term.
|
171 |
Â
*/
|
172 |
Â
public function callback_delete_nav_menu( $term, $tt_id, $deleted_term ) {
|
173 |
Â
unset( $tt_id );
|
176 |
Â
$menu_id = $term->term_id;
|
177 |
Â
|
178 |
Â
$this->log(
|
179 |
+
/* translators: %s: a menu name (e.g. "Primary Menu") */
|
180 |
Â
_x( 'Deleted "%s"', 'Menu name', 'stream' ),
|
181 |
Â
compact( 'name', 'menu_id' ),
|
182 |
Â
$menu_id,
|
190 |
Â
*
|
191 |
Â
* @action update_option_theme_mods_{$stylesheet}
|
192 |
Â
*
|
193 |
+
* @param array $old Old theme data.
|
194 |
+
* @param array $new New theme data.
|
195 |
Â
*/
|
196 |
Â
public function callback_update_option_theme_mods( $old, $new ) {
|
197 |
+
// Disable if we're switching themes.
|
198 |
Â
if ( did_action( 'after_switch_theme' ) ) {
|
199 |
Â
return;
|
200 |
Â
}
|
202 |
Â
$key = 'nav_menu_locations';
|
203 |
Â
|
204 |
Â
if ( ! isset( $new[ $key ] ) ) {
|
205 |
+
return; // Switching themes ?.
|
206 |
Â
}
|
207 |
Â
|
208 |
Â
if ( $old[ $key ] === $new[ $key ] ) {
|
224 |
Â
if ( empty( $new[ $key ][ $location_id ] ) ) {
|
225 |
Â
$action = 'unassigned';
|
226 |
Â
$menu_id = isset( $old[ $key ][ $location_id ] ) ? $old[ $key ][ $location_id ] : 0;
|
227 |
+
/* translators: %1$s: a menu name, %2$s: a theme location (e.g. "Primary Menu", "primary_nav") */
|
228 |
Â
$message = _x(
|
229 |
Â
'"%1$s" has been unassigned from "%2$s"',
|
230 |
Â
'1: Menu name, 2: Theme location',
|
233 |
Â
} else {
|
234 |
Â
$action = 'assigned';
|
235 |
Â
$menu_id = isset( $new[ $key ][ $location_id ] ) ? $new[ $key ][ $location_id ] : 0;
|
236 |
+
/* translators: %1$s: a menu name, %2$s a theme location (e.g. "Primary Menu", "primary_nav") */
|
237 |
Â
$message = _x(
|
238 |
Â
'"%1$s" has been assigned to "%2$s"',
|
239 |
Â
'1: Menu name, 2: Theme location',
|
244 |
Â
$menu = get_term( $menu_id, 'nav_menu' );
|
245 |
Â
|
246 |
Â
if ( ! $menu || is_wp_error( $menu ) ) {
|
247 |
+
continue; // This is a deleted menu.
|
248 |
Â
}
|
249 |
Â
|
250 |
Â
$name = $menu->name;
|
connectors/class-connector-mercator.php
CHANGED
@@ -1,7 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
|
3 |
Â
namespace WP_Stream;
|
4 |
Â
|
Â
|
|
Â
|
|
Â
|
|
5 |
Â
class Connector_Mercator extends Connector {
|
6 |
Â
/**
|
7 |
Â
* Connector slug
|
@@ -65,7 +73,7 @@ class Connector_Mercator extends Connector {
|
|
65 |
Â
|
66 |
Â
foreach ( $blogs as $blog ) {
|
67 |
Â
$blog_details = get_site( $blog->blog_id );
|
68 |
-
$key =
|
69 |
Â
$labels[ $key ] = $blog_details->blogname;
|
70 |
Â
}
|
71 |
Â
}
|
@@ -78,8 +86,8 @@ class Connector_Mercator extends Connector {
|
|
78 |
Â
*
|
79 |
Â
* @filter wp_stream_action_links_{connector}
|
80 |
Â
*
|
81 |
-
* @param
|
82 |
-
* @param
|
83 |
Â
*
|
84 |
Â
* @return array
|
85 |
Â
*/
|
@@ -112,14 +120,14 @@ class Connector_Mercator extends Connector {
|
|
112 |
Â
/**
|
113 |
Â
* Log if domain is made primary.
|
114 |
Â
*
|
115 |
-
* @param $mapping
|
116 |
Â
*/
|
117 |
Â
public function callback_mercator_mapping_made_primary( $mapping ) {
|
118 |
Â
$blog_id = $mapping->get_site_id();
|
119 |
Â
$blog = get_site( $blog_id );
|
120 |
Â
|
121 |
Â
$this->log(
|
122 |
-
|
123 |
Â
_x(
|
124 |
Â
'"%1$s" domain alias was make primary for "%2$s"',
|
125 |
Â
'1. Domain alias 2. Site name',
|
@@ -138,8 +146,8 @@ class Connector_Mercator extends Connector {
|
|
138 |
Â
/**
|
139 |
Â
* Log if domain alias is updated.
|
140 |
Â
*
|
141 |
-
* @param $mapping
|
142 |
-
* @param $old_mapping
|
143 |
Â
*/
|
144 |
Â
public function callback_mercator_mapping_updated( $mapping, $old_mapping ) {
|
145 |
Â
|
@@ -147,7 +155,7 @@ class Connector_Mercator extends Connector {
|
|
147 |
Â
$blog = get_site( $blog_id );
|
148 |
Â
|
149 |
Â
$this->log(
|
150 |
-
|
151 |
Â
_x(
|
152 |
Â
'The domain alias "%1$s" was updated to "%2$s" for site "%3$s"',
|
153 |
Â
'1. Old Domain alias 2. Domain alias 2. Site name',
|
@@ -168,7 +176,7 @@ class Connector_Mercator extends Connector {
|
|
168 |
Â
/**
|
169 |
Â
* Log if domain alias is deleted.
|
170 |
Â
*
|
171 |
-
* @param $mapping
|
172 |
Â
*/
|
173 |
Â
public function callback_mercator_mapping_deleted( $mapping ) {
|
174 |
Â
|
@@ -176,7 +184,7 @@ class Connector_Mercator extends Connector {
|
|
176 |
Â
$blog = get_site( $blog_id );
|
177 |
Â
|
178 |
Â
$this->log(
|
179 |
-
|
180 |
Â
_x(
|
181 |
Â
'"%1$s" domain alias was deleted for "%2$s"',
|
182 |
Â
'1. Domain alias 2. Site name',
|
@@ -196,14 +204,14 @@ class Connector_Mercator extends Connector {
|
|
196 |
Â
/**
|
197 |
Â
* Log if domain alias is created.
|
198 |
Â
*
|
199 |
-
* @param $mapping
|
200 |
Â
*/
|
201 |
Â
public function callback_mercator_mapping_created( $mapping ) {
|
202 |
Â
$blog_id = $mapping->get_site_id();
|
203 |
Â
$blog = get_site( $blog_id );
|
204 |
Â
|
205 |
Â
$this->log(
|
206 |
-
|
207 |
Â
_x(
|
208 |
Â
'"%1$s" domain alias was created for "%2$s"',
|
209 |
Â
'1. Domain alias 2. Site name',
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for Mercator
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
Â
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_Mercator
|
12 |
+
*/
|
13 |
Â
class Connector_Mercator extends Connector {
|
14 |
Â
/**
|
15 |
Â
* Connector slug
|
73 |
Â
|
74 |
Â
foreach ( $blogs as $blog ) {
|
75 |
Â
$blog_details = get_site( $blog->blog_id );
|
76 |
+
$key = sprintf( 'blog-%d', $blog->blog_id );
|
77 |
Â
$labels[ $key ] = $blog_details->blogname;
|
78 |
Â
}
|
79 |
Â
}
|
86 |
Â
*
|
87 |
Â
* @filter wp_stream_action_links_{connector}
|
88 |
Â
*
|
89 |
+
* @param array $links Previous links registered.
|
90 |
+
* @param object $record Stream record.
|
91 |
Â
*
|
92 |
Â
* @return array
|
93 |
Â
*/
|
120 |
Â
/**
|
121 |
Â
* Log if domain is made primary.
|
122 |
Â
*
|
123 |
+
* @param object $mapping Mapping object.
|
124 |
Â
*/
|
125 |
Â
public function callback_mercator_mapping_made_primary( $mapping ) {
|
126 |
Â
$blog_id = $mapping->get_site_id();
|
127 |
Â
$blog = get_site( $blog_id );
|
128 |
Â
|
129 |
Â
$this->log(
|
130 |
+
/* translators: %1$s: domain alias, %2$s: site name (e.g. "FooBar Blog") */
|
131 |
Â
_x(
|
132 |
Â
'"%1$s" domain alias was make primary for "%2$s"',
|
133 |
Â
'1. Domain alias 2. Site name',
|
146 |
Â
/**
|
147 |
Â
* Log if domain alias is updated.
|
148 |
Â
*
|
149 |
+
* @param object $mapping Mapping object.
|
150 |
+
* @param object $old_mapping Old mapping object from before update.
|
151 |
Â
*/
|
152 |
Â
public function callback_mercator_mapping_updated( $mapping, $old_mapping ) {
|
153 |
Â
|
155 |
Â
$blog = get_site( $blog_id );
|
156 |
Â
|
157 |
Â
$this->log(
|
158 |
+
/* translators: %1$s: domain alias, %2$s: site name (e.g. "FooBar Blog") */
|
159 |
Â
_x(
|
160 |
Â
'The domain alias "%1$s" was updated to "%2$s" for site "%3$s"',
|
161 |
Â
'1. Old Domain alias 2. Domain alias 2. Site name',
|
176 |
Â
/**
|
177 |
Â
* Log if domain alias is deleted.
|
178 |
Â
*
|
179 |
+
* @param object $mapping Mapping of deleted alias.
|
180 |
Â
*/
|
181 |
Â
public function callback_mercator_mapping_deleted( $mapping ) {
|
182 |
Â
|
184 |
Â
$blog = get_site( $blog_id );
|
185 |
Â
|
186 |
Â
$this->log(
|
187 |
+
/* translators: %1$s: domain alias, %2$s: site name (e.g. "FooBar Blog") */
|
188 |
Â
_x(
|
189 |
Â
'"%1$s" domain alias was deleted for "%2$s"',
|
190 |
Â
'1. Domain alias 2. Site name',
|
204 |
Â
/**
|
205 |
Â
* Log if domain alias is created.
|
206 |
Â
*
|
207 |
+
* @param object $mapping Mapping object.
|
208 |
Â
*/
|
209 |
Â
public function callback_mercator_mapping_created( $mapping ) {
|
210 |
Â
$blog_id = $mapping->get_site_id();
|
211 |
Â
$blog = get_site( $blog_id );
|
212 |
Â
|
213 |
Â
$this->log(
|
214 |
+
/* translators: %1$s: domain alias, %2$s: site name (e.g. "FooBar Blog") */
|
215 |
Â
_x(
|
216 |
Â
'"%1$s" domain alias was created for "%2$s"',
|
217 |
Â
'1. Domain alias 2. Site name',
|
connectors/class-connector-posts.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_Posts extends Connector {
|
5 |
Â
/**
|
6 |
Â
* Connector slug
|
@@ -71,8 +80,8 @@ class Connector_Posts extends Connector {
|
|
71 |
Â
*
|
72 |
Â
* @filter wp_stream_action_links_{connector}
|
73 |
Â
*
|
74 |
-
* @param array $links Previous links registered
|
75 |
-
* @param Record $record
|
76 |
Â
*
|
77 |
Â
* @return array Action links
|
78 |
Â
*/
|
@@ -105,12 +114,12 @@ class Connector_Posts extends Connector {
|
|
105 |
Â
sprintf( 'delete-post_%d', $post->ID )
|
106 |
Â
);
|
107 |
Â
|
108 |
-
|
109 |
Â
$links[ sprintf( esc_html_x( 'Restore %s', 'Post type singular name', 'stream' ), $post_type_name ) ] = $untrash;
|
110 |
-
|
111 |
Â
$links[ sprintf( esc_html_x( 'Delete %s Permenantly', 'Post type singular name', 'stream' ), $post_type_name ) ] = $delete;
|
112 |
Â
} else {
|
113 |
-
|
114 |
Â
$links[ sprintf( esc_html_x( 'Edit %s', 'Post type singular name', 'stream' ), $post_type_name ) ] = get_edit_post_link( $post->ID );
|
115 |
Â
|
116 |
Â
$view_link = get_permalink( $post->ID );
|
@@ -135,8 +144,8 @@ class Connector_Posts extends Connector {
|
|
135 |
Â
*
|
136 |
Â
* @action registered_post_type
|
137 |
Â
*
|
138 |
-
* @param string $post_type Post type slug
|
139 |
-
* @param array $args Arguments used to register the post type
|
140 |
Â
*/
|
141 |
Â
public function registered_post_type( $post_type, $args ) {
|
142 |
Â
unset( $args );
|
@@ -152,9 +161,9 @@ class Connector_Posts extends Connector {
|
|
152 |
Â
*
|
153 |
Â
* @action transition_post_status
|
154 |
Â
*
|
155 |
-
* @param mixed $new
|
156 |
-
* @param mixed $old
|
157 |
-
* @param \WP_Post $post
|
158 |
Â
*/
|
159 |
Â
public function callback_transition_post_status( $new, $old, $post ) {
|
160 |
Â
if ( in_array( $post->post_type, $this->get_excluded_post_types(), true ) ) {
|
@@ -166,14 +175,14 @@ class Connector_Posts extends Connector {
|
|
166 |
Â
} elseif ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
167 |
Â
return;
|
168 |
Â
} elseif ( 'draft' === $new && 'publish' === $old ) {
|
169 |
-
|
170 |
Â
$summary = _x(
|
171 |
Â
'"%1$s" %2$s unpublished',
|
172 |
Â
'1: Post title, 2: Post type singular name',
|
173 |
Â
'stream'
|
174 |
Â
);
|
175 |
Â
} elseif ( 'trash' === $old && 'trash' !== $new ) {
|
176 |
-
|
177 |
Â
$summary = _x(
|
178 |
Â
'"%1$s" %2$s restored from trash',
|
179 |
Â
'1: Post title, 2: Post type singular name',
|
@@ -181,56 +190,56 @@ class Connector_Posts extends Connector {
|
|
181 |
Â
);
|
182 |
Â
$action = 'untrashed';
|
183 |
Â
} elseif ( 'draft' === $new && 'draft' === $old ) {
|
184 |
-
|
185 |
Â
$summary = _x(
|
186 |
Â
'"%1$s" %2$s draft saved',
|
187 |
Â
'1: Post title, 2: Post type singular name',
|
188 |
Â
'stream'
|
189 |
Â
);
|
190 |
Â
} elseif ( 'publish' === $new && 'draft' === $old ) {
|
191 |
-
|
192 |
Â
$summary = _x(
|
193 |
Â
'"%1$s" %2$s published',
|
194 |
Â
'1: Post title, 2: Post type singular name',
|
195 |
Â
'stream'
|
196 |
Â
);
|
197 |
Â
} elseif ( 'draft' === $new ) {
|
198 |
-
|
199 |
Â
$summary = _x(
|
200 |
Â
'"%1$s" %2$s drafted',
|
201 |
Â
'1: Post title, 2: Post type singular name',
|
202 |
Â
'stream'
|
203 |
Â
);
|
204 |
Â
} elseif ( 'pending' === $new ) {
|
205 |
-
|
206 |
Â
$summary = _x(
|
207 |
Â
'"%1$s" %2$s pending review',
|
208 |
Â
'1: Post title, 2: Post type singular name',
|
209 |
Â
'stream'
|
210 |
Â
);
|
211 |
Â
} elseif ( 'future' === $new ) {
|
212 |
-
|
213 |
Â
$summary = _x(
|
214 |
Â
'"%1$s" %2$s scheduled for %3$s',
|
215 |
Â
'1: Post title, 2: Post type singular name, 3: Scheduled post date',
|
216 |
Â
'stream'
|
217 |
Â
);
|
218 |
Â
} elseif ( 'future' === $old && 'publish' === $new ) {
|
219 |
-
|
220 |
Â
$summary = _x(
|
221 |
Â
'"%1$s" scheduled %2$s published',
|
222 |
Â
'1: Post title, 2: Post type singular name',
|
223 |
Â
'stream'
|
224 |
Â
);
|
225 |
Â
} elseif ( 'private' === $new ) {
|
226 |
-
|
227 |
Â
$summary = _x(
|
228 |
Â
'"%1$s" %2$s privately published',
|
229 |
Â
'1: Post title, 2: Post type singular name',
|
230 |
Â
'stream'
|
231 |
Â
);
|
232 |
Â
} elseif ( 'trash' === $new ) {
|
233 |
-
|
234 |
Â
$summary = _x(
|
235 |
Â
'"%1$s" %2$s trashed',
|
236 |
Â
'1: Post title, 2: Post type singular name',
|
@@ -238,7 +247,7 @@ class Connector_Posts extends Connector {
|
|
238 |
Â
);
|
239 |
Â
$action = 'trashed';
|
240 |
Â
} else {
|
241 |
-
|
242 |
Â
$summary = _x(
|
243 |
Â
'"%1$s" %2$s updated',
|
244 |
Â
'1: Post title, 2: Post type singular name',
|
@@ -262,7 +271,7 @@ class Connector_Posts extends Connector {
|
|
262 |
Â
'post_type' => 'revision',
|
263 |
Â
'post_status' => 'inherit',
|
264 |
Â
'post_parent' => $post->ID,
|
265 |
-
'posts_per_page' => 1, // VIP safe
|
266 |
Â
'orderby' => 'post_date',
|
267 |
Â
'order' => 'DESC',
|
268 |
Â
)
|
@@ -298,17 +307,17 @@ class Connector_Posts extends Connector {
|
|
298 |
Â
*
|
299 |
Â
* @action deleted_post
|
300 |
Â
*
|
301 |
-
*
|
302 |
Â
*/
|
303 |
Â
public function callback_deleted_post( $post_id ) {
|
304 |
Â
$post = get_post( $post_id );
|
305 |
Â
|
306 |
-
// We check if post is an instance of WP_Post as it doesn't always resolve in unit testing
|
307 |
Â
if ( ! ( $post instanceof \WP_Post ) || in_array( $post->post_type, $this->get_excluded_post_types(), true ) ) {
|
308 |
Â
return;
|
309 |
Â
}
|
310 |
Â
|
311 |
-
// Ignore auto-drafts that are deleted by the system, see issue-293
|
312 |
Â
if ( 'auto-draft' === $post->post_status ) {
|
313 |
Â
return;
|
314 |
Â
}
|
@@ -316,7 +325,7 @@ class Connector_Posts extends Connector {
|
|
316 |
Â
$post_type_name = strtolower( $this->get_post_type_name( $post->post_type ) );
|
317 |
Â
|
318 |
Â
$this->log(
|
319 |
-
|
320 |
Â
_x(
|
321 |
Â
'"%1$s" %2$s deleted from trash',
|
322 |
Â
'1: Post title, 2: Post type singular name',
|
@@ -351,12 +360,12 @@ class Connector_Posts extends Connector {
|
|
351 |
Â
/**
|
352 |
Â
* Gets the singular post type label
|
353 |
Â
*
|
354 |
-
* @param string $post_type_slug
|
355 |
Â
*
|
356 |
Â
* @return string Post type label
|
357 |
Â
*/
|
358 |
Â
public function get_post_type_name( $post_type_slug ) {
|
359 |
-
$name = esc_html__( 'Post', 'stream' ); // Default
|
360 |
Â
|
361 |
Â
if ( post_type_exists( $post_type_slug ) ) {
|
362 |
Â
$post_type = get_post_type_object( $post_type_slug );
|
@@ -369,8 +378,8 @@ class Connector_Posts extends Connector {
|
|
369 |
Â
/**
|
370 |
Â
* Get an adjacent post revision ID
|
371 |
Â
*
|
372 |
-
* @param int $revision_id
|
373 |
-
* @param bool $previous
|
374 |
Â
*
|
375 |
Â
* @return int $revision_id
|
376 |
Â
*/
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for Posts
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_Posts
|
12 |
+
*/
|
13 |
Â
class Connector_Posts extends Connector {
|
14 |
Â
/**
|
15 |
Â
* Connector slug
|
80 |
Â
*
|
81 |
Â
* @filter wp_stream_action_links_{connector}
|
82 |
Â
*
|
83 |
+
* @param array $links Previous links registered.
|
84 |
+
* @param Record $record Stream record.
|
85 |
Â
*
|
86 |
Â
* @return array Action links
|
87 |
Â
*/
|
114 |
Â
sprintf( 'delete-post_%d', $post->ID )
|
115 |
Â
);
|
116 |
Â
|
117 |
+
/* translators: %s: a post type singular name (e.g. "Post") */
|
118 |
Â
$links[ sprintf( esc_html_x( 'Restore %s', 'Post type singular name', 'stream' ), $post_type_name ) ] = $untrash;
|
119 |
+
/* translators: %s: a post type singular name (e.g. "Post") */
|
120 |
Â
$links[ sprintf( esc_html_x( 'Delete %s Permenantly', 'Post type singular name', 'stream' ), $post_type_name ) ] = $delete;
|
121 |
Â
} else {
|
122 |
+
/* translators: %s a post type singular name (e.g. "Post") */
|
123 |
Â
$links[ sprintf( esc_html_x( 'Edit %s', 'Post type singular name', 'stream' ), $post_type_name ) ] = get_edit_post_link( $post->ID );
|
124 |
Â
|
125 |
Â
$view_link = get_permalink( $post->ID );
|
144 |
Â
*
|
145 |
Â
* @action registered_post_type
|
146 |
Â
*
|
147 |
+
* @param string $post_type Post type slug.
|
148 |
+
* @param array $args Arguments used to register the post type.
|
149 |
Â
*/
|
150 |
Â
public function registered_post_type( $post_type, $args ) {
|
151 |
Â
unset( $args );
|
161 |
Â
*
|
162 |
Â
* @action transition_post_status
|
163 |
Â
*
|
164 |
+
* @param mixed $new New status.
|
165 |
+
* @param mixed $old Old status.
|
166 |
+
* @param \WP_Post $post Post object.
|
167 |
Â
*/
|
168 |
Â
public function callback_transition_post_status( $new, $old, $post ) {
|
169 |
Â
if ( in_array( $post->post_type, $this->get_excluded_post_types(), true ) ) {
|
175 |
Â
} elseif ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
176 |
Â
return;
|
177 |
Â
} elseif ( 'draft' === $new && 'publish' === $old ) {
|
178 |
+
/* translators: %1$s: a post title, %2$s: a post type singular name (e.g. "Hello World", "Post") */
|
179 |
Â
$summary = _x(
|
180 |
Â
'"%1$s" %2$s unpublished',
|
181 |
Â
'1: Post title, 2: Post type singular name',
|
182 |
Â
'stream'
|
183 |
Â
);
|
184 |
Â
} elseif ( 'trash' === $old && 'trash' !== $new ) {
|
185 |
+
/* translators: %1$s: a post title, %2$s: a post type singular name (e.g. "Hello World", "Post") */
|
186 |
Â
$summary = _x(
|
187 |
Â
'"%1$s" %2$s restored from trash',
|
188 |
Â
'1: Post title, 2: Post type singular name',
|
190 |
Â
);
|
191 |
Â
$action = 'untrashed';
|
192 |
Â
} elseif ( 'draft' === $new && 'draft' === $old ) {
|
193 |
+
/* translators: %1$s: a post title, %2$s: a post type singular name (e.g. "Hello World", "Post") */
|
194 |
Â
$summary = _x(
|
195 |
Â
'"%1$s" %2$s draft saved',
|
196 |
Â
'1: Post title, 2: Post type singular name',
|
197 |
Â
'stream'
|
198 |
Â
);
|
199 |
Â
} elseif ( 'publish' === $new && 'draft' === $old ) {
|
200 |
+
/* translators: %1$s: a post title, %2$s: a post type singular name (e.g. "Hello World", "Post") */
|
201 |
Â
$summary = _x(
|
202 |
Â
'"%1$s" %2$s published',
|
203 |
Â
'1: Post title, 2: Post type singular name',
|
204 |
Â
'stream'
|
205 |
Â
);
|
206 |
Â
} elseif ( 'draft' === $new ) {
|
207 |
+
/* translators: %1$s: a post title, %2$s a post type singular name (e.g. "Hello World", "Post") */
|
208 |
Â
$summary = _x(
|
209 |
Â
'"%1$s" %2$s drafted',
|
210 |
Â
'1: Post title, 2: Post type singular name',
|
211 |
Â
'stream'
|
212 |
Â
);
|
213 |
Â
} elseif ( 'pending' === $new ) {
|
214 |
+
/* translators: %1$s: a post title, %2$s: a post type singular name (e.g. "Hello World", "Post") */
|
215 |
Â
$summary = _x(
|
216 |
Â
'"%1$s" %2$s pending review',
|
217 |
Â
'1: Post title, 2: Post type singular name',
|
218 |
Â
'stream'
|
219 |
Â
);
|
220 |
Â
} elseif ( 'future' === $new ) {
|
221 |
+
/* translators: %1$s: a post title, %2$s: a post type singular name (e.g. "Hello World", "Post") */
|
222 |
Â
$summary = _x(
|
223 |
Â
'"%1$s" %2$s scheduled for %3$s',
|
224 |
Â
'1: Post title, 2: Post type singular name, 3: Scheduled post date',
|
225 |
Â
'stream'
|
226 |
Â
);
|
227 |
Â
} elseif ( 'future' === $old && 'publish' === $new ) {
|
228 |
+
/* translators: %1$s: a post title, %2$s: a post type singular name (e.g. "Hello World", "Post") */
|
229 |
Â
$summary = _x(
|
230 |
Â
'"%1$s" scheduled %2$s published',
|
231 |
Â
'1: Post title, 2: Post type singular name',
|
232 |
Â
'stream'
|
233 |
Â
);
|
234 |
Â
} elseif ( 'private' === $new ) {
|
235 |
+
/* translators: %1$s: a post title, %2$s: a post type singular name (e.g. "Hello World", "Post") */
|
236 |
Â
$summary = _x(
|
237 |
Â
'"%1$s" %2$s privately published',
|
238 |
Â
'1: Post title, 2: Post type singular name',
|
239 |
Â
'stream'
|
240 |
Â
);
|
241 |
Â
} elseif ( 'trash' === $new ) {
|
242 |
+
/* translators: %1$s: a post title, %2$s: a post type singular name (e.g. "Hello World", "Post") */
|
243 |
Â
$summary = _x(
|
244 |
Â
'"%1$s" %2$s trashed',
|
245 |
Â
'1: Post title, 2: Post type singular name',
|
247 |
Â
);
|
248 |
Â
$action = 'trashed';
|
249 |
Â
} else {
|
250 |
+
/* translators: %1$s: a post title, %2$s: a post type singular name (e.g. "Hello World", "Post") */
|
251 |
Â
$summary = _x(
|
252 |
Â
'"%1$s" %2$s updated',
|
253 |
Â
'1: Post title, 2: Post type singular name',
|
271 |
Â
'post_type' => 'revision',
|
272 |
Â
'post_status' => 'inherit',
|
273 |
Â
'post_parent' => $post->ID,
|
274 |
+
'posts_per_page' => 1, // VIP safe.
|
275 |
Â
'orderby' => 'post_date',
|
276 |
Â
'order' => 'DESC',
|
277 |
Â
)
|
307 |
Â
*
|
308 |
Â
* @action deleted_post
|
309 |
Â
*
|
310 |
+
* @param integer $post_id Post ID.
|
311 |
Â
*/
|
312 |
Â
public function callback_deleted_post( $post_id ) {
|
313 |
Â
$post = get_post( $post_id );
|
314 |
Â
|
315 |
+
// We check if post is an instance of WP_Post as it doesn't always resolve in unit testing.
|
316 |
Â
if ( ! ( $post instanceof \WP_Post ) || in_array( $post->post_type, $this->get_excluded_post_types(), true ) ) {
|
317 |
Â
return;
|
318 |
Â
}
|
319 |
Â
|
320 |
+
// Ignore auto-drafts that are deleted by the system, see issue-293.
|
321 |
Â
if ( 'auto-draft' === $post->post_status ) {
|
322 |
Â
return;
|
323 |
Â
}
|
325 |
Â
$post_type_name = strtolower( $this->get_post_type_name( $post->post_type ) );
|
326 |
Â
|
327 |
Â
$this->log(
|
328 |
+
/* translators: %1$s: a post title, %2$s: a post type singular name (e.g. "Hello World", "Post") */
|
329 |
Â
_x(
|
330 |
Â
'"%1$s" %2$s deleted from trash',
|
331 |
Â
'1: Post title, 2: Post type singular name',
|
360 |
Â
/**
|
361 |
Â
* Gets the singular post type label
|
362 |
Â
*
|
363 |
+
* @param string $post_type_slug Post type slug.
|
364 |
Â
*
|
365 |
Â
* @return string Post type label
|
366 |
Â
*/
|
367 |
Â
public function get_post_type_name( $post_type_slug ) {
|
368 |
+
$name = esc_html__( 'Post', 'stream' ); // Default.
|
369 |
Â
|
370 |
Â
if ( post_type_exists( $post_type_slug ) ) {
|
371 |
Â
$post_type = get_post_type_object( $post_type_slug );
|
378 |
Â
/**
|
379 |
Â
* Get an adjacent post revision ID
|
380 |
Â
*
|
381 |
+
* @param int $revision_id Revision ID.
|
382 |
+
* @param bool $previous Has there been any revision before this one?.
|
383 |
Â
*
|
384 |
Â
* @return int $revision_id
|
385 |
Â
*/
|
connectors/class-connector-settings.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_Settings extends Connector {
|
5 |
Â
/**
|
6 |
Â
* Prefix for the highlight URL hash
|
@@ -97,7 +106,7 @@ class Connector_Settings extends Connector {
|
|
97 |
Â
parent::register();
|
98 |
Â
|
99 |
Â
$this->labels = array(
|
100 |
-
// General
|
101 |
Â
'blogname' => esc_html__( 'Site Title', 'stream' ),
|
102 |
Â
'blogdescription' => esc_html__( 'Tagline', 'stream' ),
|
103 |
Â
'gmt_offset' => esc_html__( 'Timezone', 'stream' ),
|
@@ -111,7 +120,7 @@ class Connector_Settings extends Connector {
|
|
111 |
Â
'date_format' => esc_html__( 'Date Format', 'stream' ),
|
112 |
Â
'time_format' => esc_html__( 'Time Format', 'stream' ),
|
113 |
Â
'start_of_week' => esc_html__( 'Week Starts On', 'stream' ),
|
114 |
-
// Writing
|
115 |
Â
'use_smilies' => esc_html__( 'Formatting', 'stream' ),
|
116 |
Â
'use_balanceTags' => esc_html__( 'Formatting', 'stream' ),
|
117 |
Â
'default_category' => esc_html__( 'Default Post Category', 'stream' ),
|
@@ -122,7 +131,7 @@ class Connector_Settings extends Connector {
|
|
122 |
Â
'default_email_category' => esc_html__( 'Default Mail Category', 'stream' ),
|
123 |
Â
'default_link_category' => esc_html__( 'Default Link Category', 'stream' ),
|
124 |
Â
'ping_sites' => esc_html__( 'Update Services', 'stream' ),
|
125 |
-
// Reading
|
126 |
Â
'show_on_front' => esc_html__( 'Front page displays', 'stream' ),
|
127 |
Â
'page_on_front' => esc_html__( 'Front page displays', 'stream' ),
|
128 |
Â
'page_for_posts' => esc_html__( 'Front page displays', 'stream' ),
|
@@ -130,7 +139,7 @@ class Connector_Settings extends Connector {
|
|
130 |
Â
'posts_per_rss' => esc_html__( 'Syndication feeds show the most recent', 'stream' ),
|
131 |
Â
'rss_use_excerpt' => esc_html__( 'For each article in a feed, show', 'stream' ),
|
132 |
Â
'blog_public' => esc_html__( 'Search Engine Visibility', 'stream' ),
|
133 |
-
// Discussion
|
134 |
Â
'default_pingback_flag' => esc_html__( 'Default article settings', 'stream' ),
|
135 |
Â
'default_ping_status' => esc_html__( 'Default article settings', 'stream' ),
|
136 |
Â
'default_comment_status' => esc_html__( 'Default article settings', 'stream' ),
|
@@ -154,7 +163,7 @@ class Connector_Settings extends Connector {
|
|
154 |
Â
'show_avatars' => esc_html__( 'Show Avatars', 'stream' ),
|
155 |
Â
'avatar_rating' => esc_html__( 'Maximum Rating', 'stream' ),
|
156 |
Â
'avatar_default' => esc_html__( 'Default Avatar', 'stream' ),
|
157 |
-
// Media
|
158 |
Â
'thumbnail_size_w' => esc_html__( 'Thumbnail size', 'stream' ),
|
159 |
Â
'thumbnail_size_h' => esc_html__( 'Thumbnail size', 'stream' ),
|
160 |
Â
'thumbnail_crop' => esc_html__( 'Thumbnail size', 'stream' ),
|
@@ -163,11 +172,11 @@ class Connector_Settings extends Connector {
|
|
163 |
Â
'large_size_w' => esc_html__( 'Large size', 'stream' ),
|
164 |
Â
'large_size_h' => esc_html__( 'Large size', 'stream' ),
|
165 |
Â
'uploads_use_yearmonth_folders' => esc_html__( 'Uploading Files', 'stream' ),
|
166 |
-
// Permalinks
|
167 |
Â
'permalink_structure' => esc_html__( 'Permalink Settings', 'stream' ),
|
168 |
Â
'category_base' => esc_html__( 'Category base', 'stream' ),
|
169 |
Â
'tag_base' => esc_html__( 'Tag base', 'stream' ),
|
170 |
-
// Network
|
171 |
Â
'registrationnotification' => esc_html__( 'Registration notification', 'stream' ),
|
172 |
Â
'registration' => esc_html__( 'Allow new registrations', 'stream' ),
|
173 |
Â
'add_new_users' => esc_html__( 'Add New Users', 'stream' ),
|
@@ -191,11 +200,11 @@ class Connector_Settings extends Connector {
|
|
191 |
Â
'WPLANG' => esc_html__( 'Network Language', 'stream' ),
|
192 |
Â
'blog_count' => esc_html__( 'Blog Count', 'stream' ),
|
193 |
Â
'user_count' => esc_html__( 'User Count', 'stream' ),
|
194 |
-
// Other
|
195 |
Â
'wp_stream_db' => esc_html__( 'Stream Database Version', 'stream' ),
|
196 |
Â
);
|
197 |
Â
|
198 |
-
// These option labels are special and need to change based on multisite context
|
199 |
Â
if ( is_network_admin() ) {
|
200 |
Â
$this->labels['admin_email'] = esc_html__( 'Network Admin Email', 'stream' );
|
201 |
Â
$this->labels['new_admin_email'] = esc_html__( 'Network Admin Email', 'stream' );
|
@@ -207,10 +216,12 @@ class Connector_Settings extends Connector {
|
|
207 |
Â
}
|
208 |
Â
|
209 |
Â
/**
|
Â
|
|
Â
|
|
210 |
Â
* @action update_option_theme_mods_{name}
|
211 |
Â
*
|
212 |
-
* @param mixed $old_value
|
213 |
-
* @param mixed $new_value
|
214 |
Â
*/
|
215 |
Â
public function log_theme_modification( $old_value, $new_value ) {
|
216 |
Â
$this->callback_updated_option( 'theme_mods', $old_value, $new_value );
|
@@ -272,8 +283,8 @@ class Connector_Settings extends Connector {
|
|
272 |
Â
/**
|
273 |
Â
* Return context by option name and key
|
274 |
Â
*
|
275 |
-
* @param string $option_name
|
276 |
-
* @param string $key
|
277 |
Â
*
|
278 |
Â
* @return string Context slug
|
279 |
Â
*/
|
@@ -308,8 +319,8 @@ class Connector_Settings extends Connector {
|
|
308 |
Â
/**
|
309 |
Â
* Find out if the option key should be ignored and not logged
|
310 |
Â
*
|
311 |
-
* @param string $option_name
|
312 |
-
* @param string $key
|
313 |
Â
*
|
314 |
Â
* @return bool Whether option key is ignored or not
|
315 |
Â
*/
|
@@ -331,7 +342,7 @@ class Connector_Settings extends Connector {
|
|
331 |
Â
/**
|
332 |
Â
* Find out if the option should be ignored and not logged
|
333 |
Â
*
|
334 |
-
* @param string $option_name
|
335 |
Â
*
|
336 |
Â
* @return bool Whether the option is ignored or not
|
337 |
Â
*/
|
@@ -344,19 +355,33 @@ class Connector_Settings extends Connector {
|
|
344 |
Â
return true;
|
345 |
Â
}
|
346 |
Â
|
347 |
-
$
|
348 |
Â
'image_default_link_type',
|
349 |
Â
'medium_large_size_w',
|
350 |
Â
'medium_large_size_h',
|
351 |
Â
);
|
352 |
Â
|
353 |
-
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
354 |
Â
}
|
355 |
Â
|
356 |
Â
/**
|
357 |
Â
* Find out if array keys in the option should be logged separately
|
358 |
Â
*
|
359 |
-
* @param mixed $value
|
360 |
Â
*
|
361 |
Â
* @return bool Whether the option should be treated as a group
|
362 |
Â
*/
|
@@ -375,7 +400,7 @@ class Connector_Settings extends Connector {
|
|
375 |
Â
/**
|
376 |
Â
* Return translated labels for all default Settings fields found in WordPress.
|
377 |
Â
*
|
378 |
-
* @param string $field_key
|
379 |
Â
*
|
380 |
Â
* @return array Field label translations
|
381 |
Â
*/
|
@@ -400,29 +425,29 @@ class Connector_Settings extends Connector {
|
|
400 |
Â
/**
|
401 |
Â
* Return translated labels for all serialized Settings found in WordPress.
|
402 |
Â
*
|
403 |
-
* @param string $option_name
|
404 |
-
* @param string $field_key
|
405 |
Â
*
|
406 |
Â
* @return string Field key translation or key itself if not found
|
407 |
Â
*/
|
408 |
Â
public function get_serialized_field_label( $option_name, $field_key ) {
|
409 |
Â
$labels = array(
|
410 |
Â
'theme_mods' => array(
|
411 |
-
// Custom Background
|
412 |
Â
'background_image' => esc_html__( 'Background Image', 'stream' ),
|
413 |
Â
'background_position_x' => esc_html__( 'Background Position', 'stream' ),
|
414 |
Â
'background_repeat' => esc_html__( 'Background Repeat', 'stream' ),
|
415 |
Â
'background_attachment' => esc_html__( 'Background Attachment', 'stream' ),
|
416 |
Â
'background_color' => esc_html__( 'Background Color', 'stream' ),
|
417 |
-
// Custom Header
|
418 |
Â
'header_image' => esc_html__( 'Header Image', 'stream' ),
|
419 |
Â
'header_textcolor' => esc_html__( 'Text Color', 'stream' ),
|
420 |
Â
'header_background_color' => esc_html__( 'Header and Sidebar Background Color', 'stream' ),
|
421 |
-
// Featured Content
|
422 |
Â
'featured_content_layout' => esc_html__( 'Layout', 'stream' ),
|
423 |
-
// Custom Sidebar
|
424 |
Â
'sidebar_textcolor' => esc_html__( 'Header and Sidebar Text Color', 'stream' ),
|
425 |
-
// Custom Colors
|
426 |
Â
'color_scheme' => esc_html__( 'Color Scheme', 'stream' ),
|
427 |
Â
'main_text_color' => esc_html__( 'Main Text Color', 'stream' ),
|
428 |
Â
'secondary_text_color' => esc_html__( 'Secondary Text Color', 'stream' ),
|
@@ -451,8 +476,8 @@ class Connector_Settings extends Connector {
|
|
451 |
Â
*
|
452 |
Â
* @filter wp_stream_action_links_{connector}
|
453 |
Â
*
|
454 |
-
* @param array $links Previous links registered
|
455 |
-
* @param Record $record
|
456 |
Â
*
|
457 |
Â
* @return array Action links
|
458 |
Â
*/
|
@@ -544,7 +569,7 @@ class Connector_Settings extends Connector {
|
|
544 |
Â
);
|
545 |
Â
|
546 |
Â
if ( ! empty( $applicable_rules ) ) {
|
547 |
-
// The first applicable rule wins
|
548 |
Â
$rule = array_shift( $applicable_rules );
|
549 |
Â
$menu_slug = $rule['menu_slug'];
|
550 |
Â
$submenu_slug = ( is_object( $rule['submenu_slug'] ) && $rule['submenu_slug'] instanceof Closure ? $rule['submenu_slug']( $record ) : $rule['submenu_slug'] );
|
@@ -567,7 +592,7 @@ class Connector_Settings extends Connector {
|
|
567 |
Â
$url = apply_filters( 'wp_stream_action_link_url', $url, $record );
|
568 |
Â
$field_name = $record->get_meta( 'option_key', true );
|
569 |
Â
|
570 |
-
|
571 |
Â
$text = sprintf( esc_html__( 'Edit %s Settings', 'stream' ), $context_labels[ $record->context ] );
|
572 |
Â
|
573 |
Â
if ( '' === $field_name ) {
|
@@ -592,9 +617,9 @@ class Connector_Settings extends Connector {
|
|
592 |
Â
*
|
593 |
Â
* @action update_option
|
594 |
Â
*
|
595 |
-
* @param string $option
|
596 |
-
* @param mixed $
|
597 |
-
* @param mixed $value
|
598 |
Â
*/
|
599 |
Â
public function callback_update_option( $option, $value, $old_value ) {
|
600 |
Â
if ( ( defined( '\WP_CLI' ) && \WP_CLI || did_action( 'customize_save' ) ) && array_key_exists( $option, $this->labels ) ) {
|
@@ -607,7 +632,7 @@ class Connector_Settings extends Connector {
|
|
607 |
Â
*
|
608 |
Â
* @action whitelist_options
|
609 |
Â
*
|
610 |
-
* @param array $options
|
611 |
Â
*
|
612 |
Â
* @return array
|
613 |
Â
*/
|
@@ -622,8 +647,8 @@ class Connector_Settings extends Connector {
|
|
622 |
Â
*
|
623 |
Â
* @action update_option_permalink_structure
|
624 |
Â
*
|
625 |
-
* @param mixed $old_value
|
626 |
-
* @param mixed $value
|
627 |
Â
*/
|
628 |
Â
public function callback_update_option_permalink_structure( $old_value, $value ) {
|
629 |
Â
$this->callback_updated_option( 'permalink_structure', $old_value, $value );
|
@@ -634,9 +659,9 @@ class Connector_Settings extends Connector {
|
|
634 |
Â
*
|
635 |
Â
* @action update_site_option
|
636 |
Â
*
|
637 |
-
* @param string $option
|
638 |
-
* @param mixed $
|
639 |
-
* @param mixed $value
|
640 |
Â
*/
|
641 |
Â
public function callback_update_site_option( $option, $value, $old_value ) {
|
642 |
Â
$this->callback_updated_option( $option, $value, $old_value );
|
@@ -647,8 +672,8 @@ class Connector_Settings extends Connector {
|
|
647 |
Â
*
|
648 |
Â
* @action update_option_category_base
|
649 |
Â
*
|
650 |
-
* @param mixed $old_value
|
651 |
-
* @param mixed $value
|
652 |
Â
*/
|
653 |
Â
public function callback_update_option_category_base( $old_value, $value ) {
|
654 |
Â
$this->callback_updated_option( 'category_base', $old_value, $value );
|
@@ -659,8 +684,8 @@ class Connector_Settings extends Connector {
|
|
659 |
Â
*
|
660 |
Â
* @action update_option_tag_base
|
661 |
Â
*
|
662 |
-
* @param mixed $old_value
|
663 |
-
* @param mixed $value
|
664 |
Â
*/
|
665 |
Â
public function callback_update_option_tag_base( $old_value, $value ) {
|
666 |
Â
$this->callback_updated_option( 'tag_base', $old_value, $value );
|
@@ -671,9 +696,9 @@ class Connector_Settings extends Connector {
|
|
671 |
Â
*
|
672 |
Â
* @action updated_option
|
673 |
Â
*
|
674 |
-
* @param string $option
|
675 |
-
* @param mixed $old_value
|
676 |
-
* @param mixed $value
|
677 |
Â
*/
|
678 |
Â
public function callback_updated_option( $option, $old_value, $value ) {
|
679 |
Â
global $whitelist_options, $new_whitelist_options;
|
@@ -732,7 +757,7 @@ class Connector_Settings extends Connector {
|
|
732 |
Â
|
733 |
Â
foreach ( $changed_options as $properties ) {
|
734 |
Â
$this->log(
|
735 |
-
|
736 |
Â
__( '"%s" setting was updated', 'stream' ),
|
737 |
Â
$properties,
|
738 |
Â
null,
|
@@ -752,7 +777,7 @@ class Connector_Settings extends Connector {
|
|
752 |
Â
<script>
|
753 |
Â
(function ($) {
|
754 |
Â
$(function () {
|
755 |
-
var hashPrefix = <?php echo wp_stream_json_encode( self::HIGHLIGHT_FIELD_URL_HASH_PREFIX ); // xss ok ?>,
|
756 |
Â
hashFieldName = "",
|
757 |
Â
fieldNames = [],
|
758 |
Â
$select2Choices = {},
|
@@ -818,9 +843,9 @@ class Connector_Settings extends Connector {
|
|
818 |
Â
* @deprecated Use is_option_group()
|
819 |
Â
* @see is_option_group()
|
820 |
Â
*
|
821 |
-
* @param string $key
|
822 |
-
* @param mixed $old_value
|
823 |
-
* @param mixed $value
|
824 |
Â
*
|
825 |
Â
* @return bool Whether the option should be treated as a group
|
826 |
Â
*/
|
@@ -832,7 +857,7 @@ class Connector_Settings extends Connector {
|
|
832 |
Â
/**
|
833 |
Â
* Sanitize values, so that we don't store complex data, such as arrays or objects
|
834 |
Â
*
|
835 |
-
* @param mixed $value
|
836 |
Â
* @return string
|
837 |
Â
*/
|
838 |
Â
public function sanitize_value( $value ) {
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for Settings
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_Settings
|
12 |
+
*/
|
13 |
Â
class Connector_Settings extends Connector {
|
14 |
Â
/**
|
15 |
Â
* Prefix for the highlight URL hash
|
106 |
Â
parent::register();
|
107 |
Â
|
108 |
Â
$this->labels = array(
|
109 |
+
// General.
|
110 |
Â
'blogname' => esc_html__( 'Site Title', 'stream' ),
|
111 |
Â
'blogdescription' => esc_html__( 'Tagline', 'stream' ),
|
112 |
Â
'gmt_offset' => esc_html__( 'Timezone', 'stream' ),
|
120 |
Â
'date_format' => esc_html__( 'Date Format', 'stream' ),
|
121 |
Â
'time_format' => esc_html__( 'Time Format', 'stream' ),
|
122 |
Â
'start_of_week' => esc_html__( 'Week Starts On', 'stream' ),
|
123 |
+
// Writing.
|
124 |
Â
'use_smilies' => esc_html__( 'Formatting', 'stream' ),
|
125 |
Â
'use_balanceTags' => esc_html__( 'Formatting', 'stream' ),
|
126 |
Â
'default_category' => esc_html__( 'Default Post Category', 'stream' ),
|
131 |
Â
'default_email_category' => esc_html__( 'Default Mail Category', 'stream' ),
|
132 |
Â
'default_link_category' => esc_html__( 'Default Link Category', 'stream' ),
|
133 |
Â
'ping_sites' => esc_html__( 'Update Services', 'stream' ),
|
134 |
+
// Reading.
|
135 |
Â
'show_on_front' => esc_html__( 'Front page displays', 'stream' ),
|
136 |
Â
'page_on_front' => esc_html__( 'Front page displays', 'stream' ),
|
137 |
Â
'page_for_posts' => esc_html__( 'Front page displays', 'stream' ),
|
139 |
Â
'posts_per_rss' => esc_html__( 'Syndication feeds show the most recent', 'stream' ),
|
140 |
Â
'rss_use_excerpt' => esc_html__( 'For each article in a feed, show', 'stream' ),
|
141 |
Â
'blog_public' => esc_html__( 'Search Engine Visibility', 'stream' ),
|
142 |
+
// Discussion.
|
143 |
Â
'default_pingback_flag' => esc_html__( 'Default article settings', 'stream' ),
|
144 |
Â
'default_ping_status' => esc_html__( 'Default article settings', 'stream' ),
|
145 |
Â
'default_comment_status' => esc_html__( 'Default article settings', 'stream' ),
|
163 |
Â
'show_avatars' => esc_html__( 'Show Avatars', 'stream' ),
|
164 |
Â
'avatar_rating' => esc_html__( 'Maximum Rating', 'stream' ),
|
165 |
Â
'avatar_default' => esc_html__( 'Default Avatar', 'stream' ),
|
166 |
+
// Media.
|
167 |
Â
'thumbnail_size_w' => esc_html__( 'Thumbnail size', 'stream' ),
|
168 |
Â
'thumbnail_size_h' => esc_html__( 'Thumbnail size', 'stream' ),
|
169 |
Â
'thumbnail_crop' => esc_html__( 'Thumbnail size', 'stream' ),
|
172 |
Â
'large_size_w' => esc_html__( 'Large size', 'stream' ),
|
173 |
Â
'large_size_h' => esc_html__( 'Large size', 'stream' ),
|
174 |
Â
'uploads_use_yearmonth_folders' => esc_html__( 'Uploading Files', 'stream' ),
|
175 |
+
// Permalinks.
|
176 |
Â
'permalink_structure' => esc_html__( 'Permalink Settings', 'stream' ),
|
177 |
Â
'category_base' => esc_html__( 'Category base', 'stream' ),
|
178 |
Â
'tag_base' => esc_html__( 'Tag base', 'stream' ),
|
179 |
+
// Network.
|
180 |
Â
'registrationnotification' => esc_html__( 'Registration notification', 'stream' ),
|
181 |
Â
'registration' => esc_html__( 'Allow new registrations', 'stream' ),
|
182 |
Â
'add_new_users' => esc_html__( 'Add New Users', 'stream' ),
|
200 |
Â
'WPLANG' => esc_html__( 'Network Language', 'stream' ),
|
201 |
Â
'blog_count' => esc_html__( 'Blog Count', 'stream' ),
|
202 |
Â
'user_count' => esc_html__( 'User Count', 'stream' ),
|
203 |
+
// Other.
|
204 |
Â
'wp_stream_db' => esc_html__( 'Stream Database Version', 'stream' ),
|
205 |
Â
);
|
206 |
Â
|
207 |
+
// These option labels are special and need to change based on multisite context.
|
208 |
Â
if ( is_network_admin() ) {
|
209 |
Â
$this->labels['admin_email'] = esc_html__( 'Network Admin Email', 'stream' );
|
210 |
Â
$this->labels['new_admin_email'] = esc_html__( 'Network Admin Email', 'stream' );
|
216 |
Â
}
|
217 |
Â
|
218 |
Â
/**
|
219 |
+
* Logs changes to the theme modifications.
|
220 |
+
*
|
221 |
Â
* @action update_option_theme_mods_{name}
|
222 |
Â
*
|
223 |
+
* @param mixed $old_value Old setting value.
|
224 |
+
* @param mixed $new_value New setting value.
|
225 |
Â
*/
|
226 |
Â
public function log_theme_modification( $old_value, $new_value ) {
|
227 |
Â
$this->callback_updated_option( 'theme_mods', $old_value, $new_value );
|
283 |
Â
/**
|
284 |
Â
* Return context by option name and key
|
285 |
Â
*
|
286 |
+
* @param string $option_name Option name.
|
287 |
+
* @param string $key Option key.
|
288 |
Â
*
|
289 |
Â
* @return string Context slug
|
290 |
Â
*/
|
319 |
Â
/**
|
320 |
Â
* Find out if the option key should be ignored and not logged
|
321 |
Â
*
|
322 |
+
* @param string $option_name Option name.
|
323 |
+
* @param string $key Option key.
|
324 |
Â
*
|
325 |
Â
* @return bool Whether option key is ignored or not
|
326 |
Â
*/
|
342 |
Â
/**
|
343 |
Â
* Find out if the option should be ignored and not logged
|
344 |
Â
*
|
345 |
+
* @param string $option_name Option name.
|
346 |
Â
*
|
347 |
Â
* @return bool Whether the option is ignored or not
|
348 |
Â
*/
|
355 |
Â
return true;
|
356 |
Â
}
|
357 |
Â
|
358 |
+
$default_ignored = array(
|
359 |
Â
'image_default_link_type',
|
360 |
Â
'medium_large_size_w',
|
361 |
Â
'medium_large_size_h',
|
362 |
Â
);
|
363 |
Â
|
364 |
+
/**
|
365 |
+
* Filters the boolean output for is_option_ignored().
|
366 |
+
*
|
367 |
+
* @param boolean $is_ignored True if ignored, otherwise false.
|
368 |
+
* @param string $option_name Current option name.
|
369 |
+
* @param array $default_ignored Default options for Stream to ignore.
|
370 |
+
*
|
371 |
+
* @return boolean
|
372 |
+
*/
|
373 |
+
return apply_filters(
|
374 |
+
'wp_stream_is_option_ignored',
|
375 |
+
in_array( $option_name, $default_ignored, true ),
|
376 |
+
$option_name,
|
377 |
+
$default_ignored
|
378 |
+
);
|
379 |
Â
}
|
380 |
Â
|
381 |
Â
/**
|
382 |
Â
* Find out if array keys in the option should be logged separately
|
383 |
Â
*
|
384 |
+
* @param mixed $value Option value.
|
385 |
Â
*
|
386 |
Â
* @return bool Whether the option should be treated as a group
|
387 |
Â
*/
|
400 |
Â
/**
|
401 |
Â
* Return translated labels for all default Settings fields found in WordPress.
|
402 |
Â
*
|
403 |
+
* @param string $field_key Field key.
|
404 |
Â
*
|
405 |
Â
* @return array Field label translations
|
406 |
Â
*/
|
425 |
Â
/**
|
426 |
Â
* Return translated labels for all serialized Settings found in WordPress.
|
427 |
Â
*
|
428 |
+
* @param string $option_name Option name.
|
429 |
+
* @param string $field_key Field key.
|
430 |
Â
*
|
431 |
Â
* @return string Field key translation or key itself if not found
|
432 |
Â
*/
|
433 |
Â
public function get_serialized_field_label( $option_name, $field_key ) {
|
434 |
Â
$labels = array(
|
435 |
Â
'theme_mods' => array(
|
436 |
+
// Custom Background.
|
437 |
Â
'background_image' => esc_html__( 'Background Image', 'stream' ),
|
438 |
Â
'background_position_x' => esc_html__( 'Background Position', 'stream' ),
|
439 |
Â
'background_repeat' => esc_html__( 'Background Repeat', 'stream' ),
|
440 |
Â
'background_attachment' => esc_html__( 'Background Attachment', 'stream' ),
|
441 |
Â
'background_color' => esc_html__( 'Background Color', 'stream' ),
|
442 |
+
// Custom Header.
|
443 |
Â
'header_image' => esc_html__( 'Header Image', 'stream' ),
|
444 |
Â
'header_textcolor' => esc_html__( 'Text Color', 'stream' ),
|
445 |
Â
'header_background_color' => esc_html__( 'Header and Sidebar Background Color', 'stream' ),
|
446 |
+
// Featured Content.
|
447 |
Â
'featured_content_layout' => esc_html__( 'Layout', 'stream' ),
|
448 |
+
// Custom Sidebar.
|
449 |
Â
'sidebar_textcolor' => esc_html__( 'Header and Sidebar Text Color', 'stream' ),
|
450 |
+
// Custom Colors.
|
451 |
Â
'color_scheme' => esc_html__( 'Color Scheme', 'stream' ),
|
452 |
Â
'main_text_color' => esc_html__( 'Main Text Color', 'stream' ),
|
453 |
Â
'secondary_text_color' => esc_html__( 'Secondary Text Color', 'stream' ),
|
476 |
Â
*
|
477 |
Â
* @filter wp_stream_action_links_{connector}
|
478 |
Â
*
|
479 |
+
* @param array $links Previous links registered.
|
480 |
+
* @param Record $record Stream record.
|
481 |
Â
*
|
482 |
Â
* @return array Action links
|
483 |
Â
*/
|
569 |
Â
);
|
570 |
Â
|
571 |
Â
if ( ! empty( $applicable_rules ) ) {
|
572 |
+
// The first applicable rule wins.
|
573 |
Â
$rule = array_shift( $applicable_rules );
|
574 |
Â
$menu_slug = $rule['menu_slug'];
|
575 |
Â
$submenu_slug = ( is_object( $rule['submenu_slug'] ) && $rule['submenu_slug'] instanceof Closure ? $rule['submenu_slug']( $record ) : $rule['submenu_slug'] );
|
592 |
Â
$url = apply_filters( 'wp_stream_action_link_url', $url, $record );
|
593 |
Â
$field_name = $record->get_meta( 'option_key', true );
|
594 |
Â
|
595 |
+
/* translators: %s: a context (e.g. "Editor") */
|
596 |
Â
$text = sprintf( esc_html__( 'Edit %s Settings', 'stream' ), $context_labels[ $record->context ] );
|
597 |
Â
|
598 |
Â
if ( '' === $field_name ) {
|
617 |
Â
*
|
618 |
Â
* @action update_option
|
619 |
Â
*
|
620 |
+
* @param string $option Option name.
|
621 |
+
* @param mixed $value Option new value.
|
622 |
+
* @param mixed $old_value Option old value.
|
623 |
Â
*/
|
624 |
Â
public function callback_update_option( $option, $value, $old_value ) {
|
625 |
Â
if ( ( defined( '\WP_CLI' ) && \WP_CLI || did_action( 'customize_save' ) ) && array_key_exists( $option, $this->labels ) ) {
|
632 |
Â
*
|
633 |
Â
* @action whitelist_options
|
634 |
Â
*
|
635 |
+
* @param array $options Options.
|
636 |
Â
*
|
637 |
Â
* @return array
|
638 |
Â
*/
|
647 |
Â
*
|
648 |
Â
* @action update_option_permalink_structure
|
649 |
Â
*
|
650 |
+
* @param mixed $old_value Option old value.
|
651 |
+
* @param mixed $value Option new value.
|
652 |
Â
*/
|
653 |
Â
public function callback_update_option_permalink_structure( $old_value, $value ) {
|
654 |
Â
$this->callback_updated_option( 'permalink_structure', $old_value, $value );
|
659 |
Â
*
|
660 |
Â
* @action update_site_option
|
661 |
Â
*
|
662 |
+
* @param string $option Option name.
|
663 |
+
* @param mixed $value Option new value.
|
664 |
+
* @param mixed $old_value Option old value.
|
665 |
Â
*/
|
666 |
Â
public function callback_update_site_option( $option, $value, $old_value ) {
|
667 |
Â
$this->callback_updated_option( $option, $value, $old_value );
|
672 |
Â
*
|
673 |
Â
* @action update_option_category_base
|
674 |
Â
*
|
675 |
+
* @param mixed $old_value Option old value.
|
676 |
+
* @param mixed $value Option new value.
|
677 |
Â
*/
|
678 |
Â
public function callback_update_option_category_base( $old_value, $value ) {
|
679 |
Â
$this->callback_updated_option( 'category_base', $old_value, $value );
|
684 |
Â
*
|
685 |
Â
* @action update_option_tag_base
|
686 |
Â
*
|
687 |
+
* @param mixed $old_value Option old value.
|
688 |
+
* @param mixed $value Option new value.
|
689 |
Â
*/
|
690 |
Â
public function callback_update_option_tag_base( $old_value, $value ) {
|
691 |
Â
$this->callback_updated_option( 'tag_base', $old_value, $value );
|
696 |
Â
*
|
697 |
Â
* @action updated_option
|
698 |
Â
*
|
699 |
+
* @param string $option Option name.
|
700 |
+
* @param mixed $old_value Option old value.
|
701 |
+
* @param mixed $value Option new value.
|
702 |
Â
*/
|
703 |
Â
public function callback_updated_option( $option, $old_value, $value ) {
|
704 |
Â
global $whitelist_options, $new_whitelist_options;
|
757 |
Â
|
758 |
Â
foreach ( $changed_options as $properties ) {
|
759 |
Â
$this->log(
|
760 |
+
/* translators: %s: a setting name (e.g. "Language") */
|
761 |
Â
__( '"%s" setting was updated', 'stream' ),
|
762 |
Â
$properties,
|
763 |
Â
null,
|
777 |
Â
<script>
|
778 |
Â
(function ($) {
|
779 |
Â
$(function () {
|
780 |
+
var hashPrefix = <?php echo wp_stream_json_encode( self::HIGHLIGHT_FIELD_URL_HASH_PREFIX ); // xss ok. ?>,
|
781 |
Â
hashFieldName = "",
|
782 |
Â
fieldNames = [],
|
783 |
Â
$select2Choices = {},
|
843 |
Â
* @deprecated Use is_option_group()
|
844 |
Â
* @see is_option_group()
|
845 |
Â
*
|
846 |
+
* @param string $key Key.
|
847 |
+
* @param mixed $old_value Old value.
|
848 |
+
* @param mixed $value New value.
|
849 |
Â
*
|
850 |
Â
* @return bool Whether the option should be treated as a group
|
851 |
Â
*/
|
857 |
Â
/**
|
858 |
Â
* Sanitize values, so that we don't store complex data, such as arrays or objects
|
859 |
Â
*
|
860 |
+
* @param mixed $value Raw input value.
|
861 |
Â
* @return string
|
862 |
Â
*/
|
863 |
Â
public function sanitize_value( $value ) {
|
connectors/class-connector-taxonomies.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_Taxonomies extends Connector {
|
5 |
Â
/**
|
6 |
Â
* Connector slug
|
@@ -86,13 +95,14 @@ class Connector_Taxonomies extends Connector {
|
|
86 |
Â
*
|
87 |
Â
* @filter wp_stream_action_links_{connector}
|
88 |
Â
*
|
89 |
-
* @param array $links
|
90 |
-
* @param Record $record
|
91 |
Â
*
|
92 |
Â
* @return array Action links
|
93 |
Â
*/
|
94 |
Â
public function action_links( $links, $record ) {
|
95 |
-
|
Â
|
|
96 |
Â
if ( $record->object_id && 'deleted' !== $record->action && $term ) {
|
97 |
Â
if ( ! is_wp_error( $term ) ) {
|
98 |
Â
$tax_obj = get_taxonomy( $term->taxonomy );
|
@@ -104,7 +114,7 @@ class Connector_Taxonomies extends Connector {
|
|
104 |
Â
|
105 |
Â
$term_id = empty( $term_id ) ? $term->term_id : $term_id;
|
106 |
Â
|
107 |
-
|
108 |
Â
$links[ sprintf( _x( 'Edit %s', 'Term singular name', 'stream' ), $tax_label ) ] = get_edit_term_link( $term_id, $term->taxonomy );
|
109 |
Â
$links[ esc_html__( 'View', 'stream' ) ] = wp_stream_is_vip() ? \wpcom_vip_get_term_link( $term_id, $term->taxonomy ) : get_term_link( $term_id, $term->taxonomy );
|
110 |
Â
}
|
@@ -118,9 +128,9 @@ class Connector_Taxonomies extends Connector {
|
|
118 |
Â
*
|
119 |
Â
* @action registered_taxonomy
|
120 |
Â
*
|
121 |
-
* @param string $taxonomy
|
122 |
-
* @param array|string $object_type
|
123 |
-
* @param array|string $args
|
124 |
Â
*/
|
125 |
Â
public function registered_taxonomy( $taxonomy, $object_type, $args ) {
|
126 |
Â
unset( $object_type );
|
@@ -138,9 +148,9 @@ class Connector_Taxonomies extends Connector {
|
|
138 |
Â
*
|
139 |
Â
* @action created_term
|
140 |
Â
*
|
141 |
-
* @param integer $term_id
|
142 |
-
* @param integer $tt_id
|
143 |
-
* @param string $taxonomy
|
144 |
Â
*/
|
145 |
Â
public function callback_created_term( $term_id, $tt_id, $taxonomy ) {
|
146 |
Â
if ( in_array( $taxonomy, $this->get_excluded_taxonomies(), true ) ) {
|
@@ -153,7 +163,7 @@ class Connector_Taxonomies extends Connector {
|
|
153 |
Â
$term_parent = $term->parent;
|
154 |
Â
|
155 |
Â
$this->log(
|
156 |
-
|
157 |
Â
_x(
|
158 |
Â
'"%1$s" %2$s created',
|
159 |
Â
'1: Term name, 2: Taxonomy singular label',
|
@@ -171,10 +181,10 @@ class Connector_Taxonomies extends Connector {
|
|
171 |
Â
*
|
172 |
Â
* @action delete_term
|
173 |
Â
*
|
174 |
-
* @param integer $term_id
|
175 |
-
* @param integer $tt_id
|
176 |
-
* @param string $taxonomy
|
177 |
-
* @param object $deleted_term
|
178 |
Â
*/
|
179 |
Â
public function callback_delete_term( $term_id, $tt_id, $taxonomy, $deleted_term ) {
|
180 |
Â
if ( in_array( $taxonomy, $this->get_excluded_taxonomies(), true ) ) {
|
@@ -186,7 +196,7 @@ class Connector_Taxonomies extends Connector {
|
|
186 |
Â
$taxonomy_label = strtolower( $this->context_labels[ $taxonomy ] );
|
187 |
Â
|
188 |
Â
$this->log(
|
189 |
-
|
190 |
Â
_x(
|
191 |
Â
'"%1$s" %2$s deleted',
|
192 |
Â
'1: Term name, 2: Taxonomy singular label',
|
@@ -204,15 +214,24 @@ class Connector_Taxonomies extends Connector {
|
|
204 |
Â
*
|
205 |
Â
* @action edit_term
|
206 |
Â
*
|
207 |
-
* @param integer $term_id
|
208 |
-
* @param integer $tt_id
|
209 |
-
* @param string $taxonomy
|
210 |
Â
*/
|
211 |
Â
public function callback_edit_term( $term_id, $tt_id, $taxonomy ) {
|
212 |
Â
unset( $tt_id );
|
213 |
Â
$this->cached_term_before_update = get_term( $term_id, $taxonomy );
|
214 |
Â
}
|
215 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
216 |
Â
public function callback_edited_term( $term_id, $tt_id, $taxonomy ) {
|
217 |
Â
if ( in_array( $taxonomy, $this->get_excluded_taxonomies(), true ) ) {
|
218 |
Â
return;
|
@@ -229,7 +248,7 @@ class Connector_Taxonomies extends Connector {
|
|
229 |
Â
$term_parent = $term->parent;
|
230 |
Â
|
231 |
Â
$this->log(
|
232 |
-
|
233 |
Â
_x(
|
234 |
Â
'"%1$s" %2$s updated',
|
235 |
Â
'1: Term name, 2: Taxonomy singular label',
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for Taxonomies
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_Taxonomies
|
12 |
+
*/
|
13 |
Â
class Connector_Taxonomies extends Connector {
|
14 |
Â
/**
|
15 |
Â
* Connector slug
|
95 |
Â
*
|
96 |
Â
* @filter wp_stream_action_links_{connector}
|
97 |
Â
*
|
98 |
+
* @param array $links Previous links registered.
|
99 |
+
* @param Record $record Stream record.
|
100 |
Â
*
|
101 |
Â
* @return array Action links
|
102 |
Â
*/
|
103 |
Â
public function action_links( $links, $record ) {
|
104 |
+
// wpcom_vip_get_term_by() does not indicate support for `term_taxonomy_id`.
|
105 |
+
$term = get_term_by( 'term_taxonomy_id', $record->object_id, $record->context );
|
106 |
Â
if ( $record->object_id && 'deleted' !== $record->action && $term ) {
|
107 |
Â
if ( ! is_wp_error( $term ) ) {
|
108 |
Â
$tax_obj = get_taxonomy( $term->taxonomy );
|
114 |
Â
|
115 |
Â
$term_id = empty( $term_id ) ? $term->term_id : $term_id;
|
116 |
Â
|
117 |
+
/* translators: %s a term singular name (e.g. "Tag") */
|
118 |
Â
$links[ sprintf( _x( 'Edit %s', 'Term singular name', 'stream' ), $tax_label ) ] = get_edit_term_link( $term_id, $term->taxonomy );
|
119 |
Â
$links[ esc_html__( 'View', 'stream' ) ] = wp_stream_is_vip() ? \wpcom_vip_get_term_link( $term_id, $term->taxonomy ) : get_term_link( $term_id, $term->taxonomy );
|
120 |
Â
}
|
128 |
Â
*
|
129 |
Â
* @action registered_taxonomy
|
130 |
Â
*
|
131 |
+
* @param string $taxonomy Taxonomy slug.
|
132 |
+
* @param array|string $object_type Object type or array of object types.
|
133 |
+
* @param array|string $args Array or string of taxonomy registration arguments.
|
134 |
Â
*/
|
135 |
Â
public function registered_taxonomy( $taxonomy, $object_type, $args ) {
|
136 |
Â
unset( $object_type );
|
148 |
Â
*
|
149 |
Â
* @action created_term
|
150 |
Â
*
|
151 |
+
* @param integer $term_id Term ID.
|
152 |
+
* @param integer $tt_id Taxonomy term ID.
|
153 |
+
* @param string $taxonomy Taxonomy name.
|
154 |
Â
*/
|
155 |
Â
public function callback_created_term( $term_id, $tt_id, $taxonomy ) {
|
156 |
Â
if ( in_array( $taxonomy, $this->get_excluded_taxonomies(), true ) ) {
|
163 |
Â
$term_parent = $term->parent;
|
164 |
Â
|
165 |
Â
$this->log(
|
166 |
+
/* translators: %1$s: a term name, %2$s: a taxonomy singular label (e.g. "Tags", "Genre") */
|
167 |
Â
_x(
|
168 |
Â
'"%1$s" %2$s created',
|
169 |
Â
'1: Term name, 2: Taxonomy singular label',
|
181 |
Â
*
|
182 |
Â
* @action delete_term
|
183 |
Â
*
|
184 |
+
* @param integer $term_id Term ID.
|
185 |
+
* @param integer $tt_id Taxonomy term ID.
|
186 |
+
* @param string $taxonomy Taxonomy name.
|
187 |
+
* @param object $deleted_term Deleted term object.
|
188 |
Â
*/
|
189 |
Â
public function callback_delete_term( $term_id, $tt_id, $taxonomy, $deleted_term ) {
|
190 |
Â
if ( in_array( $taxonomy, $this->get_excluded_taxonomies(), true ) ) {
|
196 |
Â
$taxonomy_label = strtolower( $this->context_labels[ $taxonomy ] );
|
197 |
Â
|
198 |
Â
$this->log(
|
199 |
+
/* translators: %1$s: a term name, %2$s: a taxonomy singular label (e.g. "Tags", "Genre") */
|
200 |
Â
_x(
|
201 |
Â
'"%1$s" %2$s deleted',
|
202 |
Â
'1: Term name, 2: Taxonomy singular label',
|
214 |
Â
*
|
215 |
Â
* @action edit_term
|
216 |
Â
*
|
217 |
+
* @param integer $term_id Term ID.
|
218 |
+
* @param integer $tt_id Taxonomy term ID.
|
219 |
+
* @param string $taxonomy Taxonomy name.
|
220 |
Â
*/
|
221 |
Â
public function callback_edit_term( $term_id, $tt_id, $taxonomy ) {
|
222 |
Â
unset( $tt_id );
|
223 |
Â
$this->cached_term_before_update = get_term( $term_id, $taxonomy );
|
224 |
Â
}
|
225 |
Â
|
226 |
+
/**
|
227 |
+
* Tracks updated of taxonomy terms
|
228 |
+
*
|
229 |
+
* @action edited_term
|
230 |
+
*
|
231 |
+
* @param integer $term_id Term ID.
|
232 |
+
* @param integer $tt_id Taxonomy term ID.
|
233 |
+
* @param string $taxonomy Taxonomy name.
|
234 |
+
*/
|
235 |
Â
public function callback_edited_term( $term_id, $tt_id, $taxonomy ) {
|
236 |
Â
if ( in_array( $taxonomy, $this->get_excluded_taxonomies(), true ) ) {
|
237 |
Â
return;
|
248 |
Â
$term_parent = $term->parent;
|
249 |
Â
|
250 |
Â
$this->log(
|
251 |
+
/* translators: %1$s: a term name, %2$s: a taxonomy singular label (e.g. "Tags", "Genre") */
|
252 |
Â
_x(
|
253 |
Â
'"%1$s" %2$s updated',
|
254 |
Â
'1: Term name, 2: Taxonomy singular label',
|
connectors/class-connector-user-switching.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_User_Switching extends Connector {
|
5 |
Â
|
6 |
Â
/**
|
@@ -100,11 +109,15 @@ class Connector_User_Switching extends Connector {
|
|
100 |
Â
* This unhooks the Users connector's login and logout actions so they don't appear when a user switches
|
101 |
Â
* user with the User Switching plugin.
|
102 |
Â
*
|
103 |
-
* @param array $labels All registered connector labels
|
104 |
-
* @param Connectors $connectors The Connectors object instance
|
105 |
Â
*/
|
106 |
Â
public function callback_wp_stream_after_connectors_registration( array $labels, Connectors $connectors ) {
|
107 |
-
$action = wp_stream_filter_input( INPUT_GET, 'action' )
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
108 |
Â
|
109 |
Â
if ( ! $action ) {
|
110 |
Â
return;
|
@@ -140,7 +153,7 @@ class Connector_User_Switching extends Connector {
|
|
140 |
Â
|
141 |
Â
$user = get_userdata( $user_id );
|
142 |
Â
$old_user = get_userdata( $old_user_id );
|
143 |
-
|
144 |
Â
$message = _x(
|
145 |
Â
'Switched user to %1$s (%2$s)',
|
146 |
Â
'1: User display name, 2: User login',
|
@@ -171,7 +184,7 @@ class Connector_User_Switching extends Connector {
|
|
171 |
Â
public function callback_switch_back_user( $user_id, $old_user_id ) {
|
172 |
Â
|
173 |
Â
$user = get_userdata( $user_id );
|
174 |
-
|
175 |
Â
$message = _x(
|
176 |
Â
'Switched back to %1$s (%2$s)',
|
177 |
Â
'1: User display name, 2: User login',
|
@@ -225,8 +238,8 @@ class Connector_User_Switching extends Connector {
|
|
225 |
Â
/**
|
226 |
Â
* Unhook the requested action from the Users connector.
|
227 |
Â
*
|
228 |
-
* @param Connectors $connectors The Connectors instance
|
229 |
-
* @param string $action The name of the action to unhook
|
230 |
Â
*/
|
231 |
Â
protected function unhook_user_action( Connectors $connectors, $action ) {
|
232 |
Â
foreach ( $connectors->connectors as $connector ) {
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for User-Switching
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_User_Switching
|
12 |
+
*/
|
13 |
Â
class Connector_User_Switching extends Connector {
|
14 |
Â
|
15 |
Â
/**
|
109 |
Â
* This unhooks the Users connector's login and logout actions so they don't appear when a user switches
|
110 |
Â
* user with the User Switching plugin.
|
111 |
Â
*
|
112 |
+
* @param array $labels All registered connector labels.
|
113 |
+
* @param Connectors $connectors The Connectors object instance.
|
114 |
Â
*/
|
115 |
Â
public function callback_wp_stream_after_connectors_registration( array $labels, Connectors $connectors ) {
|
116 |
+
$action = wp_stream_filter_input( INPUT_GET, 'action' );
|
117 |
+
|
118 |
+
if ( ! $action ) {
|
119 |
+
$action = wp_stream_filter_input( INPUT_POST, 'action' );
|
120 |
+
}
|
121 |
Â
|
122 |
Â
if ( ! $action ) {
|
123 |
Â
return;
|
153 |
Â
|
154 |
Â
$user = get_userdata( $user_id );
|
155 |
Â
$old_user = get_userdata( $old_user_id );
|
156 |
+
/* translators: %1$s: a user display name, %2$s: a username (e.g. "Jane Doe", "administrator") */
|
157 |
Â
$message = _x(
|
158 |
Â
'Switched user to %1$s (%2$s)',
|
159 |
Â
'1: User display name, 2: User login',
|
184 |
Â
public function callback_switch_back_user( $user_id, $old_user_id ) {
|
185 |
Â
|
186 |
Â
$user = get_userdata( $user_id );
|
187 |
+
/* translators: Placeholders refer to a user display name, and a username (e.g. "Jane Doe", "administrator") */
|
188 |
Â
$message = _x(
|
189 |
Â
'Switched back to %1$s (%2$s)',
|
190 |
Â
'1: User display name, 2: User login',
|
238 |
Â
/**
|
239 |
Â
* Unhook the requested action from the Users connector.
|
240 |
Â
*
|
241 |
+
* @param Connectors $connectors The Connectors instance.
|
242 |
+
* @param string $action The name of the action to unhook.
|
243 |
Â
*/
|
244 |
Â
protected function unhook_user_action( Connectors $connectors, $action ) {
|
245 |
Â
foreach ( $connectors->connectors as $connector ) {
|
connectors/class-connector-users.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_Users extends Connector {
|
5 |
Â
|
6 |
Â
/**
|
@@ -12,8 +21,10 @@ class Connector_Users extends Connector {
|
|
12 |
Â
|
13 |
Â
/**
|
14 |
Â
* Stores users object before the user being deleted.
|
Â
|
|
Â
|
|
15 |
Â
*/
|
16 |
-
protected $_users_object_pre_deleted = array();
|
17 |
Â
|
18 |
Â
/**
|
19 |
Â
* Actions registered for this connector
|
@@ -79,8 +90,8 @@ class Connector_Users extends Connector {
|
|
79 |
Â
*
|
80 |
Â
* @filter wp_stream_action_links_{connector}
|
81 |
Â
*
|
82 |
-
* @param array $links Previous links registered
|
83 |
-
* @param Record $record
|
84 |
Â
*
|
85 |
Â
* @return array Action links
|
86 |
Â
*/
|
@@ -98,7 +109,7 @@ class Connector_Users extends Connector {
|
|
98 |
Â
/**
|
99 |
Â
* Get an array of role lables assigned to a specific user.
|
100 |
Â
*
|
101 |
-
* @param object|int $user User object or user ID to get roles for
|
102 |
Â
*
|
103 |
Â
* @return array $labels An array of role labels
|
104 |
Â
*/
|
@@ -130,17 +141,17 @@ class Connector_Users extends Connector {
|
|
130 |
Â
*
|
131 |
Â
* @action user_register
|
132 |
Â
*
|
133 |
-
* @param int $user_id
|
134 |
Â
*/
|
135 |
Â
public function callback_user_register( $user_id ) {
|
136 |
Â
$current_user = wp_get_current_user();
|
137 |
Â
$registered_user = get_user_by( 'id', $user_id );
|
138 |
Â
|
139 |
-
if ( ! $current_user->ID ) { // Non logged-in user registered themselves
|
140 |
Â
$message = esc_html__( 'New user registration', 'stream' );
|
141 |
Â
$user_to_log = $registered_user->ID;
|
142 |
-
} else { // Current logged-in user created a new user
|
143 |
-
|
144 |
Â
$message = _x(
|
145 |
Â
'New user account created for %1$s (%2$s)',
|
146 |
Â
'1: User display name, 2: User role',
|
@@ -167,14 +178,14 @@ class Connector_Users extends Connector {
|
|
167 |
Â
*
|
168 |
Â
* @action profile_update
|
169 |
Â
*
|
170 |
-
* @param int $user_id
|
171 |
-
* @param \WP_User $user
|
172 |
Â
*/
|
173 |
Â
public function callback_profile_update( $user_id, $user ) {
|
174 |
Â
unset( $user_id );
|
175 |
Â
|
176 |
Â
$this->log(
|
177 |
-
|
178 |
Â
__( '%s\'s profile was updated', 'stream' ),
|
179 |
Â
array(
|
180 |
Â
'display_name' => $user->display_name,
|
@@ -190,9 +201,9 @@ class Connector_Users extends Connector {
|
|
190 |
Â
*
|
191 |
Â
* @action set_user_role
|
192 |
Â
*
|
193 |
-
* @param int $user_id
|
194 |
-
* @param string $new_role
|
195 |
-
* @param array $old_roles
|
196 |
Â
*/
|
197 |
Â
public function callback_set_user_role( $user_id, $new_role, $old_roles ) {
|
198 |
Â
if ( empty( $old_roles ) ) {
|
@@ -202,7 +213,7 @@ class Connector_Users extends Connector {
|
|
202 |
Â
global $wp_roles;
|
203 |
Â
|
204 |
Â
$this->log(
|
205 |
-
|
206 |
Â
_x(
|
207 |
Â
'%1$s\'s role was changed from %2$s to %3$s',
|
208 |
Â
'1: User display name, 2: Old role, 3: New role',
|
@@ -224,11 +235,11 @@ class Connector_Users extends Connector {
|
|
224 |
Â
*
|
225 |
Â
* @action password_reset
|
226 |
Â
*
|
227 |
-
* @param \WP_User $user
|
228 |
Â
*/
|
229 |
Â
public function callback_password_reset( $user ) {
|
230 |
Â
$this->log(
|
231 |
-
|
232 |
Â
__( '%s\'s password was reset', 'stream' ),
|
233 |
Â
array(
|
234 |
Â
'email' => $user->display_name,
|
@@ -245,7 +256,7 @@ class Connector_Users extends Connector {
|
|
245 |
Â
*
|
246 |
Â
* @action retrieve_password
|
247 |
Â
*
|
248 |
-
* @param string $user_login
|
249 |
Â
*/
|
250 |
Â
public function callback_retrieve_password( $user_login ) {
|
251 |
Â
if ( wp_stream_filter_var( $user_login, FILTER_VALIDATE_EMAIL ) ) {
|
@@ -255,7 +266,7 @@ class Connector_Users extends Connector {
|
|
255 |
Â
}
|
256 |
Â
|
257 |
Â
$this->log(
|
258 |
-
|
259 |
Â
__( '%s\'s password was requested to be reset', 'stream' ),
|
260 |
Â
array(
|
261 |
Â
'display_name' => $user->display_name,
|
@@ -272,10 +283,10 @@ class Connector_Users extends Connector {
|
|
272 |
Â
*
|
273 |
Â
* @action set_logged_in_cookie
|
274 |
Â
*
|
275 |
-
* @param string $logged_in_cookie
|
276 |
-
* @param int $expire
|
277 |
-
* @param int $expiration
|
278 |
-
* @param int $user_id
|
279 |
Â
*/
|
280 |
Â
public function callback_set_logged_in_cookie( $logged_in_cookie, $expire, $expiration, $user_id ) {
|
281 |
Â
unset( $logged_in_cookie );
|
@@ -284,7 +295,7 @@ class Connector_Users extends Connector {
|
|
284 |
Â
$user = get_user_by( 'id', $user_id );
|
285 |
Â
|
286 |
Â
$this->log(
|
287 |
-
|
288 |
Â
__( '%s logged in', 'stream' ),
|
289 |
Â
array(
|
290 |
Â
'display_name' => $user->display_name,
|
@@ -304,13 +315,13 @@ class Connector_Users extends Connector {
|
|
304 |
Â
public function callback_clear_auth_cookie() {
|
305 |
Â
$user = wp_get_current_user();
|
306 |
Â
|
307 |
-
// For some reason, incognito mode calls clear_auth_cookie on failed login attempts
|
308 |
Â
if ( empty( $user ) || ! $user->exists() ) {
|
309 |
Â
return;
|
310 |
Â
}
|
311 |
Â
|
312 |
Â
$this->log(
|
313 |
-
|
314 |
Â
__( '%s logged out', 'stream' ),
|
315 |
Â
array(
|
316 |
Â
'display_name' => $user->display_name,
|
@@ -330,7 +341,7 @@ class Connector_Users extends Connector {
|
|
330 |
Â
* was already removed from DB.
|
331 |
Â
*
|
332 |
Â
* @action delete_user
|
333 |
-
* @param int $user_id
|
334 |
Â
*/
|
335 |
Â
public function callback_delete_user( $user_id ) {
|
336 |
Â
if ( ! isset( $this->_users_object_pre_deleted[ $user_id ] ) ) {
|
@@ -342,13 +353,13 @@ class Connector_Users extends Connector {
|
|
342 |
Â
* Log deleted user.
|
343 |
Â
*
|
344 |
Â
* @action deleted_user
|
345 |
-
* @param int $user_id
|
346 |
Â
*/
|
347 |
Â
public function callback_deleted_user( $user_id ) {
|
348 |
Â
$user = wp_get_current_user();
|
349 |
Â
|
350 |
Â
if ( isset( $this->_users_object_pre_deleted[ $user_id ] ) ) {
|
351 |
-
|
352 |
Â
$message = _x(
|
353 |
Â
'%1$s\'s account was deleted (%2$s)',
|
354 |
Â
'1: User display name, 2: User roles',
|
@@ -358,7 +369,7 @@ class Connector_Users extends Connector {
|
|
358 |
Â
$deleted_user = $this->_users_object_pre_deleted[ $user_id ];
|
359 |
Â
unset( $this->_users_object_pre_deleted[ $user_id ] );
|
360 |
Â
} else {
|
361 |
-
|
362 |
Â
$message = esc_html__( 'User account #%d was deleted', 'stream' );
|
363 |
Â
$display_name = $user_id;
|
364 |
Â
$deleted_user = $user_id;
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for users
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_Users
|
12 |
+
*/
|
13 |
Â
class Connector_Users extends Connector {
|
14 |
Â
|
15 |
Â
/**
|
21 |
Â
|
22 |
Â
/**
|
23 |
Â
* Stores users object before the user being deleted.
|
24 |
+
*
|
25 |
+
* @var WP_User
|
26 |
Â
*/
|
27 |
+
protected $_users_object_pre_deleted = array(); // @codingStandardsIgnoreLine
|
28 |
Â
|
29 |
Â
/**
|
30 |
Â
* Actions registered for this connector
|
90 |
Â
*
|
91 |
Â
* @filter wp_stream_action_links_{connector}
|
92 |
Â
*
|
93 |
+
* @param array $links Previous links registered.
|
94 |
+
* @param Record $record Stream record.
|
95 |
Â
*
|
96 |
Â
* @return array Action links
|
97 |
Â
*/
|
109 |
Â
/**
|
110 |
Â
* Get an array of role lables assigned to a specific user.
|
111 |
Â
*
|
112 |
+
* @param object|int $user User object or user ID to get roles for.
|
113 |
Â
*
|
114 |
Â
* @return array $labels An array of role labels
|
115 |
Â
*/
|
141 |
Â
*
|
142 |
Â
* @action user_register
|
143 |
Â
*
|
144 |
+
* @param int $user_id Newly registered user ID.
|
145 |
Â
*/
|
146 |
Â
public function callback_user_register( $user_id ) {
|
147 |
Â
$current_user = wp_get_current_user();
|
148 |
Â
$registered_user = get_user_by( 'id', $user_id );
|
149 |
Â
|
150 |
+
if ( ! $current_user->ID ) { // Non logged-in user registered themselves.
|
151 |
Â
$message = esc_html__( 'New user registration', 'stream' );
|
152 |
Â
$user_to_log = $registered_user->ID;
|
153 |
+
} else { // Current logged-in user created a new user.
|
154 |
+
/* translators: %1$s: a user display name, %2$s: a user role (e.g. "Jane Doe", "subscriber") */
|
155 |
Â
$message = _x(
|
156 |
Â
'New user account created for %1$s (%2$s)',
|
157 |
Â
'1: User display name, 2: User role',
|
178 |
Â
*
|
179 |
Â
* @action profile_update
|
180 |
Â
*
|
181 |
+
* @param int $user_id Registered user ID.
|
182 |
+
* @param \WP_User $user Registered user object.
|
183 |
Â
*/
|
184 |
Â
public function callback_profile_update( $user_id, $user ) {
|
185 |
Â
unset( $user_id );
|
186 |
Â
|
187 |
Â
$this->log(
|
188 |
+
/* translators: %s: a user display name (e.g. "Jane Doe") */
|
189 |
Â
__( '%s\'s profile was updated', 'stream' ),
|
190 |
Â
array(
|
191 |
Â
'display_name' => $user->display_name,
|
201 |
Â
*
|
202 |
Â
* @action set_user_role
|
203 |
Â
*
|
204 |
+
* @param int $user_id User ID.
|
205 |
+
* @param string $new_role User role.
|
206 |
+
* @param array $old_roles Old user roles.
|
207 |
Â
*/
|
208 |
Â
public function callback_set_user_role( $user_id, $new_role, $old_roles ) {
|
209 |
Â
if ( empty( $old_roles ) ) {
|
213 |
Â
global $wp_roles;
|
214 |
Â
|
215 |
Â
$this->log(
|
216 |
+
/* translators: %1$s: a user display name, %2$s: a user role, %3$s: another user role (e.g. "Jane Doe", "editor", "subscriber") */
|
217 |
Â
_x(
|
218 |
Â
'%1$s\'s role was changed from %2$s to %3$s',
|
219 |
Â
'1: User display name, 2: Old role, 3: New role',
|
235 |
Â
*
|
236 |
Â
* @action password_reset
|
237 |
Â
*
|
238 |
+
* @param \WP_User $user User.
|
239 |
Â
*/
|
240 |
Â
public function callback_password_reset( $user ) {
|
241 |
Â
$this->log(
|
242 |
+
/* translators: %s: a user display name (e.g. "Jane Doe") */
|
243 |
Â
__( '%s\'s password was reset', 'stream' ),
|
244 |
Â
array(
|
245 |
Â
'email' => $user->display_name,
|
256 |
Â
*
|
257 |
Â
* @action retrieve_password
|
258 |
Â
*
|
259 |
+
* @param string $user_login User login.
|
260 |
Â
*/
|
261 |
Â
public function callback_retrieve_password( $user_login ) {
|
262 |
Â
if ( wp_stream_filter_var( $user_login, FILTER_VALIDATE_EMAIL ) ) {
|
266 |
Â
}
|
267 |
Â
|
268 |
Â
$this->log(
|
269 |
+
/* translators: %s: a user display name (e.g. "Jane Doe") */
|
270 |
Â
__( '%s\'s password was requested to be reset', 'stream' ),
|
271 |
Â
array(
|
272 |
Â
'display_name' => $user->display_name,
|
283 |
Â
*
|
284 |
Â
* @action set_logged_in_cookie
|
285 |
Â
*
|
286 |
+
* @param string $logged_in_cookie Authenticated cookie.
|
287 |
+
* @param int $expire Unused.
|
288 |
+
* @param int $expiration Unused.
|
289 |
+
* @param int $user_id Unused.
|
290 |
Â
*/
|
291 |
Â
public function callback_set_logged_in_cookie( $logged_in_cookie, $expire, $expiration, $user_id ) {
|
292 |
Â
unset( $logged_in_cookie );
|
295 |
Â
$user = get_user_by( 'id', $user_id );
|
296 |
Â
|
297 |
Â
$this->log(
|
298 |
+
/* translators: %s: a user display name (e.g. "Jane Doe") */
|
299 |
Â
__( '%s logged in', 'stream' ),
|
300 |
Â
array(
|
301 |
Â
'display_name' => $user->display_name,
|
315 |
Â
public function callback_clear_auth_cookie() {
|
316 |
Â
$user = wp_get_current_user();
|
317 |
Â
|
318 |
+
// For some reason, incognito mode calls clear_auth_cookie on failed login attempts.
|
319 |
Â
if ( empty( $user ) || ! $user->exists() ) {
|
320 |
Â
return;
|
321 |
Â
}
|
322 |
Â
|
323 |
Â
$this->log(
|
324 |
+
/* translators: %s: a user display name (e.g. "Jane Doe") */
|
325 |
Â
__( '%s logged out', 'stream' ),
|
326 |
Â
array(
|
327 |
Â
'display_name' => $user->display_name,
|
341 |
Â
* was already removed from DB.
|
342 |
Â
*
|
343 |
Â
* @action delete_user
|
344 |
+
* @param int $user_id User ID that maybe deleted.
|
345 |
Â
*/
|
346 |
Â
public function callback_delete_user( $user_id ) {
|
347 |
Â
if ( ! isset( $this->_users_object_pre_deleted[ $user_id ] ) ) {
|
353 |
Â
* Log deleted user.
|
354 |
Â
*
|
355 |
Â
* @action deleted_user
|
356 |
+
* @param int $user_id Deleted user ID.
|
357 |
Â
*/
|
358 |
Â
public function callback_deleted_user( $user_id ) {
|
359 |
Â
$user = wp_get_current_user();
|
360 |
Â
|
361 |
Â
if ( isset( $this->_users_object_pre_deleted[ $user_id ] ) ) {
|
362 |
+
/* translators: %1$s: a user display name, %2$s: a user role (e.g. "Jane Doe", "subscriber") */
|
363 |
Â
$message = _x(
|
364 |
Â
'%1$s\'s account was deleted (%2$s)',
|
365 |
Â
'1: User display name, 2: User roles',
|
369 |
Â
$deleted_user = $this->_users_object_pre_deleted[ $user_id ];
|
370 |
Â
unset( $this->_users_object_pre_deleted[ $user_id ] );
|
371 |
Â
} else {
|
372 |
+
/* translators: %d: a user display name, and a user role (e.g. "Jane Doe", "subscriber") */
|
373 |
Â
$message = esc_html__( 'User account #%d was deleted', 'stream' );
|
374 |
Â
$display_name = $user_id;
|
375 |
Â
$deleted_user = $user_id;
|
connectors/class-connector-widgets.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_Widgets extends Connector {
|
5 |
Â
|
6 |
Â
/**
|
@@ -90,8 +99,8 @@ class Connector_Widgets extends Connector {
|
|
90 |
Â
*
|
91 |
Â
* @filter wp_stream_action_links_{connector}
|
92 |
Â
*
|
93 |
-
* @param array $links Previous links registered
|
94 |
-
* @param Record $record
|
95 |
Â
*
|
96 |
Â
* @return array Action links
|
97 |
Â
*/
|
@@ -101,10 +110,10 @@ class Connector_Widgets extends Connector {
|
|
101 |
Â
global $wp_registered_sidebars;
|
102 |
Â
|
103 |
Â
if ( array_key_exists( $sidebar, $wp_registered_sidebars ) ) {
|
104 |
-
$links[ esc_html__( 'Edit Widget Area', 'stream' ) ] = admin_url( 'widgets.php#' . $sidebar ); // xss ok (@todo fix WPCS rule)
|
105 |
Â
}
|
106 |
-
// @todo Also old_sidebar_id and new_sidebar_id
|
107 |
-
// @todo Add Edit Widget link
|
108 |
Â
}
|
109 |
Â
|
110 |
Â
return $links;
|
@@ -115,13 +124,13 @@ class Connector_Widgets extends Connector {
|
|
115 |
Â
*
|
116 |
Â
* @action update_option_sidebars_widgets
|
117 |
Â
*
|
118 |
-
* @param array $old
|
119 |
-
* @param array $new
|
120 |
Â
*
|
121 |
Â
* @return void
|
122 |
Â
*/
|
123 |
Â
public function callback_update_option_sidebars_widgets( $old, $new ) {
|
124 |
-
// Disable listener if we're switching themes
|
125 |
Â
if ( did_action( 'after_switch_theme' ) ) {
|
126 |
Â
return;
|
127 |
Â
}
|
@@ -151,8 +160,10 @@ class Connector_Widgets extends Connector {
|
|
151 |
Â
}
|
152 |
Â
|
153 |
Â
/**
|
154 |
-
*
|
155 |
-
*
|
Â
|
|
Â
|
|
156 |
Â
*/
|
157 |
Â
protected function handle_sidebars_widgets_changes( $old, $new ) {
|
158 |
Â
unset( $old['array_version'] );
|
@@ -173,8 +184,8 @@ class Connector_Widgets extends Connector {
|
|
173 |
Â
/**
|
174 |
Â
* Track deactivation of widgets from sidebars
|
175 |
Â
*
|
176 |
-
* @param array $old
|
177 |
-
* @param array $new
|
178 |
Â
* @return void
|
179 |
Â
*/
|
180 |
Â
protected function handle_deactivated_widgets( $old, $new ) {
|
@@ -197,19 +208,19 @@ class Connector_Widgets extends Connector {
|
|
197 |
Â
$sidebar_name = isset( $labels[ $sidebar_id ] ) ? $labels[ $sidebar_id ] : $sidebar_id;
|
198 |
Â
|
199 |
Â
if ( $name && $title ) {
|
200 |
-
|
201 |
Â
$message = _x( '%1$s widget named "%2$s" from "%3$s" deactivated', '1: Name, 2: Title, 3: Sidebar Name', 'stream' );
|
202 |
Â
} elseif ( $name ) {
|
203 |
-
// Empty title, but we have the name
|
204 |
-
|
205 |
Â
$message = _x( '%1$s widget from "%3$s" deactivated', '1: Name, 3: Sidebar Name', 'stream' );
|
206 |
Â
} elseif ( $title ) {
|
207 |
-
// Likely a single widget since no name is available
|
208 |
-
|
209 |
Â
$message = _x( 'Unknown widget type named "%2$s" from "%3$s" deactivated', '2: Title, 3: Sidebar Name', 'stream' );
|
210 |
Â
} else {
|
211 |
-
// Neither a name nor a title are available, so use the widget ID
|
212 |
-
|
213 |
Â
$message = _x( '%4$s widget from "%3$s" deactivated', '4: Widget ID, 3: Sidebar Name', 'stream' );
|
214 |
Â
}
|
215 |
Â
|
@@ -228,8 +239,8 @@ class Connector_Widgets extends Connector {
|
|
228 |
Â
/**
|
229 |
Â
* Track reactivation of widgets from sidebars
|
230 |
Â
*
|
231 |
-
* @param array $old
|
232 |
-
* @param array $new
|
233 |
Â
* @return void
|
234 |
Â
*/
|
235 |
Â
protected function handle_reactivated_widgets( $old, $new ) {
|
@@ -250,19 +261,19 @@ class Connector_Widgets extends Connector {
|
|
250 |
Â
$title = $this->get_widget_title( $widget_id );
|
251 |
Â
|
252 |
Â
if ( $name && $title ) {
|
253 |
-
|
254 |
Â
$message = _x( '%1$s widget named "%2$s" reactivated', '1: Name, 2: Title', 'stream' );
|
255 |
Â
} elseif ( $name ) {
|
256 |
-
// Empty title, but we have the name
|
257 |
-
|
258 |
Â
$message = _x( '%1$s widget reactivated', '1: Name', 'stream' );
|
259 |
Â
} elseif ( $title ) {
|
260 |
-
// Likely a single widget since no name is available
|
261 |
-
|
262 |
Â
$message = _x( 'Unknown widget type named "%2$s" reactivated', '2: Title', 'stream' );
|
263 |
Â
} else {
|
264 |
-
// Neither a name nor a title are available, so use the widget ID
|
265 |
-
|
266 |
Â
$message = _x( '%3$s widget reactivated', '3: Widget ID', 'stream' );
|
267 |
Â
}
|
268 |
Â
|
@@ -281,8 +292,8 @@ class Connector_Widgets extends Connector {
|
|
281 |
Â
/**
|
282 |
Â
* Track deletion of widgets from sidebars
|
283 |
Â
*
|
284 |
-
* @param array $old
|
285 |
-
* @param array $new
|
286 |
Â
* @return void
|
287 |
Â
*/
|
288 |
Â
protected function handle_widget_removal( $old, $new ) {
|
@@ -310,19 +321,19 @@ class Connector_Widgets extends Connector {
|
|
310 |
Â
$sidebar_name = isset( $labels[ $sidebar_id ] ) ? $labels[ $sidebar_id ] : $sidebar_id;
|
311 |
Â
|
312 |
Â
if ( $name && $title ) {
|
313 |
-
|
314 |
Â
$message = _x( '%1$s widget named "%2$s" removed from "%3$s"', '1: Name, 2: Title, 3: Sidebar Name', 'stream' );
|
315 |
Â
} elseif ( $name ) {
|
316 |
-
// Empty title, but we have the name
|
317 |
-
|
318 |
Â
$message = _x( '%1$s widget removed from "%3$s"', '1: Name, 3: Sidebar Name', 'stream' );
|
319 |
Â
} elseif ( $title ) {
|
320 |
-
// Likely a single widget since no name is available
|
321 |
-
|
322 |
Â
$message = _x( 'Unknown widget type named "%2$s" removed from "%3$s"', '2: Title, 3: Sidebar Name', 'stream' );
|
323 |
Â
} else {
|
324 |
-
// Neither a name nor a title are available, so use the widget ID
|
325 |
-
|
326 |
Â
$message = _x( '%4$s widget removed from "%3$s"', '4: Widget ID, 3: Sidebar Name', 'stream' );
|
327 |
Â
}
|
328 |
Â
|
@@ -341,8 +352,8 @@ class Connector_Widgets extends Connector {
|
|
341 |
Â
/**
|
342 |
Â
* Track reactivation of widgets from sidebars
|
343 |
Â
*
|
344 |
-
* @param array $old
|
345 |
-
* @param array $new
|
346 |
Â
* @return void
|
347 |
Â
*/
|
348 |
Â
protected function handle_widget_addition( $old, $new ) {
|
@@ -367,19 +378,19 @@ class Connector_Widgets extends Connector {
|
|
367 |
Â
$sidebar_name = isset( $labels[ $sidebar_id ] ) ? $labels[ $sidebar_id ] : $sidebar_id;
|
368 |
Â
|
369 |
Â
if ( $name && $title ) {
|
370 |
-
|
371 |
Â
$message = _x( '%1$s widget named "%2$s" added to "%3$s"', '1: Name, 2: Title, 3: Sidebar Name', 'stream' );
|
372 |
Â
} elseif ( $name ) {
|
373 |
-
// Empty title, but we have the name
|
374 |
-
|
375 |
Â
$message = _x( '%1$s widget added to "%3$s"', '1: Name, 3: Sidebar Name', 'stream' );
|
376 |
Â
} elseif ( $title ) {
|
377 |
-
// Likely a single widget since no name is available
|
378 |
-
|
379 |
Â
$message = _x( 'Unknown widget type named "%2$s" added to "%3$s"', '2: Title, 3: Sidebar Name', 'stream' );
|
380 |
Â
} else {
|
381 |
-
// Neither a name nor a title are available, so use the widget ID
|
382 |
-
|
383 |
Â
$message = _x( '%4$s widget added to "%3$s"', '4: Widget ID, 3: Sidebar Name', 'stream' );
|
384 |
Â
}
|
385 |
Â
|
@@ -398,8 +409,8 @@ class Connector_Widgets extends Connector {
|
|
398 |
Â
/**
|
399 |
Â
* Track reordering of widgets
|
400 |
Â
*
|
401 |
-
* @param array $old
|
402 |
-
* @param array $new
|
403 |
Â
* @return void
|
404 |
Â
*/
|
405 |
Â
protected function handle_widget_reordering( $old, $new ) {
|
@@ -410,7 +421,7 @@ class Connector_Widgets extends Connector {
|
|
410 |
Â
continue;
|
411 |
Â
}
|
412 |
Â
|
413 |
-
// Use intersect to ignore widget additions and removals
|
414 |
Â
$all_widget_ids = array_unique( array_merge( $old[ $sidebar_id ], $new[ $sidebar_id ] ) );
|
415 |
Â
$common_widget_ids = array_intersect( $old[ $sidebar_id ], $new[ $sidebar_id ] );
|
416 |
Â
$uncommon_widget_ids = array_diff( $all_widget_ids, $common_widget_ids );
|
@@ -423,7 +434,7 @@ class Connector_Widgets extends Connector {
|
|
423 |
Â
$sidebar_name = isset( $labels[ $sidebar_id ] ) ? $labels[ $sidebar_id ] : $sidebar_id;
|
424 |
Â
$old_widget_ids = $old[ $sidebar_id ];
|
425 |
Â
|
426 |
-
|
427 |
Â
$message = _x( 'Widgets reordered in "%s"', 'Sidebar name', 'stream' );
|
428 |
Â
$message = sprintf( $message, $sidebar_name );
|
429 |
Â
|
@@ -442,8 +453,8 @@ class Connector_Widgets extends Connector {
|
|
442 |
Â
/**
|
443 |
Â
* Track movement of widgets to other sidebars
|
444 |
Â
*
|
445 |
-
* @param array $old
|
446 |
-
* @param array $new
|
447 |
Â
* @return void
|
448 |
Â
*/
|
449 |
Â
protected function handle_widget_moved( $old, $new ) {
|
@@ -457,7 +468,7 @@ class Connector_Widgets extends Connector {
|
|
457 |
Â
$new_widget_ids = array_diff( $new[ $new_sidebar_id ], $old[ $new_sidebar_id ] );
|
458 |
Â
|
459 |
Â
foreach ( $new_widget_ids as $widget_id ) {
|
460 |
-
// Now find the sidebar that the widget was originally located in, as long it is not wp_inactive_widgets
|
461 |
Â
$old_sidebar_id = null;
|
462 |
Â
foreach ( $old as $sidebar_id => $old_widget_ids ) {
|
463 |
Â
if ( in_array( $widget_id, $old_widget_ids, true ) ) {
|
@@ -479,19 +490,19 @@ class Connector_Widgets extends Connector {
|
|
479 |
Â
$new_sidebar_name = isset( $labels[ $new_sidebar_id ] ) ? $labels[ $new_sidebar_id ] : $new_sidebar_id;
|
480 |
Â
|
481 |
Â
if ( $name && $title ) {
|
482 |
-
|
483 |
Â
$message = _x( '%1$s widget named "%2$s" moved from "%4$s" to "%5$s"', '1: Name, 2: Title, 4: Old Sidebar Name, 5: New Sidebar Name', 'stream' );
|
484 |
Â
} elseif ( $name ) {
|
485 |
-
// Empty title, but we have the name
|
486 |
-
|
487 |
Â
$message = _x( '%1$s widget moved from "%4$s" to "%5$s"', '1: Name, 4: Old Sidebar Name, 5: New Sidebar Name', 'stream' );
|
488 |
Â
} elseif ( $title ) {
|
489 |
-
// Likely a single widget since no name is available
|
490 |
-
|
491 |
Â
$message = _x( 'Unknown widget type named "%2$s" moved from "%4$s" to "%5$s"', '2: Title, 4: Old Sidebar Name, 5: New Sidebar Name', 'stream' );
|
492 |
Â
} else {
|
493 |
-
// Neither a name nor a title are available, so use the widget ID
|
494 |
-
|
495 |
Â
$message = _x( '%3$s widget moved from "%4$s" to "%5$s"', '3: Widget ID, 4: Old Sidebar Name, 5: New Sidebar Name', 'stream' );
|
496 |
Â
}
|
497 |
Â
|
@@ -515,9 +526,9 @@ class Connector_Widgets extends Connector {
|
|
515 |
Â
*
|
516 |
Â
* @action updated_option
|
517 |
Â
*
|
518 |
-
* @param string $option_name
|
519 |
-
* @param array $old_value
|
520 |
-
* @param array $new_value
|
521 |
Â
*/
|
522 |
Â
public function callback_updated_option( $option_name, $old_value, $new_value ) {
|
523 |
Â
if ( ! preg_match( '/^widget_(.+)$/', $option_name, $matches ) || ! is_array( $new_value ) ) {
|
@@ -588,9 +599,9 @@ class Connector_Widgets extends Connector {
|
|
588 |
Â
$deletes[] = compact( 'name', 'title', 'widget_id', 'sidebar_id', 'instance' );
|
589 |
Â
}
|
590 |
Â
} else {
|
591 |
-
// Doing our best guess for tracking changes to old single widgets, assuming their options start with 'widget_'
|
592 |
Â
$widget_id = $widget_id_base;
|
593 |
-
$name = $widget_id; // There aren't names available for single widgets
|
594 |
Â
$title = ! empty( $new_value['title'] ) ? $new_value['title'] : null;
|
595 |
Â
$sidebar_id = $this->get_widget_sidebar_id( $widget_id );
|
596 |
Â
$old_instance = $old_value;
|
@@ -605,19 +616,19 @@ class Connector_Widgets extends Connector {
|
|
605 |
Â
*/
|
606 |
Â
foreach ( $updates as $update ) {
|
607 |
Â
if ( $update['name'] && $update['title'] ) {
|
608 |
-
|
609 |
Â
$message = _x( '%1$s widget named "%2$s" in "%3$s" updated', '1: Name, 2: Title, 3: Sidebar Name', 'stream' );
|
610 |
Â
} elseif ( $update['name'] ) {
|
611 |
-
// Empty title, but we have the name
|
612 |
-
|
613 |
Â
$message = _x( '%1$s widget in "%3$s" updated', '1: Name, 3: Sidebar Name', 'stream' );
|
614 |
Â
} elseif ( $update['title'] ) {
|
615 |
-
// Likely a single widget since no name is available
|
616 |
-
|
617 |
Â
$message = _x( 'Unknown widget type named "%2$s" in "%3$s" updated', '2: Title, 3: Sidebar Name', 'stream' );
|
618 |
Â
} else {
|
619 |
-
// Neither a name nor a title are available, so use the widget ID
|
620 |
-
|
621 |
Â
$message = _x( '%4$s widget in "%3$s" updated', '4: Widget ID, 3: Sidebar Name', 'stream' );
|
622 |
Â
}
|
623 |
Â
|
@@ -643,25 +654,25 @@ class Connector_Widgets extends Connector {
|
|
643 |
Â
* actions would be useful to log.
|
644 |
Â
*/
|
645 |
Â
if ( $this->verbose_widget_created_deleted_actions ) {
|
646 |
-
// We should only do these if not captured by an update to the sidebars_widgets option
|
647 |
Â
/**
|
648 |
Â
* Log created actions
|
649 |
Â
*/
|
650 |
Â
foreach ( $creates as $create ) {
|
651 |
Â
if ( $create['name'] && $create['title'] ) {
|
652 |
-
|
653 |
Â
$message = _x( '%1$s widget named "%2$s" created', '1: Name, 2: Title', 'stream' );
|
654 |
Â
} elseif ( $create['name'] ) {
|
655 |
-
// Empty title, but we have the name
|
656 |
-
|
657 |
Â
$message = _x( '%1$s widget created', '1: Name', 'stream' );
|
658 |
Â
} elseif ( $create['title'] ) {
|
659 |
-
// Likely a single widget since no name is available
|
660 |
-
|
661 |
Â
$message = _x( 'Unknown widget type named "%2$s" created', '2: Title', 'stream' );
|
662 |
Â
} else {
|
663 |
-
// Neither a name nor a title are available, so use the widget ID
|
664 |
-
|
665 |
Â
$message = _x( '%3$s widget created', '3: Widget ID', 'stream' );
|
666 |
Â
}
|
667 |
Â
|
@@ -683,19 +694,19 @@ class Connector_Widgets extends Connector {
|
|
683 |
Â
*/
|
684 |
Â
foreach ( $deletes as $delete ) {
|
685 |
Â
if ( $delete['name'] && $delete['title'] ) {
|
686 |
-
|
687 |
Â
$message = _x( '%1$s widget named "%2$s" deleted', '1: Name, 2: Title', 'stream' );
|
688 |
Â
} elseif ( $delete['name'] ) {
|
689 |
-
// Empty title, but we have the name
|
690 |
-
|
691 |
Â
$message = _x( '%1$s widget deleted', '1: Name', 'stream' );
|
692 |
Â
} elseif ( $delete['title'] ) {
|
693 |
-
// Likely a single widget since no name is available
|
694 |
-
|
695 |
Â
$message = _x( 'Unknown widget type named "%2$s" deleted', '2: Title', 'stream' );
|
696 |
Â
} else {
|
697 |
-
// Neither a name nor a title are available, so use the widget ID
|
698 |
-
|
699 |
Â
$message = _x( '%3$s widget deleted', '3: Widget ID', 'stream' );
|
700 |
Â
}
|
701 |
Â
|
@@ -715,7 +726,9 @@ class Connector_Widgets extends Connector {
|
|
715 |
Â
}
|
716 |
Â
|
717 |
Â
/**
|
718 |
-
*
|
Â
|
|
Â
|
|
719 |
Â
*
|
720 |
Â
* @return string
|
721 |
Â
*/
|
@@ -725,7 +738,9 @@ class Connector_Widgets extends Connector {
|
|
725 |
Â
}
|
726 |
Â
|
727 |
Â
/**
|
728 |
-
*
|
Â
|
|
Â
|
|
729 |
Â
*
|
730 |
Â
* @return string|null
|
731 |
Â
*/
|
@@ -735,7 +750,9 @@ class Connector_Widgets extends Connector {
|
|
735 |
Â
}
|
736 |
Â
|
737 |
Â
/**
|
738 |
-
*
|
Â
|
|
Â
|
|
739 |
Â
*
|
740 |
Â
* @return array|null
|
741 |
Â
*/
|
@@ -751,7 +768,9 @@ class Connector_Widgets extends Connector {
|
|
751 |
Â
}
|
752 |
Â
|
753 |
Â
/**
|
754 |
-
*
|
Â
|
|
Â
|
|
755 |
Â
*
|
756 |
Â
* @return \WP_Widget|null
|
757 |
Â
*/
|
@@ -781,7 +800,7 @@ class Connector_Widgets extends Connector {
|
|
781 |
Â
/**
|
782 |
Â
* Returns widget instance settings
|
783 |
Â
*
|
784 |
-
* @param string $widget_id
|
785 |
Â
*
|
786 |
Â
* @return array|null Widget instance
|
787 |
Â
*/
|
@@ -798,7 +817,7 @@ class Connector_Widgets extends Connector {
|
|
798 |
Â
$instance = $settings[ $multi_number ];
|
799 |
Â
}
|
800 |
Â
} else {
|
801 |
-
// Single widgets, try our best guess at the option used
|
802 |
Â
$potential_instance = get_option( "widget_{$widget_id}" );
|
803 |
Â
|
804 |
Â
if ( ! empty( $potential_instance ) && ! empty( $potential_instance['title'] ) ) {
|
@@ -830,7 +849,7 @@ class Connector_Widgets extends Connector {
|
|
830 |
Â
/**
|
831 |
Â
* Return the sidebar of a certain widget, based on widget_id
|
832 |
Â
*
|
833 |
-
* @param string $widget_id
|
834 |
Â
*
|
835 |
Â
* @return string Sidebar id
|
836 |
Â
*/
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for Widgets
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_Widgets
|
12 |
+
*/
|
13 |
Â
class Connector_Widgets extends Connector {
|
14 |
Â
|
15 |
Â
/**
|
99 |
Â
*
|
100 |
Â
* @filter wp_stream_action_links_{connector}
|
101 |
Â
*
|
102 |
+
* @param array $links Previous links registered.
|
103 |
+
* @param Record $record Stream record.
|
104 |
Â
*
|
105 |
Â
* @return array Action links
|
106 |
Â
*/
|
110 |
Â
global $wp_registered_sidebars;
|
111 |
Â
|
112 |
Â
if ( array_key_exists( $sidebar, $wp_registered_sidebars ) ) {
|
113 |
+
$links[ esc_html__( 'Edit Widget Area', 'stream' ) ] = admin_url( 'widgets.php#' . $sidebar ); // xss ok (@todo fix WPCS rule).
|
114 |
Â
}
|
115 |
+
// @todo Also old_sidebar_id and new_sidebar_id.
|
116 |
+
// @todo Add Edit Widget link.
|
117 |
Â
}
|
118 |
Â
|
119 |
Â
return $links;
|
124 |
Â
*
|
125 |
Â
* @action update_option_sidebars_widgets
|
126 |
Â
*
|
127 |
+
* @param array $old Old sidebars widgets.
|
128 |
+
* @param array $new New sidebars widgets.
|
129 |
Â
*
|
130 |
Â
* @return void
|
131 |
Â
*/
|
132 |
Â
public function callback_update_option_sidebars_widgets( $old, $new ) {
|
133 |
+
// Disable listener if we're switching themes.
|
134 |
Â
if ( did_action( 'after_switch_theme' ) ) {
|
135 |
Â
return;
|
136 |
Â
}
|
160 |
Â
}
|
161 |
Â
|
162 |
Â
/**
|
163 |
+
* Processes tracked widget actions
|
164 |
+
*
|
165 |
+
* @param array $old Old sidebar widgets.
|
166 |
+
* @param array $new New sidebar widgets.
|
167 |
Â
*/
|
168 |
Â
protected function handle_sidebars_widgets_changes( $old, $new ) {
|
169 |
Â
unset( $old['array_version'] );
|
184 |
Â
/**
|
185 |
Â
* Track deactivation of widgets from sidebars
|
186 |
Â
*
|
187 |
+
* @param array $old Old sidebars widgets.
|
188 |
+
* @param array $new New sidebars widgets.
|
189 |
Â
* @return void
|
190 |
Â
*/
|
191 |
Â
protected function handle_deactivated_widgets( $old, $new ) {
|
208 |
Â
$sidebar_name = isset( $labels[ $sidebar_id ] ) ? $labels[ $sidebar_id ] : $sidebar_id;
|
209 |
Â
|
210 |
Â
if ( $name && $title ) {
|
211 |
+
/* translators: %1$s: a widget name, %2$s: a widget title, %3$s: a sidebar name (e.g. "Archives", "Browse", "Footer Area 1") */
|
212 |
Â
$message = _x( '%1$s widget named "%2$s" from "%3$s" deactivated', '1: Name, 2: Title, 3: Sidebar Name', 'stream' );
|
213 |
Â
} elseif ( $name ) {
|
214 |
+
// Empty title, but we have the name.
|
215 |
+
/* translators: %1$s: a widget name, %3$s: a sidebar name (e.g. "Archives", "Footer Area 1") */
|
216 |
Â
$message = _x( '%1$s widget from "%3$s" deactivated', '1: Name, 3: Sidebar Name', 'stream' );
|
217 |
Â
} elseif ( $title ) {
|
218 |
+
// Likely a single widget since no name is available.
|
219 |
+
/* translators: %1$s: a widget title, %2$s: a sidebar name (e.g. "Browse", "Footer Area 1") */
|
220 |
Â
$message = _x( 'Unknown widget type named "%2$s" from "%3$s" deactivated', '2: Title, 3: Sidebar Name', 'stream' );
|
221 |
Â
} else {
|
222 |
+
// Neither a name nor a title are available, so use the widget ID.
|
223 |
+
/* translators: %4$s: a widget ID, %3$s: a sidebar name (e.g. "42", "Footer Area 1") */
|
224 |
Â
$message = _x( '%4$s widget from "%3$s" deactivated', '4: Widget ID, 3: Sidebar Name', 'stream' );
|
225 |
Â
}
|
226 |
Â
|
239 |
Â
/**
|
240 |
Â
* Track reactivation of widgets from sidebars
|
241 |
Â
*
|
242 |
+
* @param array $old Old sidebars widgets.
|
243 |
+
* @param array $new New sidebars widgets.
|
244 |
Â
* @return void
|
245 |
Â
*/
|
246 |
Â
protected function handle_reactivated_widgets( $old, $new ) {
|
261 |
Â
$title = $this->get_widget_title( $widget_id );
|
262 |
Â
|
263 |
Â
if ( $name && $title ) {
|
264 |
+
/* translators: %1$s: a widget name, %2$s: a widget title (e.g. "Archives", "Browse") */
|
265 |
Â
$message = _x( '%1$s widget named "%2$s" reactivated', '1: Name, 2: Title', 'stream' );
|
266 |
Â
} elseif ( $name ) {
|
267 |
+
// Empty title, but we have the name.
|
268 |
+
/* translators: %1$s: a widget name (e.g. "Archives") */
|
269 |
Â
$message = _x( '%1$s widget reactivated', '1: Name', 'stream' );
|
270 |
Â
} elseif ( $title ) {
|
271 |
+
// Likely a single widget since no name is available.
|
272 |
+
/* translators: %2$s: a widget title (e.g. "Browse") */
|
273 |
Â
$message = _x( 'Unknown widget type named "%2$s" reactivated', '2: Title', 'stream' );
|
274 |
Â
} else {
|
275 |
+
// Neither a name nor a title are available, so use the widget ID.
|
276 |
+
/* translators: %3$s: a widget ID (e.g. "42") */
|
277 |
Â
$message = _x( '%3$s widget reactivated', '3: Widget ID', 'stream' );
|
278 |
Â
}
|
279 |
Â
|
292 |
Â
/**
|
293 |
Â
* Track deletion of widgets from sidebars
|
294 |
Â
*
|
295 |
+
* @param array $old Old sidebars widgets.
|
296 |
+
* @param array $new New sidebars widgets.
|
297 |
Â
* @return void
|
298 |
Â
*/
|
299 |
Â
protected function handle_widget_removal( $old, $new ) {
|
321 |
Â
$sidebar_name = isset( $labels[ $sidebar_id ] ) ? $labels[ $sidebar_id ] : $sidebar_id;
|
322 |
Â
|
323 |
Â
if ( $name && $title ) {
|
324 |
+
/* translators: %1$s: a widget name, %2$s: a widget title, %3$s: a sidebar name (e.g. "Archives", "Browse", "Footer Area 1") */
|
325 |
Â
$message = _x( '%1$s widget named "%2$s" removed from "%3$s"', '1: Name, 2: Title, 3: Sidebar Name', 'stream' );
|
326 |
Â
} elseif ( $name ) {
|
327 |
+
// Empty title, but we have the name.
|
328 |
+
/* translators: %1$s: a widget name, %3$s: a sidebar name (e.g. "Archives", "Footer Area 1") */
|
329 |
Â
$message = _x( '%1$s widget removed from "%3$s"', '1: Name, 3: Sidebar Name', 'stream' );
|
330 |
Â
} elseif ( $title ) {
|
331 |
+
// Likely a single widget since no name is available.
|
332 |
+
/* translators: %2$s: a widget title, %3$s: a sidebar name (e.g. "Browse", "Footer Area 1") */
|
333 |
Â
$message = _x( 'Unknown widget type named "%2$s" removed from "%3$s"', '2: Title, 3: Sidebar Name', 'stream' );
|
334 |
Â
} else {
|
335 |
+
// Neither a name nor a title are available, so use the widget ID.
|
336 |
+
/* translators: %4$s: a widget ID, %3$s: a sidebar name (e.g. "42", "Footer Area 1") */
|
337 |
Â
$message = _x( '%4$s widget removed from "%3$s"', '4: Widget ID, 3: Sidebar Name', 'stream' );
|
338 |
Â
}
|
339 |
Â
|
352 |
Â
/**
|
353 |
Â
* Track reactivation of widgets from sidebars
|
354 |
Â
*
|
355 |
+
* @param array $old Old sidebars widgets.
|
356 |
+
* @param array $new New sidebars widgets.
|
357 |
Â
* @return void
|
358 |
Â
*/
|
359 |
Â
protected function handle_widget_addition( $old, $new ) {
|
378 |
Â
$sidebar_name = isset( $labels[ $sidebar_id ] ) ? $labels[ $sidebar_id ] : $sidebar_id;
|
379 |
Â
|
380 |
Â
if ( $name && $title ) {
|
381 |
+
/* translators: %1$s: a widget name, %2$s: a widget title, %3$s: a sidebar name (e.g. "Archives", "Browse", "Footer Area 1") */
|
382 |
Â
$message = _x( '%1$s widget named "%2$s" added to "%3$s"', '1: Name, 2: Title, 3: Sidebar Name', 'stream' );
|
383 |
Â
} elseif ( $name ) {
|
384 |
+
// Empty title, but we have the name.
|
385 |
+
/* translators: %1$s: a widget name, %3$s: a sidebar name (e.g. "Archives", "Footer Area 1") */
|
386 |
Â
$message = _x( '%1$s widget added to "%3$s"', '1: Name, 3: Sidebar Name', 'stream' );
|
387 |
Â
} elseif ( $title ) {
|
388 |
+
// Likely a single widget since no name is available.
|
389 |
+
/* translators: %2$s: a widget title, %3$s: a sidebar name (e.g. "Browse", "Footer Area 1") */
|
390 |
Â
$message = _x( 'Unknown widget type named "%2$s" added to "%3$s"', '2: Title, 3: Sidebar Name', 'stream' );
|
391 |
Â
} else {
|
392 |
+
// Neither a name nor a title are available, so use the widget ID.
|
393 |
+
/* translators: %4$s: a widget ID, %3$s: a sidebar name (e.g. "42", "Footer Area 1") */
|
394 |
Â
$message = _x( '%4$s widget added to "%3$s"', '4: Widget ID, 3: Sidebar Name', 'stream' );
|
395 |
Â
}
|
396 |
Â
|
409 |
Â
/**
|
410 |
Â
* Track reordering of widgets
|
411 |
Â
*
|
412 |
+
* @param array $old Old sidebars widgets.
|
413 |
+
* @param array $new New sidebars widgets.
|
414 |
Â
* @return void
|
415 |
Â
*/
|
416 |
Â
protected function handle_widget_reordering( $old, $new ) {
|
421 |
Â
continue;
|
422 |
Â
}
|
423 |
Â
|
424 |
+
// Use intersect to ignore widget additions and removals.
|
425 |
Â
$all_widget_ids = array_unique( array_merge( $old[ $sidebar_id ], $new[ $sidebar_id ] ) );
|
426 |
Â
$common_widget_ids = array_intersect( $old[ $sidebar_id ], $new[ $sidebar_id ] );
|
427 |
Â
$uncommon_widget_ids = array_diff( $all_widget_ids, $common_widget_ids );
|
434 |
Â
$sidebar_name = isset( $labels[ $sidebar_id ] ) ? $labels[ $sidebar_id ] : $sidebar_id;
|
435 |
Â
$old_widget_ids = $old[ $sidebar_id ];
|
436 |
Â
|
437 |
+
/* translators: %s: a sidebar name (e.g. "Footer Area 1") */
|
438 |
Â
$message = _x( 'Widgets reordered in "%s"', 'Sidebar name', 'stream' );
|
439 |
Â
$message = sprintf( $message, $sidebar_name );
|
440 |
Â
|
453 |
Â
/**
|
454 |
Â
* Track movement of widgets to other sidebars
|
455 |
Â
*
|
456 |
+
* @param array $old Old sidebars widgets.
|
457 |
+
* @param array $new New sidebars widgets.
|
458 |
Â
* @return void
|
459 |
Â
*/
|
460 |
Â
protected function handle_widget_moved( $old, $new ) {
|
468 |
Â
$new_widget_ids = array_diff( $new[ $new_sidebar_id ], $old[ $new_sidebar_id ] );
|
469 |
Â
|
470 |
Â
foreach ( $new_widget_ids as $widget_id ) {
|
471 |
+
// Now find the sidebar that the widget was originally located in, as long it is not wp_inactive_widgets.
|
472 |
Â
$old_sidebar_id = null;
|
473 |
Â
foreach ( $old as $sidebar_id => $old_widget_ids ) {
|
474 |
Â
if ( in_array( $widget_id, $old_widget_ids, true ) ) {
|
490 |
Â
$new_sidebar_name = isset( $labels[ $new_sidebar_id ] ) ? $labels[ $new_sidebar_id ] : $new_sidebar_id;
|
491 |
Â
|
492 |
Â
if ( $name && $title ) {
|
493 |
+
/* translators: %1$s: a widget name, %2$s: a widget title, %4$s: a sidebar name, %5$s: another sidebar name (e.g. "Archives", "Browse", "Footer Area 1", "Footer Area 2") */
|
494 |
Â
$message = _x( '%1$s widget named "%2$s" moved from "%4$s" to "%5$s"', '1: Name, 2: Title, 4: Old Sidebar Name, 5: New Sidebar Name', 'stream' );
|
495 |
Â
} elseif ( $name ) {
|
496 |
+
// Empty title, but we have the name.
|
497 |
+
/* translators: %1$s: a widget name, %4$s: a sidebar name, %5$s: another sidebar name (e.g. "Archives", "Footer Area 1", "Footer Area 2") */
|
498 |
Â
$message = _x( '%1$s widget moved from "%4$s" to "%5$s"', '1: Name, 4: Old Sidebar Name, 5: New Sidebar Name', 'stream' );
|
499 |
Â
} elseif ( $title ) {
|
500 |
+
// Likely a single widget since no name is available.
|
501 |
+
/* translators: %2$s: a widget title, %4$s: a sidebar name, %5$s: another sidebar name (e.g. "Browse", "Footer Area 1", "Footer Area 2") */
|
502 |
Â
$message = _x( 'Unknown widget type named "%2$s" moved from "%4$s" to "%5$s"', '2: Title, 4: Old Sidebar Name, 5: New Sidebar Name', 'stream' );
|
503 |
Â
} else {
|
504 |
+
// Neither a name nor a title are available, so use the widget ID.
|
505 |
+
/* translators: %3$s: a widget ID, %4$s: a sidebar name, %5$s: another sidebar name (e.g. "42", "Footer Area 1", "Footer Area 2") */
|
506 |
Â
$message = _x( '%3$s widget moved from "%4$s" to "%5$s"', '3: Widget ID, 4: Old Sidebar Name, 5: New Sidebar Name', 'stream' );
|
507 |
Â
}
|
508 |
Â
|
526 |
Â
*
|
527 |
Â
* @action updated_option
|
528 |
Â
*
|
529 |
+
* @param string $option_name Option key.
|
530 |
+
* @param array $old_value Old value.
|
531 |
+
* @param array $new_value New value.
|
532 |
Â
*/
|
533 |
Â
public function callback_updated_option( $option_name, $old_value, $new_value ) {
|
534 |
Â
if ( ! preg_match( '/^widget_(.+)$/', $option_name, $matches ) || ! is_array( $new_value ) ) {
|
599 |
Â
$deletes[] = compact( 'name', 'title', 'widget_id', 'sidebar_id', 'instance' );
|
600 |
Â
}
|
601 |
Â
} else {
|
602 |
+
// Doing our best guess for tracking changes to old single widgets, assuming their options start with 'widget_'.
|
603 |
Â
$widget_id = $widget_id_base;
|
604 |
+
$name = $widget_id; // There aren't names available for single widgets.
|
605 |
Â
$title = ! empty( $new_value['title'] ) ? $new_value['title'] : null;
|
606 |
Â
$sidebar_id = $this->get_widget_sidebar_id( $widget_id );
|
607 |
Â
$old_instance = $old_value;
|
616 |
Â
*/
|
617 |
Â
foreach ( $updates as $update ) {
|
618 |
Â
if ( $update['name'] && $update['title'] ) {
|
619 |
+
/* translators: %1$s: a widget name, %2$s: a widget title, %3$s: a sidebar name (e.g. "Archives", "Browse", "Footer Area 1") */
|
620 |
Â
$message = _x( '%1$s widget named "%2$s" in "%3$s" updated', '1: Name, 2: Title, 3: Sidebar Name', 'stream' );
|
621 |
Â
} elseif ( $update['name'] ) {
|
622 |
+
// Empty title, but we have the name.
|
623 |
+
/* translators: %1$s: a widget name, %3$s: a sidebar name (e.g. "Archives", "Footer Area 1") */
|
624 |
Â
$message = _x( '%1$s widget in "%3$s" updated', '1: Name, 3: Sidebar Name', 'stream' );
|
625 |
Â
} elseif ( $update['title'] ) {
|
626 |
+
// Likely a single widget since no name is available.
|
627 |
+
/* translators: %2$s: a widget title, %3$s: a sidebar name (e.g. "Browse", "Footer Area 1") */
|
628 |
Â
$message = _x( 'Unknown widget type named "%2$s" in "%3$s" updated', '2: Title, 3: Sidebar Name', 'stream' );
|
629 |
Â
} else {
|
630 |
+
// Neither a name nor a title are available, so use the widget ID.
|
631 |
+
/* translators: %4$s: a widget ID, %3$s: a sidebar name (e.g. "42", "Footer Area 1") */
|
632 |
Â
$message = _x( '%4$s widget in "%3$s" updated', '4: Widget ID, 3: Sidebar Name', 'stream' );
|
633 |
Â
}
|
634 |
Â
|
654 |
Â
* actions would be useful to log.
|
655 |
Â
*/
|
656 |
Â
if ( $this->verbose_widget_created_deleted_actions ) {
|
657 |
+
// We should only do these if not captured by an update to the sidebars_widgets option.
|
658 |
Â
/**
|
659 |
Â
* Log created actions
|
660 |
Â
*/
|
661 |
Â
foreach ( $creates as $create ) {
|
662 |
Â
if ( $create['name'] && $create['title'] ) {
|
663 |
+
/* translators: %1$s: a widget name, %2$s: a widget title (e.g. "Archives", "Browse") */
|
664 |
Â
$message = _x( '%1$s widget named "%2$s" created', '1: Name, 2: Title', 'stream' );
|
665 |
Â
} elseif ( $create['name'] ) {
|
666 |
+
// Empty title, but we have the name.
|
667 |
+
/* translators: %1$s: a widget name (e.g. "Archives") */
|
668 |
Â
$message = _x( '%1$s widget created', '1: Name', 'stream' );
|
669 |
Â
} elseif ( $create['title'] ) {
|
670 |
+
// Likely a single widget since no name is available.
|
671 |
+
/* translators: %2$s: a widget title (e.g. "Browse") */
|
672 |
Â
$message = _x( 'Unknown widget type named "%2$s" created', '2: Title', 'stream' );
|
673 |
Â
} else {
|
674 |
+
// Neither a name nor a title are available, so use the widget ID.
|
675 |
+
/* translators: %3$s: a widget ID (e.g. "42") */
|
676 |
Â
$message = _x( '%3$s widget created', '3: Widget ID', 'stream' );
|
677 |
Â
}
|
678 |
Â
|
694 |
Â
*/
|
695 |
Â
foreach ( $deletes as $delete ) {
|
696 |
Â
if ( $delete['name'] && $delete['title'] ) {
|
697 |
+
/* translators: %1$s: a widget name, %2$s: a widget title (e.g. "Archives", "Browse") */
|
698 |
Â
$message = _x( '%1$s widget named "%2$s" deleted', '1: Name, 2: Title', 'stream' );
|
699 |
Â
} elseif ( $delete['name'] ) {
|
700 |
+
// Empty title, but we have the name.
|
701 |
+
/* translators: %1$s: a widget name (e.g. "Archives") */
|
702 |
Â
$message = _x( '%1$s widget deleted', '1: Name', 'stream' );
|
703 |
Â
} elseif ( $delete['title'] ) {
|
704 |
+
// Likely a single widget since no name is available.
|
705 |
+
/* translators: %2$s: a widget title (e.g. "Browse") */
|
706 |
Â
$message = _x( 'Unknown widget type named "%2$s" deleted', '2: Title', 'stream' );
|
707 |
Â
} else {
|
708 |
+
// Neither a name nor a title are available, so use the widget ID.
|
709 |
+
/* translators: %3$s: a widget ID (e.g. "42") */
|
710 |
Â
$message = _x( '%3$s widget deleted', '3: Widget ID', 'stream' );
|
711 |
Â
}
|
712 |
Â
|
726 |
Â
}
|
727 |
Â
|
728 |
Â
/**
|
729 |
+
* Returns widget title.
|
730 |
+
*
|
731 |
+
* @param string $widget_id Widget instance ID.
|
732 |
Â
*
|
733 |
Â
* @return string
|
734 |
Â
*/
|
738 |
Â
}
|
739 |
Â
|
740 |
Â
/**
|
741 |
+
* Returns widget name.
|
742 |
+
*
|
743 |
+
* @param string $widget_id Widget instance ID.
|
744 |
Â
*
|
745 |
Â
* @return string|null
|
746 |
Â
*/
|
750 |
Â
}
|
751 |
Â
|
752 |
Â
/**
|
753 |
+
* Parses widget instance ID and widget type data.
|
754 |
+
*
|
755 |
+
* @param string $widget_id Widget instance ID.
|
756 |
Â
*
|
757 |
Â
* @return array|null
|
758 |
Â
*/
|
768 |
Â
}
|
769 |
Â
|
770 |
Â
/**
|
771 |
+
* Returns widget object.
|
772 |
+
*
|
773 |
+
* @param string $widget_id Widget instance ID.
|
774 |
Â
*
|
775 |
Â
* @return \WP_Widget|null
|
776 |
Â
*/
|
800 |
Â
/**
|
801 |
Â
* Returns widget instance settings
|
802 |
Â
*
|
803 |
+
* @param string $widget_id Widget ID, ex: pages-1.
|
804 |
Â
*
|
805 |
Â
* @return array|null Widget instance
|
806 |
Â
*/
|
817 |
Â
$instance = $settings[ $multi_number ];
|
818 |
Â
}
|
819 |
Â
} else {
|
820 |
+
// Single widgets, try our best guess at the option used.
|
821 |
Â
$potential_instance = get_option( "widget_{$widget_id}" );
|
822 |
Â
|
823 |
Â
if ( ! empty( $potential_instance ) && ! empty( $potential_instance['title'] ) ) {
|
849 |
Â
/**
|
850 |
Â
* Return the sidebar of a certain widget, based on widget_id
|
851 |
Â
*
|
852 |
+
* @param string $widget_id Widget id, ex: pages-1.
|
853 |
Â
*
|
854 |
Â
* @return string Sidebar id
|
855 |
Â
*/
|
connectors/class-connector-woocommerce.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_Woocommerce extends Connector {
|
5 |
Â
/**
|
6 |
Â
* Context name
|
@@ -35,6 +44,11 @@ class Connector_Woocommerce extends Connector {
|
|
35 |
Â
'woocommerce_tax_rate_deleted',
|
36 |
Â
);
|
37 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
38 |
Â
public $taxonomies = array(
|
39 |
Â
'product_type',
|
40 |
Â
'product_cat',
|
@@ -43,6 +57,11 @@ class Connector_Woocommerce extends Connector {
|
|
43 |
Â
'shop_order_status',
|
44 |
Â
);
|
45 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
46 |
Â
public $post_types = array(
|
47 |
Â
'product',
|
48 |
Â
'product_variation',
|
@@ -50,14 +69,37 @@ class Connector_Woocommerce extends Connector {
|
|
50 |
Â
'shop_coupon',
|
51 |
Â
);
|
52 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
53 |
Â
private $order_update_logged = false;
|
54 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
55 |
Â
private $settings_pages = array();
|
56 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
57 |
Â
private $settings = array();
|
58 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
59 |
Â
private $plugin_version = null;
|
60 |
Â
|
Â
|
|
Â
|
|
Â
|
|
61 |
Â
public function register() {
|
62 |
Â
parent::register();
|
63 |
Â
|
@@ -208,8 +250,8 @@ class Connector_Woocommerce extends Connector {
|
|
208 |
Â
*
|
209 |
Â
* @filter wp_stream_action_links_{connector}
|
210 |
Â
*
|
211 |
-
* @param array $links Previous links registered
|
212 |
-
* @param Record $record
|
213 |
Â
*
|
214 |
Â
* @return array Action links
|
215 |
Â
*/
|
@@ -219,7 +261,7 @@ class Connector_Woocommerce extends Connector {
|
|
219 |
Â
if ( $edit_post_link ) {
|
220 |
Â
$posts_connector = new Connector_Posts();
|
221 |
Â
$post_type_name = $posts_connector->get_post_type_name( get_post_type( $record->object_id ) );
|
222 |
-
|
223 |
Â
$links[ sprintf( esc_html_x( 'Edit %s', 'Post type singular name', 'stream' ), $post_type_name ) ] = $edit_post_link;
|
224 |
Â
}
|
225 |
Â
|
@@ -236,7 +278,7 @@ class Connector_Woocommerce extends Connector {
|
|
236 |
Â
$option_section = $record->get_meta( 'section', true );
|
237 |
Â
|
238 |
Â
if ( $option_key && $option_tab ) {
|
239 |
-
|
240 |
Â
$text = sprintf( esc_html__( 'Edit WooCommerce %s', 'stream' ), $context_labels[ $record->context ] );
|
241 |
Â
$url = add_query_arg(
|
242 |
Â
array(
|
@@ -244,7 +286,7 @@ class Connector_Woocommerce extends Connector {
|
|
244 |
Â
'tab' => $option_tab,
|
245 |
Â
'section' => $option_section,
|
246 |
Â
),
|
247 |
-
admin_url( 'admin.php' ) // Not self_admin_url here, as WooCommerce doesn't exist in Network Admin
|
248 |
Â
);
|
249 |
Â
|
250 |
Â
$links[ $text ] = $url . '#wp-stream-highlight:' . $option_key;
|
@@ -259,7 +301,7 @@ class Connector_Woocommerce extends Connector {
|
|
259 |
Â
*
|
260 |
Â
* @filter wp_stream_posts_exclude_post_types
|
261 |
Â
*
|
262 |
-
* @param array $post_types
|
263 |
Â
*
|
264 |
Â
* @return array Filtered post types
|
265 |
Â
*/
|
@@ -275,7 +317,7 @@ class Connector_Woocommerce extends Connector {
|
|
275 |
Â
*
|
276 |
Â
* @filter wp_stream_commnent_exclude_comment_types
|
277 |
Â
*
|
278 |
-
* @param array $comment_types
|
279 |
Â
*
|
280 |
Â
* @return array Filtered post types
|
281 |
Â
*/
|
@@ -290,27 +332,27 @@ class Connector_Woocommerce extends Connector {
|
|
290 |
Â
*
|
291 |
Â
* @action transition_post_status
|
292 |
Â
*
|
293 |
-
* @param string $new
|
294 |
-
* @param string $old
|
295 |
-
* @param \WP_Post $post
|
296 |
Â
*/
|
297 |
Â
public function callback_transition_post_status( $new, $old, $post ) {
|
298 |
-
// Only track orders
|
299 |
Â
if ( 'shop_order' !== $post->post_type ) {
|
300 |
Â
return;
|
301 |
Â
}
|
302 |
Â
|
303 |
-
// Don't track customer actions
|
304 |
Â
if ( ! is_admin() ) {
|
305 |
Â
return;
|
306 |
Â
}
|
307 |
Â
|
308 |
-
// Don't track minor status change actions
|
309 |
Â
if ( in_array( wp_stream_filter_input( INPUT_GET, 'action' ), array( 'mark_processing', 'mark_on-hold', 'mark_completed' ), true ) || defined( 'DOING_AJAX' ) ) {
|
310 |
Â
return;
|
311 |
Â
}
|
312 |
Â
|
313 |
-
// Don't log updates when more than one happens at the same time
|
314 |
Â
if ( $post->ID === $this->order_update_logged ) {
|
315 |
Â
return;
|
316 |
Â
}
|
@@ -318,7 +360,7 @@ class Connector_Woocommerce extends Connector {
|
|
318 |
Â
if ( in_array( $new, array( 'auto-draft', 'draft', 'inherit' ), true ) ) {
|
319 |
Â
return;
|
320 |
Â
} elseif ( 'auto-draft' === $old && 'publish' === $new ) {
|
321 |
-
|
322 |
Â
$message = esc_html_x(
|
323 |
Â
'%s created',
|
324 |
Â
'Order title',
|
@@ -326,7 +368,7 @@ class Connector_Woocommerce extends Connector {
|
|
326 |
Â
);
|
327 |
Â
$action = 'created';
|
328 |
Â
} elseif ( 'trash' === $new ) {
|
329 |
-
|
330 |
Â
$message = esc_html_x(
|
331 |
Â
'%s trashed',
|
332 |
Â
'Order title',
|
@@ -334,7 +376,7 @@ class Connector_Woocommerce extends Connector {
|
|
334 |
Â
);
|
335 |
Â
$action = 'trashed';
|
336 |
Â
} elseif ( 'trash' === $old && 'publish' === $new ) {
|
337 |
-
|
338 |
Â
$message = esc_html_x(
|
339 |
Â
'%s restored from the trash',
|
340 |
Â
'Order title',
|
@@ -342,7 +384,7 @@ class Connector_Woocommerce extends Connector {
|
|
342 |
Â
);
|
343 |
Â
$action = 'untrashed';
|
344 |
Â
} else {
|
345 |
-
|
346 |
Â
$message = esc_html_x(
|
347 |
Â
'%s updated',
|
348 |
Â
'Order title',
|
@@ -380,17 +422,17 @@ class Connector_Woocommerce extends Connector {
|
|
380 |
Â
*
|
381 |
Â
* @action deleted_post
|
382 |
Â
*
|
383 |
-
* @param int $post_id
|
384 |
Â
*/
|
385 |
Â
public function callback_deleted_post( $post_id ) {
|
386 |
Â
$post = get_post( $post_id );
|
387 |
Â
|
388 |
-
// We check if post is an instance of WP_Post as it doesn't always resolve in unit testing
|
389 |
Â
if ( ! ( $post instanceof \WP_Post ) || 'shop_order' !== $post->post_type ) {
|
390 |
Â
return;
|
391 |
Â
}
|
392 |
Â
|
393 |
-
// Ignore auto-drafts that are deleted by the system, see issue-293
|
394 |
Â
if ( 'auto-draft' === $post->post_status ) {
|
395 |
Â
return;
|
396 |
Â
}
|
@@ -400,7 +442,7 @@ class Connector_Woocommerce extends Connector {
|
|
400 |
Â
$order_type_name = esc_html__( 'order', 'stream' );
|
401 |
Â
|
402 |
Â
$this->log(
|
403 |
-
|
404 |
Â
_x(
|
405 |
Â
'"%s" deleted from trash',
|
406 |
Â
'Order title',
|
@@ -421,17 +463,17 @@ class Connector_Woocommerce extends Connector {
|
|
421 |
Â
*
|
422 |
Â
* @action woocommerce_order_status_changed
|
423 |
Â
*
|
424 |
-
* @param int $order_id
|
425 |
-
* @param string $old
|
426 |
-
* @param string $new
|
427 |
Â
*/
|
428 |
Â
public function callback_woocommerce_order_status_changed( $order_id, $old, $new ) {
|
429 |
-
// Don't track customer actions
|
430 |
Â
if ( ! is_admin() ) {
|
431 |
Â
return;
|
432 |
Â
}
|
433 |
Â
|
434 |
-
// Don't track new statuses
|
435 |
Â
if ( empty( $old ) ) {
|
436 |
Â
return;
|
437 |
Â
}
|
@@ -446,7 +488,7 @@ class Connector_Woocommerce extends Connector {
|
|
446 |
Â
$old_status_name = $old_status->name;
|
447 |
Â
}
|
448 |
Â
|
449 |
-
|
450 |
Â
$message = esc_html_x(
|
451 |
Â
'%1$s status changed from %2$s to %3$s',
|
452 |
Â
'1. Order title, 2. Old status, 3. New status',
|
@@ -479,12 +521,12 @@ class Connector_Woocommerce extends Connector {
|
|
479 |
Â
*
|
480 |
Â
* @action woocommerce_attribute_added
|
481 |
Â
*
|
482 |
-
* @param int $attribute_id
|
483 |
-
* @param array $attribute
|
484 |
Â
*/
|
485 |
Â
public function callback_woocommerce_attribute_added( $attribute_id, $attribute ) {
|
486 |
Â
$this->log(
|
487 |
-
|
488 |
Â
_x(
|
489 |
Â
'"%s" product attribute created',
|
490 |
Â
'Term name',
|
@@ -502,12 +544,12 @@ class Connector_Woocommerce extends Connector {
|
|
502 |
Â
*
|
503 |
Â
* @action woocommerce_attribute_updated
|
504 |
Â
*
|
505 |
-
* @param int $attribute_id
|
506 |
-
* @param array $attribute
|
507 |
Â
*/
|
508 |
Â
public function callback_woocommerce_attribute_updated( $attribute_id, $attribute ) {
|
509 |
Â
$this->log(
|
510 |
-
|
511 |
Â
_x(
|
512 |
Â
'"%s" product attribute updated',
|
513 |
Â
'Term name',
|
@@ -525,12 +567,12 @@ class Connector_Woocommerce extends Connector {
|
|
525 |
Â
*
|
526 |
Â
* @action woocommerce_attribute_updated
|
527 |
Â
*
|
528 |
-
* @param int $attribute_id
|
529 |
-
* @param string $attribute_name
|
530 |
Â
*/
|
531 |
Â
public function callback_woocommerce_attribute_deleted( $attribute_id, $attribute_name ) {
|
532 |
Â
$this->log(
|
533 |
-
|
534 |
Â
_x(
|
535 |
Â
'"%s" product attribute deleted',
|
536 |
Â
'Term name',
|
@@ -550,12 +592,12 @@ class Connector_Woocommerce extends Connector {
|
|
550 |
Â
*
|
551 |
Â
* @action woocommerce_tax_rate_added
|
552 |
Â
*
|
553 |
-
* @param int $tax_rate_id
|
554 |
-
* @param array $tax_rate
|
555 |
Â
*/
|
556 |
Â
public function callback_woocommerce_tax_rate_added( $tax_rate_id, $tax_rate ) {
|
557 |
Â
$this->log(
|
558 |
-
|
559 |
Â
_x(
|
560 |
Â
'"%4$s" tax rate created',
|
561 |
Â
'Tax rate name',
|
@@ -573,12 +615,12 @@ class Connector_Woocommerce extends Connector {
|
|
573 |
Â
*
|
574 |
Â
* @action woocommerce_tax_rate_updated
|
575 |
Â
*
|
576 |
-
* @param int $tax_rate_id
|
577 |
-
* @param array $tax_rate
|
578 |
Â
*/
|
579 |
Â
public function callback_woocommerce_tax_rate_updated( $tax_rate_id, $tax_rate ) {
|
580 |
Â
$this->log(
|
581 |
-
|
582 |
Â
_x(
|
583 |
Â
'"%4$s" tax rate updated',
|
584 |
Â
'Tax rate name',
|
@@ -596,7 +638,7 @@ class Connector_Woocommerce extends Connector {
|
|
596 |
Â
*
|
597 |
Â
* @action woocommerce_tax_rate_updated
|
598 |
Â
*
|
599 |
-
* @param int $tax_rate_id
|
600 |
Â
*/
|
601 |
Â
public function callback_woocommerce_tax_rate_deleted( $tax_rate_id ) {
|
602 |
Â
global $wpdb;
|
@@ -611,7 +653,7 @@ class Connector_Woocommerce extends Connector {
|
|
611 |
Â
);
|
612 |
Â
|
613 |
Â
$this->log(
|
614 |
-
|
615 |
Â
_x(
|
616 |
Â
'"%s" tax rate deleted',
|
617 |
Â
'Tax rate name',
|
@@ -631,7 +673,7 @@ class Connector_Woocommerce extends Connector {
|
|
631 |
Â
*
|
632 |
Â
* @filter wp_stream_record_array
|
633 |
Â
*
|
634 |
-
* @param array $recordarr
|
635 |
Â
*
|
636 |
Â
* @return array Filtered record data
|
637 |
Â
*/
|
@@ -641,7 +683,7 @@ class Connector_Woocommerce extends Connector {
|
|
641 |
Â
continue;
|
642 |
Â
}
|
643 |
Â
|
644 |
-
// Change connector::posts records
|
645 |
Â
if ( 'posts' === $record['connector'] && in_array( $record['context'], $this->post_types, true ) ) {
|
646 |
Â
$recordarr[ $key ]['connector'] = $this->name;
|
647 |
Â
} elseif ( 'taxonomies' === $record['connector'] && in_array( $record['context'], $this->taxonomies, true ) ) {
|
@@ -658,6 +700,13 @@ class Connector_Woocommerce extends Connector {
|
|
658 |
Â
return $recordarr;
|
659 |
Â
}
|
660 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
661 |
Â
public function callback_updated_option( $option_key, $old_value, $value ) {
|
662 |
Â
$options = array( $option_key );
|
663 |
Â
|
@@ -673,7 +722,7 @@ class Connector_Woocommerce extends Connector {
|
|
673 |
Â
}
|
674 |
Â
|
675 |
Â
$this->log(
|
676 |
-
|
677 |
Â
__( '"%1$s" %2$s updated', 'stream' ),
|
678 |
Â
array(
|
679 |
Â
'label' => $this->settings[ $option ]['title'],
|
@@ -692,6 +741,9 @@ class Connector_Woocommerce extends Connector {
|
|
692 |
Â
}
|
693 |
Â
}
|
694 |
Â
|
Â
|
|
Â
|
|
Â
|
|
695 |
Â
public function get_woocommerce_settings_fields() {
|
696 |
Â
if ( ! defined( 'WC_VERSION' ) || ! class_exists( 'WC_Admin_Settings' ) ) {
|
697 |
Â
return false;
|
@@ -714,8 +766,10 @@ class Connector_Woocommerce extends Connector {
|
|
714 |
Â
$settings_pages = array();
|
715 |
Â
|
716 |
Â
foreach ( \WC_Admin_Settings::get_settings_pages() as $page ) {
|
717 |
-
|
718 |
-
|
Â
|
|
Â
|
|
719 |
Â
$info = $page->add_settings_page( array() );
|
720 |
Â
$page_id = key( $info );
|
721 |
Â
$page_label = current( $info );
|
@@ -727,7 +781,7 @@ class Connector_Woocommerce extends Connector {
|
|
727 |
Â
|
728 |
Â
$settings_pages[ $page_id ] = $page_label;
|
729 |
Â
|
730 |
-
// Remove non-fields ( sections, titles and whatever )
|
731 |
Â
$fields = array();
|
732 |
Â
|
733 |
Â
foreach ( $sections as $section_key => $section_label ) {
|
@@ -750,11 +804,11 @@ class Connector_Woocommerce extends Connector {
|
|
750 |
Â
}
|
751 |
Â
}
|
752 |
Â
|
753 |
-
// Store fields in the global array to be searched later
|
754 |
Â
$settings = array_merge( $settings, $fields );
|
755 |
Â
}
|
756 |
Â
|
757 |
-
// Provide additional context for each of the settings pages
|
758 |
Â
array_walk(
|
759 |
Â
$settings_pages,
|
760 |
Â
function( &$value ) {
|
@@ -762,7 +816,7 @@ class Connector_Woocommerce extends Connector {
|
|
762 |
Â
}
|
763 |
Â
);
|
764 |
Â
|
765 |
-
// Load Payment Gateway Settings
|
766 |
Â
$payment_gateway_settings = array();
|
767 |
Â
$payment_gateways = $woocommerce->payment_gateways();
|
768 |
Â
|
@@ -781,7 +835,7 @@ class Connector_Woocommerce extends Connector {
|
|
781 |
Â
|
782 |
Â
$settings = array_merge( $settings, $payment_gateway_settings );
|
783 |
Â
|
784 |
-
// Load Shipping Method Settings
|
785 |
Â
$shipping_method_settings = array();
|
786 |
Â
$shipping_methods = $woocommerce->shipping();
|
787 |
Â
|
@@ -800,7 +854,7 @@ class Connector_Woocommerce extends Connector {
|
|
800 |
Â
|
801 |
Â
$settings = array_merge( $settings, $shipping_method_settings );
|
802 |
Â
|
803 |
-
// Load Email Settings
|
804 |
Â
$email_settings = array();
|
805 |
Â
$emails = $woocommerce->mailer();
|
806 |
Â
|
@@ -819,14 +873,14 @@ class Connector_Woocommerce extends Connector {
|
|
819 |
Â
|
820 |
Â
$settings = array_merge( $settings, $email_settings );
|
821 |
Â
|
822 |
-
// Tools page
|
823 |
Â
$tools_page = array(
|
824 |
Â
'tools' => esc_html__( 'Tools', 'stream' ),
|
825 |
Â
);
|
826 |
Â
|
827 |
Â
$settings_pages = array_merge( $settings_pages, $tools_page );
|
828 |
Â
|
829 |
-
// Cache the results
|
830 |
Â
$settings_cache = array(
|
831 |
Â
'settings' => $settings,
|
832 |
Â
'settings_pages' => $settings_pages,
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for WooCommerce
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_WooCommerce
|
12 |
+
*/
|
13 |
Â
class Connector_Woocommerce extends Connector {
|
14 |
Â
/**
|
15 |
Â
* Context name
|
44 |
Â
'woocommerce_tax_rate_deleted',
|
45 |
Â
);
|
46 |
Â
|
47 |
+
/**
|
48 |
+
* Taxonomies tracked by this connector.
|
49 |
+
*
|
50 |
+
* @var array
|
51 |
+
*/
|
52 |
Â
public $taxonomies = array(
|
53 |
Â
'product_type',
|
54 |
Â
'product_cat',
|
57 |
Â
'shop_order_status',
|
58 |
Â
);
|
59 |
Â
|
60 |
+
/**
|
61 |
+
* Post-types tracked by this connector.
|
62 |
+
*
|
63 |
+
* @var array
|
64 |
+
*/
|
65 |
Â
public $post_types = array(
|
66 |
Â
'product',
|
67 |
Â
'product_variation',
|
69 |
Â
'shop_coupon',
|
70 |
Â
);
|
71 |
Â
|
72 |
+
/**
|
73 |
+
* Is the most recently update order logged yet.
|
74 |
+
*
|
75 |
+
* @var boolean
|
76 |
+
*/
|
77 |
Â
private $order_update_logged = false;
|
78 |
Â
|
79 |
+
/**
|
80 |
+
* Caches WooCommerce settings page objects.
|
81 |
+
*
|
82 |
+
* @var array
|
83 |
+
*/
|
84 |
Â
private $settings_pages = array();
|
85 |
Â
|
86 |
+
/**
|
87 |
+
* Caches WooCommerce settings.
|
88 |
+
*
|
89 |
+
* @var array
|
90 |
+
*/
|
91 |
Â
private $settings = array();
|
92 |
Â
|
93 |
+
/**
|
94 |
+
* Stores the WooCommerce version number.
|
95 |
+
*
|
96 |
+
* @var string|null
|
97 |
+
*/
|
98 |
Â
private $plugin_version = null;
|
99 |
Â
|
100 |
+
/**
|
101 |
+
* Register connection
|
102 |
+
*/
|
103 |
Â
public function register() {
|
104 |
Â
parent::register();
|
105 |
Â
|
250 |
Â
*
|
251 |
Â
* @filter wp_stream_action_links_{connector}
|
252 |
Â
*
|
253 |
+
* @param array $links Previous links registered.
|
254 |
+
* @param Record $record Stream record.
|
255 |
Â
*
|
256 |
Â
* @return array Action links
|
257 |
Â
*/
|
261 |
Â
if ( $edit_post_link ) {
|
262 |
Â
$posts_connector = new Connector_Posts();
|
263 |
Â
$post_type_name = $posts_connector->get_post_type_name( get_post_type( $record->object_id ) );
|
264 |
+
/* translators: %s: a post type singular name (e.g. "Post") */
|
265 |
Â
$links[ sprintf( esc_html_x( 'Edit %s', 'Post type singular name', 'stream' ), $post_type_name ) ] = $edit_post_link;
|
266 |
Â
}
|
267 |
Â
|
278 |
Â
$option_section = $record->get_meta( 'section', true );
|
279 |
Â
|
280 |
Â
if ( $option_key && $option_tab ) {
|
281 |
+
/* translators: %s a context (e.g. "Attribute") */
|
282 |
Â
$text = sprintf( esc_html__( 'Edit WooCommerce %s', 'stream' ), $context_labels[ $record->context ] );
|
283 |
Â
$url = add_query_arg(
|
284 |
Â
array(
|
286 |
Â
'tab' => $option_tab,
|
287 |
Â
'section' => $option_section,
|
288 |
Â
),
|
289 |
+
admin_url( 'admin.php' ) // Not self_admin_url here, as WooCommerce doesn't exist in Network Admin.
|
290 |
Â
);
|
291 |
Â
|
292 |
Â
$links[ $text ] = $url . '#wp-stream-highlight:' . $option_key;
|
301 |
Â
*
|
302 |
Â
* @filter wp_stream_posts_exclude_post_types
|
303 |
Â
*
|
304 |
+
* @param array $post_types Ignored post types.
|
305 |
Â
*
|
306 |
Â
* @return array Filtered post types
|
307 |
Â
*/
|
317 |
Â
*
|
318 |
Â
* @filter wp_stream_commnent_exclude_comment_types
|
319 |
Â
*
|
320 |
+
* @param array $comment_types Ignored post types.
|
321 |
Â
*
|
322 |
Â
* @return array Filtered post types
|
323 |
Â
*/
|
332 |
Â
*
|
333 |
Â
* @action transition_post_status
|
334 |
Â
*
|
335 |
+
* @param string $new New status.
|
336 |
+
* @param string $old Old status.
|
337 |
+
* @param \WP_Post $post Post object.
|
338 |
Â
*/
|
339 |
Â
public function callback_transition_post_status( $new, $old, $post ) {
|
340 |
+
// Only track orders.
|
341 |
Â
if ( 'shop_order' !== $post->post_type ) {
|
342 |
Â
return;
|
343 |
Â
}
|
344 |
Â
|
345 |
+
// Don't track customer actions.
|
346 |
Â
if ( ! is_admin() ) {
|
347 |
Â
return;
|
348 |
Â
}
|
349 |
Â
|
350 |
+
// Don't track minor status change actions.
|
351 |
Â
if ( in_array( wp_stream_filter_input( INPUT_GET, 'action' ), array( 'mark_processing', 'mark_on-hold', 'mark_completed' ), true ) || defined( 'DOING_AJAX' ) ) {
|
352 |
Â
return;
|
353 |
Â
}
|
354 |
Â
|
355 |
+
// Don't log updates when more than one happens at the same time.
|
356 |
Â
if ( $post->ID === $this->order_update_logged ) {
|
357 |
Â
return;
|
358 |
Â
}
|
360 |
Â
if ( in_array( $new, array( 'auto-draft', 'draft', 'inherit' ), true ) ) {
|
361 |
Â
return;
|
362 |
Â
} elseif ( 'auto-draft' === $old && 'publish' === $new ) {
|
363 |
+
/* translators: %s: an order title (e.g. "Order #42") */
|
364 |
Â
$message = esc_html_x(
|
365 |
Â
'%s created',
|
366 |
Â
'Order title',
|
368 |
Â
);
|
369 |
Â
$action = 'created';
|
370 |
Â
} elseif ( 'trash' === $new ) {
|
371 |
+
/* translators: %s: an order title (e.g. "Order #42") */
|
372 |
Â
$message = esc_html_x(
|
373 |
Â
'%s trashed',
|
374 |
Â
'Order title',
|
376 |
Â
);
|
377 |
Â
$action = 'trashed';
|
378 |
Â
} elseif ( 'trash' === $old && 'publish' === $new ) {
|
379 |
+
/* translators: %s: an order title (e.g. "Order #42") */
|
380 |
Â
$message = esc_html_x(
|
381 |
Â
'%s restored from the trash',
|
382 |
Â
'Order title',
|
384 |
Â
);
|
385 |
Â
$action = 'untrashed';
|
386 |
Â
} else {
|
387 |
+
/* translators: %s: an order title (e.g. "Order #42") */
|
388 |
Â
$message = esc_html_x(
|
389 |
Â
'%s updated',
|
390 |
Â
'Order title',
|
422 |
Â
*
|
423 |
Â
* @action deleted_post
|
424 |
Â
*
|
425 |
+
* @param int $post_id Post ID.
|
426 |
Â
*/
|
427 |
Â
public function callback_deleted_post( $post_id ) {
|
428 |
Â
$post = get_post( $post_id );
|
429 |
Â
|
430 |
+
// We check if post is an instance of WP_Post as it doesn't always resolve in unit testing.
|
431 |
Â
if ( ! ( $post instanceof \WP_Post ) || 'shop_order' !== $post->post_type ) {
|
432 |
Â
return;
|
433 |
Â
}
|
434 |
Â
|
435 |
+
// Ignore auto-drafts that are deleted by the system, see issue-293.
|
436 |
Â
if ( 'auto-draft' === $post->post_status ) {
|
437 |
Â
return;
|
438 |
Â
}
|
442 |
Â
$order_type_name = esc_html__( 'order', 'stream' );
|
443 |
Â
|
444 |
Â
$this->log(
|
445 |
+
/* translators: %s: an order title (e.g. "Order #42") */
|
446 |
Â
_x(
|
447 |
Â
'"%s" deleted from trash',
|
448 |
Â
'Order title',
|
463 |
Â
*
|
464 |
Â
* @action woocommerce_order_status_changed
|
465 |
Â
*
|
466 |
+
* @param int $order_id Order ID.
|
467 |
+
* @param string $old Old status.
|
468 |
+
* @param string $new New status.
|
469 |
Â
*/
|
470 |
Â
public function callback_woocommerce_order_status_changed( $order_id, $old, $new ) {
|
471 |
+
// Don't track customer actions.
|
472 |
Â
if ( ! is_admin() ) {
|
473 |
Â
return;
|
474 |
Â
}
|
475 |
Â
|
476 |
+
// Don't track new statuses.
|
477 |
Â
if ( empty( $old ) ) {
|
478 |
Â
return;
|
479 |
Â
}
|
488 |
Â
$old_status_name = $old_status->name;
|
489 |
Â
}
|
490 |
Â
|
491 |
+
/* translators: %1$s: an order title, %2$s: order status, %3$s: another order status (e.g. "Order #42", "processing", "complete") */
|
492 |
Â
$message = esc_html_x(
|
493 |
Â
'%1$s status changed from %2$s to %3$s',
|
494 |
Â
'1. Order title, 2. Old status, 3. New status',
|
521 |
Â
*
|
522 |
Â
* @action woocommerce_attribute_added
|
523 |
Â
*
|
524 |
+
* @param int $attribute_id Attribute ID.
|
525 |
+
* @param array $attribute Attribute data.
|
526 |
Â
*/
|
527 |
Â
public function callback_woocommerce_attribute_added( $attribute_id, $attribute ) {
|
528 |
Â
$this->log(
|
529 |
+
/* translators: %s: a term name (e.g. "color") */
|
530 |
Â
_x(
|
531 |
Â
'"%s" product attribute created',
|
532 |
Â
'Term name',
|
544 |
Â
*
|
545 |
Â
* @action woocommerce_attribute_updated
|
546 |
Â
*
|
547 |
+
* @param int $attribute_id Attribute ID.
|
548 |
+
* @param array $attribute Attribute data.
|
549 |
Â
*/
|
550 |
Â
public function callback_woocommerce_attribute_updated( $attribute_id, $attribute ) {
|
551 |
Â
$this->log(
|
552 |
+
/* translators: %s a term name (e.g. "color") */
|
553 |
Â
_x(
|
554 |
Â
'"%s" product attribute updated',
|
555 |
Â
'Term name',
|
567 |
Â
*
|
568 |
Â
* @action woocommerce_attribute_updated
|
569 |
Â
*
|
570 |
+
* @param int $attribute_id Attribute ID.
|
571 |
+
* @param string $attribute_name Attribute name.
|
572 |
Â
*/
|
573 |
Â
public function callback_woocommerce_attribute_deleted( $attribute_id, $attribute_name ) {
|
574 |
Â
$this->log(
|
575 |
+
/* translators: %s: a term name (e.g. "color") */
|
576 |
Â
_x(
|
577 |
Â
'"%s" product attribute deleted',
|
578 |
Â
'Term name',
|
592 |
Â
*
|
593 |
Â
* @action woocommerce_tax_rate_added
|
594 |
Â
*
|
595 |
+
* @param int $tax_rate_id Tax Rate ID.
|
596 |
+
* @param array $tax_rate Tax Rate data.
|
597 |
Â
*/
|
598 |
Â
public function callback_woocommerce_tax_rate_added( $tax_rate_id, $tax_rate ) {
|
599 |
Â
$this->log(
|
600 |
+
/* translators: %4$s: a tax rate name (e.g. "GST") */
|
601 |
Â
_x(
|
602 |
Â
'"%4$s" tax rate created',
|
603 |
Â
'Tax rate name',
|
615 |
Â
*
|
616 |
Â
* @action woocommerce_tax_rate_updated
|
617 |
Â
*
|
618 |
+
* @param int $tax_rate_id Tax Rate ID.
|
619 |
+
* @param array $tax_rate Tax Rate data.
|
620 |
Â
*/
|
621 |
Â
public function callback_woocommerce_tax_rate_updated( $tax_rate_id, $tax_rate ) {
|
622 |
Â
$this->log(
|
623 |
+
/* translators: %4$s: a tax rate name (e.g. "GST") */
|
624 |
Â
_x(
|
625 |
Â
'"%4$s" tax rate updated',
|
626 |
Â
'Tax rate name',
|
638 |
Â
*
|
639 |
Â
* @action woocommerce_tax_rate_updated
|
640 |
Â
*
|
641 |
+
* @param int $tax_rate_id Tax Rate ID.
|
642 |
Â
*/
|
643 |
Â
public function callback_woocommerce_tax_rate_deleted( $tax_rate_id ) {
|
644 |
Â
global $wpdb;
|
653 |
Â
);
|
654 |
Â
|
655 |
Â
$this->log(
|
656 |
+
/* translators: %4$s: a tax rate name (e.g. "GST") */
|
657 |
Â
_x(
|
658 |
Â
'"%s" tax rate deleted',
|
659 |
Â
'Tax rate name',
|
673 |
Â
*
|
674 |
Â
* @filter wp_stream_record_array
|
675 |
Â
*
|
676 |
+
* @param array $recordarr Record data to be inserted.
|
677 |
Â
*
|
678 |
Â
* @return array Filtered record data
|
679 |
Â
*/
|
683 |
Â
continue;
|
684 |
Â
}
|
685 |
Â
|
686 |
+
// Change connector::posts records.
|
687 |
Â
if ( 'posts' === $record['connector'] && in_array( $record['context'], $this->post_types, true ) ) {
|
688 |
Â
$recordarr[ $key ]['connector'] = $this->name;
|
689 |
Â
} elseif ( 'taxonomies' === $record['connector'] && in_array( $record['context'], $this->taxonomies, true ) ) {
|
700 |
Â
return $recordarr;
|
701 |
Â
}
|
702 |
Â
|
703 |
+
/**
|
704 |
+
* Track WooCommerce-specific option changes.
|
705 |
+
*
|
706 |
+
* @param string $option_key Option key.
|
707 |
+
* @param string $old_value Old value.
|
708 |
+
* @param string $value New value.
|
709 |
+
*/
|
710 |
Â
public function callback_updated_option( $option_key, $old_value, $value ) {
|
711 |
Â
$options = array( $option_key );
|
712 |
Â
|
722 |
Â
}
|
723 |
Â
|
724 |
Â
$this->log(
|
725 |
+
/* translators: %1$s: a setting name, %2$s: a setting type (e.g. "Direct Deposit", "Payment Method") */
|
726 |
Â
__( '"%1$s" %2$s updated', 'stream' ),
|
727 |
Â
array(
|
728 |
Â
'label' => $this->settings[ $option ]['title'],
|
741 |
Â
}
|
742 |
Â
}
|
743 |
Â
|
744 |
+
/**
|
745 |
+
* Loads the WooCommerce admin settings.
|
746 |
+
*/
|
747 |
Â
public function get_woocommerce_settings_fields() {
|
748 |
Â
if ( ! defined( 'WC_VERSION' ) || ! class_exists( 'WC_Admin_Settings' ) ) {
|
749 |
Â
return false;
|
766 |
Â
$settings_pages = array();
|
767 |
Â
|
768 |
Â
foreach ( \WC_Admin_Settings::get_settings_pages() as $page ) {
|
769 |
+
/**
|
770 |
+
* Get ID / Label of the page, since they're protected, by hacking into
|
771 |
+
* the callback filter for 'woocommerce_settings_tabs_array'.
|
772 |
+
*/
|
773 |
Â
$info = $page->add_settings_page( array() );
|
774 |
Â
$page_id = key( $info );
|
775 |
Â
$page_label = current( $info );
|
781 |
Â
|
782 |
Â
$settings_pages[ $page_id ] = $page_label;
|
783 |
Â
|
784 |
+
// Remove non-fields ( sections, titles and whatever ).
|
785 |
Â
$fields = array();
|
786 |
Â
|
787 |
Â
foreach ( $sections as $section_key => $section_label ) {
|
804 |
Â
}
|
805 |
Â
}
|
806 |
Â
|
807 |
+
// Store fields in the global array to be searched later.
|
808 |
Â
$settings = array_merge( $settings, $fields );
|
809 |
Â
}
|
810 |
Â
|
811 |
+
// Provide additional context for each of the settings pages.
|
812 |
Â
array_walk(
|
813 |
Â
$settings_pages,
|
814 |
Â
function( &$value ) {
|
816 |
Â
}
|
817 |
Â
);
|
818 |
Â
|
819 |
+
// Load Payment Gateway Settings.
|
820 |
Â
$payment_gateway_settings = array();
|
821 |
Â
$payment_gateways = $woocommerce->payment_gateways();
|
822 |
Â
|
835 |
Â
|
836 |
Â
$settings = array_merge( $settings, $payment_gateway_settings );
|
837 |
Â
|
838 |
+
// Load Shipping Method Settings.
|
839 |
Â
$shipping_method_settings = array();
|
840 |
Â
$shipping_methods = $woocommerce->shipping();
|
841 |
Â
|
854 |
Â
|
855 |
Â
$settings = array_merge( $settings, $shipping_method_settings );
|
856 |
Â
|
857 |
+
// Load Email Settings.
|
858 |
Â
$email_settings = array();
|
859 |
Â
$emails = $woocommerce->mailer();
|
860 |
Â
|
873 |
Â
|
874 |
Â
$settings = array_merge( $settings, $email_settings );
|
875 |
Â
|
876 |
+
// Tools page.
|
877 |
Â
$tools_page = array(
|
878 |
Â
'tools' => esc_html__( 'Tools', 'stream' ),
|
879 |
Â
);
|
880 |
Â
|
881 |
Â
$settings_pages = array_merge( $settings_pages, $tools_page );
|
882 |
Â
|
883 |
+
// Cache the results.
|
884 |
Â
$settings_cache = array(
|
885 |
Â
'settings' => $settings,
|
886 |
Â
'settings_pages' => $settings_pages,
|
connectors/class-connector-wordpress-seo.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Connector_WordPress_SEO extends Connector {
|
5 |
Â
|
6 |
Â
/**
|
@@ -104,13 +113,13 @@ class Connector_WordPress_SEO extends Connector {
|
|
104 |
Â
*
|
105 |
Â
* @filter wp_stream_action_links_{connector}
|
106 |
Â
*
|
107 |
-
* @param array $links
|
108 |
-
* @param Record $record
|
109 |
Â
*
|
110 |
Â
* @return array Action links
|
111 |
Â
*/
|
112 |
Â
public function action_links( $links, $record ) {
|
113 |
-
// Options
|
114 |
Â
$option = $record->get_meta( 'option', true );
|
115 |
Â
if ( $option ) {
|
116 |
Â
$key = $record->get_meta( 'option_key', true );
|
@@ -158,12 +167,12 @@ class Connector_WordPress_SEO extends Connector {
|
|
158 |
Â
sprintf( 'delete-post_%d', $post->ID )
|
159 |
Â
);
|
160 |
Â
|
161 |
-
|
162 |
Â
$links[ sprintf( esc_html_x( 'Restore %s', 'Post type singular name', 'stream' ), $post_type_name ) ] = $untrash;
|
163 |
-
|
164 |
Â
$links[ sprintf( esc_html_x( 'Delete %s Permenantly', 'Post type singular name', 'stream' ), $post_type_name ) ] = $delete;
|
165 |
Â
} else {
|
166 |
-
|
167 |
Â
$links[ sprintf( esc_html_x( 'Edit %s', 'Post type singular name', 'stream' ), $post_type_name ) ] = get_edit_post_link( $post->ID );
|
168 |
Â
|
169 |
Â
$view_link = get_permalink( $post->ID );
|
@@ -182,6 +191,9 @@ class Connector_WordPress_SEO extends Connector {
|
|
182 |
Â
return $links;
|
183 |
Â
}
|
184 |
Â
|
Â
|
|
Â
|
|
Â
|
|
185 |
Â
public function register() {
|
186 |
Â
if ( is_network_admin() && ! is_plugin_active_for_network( 'wordpress-seo/wordpress-seo-main.php' ) ) {
|
187 |
Â
return;
|
@@ -189,7 +201,11 @@ class Connector_WordPress_SEO extends Connector {
|
|
189 |
Â
parent::register();
|
190 |
Â
|
191 |
Â
foreach ( \WPSEO_Options::$options as $class ) {
|
192 |
-
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
193 |
Â
$this->option_groups[ $class::get_instance()->group_name ] = array(
|
194 |
Â
'class' => $class,
|
195 |
Â
'name' => $class::get_instance()->option_name,
|
@@ -200,26 +216,39 @@ class Connector_WordPress_SEO extends Connector {
|
|
200 |
Â
add_filter( 'wp_stream_log_data', array( $this, 'log_override' ) );
|
201 |
Â
}
|
202 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
203 |
Â
public function admin_enqueue_scripts( $hook ) {
|
204 |
Â
if ( 0 === strpos( $hook, 'seo_page_' ) ) {
|
205 |
Â
$stream = wp_stream_get_instance();
|
206 |
Â
$src = $stream->locations['url'] . '/ui/js/wpseo-admin.js';
|
207 |
-
wp_enqueue_script(
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
208 |
Â
}
|
209 |
Â
}
|
210 |
Â
|
211 |
Â
/**
|
212 |
Â
* Track importing settings from other plugins
|
Â
|
|
Â
|
|
213 |
Â
*/
|
214 |
Â
public function callback_wpseo_handle_import() {
|
215 |
Â
$imports = array(
|
216 |
-
'importheadspace' => esc_html__( 'HeadSpace2', 'stream' ), // type = checkbox
|
217 |
-
'importaioseo' => esc_html__( 'All-in-One SEO', 'stream' ), // type = checkbox
|
218 |
-
'importaioseoold' => esc_html__( 'OLD All-in-One SEO', 'stream' ), // type = checkbox
|
219 |
-
'importwoo' => esc_html__( 'WooThemes SEO framework', 'stream' ), // type = checkbox
|
220 |
-
'importrobotsmeta' => esc_html__( 'Robots Meta (by Yoast)', 'stream' ), // type = checkbox
|
221 |
-
'importrssfooter' => esc_html__( 'RSS Footer (by Yoast)', 'stream' ), // type = checkbox
|
222 |
-
'importbreadcrumbs' => esc_html__( 'Yoast Breadcrumbs', 'stream' ), // type = checkbox
|
223 |
Â
);
|
224 |
Â
|
225 |
Â
$opts = wp_stream_filter_input( INPUT_POST, 'wpseo' );
|
@@ -228,7 +257,7 @@ class Connector_WordPress_SEO extends Connector {
|
|
228 |
Â
if ( isset( $opts[ $key ] ) ) {
|
229 |
Â
$this->log(
|
230 |
Â
sprintf(
|
231 |
-
|
232 |
Â
__( 'Imported settings from %1$s%2$s', 'stream' ),
|
233 |
Â
$name,
|
234 |
Â
isset( $opts['deleteolddata'] ) ? esc_html__( ', and deleted old data', 'stream' ) : ''
|
@@ -245,13 +274,18 @@ class Connector_WordPress_SEO extends Connector {
|
|
245 |
Â
}
|
246 |
Â
}
|
247 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
248 |
Â
public function callback_wpseo_import() {
|
249 |
Â
$opts = wp_stream_filter_input( INPUT_POST, 'wpseo' );
|
250 |
Â
|
251 |
Â
if ( wp_stream_filter_input( INPUT_POST, 'wpseo_export' ) ) {
|
252 |
Â
$this->log(
|
253 |
Â
sprintf(
|
254 |
-
|
255 |
Â
__( 'Exported settings%s', 'stream' ),
|
256 |
Â
isset( $opts['include_taxonomy_meta'] ) ? esc_html__( ', including taxonomy meta', 'stream' ) : ''
|
257 |
Â
),
|
@@ -262,15 +296,15 @@ class Connector_WordPress_SEO extends Connector {
|
|
262 |
Â
'wpseo_import',
|
263 |
Â
'exported'
|
264 |
Â
);
|
265 |
-
} elseif ( isset( $_FILES['settings_import_file']['name'] ) ) { // phpcs: input var okay
|
266 |
Â
$this->log(
|
267 |
Â
sprintf(
|
268 |
-
|
269 |
Â
__( 'Tried importing settings from "%s"', 'stream' ),
|
270 |
-
sanitize_text_field( wp_unslash( $_FILES['settings_import_file']['name'] ) ) // phpcs: input var okay
|
271 |
Â
),
|
272 |
Â
array(
|
273 |
-
'file' => sanitize_text_field( wp_unslash( $_FILES['settings_import_file']['name'] ) ), // phpcs: input var okay
|
274 |
Â
),
|
275 |
Â
null,
|
276 |
Â
'wpseo_import',
|
@@ -279,6 +313,11 @@ class Connector_WordPress_SEO extends Connector {
|
|
279 |
Â
}
|
280 |
Â
}
|
281 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
282 |
Â
public function callback_seo_page_wpseo_files() {
|
283 |
Â
if ( wp_stream_filter_input( INPUT_POST, 'create_robots' ) ) {
|
284 |
Â
$message = esc_html__( 'Tried creating robots.txt file', 'stream' );
|
@@ -299,19 +338,58 @@ class Connector_WordPress_SEO extends Connector {
|
|
299 |
Â
}
|
300 |
Â
}
|
301 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
302 |
Â
public function callback_added_post_meta( $meta_id, $object_id, $meta_key, $meta_value ) {
|
303 |
Â
unset( $meta_id );
|
304 |
Â
$this->meta( $object_id, $meta_key, $meta_value );
|
305 |
Â
}
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
306 |
Â
public function callback_updated_post_meta( $meta_id, $object_id, $meta_key, $meta_value ) {
|
307 |
Â
unset( $meta_id );
|
308 |
Â
$this->meta( $object_id, $meta_key, $meta_value );
|
309 |
Â
}
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
310 |
Â
public function callback_deleted_post_meta( $meta_id, $object_id, $meta_key, $meta_value ) {
|
311 |
Â
unset( $meta_id );
|
312 |
Â
$this->meta( $object_id, $meta_key, $meta_value );
|
313 |
Â
}
|
314 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
315 |
Â
private function meta( $object_id, $meta_key, $meta_value ) {
|
316 |
Â
$prefix = \WPSEO_Meta::$meta_prefix;
|
317 |
Â
|
@@ -339,7 +417,7 @@ class Connector_WordPress_SEO extends Connector {
|
|
339 |
Â
|
340 |
Â
$this->log(
|
341 |
Â
sprintf(
|
342 |
-
|
343 |
Â
__( 'Updated "%1$s" of "%2$s" %3$s', 'stream' ),
|
344 |
Â
$field['title'],
|
345 |
Â
$post->post_title,
|
@@ -359,7 +437,7 @@ class Connector_WordPress_SEO extends Connector {
|
|
359 |
Â
/**
|
360 |
Â
* Override connector log for our own Settings / Actions
|
361 |
Â
*
|
362 |
-
* @param array $data
|
363 |
Â
*
|
364 |
Â
* @return array|bool
|
365 |
Â
*/
|
@@ -384,7 +462,7 @@ class Connector_WordPress_SEO extends Connector {
|
|
384 |
Â
|
385 |
Â
$label = $this->settings_labels( $data['args']['option_key'] );
|
386 |
Â
if ( ! $label ) {
|
387 |
-
|
388 |
Â
$data['message'] = esc_html__( '%s settings updated', 'stream' );
|
389 |
Â
$label = $labels[ $page ];
|
390 |
Â
}
|
@@ -398,114 +476,121 @@ class Connector_WordPress_SEO extends Connector {
|
|
398 |
Â
return $data;
|
399 |
Â
}
|
400 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
401 |
Â
private function settings_labels( $option ) {
|
402 |
Â
$labels = array(
|
403 |
-
// wp-content/plugins/wordpress-seo/admin/pages/dashboard.php
|
404 |
-
'yoast_tracking' => esc_html_x( "Allow tracking of this WordPress install's anonymous data.", 'wordpress-seo', 'stream' ), // type = checkbox
|
405 |
-
'disableadvanced_meta' => esc_html_x( 'Disable the Advanced part of the WordPress SEO meta box', 'wordpress-seo', 'stream' ), // type = checkbox
|
406 |
-
'alexaverify' => esc_html_x( 'Alexa Verification ID', 'wordpress-seo', 'stream' ), // type = textinput
|
407 |
-
'msverify' => esc_html_x( 'Bing Webmaster Tools', 'wordpress-seo', 'stream' ), // type = textinput
|
408 |
-
'googleverify' => esc_html_x( 'Google Webmaster Tools', 'wordpress-seo', 'stream' ), // type = textinput
|
409 |
-
'pinterestverify' => esc_html_x( 'Pinterest', 'wordpress-seo', 'stream' ), // type = textinput
|
410 |
-
'yandexverify' => esc_html_x( 'Yandex Webmaster Tools', 'wordpress-seo', 'stream' ), // type = textinput
|
411 |
-
|
412 |
-
// wp-content/plugins/wordpress-seo/admin/pages/advanced.php
|
413 |
-
'breadcrumbs-enable' => esc_html_x( 'Enable Breadcrumbs', 'wordpress-seo', 'stream' ), // type = checkbox
|
414 |
-
'breadcrumbs-sep' => esc_html_x( 'Separator between breadcrumbs', 'wordpress-seo', 'stream' ), // type = textinput
|
415 |
-
'breadcrumbs-home' => esc_html_x( 'Anchor text for the Homepage', 'wordpress-seo', 'stream' ), // type = textinput
|
416 |
-
'breadcrumbs-prefix' => esc_html_x( 'Prefix for the breadcrumb path', 'wordpress-seo', 'stream' ), // type = textinput
|
417 |
-
'breadcrumbs-archiveprefix' => esc_html_x( 'Prefix for Archive breadcrumbs', 'wordpress-seo', 'stream' ), // type = textinput
|
418 |
-
'breadcrumbs-searchprefix' => esc_html_x( 'Prefix for Search Page breadcrumbs', 'wordpress-seo', 'stream' ), // type = textinput
|
419 |
-
'breadcrumbs-404crumb' => esc_html_x( 'Breadcrumb for 404 Page', 'wordpress-seo', 'stream' ), // type = textinput
|
420 |
-
'breadcrumbs-blog-remove' => esc_html_x( 'Remove Blog page from Breadcrumbs', 'wordpress-seo', 'stream' ), // type = checkbox
|
421 |
-
'breadcrumbs-boldlast' => esc_html_x( 'Bold the last page in the breadcrumb', 'wordpress-seo', 'stream' ), // type = checkbox
|
422 |
-
'post_types-post-maintax' => esc_html_x( 'Taxonomy to show in breadcrumbs for post types', 'wordpress-seo', 'stream' ), // type = select
|
423 |
-
|
424 |
-
// wp-content/plugins/wordpress-seo/admin/pages/metas.php
|
425 |
-
'forcerewritetitle' => esc_html_x( 'Force rewrite titles', 'wordpress-seo', 'stream' ), // type = checkbox
|
426 |
-
'noindex-subpages-wpseo' => esc_html_x( 'Noindex subpages of archives', 'wordpress-seo', 'stream' ), // type = checkbox
|
427 |
-
'usemetakeywords' => _x( 'Use <code>meta</code> keywords tag?', 'wordpress-seo', 'stream' ), // type = checkbox
|
428 |
-
'noodp' => _x( 'Add <code>noodp</code> meta robots tag sitewide', 'wordpress-seo', 'stream' ), // type = checkbox
|
429 |
-
'noydir' => _x( 'Add <code>noydir</code> meta robots tag sitewide', 'wordpress-seo', 'stream' ), // type = checkbox
|
430 |
-
'hide-rsdlink' => esc_html_x( 'Hide RSD Links', 'wordpress-seo', 'stream' ), // type = checkbox
|
431 |
-
'hide-wlwmanifest' => esc_html_x( 'Hide WLW Manifest Links', 'wordpress-seo', 'stream' ), // type = checkbox
|
432 |
-
'hide-shortlink' => esc_html_x( 'Hide Shortlink for posts', 'wordpress-seo', 'stream' ), // type = checkbox
|
433 |
-
'hide-feedlinks' => esc_html_x( 'Hide RSS Links', 'wordpress-seo', 'stream' ), // type = checkbox
|
434 |
-
'disable-author' => esc_html_x( 'Disable the author archives', 'wordpress-seo', 'stream' ), // type = checkbox
|
435 |
-
'disable-date' => esc_html_x( 'Disable the date-based archives', 'wordpress-seo', 'stream' ), // type = checkbox
|
436 |
-
|
437 |
-
// wp-content/plugins/wordpress-seo/admin/pages/network.php
|
438 |
-
'access' => esc_html_x( 'Who should have access to the WordPress SEO settings', 'wordpress-seo', 'stream' ), // type = select
|
439 |
-
'defaultblog' => esc_html_x( 'New blogs get the SEO settings from this blog', 'wordpress-seo', 'stream' ), // type = textinput
|
440 |
-
'restoreblog' => esc_html_x( 'Blog ID', 'wordpress-seo', 'stream' ), // type = textinput
|
441 |
-
|
442 |
-
// wp-content/plugins/wordpress-seo/admin/pages/permalinks.php
|
443 |
-
'stripcategorybase' => _x( 'Strip the category base (usually <code>/category/</code>) from the category URL.', 'wordpress-seo', 'stream' ), // type = checkbox
|
444 |
-
'trailingslash' => esc_html_x( "Enforce a trailing slash on all category and tag URL's", 'wordpress-seo', 'stream' ), // type = checkbox
|
445 |
-
'cleanslugs' => esc_html_x( 'Remove stop words from slugs.', 'wordpress-seo', 'stream' ), // type = checkbox
|
446 |
-
'redirectattachment' => esc_html_x( "Redirect attachment URL's to parent post URL.", 'wordpress-seo', 'stream' ), // type = checkbox
|
447 |
-
'cleanreplytocom' => _x( 'Remove the <code>?replytocom</code> variables.', 'wordpress-seo', 'stream' ), // type = checkbox
|
448 |
-
'cleanpermalinks' => esc_html_x( "Redirect ugly URL's to clean permalinks. (Not recommended in many cases!)", 'wordpress-seo', 'stream' ), // type = checkbox
|
449 |
-
'force_transport' => esc_html_x( 'Force Transport', 'wordpress-seo', 'stream' ), // type = select
|
450 |
-
'cleanpermalink-googlesitesearch' => esc_html_x( "Prevent cleaning out Google Site Search URL's.", 'wordpress-seo', 'stream' ), // type = checkbox
|
451 |
-
'cleanpermalink-googlecampaign' => esc_html_x( 'Prevent cleaning out Google Analytics Campaign & Google AdWords Parameters.', 'wordpress-seo', 'stream' ), // type = checkbox
|
452 |
-
'cleanpermalink-extravars' => esc_html_x( 'Other variables not to clean', 'wordpress-seo', 'stream' ), // type = textinput
|
453 |
-
|
454 |
-
// wp-content/plugins/wordpress-seo/admin/pages/social.php
|
455 |
-
'opengraph' => esc_html_x( 'Add Open Graph meta data', 'wordpress-seo', 'stream' ), // type = checkbox
|
456 |
-
'facebook_site' => esc_html_x( 'Facebook Page URL', 'wordpress-seo', 'stream' ), // type = textinput
|
457 |
-
'instagram_url' => esc_html_x( 'Instagram URL', 'wordpress-seo', 'stream' ), // type = textinput
|
458 |
-
'linkedin_url' => esc_html_x( 'LinkedIn URL', 'wordpress-seo', 'stream' ), // type = textinput
|
459 |
-
'myspace_url' => esc_html_x( 'MySpace URL', 'wordpress-seo', 'stream' ), // type = textinput
|
460 |
-
'pinterest_url' => esc_html_x( 'Pinterest URL', 'wordpress-seo', 'stream' ), // type = textinput
|
461 |
-
'youtube_url' => esc_html_x( 'YouTube URL', 'wordpress-seo', 'stream' ), // type = textinput
|
462 |
-
'google_plus_url' => esc_html_x( 'Google+ URL', 'wordpress-seo', 'stream' ), // type = textinput
|
463 |
-
'og_frontpage_image' => esc_html_x( 'Image URL', 'wordpress-seo', 'stream' ), // type = textinput
|
464 |
-
'og_frontpage_desc' => esc_html_x( 'Description', 'wordpress-seo', 'stream' ), // type = textinput
|
465 |
-
'og_frontpage_title' => esc_html_x( 'Title', 'wordpress-seo', 'stream' ), // type = textinput
|
466 |
-
'og_default_image' => esc_html_x( 'Image URL', 'wordpress-seo', 'stream' ), // type = textinput
|
467 |
-
'twitter' => esc_html_x( 'Add Twitter card meta data', 'wordpress-seo', 'stream' ), // type = checkbox
|
468 |
-
'twitter_site' => esc_html_x( 'Site Twitter Username', 'wordpress-seo', 'stream' ), // type = textinput
|
469 |
-
'twitter_card_type' => esc_html_x( 'The default card type to use', 'wordpress-seo', 'stream' ), // type = select
|
470 |
-
'googleplus' => esc_html_x( 'Add Google+ specific post meta data (excluding author metadata)', 'wordpress-seo', 'stream' ), // type = checkbox
|
471 |
-
'plus-publisher' => esc_html_x( 'Google Publisher Page', 'wordpress-seo', 'stream' ), // type = textinput
|
472 |
-
'fbadminapp' => esc_html_x( 'Facebook App ID', 'wordpress-seo', 'stream' ), // type = textinput
|
473 |
-
|
474 |
-
// wp-content/plugins/wordpress-seo/admin/pages/xml-sitemaps.php
|
475 |
-
'enablexmlsitemap' => esc_html_x( 'Check this box to enable XML sitemap functionality.', 'wordpress-seo', 'stream' ), // type = checkbox
|
476 |
-
'disable_author_sitemap' => esc_html_x( 'Disable author/user sitemap', 'wordpress-seo', 'stream' ), // type = checkbox
|
477 |
-
'disable_author_noposts' => esc_html_x( 'Users with zero posts', 'wordpress-seo', 'stream' ), // type = checkbox
|
478 |
-
'user_role-administrator-not_in_sitemap' => esc_html_x( 'Filter specific user roles - Administrator', 'wordpress-seo', 'stream' ), // type = checkbox
|
479 |
-
'user_role-editor-not_in_sitemap' => esc_html_x( 'Filter specific user roles - Editor', 'wordpress-seo', 'stream' ), // type = checkbox
|
480 |
-
'user_role-author-not_in_sitemap' => esc_html_x( 'Filter specific user roles - Author', 'wordpress-seo', 'stream' ), // type = checkbox
|
481 |
-
'user_role-contributor-not_in_sitemap' => esc_html_x( 'Filter specific user roles - Contributor', 'wordpress-seo', 'stream' ), // type = checkbox
|
482 |
-
'user_role-subscriber-not_in_sitemap' => esc_html_x( 'Filter specific user roles - Subscriber', 'wordpress-seo', 'stream' ), // type = checkbox
|
483 |
-
'xml_ping_yahoo' => esc_html_x( 'Ping Yahoo!', 'wordpress-seo', 'stream' ), // type = checkbox
|
484 |
-
'xml_ping_ask' => esc_html_x( 'Ping Ask.com', 'wordpress-seo', 'stream' ), // type = checkbox
|
485 |
-
'entries-per-page' => esc_html_x( 'Max entries per sitemap page', 'wordpress-seo', 'stream' ), // type = textinput
|
486 |
-
'excluded-posts' => esc_html_x( 'Posts to exclude', 'wordpress-seo', 'stream' ), // type = textinput
|
487 |
-
'post_types-post-not_in_sitemap' => _x( 'Post Types Posts (<code>post</code>)', 'wordpress-seo', 'stream' ), // type = checkbox
|
488 |
-
'post_types-page-not_in_sitemap' => _x( 'Post Types Pages (<code>page</code>)', 'wordpress-seo', 'stream' ), // type = checkbox
|
489 |
-
'post_types-attachment-not_in_sitemap' => _x( 'Post Types Media (<code>attachment</code>)', 'wordpress-seo', 'stream' ), // type = checkbox
|
490 |
-
'taxonomies-category-not_in_sitemap' => _x( 'Taxonomies Categories (<code>category</code>)', 'wordpress-seo', 'stream' ), // type = checkbox
|
491 |
-
'taxonomies-post_tag-not_in_sitemap' => _x( 'Taxonomies Tags (<code>post_tag</code>)', 'wordpress-seo', 'stream' ), // type = checkbox
|
492 |
-
|
493 |
-
// Added manually
|
494 |
Â
'rssbefore' => esc_html_x( 'Content to put before each post in the feed', 'wordpress-seo', 'stream' ),
|
495 |
Â
'rssafter' => esc_html_x( 'Content to put after each post', 'wordpress-seo', 'stream' ),
|
496 |
Â
);
|
497 |
Â
|
498 |
Â
$ast_labels = array(
|
499 |
-
'title-' => esc_html_x( 'Title template', 'wordpress-seo', 'stream' ), // type = textinput
|
500 |
-
'metadesc-' => esc_html_x( 'Meta description template', 'wordpress-seo', 'stream' ), // type = textarea
|
501 |
-
'metakey-' => esc_html_x( 'Meta keywords template', 'wordpress-seo', 'stream' ), // type = textinput
|
502 |
-
'noindex-' => esc_html_x( 'Meta Robots', 'wordpress-seo', 'stream' ), // type = checkbox
|
503 |
-
'noauthorship-' => esc_html_x( 'Authorship', 'wordpress-seo', 'stream' ), // type = checkbox
|
504 |
-
'showdate-' => esc_html_x( 'Show date in snippet preview?', 'wordpress-seo', 'stream' ), // type = checkbox
|
505 |
-
'hideeditbox-' => esc_html_x( 'WordPress SEO Meta Box', 'wordpress-seo', 'stream' ), // type = checkbox
|
506 |
-
'bctitle-' => esc_html_x( 'Breadcrumbs Title', 'wordpress-seo', 'stream' ), // type = textinput
|
507 |
-
'post_types-' => esc_html_x( 'Post types', 'wordpress-seo', 'stream' ), // type = checkbox
|
508 |
-
'taxonomies-' => esc_html_x( 'Taxonomies', 'wordpress-seo', 'stream' ), // type = checkbox
|
509 |
Â
);
|
510 |
Â
|
511 |
Â
if ( $option ) {
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Connector for WordPress SEO
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Connector_WordPress_SEO
|
12 |
+
*/
|
13 |
Â
class Connector_WordPress_SEO extends Connector {
|
14 |
Â
|
15 |
Â
/**
|
113 |
Â
*
|
114 |
Â
* @filter wp_stream_action_links_{connector}
|
115 |
Â
*
|
116 |
+
* @param array $links Previous links registered.
|
117 |
+
* @param Record $record Stream record.
|
118 |
Â
*
|
119 |
Â
* @return array Action links
|
120 |
Â
*/
|
121 |
Â
public function action_links( $links, $record ) {
|
122 |
+
// Options.
|
123 |
Â
$option = $record->get_meta( 'option', true );
|
124 |
Â
if ( $option ) {
|
125 |
Â
$key = $record->get_meta( 'option_key', true );
|
167 |
Â
sprintf( 'delete-post_%d', $post->ID )
|
168 |
Â
);
|
169 |
Â
|
170 |
+
/* translators: %s: a post type singular name (e.g. "Post") */
|
171 |
Â
$links[ sprintf( esc_html_x( 'Restore %s', 'Post type singular name', 'stream' ), $post_type_name ) ] = $untrash;
|
172 |
+
/* translators: %s: a post type singular name (e.g. "Post") */
|
173 |
Â
$links[ sprintf( esc_html_x( 'Delete %s Permenantly', 'Post type singular name', 'stream' ), $post_type_name ) ] = $delete;
|
174 |
Â
} else {
|
175 |
+
/* translators: %s: a post type singular name (e.g. "Post") */
|
176 |
Â
$links[ sprintf( esc_html_x( 'Edit %s', 'Post type singular name', 'stream' ), $post_type_name ) ] = get_edit_post_link( $post->ID );
|
177 |
Â
|
178 |
Â
$view_link = get_permalink( $post->ID );
|
191 |
Â
return $links;
|
192 |
Â
}
|
193 |
Â
|
194 |
+
/**
|
195 |
+
* Register connection
|
196 |
+
*/
|
197 |
Â
public function register() {
|
198 |
Â
if ( is_network_admin() && ! is_plugin_active_for_network( 'wordpress-seo/wordpress-seo-main.php' ) ) {
|
199 |
Â
return;
|
201 |
Â
parent::register();
|
202 |
Â
|
203 |
Â
foreach ( \WPSEO_Options::$options as $class ) {
|
204 |
+
/**
|
205 |
+
* WPSEO Options object.
|
206 |
+
*
|
207 |
+
* @var WPSEO_Options $class
|
208 |
+
*/
|
209 |
Â
$this->option_groups[ $class::get_instance()->group_name ] = array(
|
210 |
Â
'class' => $class,
|
211 |
Â
'name' => $class::get_instance()->option_name,
|
216 |
Â
add_filter( 'wp_stream_log_data', array( $this, 'log_override' ) );
|
217 |
Â
}
|
218 |
Â
|
219 |
+
/**
|
220 |
+
* Register admin scripts.
|
221 |
+
*
|
222 |
+
* @param string $hook Current hook.
|
223 |
+
*/
|
224 |
Â
public function admin_enqueue_scripts( $hook ) {
|
225 |
Â
if ( 0 === strpos( $hook, 'seo_page_' ) ) {
|
226 |
Â
$stream = wp_stream_get_instance();
|
227 |
Â
$src = $stream->locations['url'] . '/ui/js/wpseo-admin.js';
|
228 |
+
wp_enqueue_script(
|
229 |
+
'stream-connector-wpseo',
|
230 |
+
$src,
|
231 |
+
array( 'jquery' ),
|
232 |
+
$stream->get_version(),
|
233 |
+
false
|
234 |
+
);
|
235 |
Â
}
|
236 |
Â
}
|
237 |
Â
|
238 |
Â
/**
|
239 |
Â
* Track importing settings from other plugins
|
240 |
+
*
|
241 |
+
* @action wpseo_handle_import
|
242 |
Â
*/
|
243 |
Â
public function callback_wpseo_handle_import() {
|
244 |
Â
$imports = array(
|
245 |
+
'importheadspace' => esc_html__( 'HeadSpace2', 'stream' ), // type = checkbox.
|
246 |
+
'importaioseo' => esc_html__( 'All-in-One SEO', 'stream' ), // type = checkbox.
|
247 |
+
'importaioseoold' => esc_html__( 'OLD All-in-One SEO', 'stream' ), // type = checkbox.
|
248 |
+
'importwoo' => esc_html__( 'WooThemes SEO framework', 'stream' ), // type = checkbox.
|
249 |
+
'importrobotsmeta' => esc_html__( 'Robots Meta (by Yoast)', 'stream' ), // type = checkbox.
|
250 |
+
'importrssfooter' => esc_html__( 'RSS Footer (by Yoast)', 'stream' ), // type = checkbox.
|
251 |
+
'importbreadcrumbs' => esc_html__( 'Yoast Breadcrumbs', 'stream' ), // type = checkbox.
|
252 |
Â
);
|
253 |
Â
|
254 |
Â
$opts = wp_stream_filter_input( INPUT_POST, 'wpseo' );
|
257 |
Â
if ( isset( $opts[ $key ] ) ) {
|
258 |
Â
$this->log(
|
259 |
Â
sprintf(
|
260 |
+
/* translators: %1$s: an import method, %2$s: an extra string (sometimes blank) (e.g. "HeadSpace2", ", and deleted old data") */
|
261 |
Â
__( 'Imported settings from %1$s%2$s', 'stream' ),
|
262 |
Â
$name,
|
263 |
Â
isset( $opts['deleteolddata'] ) ? esc_html__( ', and deleted old data', 'stream' ) : ''
|
274 |
Â
}
|
275 |
Â
}
|
276 |
Â
|
277 |
+
/**
|
278 |
+
* Track importing settings
|
279 |
+
*
|
280 |
+
* @callback wpseo_import
|
281 |
+
*/
|
282 |
Â
public function callback_wpseo_import() {
|
283 |
Â
$opts = wp_stream_filter_input( INPUT_POST, 'wpseo' );
|
284 |
Â
|
285 |
Â
if ( wp_stream_filter_input( INPUT_POST, 'wpseo_export' ) ) {
|
286 |
Â
$this->log(
|
287 |
Â
sprintf(
|
288 |
+
/* translators: %s: an extra string (sometimes blank) (e.g. ", including taxonomy meta") */
|
289 |
Â
__( 'Exported settings%s', 'stream' ),
|
290 |
Â
isset( $opts['include_taxonomy_meta'] ) ? esc_html__( ', including taxonomy meta', 'stream' ) : ''
|
291 |
Â
),
|
296 |
Â
'wpseo_import',
|
297 |
Â
'exported'
|
298 |
Â
);
|
299 |
+
} elseif ( isset( $_FILES['settings_import_file']['name'] ) ) { // phpcs: input var okay.
|
300 |
Â
$this->log(
|
301 |
Â
sprintf(
|
302 |
+
/* translators: %s: a filename (e.g. "test.xml") */
|
303 |
Â
__( 'Tried importing settings from "%s"', 'stream' ),
|
304 |
+
sanitize_text_field( wp_unslash( $_FILES['settings_import_file']['name'] ) ) // phpcs: input var okay.
|
305 |
Â
),
|
306 |
Â
array(
|
307 |
+
'file' => sanitize_text_field( wp_unslash( $_FILES['settings_import_file']['name'] ) ), // phpcs: input var okay.
|
308 |
Â
),
|
309 |
Â
null,
|
310 |
Â
'wpseo_import',
|
313 |
Â
}
|
314 |
Â
}
|
315 |
Â
|
316 |
+
/**
|
317 |
+
* Tracks creation of SEO-related files.
|
318 |
+
*
|
319 |
+
* @action seo_page_wpseo_files
|
320 |
+
*/
|
321 |
Â
public function callback_seo_page_wpseo_files() {
|
322 |
Â
if ( wp_stream_filter_input( INPUT_POST, 'create_robots' ) ) {
|
323 |
Â
$message = esc_html__( 'Tried creating robots.txt file', 'stream' );
|
338 |
Â
}
|
339 |
Â
}
|
340 |
Â
|
341 |
+
/**
|
342 |
+
* Tracks the creation of WordPress SEO post meta
|
343 |
+
*
|
344 |
+
* @action added_post_meta
|
345 |
+
*
|
346 |
+
* @param int $meta_id Meta ID.
|
347 |
+
* @param int $object_id Object ID.
|
348 |
+
* @param string $meta_key Meta key.
|
349 |
+
* @param string $meta_value Meta value.
|
350 |
+
*/
|
351 |
Â
public function callback_added_post_meta( $meta_id, $object_id, $meta_key, $meta_value ) {
|
352 |
Â
unset( $meta_id );
|
353 |
Â
$this->meta( $object_id, $meta_key, $meta_value );
|
354 |
Â
}
|
355 |
+
|
356 |
+
/**
|
357 |
+
* Tracks the updates to WordPress SEO post meta
|
358 |
+
*
|
359 |
+
* @action updated_post_meta
|
360 |
+
*
|
361 |
+
* @param int $meta_id Meta ID.
|
362 |
+
* @param int $object_id Object ID.
|
363 |
+
* @param string $meta_key Meta key.
|
364 |
+
* @param string $meta_value Meta value.
|
365 |
+
*/
|
366 |
Â
public function callback_updated_post_meta( $meta_id, $object_id, $meta_key, $meta_value ) {
|
367 |
Â
unset( $meta_id );
|
368 |
Â
$this->meta( $object_id, $meta_key, $meta_value );
|
369 |
Â
}
|
370 |
+
|
371 |
+
/**
|
372 |
+
* Tracks the deletions of WordPress SEO post meta
|
373 |
+
*
|
374 |
+
* @action deleted_post_meta
|
375 |
+
*
|
376 |
+
* @param int $meta_id Meta ID.
|
377 |
+
* @param int $object_id Object ID.
|
378 |
+
* @param string $meta_key Meta key.
|
379 |
+
* @param string $meta_value Meta value.
|
380 |
+
*/
|
381 |
Â
public function callback_deleted_post_meta( $meta_id, $object_id, $meta_key, $meta_value ) {
|
382 |
Â
unset( $meta_id );
|
383 |
Â
$this->meta( $object_id, $meta_key, $meta_value );
|
384 |
Â
}
|
385 |
Â
|
386 |
+
/**
|
387 |
+
* Logs WordPress SEO meta activity
|
388 |
+
*
|
389 |
+
* @param int $object_id Object ID.
|
390 |
+
* @param int $meta_key Meta key.
|
391 |
+
* @param string $meta_value Meta value.
|
392 |
+
*/
|
393 |
Â
private function meta( $object_id, $meta_key, $meta_value ) {
|
394 |
Â
$prefix = \WPSEO_Meta::$meta_prefix;
|
395 |
Â
|
417 |
Â
|
418 |
Â
$this->log(
|
419 |
Â
sprintf(
|
420 |
+
/* translators: %1$s: a meta field title, %2$s: a post title, %3$s: a post type (e.g. "Description", "Hello World", "Post") */
|
421 |
Â
__( 'Updated "%1$s" of "%2$s" %3$s', 'stream' ),
|
422 |
Â
$field['title'],
|
423 |
Â
$post->post_title,
|
437 |
Â
/**
|
438 |
Â
* Override connector log for our own Settings / Actions
|
439 |
Â
*
|
440 |
+
* @param array $data Record data.
|
441 |
Â
*
|
442 |
Â
* @return array|bool
|
443 |
Â
*/
|
462 |
Â
|
463 |
Â
$label = $this->settings_labels( $data['args']['option_key'] );
|
464 |
Â
if ( ! $label ) {
|
465 |
+
/* translators: %s: a context (e.g. "Dashboard") */
|
466 |
Â
$data['message'] = esc_html__( '%s settings updated', 'stream' );
|
467 |
Â
$label = $labels[ $page ];
|
468 |
Â
}
|
476 |
Â
return $data;
|
477 |
Â
}
|
478 |
Â
|
479 |
+
/**
|
480 |
+
* Return the labels
|
481 |
+
*
|
482 |
+
* @param string $option Name of option to be retrieved.
|
483 |
+
*
|
484 |
+
* @return array|bool.
|
485 |
+
*/
|
486 |
Â
private function settings_labels( $option ) {
|
487 |
Â
$labels = array(
|
488 |
+
// wp-content/plugins/wordpress-seo/admin/pages/dashboard.php:.
|
489 |
+
'yoast_tracking' => esc_html_x( "Allow tracking of this WordPress install's anonymous data.", 'wordpress-seo', 'stream' ), // type = checkbox.
|
490 |
+
'disableadvanced_meta' => esc_html_x( 'Disable the Advanced part of the WordPress SEO meta box', 'wordpress-seo', 'stream' ), // type = checkbox.
|
491 |
+
'alexaverify' => esc_html_x( 'Alexa Verification ID', 'wordpress-seo', 'stream' ), // type = textinput.
|
492 |
+
'msverify' => esc_html_x( 'Bing Webmaster Tools', 'wordpress-seo', 'stream' ), // type = textinput.
|
493 |
+
'googleverify' => esc_html_x( 'Google Webmaster Tools', 'wordpress-seo', 'stream' ), // type = textinput.
|
494 |
+
'pinterestverify' => esc_html_x( 'Pinterest', 'wordpress-seo', 'stream' ), // type = textinput.
|
495 |
+
'yandexverify' => esc_html_x( 'Yandex Webmaster Tools', 'wordpress-seo', 'stream' ), // type = textinput.
|
496 |
+
|
497 |
+
// wp-content/plugins/wordpress-seo/admin/pages/advanced.php:.
|
498 |
+
'breadcrumbs-enable' => esc_html_x( 'Enable Breadcrumbs', 'wordpress-seo', 'stream' ), // type = checkbox.
|
499 |
+
'breadcrumbs-sep' => esc_html_x( 'Separator between breadcrumbs', 'wordpress-seo', 'stream' ), // type = textinput.
|
500 |
+
'breadcrumbs-home' => esc_html_x( 'Anchor text for the Homepage', 'wordpress-seo', 'stream' ), // type = textinput.
|
501 |
+
'breadcrumbs-prefix' => esc_html_x( 'Prefix for the breadcrumb path', 'wordpress-seo', 'stream' ), // type = textinput.
|
502 |
+
'breadcrumbs-archiveprefix' => esc_html_x( 'Prefix for Archive breadcrumbs', 'wordpress-seo', 'stream' ), // type = textinput.
|
503 |
+
'breadcrumbs-searchprefix' => esc_html_x( 'Prefix for Search Page breadcrumbs', 'wordpress-seo', 'stream' ), // type = textinput.
|
504 |
+
'breadcrumbs-404crumb' => esc_html_x( 'Breadcrumb for 404 Page', 'wordpress-seo', 'stream' ), // type = textinput.
|
505 |
+
'breadcrumbs-blog-remove' => esc_html_x( 'Remove Blog page from Breadcrumbs', 'wordpress-seo', 'stream' ), // type = checkbox.
|
506 |
+
'breadcrumbs-boldlast' => esc_html_x( 'Bold the last page in the breadcrumb', 'wordpress-seo', 'stream' ), // type = checkbox.
|
507 |
+
'post_types-post-maintax' => esc_html_x( 'Taxonomy to show in breadcrumbs for post types', 'wordpress-seo', 'stream' ), // type = select.
|
508 |
+
|
509 |
+
// wp-content/plugins/wordpress-seo/admin/pages/metas.php:.
|
510 |
+
'forcerewritetitle' => esc_html_x( 'Force rewrite titles', 'wordpress-seo', 'stream' ), // type = checkbox.
|
511 |
+
'noindex-subpages-wpseo' => esc_html_x( 'Noindex subpages of archives', 'wordpress-seo', 'stream' ), // type = checkbox.
|
512 |
+
'usemetakeywords' => _x( 'Use <code>meta</code> keywords tag?', 'wordpress-seo', 'stream' ), // type = checkbox.
|
513 |
+
'noodp' => _x( 'Add <code>noodp</code> meta robots tag sitewide', 'wordpress-seo', 'stream' ), // type = checkbox.
|
514 |
+
'noydir' => _x( 'Add <code>noydir</code> meta robots tag sitewide', 'wordpress-seo', 'stream' ), // type = checkbox.
|
515 |
+
'hide-rsdlink' => esc_html_x( 'Hide RSD Links', 'wordpress-seo', 'stream' ), // type = checkbox.
|
516 |
+
'hide-wlwmanifest' => esc_html_x( 'Hide WLW Manifest Links', 'wordpress-seo', 'stream' ), // type = checkbox.
|
517 |
+
'hide-shortlink' => esc_html_x( 'Hide Shortlink for posts', 'wordpress-seo', 'stream' ), // type = checkbox.
|
518 |
+
'hide-feedlinks' => esc_html_x( 'Hide RSS Links', 'wordpress-seo', 'stream' ), // type = checkbox.
|
519 |
+
'disable-author' => esc_html_x( 'Disable the author archives', 'wordpress-seo', 'stream' ), // type = checkbox.
|
520 |
+
'disable-date' => esc_html_x( 'Disable the date-based archives', 'wordpress-seo', 'stream' ), // type = checkbox.
|
521 |
+
|
522 |
+
// wp-content/plugins/wordpress-seo/admin/pages/network.php:.
|
523 |
+
'access' => esc_html_x( 'Who should have access to the WordPress SEO settings', 'wordpress-seo', 'stream' ), // type = select.
|
524 |
+
'defaultblog' => esc_html_x( 'New blogs get the SEO settings from this blog', 'wordpress-seo', 'stream' ), // type = textinput.
|
525 |
+
'restoreblog' => esc_html_x( 'Blog ID', 'wordpress-seo', 'stream' ), // type = textinput.
|
526 |
+
|
527 |
+
// wp-content/plugins/wordpress-seo/admin/pages/permalinks.php:.
|
528 |
+
'stripcategorybase' => _x( 'Strip the category base (usually <code>/category/</code>) from the category URL.', 'wordpress-seo', 'stream' ), // type = checkbox.
|
529 |
+
'trailingslash' => esc_html_x( "Enforce a trailing slash on all category and tag URL's", 'wordpress-seo', 'stream' ), // type = checkbox.
|
530 |
+
'cleanslugs' => esc_html_x( 'Remove stop words from slugs.', 'wordpress-seo', 'stream' ), // type = checkbox.
|
531 |
+
'redirectattachment' => esc_html_x( "Redirect attachment URL's to parent post URL.", 'wordpress-seo', 'stream' ), // type = checkbox.
|
532 |
+
'cleanreplytocom' => _x( 'Remove the <code>?replytocom</code> variables.', 'wordpress-seo', 'stream' ), // type = checkbox.
|
533 |
+
'cleanpermalinks' => esc_html_x( "Redirect ugly URL's to clean permalinks. (Not recommended in many cases!)", 'wordpress-seo', 'stream' ), // type = checkbox.
|
534 |
+
'force_transport' => esc_html_x( 'Force Transport', 'wordpress-seo', 'stream' ), // type = select.
|
535 |
+
'cleanpermalink-googlesitesearch' => esc_html_x( "Prevent cleaning out Google Site Search URL's.", 'wordpress-seo', 'stream' ), // type = checkbox.
|
536 |
+
'cleanpermalink-googlecampaign' => esc_html_x( 'Prevent cleaning out Google Analytics Campaign & Google AdWords Parameters.', 'wordpress-seo', 'stream' ), // type = checkbox.
|
537 |
+
'cleanpermalink-extravars' => esc_html_x( 'Other variables not to clean', 'wordpress-seo', 'stream' ), // type = textinput.
|
538 |
+
|
539 |
+
// wp-content/plugins/wordpress-seo/admin/pages/social.php:.
|
540 |
+
'opengraph' => esc_html_x( 'Add Open Graph meta data', 'wordpress-seo', 'stream' ), // type = checkbox.
|
541 |
+
'facebook_site' => esc_html_x( 'Facebook Page URL', 'wordpress-seo', 'stream' ), // type = textinput.
|
542 |
+
'instagram_url' => esc_html_x( 'Instagram URL', 'wordpress-seo', 'stream' ), // type = textinput.
|
543 |
+
'linkedin_url' => esc_html_x( 'LinkedIn URL', 'wordpress-seo', 'stream' ), // type = textinput.
|
544 |
+
'myspace_url' => esc_html_x( 'MySpace URL', 'wordpress-seo', 'stream' ), // type = textinput.
|
545 |
+
'pinterest_url' => esc_html_x( 'Pinterest URL', 'wordpress-seo', 'stream' ), // type = textinput.
|
546 |
+
'youtube_url' => esc_html_x( 'YouTube URL', 'wordpress-seo', 'stream' ), // type = textinput.
|
547 |
+
'google_plus_url' => esc_html_x( 'Google+ URL', 'wordpress-seo', 'stream' ), // type = textinput.
|
548 |
+
'og_frontpage_image' => esc_html_x( 'Image URL', 'wordpress-seo', 'stream' ), // type = textinput.
|
549 |
+
'og_frontpage_desc' => esc_html_x( 'Description', 'wordpress-seo', 'stream' ), // type = textinput.
|
550 |
+
'og_frontpage_title' => esc_html_x( 'Title', 'wordpress-seo', 'stream' ), // type = textinput.
|
551 |
+
'og_default_image' => esc_html_x( 'Image URL', 'wordpress-seo', 'stream' ), // type = textinput.
|
552 |
+
'twitter' => esc_html_x( 'Add Twitter card meta data', 'wordpress-seo', 'stream' ), // type = checkbox.
|
553 |
+
'twitter_site' => esc_html_x( 'Site Twitter Username', 'wordpress-seo', 'stream' ), // type = textinput.
|
554 |
+
'twitter_card_type' => esc_html_x( 'The default card type to use', 'wordpress-seo', 'stream' ), // type = select.
|
555 |
+
'googleplus' => esc_html_x( 'Add Google+ specific post meta data (excluding author metadata)', 'wordpress-seo', 'stream' ), // type = checkbox.
|
556 |
+
'plus-publisher' => esc_html_x( 'Google Publisher Page', 'wordpress-seo', 'stream' ), // type = textinput.
|
557 |
+
'fbadminapp' => esc_html_x( 'Facebook App ID', 'wordpress-seo', 'stream' ), // type = textinput.
|
558 |
+
|
559 |
+
// wp-content/plugins/wordpress-seo/admin/pages/xml-sitemaps.php:.
|
560 |
+
'enablexmlsitemap' => esc_html_x( 'Check this box to enable XML sitemap functionality.', 'wordpress-seo', 'stream' ), // type = checkbox.
|
561 |
+
'disable_author_sitemap' => esc_html_x( 'Disable author/user sitemap', 'wordpress-seo', 'stream' ), // type = checkbox.
|
562 |
+
'disable_author_noposts' => esc_html_x( 'Users with zero posts', 'wordpress-seo', 'stream' ), // type = checkbox.
|
563 |
+
'user_role-administrator-not_in_sitemap' => esc_html_x( 'Filter specific user roles - Administrator', 'wordpress-seo', 'stream' ), // type = checkbox.
|
564 |
+
'user_role-editor-not_in_sitemap' => esc_html_x( 'Filter specific user roles - Editor', 'wordpress-seo', 'stream' ), // type = checkbox.
|
565 |
+
'user_role-author-not_in_sitemap' => esc_html_x( 'Filter specific user roles - Author', 'wordpress-seo', 'stream' ), // type = checkbox.
|
566 |
+
'user_role-contributor-not_in_sitemap' => esc_html_x( 'Filter specific user roles - Contributor', 'wordpress-seo', 'stream' ), // type = checkbox.
|
567 |
+
'user_role-subscriber-not_in_sitemap' => esc_html_x( 'Filter specific user roles - Subscriber', 'wordpress-seo', 'stream' ), // type = checkbox.
|
568 |
+
'xml_ping_yahoo' => esc_html_x( 'Ping Yahoo!', 'wordpress-seo', 'stream' ), // type = checkbox.
|
569 |
+
'xml_ping_ask' => esc_html_x( 'Ping Ask.com', 'wordpress-seo', 'stream' ), // type = checkbox.
|
570 |
+
'entries-per-page' => esc_html_x( 'Max entries per sitemap page', 'wordpress-seo', 'stream' ), // type = textinput.
|
571 |
+
'excluded-posts' => esc_html_x( 'Posts to exclude', 'wordpress-seo', 'stream' ), // type = textinput.
|
572 |
+
'post_types-post-not_in_sitemap' => _x( 'Post Types Posts (<code>post</code>)', 'wordpress-seo', 'stream' ), // type = checkbox.
|
573 |
+
'post_types-page-not_in_sitemap' => _x( 'Post Types Pages (<code>page</code>)', 'wordpress-seo', 'stream' ), // type = checkbox.
|
574 |
+
'post_types-attachment-not_in_sitemap' => _x( 'Post Types Media (<code>attachment</code>)', 'wordpress-seo', 'stream' ), // type = checkbox.
|
575 |
+
'taxonomies-category-not_in_sitemap' => _x( 'Taxonomies Categories (<code>category</code>)', 'wordpress-seo', 'stream' ), // type = checkbox.
|
576 |
+
'taxonomies-post_tag-not_in_sitemap' => _x( 'Taxonomies Tags (<code>post_tag</code>)', 'wordpress-seo', 'stream' ), // type = checkbox.
|
577 |
+
|
578 |
+
// Added manually.
|
579 |
Â
'rssbefore' => esc_html_x( 'Content to put before each post in the feed', 'wordpress-seo', 'stream' ),
|
580 |
Â
'rssafter' => esc_html_x( 'Content to put after each post', 'wordpress-seo', 'stream' ),
|
581 |
Â
);
|
582 |
Â
|
583 |
Â
$ast_labels = array(
|
584 |
+
'title-' => esc_html_x( 'Title template', 'wordpress-seo', 'stream' ), // type = textinput.
|
585 |
+
'metadesc-' => esc_html_x( 'Meta description template', 'wordpress-seo', 'stream' ), // type = textarea.
|
586 |
+
'metakey-' => esc_html_x( 'Meta keywords template', 'wordpress-seo', 'stream' ), // type = textinput.
|
587 |
+
'noindex-' => esc_html_x( 'Meta Robots', 'wordpress-seo', 'stream' ), // type = checkbox.
|
588 |
+
'noauthorship-' => esc_html_x( 'Authorship', 'wordpress-seo', 'stream' ), // type = checkbox.
|
589 |
+
'showdate-' => esc_html_x( 'Show date in snippet preview?', 'wordpress-seo', 'stream' ), // type = checkbox.
|
590 |
+
'hideeditbox-' => esc_html_x( 'WordPress SEO Meta Box', 'wordpress-seo', 'stream' ), // type = checkbox.
|
591 |
+
'bctitle-' => esc_html_x( 'Breadcrumbs Title', 'wordpress-seo', 'stream' ), // type = textinput.
|
592 |
+
'post_types-' => esc_html_x( 'Post types', 'wordpress-seo', 'stream' ), // type = checkbox.
|
593 |
+
'taxonomies-' => esc_html_x( 'Taxonomies', 'wordpress-seo', 'stream' ), // type = checkbox.
|
594 |
Â
);
|
595 |
Â
|
596 |
Â
if ( $option ) {
|
contributing.md
CHANGED
@@ -26,7 +26,7 @@ For setups with local Docker environment you don't need Vagrant and VirtualBox.
|
|
26 |
Â
1. See the [Git Flow](#git-flow) section below for how to fork the repository.
|
27 |
Â
2. Run `npm install` to install all project dependencies.
|
28 |
Â
3. Run `vagrant up` to start the development environment.
|
29 |
-
4. Visit [stream.local](
|
30 |
Â
5. Activate the Stream plugin.
|
31 |
Â
|
32 |
Â
### PHP Xdebug
|
26 |
Â
1. See the [Git Flow](#git-flow) section below for how to fork the repository.
|
27 |
Â
2. Run `npm install` to install all project dependencies.
|
28 |
Â
3. Run `vagrant up` to start the development environment.
|
29 |
+
4. Visit [stream.local](http://stream.local) and login using `admin` / `password`.
|
30 |
Â
5. Activate the Stream plugin.
|
31 |
Â
|
32 |
Â
### PHP Xdebug
|
exporters/class-exporter-csv.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Exporter_CSV extends Exporter {
|
5 |
Â
/**
|
6 |
Â
* Exporter name
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* CSV Exporter
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Exporter_CSV
|
12 |
+
*/
|
13 |
Â
class Exporter_CSV extends Exporter {
|
14 |
Â
/**
|
15 |
Â
* Exporter name
|
exporters/class-exporter-json.php
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
namespace WP_Stream;
|
3 |
Â
|
Â
|
|
Â
|
|
Â
|
|
4 |
Â
class Exporter_JSON extends Exporter {
|
5 |
Â
/**
|
6 |
Â
* Exporter name
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* JSON Exporter
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
namespace WP_Stream;
|
9 |
Â
|
10 |
+
/**
|
11 |
+
* Class - Exporter_JSON
|
12 |
+
*/
|
13 |
Â
class Exporter_JSON extends Exporter {
|
14 |
Â
/**
|
15 |
Â
* Exporter name
|
includes/db-updates.php
CHANGED
@@ -1,11 +1,17 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
/**
|
3 |
Â
* Version 3.0.8
|
4 |
Â
*
|
5 |
Â
* Force update for older versions to call \dbdelta in install() method to fix column widths.
|
6 |
Â
*
|
7 |
-
* @param string $db_version
|
8 |
-
* @param string $current_version
|
9 |
Â
*
|
10 |
Â
* @return string
|
11 |
Â
*/
|
@@ -19,8 +25,8 @@ function wp_stream_update_auto_308( $db_version, $current_version ) {
|
|
19 |
Â
/**
|
20 |
Â
* Version 3.0.2
|
21 |
Â
*
|
22 |
-
* @param string $db_version
|
23 |
-
* @param string $current_version
|
24 |
Â
*
|
25 |
Â
* @return string
|
26 |
Â
*/
|
@@ -62,15 +68,15 @@ function wp_stream_update_302( $db_version, $current_version ) {
|
|
62 |
Â
*
|
63 |
Â
* Update from 1.4.9
|
64 |
Â
*
|
65 |
-
* @param string $db_version
|
66 |
-
* @param string $current_version
|
67 |
Â
*
|
68 |
Â
* @return string
|
69 |
Â
*/
|
70 |
Â
function wp_stream_update_auto_300( $db_version, $current_version ) {
|
71 |
Â
global $wpdb;
|
72 |
Â
|
73 |
-
// Get only the author_meta values that are double-serialized
|
74 |
Â
$wpdb->query( "RENAME TABLE {$wpdb->base_prefix}stream TO {$wpdb->base_prefix}stream_tmp, {$wpdb->base_prefix}stream_context TO {$wpdb->base_prefix}stream_context_tmp" );
|
75 |
Â
|
76 |
Â
$plugin = wp_stream_get_instance();
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Defines DB migrations.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
/**
|
9 |
Â
* Version 3.0.8
|
10 |
Â
*
|
11 |
Â
* Force update for older versions to call \dbdelta in install() method to fix column widths.
|
12 |
Â
*
|
13 |
+
* @param string $db_version New database version.
|
14 |
+
* @param string $current_version Current database version.
|
15 |
Â
*
|
16 |
Â
* @return string
|
17 |
Â
*/
|
25 |
Â
/**
|
26 |
Â
* Version 3.0.2
|
27 |
Â
*
|
28 |
+
* @param string $db_version New database version.
|
29 |
+
* @param string $current_version Current database version.
|
30 |
Â
*
|
31 |
Â
* @return string
|
32 |
Â
*/
|
68 |
Â
*
|
69 |
Â
* Update from 1.4.9
|
70 |
Â
*
|
71 |
+
* @param string $db_version New database version.
|
72 |
+
* @param string $current_version Current database version.
|
73 |
Â
*
|
74 |
Â
* @return string
|
75 |
Â
*/
|
76 |
Â
function wp_stream_update_auto_300( $db_version, $current_version ) {
|
77 |
Â
global $wpdb;
|
78 |
Â
|
79 |
+
// Get only the author_meta values that are double-serialized.
|
80 |
Â
$wpdb->query( "RENAME TABLE {$wpdb->base_prefix}stream TO {$wpdb->base_prefix}stream_tmp, {$wpdb->base_prefix}stream_context TO {$wpdb->base_prefix}stream_context_tmp" );
|
81 |
Â
|
82 |
Â
$plugin = wp_stream_get_instance();
|
includes/feeds/atom.php
CHANGED
@@ -1,4 +1,10 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
header( 'Content-Type: ' . feed_content_type( 'atom' ) . '; charset=' . get_option( 'blog_charset' ), true );
|
3 |
Â
printf( '<?xml version="1.0" encoding="%s"?>', esc_attr( get_option( 'blog_charset' ) ) );
|
4 |
Â
?>
|
@@ -30,7 +36,7 @@ printf( '<?xml version="1.0" encoding="%s"?>', esc_attr( get_option( 'blog_chars
|
|
30 |
Â
$display_name = isset( $author->display_name ) ? $author->display_name : 'N/A';
|
31 |
Â
?>
|
32 |
Â
<entry>
|
33 |
-
<title type="html"><![CDATA[[<?php echo esc_html( $domain ); ?>] <?php echo esc_html( $record->summary ); // xss ok ?> ]]></title>
|
34 |
Â
<link href="<?php echo esc_url( $record_link ); ?>" />
|
35 |
Â
<updated><?php echo esc_html( mysql2date( 'c', $record->created, false ) ); ?></updated>
|
36 |
Â
<author>
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Renders an Atom feed of records.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
header( 'Content-Type: ' . feed_content_type( 'atom' ) . '; charset=' . get_option( 'blog_charset' ), true );
|
9 |
Â
printf( '<?xml version="1.0" encoding="%s"?>', esc_attr( get_option( 'blog_charset' ) ) );
|
10 |
Â
?>
|
36 |
Â
$display_name = isset( $author->display_name ) ? $author->display_name : 'N/A';
|
37 |
Â
?>
|
38 |
Â
<entry>
|
39 |
+
<title type="html"><![CDATA[[<?php echo esc_html( $domain ); ?>] <?php echo esc_html( $record->summary ); // xss ok. ?> ]]></title>
|
40 |
Â
<link href="<?php echo esc_url( $record_link ); ?>" />
|
41 |
Â
<updated><?php echo esc_html( mysql2date( 'c', $record->created, false ) ); ?></updated>
|
42 |
Â
<author>
|
includes/feeds/json.php
CHANGED
@@ -1,7 +1,13 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
header( 'Content-type: application/json; charset=' . get_option( 'blog_charset' ), true );
|
3 |
Â
if ( version_compare( PHP_VERSION, '5.4', '<' ) ) {
|
4 |
-
echo wp_stream_json_encode( $records ); // xss ok
|
5 |
Â
} else {
|
6 |
-
echo wp_stream_json_encode( $records, JSON_PRETTY_PRINT ); // xss ok
|
7 |
Â
}
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Renders a JSON of records.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
header( 'Content-type: application/json; charset=' . get_option( 'blog_charset' ), true );
|
9 |
Â
if ( version_compare( PHP_VERSION, '5.4', '<' ) ) {
|
10 |
+
echo wp_stream_json_encode( $records ); // xss ok.
|
11 |
Â
} else {
|
12 |
+
echo wp_stream_json_encode( $records, JSON_PRETTY_PRINT ); // xss ok.
|
13 |
Â
}
|
includes/feeds/rss-2.0.php
CHANGED
@@ -1,4 +1,10 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
header( 'Content-Type: ' . feed_content_type( 'rss-http' ) . '; charset=' . get_option( 'blog_charset' ), true );
|
3 |
Â
printf( '<?xml version="1.0" encoding="%s"?>', esc_attr( get_option( 'blog_charset' ) ) );
|
4 |
Â
?>
|
@@ -44,7 +50,7 @@ printf( '<?xml version="1.0" encoding="%s"?>', esc_attr( get_option( 'blog_chars
|
|
44 |
Â
$display_name = isset( $author->display_name ) ? $author->display_name : 'N/A';
|
45 |
Â
?>
|
46 |
Â
<item>
|
47 |
-
<title><![CDATA[ <?php echo esc_html( $record->summary ); // xss ok ?> ]]></title>
|
48 |
Â
<pubDate><?php echo esc_html( mysql2date( 'r', $record->created, false ) ); ?></pubDate>
|
49 |
Â
<dc:creator><?php echo esc_html( $display_name ); ?></dc:creator>
|
50 |
Â
<category domain="connector"><![CDATA[ <?php echo esc_html( $record->connector ); ?> ]]></category>
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Renders a RSS feed of records.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
header( 'Content-Type: ' . feed_content_type( 'rss-http' ) . '; charset=' . get_option( 'blog_charset' ), true );
|
9 |
Â
printf( '<?xml version="1.0" encoding="%s"?>', esc_attr( get_option( 'blog_charset' ) ) );
|
10 |
Â
?>
|
50 |
Â
$display_name = isset( $author->display_name ) ? $author->display_name : 'N/A';
|
51 |
Â
?>
|
52 |
Â
<item>
|
53 |
+
<title><![CDATA[ <?php echo esc_html( $record->summary ); // xss ok. ?> ]]></title>
|
54 |
Â
<pubDate><?php echo esc_html( mysql2date( 'r', $record->created, false ) ); ?></pubDate>
|
55 |
Â
<dc:creator><?php echo esc_html( $display_name ); ?></dc:creator>
|
56 |
Â
<category domain="connector"><![CDATA[ <?php echo esc_html( $record->connector ); ?> ]]></category>
|
includes/functions.php
CHANGED
@@ -1,4 +1,10 @@
|
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
/**
|
3 |
Â
* Gets a specific external variable by name and optionally filters it.
|
4 |
Â
*
|
@@ -35,8 +41,8 @@ function wp_stream_filter_var( $var, $filter = null, $options = array() ) {
|
|
35 |
Â
/**
|
36 |
Â
* Converts a time into an ISO 8601 extended formatted string.
|
37 |
Â
*
|
38 |
-
* @param int|bool $time
|
39 |
-
* @param int $offset
|
40 |
Â
*
|
41 |
Â
* @return string an ISO 8601 extended formatted time
|
42 |
Â
*/
|
@@ -48,25 +54,20 @@ function wp_stream_get_iso_8601_extended_date( $time = false, $offset = 0 ) {
|
|
48 |
Â
}
|
49 |
Â
|
50 |
Â
$micro_seconds = sprintf( '%06d', ( $microtime - floor( $microtime ) ) * 1000000 );
|
51 |
-
$offset_string = sprintf( 'Etc/GMT%s%
|
52 |
Â
|
53 |
Â
$timezone = new DateTimeZone( $offset_string );
|
54 |
-
$date = new DateTime(
|
55 |
Â
|
56 |
-
return
|
57 |
-
'%s%03d%s',
|
58 |
-
$date->format( 'Y-m-d\TH:i:s.' ),
|
59 |
-
floor( $date->format( 'u' ) / 1000 ),
|
60 |
-
$date->format( 'O' )
|
61 |
-
);
|
62 |
Â
}
|
63 |
Â
|
64 |
Â
/**
|
65 |
Â
* Encode to JSON in a way that is also backwards compatible
|
66 |
Â
*
|
67 |
-
* @param mixed $data
|
68 |
-
* @param int $options (optional)
|
69 |
-
* @param int $depth (optional)
|
70 |
Â
*
|
71 |
Â
* @return string
|
72 |
Â
*/
|
@@ -89,7 +90,7 @@ function wp_stream_json_encode( $data, $options = 0, $depth = 512 ) {
|
|
89 |
Â
/**
|
90 |
Â
* Return an array of sites for a network in a way that is also backwards compatible
|
91 |
Â
*
|
92 |
-
* @param string|array $args
|
93 |
Â
*
|
94 |
Â
* @return array
|
95 |
Â
*/
|
@@ -131,7 +132,7 @@ function wp_stream_is_cron_enabled() {
|
|
131 |
Â
* @return string
|
132 |
Â
*/
|
133 |
Â
function wp_stream_min_suffix() {
|
134 |
-
$min
|
135 |
Â
$is_script_debugging = ! defined( 'SCRIPT_DEBUG' ) || false === SCRIPT_DEBUG;
|
136 |
Â
|
137 |
Â
if ( apply_filters( 'wp_stream_load_min_assets', $is_script_debugging ) ) {
|
1 |
Â
<?php
|
2 |
+
/**
|
3 |
+
* Defines common functionality used throughout the plugin.
|
4 |
+
*
|
5 |
+
* @package WP_Stream
|
6 |
+
*/
|
7 |
+
|
8 |
Â
/**
|
9 |
Â
* Gets a specific external variable by name and optionally filters it.
|
10 |
Â
*
|
41 |
Â
/**
|
42 |
Â
* Converts a time into an ISO 8601 extended formatted string.
|
43 |
Â
*
|
44 |
+
* @param int|bool $time Seconds since unix epoch.
|
45 |
+
* @param int $offset Timezone offset.
|
46 |
Â
*
|
47 |
Â
* @return string an ISO 8601 extended formatted time
|
48 |
Â
*/
|
54 |
Â
}
|
55 |
Â
|
56 |
Â
$micro_seconds = sprintf( '%06d', ( $microtime - floor( $microtime ) ) * 1000000 );
|
57 |
+
$offset_string = sprintf( 'Etc/GMT%s%d', $offset < 0 ? '+' : '-', abs( $offset ) );
|
58 |
Â
|
59 |
Â
$timezone = new DateTimeZone( $offset_string );
|
60 |
+
$date = new DateTime( gmdate( 'Y-m-d H:i:s.' . $micro_seconds, $microtime ), $timezone );
|
61 |
Â
|
62 |
+
return $date->format( 'Y-m-d\TH:i:sO' );
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
63 |
Â
}
|
64 |
Â
|
65 |
Â
/**
|
66 |
Â
* Encode to JSON in a way that is also backwards compatible
|
67 |
Â
*
|
68 |
+
* @param mixed $data Data to be encoded.
|
69 |
+
* @param int $options Compression options (optional).
|
70 |
+
* @param int $depth Tree depth limit (optional).
|
71 |
Â
*
|
72 |
Â
* @return string
|
73 |
Â
*/
|
90 |
Â
/**
|
91 |
Â
* Return an array of sites for a network in a way that is also backwards compatible
|
92 |
Â
*
|
93 |
+
* @param string|array $args Argument to filter results by.
|
94 |
Â
*
|
95 |
Â
* @return array
|
96 |
Â
*/
|
132 |
Â
* @return string
|
133 |
Â
*/
|
134 |
Â
function wp_stream_min_suffix() {
|
135 |
+
$min = '';
|
136 |
Â
$is_script_debugging = ! defined( 'SCRIPT_DEBUG' ) || false === SCRIPT_DEBUG;
|
137 |
Â
|
138 |
Â
if ( apply_filters( 'wp_stream_load_min_assets', $is_script_debugging ) ) {
|
includes/lib/Carbon.php
CHANGED
@@ -312,14 +312,14 @@ class Carbon extends DateTime
|
|
312 |
Â
*/
|
313 |
Â
public static function create($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $tz = null)
|
314 |
Â
{
|
315 |
-
$year = ($year === null) ?
|
316 |
-
$month = ($month === null) ?
|
317 |
-
$day = ($day === null) ?
|
318 |
Â
|
319 |
Â
if ($hour === null) {
|
320 |
-
$hour =
|
321 |
-
$minute = ($minute === null) ?
|
322 |
-
$second = ($second === null) ?
|
323 |
Â
} else {
|
324 |
Â
$minute = ($minute === null) ? 0 : $minute;
|
325 |
Â
$second = ($second === null) ? 0 : $second;
|
@@ -2211,4 +2211,4 @@ class Carbon extends DateTime
|
|
2211 |
Â
{
|
2212 |
Â
return $this->month === $dt->month && $this->day === $dt->day;
|
2213 |
Â
}
|
2214 |
-
}
|
312 |
Â
*/
|
313 |
Â
public static function create($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $tz = null)
|
314 |
Â
{
|
315 |
+
$year = ($year === null) ? gmdate('Y') : $year;
|
316 |
+
$month = ($month === null) ? gmdate('n') : $month;
|
317 |
+
$day = ($day === null) ? gmdate('j') : $day;
|
318 |
Â
|
319 |
Â
if ($hour === null) {
|
320 |
+
$hour = gmdate('G');
|
321 |
+
$minute = ($minute === null) ? gmdate('i') : $minute;
|
322 |
+
$second = ($second === null) ? gmdate('s') : $second;
|
323 |
Â
} else {
|
324 |
Â
$minute = ($minute === null) ? 0 : $minute;
|
325 |
Â
$second = ($second === null) ? 0 : $second;
|
2211 |
Â
{
|
2212 |
Â
return $this->month === $dt->month && $this->day === $dt->day;
|
2213 |
Â
}
|
2214 |
+
}
|
readme.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
Â
# Stream for WordPress
|
2 |
Â
|
3 |
Â
[![Build Status](https://travis-ci.com/xwp/stream.svg?branch=master)](https://travis-ci.com/xwp/stream)
|
Â
|
|
4 |
Â
|
5 |
Â
**Track WordPress user and system actions for debugging, logging and compliance purposes.**
|
6 |
Â
|
1 |
Â
# Stream for WordPress
|
2 |
Â
|
3 |
Â
[![Build Status](https://travis-ci.com/xwp/stream.svg?branch=master)](https://travis-ci.com/xwp/stream)
|
4 |
+
[![Coverage Status](https://coveralls.io/repos/github/xwp/stream/badge.svg?branch=develop)](https://coveralls.io/github/xwp/stream?branch=develop)
|
5 |
Â
|
6 |
Â
**Track WordPress user and system actions for debugging, logging and compliance purposes.**
|
7 |
Â
|
readme.txt
CHANGED
@@ -1,24 +1,26 @@
|
|
1 |
Â
=== Stream ===
|
2 |
-
Contributors:
|
3 |
Â
Tags: wp stream, stream, activity, logs, track
|
4 |
Â
Requires at least: 4.5
|
5 |
Â
Tested up to: 5.4
|
6 |
-
Stable tag: 3.
|
7 |
Â
License: GPLv2 or later
|
8 |
Â
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
9 |
Â
|
10 |
-
|
11 |
-
|
12 |
Â
|
13 |
Â
== Description ==
|
14 |
Â
|
15 |
-
With
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
16 |
Â
|
17 |
-
|
18 |
Â
|
19 |
-
|
20 |
Â
|
21 |
-
Stream is perfect for keeping tabs on your clients. When something breaks, Stream is there to help. See what changed and who changed it.
|
22 |
Â
|
23 |
Â
= Built-In Tracking Integrations For Popular Plugins: =
|
24 |
Â
|
@@ -30,7 +32,7 @@ Stream is perfect for keeping tabs on your clients. When something breaks, Strea
|
|
30 |
Â
* Jetpack
|
31 |
Â
* User Switching
|
32 |
Â
* WooCommerce
|
33 |
-
*
|
34 |
Â
|
35 |
Â
= Built-In Tracking For Core Actions: =
|
36 |
Â
|
@@ -77,6 +79,8 @@ There are several ways you can get involved to help make Stream better:
|
|
77 |
Â
|
78 |
Â
Thank you for wanting to make Stream better for everyone!
|
79 |
Â
|
Â
|
|
Â
|
|
80 |
Â
|
81 |
Â
== Screenshots ==
|
82 |
Â
|
@@ -87,6 +91,12 @@ Thank you for wanting to make Stream better for everyone!
|
|
87 |
Â
|
88 |
Â
== Changelog ==
|
89 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
90 |
Â
= 3.4.3 - March 19, 2020 =
|
91 |
Â
|
92 |
Â
* Fix: Stream records can be filtered by users again [#929](https://github.com/xwp/stream/issues/929), props [@tareiking](https://github.com/tareiking).
|
1 |
Â
=== Stream ===
|
2 |
+
Contributors: xwp
|
3 |
Â
Tags: wp stream, stream, activity, logs, track
|
4 |
Â
Requires at least: 4.5
|
5 |
Â
Tested up to: 5.4
|
6 |
+
Stable tag: 3.5.0
|
7 |
Â
License: GPLv2 or later
|
8 |
Â
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
9 |
Â
|
10 |
+
With Stream, you’re never left in the dark about changes to your WordPress site.
|
Â
|
|
11 |
Â
|
12 |
Â
== Description ==
|
13 |
Â
|
14 |
+
With real-time notifications and third-party integrations, Stream can proactively alert you when something goes wrong with your WordPress site.
|
15 |
+
|
16 |
+
Designed for debugging and compliance purposes, Stream is useful for keeping tabs on your WordPress users: From activating plugins to deleting posts, to login attempts and new user creation, you can see what’s changed, who changed it and when.
|
17 |
+
|
18 |
+
The plugin records WordPress user and system action to the Stream logs. Every logged-in user action is displayed in an activity stream and organized for easy filtering by User, Role, Context, Action or IP address. Admins can highlight entries in the Stream log—such as suspicious user activity—to investigate what’s happening in real time. Stream also allows you to configure email alerts and webhooks for integrations like Slack and IFTTT to notify you and your team when something has gone wrong.
|
19 |
Â
|
20 |
+
For advanced users, Stream also supports a network view of all activity records on your Multisite, the ability to set exclude rules to ignore certain kinds of user activity, and a WP‑CLI command for querying records.
|
21 |
Â
|
22 |
+
With Stream’s powerful logging, you’ll have the valuable information you need to responsibly manage your WordPress sites.
|
23 |
Â
|
Â
|
|
24 |
Â
|
25 |
Â
= Built-In Tracking Integrations For Popular Plugins: =
|
26 |
Â
|
32 |
Â
* Jetpack
|
33 |
Â
* User Switching
|
34 |
Â
* WooCommerce
|
35 |
+
* Yoast SEO
|
36 |
Â
|
37 |
Â
= Built-In Tracking For Core Actions: =
|
38 |
Â
|
79 |
Â
|
80 |
Â
Thank you for wanting to make Stream better for everyone!
|
81 |
Â
|
82 |
+
Past Contributors: fjarrett, shadyvb, chacha, westonruter, johnregan3, jacobschweitzer, lukecarbis, kasparsd, bordoni, dero, faishal, rob, desaiuditd, DavidCramer, renovate-bot, marcin-lawrowski, JeffMatson, Powdered-Toast-Man, johnolek, johnbillion, greguly, pascal-klaeres, szepeviktor, rheinardkorf, frozzare, khromov, dkotter, bhubbard, stipsan, stephenharris, omniwired, kopepasah, joehoyle, eugenekireev, barryceelen, valendesigns, tlovett1, tareiking, stayallive, sayedtaqui, robbiet480, oscarssanchez, kidunot89, johnwatkins0, javorszky, jamesgol, desrosj, davelozier, davefx, cfoellmann, JustinSainton, JJJ, postphotos
|
83 |
+
|
84 |
Â
|
85 |
Â
== Screenshots ==
|
86 |
Â
|
91 |
Â
|
92 |
Â
== Changelog ==
|
93 |
Â
|
94 |
+
= 3.5.0 - July 8, 2020 =
|
95 |
+
|
96 |
+
* Fix: Stream records now show the correct timestamp instead of dates like `-0001/11/30` [#1091](https://github.com/xwp/stream/issues/1091), props [@kidunot89](https://github.com/kidunot89).
|
97 |
+
* Fix: Searching Stream records is now more performant as we throttle the amount of search requests [#1081](https://github.com/xwp/stream/issues/1081), props [@oscarssanchez](https://github.com/oscarssanchez).
|
98 |
+
* Tweak: Inline PHP documentation updates and WordPress coding standard fixes, props [@kidunot89](https://github.com/kidunot89).
|
99 |
+
|
100 |
Â
= 3.4.3 - March 19, 2020 =
|
101 |
Â
|
102 |
Â
* Fix: Stream records can be filtered by users again [#929](https://github.com/xwp/stream/issues/929), props [@tareiking](https://github.com/tareiking).
|
stream.php
CHANGED
@@ -3,12 +3,14 @@
|
|
3 |
Â
* Plugin Name: Stream
|
4 |
Â
* Plugin URI: https://wp-stream.com
|
5 |
Â
* Description: Stream tracks logged-in user activity so you can monitor every change made on your WordPress site in beautifully organized detail. All activity is organized by context, action and IP address for easy filtering. Developers can extend Stream with custom connectors to log any kind of action.
|
6 |
-
* Version: 3.
|
7 |
Â
* Author: XWP
|
8 |
Â
* Author URI: https://xwp.co
|
9 |
Â
* License: GPLv2+
|
10 |
Â
* Text Domain: stream
|
11 |
Â
* Domain Path: /languages
|
Â
|
|
Â
|
|
12 |
Â
*/
|
13 |
Â
|
14 |
Â
/**
|
3 |
Â
* Plugin Name: Stream
|
4 |
Â
* Plugin URI: https://wp-stream.com
|
5 |
Â
* Description: Stream tracks logged-in user activity so you can monitor every change made on your WordPress site in beautifully organized detail. All activity is organized by context, action and IP address for easy filtering. Developers can extend Stream with custom connectors to log any kind of action.
|
6 |
+
* Version: 3.5.0
|
7 |
Â
* Author: XWP
|
8 |
Â
* Author URI: https://xwp.co
|
9 |
Â
* License: GPLv2+
|
10 |
Â
* Text Domain: stream
|
11 |
Â
* Domain Path: /languages
|
12 |
+
*
|
13 |
+
* @package WP_Stream
|
14 |
Â
*/
|
15 |
Â
|
16 |
Â
/**
|
ui/js/admin.js
CHANGED
@@ -68,6 +68,7 @@ jQuery(
|
|
68 |
Â
width: '165px',
|
69 |
Â
ajax: {
|
70 |
Â
url: ajaxurl,
|
Â
|
|
71 |
Â
dataType: 'json',
|
72 |
Â
quietMillis: 100,
|
73 |
Â
data: function( term ) {
|
68 |
Â
width: '165px',
|
69 |
Â
ajax: {
|
70 |
Â
url: ajaxurl,
|
71 |
+
delay: 500,
|
72 |
Â
dataType: 'json',
|
73 |
Â
quietMillis: 100,
|
74 |
Â
data: function( term ) {
|
ui/js/admin.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
jQuery(function(
|
1 |
+
jQuery(function(m){"en"===wp_stream.locale&&void 0!==m.timeago&&(m.timeago.settings.strings.seconds="seconds",m.timeago.settings.strings.minute="a minute",m.timeago.settings.strings.hour="an hour",m.timeago.settings.strings.hours="%d hours",m.timeago.settings.strings.month="a month",m.timeago.settings.strings.year="a year"),m("li.toplevel_page_wp_stream ul li.wp-first-item.current").parent().parent().find(".update-plugins").remove(),m(".toplevel_page_wp_stream :input.chosen-select").each(function(e,t){function a(e){var t=m("<span>"),a=m(e.element),i="";return"- "===e.text.substring(0,2)&&(e.text=e.text.substring(2)),void 0!==e.id&&"string"==typeof e.id&&(0===e.id.indexOf("group-")?t.addClass("parent"):a.hasClass("level-2")&&t.addClass("child")),void 0!==e.icon?i=e.icon:void 0!==a&&""!==a.data("icon")&&(i=a.data("icon")),i&&t.html('<img src="'+i+'" class="wp-stream-select2-icon">'),t.append(e.text),t}function i(e){return"- "===e.text.substring(0,2)&&(e.text=e.text.substring(2)),e.text}var n={};n=0<m(t).find("option").not(":selected").not(":empty").length?{minimumResultsForSearch:10,templateResult:a,templateSelection:i,allowClear:!0,width:"165px"}:{minimumInputLength:3,allowClear:!0,width:"165px",ajax:{url:ajaxurl,delay:500,dataType:"json",quietMillis:100,data:function(e){return{action:"wp_stream_filters",nonce:m("#stream_filters_user_search_nonce").val(),filter:m(t).attr("name"),q:e.term}},processResults:function(e){var a=[];return m.each(e,function(e,t){a.push({id:t.id,text:t.label})}),{results:a}}},templateResult:a,templateSelection:i},m(t).select2(n)});var e=m.streamGetQueryVars(),t=m('.toplevel_page_wp_stream select.chosen-select[name="context"]');void 0!==e.context&&""!==e.context||void 0===e.connector||(t.val("group-"+e.connector),t.trigger("change")),m("input[type=submit]","#record-filter-form").click(function(){m("input[type=submit]",m(this).parents("form")).removeAttr("clicked"),m(this).attr("clicked","true")}),m("#record-filter-form").submit(function(){var e=m('.toplevel_page_wp_stream :input.chosen-select[name="context"]'),t=e.find("option:selected"),a=e.parent().find(".record-filter-connector"),i=t.data("group"),n=t.prop("class"),r=m(".recordactions select");"true"!==m("#record-actions-submit").attr("clicked")&&r.val(""),a.val(i),"level-1"===n&&t.val("")}),m(window).load(function(){m('.toplevel_page_wp_stream input[type="search"]').off("mousedown")}),m("body").on("click","#wp_stream_advanced_delete_all_records, #wp_stream_network_advanced_delete_all_records",function(e){window.confirm(wp_stream.i18n.confirm_purge)||e.preventDefault()}),m("body").on("click","#wp_stream_advanced_reset_site_settings, #wp_stream_network_advanced_reset_site_settings",function(e){window.confirm(wp_stream.i18n.confirm_defaults)||e.preventDefault()}),m("body").on("click","#wp_stream_uninstall",function(e){window.confirm(wp_stream.i18n.confirm_uninstall)||e.preventDefault()});var a=m(".wp_stream_screen .nav-tab-wrapper"),i=m(".wp_stream_screen .nav-tab-content table.form-table"),n=a.find(".nav-tab-active"),r=0<n.length?a.find("a").index(n):0,s=window.location.hash.match(/^#(\d+)$/),o=null!==s?s[1]:r;a.on("click","a",function(){var e=a.find("a").index(m(this)),t=window.location.hash.match(/^#(\d+)$/);return i.hide().eq(e).show(),a.find("a").removeClass("nav-tab-active").filter(m(this)).addClass("nav-tab-active"),""!==window.location.hash&&null===t||(window.location.hash=e),function(e){var t=m('input[name="option_page"][value^="wp_stream"]').closest("form");if(0!==t.length){var a=t.attr("action");t.prop("action",a.replace(/(^[^#]*).*$/,"$1#"+e))}}(e),!1}),a.children().eq(o).trigger("click"),m(document).ready(function(){function t(){var e=!0;m('div.metabox-prefs [name="date-hide"]').is(":checked")&&(e=!1),m("div.alignleft.actions div.select2-container").each(function(){if(!m(this).is(":hidden"))return e=!1}),e?(m("input#record-query-submit").hide(),m("span.filter_info").show()):(m("input#record-query-submit").show(),m("span.filter_info").hide())}m("#enable_live_update").click(function(){var e,t=m("#stream_live_update_nonce").val(),a=m("#enable_live_update_user").val(),i="unchecked";m("#enable_live_update").is(":checked")&&(i="checked"),e=m("#enable_live_update").data("heartbeat"),m.ajax({type:"POST",url:ajaxurl,data:{action:"stream_enable_live_update",nonce:t,user:a,checked:i,heartbeat:e},dataType:"json",beforeSend:function(){m(".stream-live-update-checkbox .spinner").show().css({display:"inline-block"})},success:function(e){m(".stream-live-update-checkbox .spinner").hide(),!1===e.success&&(m("#enable_live_update").prop("checked",!1),e.data&&window.alert(e.data))}})}),m('div.metabox-prefs [name="date-hide"]').is(":checked")?m("div.date-interval").show():m("div.date-interval").hide(),m("div.actions select.chosen-select").each(function(){var e=m(this).prop("name");m('div.metabox-prefs [name="'+e+'-hide"]').is(":checked")?m(this).prev(".select2-container").show():m(this).prev(".select2-container").hide()}),t(),m('div.metabox-prefs [type="checkbox"]').click(function(){var e=m(this).prop("id");"date-hide"===e?m(this).is(":checked")?m("div.date-interval").show():m("div.date-interval").hide():(e=e.replace("-hide",""),m(this).is(":checked")?m('[name="'+e+'"]').prev(".select2-container").show():m('[name="'+e+'"]').prev(".select2-container").hide()),t()}),m("#ui-datepicker-div").addClass("stream-datepicker")}),m("table.wp-list-table").on("updated",function(){m(this).find("time.relative-time").each(function(e,t){var a=m(t);a.removeClass("relative-time"),m('<strong><time datetime="'+a.attr("datetime")+'" class="timeago"/></time></strong><br/>').prependTo(a.parent().parent()).find("time.timeago").timeago()})}).trigger("updated");var c={init:function(e){this.wrapper=e,this.save_interval(this.wrapper.find(".button-primary"),this.wrapper),this.$=this.wrapper.each(function(e,t){var a=m(t),n=a.find(".date-inputs"),r=a.find(".field-from"),s=a.find(".field-to"),i=s.prev(".date-remove"),o=r.prev(".date-remove"),c=a.children(".field-predefined"),d=m("").add(s).add(r);if(jQuery.datepicker){var l=parseFloat(wp_stream.gmt_offset)-(new Date).getTimezoneOffset()/60*-1,p=new Date,u=new Date(p.getTime()+60*l*60*1e3),h=0;p.getDate()===u.getDate()&&p.getMonth()===u.getMonth()||(h=p.getTime()<u.getTime()?"+1d":"-1d"),d.datepicker({dateFormat:"yy/mm/dd",minDate:null,maxDate:h,defaultDate:u,beforeShow:function(){m(this).prop("disabled",!0)},onClose:function(){m(this).prop("disabled",!1)}}),d.datepicker("widget").addClass("stream-datepicker")}c.select2({allowClear:!0}),""!==r.val()&&o.show(),""!==s.val()&&i.show(),c.on({change:function(){var e=m(this).val(),t=c.find('[value="'+e+'"]'),a=t.data("to"),i=t.data("from");if("custom"===e)return n.show(),!1;n.hide(),d.datepicker("hide"),r.val(i).trigger("change",[!0]),s.val(a).trigger("change",[!0]),jQuery.datepicker&&d.datepicker("widget").is(":visible")&&d.datepicker("refresh").datepicker("hide")},"select2-removed":function(){c.val("").trigger("change")},check_options:function(){if(""!==s.val()&&""!==r.val()){var e=c.find("option").filter('[data-to="'+s.val()+'"]').filter('[data-from="'+r.val()+'"]');0!==e.length?c.val(e.attr("value")).trigger("change",[!0]):c.val("custom").trigger("change",[!0])}else""===s.val()&&""===r.val()?c.val("").trigger("change",[!0]):c.val("custom").trigger("change",[!0])}}),r.on("change",function(){if(""!==r.val()?(o.show(),s.datepicker("option","minDate",r.val())):o.hide(),!0===arguments[arguments.length-1])return!1;c.trigger("check_options")}),s.on("change",function(){if(""!==s.val()?(i.show(),r.datepicker("option","maxDate",s.val())):i.hide(),!0===arguments[arguments.length-1])return!1;c.trigger("check_options")}),c.trigger("change"),m("").add(o).add(i).on("click",function(){m(this).next("input").val("").trigger("change")})})},save_interval:function(e){var t=this.wrapper;e.click(function(){var e={key:t.find("select.field-predefined").find(":selected").val(),start:t.find(".date-inputs .field-from").val(),end:t.find(".date-inputs .field-to").val()};m(this).attr("href",m(this).attr("href")+"&"+m.param(e))})}};m(document).ready(function(){c.init(m(".date-interval")),m('select[name="context"] .level-1').each(function(){var e=!0;m(this).nextUntil(".level-1").each(function(){if(m(this).is(":not(:disabled)"))return e=!1}),!0===e&&m(this).prop("disabled",!0)})})}),jQuery.extend({streamGetQueryVars:function(e){return(e||document.location.search).replace(/(^\?)/,"").split("&").map(function(e){return this[(e=e.split("="))[0]]=e[1],this}.bind({}))[0]}});
|
ui/js/alerts.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
jQuery(function(
|
1 |
+
jQuery(function(o){"use strict";function c(t){var e=o(t);e.find(".select2-select.connector_or_context").each(function(t,e){o(e).select2({allowClear:!0,placeholder:streamAlerts.anyContext,templateResult:function(t){return void 0===t.id?t.text:-1===t.id.indexOf("-")?o('<span class="parent">'+t.text+"</span>"):o('<span class="child">'+t.text+"</span>")},matcher:function(t,e){var n=o.extend(!0,{},e);if(null===t.term||""===o.trim(t.term))return n;var a=t.term.toLowerCase();if(n.id=n.id.replace("blogs","sites"),0<=n.id.toLowerCase().indexOf(a))return n;if(n.children){for(var i=n.children.length-1;0<=i;i--){-1===n.children[i].id.toLowerCase().indexOf(a)&&n.children.splice(i,1)}if(0<n.children.length)return n}return null}}).change(function(){var t=o(this).val();if(t){var e=t.split("-");o(this).siblings(".connector").val(e[0]),o(this).siblings(".context").val(e[1])}});var n=[o(e).siblings(".connector").val(),o(e).siblings(".context").val()];""===n[1]&&n.splice(1,1),o(e).val(n.join("-")).trigger("change")}),e.find("select.select2-select:not(.connector_or_context)").each(function(){var t=o(this).attr("id").split("_"),e=t[t.length-1].charAt(0).toUpperCase()+t[t.length-1].slice(1);o(this).select2({allowClear:!0,placeholder:streamAlerts.any+" "+e})})}function i(t){var e={action:"load_alerts_settings",alert_type:t},n=o("#wp_stream_alert_type").closest("tr").attr("id");e.post_id=n.split("-")[1],o.post(window.ajaxurl,e,function(t){var e=o("#wp_stream_alert_type_form");"none"!==o("#wp_stream_alert_type").val()?(e.html(t.data.html),e.show()):e.hide()})}var p,_,t=o("#wp_stream_alert_type");o("#the-list").on("change","#wp_stream_trigger_connector_or_context",function(){if("wp_stream_trigger_connector_or_context"===o(this).attr("id")){var t=o(this).val();if(t&&0<t.indexOf("-"))t=t.split("-")[0];e(t)}});var e=function(t){var s=o("#wp_stream_trigger_action");s.empty(),s.prop("disabled",!0);var e=o("<option/>",{value:"",text:""});s.append(e);var n={action:"get_actions",connector:t};o.post(window.ajaxurl,n,function(t){var e=t.success,n=t.data;if(e){for(var a in n)if(n.hasOwnProperty(a)){var i=n[a],r=o("<option/>",{value:a,text:i});s.append(r)}s.prop("disabled",!1),o(document).trigger("alert-actions-updated")}})};t.change(function(){i(o(this).val())}),o("#wpbody-content").on("click","a.page-title-action",function(t){t.preventDefault(),o("#add-new-alert").remove(),0<o(".inline-edit-wp_stream_alerts").length&&o(".inline-edit-wp_stream_alerts .inline-edit-save button.button-secondary.cancel").trigger("click");var a="";o.post(window.ajaxurl,{action:"get_new_alert_triggers_notifications"},function(t){if(!0===t.success){a=t.data.html,o("tbody#the-list").prepend('<tr id="add-new-alert" class="inline-edit-row inline-edit-row-page inline-edit-page quick-edit-row quick-edit-row-page inline-edit-page inline-editor" style=""><td colspan="4" class="colspanchange">'+a+'<p class="submit inline-edit-save"> <button type="button" class="button-secondary cancel alignleft">Cancel</button> <input type="hidden" id="_inline_edit" name="_inline_edit" value="3550d271fe"> <button type="button" class="button-primary save alignright">Save</button> <span class="spinner"></span><span class="error" style="display:none"></span> <br class="clear"></p></td></tr>');var e=o("#add-new-alert"),n=e.css("background-color");e.css("background-color","#C1E1B9"),setTimeout(function(){e.css("background-color",n)},250),o("#wp_stream_alert_type").change(function(){i(o(this).val())}),e.on("click",".button-secondary.cancel",function(){o("#add-new-alert").remove()}),e.on("click",".button-primary.save",r),c("#add-new-alert")}})});var r=function(t){t.preventDefault(),o("#add-new-alert").find("p.submit.inline-edit-save span.spinner").css("visibility","visible");var e={action:"save_new_alert",wp_stream_alerts_nonce:o("#wp_stream_alerts_nonce").val(),wp_stream_trigger_author:o("#wp_stream_trigger_author").val(),wp_stream_trigger_context:o("#wp_stream_trigger_connector_or_context").val(),wp_stream_trigger_action:o("#wp_stream_trigger_action").val(),wp_stream_alert_type:o("#wp_stream_alert_type").val(),wp_stream_alert_status:o("#wp_stream_alert_status").val()};o("#wp_stream_alert_type_form").find(":input").each(function(){var t=o(this).attr("id");o(this).val()&&(e[t]=o(this).val())}),o.post(window.ajaxurl,e,function(t){!0===t.success&&(o("#add-new-alert").find("p.submit.inline-edit-save span.spinner").css("visibility","hidden"),location.reload())})},d=inlineEditPost.edit;if(inlineEditPost.edit=function(t){d.apply(this,arguments);var e=0;if("object"==typeof t&&(e=parseInt(this.getId(t),10)),0<e){_=o("#edit-"+e);var n=(p=o("#post-"+e)).find('input[name="wp_stream_trigger_connector"]').val(),a=p.find('input[name="wp_stream_trigger_context"]').val(),i=n+"-"+a,r=p.find('input[name="wp_stream_trigger_action"]').val(),s=p.find('input[name="wp_stream_alert_status"]').val();_.find('input[name="wp_stream_trigger_connector"]').attr("value",n),_.find('input[name="wp_stream_trigger_context"]').attr("value",a),_.find('select[name="wp_stream_trigger_connector_or_context"] option[value="'+i+'"]').attr("selected","selected"),o(document).one("alert-actions-updated",function(){_.find('input[name="wp_stream_trigger_action"]').attr("value",r),_.find('select[name="wp_stream_trigger_action"] option[value="'+r+'"]').attr("selected","selected").trigger("change")}),_.find('select[name="wp_stream_alert_status"] option[value="'+s+'"]').attr("selected","selected"),c("#edit-"+e),o("#wp_stream_alert_type_form").hide();var l=p.find('input[name="wp_stream_alert_type"]').val();_.find('select[name="wp_stream_alert_type"] option[value="'+l+'"]').attr("selected","selected").trigger("change")}},window.location.hash){var n=o(window.location.hash);if(n.length){var a=n.offset().top-o("#wpadminbar").height();o("html, body").animate({scrollTop:a},1e3),n.find(".row-actions a.editinline").trigger("click")}}});
|
ui/js/exclude.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
jQuery(function(
|
1 |
+
jQuery(function(a){function t(e){var s;a("select.select2-select.connector_or_context",e).each(function(e,t){a(t).select2({allowClear:!0,templateResult:function(e){return void 0===e.id?e.text:-1===e.id.indexOf("-")?a('<span class="parent">'+e.text+"</span>"):a('<span class="child">'+e.text+"</span>")},matcher:function(e,t){var s=a.extend(!0,{},t);if(null===e.term||""===a.trim(e.term))return s;var n=e.term.toLowerCase();if(s.id=s.id.replace("blogs","sites"),0<=s.id.toLowerCase().indexOf(n))return s;if(s.children){for(var i=s.children.length-1;0<=i;i--){-1===s.children[i].id.toLowerCase().indexOf(n)&&s.children.splice(i,1)}if(0<s.children.length)return s}return null}}).on("change",function(){var e=a(this).closest("tr"),t=a(this).val();t&&0<t.indexOf("-")&&(t=t.split("-")[0]);!function(e,t){var c=a(".select2-select.action",e),r=c.val();c.empty(),c.prop("disabled",!0);var s=a("<option/>",{value:"",text:""});c.append(s);var n={action:"get_actions",connector:t};a.post(window.ajaxurl,n,function(e){var t=e.success,s=e.data;if(t){for(var n in s)if(s.hasOwnProperty(n)){var i=s[n],l=a("<option/>",{value:n,text:i});c.append(l)}c.val(r),c.prop("disabled",!1),a(document).trigger("alert-actions-updated")}})}(e,t)})}),a("select.select2-select.action",e).each(function(e,t){a(t).select2({allowClear:!0})}),a("select.select2-select.author_or_role",e).each(function(e,t){(s=a(t)).select2({ajax:{type:"POST",url:ajaxurl,dataType:"json",quietMillis:500,data:function(e,t){return{find:e,limit:10,pager:t,action:"stream_get_users",nonce:s.data("nonce")}},processResults:function(e){var t={results:[{text:"",id:""},{text:"Roles",children:[]},{text:"Users",children:[]}]};if(!0!==e.success||void 0===e.data||!0!==e.data.status)return t;if(void 0===e.data.users||void 0===e.data.roles)return t;var s=[];return a.each(e.data.roles,function(e,t){s.push({id:e,text:t})}),t.results[1].children=s,t.results[2].children=e.data.users,t}},templateResult:function(e){var t=a("<div>").text(e.text);return void 0!==e.icon&&e.icon&&(t.prepend(a('<img src="'+e.icon+'" class="wp-stream-select2-icon">')),t.attr("title",e.tooltip)),void 0!==e.tooltip?t.attr("title",e.tooltip):void 0!==e.user_count&&t.attr("title",e.user_count),t},templateSelection:function(e){var t=a("<div>").text(e.text);return a.isNumeric(e.id)&&e.text.indexOf("icon-users")<0&&t.append(a('<i class="icon16 icon-users"></i>')),t},allowClear:!0,placeholder:s.data("placeholder")}).on("change",function(){var e=a(this).select2("data");a(this).data("selected-id",e.id),a(this).data("selected-text",e.text)})}),a("select.select2-select.ip_address",e).each(function(e,t){var s=a(t),n="";s.select2({ajax:{type:"POST",url:ajaxurl,dataType:"json",quietMillis:500,data:function(e){return n=e.term,{find:e,limit:10,action:"stream_get_ips",nonce:s.data("nonce")}},processResults:function(e){var s={results:[]},t=[];return!0===e.success&&void 0!==e.data&&a.each(e.data,function(e,t){s.results.push({id:t,text:t})}),void 0===n||null===(t=n.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/))||(t.shift(),4<=(t=a.grep(t,function(e){var t=parseInt(e,10);return t<=255&&t.toString()===e})).length&&s.results.push({id:n,text:n})),s}},allowClear:!1,multiple:!0,maximumSelectionSize:1,placeholder:s.data("placeholder"),tags:!0})}).on("change",function(){a(this).prev(".select2-container").find("input.select2-input").blur()}),a("ul.select2-choices, ul.select2-choices li, input.select2-input",".stream-exclude-list tr:not(.hidden) .ip_address").on("mousedown click focus",function(){var e=a(this).closest(".select2-container"),t=e.find("input.select2-input");if(1<=e.select2("data").length)return t.blur(),!1}),a(".exclude_rules_remove_rule_row",e).on("click",function(e){a(this).closest("tr").remove(),i(),n(),e.preventDefault()})}var e=a(".stream-exclude-list tbody tr:not(.hidden)"),s=a(".stream-exclude-list tr.helper");function n(){var e=a("table.stream-exclude-list tbody tr:not( .hidden ) input.cb-select:checked"),t=a("#exclude_rules_remove_rules");0===e.length?t.prop("disabled",!0):t.prop("disabled",!1)}function i(){var e=a("table.stream-exclude-list tbody tr:not( .hidden )"),t=a("table.stream-exclude-list tbody tr.no-items"),s=a(".check-column.manage-column input.cb-select"),n=a("#exclude_rules_remove_rules");0===e.length?(t.show(),s.prop("disabled",!0),n.prop("disabled",!0)):(t.hide(),s.prop("disabled",!1)),wp_stream_regenerate_alt_rows(e)}t(e),a("select.select2-select.author_or_role",e).each(function(){var e=a("<option selected>"+a(this).data("selected-text")+"</option>").val(a(this).data("selected-id"));a(this).append(e).trigger("change")}),a("select.select2-select.connector_or_context",e).each(function(){var e=[a(this).siblings(".connector").val(),a(this).siblings(".context").val()];""===e[1]&&e.splice(1,1),a(this).val(e.join("-")).trigger("change")}),a("#exclude_rules_new_rule").on("click",function(){var e=s.clone();e.removeAttr("class"),e.insertBefore(s),t(e),i(),n()}),a("#exclude_rules_remove_rules").on("click",function(){var e=a("table.stream-exclude-list"),t=a("tbody input.cb-select:checked",e).closest("tr");2<=a("tbody tr",e).length-t.length?t.remove():(a(":input",t).val(""),a(t).not(":first").remove(),a(".select2-select",t).select2("val","")),e.find("input.cb-select").prop("checked",!1),i(),n()}),a(".stream-exclude-list").closest("form").submit(function(){a(".stream-exclude-list tbody tr.hidden",this).each(function(){a(this).find(":input").removeAttr("name")}),a(".stream-exclude-list tbody tr:not(.hidden) select.select2-select.connector_or_context",this).each(function(){var e=a(this).val().split("-");a(this).siblings(".connector").val(e[0]),a(this).siblings(".context").val(e[1]),a(this).removeAttr("name")}),a(".stream-exclude-list tbody tr:not(.hidden) select.select2-select.ip_address",this).each(function(){var e=a("option:selected",this).first();e.length||a(this).append('<option selected="selected"></option>'),a("option:selected:not(:first)",this).each(function(){e.attr("value",e.attr("value")+","+a(this).attr("value")),a(this).removeAttr("selected")})})}),a(".stream-exclude-list").closest("td").prev("th").hide(),a("table.stream-exclude-list").on("click","input.cb-select",function(){n()}),a(document).ready(function(){i(),n()})});
|
ui/js/global.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
jQuery(function(
|
1 |
+
jQuery(function(e){function n(t){window.confirm(wp_stream_global.bulk_actions.i18n.confirm_action)||t.preventDefault()}e('.actions :submit:not([name="filter_action"])').on("click",function(t){e("table.widefat tbody :checkbox:checked").length>wp_stream_global.bulk_actions.threshold&&n(t)}),e("#delete_all").on("click",function(t){parseInt(e("ul.subsubsub li.trash .count").text().replace(/\D/g,""),10)>wp_stream_global.bulk_actions.threshold&&n(t)})});var wp_stream_regenerate_alt_rows=function(t){if(!t.length)return!1;t.removeClass("alternate"),t.each(function(t){jQuery(this).addClass(t%2?"":"alternate")})};
|
ui/js/live-updates.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
jQuery(function(
|
1 |
+
jQuery(function(d){d(document).ready(function(){if("toplevel_page_wp_stream"===wp_stream_live_updates.current_screen&&"1"===wp_stream_live_updates.current_page&&"asc"!==wp_stream_live_updates.current_order&&!(1<parseInt(wp_stream_live_updates.current_query_count,10))){var _=".toplevel_page_wp_stream #the-list";wp.heartbeat.interval("fast"),d(document).on("heartbeat-send.stream",function(e,t){t["wp-stream-heartbeat"]="live-update";var a=d(_+" tr:first .column-date time"),r=1;0!==a.length&&(r=""===a.attr("datetime")?1:a.attr("datetime")),t["wp-stream-heartbeat-last-time"]=r,t["wp-stream-heartbeat-query"]=wp_stream_live_updates.current_query}),d(document).on("heartbeat-tick.stream",function(e,t){if(t["wp-stream-heartbeat"]&&0!==t["wp-stream-heartbeat"].length){var a=d("#edit_stream_per_page").val(),r=d(_+" tr"),s=d(t["wp-stream-heartbeat"]);s.addClass("new-row");var n=r.first().hasClass("alternate");if(1!==s.length||n){var l=0!=s.length%2||n?"odd":"even";s.filter(":nth-child("+l+")").addClass("alternate")}else s.addClass("alternate");d(_).prepend(s),d(".metabox-prefs input").each(function(){if(!0!==d(this).prop("checked")){var e=d(this).val();d("td.column-"+e).hide()}});var p=a-(s.length+r.length);p<0&&d(_+" tr").slice(p).remove(),d(_+" tr.no-items").remove();var i=t.total_items_i18n||"";i&&(d(".displaying-num").text(i),d(".total-pages").text(t.total_pages_i18n),d(".tablenav-pages").find(".next-page, .last-page").toggleClass("disabled",t.total_pages===d(".current-page").val()),d(".tablenav-pages .last-page").attr("href",t.last_page_link)),d(_).parent().trigger("updated"),wp_stream_regenerate_alt_rows(d(_+" tr")),setTimeout(function(){d(".new-row").addClass("fadeout"),setTimeout(function(){d(_+" tr").removeClass("new-row fadeout")},500)},3e3)}})}})});
|
ui/js/settings.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
jQuery(function(
|
1 |
+
jQuery(function(t){var e;e="wp_stream_network"===t('input[name="option_page"]').val()?"_network_affix":"";var a=t("#wp_stream"+e+"\\[general_keep_records_indefinitely\\]"),n=t("#wp_stream"+e+"_general_records_ttl"),i=n.closest("tr");function r(){a.is(":checked")?(i.addClass("hidden"),n.addClass("hidden")):(i.removeClass("hidden"),n.removeClass("hidden"))}a.on("change",function(){r()}),r(),t("#wp_stream_general_reset_site_settings").click(function(e){confirm(wp_stream.i18n.confirm_defaults)||e.preventDefault()});var o=t(".nav-tab-wrapper"),s=t(".nav-tab-content table.form-table"),c=o.find(".nav-tab-active"),l=0<c.length?o.find("a").index(c):0,d=window.location.hash.match(/^#(\d+)$/),h=null!==d?d[1]:l;o.on("click","a",function(){var e=o.find("a").index(t(this)),a=window.location.hash.match(/^#(\d+)$/);return s.hide().eq(e).show(),o.find("a").removeClass("nav-tab-active").filter(t(this)).addClass("nav-tab-active"),""!==window.location.hash&&null===a||(window.location.hash=e),function(e){var a=t('input[name="option_page"][value^="wp_stream"]').closest("form");if(0!==a.length){var n=a.attr("action");a.prop("action",n.replace(/(^[^#]*).*$/,"$1#"+e))}}(e),!1}),o.children().eq(h).trigger("click")});
|