Giter Site home page Giter Site logo

mulxcode / air-reactions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from digitoimistodude/air-reactions

0.0 1.0 0.0 107 KB

A developer-friendly WordPress-plugin for adding customizable reactions (likes, hearts, dislikes, shrugs or whatever you feel like) to your content.

PHP 76.54% JavaScript 23.46%

air-reactions's Introduction

Air Reactions

A developer-friendly WordPress-plugin for adding customizable reactions (likes, hearts, dislikes, shrugs or whatever you feel like) to your content.

Usage

Basic usage

Call hook air_reactions_display on your template file

do_action( 'air_reactions_display', [] );

It will echo the reaction container with default buttons where called. You can specify the default buttons using 'air_reactions_default_types' filter.

Advanced usage

Available parameters are:

  [
    'echo'    => (bool),
    'types'   => (array),
    'post_id' => (int),
  ]

Example:

do_action(
  'air_reactions_display',
  [
    'echo' => false,
    'post_id' => 5,
    'types' => [
      'like' => [
        'icon_path' => get_theme_file_path( 'svg/thumbs-up.svg' ),
        'texts'     => [
          'reaction'   => 'Like this post',
          'amount_pre' => 'Likesd',
          'amount_post' => 'times',
        ],
      ],
    ],
  ]
)

Hooks

Set allowed post types

Liking is allowed only on these post types.

Default: [ 'post', 'page' ]

add_filter( 'air_reactions_post_types', function( (array) $post_types ) {
  return [ 'post', 'page' ];
} );

Allow only registered users to react

By default, reactions will be saved to user meta to allow users to react once per post.

TODO: If this is set to false, the plugin uses FingerprintJS to set browser fingerprints to reaction events and save the reactions to the posts only.

Default: true

add_filter( 'air_reactions_only_registered_users', function( (bool) $allow_only_logged_in_users ) {
  return true;
} );

Set capability for reacting posts

You can use any capability recognized by current_user_can() function

Default: read

add_filter( 'air_reactions_capability', function( (string) $capability ) {
  return 'read';
} );

Filter post reactions after they are loaded from meta

add_filter( 'air_reactions_get_post_reactions', function( (array) $post_reactions, (int) $post_id, (string) $meta_key ) {
  // Do something
  return $post_reactions;
} )

Set default reaction types

Default:

[
  'heart' => [
    'icon_path' => plugin_dir_path( __DIR__ ) . 'svg/heart.svg',
    'texts'     => [
      'reaction'   => __( 'Love this post', 'air-reactions' ),
      'amount_pre' => __( 'Loved', 'air-reactions' ),
      'amount_post' => __( 'times', 'air-reactions' ),
    ],
  ],
  'like' => [
    'icon_path' => plugin_dir_path( __DIR__ ) . 'svg/thumbs-up.svg',
    'texts'     => [
      'reaction'   => __( 'Like this post', 'air-reactions' ),
      'amount_pre' => __( 'Liked', 'air-reactions' ),
      'amount_post' => __( 'times', 'air-reactions' ),
    ],
  ],
  'dislike' => [
    'icon_path' => plugin_dir_path( __DIR__ ) . 'svg/thumbs-down.svg',
    'texts'     => [
      'reaction'   => __( 'Dislike this post', 'air-reactions' ),
      'amount_pre' => __( 'Disliked', 'air-reactions' ),
      'amount_post' => __( 'times', 'air-reactions' ),
    ],
  ],
]

Example:

add_filter( 'air_reactions_default_types', function( (array) $default_types ) {
  return [
    'heart' => [
      'icon_path' => get_theme_file_path( 'svg/heart.svg' ),
      'texts'     => [
        'reaction'   => 'Love this post',
        'amount_pre' => 'Loved',
        'amount_post' => 'times',
      ],
    ],
  ];
});

Modify reaction item markup

You can use this to build your own reaction item, just remember to add data-attributes like in the original, the javascript depends entirely on those. Feel free to modify the structure and classes etc.

add_filter( 'air_reactions_reaction_item', function( (string) $output, (string) $key, (array) $item ) {
  // Do something
  return $output;
});

Modify container start and end markup

You can change the markup or add wrapper etc. Just remember to add data-attributes like in the original, the javascript depends entirely on those.

add_filter( 'air_reactions_container_start', function( (string) $output, (array) $args, (bool), (int) $current_user_id ) {
  // Do something
  return $output;
});
add_filter( 'air_reactions_container_start', function( (string) $output, (array) $args, (bool), (int) $current_user_id ) {
  // Do something
  return $output;
});

air-reactions's People

Contributors

niq1982 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.