From b4c2ff15dd4832a3cfacc8f2b96c80739e396697 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Mon, 8 Oct 2018 23:36:05 +0300 Subject: [PATCH] - fixed User Profile posts pagination; - 2.0.29 release; --- README.md | 6 +- assets/js/um-scripts.js | 81 +++++++++++++------ assets/js/um-scripts.min.js | 2 +- includes/core/class-ajax-common.php | 3 + includes/core/class-shortcodes.php | 3 - includes/core/class-user-posts.php | 121 +++++++++++++++++++++------- languages/ultimate-member-en_US.po | 34 ++++---- readme.txt | 7 +- templates/profile/posts-single.php | 64 ++++++++------- templates/profile/posts.php | 72 ++++++++--------- ultimate-member.php | 2 +- 11 files changed, 246 insertions(+), 149 deletions(-) diff --git a/README.md b/README.md index e5ba1c68..87dccf71 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Ultimate Member is the #1 user profile & membership plugin for WordPress. The pl | Latest Version |Requires at least|Stable Tag| | :------------: |:------------:|:------------:| -| 2.0.28 | WordPress 4.9 or higher| 2.0.28 | +| 2.0.29 | WordPress 4.9 or higher| 2.0.29 | Features of the plugin include: @@ -48,9 +48,7 @@ GNU Version 2 or Any Later Version Releases ==================== -[Official Release Version: 2.0.28](https://github.com/ultimatemember/ultimatemember/releases/tag/2.0.28). - -[Official Release Version: 1.3.88](https://github.com/ultimatemember/ultimatemember/releases). +[Official Release Version: 2.0.29](https://github.com/ultimatemember/ultimatemember/releases/tag/2.0.29). Changelog ==================== diff --git a/assets/js/um-scripts.js b/assets/js/um-scripts.js index df13cd0e..0be9ab66 100644 --- a/assets/js/um-scripts.js +++ b/assets/js/um-scripts.js @@ -241,31 +241,62 @@ jQuery(document).ready(function() { return false; }); - jQuery(document).on('click', '.um-ajax-paginate', function(e){ - e.preventDefault(); - var parent = jQuery(this).parent(); - parent.addClass('loading'); - var args = jQuery(this).data('args'); - var hook = jQuery(this).data('hook'); - var container = jQuery(this).parents('.um').find('.um-ajax-items'); - jQuery.ajax({ - url: wp.ajax.settings.url, - type: 'post', - data: { - action: 'um_ajax_paginate', - hook: hook, - args: args - }, - complete: function(){ - parent.removeClass('loading'); - }, - success: function(data){ - parent.remove(); - container.append( data ); - } - }); - return false; - }); + + jQuery( document.body ).on( 'click', '.um-ajax-paginate', function(e) { + e.preventDefault(); + + var obj = jQuery(this); + var parent = jQuery(this).parent(); + parent.addClass( 'loading' ); + + var hook = jQuery(this).data('hook'); + if ( 'um_load_posts' === 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_posts', + author: jQuery(this).data('author'), + page: next_page + }, + 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'); + + jQuery.ajax({ + url: wp.ajax.settings.url, + type: 'post', + data: { + action: 'um_ajax_paginate', + hook: hook, + args: args + }, + complete: function() { + parent.removeClass( 'loading' ); + }, + success: function(data){ + parent.remove(); + container.append( data ); + } + }); + } + }); + jQuery(document).on('click', '.um-ajax-action', function(e){ e.preventDefault(); diff --git a/assets/js/um-scripts.min.js b/assets/js/um-scripts.min.js index f2de24a3..82a00880 100644 --- a/assets/js/um-scripts.min.js +++ b/assets/js/um-scripts.min.js @@ -1 +1 @@ -jQuery(document).ready(function(){jQuery(document).on("click",".um-dropdown a",function(e){return!1}),jQuery(document).on("click",".um-dropdown a.real_url",function(e){window.location=jQuery(this).attr("href")}),jQuery(document).on("click",".um-trigger-menu-on-click",function(e){return jQuery(".um-dropdown").hide(),menu=jQuery(this).find(".um-dropdown"),menu.show(),!1}),jQuery(document).on("click",".um-dropdown-hide",function(e){UM_hide_menus()}),jQuery(document).on("click","a.um-manual-trigger",function(){var e=jQuery(this).attr("data-child"),t=jQuery(this).attr("data-parent");jQuery(this).parents(t).find(e).trigger("click")}),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).on("change",".um-field-area input[type=radio]",function(){var e=jQuery(this).parents(".um-field-area"),t=jQuery(this).parents("label");e.find(".um-field-radio").removeClass("active"),e.find(".um-field-radio").find("i").removeAttr("class").addClass("um-icon-android-radio-button-off"),t.addClass("active"),t.find("i").removeAttr("class").addClass("um-icon-android-radio-button-on")}),jQuery(document).on("change",".um-field-area input[type=checkbox]",function(){jQuery(this).parents(".um-field-area");var e=jQuery(this).parents("label");e.hasClass("active")?(e.removeClass("active"),e.find("i").removeAttr("class").addClass("um-icon-android-checkbox-outline-blank")):(e.addClass("active"),e.find("i").removeAttr("class").addClass("um-icon-android-checkbox-outline"))}),jQuery(".um-datepicker").each(function(){if(elem=jQuery(this),""!=elem.attr("data-disabled_weekdays"))var e=JSON.parse(elem.attr("data-disabled_weekdays"));else e=!1;var t=elem.attr("data-years"),a=elem.attr("data-date_min"),i=elem.attr("data-date_max"),r=a.split(","),n=i.split(","),u=r.length?new Date(r):null,o=r.length?new Date(n):null;if(u&&"Invalid Date"==u.toString()&&3==r.length){var d=r[1]+"/"+r[2]+"/"+r[0];u=new Date(Date.parse(d))}if(o&&"Invalid Date"==o.toString()&&3==n.length){var s=n[1]+"/"+n[2]+"/"+n[0];o=new Date(Date.parse(s))}elem.pickadate({selectYears:t,min:u,max:o,disable:e,format:elem.attr("data-format"),formatSubmit:"yyyy/mm/dd",hiddenName:!0,onOpen:function(){elem.blur()},onClose:function(){elem.blur()}})}),jQuery(".um-timepicker").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()}})}),jQuery(".um-rating").um_raty({half:!1,starType:"i",number:function(){return jQuery(this).attr("data-number")},score:function(){return jQuery(this).attr("data-score")},scoreName:function(){return jQuery(this).attr("data-key")},hints:!1,click:function(e,t){live_field=this.id,live_value=e,um_conditional()}}),jQuery(".um-rating-readonly").um_raty({half:!1,starType:"i",number:function(){return jQuery(this).attr("data-number")},score:function(){return jQuery(this).attr("data-score")},scoreName:function(){return jQuery(this).attr("data-key")},hints:!1,readOnly:!0}),jQuery(document).on("click",".um .um-single-image-preview a.cancel",function(e){e.preventDefault();var t=jQuery(this).parents(".um-field"),a=jQuery(this).parents(".um-field").find(".um-single-image-preview img").attr("src");return t.find(".um-single-image-preview img").attr("src",""),t.find(".um-single-image-preview").hide(),t.find(".um-btn-auto-width").html("Upload"),t.find("input[type=hidden]").val("empty_file"),jQuery.ajax({url:wp.ajax.settings.url,type:"post",data:{action:"um_remove_file",src:a}}),!1}),jQuery(document).on("click",".um .um-single-file-preview a.cancel",function(e){e.preventDefault();var t=jQuery(this).parents(".um-field"),a=jQuery(this).parents(".um-field").find(".um-single-fileinfo a").attr("href");return t.find(".um-single-file-preview").hide(),t.find(".um-btn-auto-width").html("Upload"),t.find("input[type=hidden]").val("empty_file"),jQuery.ajax({url:wp.ajax.settings.url,type:"post",data:{action:"um_remove_file",src:a}}),!1}),jQuery(".um-s1,.um-s2").css({display:"block"}),jQuery(".um-s1").select2({allowClear:!0}),jQuery(".um-s2").select2({allowClear:!1,minimumResultsForSearch:10}),jQuery(document).on("click",".um-field-group-head:not(.disabled)",function(){var e=jQuery(this).parents(".um-field-group"),t=e.data("max_entries");e.find(".um-field-group-body").is(":hidden")?e.find(".um-field-group-body").show():e.find(".um-field-group-body:first").clone().appendTo(e),increase_id=0,e.find(".um-field-group-body").each(function(){increase_id++,jQuery(this).find("input").each(function(){var e=jQuery(this);e.attr("id",e.data("key")+"-"+increase_id),e.attr("name",e.data("key")+"-"+increase_id),e.parent().parent().find("label").attr("for",e.data("key")+"-"+increase_id)})}),0profile(), 'ajax_delete_profile_photo' ) ); add_action( 'wp_ajax_um_delete_cover_photo', array( UM()->profile(), 'ajax_delete_cover_photo' ) ); + 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_muted_action', array( UM()->form(), 'ajax_muted_action' ) ); add_action( 'wp_ajax_um_remove_file', array( UM()->files(), 'ajax_remove_file' ) ); diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php index aadc3e80..0a0c01b3 100644 --- a/includes/core/class-shortcodes.php +++ b/includes/core/class-shortcodes.php @@ -272,14 +272,11 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { $file = um_path . "templates/{$tpl}.php"; $theme_file = get_stylesheet_directory() . "/ultimate-member/templates/{$tpl}.php"; - - if ( file_exists( $theme_file ) ) { $file = $theme_file; } if ( file_exists( $file ) ) { - include $file; } } diff --git a/includes/core/class-user-posts.php b/includes/core/class-user-posts.php index 4ec2686b..24ec6f76 100644 --- a/includes/core/class-user-posts.php +++ b/includes/core/class-user-posts.php @@ -20,32 +20,109 @@ if ( ! class_exists( 'um\core\User_posts' ) ) { 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_posts', array( &$this, 'load_posts' ) ); - add_action( 'um_ajax_load_posts__um_load_comments', array( &$this, 'load_comments' ) ); + add_action( 'um_ajax_load_posts__um_load_comments', array( &$this, 'load_comments' ), 10, 1 ); + } + + + /** + * Add posts + */ + function add_posts() { + + $args = array( + 'post_type' => 'post', + 'posts_per_page' => 10, + 'offset' => 0, + 'author' => um_get_requested_user(), + 'post_status' => array( 'publish' ) + ); + + /** + * UM hook + * + * @type filter + * @title um_profile_query_make_posts + * @description Some changes of WP_Query Posts Tab + * @input_vars + * [{"var":"$query_posts","type":"WP_Query","desc":"UM Posts Tab query"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $args = apply_filters( 'um_profile_query_make_posts', $args ); + $posts = get_posts( $args ); + + $count_posts = wp_count_posts(); + $count_posts = ! empty( $count_posts->publish ) ? $count_posts->publish : 0; + + UM()->shortcodes()->set_args = array( 'posts' => $posts, 'count_posts' => $count_posts ); + UM()->shortcodes()->load_template( 'profile/posts' ); + } + + + /** + * Add comments + */ + function add_comments() { + UM()->shortcodes()->load_template( 'profile/comments' ); } /** * Dynamic load of posts * - * @param array $args */ - function load_posts( $args ) { - $array = explode(',', $args ); - $post_type = $array[0]; - $posts_per_page = $array[1]; - $offset = $array[2]; - $author = $array[3]; + function load_posts() { + $author = ! empty( $_POST['author'] ) ? $_POST['author'] : get_current_user_id(); + $page = ! empty( $_POST['page'] ) ? $_POST['page'] : 0; - $offset_n = $posts_per_page + $offset; + $args = array( + 'post_type' => 'post', + 'posts_per_page' => 10, + 'offset' => ( $page - 1 ) * 10, + 'author' => $author, + 'post_status' => array( 'publish' ) + ); - UM()->shortcodes()->modified_args = "$post_type,$posts_per_page,$offset_n,$author"; + /** + * UM hook + * + * @type filter + * @title um_profile_query_make_posts + * @description Some changes of WP_Query Posts Tab + * @input_vars + * [{"var":"$query_posts","type":"WP_Query","desc":"UM Posts Tab query"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $args = apply_filters( 'um_profile_query_make_posts', $args ); + $posts = get_posts( $args ); - UM()->shortcodes()->loop = UM()->query()->make("post_type=$post_type&posts_per_page=$posts_per_page&offset=$offset&author=$author"); - - UM()->shortcodes()->load_template('profile/posts-single'); + UM()->shortcodes()->set_args = array( 'posts' => $posts ); + UM()->shortcodes()->load_template( 'profile/posts' ); + wp_die(); } + /** * Dynamic load of comments * @@ -68,22 +145,6 @@ if ( ! class_exists( 'um\core\User_posts' ) ) { } - /** - * Add posts - */ - function add_posts() { - UM()->shortcodes()->load_template( 'profile/posts' ); - } - - - /** - * Add comments - */ - function add_comments() { - UM()->shortcodes()->load_template( 'profile/comments' ); - } - - /** * Count posts by type * diff --git a/languages/ultimate-member-en_US.po b/languages/ultimate-member-en_US.po index bcab794e..48622378 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: 2018-10-05 10:16+0300\n" -"PO-Revision-Date: 2018-10-05 10:16+0300\n" +"POT-Creation-Date: 2018-10-08 23:32+0300\n" +"PO-Revision-Date: 2018-10-08 23:32+0300\n" "Last-Translator: \n" "Language-Team: \n" "Language: en_US\n" @@ -6513,17 +6513,17 @@ msgstr "" msgid "Wrong nonce" msgstr "" -#: includes/core/class-shortcodes.php:358 +#: includes/core/class-shortcodes.php:355 msgid "" "This content has been restricted to logged in users only. Please login to view this content." msgstr "" -#: includes/core/class-shortcodes.php:518 +#: includes/core/class-shortcodes.php:515 msgid "You are already registered" msgstr "" -#: includes/core/class-shortcodes.php:760 +#: includes/core/class-shortcodes.php:757 msgid "Default Template" msgstr "" @@ -7043,37 +7043,37 @@ msgstr "" msgid "This user has not made any comments." msgstr "" -#: templates/profile/posts-single.php:16 +#: templates/profile/posts-single.php:21 #, php-format msgid "%s ago" msgstr "" -#: templates/profile/posts-single.php:17 +#: templates/profile/posts-single.php:24 msgid "in" msgstr "" -#: templates/profile/posts-single.php:18 +#: templates/profile/posts-single.php:30 msgid "no comments" msgstr "" -#: templates/profile/posts-single.php:18 +#: templates/profile/posts-single.php:32 +#, php-format +msgid "%s comments" +msgstr "" + +#: templates/profile/posts-single.php:34 msgid "1 comment" msgstr "" -#: templates/profile/posts-single.php:18 -#, php-format -msgid "% comments" -msgstr "" - -#: templates/profile/posts-single.php:27 templates/profile/posts.php:35 +#: templates/profile/posts.php:21 msgid "load more posts" msgstr "" -#: templates/profile/posts.php:43 +#: templates/profile/posts.php:32 msgid "You have not created any posts." msgstr "" -#: templates/profile/posts.php:43 +#: templates/profile/posts.php:32 msgid "This user has not created any posts." msgstr "" diff --git a/readme.txt b/readme.txt index b6559a30..4a3feed2 100644 --- a/readme.txt +++ b/readme.txt @@ -6,7 +6,7 @@ Donate link: Tags: community, member, membership, user-profile, user-registration Requires at least: 4.7 Tested up to: 4.9 -Stable tag: 2.0.28 +Stable tag: 2.0.29 License: GNU Version 2 or Any Later Version License URI: http://www.gnu.org/licenses/gpl-3.0.txt @@ -133,6 +133,11 @@ The plugin works with popular caching plugins by automatically excluding Ultimat = Important: UM2.0+ is a significant update to the code base from 1.3.88. Please make sure you take a full-site backup with restore point before updating the plugin = += 2.0.29: October 8, 2018 = + +* Bugfixes: + - Fixed User Profile Posts pagination + = 2.0.28: October 5, 2018 = * Bugfixes: diff --git a/templates/profile/posts-single.php b/templates/profile/posts-single.php index a2d94511..e7b31c75 100644 --- a/templates/profile/posts-single.php +++ b/templates/profile/posts-single.php @@ -1,30 +1,40 @@ - shortcodes()->loop->have_posts()) { UM()->shortcodes()->loop->the_post(); $post_id = get_the_ID(); ?> +
+ -
- - - - -
- - - -
- - : - -
+ ID ) ) { + $image_id = get_post_thumbnail_id( $post->ID ); + $image_url = wp_get_attachment_image_src( $image_id, 'full', true ); ?> + + - + - - shortcodes()->modified_args) && UM()->shortcodes()->loop->have_posts() && UM()->shortcodes()->loop->found_posts >= 10 ) { ?> - -
- -
- - \ No newline at end of file + +
+ + ID ), current_time( 'timestamp' ) ) ); ?> + + + : ID ); ?> + + + ID ); + + if ( $num_comments == 0 ) { + $comments = __( 'no comments', 'ultimate-member' ); + } elseif ( $num_comments > 1 ) { + $comments = sprintf( __( '%s comments', 'ultimate-member' ), $num_comments ); + } else { + $comments = __( '1 comment', 'ultimate-member' ); + } ?> + + + +
+
\ No newline at end of file diff --git a/templates/profile/posts.php b/templates/profile/posts.php index dd720abf..6b13e9fb 100644 --- a/templates/profile/posts.php +++ b/templates/profile/posts.php @@ -1,45 +1,37 @@ -query()->make('post_type=post&posts_per_page=10&offset=0&author=' . um_get_requested_user() ); +shortcodes()->set_args = array( 'post' => $post ); + UM()->shortcodes()->load_template( 'profile/posts-single' ); + } + } +} else { + if ( ! empty( $posts ) ) { ?> +
-/** - * UM hook - * - * @type filter - * @title um_profile_query_make_posts - * @description Some changes of WP_Query Posts Tab - * @input_vars - * [{"var":"$query_posts","type":"WP_Query","desc":"UM Posts Tab query"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ -UM()->shortcodes()->loop = apply_filters( 'um_profile_query_make_posts', $query_posts ); + shortcodes()->set_args = array( 'post' => $post ); + UM()->shortcodes()->load_template( 'profile/posts-single' ); + } -if ( UM()->shortcodes()->loop->have_posts() ) { + if ( $count_posts > 10 ) { ?> +
+ + + +
+ - UM()->shortcodes()->load_template( 'profile/posts-single' ); ?> - -
- - shortcodes()->loop->found_posts >= 10 ) { ?> - -
- -
+
- -
- - + -
- - \ No newline at end of file +
+ + + +
+ +