From 012eedef67a0ac9ddcb58333c02c1c6bb56db99c Mon Sep 17 00:00:00 2001 From: William Chong Date: Mon, 20 Mar 2023 16:09:59 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20Limit=20number=20of=20t?= =?UTF-8?q?ags=20in=20matters=20to=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- likecoin/admin/matters.php | 4 ++-- likecoin/admin/post.php | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/likecoin/admin/matters.php b/likecoin/admin/matters.php index 20b19f7f..6c6557c6 100644 --- a/likecoin/admin/matters.php +++ b/likecoin/admin/matters.php @@ -452,7 +452,7 @@ function likecoin_save_to_matters( $post_id, $post, $update = true ) { } $matters_draft_id = isset( $matters_info['draft_id'] ) ? $matters_info['draft_id'] : null; $title = apply_filters( 'the_title_rss', $post->post_title ); - $tags = likecoin_get_post_tags( $post ); + $tags = likecoin_get_post_tags( $post, 5 ); $api = LikeCoin_Matters_API::get_instance(); if ( $update && $matters_draft_id ) { @@ -507,7 +507,7 @@ function likecoin_publish_to_matters( $post_id, $post ) { } $matters_draft_id = isset( $matters_info['draft_id'] ) ? $matters_info['draft_id'] : null; $title = apply_filters( 'the_title_rss', $post->post_title ); - $tags = likecoin_get_post_tags( $post ); + $tags = likecoin_get_post_tags( $post, 5 ); $api = LikeCoin_Matters_API::get_instance(); if ( ! $matters_draft_id ) { $content = likecoin_filter_matters_post_content( $post ); diff --git a/likecoin/admin/post.php b/likecoin/admin/post.php index fa49d18a..0bbc4084 100644 --- a/likecoin/admin/post.php +++ b/likecoin/admin/post.php @@ -167,8 +167,9 @@ function likecoin_get_default_post_style() { * Get all tags names in a post * * @param WP_Post| $post Post object. + * @param integer| $limit Number of tags. */ -function likecoin_get_post_tags( $post ) { +function likecoin_get_post_tags( $post, $limit = 0 ) { $post_id = $post->ID; $func = function( $terms ) { return htmlspecialchars_decode( $terms->name ); @@ -178,7 +179,11 @@ function likecoin_get_post_tags( $post ) { if ( ! $post_tags ) { $post_tags = array(); } - return array_map( $func, $post_tags ); + $result = array_map( $func, $post_tags ); + if ( $limit ) { + $result = array_slice( $result, 0, $limit ); + } + return $result; } /**