get_elasticsearch_version() ) { return; } add_action( 'delete_user', [ $this, 'action_delete_user' ] ); add_action( 'wpmu_delete_user', [ $this, 'action_delete_user' ] ); add_action( 'profile_update', [ $this, 'action_sync_on_update' ] ); add_action( 'user_register', [ $this, 'action_sync_on_update' ] ); add_action( 'updated_user_meta', [ $this, 'action_queue_meta_sync' ], 10, 4 ); add_action( 'added_user_meta', [ $this, 'action_queue_meta_sync' ], 10, 4 ); add_action( 'deleted_user_meta', [ $this, 'action_queue_meta_sync' ], 10, 4 ); // Clear index settings cache add_action( 'ep_update_index_settings', [ $this, 'clear_index_settings_cache' ] ); add_action( 'ep_after_put_mapping', [ $this, 'clear_index_settings_cache' ] ); add_action( 'ep_saved_weighting_configuration', [ $this, 'clear_index_settings_cache' ] ); // @todo Handle deleted meta } /** * Dummy implementation of site unsetup method (for now) */ public function tear_down() { } /** * When whitelisted meta is updated/added/deleted, queue the object for reindex * * @param int $meta_id Meta id. * @param int|array $object_id Object id. * @param string $meta_key Meta key. * @param string $meta_value Meta value. * @since 2.0 */ public function action_queue_meta_sync( $meta_id, $object_id, $meta_key, $meta_value ) { if ( $this->kill_sync() ) { return; } $indexable = Indexables::factory()->get( 'user' ); $this->add_to_queue( $object_id ); } /** * Delete ES user when WP user is deleted * * @param int $user_id User ID * @since 3.0 */ public function action_delete_user( $user_id ) { if ( $this->kill_sync() ) { return; } if ( ! current_user_can( 'edit_user', $user_id ) ) { return; } Indexables::factory()->get( 'user' )->delete( $user_id, false ); } /** * Sync ES index with what happened to the user being saved * * @param int $user_id User id. * @since 3.0 */ public function action_sync_on_update( $user_id ) { if ( $this->kill_sync() ) { return; } if ( ! current_user_can( 'edit_user', $user_id ) ) { return; } /** * Filter whether to kill sync for a particular user * * @hook ep_user_sync_kill * @param {bool} $kill True means dont sync * @param {int} $user_id User ID * @since 3.0 * @return {bool} New kill value */ if ( apply_filters( 'ep_user_sync_kill', false, $user_id ) ) { return; } /** * Fires before adding user to sync queue * * @hook ep_sync_user_on_transition * @param {int} $user_id User ID * @since 3.0 */ do_action( 'ep_sync_user_on_transition', $user_id ); $this->add_to_queue( $user_id ); } }