Advertisement
designbymerovingi

BP Bookmark hook

Aug 16th, 2016
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. /**
  2. * Register Hook
  3. * @since 0.1
  4. * @version 1.0.1
  5. */
  6. add_filter( 'mycred_setup_hooks', 'mycred_register_bookmark_hook', 40 );
  7. function mycred_register_bookmark_hook( $installed )
  8. {
  9. $installed['hook_bookmark'] = array(
  10. 'title' => __( 'Bookmark', 'mycred' ),
  11. 'description' => __( 'Awards %_plural% for bookmarking a site.', 'mycred' ),
  12. 'callback' => array( 'myCRED_BP_Bookmarks' )
  13. );
  14. }
  15.  
  16. return $installed;
  17.  
  18. }
  19.  
  20. /**
  21. * myCRED_BP_Bookmarks class
  22. * Creds for bookmarks
  23. * @since 0.1
  24. * @version 1.3
  25. */
  26. add_action( 'mycred_load_hooks', 'mycred_load_bookmark_hook', 40 );
  27. function mycred_load_bookmark_hook() {
  28.  
  29. // myCRED Custom Hook Class
  30. class myCRED_BP_Bookmarks extends myCRED_Hook {
  31.  
  32. /**
  33. * Construct
  34. */
  35. function __construct( $hook_prefs, $type = 'mycred_default' ) {
  36.  
  37. parent::__construct( array(
  38. 'id' => 'hook_bookmark',
  39. 'defaults' => array(
  40. 'bookmark' => array(
  41. 'creds' => 1,
  42. 'log' => '%plural% for bookmarking a site',
  43. 'limit' => '0/x'
  44. )
  45. )
  46. ), $hook_prefs, $type );
  47.  
  48. }
  49.  
  50. /**
  51. * Run
  52. * @since 0.1
  53. * @version 1.0
  54. */
  55. public function run() {
  56.  
  57. if ( $this->prefs['bookmark']['creds'] != 0 )
  58. add_action( 'bp_activity_bookmark_published', array( $this, 'bookmarks' ), 10, 3 );
  59.  
  60. }
  61.  
  62. /**
  63. * New Bookmark
  64. * @since 0.1
  65. * @version 1.2
  66. */
  67. public function new_bookmark( $content, $user_id, $activity_id ) {
  68.  
  69. // Check if user is excluded
  70. if ( $this->core->exclude_user( $user_id ) ) return;
  71.  
  72. // Limit
  73. if ( $this->over_hook_limit( 'bookmark', 'new_bookmark', $user_id ) ) return;
  74.  
  75. // Make sure this is unique event
  76. if ( $this->core->has_entry( 'new_bookmark', $activity_id, $user_id ) ) return;
  77.  
  78. // Execute
  79. $this->core->add_creds(
  80. 'new_bookmark',
  81. $user_id,
  82. $this->prefs['bookmark']['creds'],
  83. $this->prefs['bookmark']['log'],
  84. $activity_id,
  85. 'bp_activity',
  86. $this->mycred_type
  87. );
  88.  
  89. }
  90.  
  91.  
  92. /**
  93. * Preferences
  94. * @since 0.1
  95. * @version 1.2
  96. */
  97. public function preferences() {
  98.  
  99. $prefs = $this->prefs;
  100.  
  101. ?>
  102. <!-- Creds for Bookmark -->
  103. <label for="<?php echo $this->field_id( array( 'bookmark', 'creds' ) ); ?>" class="subheader"><?php _e( 'New Bookmark', 'mycred' ); ?></label>
  104. <ol>
  105. <li>
  106. <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'bookmark', 'creds' ) ); ?>" id="<?php echo $this->field_id( array( 'bookmark', 'creds' ) ); ?>" value="<?php echo $this->core->number( $prefs['bookmark']['creds'] ); ?>" size="8" /></div>
  107. </li>
  108. <li>
  109. <label for="<?php echo $this->field_id( array( 'bookmark', 'limit' ) ); ?>"><?php _e( 'Limit', 'mycred' ); ?></label>
  110. <?php echo $this->hook_limit_setting( $this->field_name( array( 'bookmark', 'limit' ) ), $this->field_id( array( 'bookmark', 'limit' ) ), $prefs['bookmark']['limit'] ); ?>
  111. </li>
  112. <li class="empty">&nbsp;</li>
  113. <li>
  114. <label for="<?php echo $this->field_id( array( 'bookmark', 'log' ) ); ?>"><?php _e( 'Log template', 'mycred' ); ?></label>
  115. <div class="h2"><input type="text" name="<?php echo $this->field_name( array( 'bookmark', 'log' ) ); ?>" id="<?php echo $this->field_id( array( 'bookmark', 'log' ) ); ?>" value="<?php echo esc_attr( $prefs['bookmark']['log'] ); ?>" class="long" /></div>
  116. <span class="description"><?php echo $this->available_template_tags( array( 'general' ) ); ?></span>
  117. </li>
  118. </ol>
  119.  
  120. <?php
  121.  
  122. }
  123.  
  124. /**
  125. * Sanitise Preferences
  126. * @since 1.6
  127. * @version 1.1
  128. */
  129. function sanitise_preferences( $data ) {
  130.  
  131. if ( isset( $data['bookmark']['limit'] ) && isset( $data['bookmark']['limit_by'] ) ) {
  132. $limit = sanitize_text_field( $data['bookmark']['limit'] );
  133. if ( $limit == '' ) $limit = 0;
  134. $data['bookmark']['limit'] = $limit . '/' . $data['bookmark']['limit_by'];
  135. unset( $data['bookmark']['limit_by'] );
  136. }
  137.  
  138. return $data;
  139.  
  140. }
  141.  
  142. }
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement