digitoimistodude/air-reactions

Add new reactions

Closed this issue · 3 comments

Hi,

How could I append more reactions like 'sad', 'angry'? By defaults, only 3.

I tried below but it didn't show up.

add_filter( 'air_reactions_types', function( (array) $extra_reaction ) {
return [
'sad' => [
'icon_path' => get_theme_file_path( 'svg/sad.svg' ),
'texts' => [
'reaction' => 'This post is sad',
'amount_pre' => 'Sad',
'amount_post' => 'times',
],
],
];
});

Thank you.

Hi,

To append you need to push the new reaction to the default types array and then return it. In your example you overwrite the array so you only should get the sad reaction in that case. Example:

add_filter( 'air_reactions_types', function( (array) $default_types ) {
  // Add "sad" to reaction types
  $default_types['sad'] = [
     'icon_path' => get_theme_file_path( 'svg/sad.svg' ),
     'texts' => [ 
       'reaction' => 'This post is sad',
       'amount_pre' => 'Sad',
       'amount_post' => 'times',
      ]
  ];

  return $default_types;
});

If that doesn't help, the other question is: did you define the reaction types when outputting the reaction html? Like this:

[air-reactions types="heart,like,dislike,sad"]

OR 

do_action(
  'air_reactions_display',
  [
    'types' => [ 'heart' , 'dislike', 'like', 'sad' ],
  ]
)

It would actually make a lot of sense if default reactions would automatically be the ones you define with that hook so you don't have to define them when outputting the reaction buttons. Thank you for pointing out the inconvenience. That will be changed in the next version.

Thank you. I missed the second step, which to define the reaction types. Now it works! Thank you <3

The 1.0.1 release fixes this, so you don't need to specify the types when displaying reactions, it will automatically show all defined types.