WP Reactions Documentation WP Reactions Documentation
  • Knowledge Base 
  • Open a Ticket 
Ask a Question
WP Reactions Documentation WP Reactions Documentation
Ask a Question
WP Reactions Documentation
  • Knowledge Base 
  • Open a Ticket 

WP Reactions

  • folder icon closed folder iconGetting Started
    • Download WP Reactions
    • Installing WP Reactions
    • Activate License Key
    • Quick Start Guide
    • Revoke License Key
  • folder icon closed folder iconEmoji Reaction Layouts
    • Original Reactions
    • Reaction Button
    • Jane Reactions
    • Jimbo Reactions
    • Mini Reactions
  • folder icon closed folder iconLayout Options
    • Emoji Picker
    • Emoji Reveal
    • Flying Animated Text
    • Reaction Button Design
    • Reaction Container Styling
    • Emoji Animation
    • Call to Action
    • Random Counts
    • Fake Counts
    • Button Padding
    • Emoji Border Styling
    • Emoji Background Styling
    • Emoji Sizes
    • Shortcode Alignment
    • Emoji Badges
    • Flying Animation Effect
    • Primary Call to Action
    • Social Share Call to Action
    • Button Icon Styling
  • folder icon closed folder iconSettings
    • General
    • Advanced
    • WooCommerce Reactions
  • folder icon closed folder iconSocial Media Sharing
    • Social Share Platforms
    • Button Design
    • Share Counter
    • Button Behavior
    • Social Popup Overlay
  • folder icon closed folder iconWPML Intergration
    • Installing Required WPML Plugins
    • Translate Global Activation
    • Translate Shortcodes
  • folder icon closed folder iconShortcode Generator
    • Shortcode Editor
    • Bind Shortcode to Post
  • folder icon closed folder iconGlobal Activation
    • On Page Options
    • Custom Post Types
  • folder icon closed folder iconAnalytics
    • Emoji Reaction Data
    • Social Sharing Data
  • folder icon closed folder iconTools
    • Advanced Random Counts
    • Reset User Counts
  • folder icon closed folder iconDevelopers
    • Action Hooks & Filters
    • JavaScript Events
loading
Popular Searches
  • Global Activation
  • Shortcode
  • Layout Options
  1. Home
  2. WP Reactions
  3. Developers
  4. Action Hooks & Filters
Updated on April 13, 2022

WP Reactions

  • folder icon closed folder iconGetting Started
    • Download WP Reactions
    • Installing WP Reactions
    • Activate License Key
    • Quick Start Guide
    • Revoke License Key
  • folder icon closed folder iconEmoji Reaction Layouts
    • Original Reactions
    • Reaction Button
    • Jane Reactions
    • Jimbo Reactions
    • Mini Reactions
  • folder icon closed folder iconLayout Options
    • Emoji Picker
    • Emoji Reveal
    • Flying Animated Text
    • Reaction Button Design
    • Reaction Container Styling
    • Emoji Animation
    • Call to Action
    • Random Counts
    • Fake Counts
    • Button Padding
    • Emoji Border Styling
    • Emoji Background Styling
    • Emoji Sizes
    • Shortcode Alignment
    • Emoji Badges
    • Flying Animation Effect
    • Primary Call to Action
    • Social Share Call to Action
    • Button Icon Styling
  • folder icon closed folder iconSettings
    • General
    • Advanced
    • WooCommerce Reactions
  • folder icon closed folder iconSocial Media Sharing
    • Social Share Platforms
    • Button Design
    • Share Counter
    • Button Behavior
    • Social Popup Overlay
  • folder icon closed folder iconWPML Intergration
    • Installing Required WPML Plugins
    • Translate Global Activation
    • Translate Shortcodes
  • folder icon closed folder iconShortcode Generator
    • Shortcode Editor
    • Bind Shortcode to Post
  • folder icon closed folder iconGlobal Activation
    • On Page Options
    • Custom Post Types
  • folder icon closed folder iconAnalytics
    • Emoji Reaction Data
    • Social Sharing Data
  • folder icon closed folder iconTools
    • Advanced Random Counts
    • Reset User Counts
  • folder icon closed folder iconDevelopers
    • Action Hooks & Filters
    • JavaScript Events

