| @@ -63,11 +63,8 @@ | ||
| 63 | 63 | // Follower Cleanups |
| 64 | 64 | \add_action( 'activitypub_update_followers', array( self::class, 'update_followers' ) ); |
| 65 | 65 | \add_action( 'activitypub_cleanup_followers', array( self::class, 'cleanup_followers' ) ); |
| 66 | 66 | |
| 67 | - // Migration | |
| 68 | - \add_action( 'admin_init', array( self::class, 'schedule_migration' ) ); | |
| 69 | - | |
| 70 | 67 | // profile updates for blog options |
| 71 | 68 | if ( ! is_user_type_disabled( 'blog' ) ) { |
| 72 | 69 | \add_action( 'update_option_site_icon', array( self::class, 'blog_user_update' ) ); |
| 73 | 70 | \add_action( 'update_option_blogdescription', array( self::class, 'blog_user_update' ) ); |
| @@ -119,8 +116,18 @@ | ||
| 119 | 116 | */ |
| 120 | 117 | public static function schedule_post_activity( $new_status, $old_status, $post ) { |
| 121 | 118 | $post = get_post( $post ); |
| 122 | 119 | |
| 120 | + if ( 'ap_extrafield' === $post->post_type ) { | |
| 121 | + self::schedule_profile_update( $post->post_author ); | |
| 122 | + return; | |
| 123 | + } | |
| 124 | + | |
| 125 | + if ( 'ap_extrafield_blog' === $post->post_type ) { | |
| 126 | + self::schedule_profile_update( 0 ); | |
| 127 | + return; | |
| 128 | + } | |
| 129 | + | |
| 123 | 130 | // Do not send activities if post is password protected. |
| 124 | 131 | if ( \post_password_required( $post ) ) { |
| 125 | 132 | return; |
| 126 | 133 | } |
| @@ -132,11 +139,19 @@ | ||
| 132 | 139 | } |
| 133 | 140 | |
| 134 | 141 | $type = false; |
| 135 | 142 | |
| 136 | - if ( 'publish' === $new_status && 'publish' !== $old_status ) { | |
| 143 | + if ( | |
| 144 | + 'publish' === $new_status && | |
| 145 | + 'publish' !== $old_status | |
| 146 | + ) { | |
| 137 | 147 | $type = 'Create'; |
| 138 | - } elseif ( 'publish' === $new_status ) { | |
| 148 | + } elseif ( | |
| 149 | + 'publish' === $new_status || | |
| 150 | + // We want to send updates for posts that are published and then moved to draft. | |
| 151 | + ( 'draft' === $new_status && | |
| 152 | + 'publish' === $old_status ) | |
| 153 | + ) { | |
| 139 | 154 | $type = 'Update'; |
| 140 | 155 | } elseif ( 'trash' === $new_status ) { |
| 141 | 156 | $type = 'Delete'; |
| 142 | 157 | } |
| @@ -144,22 +159,15 @@ | ||
| 144 | 159 | if ( empty( $type ) ) { |
| 145 | 160 | return; |
| 146 | 161 | } |
| 147 | 162 | |
| 148 | - \wp_schedule_single_event( | |
| 149 | - \time(), | |
| 150 | - 'activitypub_send_activity', | |
| 151 | - array( $post, $type ) | |
| 152 | - ); | |
| 163 | + $hook = 'activitypub_send_post'; | |
| 164 | + $args = array( $post->ID, $type ); | |
| 153 | 165 | |
| 154 | - \wp_schedule_single_event( | |
| 155 | - \time(), | |
| 156 | - sprintf( | |
| 157 | - 'activitypub_send_%s_activity', | |
| 158 | - \strtolower( $type ) | |
| 159 | - ), | |
| 160 | - array( $post ) | |
| 161 | - ); | |
| 166 | + if ( false === wp_next_scheduled( $hook, $args ) ) { | |
| 167 | + set_wp_object_state( $post, 'federate' ); | |
| 168 | + \wp_schedule_single_event( \time(), $hook, $args ); | |
| 169 | + } | |
| 162 | 170 | } |
| 163 | 171 | |
| 164 | 172 | /** |
| 165 | 173 | * Schedule Comment Activities |
| @@ -203,24 +211,15 @@ | ||
| 203 | 211 | if ( ! should_comment_be_federated( $comment ) ) { |
| 204 | 212 | return; |
| 205 | 213 | } |
| 206 | 214 | |
| 207 | - set_wp_object_state( $comment, 'federate' ); | |
| 215 | + $hook = 'activitypub_send_comment'; | |
| 216 | + $args = array( $comment->comment_ID, $type ); | |
| 208 | 217 | |
| 209 | - \wp_schedule_single_event( | |
| 210 | - \time(), | |
| 211 | - 'activitypub_send_activity', | |
| 212 | - array( $comment, $type ) | |
| 213 | - ); | |
| 214 | - | |
| 215 | - \wp_schedule_single_event( | |
| 216 | - \time(), | |
| 217 | - sprintf( | |
| 218 | - 'activitypub_send_%s_activity', | |
| 219 | - \strtolower( $type ) | |
| 220 | - ), | |
| 221 | - array( $comment ) | |
| 222 | - ); | |
| 218 | + if ( false === wp_next_scheduled( $hook, $args ) ) { | |
| 219 | + set_wp_object_state( $comment, 'federate' ); | |
| 220 | + \wp_schedule_single_event( \time(), $hook, $args ); | |
| 221 | + } | |
| 223 | 222 | } |
| 224 | 223 | |
| 225 | 224 | /** |
| 226 | 225 | * Update followers |
| @@ -271,8 +270,13 @@ | ||
| 271 | 270 | $follower->delete(); |
| 272 | 271 | } elseif ( empty( $meta ) || ! is_array( $meta ) || is_wp_error( $meta ) ) { |
| 273 | 272 | if ( $follower->count_errors() >= 5 ) { |
| 274 | 273 | $follower->delete(); |
| 274 | + \wp_schedule_single_event( | |
| 275 | + \time(), | |
| 276 | + 'activitypub_delete_actor_interactions', | |
| 277 | + array( $follower->get_id() ) | |
| 278 | + ); | |
| 275 | 279 | } else { |
| 276 | 280 | Followers::add_error( $follower->get__id(), $meta ); |
| 277 | 281 | } |
| 278 | 282 | } else { |
| @@ -281,19 +285,8 @@ | ||
| 281 | 285 | } |
| 282 | 286 | } |
| 283 | 287 | |
| 284 | 288 | /** |
| 285 | - * Schedule migration if DB-Version is not up to date. | |
| 286 | - * | |
| 287 | - * @return void | |
| 288 | - */ | |
| 289 | - public static function schedule_migration() { | |
| 290 | - if ( ! \wp_next_scheduled( 'activitypub_schedule_migration' ) && ! Migration::is_latest_version() ) { | |
| 291 | - \wp_schedule_single_event( \time(), 'activitypub_schedule_migration' ); | |
| 292 | - } | |
| 293 | - } | |
| 294 | - | |
| 295 | - /** | |
| 296 | 289 | * Send a profile update when relevant user meta is updated. |
| 297 | 290 | * |
| 298 | 291 | * @param int $meta_id Meta ID being updated. |
| 299 | 292 | * @param int $user_id User ID being updated. |
| @@ -302,14 +295,15 @@ | ||
| 302 | 295 | * @return void |
| 303 | 296 | */ |
| 304 | 297 | public static function user_meta_update( $meta_id, $user_id, $meta_key ) { |
| 305 | 298 | // don't bother if the user can't publish |
| 306 | - if ( ! \user_can( $user_id, 'publish_posts' ) ) { | |
| 299 | + if ( ! \user_can( $user_id, 'activitypub' ) ) { | |
| 307 | 300 | return; |
| 308 | 301 | } |
| 309 | 302 | // the user meta fields that affect a profile. |
| 310 | 303 | $fields = array( |
| 311 | - 'activitypub_user_description', | |
| 304 | + 'activitypub_description', | |
| 305 | + 'activitypub_header_image', | |
| 312 | 306 | 'description', |
| 313 | 307 | 'user_url', |
| 314 | 308 | 'display_name', |
| 315 | 309 | ); |
| @@ -326,9 +320,9 @@ | ||
| 326 | 320 | * @return void |
| 327 | 321 | */ |
| 328 | 322 | public static function user_update( $user_id ) { |
| 329 | 323 | // don't bother if the user can't publish |
| 330 | - if ( ! \user_can( $user_id, 'publish_posts' ) ) { | |
| 324 | + if ( ! \user_can( $user_id, 'activitypub' ) ) { | |
| 331 | 325 | return; |
| 332 | 326 | } |
| 333 | 327 | |
| 334 | 328 | self::schedule_profile_update( $user_id ); |
| @@ -335,9 +329,11 @@ | ||
| 335 | 329 | } |
| 336 | 330 | |
| 337 | 331 | /** |
| 338 | 332 | * Theme mods only have a dynamic filter so we fudge it like this. |
| 339 | - * @param mixed $value | |
| 333 | + * | |
| 334 | + * @param mixed $value | |
| 335 | + * | |
| 340 | 336 | * @return mixed |
| 341 | 337 | */ |
| 342 | 338 | public static function blog_user_update( $value = null ) { |
| 343 | 339 | self::schedule_profile_update( 0 ); |
| @@ -345,8 +341,9 @@ | ||
| 345 | 341 | } |
| 346 | 342 | |
| 347 | 343 | /** |
| 348 | 344 | * Send a profile update to all followers. Gets hooked into all relevant options/meta etc. |
| 345 | + * | |
| 349 | 346 | * @param int $user_id The user ID to update (Could be 0 for Blog-User). |
| 350 | 347 | */ |
| 351 | 348 | public static function schedule_profile_update( $user_id ) { |
| 352 | 349 | \wp_schedule_single_event( |