Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuriinalivaiko/f12a246c4d820edd575fc89ea7aff32a to your computer and use it in GitHub Desktop.
Save yuriinalivaiko/f12a246c4d820edd575fc89ea7aff32a to your computer and use it in GitHub Desktop.
This code adds the "Add emoji" tool to the activity post form. This code uses elements of the "Ultimate Member - Private Messages", so this extension is required.
<?php
// "Add emoji" tool for the activity post form.
add_action( 'wp_loaded', 'um_fix_emotize', 20 );
add_action( 'um_activity_post_insert_tools', 'um_activity_post_insert_tools_emoji' );
function um_activity_post_insert_tools_emoji() {
if ( defined( 'um_messaging_plugin' ) ) {
UM()->get_template( 'emoji.php', um_messaging_plugin, array(), true );
wp_enqueue_script( 'um-messaging' );
wp_enqueue_style( 'um-messaging' );
add_action( 'wp_footer', 'um_activity_post_insert_tools_emoji_script', 20 );
}
}
function um_activity_post_insert_tools_emoji_script() {
?><script type="text/javascript">
jQuery( function() {
// Update caret position.
jQuery( 'form.um-activity-publish' ).on('click touchend keyup', 'textarea.um-activity-textarea-elem', function(e) {
e.target.umCaretPosition = um_getCaretPosition( e.target );
});
// Insert a smiley.
jQuery( 'form.um-activity-publish' ).on('click', '.um-message-emolist span.um-message-insert-emo', function(e){
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
var form = jQuery(e.delegateTarget);
var code = jQuery(this).attr('data-emo');
var chatbox = form.find('textarea.um-activity-textarea-elem');
var old_pos = chatbox.prop('umCaretPosition') ? chatbox.prop('umCaretPosition').end : 0;
var first_str = chatbox.val().substr( 0, old_pos );
var last_str = chatbox.val().substr( old_pos, chatbox.val().length );
var new_pos = ( first_str + ' ' + code + ' ' ).length;
chatbox.val( first_str + ' ' + code + ' ' + last_str );
um_setCaretPosition( chatbox.get(0), new_pos );
chatbox.trigger('focus');
um_Hide_Emobox();
});
} );
</script>
<style type="text/css">
.um-activity-widget .um-message-emoji {
float: left;
position: relative;
}
.um-activity-widget .um-message-emoji .um-message-emo {
color: #999;
cursor: pointer !important;
height: auto !important;
line-height: 20px !important;
min-width: 40px;
}
</style><?php
}
function um_fix_emotize() {
if ( function_exists( 'UM' ) && isset( UM()->shortcodes()->emoji ) ) {
$img = UM()->shortcodes()->emoji[':$'];
unset( UM()->shortcodes()->emoji[':$'] );
UM()->shortcodes()->emoji[':\$'] = $img;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment