repository = $repository; $this->builder = $builder; } /** * Initializes the integration. * * This is the place to register hooks and filters. */ public function register_hooks() { \add_action( 'user_register', [ $this, 'build_indexable' ], \PHP_INT_MAX ); \add_action( 'profile_update', [ $this, 'build_indexable' ], \PHP_INT_MAX ); \add_action( 'deleted_user', [ $this, 'delete_indexable' ] ); } /** * Deletes user meta. * * @param int $user_id User ID to delete the metadata of. * * @return void */ public function delete_indexable( $user_id ) { $indexable = $this->repository->find_by_id_and_type( $user_id, 'user', false ); if ( ! $indexable ) { return; } $indexable->delete(); } /** * Saves user meta. * * @param int $user_id User ID. * * @return void */ public function build_indexable( $user_id ) { $indexable = $this->repository->find_by_id_and_type( $user_id, 'user', false ); $this->builder->build_for_id_and_type( $user_id, 'user', $indexable ); } }