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 {
|
||||
var args = jQuery(this).data('args');
|
||||
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_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_comments', array( UM()->user_posts(), 'load_comments' ) );
|
||||
|
||||
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 );
|
||||
|
||||
|
||||
|
||||
if ( ! is_user_logged_in() ) {
|
||||
if ( $args['show_lock'] == 'no' ) {
|
||||
echo '';
|
||||
} else {
|
||||
$args['lock_text'] = $this->convert_locker_tags( $args['lock_text'] );
|
||||
$this->set_args = $args;
|
||||
$this->load_template( 'login-to-view' );
|
||||
UM()->get_template( 'login-to-view.php', '', $args, true );
|
||||
}
|
||||
} else {
|
||||
echo do_shortcode( $this->convert_locker_tags( wpautop( $content ) ) );
|
||||
@@ -388,7 +385,7 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function um_loggedout($args = array(), $content = "") {
|
||||
function um_loggedout( $args = array(), $content = '' ) {
|
||||
ob_start();
|
||||
|
||||
// Hide for logged in users
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<?php
|
||||
namespace um\core;
|
||||
|
||||
// Exit if accessed directly
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
|
||||
if ( ! class_exists( 'um\core\User_posts' ) ) {
|
||||
|
||||
|
||||
@@ -13,14 +14,13 @@ if ( ! class_exists( 'um\core\User_posts' ) ) {
|
||||
*/
|
||||
class User_posts {
|
||||
|
||||
|
||||
/**
|
||||
* User_posts constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
add_action( 'um_profile_content_posts', array( &$this, 'add_posts' ) );
|
||||
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
|
||||
*/
|
||||
function add_posts() {
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'post',
|
||||
'posts_per_page' => 10,
|
||||
@@ -71,7 +70,23 @@ if ( ! class_exists( 'um\core\User_posts' ) ) {
|
||||
* 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
|
||||
*
|
||||
* @param $args
|
||||
*/
|
||||
function load_comments( $args ) {
|
||||
$array = explode(',', $args );
|
||||
$post_type = $array[0];
|
||||
$posts_per_page = $array[1];
|
||||
$offset = $array[2];
|
||||
$author = $array[3];
|
||||
function load_comments() {
|
||||
UM()->check_ajax_nonce();
|
||||
|
||||
$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()->shortcodes()->load_template('profile/comments-single');
|
||||
UM()->get_template( 'profile/comments.php', '', array( 'comments' => $comments ), true );
|
||||
wp_die();
|
||||
}
|
||||
|
||||
|
||||
@@ -152,12 +167,15 @@ if ( ! class_exists( 'um\core\User_posts' ) ) {
|
||||
*
|
||||
* @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;
|
||||
if ( !$user_id )
|
||||
if ( ! $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 );
|
||||
$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 ) {
|
||||
global $wpdb;
|
||||
if ( !$user_id )
|
||||
$user_id = um_user('ID');
|
||||
if ( ! $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'");
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Ultimate Member\n"
|
||||
"POT-Creation-Date: 2019-10-17 16:12+0300\n"
|
||||
"PO-Revision-Date: 2019-10-17 16:12+0300\n"
|
||||
"POT-Creation-Date: 2019-10-17 18:03+0300\n"
|
||||
"PO-Revision-Date: 2019-10-17 18:03+0300\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"Language: en_US\n"
|
||||
@@ -7221,11 +7221,11 @@ msgid ""
|
||||
"\"{login_referrer}\">login</a> to view this content."
|
||||
msgstr ""
|
||||
|
||||
#: includes/core/class-shortcodes.php:646
|
||||
#: includes/core/class-shortcodes.php:643
|
||||
msgid "You are already registered"
|
||||
msgstr ""
|
||||
|
||||
#: includes/core/class-shortcodes.php:893
|
||||
#: includes/core/class-shortcodes.php:890
|
||||
msgid "Default Template"
|
||||
msgstr ""
|
||||
|
||||
@@ -7783,20 +7783,20 @@ msgstr ""
|
||||
msgid "Reset my password"
|
||||
msgstr ""
|
||||
|
||||
#: templates/profile/comments-single.php:24
|
||||
#: templates/profile/comments-single.php:14
|
||||
#, php-format
|
||||
msgid "On <a href=\"%1$s\">%2$s</a>"
|
||||
msgstr ""
|
||||
|
||||
#: templates/profile/comments-single.php:35 templates/profile/comments.php:18
|
||||
#: templates/profile/comments.php:24
|
||||
msgid "load more comments"
|
||||
msgstr ""
|
||||
|
||||
#: templates/profile/comments.php:31
|
||||
#: templates/profile/comments.php:36
|
||||
msgid "You have not made any comments."
|
||||
msgstr ""
|
||||
|
||||
#: templates/profile/comments.php:33
|
||||
#: templates/profile/comments.php:38
|
||||
msgid "This user has not made any comments."
|
||||
msgstr ""
|
||||
|
||||
|
||||
@@ -1,19 +1,9 @@
|
||||
<?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 );
|
||||
if ( $post_type == 'um_groups_discussion' ) {
|
||||
$comment_id = $comment->comment_post_ID;
|
||||
$group_id = get_post_meta( $comment_id, '_group_id', true );
|
||||
$comment_title = get_the_title( $group_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">
|
||||
<div class="um-item-link">
|
||||
<i class="um-icon-chatboxes"></i>
|
||||
<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
|
||||
@@ -23,17 +13,4 @@ foreach ( UM()->shortcodes()->loop as $comment ) {
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<?php }
|
||||
</div>
|
||||
@@ -1,29 +1,34 @@
|
||||
<?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 ) {
|
||||
|
||||
UM()->shortcodes()->load_template('profile/comments-single'); ?>
|
||||
|
||||
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">
|
||||
|
||||
<!--Ajax output-->
|
||||
|
||||
<?php if ( count( UM()->shortcodes()->loop ) >= 10 ) { ?>
|
||||
<?php foreach ( $comments as $comment ) {
|
||||
UM()->get_template( 'profile/comments-single.php', '', array( 'comment' => $comment ), true );
|
||||
}
|
||||
|
||||
if ( $count_comments > 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' ) ); ?>">
|
||||
data-user_id="<?php echo esc_attr( um_get_requested_user() ); ?>" data-page="1"
|
||||
data-pages="<?php echo esc_attr( ceil( $count_comments / 10 ) ); ?>">
|
||||
<?php _e( 'load more comments', 'ultimate-member' ); ?>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php } else { ?>
|
||||
<?php } else { ?>
|
||||
|
||||
<div class="um-profile-note">
|
||||
<span>
|
||||
@@ -35,4 +40,5 @@ if ( UM()->shortcodes()->loop ) {
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<?php }
|
||||
<?php }
|
||||
}
|
||||
Reference in New Issue
Block a user