0, 'message' => $this->handle_error( $data, '', sprintf( __( 'Error: %s creation is disabled in settings.', AINSYS_CONNECTOR_TEXTDOMAIN ), self::$entity ), self::$entity, $action ), ]; } $data['user_pass'] = $data['user_pass'] ?? wp_generate_password( 15, true, true ); $result = wp_insert_user( $data ); return [ 'id' => is_wp_error( $result ) ? 0 : $result, 'message' => $this->get_message( $result, $data, self::$entity, $action ), ]; } /** * @param $data * @param $action * @param $object_id * * @return array */ protected function update( $data, $action, $object_id ): array { if ( Conditions::has_entity_disable( self::$entity, $action, 'incoming' ) ) { return [ 'id' => 0, 'message' => $this->handle_error( $data, '', sprintf( __( 'Error: %s update is disabled in settings.', AINSYS_CONNECTOR_TEXTDOMAIN ), self::$entity ), self::$entity, $action ), ]; } $result = wp_update_user( $data ); return [ 'id' => is_wp_error( $result ) ? 0 : $result, 'message' => $this->get_message( $result, $data, self::$entity, $action ), ]; } /** * @param $object_id * @param $data * @param $action * * @return array */ protected function delete( $object_id, $data, $action ): array { if ( Conditions::has_entity_disable( self::$entity, $action, 'incoming' ) ) { return [ 'id' => 0, 'message' => $this->handle_error( $data, '', sprintf( __( 'Error: %s delete is disabled in settings.', AINSYS_CONNECTOR_TEXTDOMAIN ), self::$entity ), self::$entity, $action ), ]; } $result = wp_delete_user( $object_id ); return [ 'id' => $result ? $object_id : 0, 'message' => $this->get_message( $result, $data, self::$entity, $action ), ]; } }