Fix shortcode output.

This commit is contained in:
Greg 2023-01-16 12:51:18 -05:00
parent 4a17bb4ea7
commit bc8e46e121

View file

@ -29,11 +29,6 @@ class Post {
$this->object_type = $this->generate_object_type(); $this->object_type = $this->generate_object_type();
} }
$shortcodes = array( 'ap_title', 'ap_excerpt', 'ap_content', 'ap_permalink', 'ap_shortlink', 'ap_hashtags', 'ap_thumbnail', 'ap_image', 'ap_hashcats', 'ap_author', 'ap_authorurl', 'ap_blogurl', 'ap_blogname', 'ap_blogdesc', 'ap_date', 'ap_time', 'ap_datetime' );
foreach( $shortcodes as $tag ) {
add_shortcode( $tag, [ $this, 'shortcode_content' ] );
}
} }
public function __call( $method, $params ) { public function __call( $method, $params ) {
@ -246,9 +241,11 @@ class Post {
$tag = strtolower( $tag ); $tag = strtolower( $tag );
$post = $this->post; $post = $this->post;
$text = '';
switch( $tag ) { switch( $tag ) {
case 'ap_title': case 'ap_title':
echo \get_the_title( $post->ID ); $text = \get_the_title( $post->ID );
break; break;
case 'ap_excerpt': case 'ap_excerpt':
@ -260,70 +257,72 @@ class Post {
if( $length == 0 ) { $length = ACTIVITYPUB_EXCERPT_LENGTH; } if( $length == 0 ) { $length = ACTIVITYPUB_EXCERPT_LENGTH; }
echo $this->get_the_post_excerpt( $length ); $text = $this->get_the_post_excerpt( $length );
break; break;
case 'ap_content': case 'ap_content':
echo $this->get_the_post_content(); $text = $this->get_the_post_content();
break; break;
case 'ap_permalink': case 'ap_permalink':
echo $this->get_the_post_link( 'permalink' ); $text = $this->get_the_post_link( 'permalink' );
break; break;
case 'ap_shortlink': case 'ap_shortlink':
echo $this->get_the_post_link( 'shortlink' ); $text = $this->get_the_post_link( 'shortlink' );
break; break;
case 'ap_hashtags': case 'ap_hashtags':
echo $this->get_the_post_hashtags(); $text = $this->get_the_post_hashtags();
break; break;
case 'ap_thumbnail': case 'ap_thumbnail':
echo $this->get_the_post_image( 'thumbnail' ); $text = $this->get_the_post_image( 'thumbnail' );
break; break;
case 'ap_image': case 'ap_image':
echo $this->get_the_post_image(); $text = $this->get_the_post_image();
break; break;
case 'ap_hashcats': case 'ap_hashcats':
echo $this->get_the_post_categories(); $text = $this->get_the_post_categories();
break; break;
case 'ap_author': case 'ap_author':
echo $this->get_the_post_author(); $text = $this->get_the_post_author();
break; break;
case 'ap_authorurl': case 'ap_authorurl':
echo $this->get_the_post_author_url(); $text = $this->get_the_post_author_url();
break; break;
case 'ap_blogurl': case 'ap_blogurl':
echo \get_bloginfo('url'); $text = \get_bloginfo('url');
break; break;
case 'ap_blogname': case 'ap_blogname':
echo \get_bloginfo('name'); $text = \get_bloginfo('name');
break; break;
case 'ap_blogdesc': case 'ap_blogdesc':
echo \get_bloginfo('description'); $text = \get_bloginfo('description');
break; break;
case 'ap_date': case 'ap_date':
echo $this->get_the_post_date( 'time' ); $text = $this->get_the_post_date( 'time' );
break; break;
case 'ap_time': case 'ap_time':
echo $this->get_the_post_date( 'date' ); $text = $this->get_the_post_date( 'date' );
break; break;
case 'ap_datetime': case 'ap_datetime':
echo $this->get_the_post_date( 'both' ); $text = $this->get_the_post_date( 'both' );
break; break;
} }
return $text;
} }
/** /**
@ -335,6 +334,12 @@ class Post {
$post = $this->post; $post = $this->post;
$content = $this->get_post_content_template(); $content = $this->get_post_content_template();
$shortcodes = array( 'ap_title', 'ap_excerpt', 'ap_content', 'ap_permalink', 'ap_shortlink', 'ap_hashtags', 'ap_thumbnail', 'ap_image', 'ap_hashcats', 'ap_author', 'ap_authorurl', 'ap_blogurl', 'ap_blogname', 'ap_blogdesc', 'ap_date', 'ap_time', 'ap_datetime' );
foreach( $shortcodes as $tag ) {
add_shortcode( $tag, [ $this, 'shortcode_content' ] );
}
// Fill in the shortcodes. // Fill in the shortcodes.
$content = do_shortcode( $content ); $content = do_shortcode( $content );