Suggestion: Add filters to change entries
-
Suggestion for future development:
Add filters to allow changes/additions to chat entries.
Currently date/time of each entry is only visible via title attribute and mouseover, not available on mobile devices.
We wanted to add date/time in front of username, this was our solution by hacking a filter into plugin code, maybe official filters could be added in a similar way in future versions.
simple-ajax-chat-form.php
line 148$sac_out .= convert_smilies(' '. $chat_text) .'</li>'. "\n"; // added this line: $sac_out = apply_filters( 'sac_line', $sac_out, $chat_text, $chat_time, $url, $chat_name );
simple-ajax-chat.php
line 178$loop = $id .'---'. $name .'---'. $text .'---'. $time .' '. esc_html__('ago', 'simple-ajax-chat') .'---'. $url .'---'; // added these two line: $time = isset($query[$row]['time']) ? $query[$row]['time'] : ''; $loop = apply_filters( 'sac_line', $loop, $text, $time, $url, $name );
Our code in child theme:
function my_sac_line( $line, $text, $time, $url, $name ) { $nice_time = date_i18n( 'd.m. H:i', $time ); $line = str_replace( array( '<span class="sac-chat-name"', '---'. $name .'---' ), array( $nice_time . ' <span class="sac-chat-name"', '---' . $nice_time . ' ' . $name .'---' ), $line ); return $line; } add_filter( 'sac_line', 'my_sac_line', 10, 5 );
Note: During implementation we saw a possible bug. Calls to
simple-ajax-chat-core.php?sacGetChat=yes...
would always also return an htmlpage with error message, no matter if valid data is sent or not.Plugin SAC: JavaScript not enabled. Please enable JavaScript and try again.
Probably an
exit();
should be added infunction sac_getData()
if$loop
was not empty or similar.Thanks for great plugin.
- The topic ‘Suggestion: Add filters to change entries’ is closed to new replies.