Title: &quot;Likes&quot; Hook
Last modified: August 22, 2016

---

# "Likes" Hook

 *  [robint](https://wordpress.org/support/users/robint/)
 * (@robint)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/likes-hook/)
 * My site allows users to “Like” other peoples posts.
 * I was wondering how I can use this meta-key;
    _Likes Count
 * I’ve taken the “comment.php” hook and changed all to likes…but nothing is displaying
   in the “points hooks”
 *     ```
       <?php
   
       /**
        * The like points hook class.
        *
        * @package WordPoints\Points\Hooks
        * @since 1.4.0
        */
   
       // Register the like hook.
       WordPoints_Points_Hooks::register( 'WordPoints_Like_Points_Hook' );
   
       /**
        * Like points hook.
        *
        * This hook will award points when a user leaves a like.
        *
        * @since 1.0.0
        * @since 1.4.0 No longer subtracts points for like removal.
        * @since 1.8.0 Now extends WordPoints_Like_Approved_Points_Hook_Base.
        */
       class WordPoints_Like_Points_Hook extends WordPoints_Like_Approved_Points_Hook_Base {
   
       	/**
       	 * @since 1.8.0
       	 */
       	protected $log_type = 'like_approve';
   
       	/**
       	 * Initialize the hook.
       	 *
       	 * @since 1.0.0
       	 */
       	public function __construct() {
   
       		parent::__construct(
       			_x( 'Like', 'points hook name', 'wordpoints' )
       			, array(
       				'description' => __( 'Leaving a new like.', 'wordpoints' ),
       				/* translators: the post type name. */
       				'post_type_description' => __( 'Leaving a new like on a %s.', 'wordpoints' ),
       				/* translators: %s will be the post's title. */
       				'log_text_post_title' => _x( 'Like on %s.', 'points log description', 'wordpoints' ),
       				'log_text_no_post_title' => _x( 'Like', 'points log description', 'wordpoints' ),
       				/* translators: %s is the name of a post type. */
       				'log_text_post_type' => _x( 'Like on a %s.', 'points log description', 'wordpoints' ),
       				/* translators: %s will be the post's title. */
       				'log_text_post_title_reverse' => _x( 'Like on %s removed.', 'points log description', 'wordpoints' ),
       				'log_text_no_post_title_reverse' => _x( 'Like removed.', 'points log description', 'wordpoints' ),
       				/* translators: %s is the name of a post type. */
       				'log_text_post_type_reverse' => _x( 'Like on a %s removed.', 'points log description', 'wordpoints' ),
       				'last_status_meta_key' => 'wordpoints_last_status',
       			)
       		);
   
       		if ( get_site_option( 'wordpoints_like_hook_legacy' ) ) {
       			$this->set_option(
       				'disable_auto_reverse_label'
       				, __( 'Revoke the points if the like is removed.', 'wordpoints' )
       			);
       		}
       	}
   
       	/**
       	 * Generate the log entry for an approve like transaction.
       	 *
       	 * @since 1.0.0
       	 * @deprecated 1.8.0 Use self::logs() instead.
       	 *
       	 * @param string $text        The text for the log entry.
       	 * @param int    $points      The number of points.
       	 * @param string $points_type The type of points for the transaction.
       	 * @param int    $user_id     The affected user's ID.
       	 * @param string $log_type    The type of transaction.
       	 * @param array  $meta        Transaction meta data.
       	 *
       	 * @return string
       	 */
       	public function approve_logs( $text, $points, $points_type, $user_id, $log_type, $meta ) {
   
       		_deprecated_function( __METHOD__, '1.8.0', __CLASS__ . '::logs()' );
   
       		return $this->logs( $text, $points, $points_type, $user_id, $log_type, $meta );
       	}
   
       	/**
       	 * Generate the log entry for a disapprove like transaction.
       	 *
       	 * @since 1.0.0
       	 * @deprecated 1.4.0
       	 * @deprecated Use wordpoints_points_logs_like_disapprove() instead.
       	 *
       	 * @param string $text        The text for the log entry.
       	 * @param int    $points      The number of points.
       	 * @param string $points_type The type of points for the transaction.
       	 * @param int    $user_id     The affected user's ID.
       	 * @param string $log_type    The type of transaction.
       	 * @param array  $meta        Transaction meta data.
       	 *
       	 * @return string
       	 */
       	public function disapprove_logs( $text, $points, $points_type, $user_id, $log_type, $meta ) {
   
       		_deprecated_function( __METHOD__, '1.4.0', 'wordpoints_points_logs_like_disapprove' );
   
       		return wordpoints_points_logs_like_disapprove(
       			$text
       			, $points
       			, $points_type
       			, $user_id
       			, $log_type
       			, $meta
       		);
       	}
   
       	/**
       	 * Check if points have already been awarded for a like.
       	 *
       	 * The behavior of this hook is to award points when a like has been approved,
       	 * given the following conditions:
       	 *
       	 * * No points have been awarded for the like yet, or
       	 * * The last status of the like where points were affected was not 'approved'
       	 *
       	 * This function was deprecated in 1.8.0 because of confusion surrounding its
       	 * name. It seems that it should only check a value in the database, but it goes
       	 * beyond that and updates the value in anticipation of points being awarded.
       	 * Because of this, strange things will happen if it is used more than once
       	 * and points haven't been awarded, because after the first time it is used in
       	 * such a case it will always return true.
       	 *
       	 * It is possible that this function would be resurected in a later version, with
       	 * this behavior corrected, but until then it should be avoided.
       	 *
       	 * @since 1.0.0
       	 * @deprecated 1.8.0
       	 *
       	 * @param int    $_Likes Count  The ID of a like.
       	 * @param string $points_type The points type to check.
       	 *
       	 * @return bool Whether points have been awarded.
       	 */
       	public function awarded_points_already( $_Likes Count, $points_type ) {
   
       		_deprecated_function( __METHOD__, '1.8.0' );
   
       		$meta_key = $this->get_last_status_like_meta_key( $points_type );
   
       		$last_status = get_like_meta( $_Likes Count, $meta_key, true );
   
       		if ( 'approved' !== $last_status ) {
   
       			update_likes_meta( $_Likes Count, $meta_key, 'approved', $last_status );
   
       			return false;
       		}
   
       		return true;
       	}
   
       } // class WordPoints_Like_Points_Hook
   
       // EOF
       ```
   
 * [https://wordpress.org/plugins/wordpoints/](https://wordpress.org/plugins/wordpoints/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [J.D. Grimes](https://wordpress.org/support/users/jdgrimes/)
 * (@jdgrimes)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/likes-hook/#post-5771680)
 * The reason why it isn’t working is because most of the important logic is provided
   by `WordPoints_Comment_Approved_Points_Hook_Base` (in `abstracts/comment-approved.
   php`).
 * If you let me know what plugin/theme you are using, I’ll consider creating a 
   module for the plugin that offers this feature.
 *  Thread Starter [robint](https://wordpress.org/support/users/robint/)
 * (@robint)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/likes-hook/#post-5771738)
 * Is there a way to email you? As I’d prefer not to make my comments public.
 * Robin 🙂
 *  Plugin Author [J.D. Grimes](https://wordpress.org/support/users/jdgrimes/)
 * (@jdgrimes)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/likes-hook/#post-5771746)
 * [https://wordpoints.org/contact/](https://wordpoints.org/contact/)
 *  Thread Starter [robint](https://wordpress.org/support/users/robint/)
 * (@robint)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/likes-hook/#post-5771748)
 * I’ve tried that , but for some reason when I click on “submit”
 * It says SSL error connection.
 * 🙁
 *  Plugin Author [J.D. Grimes](https://wordpress.org/support/users/jdgrimes/)
 * (@jdgrimes)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/likes-hook/#post-5771749)
 * Oops. Sorry about that. I’ve just changes some settings that should fix this.
   Could you try again?
 *  Thread Starter [robint](https://wordpress.org/support/users/robint/)
 * (@robint)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/likes-hook/#post-5771816)
 * Just seeing if you got an email?
    If the contact form doesn’t work is there anything
   else I could try to contact you.
 *  Plugin Author [J.D. Grimes](https://wordpress.org/support/users/jdgrimes/)
 * (@jdgrimes)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/likes-hook/#post-5771829)
 * No I didn’t get it. I guess I’ll have to find out what is wrong with my contact
   form. Meanwhile, you will find instructions to contact me here: [http://codesymphony.co/contact/](http://codesymphony.co/contact/)(
   or you can see if that contact form works).
 *  Thread Starter [robint](https://wordpress.org/support/users/robint/)
 * (@robint)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/likes-hook/#post-5771832)
 * Hey JD,
    Thank you. That one worked 😀
 *  [MathiasP](https://wordpress.org/support/users/mathiasp/)
 * (@mathiasp)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/likes-hook/#post-5772012)
 * Hey robint,
 * did you just get the Hook working well?
    I need to realize the same thing (see
   the newest topic in this support section)
 * Maybe you can help me with that?
 * Mathias

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘"Likes" Hook’ is closed to new replies.

 * ![](https://ps.w.org/wordpoints/assets/icon.svg?rev=1662380)
 * [WordPoints](https://wordpress.org/plugins/wordpoints/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpoints/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpoints/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpoints/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpoints/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpoints/reviews/)

 * 9 replies
 * 3 participants
 * Last reply from: [MathiasP](https://wordpress.org/support/users/mathiasp/)
 * Last activity: [10 years, 10 months ago](https://wordpress.org/support/topic/likes-hook/#post-5772012)
 * Status: not resolved