iFlyChat
  • Documentation
  • Installation
    • WordPress Chat Plugin
    • Drupal Chat Module
    • PHP Chat Client
  • WordPress
    • Embed Chatroom in WordPress Post
    • Disable Popup Chat
    • Hide Popup Chat from a Page
    • Embed Inbox View
    • View Chat Logs
    • Guest User Access
    • Show/Hide Popup Chat On Specific Pages
    • WordPress Filters and Hooks
  • API Reference
    • Create a new chat room
    • Retrieve list of all chat rooms
    • Edit a chat room
    • Retrieve list of all online users
    • Kick a user from the chat
    • Retrieve list of all users online in a chat room
    • Delete a chat room
    • Retrieve Thread History
  • JavaScript SDK
    • Quickstart
    • Custom Label In Chat Window
    • User Chat Button Widget
    • Reference
      • message receive
      • message send
      • user list update
      • connect
      • disconnect
      • ready
      • iflychat.startChat
      • iflychat.closeChat
      • iflychat.minimiseChat
      • iflychat.init
      • iflychat.setStatus
      • iflychat.sound
      • iflychat.openAdminDashboard
      • current user status update
      • current user sound update
      • iflychat.renderLabelInChatWindow
  • Help
    • General
      • Introduction
      • Accounts and Billing
      • Chat Theme and Colors
      • Chat Notification Sound
      • Going Offline
      • Change billing card information
    • Embedded Chatroom
      • Create a New Room
      • Create a New Embed Room
      • Embed Room in PHP
    • Feature Description
      • Moderated Chatroom
      • Group Chat
      • Private Embedded Chatroom
      • Change Guest Name
      • Resize Popup Chat Window
      • Mute Sound Notification
      • Change User Status
      • Desktop Notification
      • Popout or Full Screen Mode
      • Share Media Files
      • Video Chat
    • Chat Moderation
      • Kick/Ban/BanIP
      • Delete or Clear Messages
      • Popup Chat Position
      • Popup Chat Launcher Position
      • App Dashboard
      • Emoji Packs
      • Message Display Format
      • Time Display Format
      • Mobile Web Chat
      • Show Only Admins in Chat
      • Hide Recent Chats Section
      • Hide Users in Popup Chat List
      • Hide Popup Chat List
      • Minimize Popup Chat List
Powered by GitBook
On this page

Was this helpful?

  1. WordPress

WordPress Filters and Hooks

iFlyChat Filters Implementation

To implement Wordpress filter in your module, you just need to add the filter definition of these filter in your main plugin file. Sample implementations are given below:

Note: These filters are supported from version >= 4.2.5

1: iflychat_get_username_filter - Assigns a username to a given user.

/**
 * Implements my_custom_get_username()
 * @params $user_name string 
 * @params $uid string 
 */
function my_custom_get_username($user_name,$uid){
  $user_name = 'SampleName';
  return $user_name;
}
add_filter('iflychat_get_username_filter','my_custom_get_username',10,2);

2: iflychat_get_user_avatar_url_filter() - Assigns a avatar url to the given user.

/**
 * Implements my_custom_get_user_avatar_url()
 * @params $user_avatar_url string 
 * @params $uid string 
 */
function my_custom_get_user_avatar_url($user_avatar_url,$uid){
  $user_avatar_url = 'http://sample-avatar-url';
  return $user_avatar_url;
}
add_filter('iflychat_get_user_avatar_url_filter','my_custom_get_user_avatar_url',10,2);

3: iflychat_get_user_profile_url_filter() - Assigns a profile url to a given user.

/**
 * Implements my_custom_get_profile_url(). 
 * @params $user_profile_url string 
 * @params $uid string 
 */
function my_custom_get_profile_url($user_profile_url,$uid){
  $user_profile_url = 'http://sample-profile-url';
  return $user_profile_url;
}
add_filter('iflychat_get_user_profile_url_filter','my_custom_get_profile_url',10,2);

4: iflychat_get_user_roles_filter() - Assigns roles to a given user.

/**
 * Implements my_custom_get_user_roles().
 * @params $roles associative array 
 * @params $uid string 
 */

function my_custom_get_user_roles($roles,$uid){
  if($uid === 0){
    $roles['sample-role-index-1'] = 'Sample-Role-Name-1'; // users with odd user id have Sample-Role-1;
  }else{
    $roles['sample-role-index-2'] = 'Sample-Role-Name-2'; // users with even user id have Sample-Role-2;
  }
  return $roles;
}
add_filter('iflychat_get_user_roles_filter','my_custom_get_user_roles',10,2);

5: iflychat_get_user_groups_filter() - Assigns a group to a given user.

/**
 * Implements my_custom_groups().
 * @params $user_groups array 
 * @params $uid string 
 */

 function my_custom_groups($user_groups,$uid){
  global $current_user;
  if($current_user->ID % 2 === 0){
    $user_groups['A'] = "A";
 } else {
    $user_groups['B'] = "B";
 }
    return (array)$user_groups;
 };
 add_filter('iflychat_get_user_groups_filter','my_custom_groups',10,2);

6: iflychat_get_user_friends_filter() - Assigns a relationship to a given user.

/**
 * Implements my_custom_get_friends().
 * @params $friends array 
 * @params $uid string 
 */
function my_custom_get_friends($friends,$uid){
  $friends = ['1','2','3'];    //Id's of friends
  return (array)$friends;
}
add_filter('iflychat_get_user_friends_filter', 'my_custom_get_friends',10,2);

7: iflychat_check_access_filter() - Display chat to a limited set of users.

/**
 * Implements my_custom_filter().
 * @params $access boolean
 * @params $uid string 
 */
function my_custom_filter($access,$uid) {
  $access = true;
  /** Get current user information **/
  global $current_user;
  get_currentuserinfo();
  /** Return $access as true or false based on your custom code */ 
  return $access;
}
add_filter('iflychat_check_access_filter', 'my_custom_filter',10,2);

For reference - https://developer.wordpress.org/reference/functions/add_filter/

PreviousShow/Hide Popup Chat On Specific PagesNextCreate a new chat room

Last updated 5 years ago

Was this helpful?