Action Hooks & Filters

Estimated reading: 4 minutes 6813 views

Overview

WordPress allows using action hooks and filters to change functionality of plugins and themes. You can read about hooks and filters more here.

Action Hooks

WP Reactions include some action hooks that can be useful for developers to extend functionality of plugin by using them. We have listed action hooks with their data and example below.

wpreactions/user/initialized

Fires just after plugin loads all of itse components and ready. This hook can be used to do some actions that needs to be ensure plugin is loaded and ready.

wpreactions/user/react

After user reacts to any of reactions, this hook is fired with the reacted emoji data. You can use this hook to do certain actions after user react, for example give them some points in your site.

Hook function receive 2 parameters:

array $data – holds information about user react

  • bind_id – post id or unique id for standalone shortcodes
  • react_id –  unique id to identify user reaction
  • reacted_date – date of reaction
  • source – identify if reaction comes from global activation or shortcode
  • emoji_id – id of emoji
  • user_id – user id if user logged in, 0 (zero) if not logged in
  • sgc_id – if source is shortcode, then this will set to shortcode id
  • post_type – post type of the post user is reacting

array $response – holds information about reaction if it is success or fail

  • action – if user react first time ‘insert’, otherwise ‘update’
  • status – determine if reaction was ‘success’ or ‘error’
  • error_message – in case of error, it holds information about error
Below example gives 10 points to the user_id = 1 when he is reacting to any of emojis.
 
add_action('wpreactions/user/react', function($data, $response) {
    if ($response['status'] == 'success' && $data['user_id'] == 1) {
        update_user_meta($data, 'user_bonus', 10);
    }
});

wpreactions/user/socialShare

After user reacts to any of reactions, this hook is fired with the reacted emoji data. You can use this hook to do certain actions after user react, for example give them some points in your site.

Hook function receive 2 parameters:

array $data – holds information about user react 

  • bind_id – post id or unique id for standalone shortcodes
  • platform –  social platform that user shared to
  • click_date – date of sharing
  • source – identify if share comes from global activation or shortcode
  • user_id – user id if user logged in, 0 (zero) if not logged in
  • sgc_id – if source is shortcode, then this will set to shortcode id
  • post_type – post type of the post user is sharing

array $response – holds information about sharing if it is success or fail

  • action – if user react first time ‘insert’, otherwise ‘update’
  • status – determine if reaction was ‘success’ or ‘error’
  • error_message – in case of error, it holds information about error 

If user share on Facebook, we mark it as facebook_user.

add_action('wpreactions/user/socialShare', function($data, $response) {
    if ($response['status'] == 'success' && $data['platform'] == 'facebook') {
        update_user_meta($data, 'facebook_user', 'yes');
    }
});

Filters

WP Reactions provides some filters that can be useful for developers to extend functionality of plugin by using them. We have listed filters with their data and example below.

wpreactions/output/params

Filters parameters of reactions just before rendered in frontend. You can change these params by using the filter and have customized look with some complex logic. There are lots of params that passed in $params array, you can just print it out and see full list in your code.

Example shows that how you can disable how you can disable social share buttons for pages.

add_filter('wpreactions/output/params', function($params) {
    global $post;
    if ($post->post_type == 'page') {
       $params['enable_share_buttons'] = 'false';
    }
    return $params;
});

wpreactions/output

Filters output HTML just before rendering it on frontend. You can use it to add some HTML before and after reactions based on your needs.

Example show that you can remove reactions for page id = 1 (front page) returning to empty string.

add_filter('wpreactions/output', function($html) {
    global $post;

    if ($post->ID == 1) {
        $html = '';
    }

    return $html;
});
  • Tagged:
  • action hook
  • filter
  • hook

Still need help?

Helpful? Yes 8 No 1

How can we help?

A premium WordPress theme with integrated Knowledge Base,
providing 24/7 community based support.

CONTENTS

Quick Links

  • Demo Site
  • Pricing
  • Contact Us

Products

  • WP Reactions PRO
  • WP Reactions Lite
  • Emoji Uploader

Support

  • Open a Ticket
  • Lite Support
  • Knowledge Base
  • Terms of Use
  • Refund Policy
  • Privacy

© Copyright 2022, All Rights Reserved WP Reactions, LLC