WP ULike - Version 4.3.1

Version Description

  • Fixed: Third-party plugin issues.
Download this release

Release Info

Developer alimir
Plugin Icon 128x128 WP ULike
Version 4.3.1
Comparing to
See all releases

Code changes from version 4.3.0 to 4.3.1

admin/assets/js/plugins.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! WP ULike - v4.3.0
2
  * https://wpulike.com
3
  * TechnoWich 2020;
4
  */
1
+ /*! WP ULike - v4.3.1
2
  * https://wpulike.com
3
  * TechnoWich 2020;
4
  */
assets/js/wp-ulike.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! WP ULike - v4.3.0
2
  * https://wpulike.com
3
  * TechnoWich 2020;
4
  */
1
+ /*! WP ULike - v4.3.1
2
  * https://wpulike.com
3
  * TechnoWich 2020;
4
  */
inc/hooks/third-party.php CHANGED
@@ -16,434 +16,431 @@ if ( ! defined( 'WPINC' ) ) {
16
  BuddyPress
17
  *******************************************************/
18
 
19
- if( defined( 'BP_VERSION' ) ) {
20
-
21
- if( ! function_exists( 'wp_ulike_put_buddypress' ) ){
22
- /**
23
- * Auto insert wp_ulike_buddypress in the activities content
24
- *
25
- * @since 1.7
26
- * @return void
27
- */
28
- function wp_ulike_put_buddypress() {
29
- $options = wp_ulike_get_option( 'buddypress_group' );
30
- $action = current_action();
31
 
32
- if ( isset( $options['enable_auto_display'] ) && wp_ulike_is_true( $options['enable_auto_display'] ) ) {
33
- // Add wp_ulike function
34
- $button = wp_ulike_buddypress('put');
35
-
36
- switch ( $action ) {
37
- case 'bp_activity_comment_options':
38
- if( isset( $options['enable_comments'] ) && wp_ulike_is_true( $options['enable_comments'] ) ) {
39
- if ( isset( $options['auto_display_position'] ) && $options['auto_display_position'] === 'meta' ){
40
- echo $button;
41
- }
42
- }
43
- break;
44
 
45
- case 'bp_activity_entry_meta':
 
 
46
  if ( isset( $options['auto_display_position'] ) && $options['auto_display_position'] === 'meta' ){
47
  echo $button;
48
  }
49
- break;
 
50
 
51
- case 'bp_activity_entry_content':
52
- if ( isset( $options['auto_display_position'] ) && $options['auto_display_position'] === 'content' ){
53
- echo $button;
54
- }
55
- break;
56
- }
 
 
 
 
 
57
  }
58
  }
59
- add_action( 'bp_activity_entry_meta', 'wp_ulike_put_buddypress', 15 );
60
- add_action( 'bp_activity_comment_options', 'wp_ulike_put_buddypress', 15 );
61
- add_action( 'bp_activity_entry_content', 'wp_ulike_put_buddypress', 15 );
62
  }
 
 
 
 
63
 
64
 
65
- if( ! function_exists( 'wp_ulike_buddypress_activity_content_ajax_display' ) ){
66
- /**
67
- * BuddyPress activity content display for ajax load more
68
- *
69
- * @param string $content
70
- * @return string
71
- */
72
- function wp_ulike_buddypress_activity_content_ajax_display( &$activity ) {
73
- $activityID = $activity->id;
74
 
75
- add_filter( 'bp_get_activity_content_body', function( $content ) use ( $activityID ){
76
- $options = wp_ulike_get_option( 'buddypress_group' );
77
- if ( isset( $options['enable_auto_display'] ) && wp_ulike_is_true( $options['enable_auto_display'] ) ) {
78
- if ( isset( $options['auto_display_position'] ) && $options['auto_display_position'] === 'content' ){
79
- return $content . wp_ulike_buddypress( 'put', array( 'id' => $activityID ) );
80
- }
81
  }
82
- return $content;
83
- } );
 
84
 
85
- }
86
- add_action( 'bp_nouveau_get_single_activity_content', 'wp_ulike_buddypress_activity_content_ajax_display', 15, 1 );
87
  }
 
 
88
 
89
- if( ! function_exists( 'wp_ulike_buddypress_comment_content_display' ) ){
90
- /**
91
- * BuddyPress Comment Content auto display hook
92
- *
93
- * @param string $content
94
- * @return string
95
- */
96
- function wp_ulike_buddypress_comment_content_display( $content, $context ) {
97
- $options = wp_ulike_get_option( 'buddypress_group' );
98
 
99
- if ( isset( $options['enable_auto_display'] ) && wp_ulike_is_true( $options['enable_auto_display'] ) && $context === 'get' ) {
100
 
101
- if( isset( $options['enable_comments'] ) && wp_ulike_is_true( $options['enable_comments'] ) ) {
102
- if ( isset( $options['auto_display_position'] ) && $options['auto_display_position'] === 'content' ){
103
- return $content . wp_ulike_buddypress('put');
104
- }
105
  }
106
  }
107
-
108
- return $content;
109
  }
110
- add_filter( 'bp_activity_comment_content', 'wp_ulike_buddypress_comment_content_display', 15, 2 );
 
111
  }
 
 
112
 
113
- if( ! function_exists( 'wp_ulike_register_activity_actions' ) ){
114
- /**
115
- * Register "WP ULike Activity" action
116
- *
117
- * @since 1.7
118
- * @return void
119
- */
120
- function wp_ulike_register_activity_actions() {
121
- global $bp;
122
- bp_activity_set_action(
123
- $bp->activity->id,
124
- 'wp_like_group',
125
- __( 'WP ULike Activity', WP_ULIKE_SLUG )
126
- );
127
- }
128
- add_action( 'bp_register_activity_actions', 'wp_ulike_register_activity_actions' );
129
  }
 
 
130
 
131
- if( ! function_exists( 'wp_ulike_bp_activity_filter_options' ) ){
132
- /**
133
- * Display likes option in BuddyPress activity filter
134
- *
135
- * @since 2.5.1
136
- * @return void
137
- */
138
- function wp_ulike_bp_activity_filter_options() {
139
- echo "<option value='wp_like_group'>". __( 'Votes', WP_ULIKE_SLUG ) ."</option>";
140
- }
141
- add_action( 'bp_activity_filter_options', 'wp_ulike_bp_activity_filter_options' ); // Activity Directory
142
- add_action( 'bp_member_activity_filter_options', 'wp_ulike_bp_activity_filter_options' ); // Member's profile activity
143
- add_action( 'bp_group_activity_filter_options', 'wp_ulike_bp_activity_filter_options' ); // Group's activity
144
  }
 
 
 
 
145
 
146
- if( ! function_exists( 'wp_ulike_filter_notifications_get_registered_components' ) ){
147
- /**
148
- * Register 'wp_ulike' to BuddyPress component
149
- *
150
- * @since 2.5
151
- * @param array $component_names
152
- * @return string
153
- */
154
- function wp_ulike_filter_notifications_get_registered_components( $component_names = array() ) {
155
- // Force $component_names to be an array
156
- if ( ! is_array( $component_names ) ) {
157
- $component_names = array();
158
- }
159
- // Add 'wp_ulike' component to registered components array
160
- array_push( $component_names, 'wp_ulike' );
161
- // Return component's with 'wp_ulike' appended
162
- return $component_names;
163
  }
164
- add_filter( 'bp_notifications_get_registered_components', 'wp_ulike_filter_notifications_get_registered_components', 10 );
 
 
 
165
  }
 
 
166
 
167
 
168
- if( ! function_exists( 'wp_ulike_add_bp_notifications' ) ){
169
- /**
170
- * Add new buddypress activities on each like
171
- *
172
- * @since 1.6
173
- * @param integer $cp_ID
174
- * @param string $type
175
- * @param integer $user_ID
176
- * @param string $status
177
- * @param boolean $has_log
178
- * @return void
179
- */
180
- function wp_ulike_add_bp_notifications( $cp_ID, $type, $user_ID, $status, $has_log ){
181
-
182
- // Return if user not logged in or an older data log exist
183
- if( ! is_user_logged_in() || $has_log > 0 || ! function_exists( 'bp_is_active' ) ){
184
- return;
185
- }
186
 
187
- $options = wp_ulike_get_option( 'buddypress_group' );
 
 
 
188
 
189
- //Create a new activity when an user likes something
190
- if ( isset( $options['enable_add_bp_activity'] ) && wp_ulike_is_true( $options['enable_add_bp_activity'] ) ) {
191
 
192
- switch ( $type ) {
193
- case '_liked':
194
- // Replace the post variables
195
- $post_template = wp_ulike_get_option( 'posts_notification_template', '<strong>%POST_LIKER%</strong> liked <a href="%POST_PERMALINK%" title="%POST_TITLE%">%POST_TITLE%</a>. (So far, This post has <span class="badge">%POST_COUNT%</span> likes)' );
196
 
197
- if ( strpos( $post_template, '%POST_LIKER%' ) !== false ) {
198
- $POST_LIKER = bp_core_get_userlink( $user_ID );
199
- $post_template = str_replace( "%POST_LIKER%", $POST_LIKER, $post_template );
200
- }
201
- if ( strpos( $post_template, '%POST_PERMALINK%' ) !== false ) {
202
- $POST_PERMALINK = get_permalink($cp_ID);
203
- $post_template = str_replace( "%POST_PERMALINK%", $POST_PERMALINK, $post_template );
204
- }
205
- if ( strpos( $post_template, '%POST_COUNT%' ) !== false ) {
206
- $POST_COUNT = wp_ulike_get_post_likes( $cp_ID );
207
- $post_template = str_replace( "%POST_COUNT%", $POST_COUNT, $post_template );
208
- }
209
- if ( strpos( $post_template, '%POST_TITLE%' ) !== false ) {
210
- $POST_TITLE = get_the_title( $cp_ID );
211
- $post_template = str_replace( "%POST_TITLE%", $POST_TITLE, $post_template );
212
- }
213
- bp_activity_add( array(
214
- 'user_id' => $user_ID,
215
- 'action' => $post_template,
216
- 'component' => 'activity',
217
- 'type' => 'wp_like_group',
218
- 'item_id' => $cp_ID
219
- ));
220
- break;
221
-
222
- case '_commentliked':
223
- // Replace the comment variables
224
- $comment_template = wp_ulike_get_option( 'comments_notification_template', '<strong>%COMMENT_LIKER%</strong> liked <strong>%COMMENT_AUTHOR%</strong> comment. (So far, %COMMENT_AUTHOR% has <span class="badge">%COMMENT_COUNT%</span> likes for this comment)' );
225
-
226
- if ( strpos( $comment_template, '%COMMENT_LIKER%' ) !== false ) {
227
- $COMMENT_LIKER = bp_core_get_userlink( $user_ID );
228
- $comment_template = str_replace("%COMMENT_LIKER%", $COMMENT_LIKER, $comment_template );
229
- }
230
- if ( strpos( $comment_template, '%COMMENT_PERMALINK%' ) !== false ) {
231
- $COMMENT_PERMALINK = get_comment_link( $cp_ID );
232
- $comment_template = str_replace( "%COMMENT_PERMALINK%", $COMMENT_PERMALINK, $comment_template );
233
- }
234
- if ( strpos( $comment_template, '%COMMENT_AUTHOR%' ) !== false ) {
235
- $COMMENT_AUTHOR = get_comment_author( $cp_ID );
236
- $comment_template = str_replace( "%COMMENT_AUTHOR%", $COMMENT_AUTHOR, $comment_template );
237
- }
238
- if ( strpos( $comment_template, '%COMMENT_COUNT%' ) !== false ) {
239
- $COMMENT_COUNT = wp_ulike_get_comment_likes( $cp_ID );
240
- $comment_template = str_replace( "%COMMENT_COUNT%", $COMMENT_COUNT, $comment_template );
241
- }
242
- bp_activity_add( array(
243
- 'user_id' => $user_ID,
244
- 'action' => $comment_template,
245
- 'component' => 'activity',
246
- 'type' => 'wp_like_group',
247
- 'item_id' => $cp_ID
248
- ));
249
- break;
250
-
251
- default:
252
- break;
253
- }
254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  }
256
 
257
- //Sends out notifications when you get a like from someone
258
- if ( isset( $options['enable_add_notification'] ) && wp_ulike_is_true( $options['enable_add_notification'] ) ) {
259
- // No notifications from Anonymous
260
- if ( ! $user_ID || false === get_userdata( $user_ID ) ) {
261
- return false;
262
- }
263
- $author_ID = wp_ulike_get_auhtor_id( $cp_ID, $type );
264
- if ( ! $author_ID || $author_ID == $user_ID ) {
265
- return false;
266
- }
267
- bp_notifications_add_notification( array(
268
- 'user_id' => $author_ID,
269
- 'item_id' => $cp_ID,
270
- 'secondary_item_id' => $user_ID,
271
- 'component_name' => 'wp_ulike',
272
- 'component_action' => 'wp_ulike' . $type . '_action',
273
- 'date_notified' => bp_core_current_time(),
274
- 'is_new' => 1,
275
- )
276
- );
277
- }
278
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  }
280
- add_action( 'wp_ulike_after_process', 'wp_ulike_add_bp_notifications', 10, 5 );
281
  }
 
 
282
 
283
- if( ! function_exists( 'wp_ulike_format_buddypress_notifications' ) ){
284
- /**
285
- * Format notifications related to activity.
286
- *
287
- * @param string $content Component action. Deprecated. Do not do checks against this! Use
288
- * the 6th parameter instead - $component_action_name.
289
- * @param int $item_id Notification item ID.
290
- * @param int $secondary_item_id Notification secondary item ID.
291
- * @param int $total_items Number of notifications with the same action.
292
- * @param string $format Format of return. Either 'string' or 'object'.
293
- * @param string $action Canonical notification action.
294
- * @param string $component Notification component ID.
295
- * @param int $id Notification ID.
296
- * @return string $return Formatted notification.
297
- */
298
- function wp_ulike_format_buddypress_notifications( $content, $item_id, $secondary_item_id, $total_items, $format = 'string', $action, $component, $id ) {
299
- global $wp_filter,$wp_version;
300
-
301
- if ( strpos( $action, 'wp_ulike_' ) !== false ) {
302
- //Extracting ulike type from the action value.
303
- preg_match('/wp_ulike_(.*?)_action/', $action, $type);
304
- //Extracting user id from old action name values.
305
- preg_match('/action_([0-9]+)/', $action, $user_ID);
306
- //Get user info
307
- $user_ID = isset( $user_ID[1] ) ? $user_ID[1] : $secondary_item_id;
308
- $action_type = __( 'posts' , WP_ULIKE_SLUG );
309
- $custom_link = '';
310
-
311
- // Check the the ulike types
312
- switch ( $type[1] ) {
313
- case 'commentliked':
314
- $custom_link = get_comment_link( $item_id );
315
- $action_type = __( 'comments' , WP_ULIKE_SLUG );
316
- break;
317
-
318
- case 'activityliked':
319
- $custom_link = bp_activity_get_permalink( $item_id );
320
- $action_type = __( 'activities' , WP_ULIKE_SLUG );
321
- break;
322
-
323
- default:
324
- $custom_link = get_permalink( $item_id );
325
- break;
326
- }
327
 
328
- // Setup the output strings
329
- if ( (int) $total_items > 1 ) {
330
- $custom_text = sprintf( __( 'You have %d new %s likes', WP_ULIKE_SLUG ), (int) $total_items, $action_type );
331
- $custom_link = add_query_arg( 'type', $action, bp_get_notifications_permalink() );
332
- } else {
333
- $user_fullname = bp_core_get_user_displayname( $user_ID );
334
- $custom_text = sprintf( __( '%s liked one of your %s', WP_ULIKE_SLUG ), $user_fullname, $action_type );
335
- $custom_link = add_query_arg( 'read_ulike_notification', (int) $id, $custom_link );
336
- }
337
 
338
- // WordPress Toolbar
339
- if ( 'string' === $format ) {
340
- $content = apply_filters( 'wp_ulike_bp_notifications_template', '<a href="' . esc_url( $custom_link ) . '" title="' . esc_attr( $custom_text ) . '">' . esc_html( $custom_text ) . '</a>', $custom_link, (int) $total_items, $item_id, $user_ID );
341
- // Deprecated BuddyBar
342
- } else {
343
- $content = apply_filters( 'wp_ulike_bp_notifications_template', array(
344
- 'text' => $custom_text,
345
- 'link' => $custom_link
346
- ), $custom_link, (int) $total_items, $item_id, $user_ID );
347
- }
348
 
349
- if ( function_exists('bbp_get_version') && version_compare( bbp_get_version(), '2.6.0' , '<') ) {
350
- // global wp_filter to call bbPress wrapper function
351
- if( isset( $wp_filter['bp_notifications_get_notifications_for_user'][10]['bbp_format_buddypress_notifications'] ) ) {
352
- if( version_compare( $wp_version, '4.7', '>=' ) ) {
353
- $wp_filter['bp_notifications_get_notifications_for_user']->callbacks[10]['bbp_format_buddypress_notifications']['function'] = 'wp_ulike_bbp_format_buddypress_notifications';
354
- } else {
355
- $wp_filter['bp_notifications_get_notifications_for_user'][10]['bbp_format_buddypress_notifications']['function'] = 'wp_ulike_bbp_format_buddypress_notifications';
356
- }
357
  }
358
  }
359
-
360
- return $content;
361
  }
362
 
363
  return $content;
364
  }
365
- add_filter( 'bp_notifications_get_notifications_for_user', 'wp_ulike_format_buddypress_notifications', 25, 8 );
366
- }
367
 
368
- if( ! function_exists( 'wp_ulike_notification_filters' ) ){
369
- /**
370
- * Add ulike notifications to initial buddyPress filters
371
- *
372
- * @return void
373
- */
374
- function wp_ulike_notification_filters(){
375
- $notifications = array(
376
- array(
377
- 'id' => 'wp_ulike_activityliked_action',
378
- 'label' => __( 'New activity liked', WP_ULIKE_SLUG ),
379
- 'position' => 340,
380
- ),
381
- array(
382
- 'id' => 'wp_ulike_commentliked_action',
383
- 'label' => __( 'New comment liked', WP_ULIKE_SLUG ),
384
- 'position' => 345,
385
- ),
386
- array(
387
- 'id' => 'wp_ulike_liked_action',
388
- 'label' => __( 'New post liked', WP_ULIKE_SLUG ),
389
- 'position' => 355,
390
- ),
391
- array(
392
- 'id' => 'wp_ulike_topicliked_action',
393
- 'label' => __( 'New topic liked', WP_ULIKE_SLUG ),
394
- 'position' => 365,
395
- )
396
- );
397
 
398
- foreach ( $notifications as $notification ) {
399
- if( ! wp_ulike_bbp_is_component_exist( $notification['id'] ) ){
400
- continue;
401
- }
402
- bp_nouveau_notifications_register_filter( $notification );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403
  }
 
404
  }
405
- add_action( 'bp_nouveau_notifications_init_filters', 'wp_ulike_notification_filters' );
406
  }
 
 
407
 
408
- if( ! function_exists( 'wp_ulike_seen_bp_notifications' ) ){
409
- /**
410
- * Mark notifications as read when a user visits an activity permalink.
411
- *
412
- * @since 3.6.0
413
- */
414
- function wp_ulike_seen_bp_notifications() {
415
- if ( ! is_user_logged_in() ) {
416
- return;
417
- }
418
 
419
- $comment_id = 0;
420
- // For replies to a parent update.
421
- if ( isset( $_GET['read_ulike_notification'] ) && ! empty( $_GET['read_ulike_notification'] ) ) {
422
- $comment_id = (int) $_GET['read_ulike_notification'];
423
- }
424
 
425
- // Mark individual activity reply notification as read.
426
- if ( $comment_id ) {
427
- BP_Notifications_Notification::update(
428
- array(
429
- 'is_new' => false
430
- ),
431
- array(
432
- 'user_id' => bp_loggedin_user_id(),
433
- 'id' => $comment_id
434
- )
435
- );
436
- }
437
  }
438
- add_action( 'wp_loaded', 'wp_ulike_seen_bp_notifications' );
439
  }
 
440
  }
441
 
442
  /*******************************************************
443
  bbPress
444
  *******************************************************/
445
 
446
- if( ! function_exists( 'wp_ulike_put_bbpress' ) && function_exists( 'is_bbpress' ) ){
447
  /**
448
  * Auto insert wp_ulike_bbpress in the topics content
449
  *
@@ -492,7 +489,7 @@ if( ! function_exists( 'wp_ulike_put_bbpress' ) && function_exists( 'is_bbpress'
492
  *******************************************************/
493
 
494
  // Litespeed cache plugin
495
- if( ! function_exists( 'wp_ulike_purge_litespeed_cache' ) && class_exists( 'LiteSpeed\Core' ) ){
496
  /**
497
  * Purge litespeed post cache
498
  *
@@ -501,6 +498,11 @@ if( ! function_exists( 'wp_ulike_purge_litespeed_cache' ) && class_exists( 'Lite
501
  * @return void
502
  */
503
  function wp_ulike_purge_litespeed_cache( $ID, $type ){
 
 
 
 
 
504
  if( $type === '_liked' ){
505
  if( get_post_type( $ID ) ){
506
  do_action( 'litespeed_purge_post', $ID );
@@ -519,7 +521,7 @@ if( ! function_exists( 'wp_ulike_purge_litespeed_cache' ) && class_exists( 'Lite
519
  }
520
 
521
  // w3 total cache plugin
522
- if( ! function_exists( 'wp_ulike_purge_w3_total_cache' ) && function_exists( 'w3tc_flush_post' ) ){
523
  /**
524
  * Purge w3 total post cache
525
  *
@@ -528,6 +530,11 @@ if( ! function_exists( 'wp_ulike_purge_w3_total_cache' ) && function_exists( 'w3
528
  * @return void
529
  */
530
  function wp_ulike_purge_w3_total_cache( $ID, $type ){
 
 
 
 
 
531
  if( $type === '_liked' ){
532
  if( get_post_type( $ID ) ){
533
  w3tc_flush_post( $ID );
@@ -546,7 +553,7 @@ if( ! function_exists( 'wp_ulike_purge_w3_total_cache' ) && function_exists( 'w3
546
  }
547
 
548
  // wp fastest cache plugin
549
- if( ! function_exists( 'wp_ulike_purge_wp_fastest_cache' ) && class_exists( 'WpFastestCache' ) ){
550
  /**
551
  * Purge wp fastest cache
552
  *
@@ -555,9 +562,11 @@ if( ! function_exists( 'wp_ulike_purge_wp_fastest_cache' ) && class_exists( 'WpF
555
  * @return void
556
  */
557
  function wp_ulike_purge_wp_fastest_cache( $ID, $type ){
558
- if( !isset( $GLOBALS["wp_fastest_cache"] ) ){
 
559
  return;
560
  }
 
561
  $cache_interface = $GLOBALS["wp_fastest_cache"];
562
 
563
  // to remove cache if vote is from homepage or category page or tag
@@ -606,7 +615,7 @@ if( ! function_exists( 'wp_ulike_purge_wp_fastest_cache' ) && class_exists( 'WpF
606
  }
607
 
608
  // wp super cache plugin
609
- if( ! function_exists( 'wp_ulike_purge_wp_super_cache' ) && function_exists( 'wpsc_delete_post_cache' ) ){
610
  /**
611
  * Purge super post cache
612
  *
@@ -615,6 +624,11 @@ if( ! function_exists( 'wp_ulike_purge_wp_super_cache' ) && function_exists( 'wp
615
  * @return void
616
  */
617
  function wp_ulike_purge_wp_super_cache( $ID, $type ){
 
 
 
 
 
618
  if( $type === '_liked' ){
619
  if( get_post_type( $ID ) ){
620
  wpsc_delete_post_cache( $ID );
@@ -633,7 +647,7 @@ if( ! function_exists( 'wp_ulike_purge_wp_super_cache' ) && function_exists( 'wp
633
  }
634
 
635
  // wp rocket cache plugin
636
- if( ! function_exists( 'wp_ulike_purge_rocket_cache' ) && function_exists( 'rocket_clean_post' ) ){
637
  /**
638
  * Purge wp rocket cache
639
  *
@@ -642,6 +656,11 @@ if( ! function_exists( 'wp_ulike_purge_rocket_cache' ) && function_exists( 'rock
642
  * @return void
643
  */
644
  function wp_ulike_purge_rocket_cache( $ID, $type ){
 
 
 
 
 
645
  if( $type === '_liked' ){
646
  // Check post type ID
647
  if( get_post_type( $ID ) ){
@@ -661,7 +680,7 @@ if( ! function_exists( 'wp_ulike_purge_rocket_cache' ) && function_exists( 'rock
661
  }
662
 
663
  // wp optimize cache plugin
664
- if( ! function_exists( 'wp_ulike_purge_wp_optimize_cache' ) && class_exists('WPO_Page_Cache') ){
665
  /**
666
  * Purge wp optimize cache
667
  *
@@ -670,6 +689,11 @@ if( ! function_exists( 'wp_ulike_purge_wp_optimize_cache' ) && class_exists('WPO
670
  * @return void
671
  */
672
  function wp_ulike_purge_wp_optimize_cache( $ID, $type ){
 
 
 
 
 
673
  if( $type === '_liked' ){
674
  if( get_post_type( $ID ) ){
675
  WPO_Page_Cache::delete_single_post_cache( $ID );
@@ -692,172 +716,168 @@ if( ! function_exists( 'wp_ulike_purge_wp_optimize_cache' ) && class_exists('WPO
692
  *******************************************************/
693
 
694
  // My Cred Plugin
695
- if( defined( 'myCRED_VERSION' ) ){
696
- if( ! function_exists( 'wp_ulike_register_myCRED_hook' ) ){
697
- /**
698
- * register wp_ulike in mycred setup
699
- *
700
- * @since 2.3
701
- * @param array $installed
702
- * @return void
703
- */
704
- function wp_ulike_register_myCRED_hook( $installed ) {
705
- $installed['wp_ulike'] = array(
706
- 'title' => WP_ULIKE_NAME,
707
- 'description' => __( 'This hook award / deducts points from users who Like/Unlike any content of WordPress, bbPress, BuddyPress & ...', WP_ULIKE_SLUG ),
708
- 'callback' => array( 'wp_ulike_myCRED' )
709
- );
710
- return $installed;
711
- }
712
- add_filter( 'mycred_setup_hooks', 'wp_ulike_register_myCRED_hook' );
713
  }
714
- if( ! function_exists( 'wp_ulike_myCRED_references' ) ){
715
- /**
716
- * Add ulike references
717
- *
718
- * @since 2.3
719
- * @param array $list
720
- * @return void
721
- */
722
- function wp_ulike_myCRED_references( $list ) {
723
- $list['wp_add_like'] = __( 'Liking Content', WP_ULIKE_SLUG );
724
- $list['wp_get_like'] = __( 'Liked Content', WP_ULIKE_SLUG );
725
- $list['wp_add_unlike'] = __( 'Unliking Content', WP_ULIKE_SLUG );
726
- $list['wp_get_unlike'] = __( 'Unliked Content', WP_ULIKE_SLUG );
727
- return $list;
728
- }
729
- add_filter( 'mycred_all_references', 'wp_ulike_myCRED_references' );
730
  }
 
731
  }
732
 
733
  // Ultimate Member plugin
734
- if ( defined( 'ultimatemember_version' ) ) {
735
- if( ! function_exists( 'wp_ulike_add_custom_profile_tab' ) ){
736
- /**
737
- * Add custom tabs in the UltimateMember profiles.
738
- *
739
- * @since 2.3
740
- * @param array $tabs
741
- * @return array $tabs
742
- */
743
- function wp_ulike_add_custom_profile_tab( $tabs ) {
744
-
745
- $tabs['wp-ulike-posts'] = array(
746
- 'name' => __('Recent Posts Liked',WP_ULIKE_SLUG),
747
- 'icon' => 'um-faicon-thumbs-up',
748
- );
749
-
750
- $tabs['wp-ulike-comments'] = array(
751
- 'name' => __('Recent Comments Liked',WP_ULIKE_SLUG),
752
- 'icon' => 'um-faicon-thumbs-o-up',
753
- );
754
-
755
- return $tabs;
756
- }
757
- add_filter('um_profile_tabs', 'wp_ulike_add_custom_profile_tab', 1000 );
758
- }
759
-
760
- if( ! function_exists( 'wp_ulike_posts_um_profile_content' ) ){
761
- /**
762
- * Add content to the wp-ulike-posts tab
763
- *
764
- * @since 2.3
765
- * @param array $args
766
- * @return void
767
- */
768
- function wp_ulike_posts_um_profile_content() {
769
- //Main data
770
- $args = array(
771
- "type" => 'post',
772
- "rel_type" => 'post',
773
- "status" => 'like',
774
- "user_id" => um_profile_id(),
775
- "is_popular" => false,
776
- "limit" => 10
777
- );
778
-
779
- $get_items = wp_ulike_get_popular_items_ids( $args );
780
 
781
- $query_args = array(
782
- 'post__in' => $get_items,
783
- 'orderby' => 'post__in',
784
- 'posts_per_page' => $args['limit']
785
- );
786
 
787
- $query = new WP_Query( $query_args );
788
-
789
- if( $query->have_posts() ):
790
- while( $query->have_posts() ): $query->the_post();
791
- echo '<div class="um-item">';
792
- echo '<div class="um-item-link">
793
- <i class="um-icon-ios-paper"></i>
794
- <a href="'.get_permalink().'">'.get_the_title().'</a>
795
- </div>';
796
- echo '<div class="um-item-meta">
797
- <span>'.get_the_date().'</span>
798
- <span class="badge"><i class="um-faicon-thumbs-o-up"></i> '.wp_ulike_get_post_likes( get_the_ID() ).'</span>
799
- </div>';
800
- echo '</div>';
801
- endwhile;
802
- else:
803
- echo '<div style="display: block;" class="um-profile-note"><i class="um-faicon-frown-o"></i><span>'. __('This user has not made any likes.',WP_ULIKE_SLUG).'</span></div>';
804
- endif;
805
- wp_reset_postdata();
806
 
807
- }
808
- add_action('um_profile_content_wp-ulike-posts_default', 'wp_ulike_posts_um_profile_content');
809
  }
 
 
810
 
811
- if( ! function_exists( 'wp_ulike_comments_um_profile_content' ) ){
812
- /**
813
- * Add content to the wp-ulike-comments tab
814
- *
815
- * @since 2.3
816
- * @param array $args
817
- * @return void
818
- */
819
- function wp_ulike_comments_um_profile_content() {
820
- //Main data
821
- $args = array(
822
- "type" => 'comment',
823
- "rel_type" => '',
824
- "status" => 'like',
825
- "user_id" => um_profile_id(),
826
- "is_popular" => false,
827
- "limit" => 10
828
- );
829
-
830
- $get_items = wp_ulike_get_popular_items_ids( $args );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
831
 
832
- $query_args = array(
833
- 'comment__in' => $get_items,
834
- 'orderby' => 'comment__in',
835
- 'posts_per_page' => $args['limit']
836
- );
837
 
838
- // The Query
839
- $comments_query = new WP_Comment_Query;
840
- $comments = $comments_query->query( $query_args );
841
-
842
- // Comment Loop
843
- if ( $comments ) {
844
- foreach ( $comments as $comment ) {
845
- echo '<div class="um-item">';
846
- echo '<div class="um-item-link">
847
- <i class="um-icon-ios-chatboxes"></i>
848
- <a href="'.get_comment_link($comment->comment_ID).'">'.$comment->comment_content .'</a>
849
- <em style="font-size:.7em;padding:0 10px;"><span class="um-faicon-quote-left"></span> '.$comment->comment_author.' <span class="um-faicon-quote-right"></span></em>
850
- </div>';
851
- echo '<div class="um-item-meta">
852
- <span>'.get_comment_date( '', $comment->comment_ID ).'</span>
853
- <span class="badge"><i class="um-faicon-thumbs-o-up"></i> '.wp_ulike_get_comment_likes( $comment->comment_ID ).'</span>
854
- </div>';
855
- echo '</div>';
856
- }
857
- } else {
858
- echo '<div style="display: block;" class="um-profile-note"><i class="um-faicon-frown-o"></i><span>'. __('This user has not made any likes.',WP_ULIKE_SLUG).'</span></div>';
859
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
860
  }
861
- add_action('um_profile_content_wp-ulike-comments_default', 'wp_ulike_comments_um_profile_content');
862
  }
 
863
  }
16
  BuddyPress
17
  *******************************************************/
18
 
19
+ if( ! function_exists( 'wp_ulike_put_buddypress' ) ){
20
+ /**
21
+ * Auto insert wp_ulike_buddypress in the activities content
22
+ *
23
+ * @since 1.7
24
+ * @return void
25
+ */
26
+ function wp_ulike_put_buddypress() {
27
+ $options = wp_ulike_get_option( 'buddypress_group' );
28
+ $action = current_action();
 
 
29
 
30
+ if ( isset( $options['enable_auto_display'] ) && wp_ulike_is_true( $options['enable_auto_display'] ) ) {
31
+ // Add wp_ulike function
32
+ $button = wp_ulike_buddypress('put');
 
 
 
 
 
 
 
 
 
33
 
34
+ switch ( $action ) {
35
+ case 'bp_activity_comment_options':
36
+ if( isset( $options['enable_comments'] ) && wp_ulike_is_true( $options['enable_comments'] ) ) {
37
  if ( isset( $options['auto_display_position'] ) && $options['auto_display_position'] === 'meta' ){
38
  echo $button;
39
  }
40
+ }
41
+ break;
42
 
43
+ case 'bp_activity_entry_meta':
44
+ if ( isset( $options['auto_display_position'] ) && $options['auto_display_position'] === 'meta' ){
45
+ echo $button;
46
+ }
47
+ break;
48
+
49
+ case 'bp_activity_entry_content':
50
+ if ( isset( $options['auto_display_position'] ) && $options['auto_display_position'] === 'content' ){
51
+ echo $button;
52
+ }
53
+ break;
54
  }
55
  }
 
 
 
56
  }
57
+ add_action( 'bp_activity_entry_meta', 'wp_ulike_put_buddypress', 15 );
58
+ add_action( 'bp_activity_comment_options', 'wp_ulike_put_buddypress', 15 );
59
+ add_action( 'bp_activity_entry_content', 'wp_ulike_put_buddypress', 15 );
60
+ }
61
 
62
 
63
+ if( ! function_exists( 'wp_ulike_buddypress_activity_content_ajax_display' ) ){
64
+ /**
65
+ * BuddyPress activity content display for ajax load more
66
+ *
67
+ * @param string $content
68
+ * @return string
69
+ */
70
+ function wp_ulike_buddypress_activity_content_ajax_display( &$activity ) {
71
+ $activityID = $activity->id;
72
 
73
+ add_filter( 'bp_get_activity_content_body', function( $content ) use ( $activityID ){
74
+ $options = wp_ulike_get_option( 'buddypress_group' );
75
+ if ( isset( $options['enable_auto_display'] ) && wp_ulike_is_true( $options['enable_auto_display'] ) ) {
76
+ if ( isset( $options['auto_display_position'] ) && $options['auto_display_position'] === 'content' ){
77
+ return $content . wp_ulike_buddypress( 'put', array( 'id' => $activityID ) );
 
78
  }
79
+ }
80
+ return $content;
81
+ } );
82
 
 
 
83
  }
84
+ add_action( 'bp_nouveau_get_single_activity_content', 'wp_ulike_buddypress_activity_content_ajax_display', 15, 1 );
85
+ }
86
 
87
+ if( ! function_exists( 'wp_ulike_buddypress_comment_content_display' ) ){
88
+ /**
89
+ * BuddyPress Comment Content auto display hook
90
+ *
91
+ * @param string $content
92
+ * @return string
93
+ */
94
+ function wp_ulike_buddypress_comment_content_display( $content, $context ) {
95
+ $options = wp_ulike_get_option( 'buddypress_group' );
96
 
97
+ if ( isset( $options['enable_auto_display'] ) && wp_ulike_is_true( $options['enable_auto_display'] ) && $context === 'get' ) {
98
 
99
+ if( isset( $options['enable_comments'] ) && wp_ulike_is_true( $options['enable_comments'] ) ) {
100
+ if ( isset( $options['auto_display_position'] ) && $options['auto_display_position'] === 'content' ){
101
+ return $content . wp_ulike_buddypress('put');
 
102
  }
103
  }
 
 
104
  }
105
+
106
+ return $content;
107
  }
108
+ add_filter( 'bp_activity_comment_content', 'wp_ulike_buddypress_comment_content_display', 15, 2 );
109
+ }
110
 
111
+ if( ! function_exists( 'wp_ulike_register_activity_actions' ) ){
112
+ /**
113
+ * Register "WP ULike Activity" action
114
+ *
115
+ * @since 1.7
116
+ * @return void
117
+ */
118
+ function wp_ulike_register_activity_actions() {
119
+ global $bp;
120
+ bp_activity_set_action(
121
+ $bp->activity->id,
122
+ 'wp_like_group',
123
+ __( 'WP ULike Activity', WP_ULIKE_SLUG )
124
+ );
 
 
125
  }
126
+ add_action( 'bp_register_activity_actions', 'wp_ulike_register_activity_actions' );
127
+ }
128
 
129
+ if( ! function_exists( 'wp_ulike_bp_activity_filter_options' ) ){
130
+ /**
131
+ * Display likes option in BuddyPress activity filter
132
+ *
133
+ * @since 2.5.1
134
+ * @return void
135
+ */
136
+ function wp_ulike_bp_activity_filter_options() {
137
+ echo "<option value='wp_like_group'>". __( 'Votes', WP_ULIKE_SLUG ) ."</option>";
 
 
 
 
138
  }
139
+ add_action( 'bp_activity_filter_options', 'wp_ulike_bp_activity_filter_options' ); // Activity Directory
140
+ add_action( 'bp_member_activity_filter_options', 'wp_ulike_bp_activity_filter_options' ); // Member's profile activity
141
+ add_action( 'bp_group_activity_filter_options', 'wp_ulike_bp_activity_filter_options' ); // Group's activity
142
+ }
143
 
144
+ if( ! function_exists( 'wp_ulike_filter_notifications_get_registered_components' ) ){
145
+ /**
146
+ * Register 'wp_ulike' to BuddyPress component
147
+ *
148
+ * @since 2.5
149
+ * @param array $component_names
150
+ * @return string
151
+ */
152
+ function wp_ulike_filter_notifications_get_registered_components( $component_names = array() ) {
153
+ // Force $component_names to be an array
154
+ if ( ! is_array( $component_names ) ) {
155
+ $component_names = array();
 
 
 
 
 
156
  }
157
+ // Add 'wp_ulike' component to registered components array
158
+ array_push( $component_names, 'wp_ulike' );
159
+ // Return component's with 'wp_ulike' appended
160
+ return $component_names;
161
  }
162
+ add_filter( 'bp_notifications_get_registered_components', 'wp_ulike_filter_notifications_get_registered_components', 10 );
163
+ }
164
 
165
 
166
+ if( ! function_exists( 'wp_ulike_add_bp_notifications' ) ){
167
+ /**
168
+ * Add new buddypress activities on each like
169
+ *
170
+ * @since 1.6
171
+ * @param integer $cp_ID
172
+ * @param string $type
173
+ * @param integer $user_ID
174
+ * @param string $status
175
+ * @param boolean $has_log
176
+ * @return void
177
+ */
178
+ function wp_ulike_add_bp_notifications( $cp_ID, $type, $user_ID, $status, $has_log ){
 
 
 
 
 
179
 
180
+ // Return if user not logged in or an older data log exist
181
+ if( ! is_user_logged_in() || $has_log > 0 || ! function_exists( 'bp_is_active' ) || ! defined( 'BP_VERSION' ) ){
182
+ return;
183
+ }
184
 
185
+ $options = wp_ulike_get_option( 'buddypress_group' );
 
186
 
187
+ //Create a new activity when an user likes something
188
+ if ( isset( $options['enable_add_bp_activity'] ) && wp_ulike_is_true( $options['enable_add_bp_activity'] ) ) {
 
 
189
 
190
+ switch ( $type ) {
191
+ case '_liked':
192
+ // Replace the post variables
193
+ $post_template = wp_ulike_get_option( 'posts_notification_template', '<strong>%POST_LIKER%</strong> liked <a href="%POST_PERMALINK%" title="%POST_TITLE%">%POST_TITLE%</a>. (So far, This post has <span class="badge">%POST_COUNT%</span> likes)' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
 
195
+ if ( strpos( $post_template, '%POST_LIKER%' ) !== false ) {
196
+ $POST_LIKER = bp_core_get_userlink( $user_ID );
197
+ $post_template = str_replace( "%POST_LIKER%", $POST_LIKER, $post_template );
198
+ }
199
+ if ( strpos( $post_template, '%POST_PERMALINK%' ) !== false ) {
200
+ $POST_PERMALINK = get_permalink($cp_ID);
201
+ $post_template = str_replace( "%POST_PERMALINK%", $POST_PERMALINK, $post_template );
202
+ }
203
+ if ( strpos( $post_template, '%POST_COUNT%' ) !== false ) {
204
+ $POST_COUNT = wp_ulike_get_post_likes( $cp_ID );
205
+ $post_template = str_replace( "%POST_COUNT%", $POST_COUNT, $post_template );
206
+ }
207
+ if ( strpos( $post_template, '%POST_TITLE%' ) !== false ) {
208
+ $POST_TITLE = get_the_title( $cp_ID );
209
+ $post_template = str_replace( "%POST_TITLE%", $POST_TITLE, $post_template );
210
+ }
211
+ bp_activity_add( array(
212
+ 'user_id' => $user_ID,
213
+ 'action' => $post_template,
214
+ 'component' => 'activity',
215
+ 'type' => 'wp_like_group',
216
+ 'item_id' => $cp_ID
217
+ ));
218
+ break;
219
+
220
+ case '_commentliked':
221
+ // Replace the comment variables
222
+ $comment_template = wp_ulike_get_option( 'comments_notification_template', '<strong>%COMMENT_LIKER%</strong> liked <strong>%COMMENT_AUTHOR%</strong> comment. (So far, %COMMENT_AUTHOR% has <span class="badge">%COMMENT_COUNT%</span> likes for this comment)' );
223
+
224
+ if ( strpos( $comment_template, '%COMMENT_LIKER%' ) !== false ) {
225
+ $COMMENT_LIKER = bp_core_get_userlink( $user_ID );
226
+ $comment_template = str_replace("%COMMENT_LIKER%", $COMMENT_LIKER, $comment_template );
227
+ }
228
+ if ( strpos( $comment_template, '%COMMENT_PERMALINK%' ) !== false ) {
229
+ $COMMENT_PERMALINK = get_comment_link( $cp_ID );
230
+ $comment_template = str_replace( "%COMMENT_PERMALINK%", $COMMENT_PERMALINK, $comment_template );
231
+ }
232
+ if ( strpos( $comment_template, '%COMMENT_AUTHOR%' ) !== false ) {
233
+ $COMMENT_AUTHOR = get_comment_author( $cp_ID );
234
+ $comment_template = str_replace( "%COMMENT_AUTHOR%", $COMMENT_AUTHOR, $comment_template );
235
+ }
236
+ if ( strpos( $comment_template, '%COMMENT_COUNT%' ) !== false ) {
237
+ $COMMENT_COUNT = wp_ulike_get_comment_likes( $cp_ID );
238
+ $comment_template = str_replace( "%COMMENT_COUNT%", $COMMENT_COUNT, $comment_template );
239
+ }
240
+ bp_activity_add( array(
241
+ 'user_id' => $user_ID,
242
+ 'action' => $comment_template,
243
+ 'component' => 'activity',
244
+ 'type' => 'wp_like_group',
245
+ 'item_id' => $cp_ID
246
+ ));
247
+ break;
248
+
249
+ default:
250
+ break;
251
  }
252
 
253
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
 
255
+ //Sends out notifications when you get a like from someone
256
+ if ( isset( $options['enable_add_notification'] ) && wp_ulike_is_true( $options['enable_add_notification'] ) ) {
257
+ // No notifications from Anonymous
258
+ if ( ! $user_ID || false === get_userdata( $user_ID ) ) {
259
+ return false;
260
+ }
261
+ $author_ID = wp_ulike_get_auhtor_id( $cp_ID, $type );
262
+ if ( ! $author_ID || $author_ID == $user_ID ) {
263
+ return false;
264
+ }
265
+ bp_notifications_add_notification( array(
266
+ 'user_id' => $author_ID,
267
+ 'item_id' => $cp_ID,
268
+ 'secondary_item_id' => $user_ID,
269
+ 'component_name' => 'wp_ulike',
270
+ 'component_action' => 'wp_ulike' . $type . '_action',
271
+ 'date_notified' => bp_core_current_time(),
272
+ 'is_new' => 1,
273
+ )
274
+ );
275
  }
276
+
277
  }
278
+ add_action( 'wp_ulike_after_process', 'wp_ulike_add_bp_notifications', 10, 5 );
279
+ }
280
 
281
+ if( ! function_exists( 'wp_ulike_format_buddypress_notifications' ) ){
282
+ /**
283
+ * Format notifications related to activity.
284
+ *
285
+ * @param string $content Component action. Deprecated. Do not do checks against this! Use
286
+ * the 6th parameter instead - $component_action_name.
287
+ * @param int $item_id Notification item ID.
288
+ * @param int $secondary_item_id Notification secondary item ID.
289
+ * @param int $total_items Number of notifications with the same action.
290
+ * @param string $format Format of return. Either 'string' or 'object'.
291
+ * @param string $action Canonical notification action.
292
+ * @param string $component Notification component ID.
293
+ * @param int $id Notification ID.
294
+ * @return string $return Formatted notification.
295
+ */
296
+ function wp_ulike_format_buddypress_notifications( $content, $item_id, $secondary_item_id, $total_items, $format = 'string', $action, $component, $id ) {
297
+ global $wp_filter,$wp_version;
298
+
299
+ if ( strpos( $action, 'wp_ulike_' ) !== false ) {
300
+ //Extracting ulike type from the action value.
301
+ preg_match('/wp_ulike_(.*?)_action/', $action, $type);
302
+ //Extracting user id from old action name values.
303
+ preg_match('/action_([0-9]+)/', $action, $user_ID);
304
+ //Get user info
305
+ $user_ID = isset( $user_ID[1] ) ? $user_ID[1] : $secondary_item_id;
306
+ $action_type = __( 'posts' , WP_ULIKE_SLUG );
307
+ $custom_link = '';
308
+
309
+ // Check the the ulike types
310
+ switch ( $type[1] ) {
311
+ case 'commentliked':
312
+ $custom_link = get_comment_link( $item_id );
313
+ $action_type = __( 'comments' , WP_ULIKE_SLUG );
314
+ break;
315
+
316
+ case 'activityliked':
317
+ $custom_link = bp_activity_get_permalink( $item_id );
318
+ $action_type = __( 'activities' , WP_ULIKE_SLUG );
319
+ break;
320
+
321
+ default:
322
+ $custom_link = get_permalink( $item_id );
323
+ break;
324
+ }
325
 
326
+ // Setup the output strings
327
+ if ( (int) $total_items > 1 ) {
328
+ $custom_text = sprintf( __( 'You have %d new %s likes', WP_ULIKE_SLUG ), (int) $total_items, $action_type );
329
+ $custom_link = add_query_arg( 'type', $action, bp_get_notifications_permalink() );
330
+ } else {
331
+ $user_fullname = bp_core_get_user_displayname( $user_ID );
332
+ $custom_text = sprintf( __( '%s liked one of your %s', WP_ULIKE_SLUG ), $user_fullname, $action_type );
333
+ $custom_link = add_query_arg( 'read_ulike_notification', (int) $id, $custom_link );
334
+ }
335
 
336
+ // WordPress Toolbar
337
+ if ( 'string' === $format ) {
338
+ $content = apply_filters( 'wp_ulike_bp_notifications_template', '<a href="' . esc_url( $custom_link ) . '" title="' . esc_attr( $custom_text ) . '">' . esc_html( $custom_text ) . '</a>', $custom_link, (int) $total_items, $item_id, $user_ID );
339
+ // Deprecated BuddyBar
340
+ } else {
341
+ $content = apply_filters( 'wp_ulike_bp_notifications_template', array(
342
+ 'text' => $custom_text,
343
+ 'link' => $custom_link
344
+ ), $custom_link, (int) $total_items, $item_id, $user_ID );
345
+ }
346
 
347
+ if ( function_exists('bbp_get_version') && version_compare( bbp_get_version(), '2.6.0' , '<') ) {
348
+ // global wp_filter to call bbPress wrapper function
349
+ if( isset( $wp_filter['bp_notifications_get_notifications_for_user'][10]['bbp_format_buddypress_notifications'] ) ) {
350
+ if( version_compare( $wp_version, '4.7', '>=' ) ) {
351
+ $wp_filter['bp_notifications_get_notifications_for_user']->callbacks[10]['bbp_format_buddypress_notifications']['function'] = 'wp_ulike_bbp_format_buddypress_notifications';
352
+ } else {
353
+ $wp_filter['bp_notifications_get_notifications_for_user'][10]['bbp_format_buddypress_notifications']['function'] = 'wp_ulike_bbp_format_buddypress_notifications';
 
354
  }
355
  }
 
 
356
  }
357
 
358
  return $content;
359
  }
 
 
360
 
361
+ return $content;
362
+ }
363
+ add_filter( 'bp_notifications_get_notifications_for_user', 'wp_ulike_format_buddypress_notifications', 25, 8 );
364
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
365
 
366
+ if( ! function_exists( 'wp_ulike_notification_filters' ) ){
367
+ /**
368
+ * Add ulike notifications to initial buddyPress filters
369
+ *
370
+ * @return void
371
+ */
372
+ function wp_ulike_notification_filters(){
373
+ $notifications = array(
374
+ array(
375
+ 'id' => 'wp_ulike_activityliked_action',
376
+ 'label' => __( 'New activity liked', WP_ULIKE_SLUG ),
377
+ 'position' => 340,
378
+ ),
379
+ array(
380
+ 'id' => 'wp_ulike_commentliked_action',
381
+ 'label' => __( 'New comment liked', WP_ULIKE_SLUG ),
382
+ 'position' => 345,
383
+ ),
384
+ array(
385
+ 'id' => 'wp_ulike_liked_action',
386
+ 'label' => __( 'New post liked', WP_ULIKE_SLUG ),
387
+ 'position' => 355,
388
+ ),
389
+ array(
390
+ 'id' => 'wp_ulike_topicliked_action',
391
+ 'label' => __( 'New topic liked', WP_ULIKE_SLUG ),
392
+ 'position' => 365,
393
+ )
394
+ );
395
+
396
+ foreach ( $notifications as $notification ) {
397
+ if( ! wp_ulike_bbp_is_component_exist( $notification['id'] ) ){
398
+ continue;
399
  }
400
+ bp_nouveau_notifications_register_filter( $notification );
401
  }
 
402
  }
403
+ add_action( 'bp_nouveau_notifications_init_filters', 'wp_ulike_notification_filters' );
404
+ }
405
 
406
+ if( ! function_exists( 'wp_ulike_seen_bp_notifications' ) ){
407
+ /**
408
+ * Mark notifications as read when a user visits an activity permalink.
409
+ *
410
+ * @since 3.6.0
411
+ */
412
+ function wp_ulike_seen_bp_notifications() {
413
+ if ( ! is_user_logged_in() ) {
414
+ return;
415
+ }
416
 
417
+ $comment_id = 0;
418
+ // For replies to a parent update.
419
+ if ( isset( $_GET['read_ulike_notification'] ) && ! empty( $_GET['read_ulike_notification'] ) ) {
420
+ $comment_id = (int) $_GET['read_ulike_notification'];
421
+ }
422
 
423
+ // Mark individual activity reply notification as read.
424
+ if ( $comment_id ) {
425
+ BP_Notifications_Notification::update(
426
+ array(
427
+ 'is_new' => false
428
+ ),
429
+ array(
430
+ 'user_id' => bp_loggedin_user_id(),
431
+ 'id' => $comment_id
432
+ )
433
+ );
 
434
  }
 
435
  }
436
+ add_action( 'wp_loaded', 'wp_ulike_seen_bp_notifications' );
437
  }
438
 
439
  /*******************************************************
440
  bbPress
441
  *******************************************************/
442
 
443
+ if( ! function_exists( 'wp_ulike_put_bbpress' ) ){
444
  /**
445
  * Auto insert wp_ulike_bbpress in the topics content
446
  *
489
  *******************************************************/
490
 
491
  // Litespeed cache plugin
492
+ if( ! function_exists( 'wp_ulike_purge_litespeed_cache' ) ){
493
  /**
494
  * Purge litespeed post cache
495
  *
498
  * @return void
499
  */
500
  function wp_ulike_purge_litespeed_cache( $ID, $type ){
501
+ // Check functionality existence
502
+ if( ! class_exists('LiteSpeed\Core') ){
503
+ return;
504
+ }
505
+
506
  if( $type === '_liked' ){
507
  if( get_post_type( $ID ) ){
508
  do_action( 'litespeed_purge_post', $ID );
521
  }
522
 
523
  // w3 total cache plugin
524
+ if( ! function_exists( 'wp_ulike_purge_w3_total_cache' ) ){
525
  /**
526
  * Purge w3 total post cache
527
  *
530
  * @return void
531
  */
532
  function wp_ulike_purge_w3_total_cache( $ID, $type ){
533
+ // Check functionality existence
534
+ if( ! function_exists( 'w3tc_flush_post' ) ){
535
+ return;
536
+ }
537
+
538
  if( $type === '_liked' ){
539
  if( get_post_type( $ID ) ){
540
  w3tc_flush_post( $ID );
553
  }
554
 
555
  // wp fastest cache plugin
556
+ if( ! function_exists( 'wp_ulike_purge_wp_fastest_cache' ) ){
557
  /**
558
  * Purge wp fastest cache
559
  *
562
  * @return void
563
  */
564
  function wp_ulike_purge_wp_fastest_cache( $ID, $type ){
565
+ // Check functionality existence
566
+ if( ! isset( $GLOBALS["wp_fastest_cache"] ) || ! class_exists( 'WpFastestCache' ) ){
567
  return;
568
  }
569
+
570
  $cache_interface = $GLOBALS["wp_fastest_cache"];
571
 
572
  // to remove cache if vote is from homepage or category page or tag
615
  }
616
 
617
  // wp super cache plugin
618
+ if( ! function_exists( 'wp_ulike_purge_wp_super_cache' ) ){
619
  /**
620
  * Purge super post cache
621
  *
624
  * @return void
625
  */
626
  function wp_ulike_purge_wp_super_cache( $ID, $type ){
627
+ // Check functionality existence
628
+ if( ! function_exists( 'wpsc_delete_post_cache' ) ){
629
+ return;
630
+ }
631
+
632
  if( $type === '_liked' ){
633
  if( get_post_type( $ID ) ){
634
  wpsc_delete_post_cache( $ID );
647
  }
648
 
649
  // wp rocket cache plugin
650
+ if( ! function_exists( 'wp_ulike_purge_rocket_cache' ) ){
651
  /**
652
  * Purge wp rocket cache
653
  *
656
  * @return void
657
  */
658
  function wp_ulike_purge_rocket_cache( $ID, $type ){
659
+ // Check functionality existence
660
+ if( ! function_exists( 'rocket_clean_post' ) ){
661
+ return;
662
+ }
663
+
664
  if( $type === '_liked' ){
665
  // Check post type ID
666
  if( get_post_type( $ID ) ){
680
  }
681
 
682
  // wp optimize cache plugin
683
+ if( ! function_exists( 'wp_ulike_purge_wp_optimize_cache' ) ){
684
  /**
685
  * Purge wp optimize cache
686
  *
689
  * @return void
690
  */
691
  function wp_ulike_purge_wp_optimize_cache( $ID, $type ){
692
+ // Check functionality existence
693
+ if( ! class_exists('WPO_Page_Cache') ){
694
+ return;
695
+ }
696
+
697
  if( $type === '_liked' ){
698
  if( get_post_type( $ID ) ){
699
  WPO_Page_Cache::delete_single_post_cache( $ID );
716
  *******************************************************/
717
 
718
  // My Cred Plugin
719
+ if( ! function_exists( 'wp_ulike_register_myCRED_hook' ) ){
720
+ /**
721
+ * register wp_ulike in mycred setup
722
+ *
723
+ * @since 2.3
724
+ * @param array $installed
725
+ * @return void
726
+ */
727
+ function wp_ulike_register_myCRED_hook( $installed ) {
728
+ $installed['wp_ulike'] = array(
729
+ 'title' => WP_ULIKE_NAME,
730
+ 'description' => __( 'This hook award / deducts points from users who Like/Unlike any content of WordPress, bbPress, BuddyPress & ...', WP_ULIKE_SLUG ),
731
+ 'callback' => array( 'wp_ulike_myCRED' )
732
+ );
733
+ return $installed;
 
 
 
734
  }
735
+ add_filter( 'mycred_setup_hooks', 'wp_ulike_register_myCRED_hook' );
736
+ }
737
+ if( ! function_exists( 'wp_ulike_myCRED_references' ) ){
738
+ /**
739
+ * Add ulike references
740
+ *
741
+ * @since 2.3
742
+ * @param array $list
743
+ * @return void
744
+ */
745
+ function wp_ulike_myCRED_references( $list ) {
746
+ $list['wp_add_like'] = __( 'Liking Content', WP_ULIKE_SLUG );
747
+ $list['wp_get_like'] = __( 'Liked Content', WP_ULIKE_SLUG );
748
+ $list['wp_add_unlike'] = __( 'Unliking Content', WP_ULIKE_SLUG );
749
+ $list['wp_get_unlike'] = __( 'Unliked Content', WP_ULIKE_SLUG );
750
+ return $list;
751
  }
752
+ add_filter( 'mycred_all_references', 'wp_ulike_myCRED_references' );
753
  }
754
 
755
  // Ultimate Member plugin
756
+ if( ! function_exists( 'wp_ulike_add_custom_profile_tab' ) ){
757
+ /**
758
+ * Add custom tabs in the UltimateMember profiles.
759
+ *
760
+ * @since 2.3
761
+ * @param array $tabs
762
+ * @return array $tabs
763
+ */
764
+ function wp_ulike_add_custom_profile_tab( $tabs ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
765
 
766
+ $tabs['wp-ulike-posts'] = array(
767
+ 'name' => __('Recent Posts Liked',WP_ULIKE_SLUG),
768
+ 'icon' => 'um-faicon-thumbs-up',
769
+ );
 
770
 
771
+ $tabs['wp-ulike-comments'] = array(
772
+ 'name' => __('Recent Comments Liked',WP_ULIKE_SLUG),
773
+ 'icon' => 'um-faicon-thumbs-o-up',
774
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
775
 
776
+ return $tabs;
 
777
  }
778
+ add_filter('um_profile_tabs', 'wp_ulike_add_custom_profile_tab', 1000 );
779
+ }
780
 
781
+ if( ! function_exists( 'wp_ulike_posts_um_profile_content' ) ){
782
+ /**
783
+ * Add content to the wp-ulike-posts tab
784
+ *
785
+ * @since 2.3
786
+ * @param array $args
787
+ * @return void
788
+ */
789
+ function wp_ulike_posts_um_profile_content() {
790
+ //Main data
791
+ $args = array(
792
+ "type" => 'post',
793
+ "rel_type" => 'post',
794
+ "status" => 'like',
795
+ "user_id" => um_profile_id(),
796
+ "is_popular" => false,
797
+ "limit" => 10
798
+ );
799
+
800
+ $get_items = wp_ulike_get_popular_items_ids( $args );
801
+
802
+ $query_args = array(
803
+ 'post__in' => $get_items,
804
+ 'orderby' => 'post__in',
805
+ 'posts_per_page' => $args['limit']
806
+ );
807
+
808
+ $query = new WP_Query( $query_args );
809
+
810
+ if( $query->have_posts() ):
811
+ while( $query->have_posts() ): $query->the_post();
812
+ echo '<div class="um-item">';
813
+ echo '<div class="um-item-link">
814
+ <i class="um-icon-ios-paper"></i>
815
+ <a href="'.get_permalink().'">'.get_the_title().'</a>
816
+ </div>';
817
+ echo '<div class="um-item-meta">
818
+ <span>'.get_the_date().'</span>
819
+ <span class="badge"><i class="um-faicon-thumbs-o-up"></i> '.wp_ulike_get_post_likes( get_the_ID() ).'</span>
820
+ </div>';
821
+ echo '</div>';
822
+ endwhile;
823
+ else:
824
+ echo '<div style="display: block;" class="um-profile-note"><i class="um-faicon-frown-o"></i><span>'. __('This user has not made any likes.',WP_ULIKE_SLUG).'</span></div>';
825
+ endif;
826
+ wp_reset_postdata();
827
 
828
+ }
829
+ add_action('um_profile_content_wp-ulike-posts_default', 'wp_ulike_posts_um_profile_content');
830
+ }
 
 
831
 
832
+ if( ! function_exists( 'wp_ulike_comments_um_profile_content' ) ){
833
+ /**
834
+ * Add content to the wp-ulike-comments tab
835
+ *
836
+ * @since 2.3
837
+ * @param array $args
838
+ * @return void
839
+ */
840
+ function wp_ulike_comments_um_profile_content() {
841
+ //Main data
842
+ $args = array(
843
+ "type" => 'comment',
844
+ "rel_type" => '',
845
+ "status" => 'like',
846
+ "user_id" => um_profile_id(),
847
+ "is_popular" => false,
848
+ "limit" => 10
849
+ );
850
+
851
+ $get_items = wp_ulike_get_popular_items_ids( $args );
852
+
853
+ $query_args = array(
854
+ 'comment__in' => $get_items,
855
+ 'orderby' => 'comment__in',
856
+ 'posts_per_page' => $args['limit']
857
+ );
858
+
859
+ // The Query
860
+ $comments_query = new WP_Comment_Query;
861
+ $comments = $comments_query->query( $query_args );
862
+
863
+ // Comment Loop
864
+ if ( $comments ) {
865
+ foreach ( $comments as $comment ) {
866
+ echo '<div class="um-item">';
867
+ echo '<div class="um-item-link">
868
+ <i class="um-icon-ios-chatboxes"></i>
869
+ <a href="'.get_comment_link($comment->comment_ID).'">'.$comment->comment_content .'</a>
870
+ <em style="font-size:.7em;padding:0 10px;"><span class="um-faicon-quote-left"></span> '.$comment->comment_author.' <span class="um-faicon-quote-right"></span></em>
871
+ </div>';
872
+ echo '<div class="um-item-meta">
873
+ <span>'.get_comment_date( '', $comment->comment_ID ).'</span>
874
+ <span class="badge"><i class="um-faicon-thumbs-o-up"></i> '.wp_ulike_get_comment_likes( $comment->comment_ID ).'</span>
875
+ </div>';
876
+ echo '</div>';
877
+ }
878
+ } else {
879
+ echo '<div style="display: block;" class="um-profile-note"><i class="um-faicon-frown-o"></i><span>'. __('This user has not made any likes.',WP_ULIKE_SLUG).'</span></div>';
880
  }
 
881
  }
882
+ add_action('um_profile_content_wp-ulike-comments_default', 'wp_ulike_comments_um_profile_content');
883
  }
readme.txt CHANGED
@@ -6,7 +6,7 @@ Tags: like, marketing, elementor, favorite, statistics, multisite, rating, votin
6
  Requires PHP: 5.6
7
  Requires at least: 5.0
8
  Tested up to: 5.4.2
9
- Stable tag: 4.3.0
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -152,6 +152,9 @@ define( 'WP_MEMORY_LIMIT', '256M' );
152
 
153
  == Changelog ==
154
 
 
 
 
155
  = 4.3.0 =
156
  * Added: ‌New php classification for front-end processes.
157
  * Added: Comment meta box options. [PRO]
6
  Requires PHP: 5.6
7
  Requires at least: 5.0
8
  Tested up to: 5.4.2
9
+ Stable tag: 4.3.1
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
152
 
153
  == Changelog ==
154
 
155
+ = 4.3.1 =
156
+ * Fixed: Third-party plugin issues.
157
+
158
  = 4.3.0 =
159
  * Added: ‌New php classification for front-end processes.
160
  * Added: Comment meta box options. [PRO]
wp-ulike.php CHANGED
@@ -10,7 +10,7 @@
10
  * Plugin Name: WP ULike
11
  * Plugin URI: https://wpulike.com/?utm_source=wp-plugins&utm_campaign=plugin-uri&utm_medium=wp-dash
12
  * Description: WP ULike plugin allows to integrate a beautiful Ajax Like Button into your wordPress website to allow your visitors to like and unlike pages, posts, comments AND buddypress activities. Its very simple to use and supports many options.
13
- * Version: 4.3.0
14
  * Author: Ali Mirzaei
15
  * Author URI: https://wpulike.com/?utm_source=wp-plugins&utm_campaign=author-uri&utm_medium=wp-dash
16
  * Text Domain: wp-ulike
@@ -46,7 +46,7 @@ if ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) {
46
 
47
  // Do not change these values
48
  define( 'WP_ULIKE_PLUGIN_URI' , 'https://wpulike.com/' );
49
- define( 'WP_ULIKE_VERSION' , '4.3.0' );
50
  define( 'WP_ULIKE_DB_VERSION' , '2.1' );
51
  define( 'WP_ULIKE_SLUG' , 'wp-ulike' );
52
  define( 'WP_ULIKE_NAME' , __( 'WP ULike', WP_ULIKE_SLUG ));
10
  * Plugin Name: WP ULike
11
  * Plugin URI: https://wpulike.com/?utm_source=wp-plugins&utm_campaign=plugin-uri&utm_medium=wp-dash
12
  * Description: WP ULike plugin allows to integrate a beautiful Ajax Like Button into your wordPress website to allow your visitors to like and unlike pages, posts, comments AND buddypress activities. Its very simple to use and supports many options.
13
+ * Version: 4.3.1
14
  * Author: Ali Mirzaei
15
  * Author URI: https://wpulike.com/?utm_source=wp-plugins&utm_campaign=author-uri&utm_medium=wp-dash
16
  * Text Domain: wp-ulike
46
 
47
  // Do not change these values
48
  define( 'WP_ULIKE_PLUGIN_URI' , 'https://wpulike.com/' );
49
+ define( 'WP_ULIKE_VERSION' , '4.3.1' );
50
  define( 'WP_ULIKE_DB_VERSION' , '2.1' );
51
  define( 'WP_ULIKE_SLUG' , 'wp-ulike' );
52
  define( 'WP_ULIKE_NAME' , __( 'WP ULike', WP_ULIKE_SLUG ));