'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 * */ function load_posts() { $author = ! empty( $_POST['author'] ) ? $_POST['author'] : get_current_user_id(); $page = ! empty( $_POST['page'] ) ? $_POST['page'] : 0; $args = array( 'post_type' => 'post', 'posts_per_page' => 10, 'offset' => ( $page - 1 ) * 10, 'author' => $author, '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 ); UM()->shortcodes()->set_args = array( 'posts' => $posts ); UM()->shortcodes()->load_template( 'profile/posts' ); wp_die(); } /** * 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]; $offset_n = $posts_per_page + $offset; UM()->shortcodes()->modified_args = "$post_type,$posts_per_page,$offset_n,$author"; 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'); } /** * Count posts by type * * @param string $user_id * @param string $post_type * * @return int|string */ function count_user_posts_by_type( $user_id= '', $post_type = 'post' ) { global $wpdb; if ( !$user_id ) $user_id = um_user( 'ID' ); 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" ); return $this->pretty_number_formatting( $count ); } /** * Count comments * * @param int|null $user_id * * @return int|string */ function count_user_comments( $user_id = null ) { global $wpdb; if ( !$user_id ) $user_id = um_user('ID'); 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'"); return $this->pretty_number_formatting( $count ); } /** * @param int $count * * @return string */ function pretty_number_formatting( $count ) { /** * UM hook * * @type filter * @title um_pretty_number_formatting * @description Change User Posts count value * @input_vars * [{"var":"$count","type":"int","desc":"Posts Count"}] * @change_log * ["Since: 2.0"] * @usage * * @example * */ return apply_filters( 'um_pretty_number_formatting', $count ); } } }