diff --git a/assets/js/um-scripts.js b/assets/js/um-scripts.js index 85658e84..5632160a 100644 --- a/assets/js/um-scripts.js +++ b/assets/js/um-scripts.js @@ -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'); diff --git a/assets/js/um-scripts.min.js b/assets/js/um-scripts.min.js index 8a259006..564470b5 100644 --- a/assets/js/um-scripts.min.js +++ b/assets/js/um-scripts.min.js @@ -1 +1 @@ -function um_init_datetimepicker(){jQuery(".um-datepicker:not(.picker__input)").each(function(){if(elem=jQuery(this),void 0!==elem.attr("data-disabled_weekdays")&&""!=elem.attr("data-disabled_weekdays"))var e=JSON.parse(elem.attr("data-disabled_weekdays"));else e=!1;var t=null;void 0!==elem.attr("data-years")&&(t=elem.attr("data-years"));var a=elem.attr("data-date_min"),i=elem.attr("data-date_max"),r=[],n=[];void 0!==a&&(r=a.split(",")),void 0!==i&&(n=i.split(","));var u=r.length?new Date(r):null,o=r.length?new Date(n):null;if(u&&"Invalid Date"==u.toString()&&3==r.length){var s=r[1]+"/"+r[2]+"/"+r[0];u=new Date(Date.parse(s))}if(o&&"Invalid Date"==o.toString()&&3==n.length){var d=n[1]+"/"+n[2]+"/"+n[0];o=new Date(Date.parse(d))}var l={disable:e,format:elem.attr("data-format"),formatSubmit:"yyyy/mm/dd",hiddenName:!0,onOpen:function(){elem.blur()},onClose:function(){elem.blur()}};null!==t&&(l.selectYears=t),null!==u&&(l.min=u),null!==o&&(l.max=o),elem.pickadate(l)}),jQuery(".um-timepicker:not(.picker__input)").each(function(){elem=jQuery(this),elem.pickatime({format:elem.attr("data-format"),interval:parseInt(elem.attr("data-intervals")),formatSubmit:"HH:i",hiddenName:!0,onOpen:function(){elem.blur()},onClose:function(){elem.blur()}})})}function init_tipsy(){"function"==typeof jQuery.fn.tipsy&&(jQuery(".um-tip-n").tipsy({gravity:"n",opacity:1,live:"a.live",offset:3}),jQuery(".um-tip-w").tipsy({gravity:"w",opacity:1,live:"a.live",offset:3}),jQuery(".um-tip-e").tipsy({gravity:"e",opacity:1,live:"a.live",offset:3}),jQuery(".um-tip-s").tipsy({gravity:"s",opacity:1,live:"a.live",offset:3}))}jQuery(document).ready(function(){jQuery(document.body).on("click",".um-dropdown a.real_url",function(e){window.location=jQuery(this).attr("href")}),jQuery(document.body).on("click",".um-trigger-menu-on-click",function(e){return jQuery(".um-dropdown").hide(),jQuery(this).find(".um-dropdown").show(),!1}),jQuery(document.body).on("click",".um-dropdown-hide",function(e){return UM_hide_menus(),!1}),jQuery(document.body).on("click","a.um-manual-trigger",function(){var e=jQuery(this).attr("data-child"),t=jQuery(this).attr("data-parent");return jQuery(this).parents(t).find(e).trigger("click"),UM_hide_menus(),!1}),jQuery(".um-s1,.um-s2").css({display:"block"}),0query(), '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' ) ); diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php index 4b9795a5..bbc8bfce 100644 --- a/includes/core/class-shortcodes.php +++ b/includes/core/class-shortcodes.php @@ -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 diff --git a/includes/core/class-user-posts.php b/includes/core/class-user-posts.php index 0f5cb1b8..9b9b2cb7 100644 --- a/includes/core/class-user-posts.php +++ b/includes/core/class-user-posts.php @@ -1,9 +1,10 @@ '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'"); diff --git a/languages/ultimate-member-en_US.po b/languages/ultimate-member-en_US.po index aa13f93a..40e003a7 100644 --- a/languages/ultimate-member-en_US.po +++ b/languages/ultimate-member-en_US.po @@ -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 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 %2$s" 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 "" diff --git a/templates/profile/comments-single.php b/templates/profile/comments-single.php index 7d9b1739..a2b0a395 100644 --- a/templates/profile/comments-single.php +++ b/templates/profile/comments-single.php @@ -1,39 +1,16 @@ 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 ); - } ?> - -
- -
- %2$s','ultimate-member' ), $link, $comment_title ); ?> -
-
- -shortcodes()->modified_args ) && count( UM()->shortcodes()->loop ) >= 10 ) { ?> - -
- - +
+ - - + %2$s','ultimate-member' ), $link, $comment_title ); ?> +
+
\ No newline at end of file diff --git a/templates/profile/comments.php b/templates/profile/comments.php index 67e269af..4b8b3aaa 100644 --- a/templates/profile/comments.php +++ b/templates/profile/comments.php @@ -1,38 +1,44 @@ 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 ) ) { ?> +
- UM()->shortcodes()->load_template('profile/comments-single'); ?> - -
- - - - shortcodes()->loop ) >= 10 ) { ?> - -
- - - -
- - - -
- - + get_template( 'profile/comments-single.php', '', array( 'comment' => $comment ), true ); + } -
- - - -
- - 10 ) { ?> +
+ + + +
+ + +
+ + + +
+ + + +
+ +