myCRED - Version 1.0.9.2

Version Description

  • Fixed Bug #22 - BadgeOS Badge ID issue. Critical for BadgeOS users!
  • Adjusted plugin to handle custom features when adjusting a users points balance.
  • Added function to handle Post/User/Comment deletions for the log.
  • Renamed the update_users_creds method to a more logical choice of update_users_balance.
Download this release

Release Info

Developer designbymerovingi
Plugin Icon 128x128 myCRED
Version 1.0.9.2
Comparing to
See all releases

Code changes from version 1.0.9.1 to 1.0.9.2

addons/import/myCRED-addon-import.php CHANGED
@@ -174,7 +174,7 @@ if ( !class_exists( 'myCRED_Import' ) ) {
174
  }
175
 
176
  // Adjust Balance
177
- $new_balance = $this->core->update_users_cred( $user_id, $cred );
178
 
179
  // Log (if requested with the import file having top priority)
180
  if ( ( isset( $row['mycred_log'] ) && !empty( $row['mycred_log'] ) ) || !empty( $log_template ) ) {
174
  }
175
 
176
  // Adjust Balance
177
+ $new_balance = $this->core->update_users_balance( $user_id, $cred );
178
 
179
  // Log (if requested with the import file having top priority)
180
  if ( ( isset( $row['mycred_log'] ) && !empty( $row['mycred_log'] ) ) || !empty( $log_template ) ) {
includes/mycred-functions.php CHANGED
@@ -4,7 +4,7 @@ if ( !defined( 'myCRED_VERSION' ) ) exit;
4
  * myCRED_Settings class
5
  * @see http://mycred.me/classes/mycred_settings/
6
  * @since 0.1
7
- * @version 1.0
8
  */
9
  if ( !class_exists( 'myCRED_Settings' ) ) {
10
  class myCRED_Settings {
@@ -296,7 +296,19 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
296
  $post = get_post( $ref_id );
297
 
298
  // Post does not exist
299
- if ( $post === NULL ) return $content;
 
 
 
 
 
 
 
 
 
 
 
 
300
 
301
  // Let others play first
302
  $content = apply_filters( 'mycred_parse_tags_post', $content, $data, $post );
@@ -304,12 +316,14 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
304
 
305
  // Replace template tags
306
  $content = str_replace( '%post_title%', $post->post_title, $content );
307
- $content = str_replace( '%post_url%', get_permalink( $post->ID ), $content );
308
- $content = str_replace( '%link_with_title%', '<a href="' . get_permalink( $post->ID ) . '">' . $post->post_title . '</a>', $content );
309
 
310
  $post_type = get_post_type_object( $post->post_type );
311
- $content = str_replace( '%post_type%', $post_type->labels->singular_name, $content );
312
- unset( $post_type );
 
 
313
 
314
  //$content = str_replace( '', $post->, $content );
315
  unset( $post );
@@ -335,7 +349,13 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
335
  $user = get_userdata( $ref_id );
336
 
337
  // User does not exist
338
- if ( $user === false ) return $content;
 
 
 
 
 
 
339
 
340
  // Let others play first
341
  $content = apply_filters( 'mycred_parse_tags_user', $content, $data, $user );
@@ -382,19 +402,34 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
382
  $comment = get_comment( $ref_id );
383
 
384
  // Comment does not exist
385
- if ( $comment === NULL ) return $content;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
386
 
387
  // Let others play first
388
  $content = apply_filters( 'mycred_parse_tags_comment', $content, $data, $comment );
389
  $content = $this->template_tags_general( $content );
390
 
391
- $content = str_replace( '%comment_id%', $comment->comment_ID, $content );
392
 
393
  $content = str_replace( '%c_post_id%', $comment->comment_post_ID, $content );
394
- $content = str_replace( '%c_post_title%', get_the_title( $comment->comment_post_ID ), $content );
395
 
396
- $content = str_replace( '%c_post_url%', get_permalink( $comment->comment_post_ID ), $content );
397
- $content = str_replace( '%c_link_with_title%', '<a href="' . get_permalink( $comment->comment_post_ID ) . '">' . get_the_title( $comment->comment_post_ID ) . '</a>', $content );
398
 
399
  //$content = str_replace( '', $comment->, $content );
400
  unset( $comment );
@@ -597,7 +632,7 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
597
  }
598
 
599
  /**
600
- * Update users creds
601
  * Returns the updated balance of the given user.
602
  *
603
  * @param $user_id (int), required user id
@@ -606,7 +641,7 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
606
  * @since 0.1
607
  * @version 1.0
608
  */
609
- public function update_users_cred( $user_id = NULL, $amount = NULL ) {
610
  if ( $user_id === NULL || $amount === NULL ) return $amount;
611
  if ( empty( $this->cred_id ) ) $this->cred_id = $this->get_cred_id();
612
 
@@ -638,7 +673,7 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
638
  * @param $type (string), optional point name, defaults to 'mycred_default'
639
  * @returns boolean true on success or false on fail
640
  * @since 0.1
641
- * @version 1.0
642
  */
643
  public function add_creds( $ref = '', $user_id = '', $amount = '', $entry = '', $ref_id = '', $data = '', $type = 'mycred_default' ) {
644
  // All the reasons we would fail
@@ -649,16 +684,26 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
649
  // Format creds
650
  $amount = $this->number( $amount );
651
 
652
- // Adjust creds
653
- $new_balance = $this->update_users_cred( $user_id, $amount );
654
-
655
- // Let others play
656
- $request = compact( 'ref', 'amount', 'entry', 'ref_id', 'data', 'type', 'user_id', 'current_balance', 'new_balance' );
657
- do_action( 'mycred_add', $request, $this->core );
658
-
659
- // Add log entry
660
- $this->add_to_log( $ref, $user_id, $amount, $entry, $ref_id, $data, $type );
661
- return true;
 
 
 
 
 
 
 
 
 
 
662
  }
663
 
664
  /**
@@ -700,7 +745,7 @@ if ( !class_exists( 'myCRED_Settings' ) ) {
700
  array(
701
  'ref' => $ref,
702
  'ref_id' => $ref_id,
703
- 'user_id' => $user_id,
704
  'creds' => $amount,
705
  'ctype' => $type,
706
  'time' => date_i18n( 'U' ),
4
  * myCRED_Settings class
5
  * @see http://mycred.me/classes/mycred_settings/
6
  * @since 0.1
7
+ * @version 1.1
8
  */
9
  if ( !class_exists( 'myCRED_Settings' ) ) {
10
  class myCRED_Settings {
296
  $post = get_post( $ref_id );
297
 
298
  // Post does not exist
299
+ if ( $post === NULL ) {
300
+ if ( !array_key_exists( 'ID', $data ) ) return $content;
301
+ $post = new StdClass();
302
+ foreach ( $data as $key => $value ) {
303
+ if ( $key == 'post_title' ) $value .= ' (' . __( 'Deleted', 'mycred' ) . ')';
304
+ $post->$key = $value;
305
+ }
306
+ $url = get_permalink( $post->ID );
307
+ if ( empty( $url ) ) $url = '#item-has-been-deleted';
308
+ }
309
+ else {
310
+ $url = get_permalink( $post->ID );
311
+ }
312
 
313
  // Let others play first
314
  $content = apply_filters( 'mycred_parse_tags_post', $content, $data, $post );
316
 
317
  // Replace template tags
318
  $content = str_replace( '%post_title%', $post->post_title, $content );
319
+ $content = str_replace( '%post_url%', $url, $content );
320
+ $content = str_replace( '%link_with_title%', '<a href="' . $url . '">' . $post->post_title . '</a>', $content );
321
 
322
  $post_type = get_post_type_object( $post->post_type );
323
+ if ( $post_type !== NULL ) {
324
+ $content = str_replace( '%post_type%', $post_type->labels->singular_name, $content );
325
+ unset( $post_type );
326
+ }
327
 
328
  //$content = str_replace( '', $post->, $content );
329
  unset( $post );
349
  $user = get_userdata( $ref_id );
350
 
351
  // User does not exist
352
+ if ( $user === false ) {
353
+ if ( !array_key_exists( 'ID', $data ) ) return $content;
354
+ $user = new StdClass();
355
+ foreach ( $data as $key => $value ) {
356
+ $user->$key = $value;
357
+ }
358
+ }
359
 
360
  // Let others play first
361
  $content = apply_filters( 'mycred_parse_tags_user', $content, $data, $user );
402
  $comment = get_comment( $ref_id );
403
 
404
  // Comment does not exist
405
+ if ( $comment === NULL ) {
406
+ if ( !array_key_exists( 'comment_ID', $data ) ) return $content;
407
+ $comment = new StdClass();
408
+ foreach ( $data as $key => $value ) {
409
+ $comment->$key = $value;
410
+ }
411
+ $url = get_permalink( $comment->comment_post_ID );
412
+ if ( empty( $url ) ) $url = '#item-has-been-deleted';
413
+
414
+ $title = get_the_title( $comment->comment_post_ID );
415
+ if ( empty( $title ) ) $title = __( 'Deleted Item', 'mycred' );
416
+ }
417
+ else {
418
+ $url = get_permalink( $comment->comment_post_ID );
419
+ $title = get_the_title( $comment->comment_post_ID );
420
+ }
421
 
422
  // Let others play first
423
  $content = apply_filters( 'mycred_parse_tags_comment', $content, $data, $comment );
424
  $content = $this->template_tags_general( $content );
425
 
426
+ $content = str_replace( '%comment_id%', $comment->comment_ID, $content );
427
 
428
  $content = str_replace( '%c_post_id%', $comment->comment_post_ID, $content );
429
+ $content = str_replace( '%c_post_title%', $title, $content );
430
 
431
+ $content = str_replace( '%c_post_url%', $url, $content );
432
+ $content = str_replace( '%c_link_with_title%', '<a href="' . $url . '">' . $title . '</a>', $content );
433
 
434
  //$content = str_replace( '', $comment->, $content );
435
  unset( $comment );
632
  }
633
 
634
  /**
635
+ * Update users balance
636
  * Returns the updated balance of the given user.
637
  *
638
  * @param $user_id (int), required user id
641
  * @since 0.1
642
  * @version 1.0
643
  */
644
+ public function update_users_balance( $user_id = NULL, $amount = NULL ) {
645
  if ( $user_id === NULL || $amount === NULL ) return $amount;
646
  if ( empty( $this->cred_id ) ) $this->cred_id = $this->get_cred_id();
647
 
673
  * @param $type (string), optional point name, defaults to 'mycred_default'
674
  * @returns boolean true on success or false on fail
675
  * @since 0.1
676
+ * @version 1.1
677
  */
678
  public function add_creds( $ref = '', $user_id = '', $amount = '', $entry = '', $ref_id = '', $data = '', $type = 'mycred_default' ) {
679
  // All the reasons we would fail
684
  // Format creds
685
  $amount = $this->number( $amount );
686
 
687
+ // Execution Override
688
+ // Let others play before awarding points.
689
+ // Your functions should return the answer to the question: "Should myCRED adjust the users point balance?"
690
+ $execute = apply_filters( 'mycred_add', true, compact( 'ref', 'user_id', 'amount', 'entry', 'ref_id', 'data', 'type' ), $this );
691
+
692
+ // Acceptable answers:
693
+ // true (boolean) - "Yes" let myCRED add points and log the event
694
+ if ( $execute === true ) {
695
+ $this->update_users_balance( $user_id, $amount );
696
+ $this->add_to_log( $ref, $user_id, $amount, $entry, $ref_id, $data, $type );
697
+ return true;
698
+ }
699
+ // done (string) - "Already done"
700
+ elseif ( $execute === 'done' ) {
701
+ return true;
702
+ }
703
+ // false (boolean) - "No"
704
+ else {
705
+ return false;
706
+ }
707
  }
708
 
709
  /**
745
  array(
746
  'ref' => $ref,
747
  'ref_id' => $ref_id,
748
+ 'user_id' => (int) $user_id,
749
  'creds' => $amount,
750
  'ctype' => $type,
751
  'time' => date_i18n( 'U' ),
modules/mycred-module-hooks.php CHANGED
@@ -1298,7 +1298,7 @@ if ( !class_exists( 'myCRED_Hook_BadgeOS' ) && class_exists( 'BadgeOS' ) ) {
1298
  $user_id,
1299
  $achievement_data['creds'],
1300
  $achievement_data['log'],
1301
- $post_type,
1302
  array( 'ref_type' => 'post' )
1303
  );
1304
  }
@@ -1329,7 +1329,7 @@ if ( !class_exists( 'myCRED_Hook_BadgeOS' ) && class_exists( 'BadgeOS' ) ) {
1329
  $user_id,
1330
  0-$achievement_data['creds'],
1331
  $achievement_data['deduct_log'],
1332
- $post_type,
1333
  array( 'ref_type' => 'post' )
1334
  );
1335
  }
1298
  $user_id,
1299
  $achievement_data['creds'],
1300
  $achievement_data['log'],
1301
+ $achievement_id,
1302
  array( 'ref_type' => 'post' )
1303
  );
1304
  }
1329
  $user_id,
1330
  0-$achievement_data['creds'],
1331
  $achievement_data['deduct_log'],
1332
+ $achievement_id,
1333
  array( 'ref_type' => 'post' )
1334
  );
1335
  }
modules/mycred-module-log.php CHANGED
@@ -39,6 +39,11 @@ if ( !class_exists( 'myCRED_Log' ) ) {
39
  add_filter( 'set-screen-option', array( $this, 'set_entries_per_page' ), 10, 3 );
40
  add_action( 'mycred_add_menu', array( $this, 'my_history_menu' ) );
41
  add_shortcode( 'mycred_history', array( $this, 'render_my_history' ) );
 
 
 
 
 
42
  }
43
 
44
  /**
@@ -488,6 +493,129 @@ if ( !class_exists( 'myCRED_Log' ) ) {
488
 
489
  return $log->get_display();
490
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
491
  }
492
  }
493
  /**
39
  add_filter( 'set-screen-option', array( $this, 'set_entries_per_page' ), 10, 3 );
40
  add_action( 'mycred_add_menu', array( $this, 'my_history_menu' ) );
41
  add_shortcode( 'mycred_history', array( $this, 'render_my_history' ) );
42
+
43
+ // Handle deletions
44
+ add_action( 'before_delete_post', array( $this, 'post_deletions' ) );
45
+ add_action( 'delete_user', array( $this, 'user_deletions' ) );
46
+ add_action( 'delete_comment', array( $this, 'comment_deletions' ) );
47
  }
48
 
49
  /**
493
 
494
  return $log->get_display();
495
  }
496
+
497
+ /**
498
+ * Handle Post Deletions
499
+ * @since 1.0.9.2
500
+ * @version 1.0
501
+ */
502
+ public function post_deletions( $post_id ) {
503
+ global $post_type, $wpdb;
504
+ // Check log
505
+ $sql = "SELECT * FROM " . $wpdb->prefix . 'myCRED_log' . " WHERE ref_id = %d ";
506
+ $records = $wpdb->get_results( $wpdb->prepare( $sql, $post_id ) );
507
+ // If we have results
508
+ if ( $wpdb->num_rows > 0 ) {
509
+ // Loop though them
510
+ foreach ( $records as $row ) {
511
+ // Check if the data column has a serialized array
512
+ $check = @unserialize( $row->data );
513
+ if ( $check !== false && $row->data !== 'b:0;' ) {
514
+ // Unserialize
515
+ $data = unserialize( $row->data );
516
+ // If this is a post
517
+ if (
518
+ ( isset( $data['ref_type'] ) && $data['ref_type'] == 'post' ) ||
519
+ ( isset( $data['post_type'] ) && $post_type == $data['post_type'] )
520
+ ) {
521
+ // If the entry is blank continue on to the next
522
+ if ( trim( $row->entry ) === '' ) continue;
523
+ // Construct a new data array
524
+ $new_data = array( 'ref_type' => 'post' );
525
+ // Add details that will no longer be available
526
+ $post = get_post( $post_id );
527
+ $new_data['ID'] = $post->ID;
528
+ $new_data['post_title'] = $post->post_title;
529
+ $new_data['post_type'] = $post->post_type;
530
+ // Save
531
+ $wpdb->update(
532
+ $wpdb->prefix . 'myCRED_log',
533
+ array( 'data' => serialize( $new_data ) ),
534
+ array( 'id' => $row->id ),
535
+ array( '%s' ),
536
+ array( '%d' )
537
+ );
538
+ }
539
+ }
540
+ }
541
+ }
542
+ }
543
+
544
+ /**
545
+ * Handle User Deletions
546
+ * @since 1.0.9.2
547
+ * @version 1.0
548
+ */
549
+ public function user_deletions( $user_id ) {
550
+ global $wpdb;
551
+ // Check log
552
+ $sql = "SELECT * FROM " . $wpdb->prefix . 'myCRED_log' . " WHERE user_id = %d ";
553
+ $records = $wpdb->get_results( $wpdb->prepare( $sql, $user_id ) );
554
+ // If we have results
555
+ if ( $wpdb->num_rows > 0 ) {
556
+ // Loop though them
557
+ foreach ( $records as $row ) {
558
+ // Construct a new data array
559
+ $new_data = array( 'ref_type' => 'user' );
560
+ // Add details that will no longer be available
561
+ $user = get_userdata( $user_id );
562
+ $new_data['ID'] = $user->ID;
563
+ $new_data['login'] = $user->user_login;
564
+ $new_data['display_name'] = $user->display_name;
565
+ // Save
566
+ $wpdb->update(
567
+ $wpdb->prefix . 'myCRED_log',
568
+ array( 'data' => serialize( $new_data ) ),
569
+ array( 'id' => $row->id ),
570
+ array( '%s' ),
571
+ array( '%d' )
572
+ );
573
+ }
574
+ }
575
+ }
576
+
577
+ /**
578
+ * Handle Comment Deletions
579
+ * @since 1.0.9.2
580
+ * @version 1.0
581
+ */
582
+ public function comment_deletions( $comment_id ) {
583
+ global $wpdb;
584
+ // Check log
585
+ $sql = "SELECT * FROM " . $wpdb->prefix . 'myCRED_log' . " WHERE ref_id = %d ";
586
+ $records = $wpdb->get_results( $wpdb->prepare( $sql, $comment_id ) );
587
+ // If we have results
588
+ if ( $wpdb->num_rows > 0 ) {
589
+ // Loop though them
590
+ foreach ( $records as $row ) {
591
+ // Check if the data column has a serialized array
592
+ $check = @unserialize( $row->data );
593
+ if ( $check !== false && $row->data !== 'b:0;' ) {
594
+ // Unserialize
595
+ $data = unserialize( $row->data );
596
+ // If this is a post
597
+ if ( isset( $data['ref_type'] ) && $data['ref_type'] == 'comment' ) {
598
+ // If the entry is blank continue on to the next
599
+ if ( trim( $row->entry ) === '' ) continue;
600
+ // Construct a new data array
601
+ $new_data = array( 'ref_type' => 'comment' );
602
+ // Add details that will no longer be available
603
+ $comment = get_comment( $comment_id );
604
+ $new_data['comment_ID'] = $comment->comment_ID;
605
+ $new_data['comment_post_ID'] = $comment->comment_post_ID;
606
+ // Save
607
+ $wpdb->update(
608
+ $wpdb->prefix . 'myCRED_log',
609
+ array( 'data' => serialize( $new_data ) ),
610
+ array( 'id' => $row->id ),
611
+ array( '%s' ),
612
+ array( '%d' )
613
+ );
614
+ }
615
+ }
616
+ }
617
+ }
618
+ }
619
  }
620
  }
621
  /**
mycred.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: myCRED
4
  Plugin URI: http://mycred.me
5
  Description: <strong>my</strong>CRED is an adaptive points management system for WordPress powered websites, giving you full control on how points are gained, used, traded, managed, logged or presented.
6
- Version: 1.0.9.1
7
  Tags: points, tokens, credit, management, reward, charge
8
  Author: Gabriel S Merovingi
9
  Author URI: http://www.merovingi.com
@@ -13,7 +13,7 @@ Tested up to: WP 3.5.1
13
  License: GPLv2 or later
14
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
15
  */
16
- define( 'myCRED_VERSION', '1.0.9.1' );
17
  define( 'myCRED_SLUG', 'mycred' );
18
 
19
  define( 'myCRED_THIS', __FILE__ );
3
  Plugin Name: myCRED
4
  Plugin URI: http://mycred.me
5
  Description: <strong>my</strong>CRED is an adaptive points management system for WordPress powered websites, giving you full control on how points are gained, used, traded, managed, logged or presented.
6
+ Version: 1.0.9.2
7
  Tags: points, tokens, credit, management, reward, charge
8
  Author: Gabriel S Merovingi
9
  Author URI: http://www.merovingi.com
13
  License: GPLv2 or later
14
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
15
  */
16
+ define( 'myCRED_VERSION', '1.0.9.2' );
17
  define( 'myCRED_SLUG', 'mycred' );
18
 
19
  define( 'myCRED_THIS', __FILE__ );
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate Link: http://mycred.me/donate/
4
  Tags:points, tokens, credit, management, reward, charge, community, BuddyPress, Jetpack
5
  Requires at least: 3.1
6
  Tested up to: 3.5.1
7
- Stable tag: 1.0.9.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -122,6 +122,12 @@ Yes but if one of them is bought, all is shown. The mycred_sell_this shortcode w
122
 
123
  == Changelog ==
124
 
 
 
 
 
 
 
125
  = 1.0.9.1 =
126
  * Fixed Bug #17 - Shortcodes inside mycred_sell_this does not render.
127
  * Fixed Bug #18 - Pending posts that gets published by admin are not awarded points.
4
  Tags:points, tokens, credit, management, reward, charge, community, BuddyPress, Jetpack
5
  Requires at least: 3.1
6
  Tested up to: 3.5.1
7
+ Stable tag: 1.0.9.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
122
 
123
  == Changelog ==
124
 
125
+ = 1.0.9.2 =
126
+ * Fixed Bug #22 - BadgeOS Badge ID issue. Critical for BadgeOS users!
127
+ * Adjusted plugin to handle custom features when adjusting a users points balance.
128
+ * Added function to handle Post/User/Comment deletions for the log.
129
+ * Renamed the `update_users_creds` method to a more logical choice of `update_users_balance`.
130
+
131
  = 1.0.9.1 =
132
  * Fixed Bug #17 - Shortcodes inside mycred_sell_this does not render.
133
  * Fixed Bug #18 - Pending posts that gets published by admin are not awarded points.