Advertisement
designbymerovingi

custom hook bp bookmark

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