I am trying to: create a "chat with me" button between logged-in user and post author of a post in a loop. i'm using USERPRO chat plugin fir that.
I expected to see: a chat window is suppose to popup in a modal, but nothing happens and i get an error in the console:
userpro-msg.js?ver=4.4.4:40 Uncaught TypeError: Cannot read property 'html' of null
it happens only using your theme and inside a views loop....
Instead, I got: nothing.
Dear shirly,
Since it is a compatibility problem, could you post a downloadable URL for the USERPRO plugin, and describe detail steps to duplicate same problem?
I need test and debug it in my localhost, thanks
Hi Lou,
is it possible to open a privet reply for me so I could post you a link for the plugin? I've purchased it.
here are the steps of what I did:
1. I've created an "ads board" on my website so people could add their ad and other users could send them a privet message.
2. the messaging system is based on 2 plugins: "UserPro" and an extension of this plugin called "Private Messages".
3. the idea is that once I've installed "Private Messages" - I add a code in order to add a "chat now" button:
<a href="#" class="userpro-button chat userpro-init-chat" data-chat_with="1" data-chat_from="2"><i class="userpro-icon-comment"></i>Message me now!</a>
Here, 'data-chat_with="1" ' is the id of admin
so what I've tried to do on my website is to create a view that shows the ads that have been published. inside the loop- I implemented this code:
<a href="#" class="userpro-button chat userpro-init-chat" data-chat_with="[wpv-post-author format='meta' meta='ID']" data-chat_from="[wpv-current-user info='id']"><i class="userpro-icon-comment"></i>Message me now!</a>
The thing is that when I click on the button- it looks like something is going to happen (I get a gray layer on the screen and a loading icon) but eventually- nothing happens....
i would really appreciate if you could help.
thank you 🙂
OK, please fill below private detail box with the downloadable URL of USERPRO plugin, thanks
Thanks for the details, I tried these in my localhost, please correct me if there is anything missing:
1) Install Views + UserPro + userpro-messaging
I see a warning message:
You are using a trial version of UserPro plugin
2) Create a view to list posts, in views loop section, add the codes you mentioned above:
<a href="#" class="userpro-button chat userpro-init-chat" data-chat_with="[wpv-post-author format='meta' meta='ID']" data-chat_from="[wpv-current-user info='id']"><i class="userpro-icon-comment"></i>Message me now!</a>
3) put above view into a page, and view it in front-end, I see below screenshot 654.JPG,
Here is what I found:
1) There is a JS error, which produced by userpro-messaging plugin:
userpro-msg.js?ver=4.5.3:296 Uncaught TypeError: jQuery(...).smartresize is not a function
2) I checked the HTML source codes, see screenshot 655.JPG:
Views does output correct author ID and current user ID into the HTML A tag, for the problem you mentioned above, I suggest you ask help from the plugin author of userpro-messaging.
thank you Luo,
could you try and help me add a chat to my website in another way?
i'm trying the wp-chats plugin. it has a tutorial that suggest a php code that adds a chat button to each post to let the current logged in user chat with the author of the post that they’re viewing.
is there a way to take this code and add it to a post in a view loop and this way to solve my problem?
this is the tutorial: hidden link
and this is their code:
if ( !function_exists('se_start_chat_btn_by_user') ) :;
function se_start_chat_btn_by_user( $user_id ) {
global $current_user;
if ( ! $current_user->ID || ! $user_id || $current_user->ID == $user_id ) return;
ob_start(); wp_title(); $title = ob_get_clean();
$userdata = get_userdata( $user_id );
?>
<div class="wpc-start-chat">
<?php wpc_contact_user_modal_link(
$userdata,
array(
'exit_title' => $title,
'link_text' => sprintf('Start chat with %s', $userdata->display_name)
)
); ?>
</div>
<?php
}
endif;
add_filter('the_content',function($content) {
if ( is_single() ) {
global $post;
ob_start();
se_start_chat_btn_by_user( $post->post_author );
$content .= ob_get_clean();
}
return $content;
});
i attached a sample of what i'm aiming to do.
thank you 🙂
Thanks for the details, I am checking it in your test site, will feedback if there is any found.
Please try this:
1) Add below codes into your theme/functions.php:
add_shortcode('start_chat_btn_by_user', 'start_chat_btn_by_user_func');
function start_chat_btn_by_user_func($atts){
$user_id = get_the_author_id();
global $current_user;
$res = '';
if ( ! $current_user->ID || ! $user_id || $current_user->ID == $user_id || !function_exists('wpc_contact_user_modal_link') ) return;
ob_start();
$userdata = get_userdata( $user_id );
?>
<div class="wpc-start-chat">
<?php wpc_contact_user_modal_link(
$userdata,
array(
'exit_title' => $title,
'link_text' => sprintf('Start chat with %s', $userdata->display_name)
)
); ?>
</div>
<?php
$res .= ob_get_clean();
return $res;
}
2) Use above shortcode in the view's loop:
[start_chat_btn_by_user]
It is only an example, for your reference.
hi,
thanks 🙂
i'v added the code to the function.php and put the shortcode in my VIEW loop. but i don't see any button on my site, where i've putted the shortcode.
As I mentioned above, it is only an example, you will need to activate the wp-chats plugin first, and test again, if the problem still exists, since it is a custom codes problem, please duplicate same problem in a test site, and fill below private detail box with login details and ftp access, also point out the problem page URL and where I can edit your PHP codes, I need test and debug it in a live website, thanks
Thanks for the details, checking it in your website.
The "WordPress access details:" you provided, seems is a subscriber user, do debug this problem, please setup it as a admin user, and also point out the problem page URL and where I can edit your PHP codes, thanks
Thanks for the details, since you did not point out the problem page URL, so I create a post here:
hidden link
View here:
hidden link
And modify the PHP codes as below:
add_shortcode('start_chat_btn_by_user', 'start_chat_btn_by_user_func');
function start_chat_btn_by_user_func($atts){
$author_id = get_the_author_id();
$current_user_id = get_current_user_id();
$res = '';
if ( ! $current_user_id || $current_user_id == $author_id ) return;
$userdata = get_userdata( $author_id );
ob_start();
?>
<div class="wpc-start-chat">
<?php wpc_contact_user_modal_link(
$userdata,
array(
'exit_title' => $title,
'link_text' => sprintf('Start chat with %s', $userdata->user_login)
)
); ?>
</div>
<?php
$res .= ob_get_clean();
return $res;
}
Please test again, check if it is want you want
hi there,
thank you!
but i see that you have changed the theme. it was toolset starter and you changed it to Twenty Sixteen.
When i copy the code to the Toolset Starter function.php - the code does not work.
any idea why?
thanks 🙂