Skip to content

Commit

Permalink
👽️ Limit number of tags in matters to 5
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Mar 22, 2023
1 parent 708661c commit 012eede
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions likecoin/admin/matters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 );
Expand Down
9 changes: 7 additions & 2 deletions likecoin/admin/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 012eede

Please sign in to comment.