mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-11 18:56:10 +09:00
- changed logic of the comments loading on the user profile page;
This commit is contained in:
@@ -318,6 +318,31 @@ jQuery(document).ready(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else if ( 'um_load_comments' === hook ) {
|
||||||
|
var pages = jQuery(this).data('pages')*1;
|
||||||
|
var next_page = jQuery(this).data('page')*1 + 1;
|
||||||
|
|
||||||
|
jQuery.ajax({
|
||||||
|
url: wp.ajax.settings.url,
|
||||||
|
type: 'post',
|
||||||
|
data: {
|
||||||
|
action: 'um_ajax_paginate_comments',
|
||||||
|
user_id: jQuery(this).data('user_id'),
|
||||||
|
page: next_page,
|
||||||
|
nonce: um_scripts.nonce
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
parent.removeClass( 'loading' );
|
||||||
|
},
|
||||||
|
success: function( data ) {
|
||||||
|
parent.before( data );
|
||||||
|
if ( next_page === pages ) {
|
||||||
|
parent.remove();
|
||||||
|
} else {
|
||||||
|
obj.data( 'page', next_page );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
var args = jQuery(this).data('args');
|
var args = jQuery(this).data('args');
|
||||||
var container = jQuery(this).parents('.um').find('.um-ajax-items');
|
var container = jQuery(this).parents('.um').find('.um-ajax-items');
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -40,7 +40,9 @@ if ( ! class_exists( 'um\core\AJAX_Common' ) ) {
|
|||||||
|
|
||||||
add_action( 'wp_ajax_um_ajax_paginate', array( UM()->query(), 'ajax_paginate' ) );
|
add_action( 'wp_ajax_um_ajax_paginate', array( UM()->query(), 'ajax_paginate' ) );
|
||||||
add_action( 'wp_ajax_um_ajax_paginate_posts', array( UM()->user_posts(), 'load_posts' ) );
|
add_action( 'wp_ajax_um_ajax_paginate_posts', array( UM()->user_posts(), 'load_posts' ) );
|
||||||
|
add_action( 'wp_ajax_um_ajax_paginate_comments', array( UM()->user_posts(), 'load_comments' ) );
|
||||||
add_action( 'wp_ajax_nopriv_um_ajax_paginate_posts', array( UM()->user_posts(), 'load_posts' ) );
|
add_action( 'wp_ajax_nopriv_um_ajax_paginate_posts', array( UM()->user_posts(), 'load_posts' ) );
|
||||||
|
add_action( 'wp_ajax_nopriv_um_ajax_paginate_comments', array( UM()->user_posts(), 'load_comments' ) );
|
||||||
|
|
||||||
add_action( 'wp_ajax_um_muted_action', array( UM()->form(), 'ajax_muted_action' ) );
|
add_action( 'wp_ajax_um_muted_action', array( UM()->form(), 'ajax_muted_action' ) );
|
||||||
|
|
||||||
|
|||||||
@@ -361,15 +361,12 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
|
|||||||
|
|
||||||
$args = wp_parse_args( $args, $defaults );
|
$args = wp_parse_args( $args, $defaults );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ( ! is_user_logged_in() ) {
|
if ( ! is_user_logged_in() ) {
|
||||||
if ( $args['show_lock'] == 'no' ) {
|
if ( $args['show_lock'] == 'no' ) {
|
||||||
echo '';
|
echo '';
|
||||||
} else {
|
} else {
|
||||||
$args['lock_text'] = $this->convert_locker_tags( $args['lock_text'] );
|
$args['lock_text'] = $this->convert_locker_tags( $args['lock_text'] );
|
||||||
$this->set_args = $args;
|
UM()->get_template( 'login-to-view.php', '', $args, true );
|
||||||
$this->load_template( 'login-to-view' );
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
echo do_shortcode( $this->convert_locker_tags( wpautop( $content ) ) );
|
echo do_shortcode( $this->convert_locker_tags( wpautop( $content ) ) );
|
||||||
@@ -388,7 +385,7 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function um_loggedout($args = array(), $content = "") {
|
function um_loggedout( $args = array(), $content = '' ) {
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
// Hide for logged in users
|
// Hide for logged in users
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace um\core;
|
namespace um\core;
|
||||||
|
|
||||||
// Exit if accessed directly
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||||
|
|
||||||
|
|
||||||
if ( ! class_exists( 'um\core\User_posts' ) ) {
|
if ( ! class_exists( 'um\core\User_posts' ) ) {
|
||||||
|
|
||||||
|
|
||||||
@@ -13,14 +14,13 @@ if ( ! class_exists( 'um\core\User_posts' ) ) {
|
|||||||
*/
|
*/
|
||||||
class User_posts {
|
class User_posts {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User_posts constructor.
|
* User_posts constructor.
|
||||||
*/
|
*/
|
||||||
function __construct() {
|
function __construct() {
|
||||||
add_action( 'um_profile_content_posts', array( &$this, 'add_posts' ) );
|
add_action( 'um_profile_content_posts', array( &$this, 'add_posts' ) );
|
||||||
add_action( 'um_profile_content_comments', array( &$this, 'add_comments' ) );
|
add_action( 'um_profile_content_comments', array( &$this, 'add_comments' ) );
|
||||||
|
|
||||||
add_action( 'um_ajax_load_posts__um_load_comments', array( &$this, 'load_comments' ), 10, 1 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -28,7 +28,6 @@ if ( ! class_exists( 'um\core\User_posts' ) ) {
|
|||||||
* Add posts
|
* Add posts
|
||||||
*/
|
*/
|
||||||
function add_posts() {
|
function add_posts() {
|
||||||
|
|
||||||
$args = array(
|
$args = array(
|
||||||
'post_type' => 'post',
|
'post_type' => 'post',
|
||||||
'posts_per_page' => 10,
|
'posts_per_page' => 10,
|
||||||
@@ -71,7 +70,23 @@ if ( ! class_exists( 'um\core\User_posts' ) ) {
|
|||||||
* Add comments
|
* Add comments
|
||||||
*/
|
*/
|
||||||
function add_comments() {
|
function add_comments() {
|
||||||
UM()->shortcodes()->load_template( 'profile/comments' );
|
$comments = get_comments( array(
|
||||||
|
'number' => 10,
|
||||||
|
'offset' => 0,
|
||||||
|
'user_id' => um_user( 'ID' ),
|
||||||
|
'post_status' => array( 'publish' ),
|
||||||
|
'type__not_in' => apply_filters( 'um_excluded_comment_types', array('') ),
|
||||||
|
) );
|
||||||
|
|
||||||
|
|
||||||
|
$comments_count = get_comments( array(
|
||||||
|
'user_id' => um_user( 'ID' ),
|
||||||
|
'post_status' => array( 'publish' ),
|
||||||
|
'type__not_in' => apply_filters( 'um_excluded_comment_types', array('') ),
|
||||||
|
'count' => 1,
|
||||||
|
) );
|
||||||
|
|
||||||
|
UM()->get_template( 'profile/comments.php', '', array( 'comments' => $comments, 'count_comments' => $comments_count ), true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -124,23 +139,23 @@ if ( ! class_exists( 'um\core\User_posts' ) ) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Dynamic load of comments
|
* Dynamic load of comments
|
||||||
*
|
|
||||||
* @param $args
|
|
||||||
*/
|
*/
|
||||||
function load_comments( $args ) {
|
function load_comments() {
|
||||||
$array = explode(',', $args );
|
UM()->check_ajax_nonce();
|
||||||
$post_type = $array[0];
|
|
||||||
$posts_per_page = $array[1];
|
|
||||||
$offset = $array[2];
|
|
||||||
$author = $array[3];
|
|
||||||
|
|
||||||
$offset_n = $posts_per_page + $offset;
|
$user_id = ! empty( $_POST['user_id'] ) ? absint( $_POST['user_id'] ) : get_current_user_id();
|
||||||
|
$page = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 0;
|
||||||
|
|
||||||
UM()->shortcodes()->modified_args = "$post_type,$posts_per_page,$offset_n,$author";
|
$comments = get_comments( array(
|
||||||
|
'number' => 10,
|
||||||
|
'offset' => ( $page - 1 ) * 10,
|
||||||
|
'user_id' => $user_id,
|
||||||
|
'post_status' => array('publish'),
|
||||||
|
'type__not_in' => apply_filters( 'um_excluded_comment_types', array('') ),
|
||||||
|
) );
|
||||||
|
|
||||||
UM()->shortcodes()->loop = UM()->query()->make("post_type=$post_type&number=$posts_per_page&offset=$offset&user_id=$author");
|
UM()->get_template( 'profile/comments.php', '', array( 'comments' => $comments ), true );
|
||||||
|
wp_die();
|
||||||
UM()->shortcodes()->load_template('profile/comments-single');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -152,12 +167,15 @@ if ( ! class_exists( 'um\core\User_posts' ) ) {
|
|||||||
*
|
*
|
||||||
* @return int|string
|
* @return int|string
|
||||||
*/
|
*/
|
||||||
function count_user_posts_by_type( $user_id= '', $post_type = 'post' ) {
|
function count_user_posts_by_type( $user_id = '', $post_type = 'post' ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
if ( !$user_id )
|
if ( ! $user_id ) {
|
||||||
$user_id = um_user( 'ID' );
|
$user_id = um_user( 'ID' );
|
||||||
|
}
|
||||||
|
|
||||||
if ( !$user_id ) return 0;
|
if ( ! $user_id ) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
$where = get_posts_by_author_sql( $post_type, true, $user_id );
|
$where = get_posts_by_author_sql( $post_type, true, $user_id );
|
||||||
$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
|
$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
|
||||||
@@ -175,10 +193,13 @@ if ( ! class_exists( 'um\core\User_posts' ) ) {
|
|||||||
*/
|
*/
|
||||||
function count_user_comments( $user_id = null ) {
|
function count_user_comments( $user_id = null ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
if ( !$user_id )
|
if ( ! $user_id ) {
|
||||||
$user_id = um_user('ID');
|
$user_id = um_user( 'ID' );
|
||||||
|
}
|
||||||
|
|
||||||
if ( !$user_id ) return 0;
|
if ( ! $user_id ) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
$count = $wpdb->get_var("SELECT COUNT(comment_ID) FROM " . $wpdb->comments. " WHERE user_id = " . $user_id . " AND comment_approved = '1'");
|
$count = $wpdb->get_var("SELECT COUNT(comment_ID) FROM " . $wpdb->comments. " WHERE user_id = " . $user_id . " AND comment_approved = '1'");
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: Ultimate Member\n"
|
"Project-Id-Version: Ultimate Member\n"
|
||||||
"POT-Creation-Date: 2019-10-17 16:12+0300\n"
|
"POT-Creation-Date: 2019-10-17 18:03+0300\n"
|
||||||
"PO-Revision-Date: 2019-10-17 16:12+0300\n"
|
"PO-Revision-Date: 2019-10-17 18:03+0300\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: \n"
|
"Language-Team: \n"
|
||||||
"Language: en_US\n"
|
"Language: en_US\n"
|
||||||
@@ -7221,11 +7221,11 @@ msgid ""
|
|||||||
"\"{login_referrer}\">login</a> to view this content."
|
"\"{login_referrer}\">login</a> to view this content."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/core/class-shortcodes.php:646
|
#: includes/core/class-shortcodes.php:643
|
||||||
msgid "You are already registered"
|
msgid "You are already registered"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: includes/core/class-shortcodes.php:893
|
#: includes/core/class-shortcodes.php:890
|
||||||
msgid "Default Template"
|
msgid "Default Template"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@@ -7783,20 +7783,20 @@ msgstr ""
|
|||||||
msgid "Reset my password"
|
msgid "Reset my password"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: templates/profile/comments-single.php:24
|
#: templates/profile/comments-single.php:14
|
||||||
#, php-format
|
#, php-format
|
||||||
msgid "On <a href=\"%1$s\">%2$s</a>"
|
msgid "On <a href=\"%1$s\">%2$s</a>"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: templates/profile/comments-single.php:35 templates/profile/comments.php:18
|
#: templates/profile/comments.php:24
|
||||||
msgid "load more comments"
|
msgid "load more comments"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: templates/profile/comments.php:31
|
#: templates/profile/comments.php:36
|
||||||
msgid "You have not made any comments."
|
msgid "You have not made any comments."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: templates/profile/comments.php:33
|
#: templates/profile/comments.php:38
|
||||||
msgid "This user has not made any comments."
|
msgid "This user has not made any comments."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +1,16 @@
|
|||||||
<?php if ( ! defined( 'ABSPATH' ) ) exit;
|
<?php if ( ! defined( 'ABSPATH' ) ) exit;
|
||||||
|
|
||||||
foreach ( UM()->shortcodes()->loop as $comment ) {
|
$comment_title = apply_filters( 'um_user_profile_comment_title', get_the_title( $comment->comment_post_ID ), $comment );
|
||||||
|
$link = apply_filters( 'um_user_profile_comment_url', get_permalink( $comment->comment_post_ID ), $comment ); ?>
|
||||||
|
|
||||||
$post_type = get_post_type( $comment->comment_post_ID );
|
<div class="um-item">
|
||||||
if ( $post_type == 'um_groups_discussion' ) {
|
<div class="um-item-link">
|
||||||
$comment_id = $comment->comment_post_ID;
|
<i class="um-icon-chatboxes"></i>
|
||||||
$group_id = get_post_meta( $comment_id, '_group_id', true );
|
<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
|
||||||
$comment_title = get_the_title( $group_id );
|
<?php echo get_comment_excerpt( $comment->comment_ID ); ?>
|
||||||
$link = site_url() . '/groups/' . $comment_title . '/?tab=discussion#commentid-' . $comment_id;
|
|
||||||
} else {
|
|
||||||
$comment_title = get_the_title( $comment->comment_post_ID );
|
|
||||||
$link = get_permalink( $comment->comment_post_ID );
|
|
||||||
} ?>
|
|
||||||
|
|
||||||
<div class="um-item">
|
|
||||||
<div class="um-item-link">
|
|
||||||
<i class="um-icon-chatboxes"></i>
|
|
||||||
<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
|
|
||||||
<?php echo get_comment_excerpt( $comment->comment_ID ); ?>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="um-item-meta">
|
|
||||||
<span><?php printf( __( 'On <a href="%1$s">%2$s</a>','ultimate-member' ), $link, $comment_title ); ?></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php }
|
|
||||||
|
|
||||||
if ( isset( UM()->shortcodes()->modified_args ) && count( UM()->shortcodes()->loop ) >= 10 ) { ?>
|
|
||||||
|
|
||||||
<div class="um-load-items">
|
|
||||||
<a href="javascript:void(0);" class="um-ajax-paginate um-button" data-hook="um_load_comments"
|
|
||||||
data-args="<?php echo esc_attr( UM()->shortcodes()->modified_args ); ?>">
|
|
||||||
<?php _e( 'load more comments', 'ultimate-member' ); ?>
|
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="um-item-meta">
|
||||||
<?php }
|
<span><?php printf( __( 'On <a href="%1$s">%2$s</a>','ultimate-member' ), $link, $comment_title ); ?></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -1,38 +1,44 @@
|
|||||||
<?php if ( ! defined( 'ABSPATH' ) ) exit;
|
<?php if ( ! defined( 'ABSPATH' ) ) exit;
|
||||||
|
|
||||||
UM()->shortcodes()->loop = UM()->query()->make('post_type=comment&number=10&offset=0&user_id=' . um_user('ID') );
|
|
||||||
|
|
||||||
if ( UM()->shortcodes()->loop ) {
|
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
|
||||||
|
//Only for AJAX loading posts
|
||||||
|
if ( ! empty( $comments ) ) {
|
||||||
|
foreach ( $comments as $comment ) {
|
||||||
|
UM()->get_template( 'profile/comments-single.php', '', array( 'comment' => $comment ), true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ( ! empty( $comments ) ) { ?>
|
||||||
|
<div class="um-ajax-items">
|
||||||
|
|
||||||
UM()->shortcodes()->load_template('profile/comments-single'); ?>
|
<?php foreach ( $comments as $comment ) {
|
||||||
|
UM()->get_template( 'profile/comments-single.php', '', array( 'comment' => $comment ), true );
|
||||||
<div class="um-ajax-items">
|
}
|
||||||
|
|
||||||
<!--Ajax output-->
|
|
||||||
|
|
||||||
<?php if ( count( UM()->shortcodes()->loop ) >= 10 ) { ?>
|
|
||||||
|
|
||||||
<div class="um-load-items">
|
|
||||||
<a href="javascript:void(0);" class="um-ajax-paginate um-button" data-hook="um_load_comments"
|
|
||||||
data-args="comment,10,10,<?php echo esc_attr( um_user( 'ID' ) ); ?>">
|
|
||||||
<?php _e( 'load more comments', 'ultimate-member' ); ?>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php } ?>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php } else { ?>
|
|
||||||
|
|
||||||
<div class="um-profile-note">
|
if ( $count_comments > 10 ) { ?>
|
||||||
<span>
|
<div class="um-load-items">
|
||||||
<?php if ( um_profile_id() == get_current_user_id() ) {
|
<a href="javascript:void(0);" class="um-ajax-paginate um-button" data-hook="um_load_comments"
|
||||||
_e( 'You have not made any comments.', 'ultimate-member' );
|
data-user_id="<?php echo esc_attr( um_get_requested_user() ); ?>" data-page="1"
|
||||||
} else {
|
data-pages="<?php echo esc_attr( ceil( $count_comments / 10 ) ); ?>">
|
||||||
_e( 'This user has not made any comments.', 'ultimate-member' );
|
<?php _e( 'load more comments', 'ultimate-member' ); ?>
|
||||||
} ?>
|
</a>
|
||||||
</span>
|
</div>
|
||||||
</div>
|
<?php } ?>
|
||||||
|
|
||||||
<?php }
|
</div>
|
||||||
|
|
||||||
|
<?php } else { ?>
|
||||||
|
|
||||||
|
<div class="um-profile-note">
|
||||||
|
<span>
|
||||||
|
<?php if ( um_profile_id() == get_current_user_id() ) {
|
||||||
|
_e( 'You have not made any comments.', 'ultimate-member' );
|
||||||
|
} else {
|
||||||
|
_e( 'This user has not made any comments.', 'ultimate-member' );
|
||||||
|
} ?>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user