Date: Thu, 4 Jul 2024 17:59:37 +0200
Subject: [PATCH 08/22] some improvements and extra informations
---
includes/class-admin.php | 12 ++++++++++
includes/class-migration.php | 40 ++++++++++++++++++++++++++++++++++
includes/model/class-user.php | 41 ++++-------------------------------
templates/user-settings.php | 14 +++++++-----
4 files changed, 65 insertions(+), 42 deletions(-)
diff --git a/includes/class-admin.php b/includes/class-admin.php
index a8849e0f6..e7572e254 100644
--- a/includes/class-admin.php
+++ b/includes/class-admin.php
@@ -64,6 +64,8 @@ public static function admin_menu() {
$followers_list_page = \add_users_page( \__( 'Followers', 'activitypub' ), \__( 'Followers', 'activitypub' ), 'read', 'activitypub-followers-list', array( self::class, 'followers_list_page' ) );
\add_action( 'load-' . $followers_list_page, array( self::class, 'add_followers_list_help_tab' ) );
+
+ \add_users_page( \__( 'Extra Fields', 'activitypub' ), \__( 'Extra Fields', 'activitypub' ), 'read', esc_url( admin_url( '/edit.php?post_type=ap_extrafield' ) ) );
}
}
@@ -78,6 +80,16 @@ public static function admin_notices() {
$admin_notice = \__( 'You are using the ActivityPub plugin with a permalink structure of "plain". This will prevent ActivityPub from working. Please go to "Settings" / "Permalinks" and choose a permalink structure other than "plain".', 'activitypub' );
self::show_admin_notice( $admin_notice, 'error' );
}
+
+ $current_screen = get_current_screen();
+
+ if ( isset( $current_screen->id ) && 'edit-ap_extrafield' === $current_screen->id ) {
+ ?>
+
+
+
+ add_cap( 'activitypub' );
}
}
+
+ public static function generate_extra_fields( $user_id ) {
+ $blog = array(
+ 'post_type' => 'ap_extrafield',
+ 'post_title' => \__( 'Blog', 'activitypub' ),
+ 'post_status' => 'publish',
+ 'post_author' => $user_id,
+ // format to block editor format
+ 'post_content' => '' . \wp_parse_url( \home_url( '/' ), \PHP_URL_HOST ) . '
',
+ 'comment_status' => 'closed',
+ );
+
+ wp_insert_post( $blog );
+
+ $profile = array(
+ 'post_type' => 'ap_extrafield',
+ 'post_title' => \__( 'Profile', 'activitypub' ),
+ 'post_status' => 'publish',
+ 'post_author' => $user_id,
+ // format to block editor format
+ 'post_content' => '' . \wp_parse_url( \get_author_posts_url( $user_id ), \PHP_URL_HOST ) . '
',
+ 'comment_status' => 'closed',
+ );
+
+ wp_insert_post( $profile );
+
+ if ( \get_the_author_meta( 'user_url', $user_id ) ) {
+ $homepage = array(
+ 'post_type' => 'ap_extrafield',
+ 'post_title' => \__( 'Homepage', 'activitypub' ),
+ 'post_status' => 'publish',
+ 'post_author' => $user_id,
+ // format to block editor format
+ 'post_content' => '' . \wp_parse_url( \get_the_author_meta( 'user_url', $user_id ), \PHP_URL_HOST ) . '
',
+ 'comment_status' => 'closed',
+ );
+
+ wp_insert_post( $homepage );
+ }
+ }
}
diff --git a/includes/model/class-user.php b/includes/model/class-user.php
index d8778f77d..cfcf0f8b9 100644
--- a/includes/model/class-user.php
+++ b/includes/model/class-user.php
@@ -3,6 +3,7 @@
use WP_Query;
use WP_Error;
+use Activitypub\Migration;
use Activitypub\Signature;
use Activitypub\Model\Blog;
use Activitypub\Activity\Actor;
@@ -242,8 +243,9 @@ public function get_attachment() {
)
);
+ $attachments = array();
+
if ( $extra_fields->have_posts() ) {
- $attachments = array();
foreach ( $extra_fields->posts as $post ) {
$content = \get_the_content( null, false, $post );
$content = \make_clickable( $content );
@@ -265,44 +267,9 @@ public function get_attachment() {
),
);
}
- return $attachments;
- }
-
- $extra_fields = array();
-
- $extra_fields[] = array(
- 'type' => 'PropertyValue',
- 'name' => \__( 'Blog', 'activitypub' ),
- 'value' => \html_entity_decode(
- '' . \wp_parse_url( \home_url( '/' ), \PHP_URL_HOST ) . '',
- \ENT_QUOTES,
- 'UTF-8'
- ),
- );
-
- $extra_fields[] = array(
- 'type' => 'PropertyValue',
- 'name' => \__( 'Profile', 'activitypub' ),
- 'value' => \html_entity_decode(
- '' . \wp_parse_url( \get_author_posts_url( $this->get__id() ), \PHP_URL_HOST ) . '',
- \ENT_QUOTES,
- 'UTF-8'
- ),
- );
-
- if ( \get_the_author_meta( 'user_url', $this->get__id() ) ) {
- $extra_fields[] = array(
- 'type' => 'PropertyValue',
- 'name' => \__( 'Website', 'activitypub' ),
- 'value' => \html_entity_decode(
- '' . \wp_parse_url( \get_the_author_meta( 'user_url', $this->get__id() ), \PHP_URL_HOST ) . '',
- \ENT_QUOTES,
- 'UTF-8'
- ),
- );
}
- return $extra_fields;
+ return $attachments;
}
/**
diff --git a/templates/user-settings.php b/templates/user-settings.php
index 5bd8e57a0..2dcdc5761 100644
--- a/templates/user-settings.php
+++ b/templates/user-settings.php
@@ -34,6 +34,8 @@
+
+
+
From 039bba2d13bdbf130110f5d0351416efe5d3d652 Mon Sep 17 00:00:00 2001
From: Matthias Pfefferle
Date: Fri, 5 Jul 2024 07:24:06 +0200
Subject: [PATCH 09/22] description
---
includes/class-admin.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/includes/class-admin.php b/includes/class-admin.php
index e7572e254..fa1f41696 100644
--- a/includes/class-admin.php
+++ b/includes/class-admin.php
@@ -86,7 +86,7 @@ public static function admin_notices() {
if ( isset( $current_screen->id ) && 'edit-ap_extrafield' === $current_screen->id ) {
?>
-
+
Date: Fri, 5 Jul 2024 08:23:31 +0200
Subject: [PATCH 10/22] use nopaging instead
---
includes/model/class-user.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/includes/model/class-user.php b/includes/model/class-user.php
index cfcf0f8b9..93591e8e2 100644
--- a/includes/model/class-user.php
+++ b/includes/model/class-user.php
@@ -236,10 +236,10 @@ public function get_endpoints() {
public function get_attachment() {
$extra_fields = new WP_Query(
array(
- 'post_type' => 'ap_extrafield',
- 'posts_per_page' => -1,
- 'status' => 'publish',
- 'author' => $this->get__id(),
+ 'post_type' => 'ap_extrafield',
+ 'nopaging' => true,
+ 'status' => 'publish',
+ 'author' => $this->get__id(),
)
);
From cfe9a11e3e688a059aea24171e28bd8e7639ed95 Mon Sep 17 00:00:00 2001
From: Matthias Pfefferle
Date: Mon, 8 Jul 2024 11:43:05 +0200
Subject: [PATCH 11/22] add blog url
---
includes/model/class-blog.php | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/includes/model/class-blog.php b/includes/model/class-blog.php
index cc515385c..70109683b 100644
--- a/includes/model/class-blog.php
+++ b/includes/model/class-blog.php
@@ -368,4 +368,28 @@ public function get_indexable() {
return false;
}
}
+
+ /**
+ * Extend the User-Output with Attachments.
+ *
+ * @return array The extended User-Output.
+ */
+ public function get_attachment() {
+ $array = array();
+
+ $array[] = array(
+ 'type' => 'PropertyValue',
+ 'name' => \__( 'Blog', 'activitypub' ),
+ 'value' => \html_entity_decode(
+ sprintf(
+ '%s',
+ \esc_attr( \home_url( '/' ) ),
+ \home_url( '/' ),
+ \wp_parse_url( \home_url( '/' ), \PHP_URL_HOST )
+ ),
+ \ENT_QUOTES,
+ 'UTF-8'
+ ),
+ );
+ }
}
From 3ddbdae7115737fb3def146ee594594758f970fb Mon Sep 17 00:00:00 2001
From: Matthias Pfefferle
Date: Mon, 8 Jul 2024 11:43:12 +0200
Subject: [PATCH 12/22] formatting
---
includes/class-migration.php | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/includes/class-migration.php b/includes/class-migration.php
index 78ca6288e..0123759cd 100644
--- a/includes/class-migration.php
+++ b/includes/class-migration.php
@@ -287,24 +287,24 @@ private static function add_activitypub_capability() {
public static function generate_extra_fields( $user_id ) {
$blog = array(
- 'post_type' => 'ap_extrafield',
- 'post_title' => \__( 'Blog', 'activitypub' ),
- 'post_status' => 'publish',
- 'post_author' => $user_id,
+ 'post_type' => 'ap_extrafield',
+ 'post_title' => \__( 'Blog', 'activitypub' ),
+ 'post_status' => 'publish',
+ 'post_author' => $user_id,
// format to block editor format
- 'post_content' => '' . \wp_parse_url( \home_url( '/' ), \PHP_URL_HOST ) . ' ',
+ 'post_content' => '' . \wp_parse_url( \home_url( '/' ), \PHP_URL_HOST ) . ' ',
'comment_status' => 'closed',
);
wp_insert_post( $blog );
$profile = array(
- 'post_type' => 'ap_extrafield',
- 'post_title' => \__( 'Profile', 'activitypub' ),
- 'post_status' => 'publish',
- 'post_author' => $user_id,
+ 'post_type' => 'ap_extrafield',
+ 'post_title' => \__( 'Profile', 'activitypub' ),
+ 'post_status' => 'publish',
+ 'post_author' => $user_id,
// format to block editor format
- 'post_content' => '' . \wp_parse_url( \get_author_posts_url( $user_id ), \PHP_URL_HOST ) . ' ',
+ 'post_content' => '' . \wp_parse_url( \get_author_posts_url( $user_id ), \PHP_URL_HOST ) . ' ',
'comment_status' => 'closed',
);
@@ -312,12 +312,12 @@ public static function generate_extra_fields( $user_id ) {
if ( \get_the_author_meta( 'user_url', $user_id ) ) {
$homepage = array(
- 'post_type' => 'ap_extrafield',
- 'post_title' => \__( 'Homepage', 'activitypub' ),
- 'post_status' => 'publish',
- 'post_author' => $user_id,
+ 'post_type' => 'ap_extrafield',
+ 'post_title' => \__( 'Homepage', 'activitypub' ),
+ 'post_status' => 'publish',
+ 'post_author' => $user_id,
// format to block editor format
- 'post_content' => '' . \wp_parse_url( \get_the_author_meta( 'user_url', $user_id ), \PHP_URL_HOST ) . ' ',
+ 'post_content' => '' . \wp_parse_url( \get_the_author_meta( 'user_url', $user_id ), \PHP_URL_HOST ) . ' ',
'comment_status' => 'closed',
);
From 483b13620eb95bb21bbdabdd0849c639e0fe0e34 Mon Sep 17 00:00:00 2001
From: Matthias Pfefferle
Date: Mon, 8 Jul 2024 12:52:01 +0200
Subject: [PATCH 13/22] formatting
---
includes/class-admin.php | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/includes/class-admin.php b/includes/class-admin.php
index fa1f41696..e2f4e0989 100644
--- a/includes/class-admin.php
+++ b/includes/class-admin.php
@@ -403,9 +403,7 @@ public static function list_posts() {
\add_action(
'pre_get_posts',
function ( $query ) {
- if (
- $query->get( 'post_type' ) === 'ap_extrafield'
- ) {
+ if ( $query->get( 'post_type' ) === 'ap_extrafield' ) {
$query->set( 'author', get_current_user_id() );
}
}
From 6e45ed148de199070edf4eda387cc8e7fe3723c4 Mon Sep 17 00:00:00 2001
From: Matthias Pfefferle
Date: Mon, 8 Jul 2024 15:40:56 +0200
Subject: [PATCH 14/22] some cosmetics
---
includes/class-admin.php | 44 ++++++++++++++++++++++++++++++++++---
templates/user-settings.php | 14 +++++++++---
2 files changed, 52 insertions(+), 6 deletions(-)
diff --git a/includes/class-admin.php b/includes/class-admin.php
index e2f4e0989..267a5982c 100644
--- a/includes/class-admin.php
+++ b/includes/class-admin.php
@@ -31,10 +31,13 @@ public static function init() {
\add_filter( 'comment_row_actions', array( self::class, 'comment_row_actions' ), 10, 2 );
\add_filter( 'manage_edit-comments_columns', array( static::class, 'manage_comment_columns' ) );
- \add_filter( 'manage_comments_custom_column', array( static::class, 'manage_comments_custom_column' ), 9, 2 );
+ \add_action( 'manage_comments_custom_column', array( static::class, 'manage_comments_custom_column' ), 9, 2 );
+
+ \add_filter( 'manage_posts_columns', array( static::class, 'manage_post_columns' ), 10, 2 );
+ \add_action( 'manage_posts_custom_column', array( self::class, 'manage_posts_custom_column' ), 10, 2 );
\add_filter( 'manage_users_columns', array( self::class, 'manage_users_columns' ), 10, 1 );
- \add_filter( 'manage_users_custom_column', array( self::class, 'manage_users_custom_column' ), 10, 3 );
+ \add_action( 'manage_users_custom_column', array( self::class, 'manage_users_custom_column' ), 10, 3 );
\add_filter( 'bulk_actions-users', array( self::class, 'user_bulk_options' ) );
\add_filter( 'handle_bulk_actions-users', array( self::class, 'handle_bulk_request' ), 10, 3 );
@@ -453,12 +456,28 @@ public static function manage_users_columns( $columns ) {
* @param array $columns the list of column names
*/
public static function manage_comment_columns( $columns ) {
- $columns['comment_type'] = esc_attr__( 'Comment-Type', 'activitypub' );
+ $columns['comment_type'] = esc_attr__( 'Comment-Type', 'activitypub' );
$columns['comment_protocol'] = esc_attr__( 'Protocol', 'activitypub' );
return $columns;
}
+ /**
+ * Add "post_content" as column for Extra-Fields in WP-Admin
+ *
+ * @param array $columns Tthe list of column names.
+ * @param string $post_type The post type.
+ */
+ public static function manage_post_columns( $columns, $post_type ) {
+ if ( 'ap_extrafield' === $post_type ) {
+ $after_key = 'title';
+ $index = array_search( $after_key, array_keys( $columns ), true );
+ $columns = array_slice( $columns, 0, $index + 1 ) + array( 'extra_field_content' => esc_attr__( 'Content', 'activitypub' ) ) + $columns;
+ }
+
+ return $columns;
+ }
+
/**
* Add "comment-type" and "protocol" as column in WP-Admin
*
@@ -500,6 +519,25 @@ public static function manage_users_custom_column( $output, $column_name, $user_
}
}
+ /**
+ * Add a column "extra_field_content" to the post list view
+ *
+ * @param string $column_name The column name.
+ * @param int $post_id The post ID.
+ *
+ * @return void
+ */
+ public static function manage_posts_custom_column( $column_name, $post_id ) {
+ $post = get_post( $post_id );
+
+ if ( 'extra_field_content' === $column_name ) {
+ $post = get_post( $post_id );
+ if ( 'ap_extrafield' === $post->post_type ) {
+ echo esc_attr( wp_strip_all_tags( $post->post_content ) );
+ }
+ }
+ }
+
/**
* Add options to the Bulk dropdown on the users page
*
diff --git a/templates/user-settings.php b/templates/user-settings.php
index 2dcdc5761..9c548ab9a 100644
--- a/templates/user-settings.php
+++ b/templates/user-settings.php
@@ -51,14 +51,22 @@
post_title ); ?> |
|
- |
+
+
+
+
+ |
-
-
+
+
+
+
+
+
|
From 896d82594d4fb741f0ba956872a9c23d26c63aec Mon Sep 17 00:00:00 2001
From: Matthias Pfefferle
Date: Mon, 8 Jul 2024 16:29:07 +0200
Subject: [PATCH 15/22] return attachments
---
includes/model/class-blog.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/includes/model/class-blog.php b/includes/model/class-blog.php
index 70109683b..864644d33 100644
--- a/includes/model/class-blog.php
+++ b/includes/model/class-blog.php
@@ -391,5 +391,7 @@ public function get_attachment() {
'UTF-8'
),
);
+
+ return $array;
}
}
From 300c4362677e70e13d94b4836403ad16a8d69a08 Mon Sep 17 00:00:00 2001
From: Matthias Pfefferle
Date: Mon, 8 Jul 2024 16:47:39 +0200
Subject: [PATCH 16/22] formatting
---
integration/class-buddypress.php | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/integration/class-buddypress.php b/integration/class-buddypress.php
index 45cfc0d63..8d71c1d23 100644
--- a/integration/class-buddypress.php
+++ b/integration/class-buddypress.php
@@ -32,7 +32,12 @@ public static function add_user_metadata( $object, $author_id ) {
'type' => 'PropertyValue',
'name' => \__( 'Profile', 'activitypub' ),
'value' => \html_entity_decode(
- '' . \wp_parse_url( \bp_core_get_user_domain( $author_id ), \PHP_URL_HOST ) . '',
+ sprintf(
+ '%s',
+ \esc_attr( bp_core_get_user_domain( $author_id ) ),
+ \bp_core_get_user_domain( $author_id ),
+ \wp_parse_url( \bp_core_get_user_domain( $author_id ), \PHP_URL_HOST )
+ ),
\ENT_QUOTES,
'UTF-8'
),
@@ -51,7 +56,12 @@ public static function add_user_metadata( $object, $author_id ) {
'type' => 'PropertyValue',
'name' => $blog->blogname,
'value' => \html_entity_decode(
- '' . \wp_parse_url( $blog->siteurl, \PHP_URL_HOST ) . '',
+ sprintf(
+ '%s',
+ \esc_attr( $blog->siteurl ),
+ $blog->siteurl,
+ \wp_parse_url( $blog->siteurl, \PHP_URL_HOST )
+ ),
\ENT_QUOTES,
'UTF-8'
),
From f7d9b7d7dfaf379bf6f65529f11f634052050a6f Mon Sep 17 00:00:00 2001
From: Matthias Pfefferle
Date: Mon, 8 Jul 2024 16:51:03 +0200
Subject: [PATCH 17/22] formatting
---
includes/class-webfinger.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/includes/class-webfinger.php b/includes/class-webfinger.php
index 3233fcb5c..78c8b4b2f 100644
--- a/includes/class-webfinger.php
+++ b/includes/class-webfinger.php
@@ -174,7 +174,7 @@ public static function get_data( $uri ) {
return $data;
}
- $webfinger_url = 'https://' . $host . '/.well-known/webfinger?resource=' . rawurlencode( $identifier );
+ $webfinger_url = sprintf( 'https://%s/.well-known/webfinger?resource=%s', $host, rawurlencode( $identifier ) );
$response = wp_safe_remote_get(
$webfinger_url,
From 68404f0fd55100d261fdc65dd9ed4196c42c71b6 Mon Sep 17 00:00:00 2001
From: Matthias Pfefferle
Date: Mon, 8 Jul 2024 18:50:45 +0200
Subject: [PATCH 18/22] add default extra fields
---
includes/collection/class-users.php | 37 ++----------
includes/functions.php | 90 +++++++++++++++++++++++++++++
includes/model/class-user.php | 52 +++++++----------
templates/user-settings.php | 13 +----
4 files changed, 121 insertions(+), 71 deletions(-)
diff --git a/includes/collection/class-users.php b/includes/collection/class-users.php
index b210504e9..e4596b878 100644
--- a/includes/collection/class-users.php
+++ b/includes/collection/class-users.php
@@ -8,6 +8,8 @@
use Activitypub\Model\Application;
use function Activitypub\object_to_uri;
+use function Activitypub\normalize_url;
+use function Activitypub\normalize_host;
use function Activitypub\url_to_authorid;
use function Activitypub\is_user_disabled;
@@ -182,8 +184,8 @@ public static function get_by_resource( $resource ) {
// check for http(s)://blog.example.com/
if (
- self::normalize_url( site_url() ) === self::normalize_url( $resource ) ||
- self::normalize_url( home_url() ) === self::normalize_url( $resource )
+ normalize_url( site_url() ) === normalize_url( $resource ) ||
+ normalize_url( home_url() ) === normalize_url( $resource )
) {
return self::get_by_id( self::BLOG_USER_ID );
}
@@ -197,8 +199,8 @@ public static function get_by_resource( $resource ) {
case 'acct':
$resource = \str_replace( 'acct:', '', $resource );
$identifier = \substr( $resource, 0, \strrpos( $resource, '@' ) );
- $host = self::normalize_host( \substr( \strrchr( $resource, '@' ), 1 ) );
- $blog_host = self::normalize_host( \wp_parse_url( \home_url( '/' ), \PHP_URL_HOST ) );
+ $host = normalize_host( \substr( \strrchr( $resource, '@' ), 1 ) );
+ $blog_host = normalize_host( \wp_parse_url( \home_url( '/' ), \PHP_URL_HOST ) );
if ( $blog_host !== $host ) {
return new WP_Error(
@@ -253,33 +255,6 @@ public static function get_by_various( $id ) {
return self::get_by_username( $id );
}
- /**
- * Normalize a host.
- *
- * @param string $host The host.
- *
- * @return string The normalized host.
- */
- public static function normalize_host( $host ) {
- return \str_replace( 'www.', '', $host );
- }
-
- /**
- * Normalize a URL.
- *
- * @param string $url The URL.
- *
- * @return string The normalized URL.
- */
- public static function normalize_url( $url ) {
- $url = \untrailingslashit( $url );
- $url = \str_replace( 'https://', '', $url );
- $url = \str_replace( 'http://', '', $url );
- $url = \str_replace( 'www.', '', $url );
-
- return $url;
- }
-
/**
* Get the User collection.
*
diff --git a/includes/functions.php b/includes/functions.php
index bf923a159..9fb51ceba 100644
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -1,6 +1,7 @@
'ap_extrafield',
+ 'nopaging' => true,
+ 'status' => 'publish',
+ 'author' => $user_id,
+ )
+ );
+
+ if ( $extra_fields->have_posts() ) {
+ return $extra_fields->posts;
+ }
+
+ $extra_fields = array();
+ $already_migrated = \get_user_meta( $user_id, 'activitypub_default_extra_fields', true );
+
+ if ( $already_migrated ) {
+ return $extra_fields;
+ }
+
+ $defaults = array(
+ \__( 'Blog', 'activitypub' ) => \home_url( '/' ),
+ \__( 'Profile', 'activitypub' ) => \get_author_posts_url( $user_id ),
+ \__( 'Homepage', 'activitypub' ) => \get_the_author_meta( 'user_url', $user_id ),
+ );
+
+ foreach ( $defaults as $title => $url ) {
+ if ( ! $url ) {
+ continue;
+ }
+
+ $extra_field = array(
+ 'post_type' => 'ap_extrafield',
+ 'post_title' => $title,
+ 'post_status' => 'publish',
+ 'post_author' => $user_id,
+ 'post_content' => sprintf(
+ '%s
',
+ \esc_attr( $url ),
+ $url,
+ \wp_parse_url( $url, \PHP_URL_HOST )
+ ),
+ 'comment_status' => 'closed',
+ );
+
+ $extra_field_id = wp_insert_post( $extra_field );
+ $extra_fields[] = get_post( $extra_field_id );
+ }
+
+ \update_user_meta( $user_id, 'activitypub_default_extra_fields', true );
+
+ return $extra_fields;
+}
diff --git a/includes/model/class-user.php b/includes/model/class-user.php
index 93591e8e2..ac7879c66 100644
--- a/includes/model/class-user.php
+++ b/includes/model/class-user.php
@@ -11,6 +11,7 @@
use function Activitypub\is_user_disabled;
use function Activitypub\get_rest_url_by_path;
+use function Activitypub\get_actor_extra_fields;
class User extends Actor {
/**
@@ -234,39 +235,30 @@ public function get_endpoints() {
* @return array The extended User-Output.
*/
public function get_attachment() {
- $extra_fields = new WP_Query(
- array(
- 'post_type' => 'ap_extrafield',
- 'nopaging' => true,
- 'status' => 'publish',
- 'author' => $this->get__id(),
- )
- );
+ $extra_fields = get_actor_extra_fields( \get_current_user_id() );
$attachments = array();
- if ( $extra_fields->have_posts() ) {
- foreach ( $extra_fields->posts as $post ) {
- $content = \get_the_content( null, false, $post );
- $content = \make_clickable( $content );
- $content = \do_blocks( $content );
- $content = \wptexturize( $content );
- $content = \wp_filter_content_tags( $content );
- // replace script and style elements
- $content = \preg_replace( '@<(script|style)[^>]*?>.*?\\1>@si', '', $content );
- $content = \strip_shortcodes( $content );
- $content = \trim( \preg_replace( '/[\n\r\t]/', '', $content ) );
-
- $attachments[] = array(
- 'type' => 'PropertyValue',
- 'name' => \get_the_title( $post ),
- 'value' => \html_entity_decode(
- $content,
- \ENT_QUOTES,
- 'UTF-8'
- ),
- );
- }
+ foreach ( $extra_fields as $post ) {
+ $content = \get_the_content( null, false, $post );
+ $content = \make_clickable( $content );
+ $content = \do_blocks( $content );
+ $content = \wptexturize( $content );
+ $content = \wp_filter_content_tags( $content );
+ // replace script and style elements
+ $content = \preg_replace( '@<(script|style)[^>]*?>.*?\\1>@si', '', $content );
+ $content = \strip_shortcodes( $content );
+ $content = \trim( \preg_replace( '/[\n\r\t]/', '', $content ) );
+
+ $attachments[] = array(
+ 'type' => 'PropertyValue',
+ 'name' => \get_the_title( $post ),
+ 'value' => \html_entity_decode(
+ $content,
+ \ENT_QUOTES,
+ 'UTF-8'
+ ),
+ );
}
return $attachments;
diff --git a/templates/user-settings.php b/templates/user-settings.php
index 9c548ab9a..9489acbd8 100644
--- a/templates/user-settings.php
+++ b/templates/user-settings.php
@@ -37,17 +37,10 @@