Create actors for users on plugin update/user registration
This commit is contained in:
parent
3fc6fd546c
commit
e7cda74671
@ -60,10 +60,31 @@ function create_actors_table() {
|
||||
"
|
||||
CREATE TABLE IF NOT EXISTS activitypub_actors(
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
slug VARCHAR(255) UNIQUE NOT NULL,
|
||||
type VARCHAR(64)
|
||||
slug VARCHAR(64) UNIQUE NOT NULL,
|
||||
type VARCHAR(64) NOT NULL
|
||||
);
|
||||
"
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
For every user in the WP instance, create a new actor row for that user
|
||||
if it doesn't already exist
|
||||
*/
|
||||
function initialize_user_actors() {
|
||||
global $wpdb;
|
||||
$user_slugs = $wpdb->get_col(
|
||||
"SELECT user_nicename FROM wp_users;"
|
||||
);
|
||||
foreach ( $user_slugs as $user_slug ) {
|
||||
create_actor_from_user( $user_slug );
|
||||
}
|
||||
}
|
||||
|
||||
function create_actor_from_user( $user_slug ) {
|
||||
global $wpdb;
|
||||
$wpdb->query( $wpdb->prepare(
|
||||
"INSERT IGNORE INTO activitypub_actors(slug, type) VALUES(%s, 'user')", $user_slug
|
||||
) );
|
||||
}
|
||||
?>
|
||||
|
@ -8,8 +8,7 @@ require_once plugin_dir_path( __FILE__ ) . '/activities.php';
|
||||
|
||||
function get_actor( $request ) {
|
||||
$actor = $request['actor'];
|
||||
$user = get_user_by( 'slug', $actor );
|
||||
return \actors\get_actor( $user );
|
||||
return \actors\get_actor_by_slug( $user );
|
||||
}
|
||||
|
||||
function handle_activity( $request ) {
|
||||
|
@ -11,10 +11,16 @@ add_action( 'rest_api_init', function() {
|
||||
\api\register_routes();
|
||||
} );
|
||||
|
||||
add_action( 'user_register', function( $user_id ) {
|
||||
$slug = get_the_author_meta( 'user_nicename', $user_id );
|
||||
\actors\create_actor_from_user( $slug );
|
||||
} );
|
||||
|
||||
add_action( 'activitypub_init', function() {
|
||||
\activities\create_activities_table();
|
||||
\objects\create_object_table();
|
||||
\outbox\create_outbox_table();
|
||||
\actors\create_actors_table();
|
||||
\actors\initialize_user_actors();
|
||||
} );
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user