Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pfefferle committed Jul 17, 2023
1 parent d7e9d54 commit 964ceee
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 52 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ActivityPub #
**Contributors:** [pfefferle](https://profiles.wordpress.org/pfefferle/), [mediaformat](https://profiles.wordpress.org/mediaformat/), [akirk](https://profiles.wordpress.org/akirk/), [automattic](https://profiles.wordpress.org/automattic/)
**Contributors:** [automattic](https://profiles.wordpress.org/automattic/), [pfefferle](https://profiles.wordpress.org/pfefferle/), [mediaformat](https://profiles.wordpress.org/mediaformat/), [mattwiebe](https://profiles.wordpress.org/mattwiebe/), [akirk](https://profiles.wordpress.org/akirk/), [jeherve](https://profiles.wordpress.org/jeherve/), [nuriapena](https://profiles.wordpress.org/nuriapena/)
**Tags:** OStatus, fediverse, activitypub, activitystream
**Requires at least:** 4.7
**Tested up to:** 6.2
Expand Down
90 changes: 45 additions & 45 deletions includes/class-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public static function init() {
* @return string The post tags as hashtags.
*/
public static function hashtags( $atts, $content, $tag ) {
$post = get_item();
$item = get_item();

if ( ! $post ) {
if ( ! $item ) {
return '';
}

$tags = \get_the_tags( $post->ID );
$tags = \get_the_tags( $item->ID );

if ( ! $tags ) {
return '';
Expand Down Expand Up @@ -65,13 +65,13 @@ public static function hashtags( $atts, $content, $tag ) {
* @return string The post title.
*/
public static function title( $atts, $content, $tag ) {
$post = get_item();
$item = get_item();

if ( ! $post ) {
if ( ! $item ) {
return '';
}

return \wp_strip_all_tags( \get_the_title( $post->ID ), true );
return \wp_strip_all_tags( \get_the_title( $item->ID ), true );

}

Expand All @@ -85,9 +85,9 @@ public static function title( $atts, $content, $tag ) {
* @return string The post excerpt.
*/
public static function excerpt( $atts, $content, $tag ) {
$post = get_item();
$item = get_item();

if ( ! $post ) {
if ( ! $item ) {
return '';
}

Expand All @@ -103,11 +103,11 @@ public static function excerpt( $atts, $content, $tag ) {
$excerpt_length = ACTIVITYPUB_EXCERPT_LENGTH;
}

$excerpt = \get_post_field( 'post_excerpt', $post );
$excerpt = \get_post_field( 'post_excerpt', $item );

if ( '' === $excerpt ) {

$content = \get_post_field( 'post_content', $post );
$content = \get_post_field( 'post_content', $item );

// An empty string will make wp_trim_excerpt do stuff we do not want.
if ( '' !== $content ) {
Expand Down Expand Up @@ -188,22 +188,22 @@ public static function excerpt( $atts, $content, $tag ) {
* @return string The post content.
*/
public static function content( $atts, $content, $tag ) {
// prevent inception
remove_shortcode( 'ap_content' );

$post = get_item();
$item = get_item();

if ( ! $post ) {
if ( ! $item ) {
return '';
}

// prevent inception
remove_shortcode( 'ap_content' );

$atts = shortcode_atts(
array( 'apply_filters' => 'yes' ),
$atts,
$tag
);

$content = \get_post_field( 'post_content', $post );
$content = \get_post_field( 'post_content', $item );

if ( 'yes' === $atts['apply_filters'] ) {
$content = \apply_filters( 'the_content', $content );
Expand Down Expand Up @@ -233,9 +233,9 @@ public static function content( $atts, $content, $tag ) {
* @return string The post permalink.
*/
public static function permalink( $atts, $content, $tag ) {
$post = get_item();
$item = get_item();

if ( ! $post ) {
if ( ! $item ) {
return '';
}

Expand All @@ -248,12 +248,12 @@ public static function permalink( $atts, $content, $tag ) {
);

if ( 'url' === $atts['type'] ) {
return \esc_url( \get_permalink( $post->ID ) );
return \esc_url( \get_permalink( $item->ID ) );
}

return \sprintf(
'<a href="%1$s">%1$s</a>',
\esc_url( \get_permalink( $post->ID ) )
\esc_url( \get_permalink( $item->ID ) )
);
}

Expand All @@ -267,9 +267,9 @@ public static function permalink( $atts, $content, $tag ) {
* @return string The post shortlink.
*/
public static function shortlink( $atts, $content, $tag ) {
$post = get_item();
$item = get_item();

if ( ! $post ) {
if ( ! $item ) {
return '';
}

Expand All @@ -282,12 +282,12 @@ public static function shortlink( $atts, $content, $tag ) {
);

if ( 'url' === $atts['type'] ) {
return \esc_url( \wp_get_shortlink( $post->ID ) );
return \esc_url( \wp_get_shortlink( $item->ID ) );
}

return \sprintf(
'<a href="%1$s">%1$s</a>',
\esc_url( \wp_get_shortlink( $post->ID ) )
\esc_url( \wp_get_shortlink( $item->ID ) )
);
}

Expand All @@ -301,9 +301,9 @@ public static function shortlink( $atts, $content, $tag ) {
* @return string
*/
public static function image( $atts, $content, $tag ) {
$post = get_item();
$item = get_item();

if ( ! $post ) {
if ( ! $item ) {
return '';
}

Expand All @@ -325,7 +325,7 @@ public static function image( $atts, $content, $tag ) {
$size = $atts['type'];
}

$image = \get_the_post_thumbnail_url( $post->ID, $size );
$image = \get_the_post_thumbnail_url( $item->ID, $size );

if ( ! $image ) {
return '';
Expand All @@ -344,13 +344,13 @@ public static function image( $atts, $content, $tag ) {
* @return string The post categories as hashtags.
*/
public static function hashcats( $atts, $content, $tag ) {
$post = get_item();
$item = get_item();

if ( ! $post ) {
if ( ! $item ) {
return '';
}

$categories = \get_the_category( $post->ID );
$categories = \get_the_category( $item->ID );

if ( ! $categories ) {
return '';
Expand Down Expand Up @@ -379,13 +379,13 @@ public static function hashcats( $atts, $content, $tag ) {
* @return string The author name.
*/
public static function author( $atts, $content, $tag ) {
$post = get_item();
$item = get_item();

if ( ! $post ) {
if ( ! $item ) {
return '';
}

$name = \get_the_author_meta( 'display_name', $post->post_author );
$name = \get_the_author_meta( 'display_name', $item->post_author );

if ( ! $name ) {
return '';
Expand All @@ -404,13 +404,13 @@ public static function author( $atts, $content, $tag ) {
* @return string The author URL.
*/
public static function authorurl( $atts, $content, $tag ) {
$post = get_item();
$item = get_item();

if ( ! $post ) {
if ( ! $item ) {
return '';
}

$url = \get_the_author_meta( 'user_url', $post->post_author );
$url = \get_the_author_meta( 'user_url', $item->post_author );

if ( ! $url ) {
return '';
Expand Down Expand Up @@ -468,13 +468,13 @@ public static function blogdesc( $atts, $content, $tag ) {
* @return string The post date.
*/
public static function date( $atts, $content, $tag ) {
$post = get_item();
$item = get_item();

if ( ! $post ) {
if ( ! $item ) {
return '';
}

$datetime = \get_post_datetime( $post );
$datetime = \get_post_datetime( $item );
$dateformat = \get_option( 'date_format' );
$timeformat = \get_option( 'time_format' );

Expand All @@ -497,13 +497,13 @@ public static function date( $atts, $content, $tag ) {
* @return string The post time.
*/
public static function time( $atts, $content, $tag ) {
$post = get_item();
$item = get_item();

if ( ! $post ) {
if ( ! $item ) {
return '';
}

$datetime = \get_post_datetime( $post );
$datetime = \get_post_datetime( $item );
$dateformat = \get_option( 'date_format' );
$timeformat = \get_option( 'time_format' );

Expand All @@ -526,13 +526,13 @@ public static function time( $atts, $content, $tag ) {
* @return string The post date/time.
*/
public static function datetime( $atts, $content, $tag ) {
$post = get_item();
$item = get_item();

if ( ! $post ) {
if ( ! $item ) {
return '';
}

$datetime = \get_post_datetime( $post );
$datetime = \get_post_datetime( $item );
$dateformat = \get_option( 'date_format' );
$timeformat = \get_option( 'time_format' );

Expand Down
6 changes: 3 additions & 3 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,15 @@ function get_item() {
return null;
}

if ( ! \in_array( $post->post_type, \get_post_types_by_support( 'activitypub' ), true ) ) {
if ( 'publish' !== \get_post_status( $post ) ) {
return null;
}

if ( 'publish' !== $post->post_status ) {
if ( \post_password_required( $post ) ) {
return null;
}

if ( \post_password_required( $post ) ) {
if ( ! \in_array( \get_post_type( $post ), \get_post_types_by_support( 'activitypub' ), true ) ) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
=== ActivityPub ===
Contributors: pfefferle, mediaformat, akirk, automattic
Contributors: automattic, pfefferle, mediaformat, mattwiebe, akirk, jeherve, nuriapena
Tags: OStatus, fediverse, activitypub, activitystream
Requires at least: 4.7
Tested up to: 6.2
Expand Down
3 changes: 1 addition & 2 deletions tests/test-class-activitypub-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ public function test_password_protected_content() {
$post->post_date_gmt = current_time( 'mysql', 1 );
$post->post_title = 'Some title or other';
$post->post_content = '<script>test</script>hallo<script type="javascript">{"asdf": "qwerty"}</script><style></style>';
$post->post_status = 'publish';
$post->comment_status = 'closed';
$post->ping_status = 'closed';
$post->post_name = 'fake-page-' . rand( 1, 99999 ); // append random number to avoid clash
$post->post_type = 'page';
$post->post_password = 'abc';
$post->filter = 'raw'; // important!
$post->post_password = 'abc';

$content = '[ap_content]';

Expand Down

0 comments on commit 964ceee

Please sign in to comment.