array( $response ) || 0 === count( $response ) || ! $this->check_prompt_structure( $response ) ) { set_transient( $this->timeout_transient, '1', 5 * MINUTE_IN_SECONDS ); return array( 'response' => array(), 'code' => '2', 'error' => __( 'Invalid data from central server. Please try again in', 'otter-blocks' ) . 5 . __( 'minutes.', 'otter-blocks' ), ); } set_transient( $this->transient_prompts, $response, WEEK_IN_SECONDS ); return array( 'prompts' => $response, 'code' => '0', 'error' => '', ); } /** * Check if the prompt structure is valid. * * @param mixed $response Response from the server. * @return bool */ public function check_prompt_structure( $response ) { if ( ! isset( $response ) ) { return false; } if ( ! is_array( $response ) ) { return false; } if ( 0 === count( $response ) ) { return false; } return true; } /** * Record prompt usage. * * @param array $otter_metadata The metadata from the prompt usage request. * @return void * @phpstan-ignore-next-line */ private function record_prompt_usage( $otter_metadata ) { if ( ! isset( $otter_metadata['otter_used_action'] ) || ! isset( $otter_metadata['otter_user_content'] ) ) { return; } $action = $otter_metadata['otter_used_action']; $user_content = $otter_metadata['otter_user_content']; $usage = get_option( 'themeisle_otter_ai_usage' ); if ( ! is_array( $usage ) ) { $usage = array( 'usage_count' => array(), 'prompts' => array(), ); } if ( ! is_array( $usage['usage_count'] ) ) { $usage['usage_count'] = array(); } if ( ! is_array( $usage['prompts'] ) ) { $usage['prompts'] = array(); } $is_missing = true; foreach ( $usage['usage_count'] as &$u ) { if ( isset( $u['key'] ) && $u['key'] === $action ) { ++$u['value']; $is_missing = false; } } unset( $u ); if ( $is_missing ) { $usage['usage_count'][] = array( 'key' => $action, 'value' => 1, ); } $is_missing = true; foreach ( $usage['prompts'] as &$u ) { if ( isset( $u['key'] ) && $u['key'] === $action ) { $u['values'][] = $user_content; $is_missing = false; // Keep only the last 10 prompts. if ( count( $u['values'] ) > 10 ) { array_shift( $u['values'] ); } } } unset( $u ); if ( $is_missing ) { $usage['prompts'][] = array( 'key' => $action, 'values' => array( $user_content ), ); } update_option( 'themeisle_otter_ai_usage', $usage ); } /** * The instance method for the static class. * Defines and returns the instance of the static class. * * @static * @since 1.7.0 * @access public * @return Prompt_Server */ public static function instance() { if ( is_null( self::$instance ) ) { self::$instance = new self(); self::$instance->init(); } return self::$instance; } /** * Throw error on object clone * * The whole idea of the singleton design pattern is that there is a single * object therefore, we don't want the object to be cloned. * * @access public * @since 1.7.0 * @return void */ public function __clone() { // Cloning instances of the class is forbidden. _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'otter-blocks' ), '1.0.0' ); } /** * Disable unserializing of the class * * @access public * @since 1.7.0 * @return void */ public function __wakeup() { // Unserializing instances of the class is forbidden. _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'otter-blocks' ), '1.0.0' ); } } WordPress › Error

There has been a critical error on this website.

Learn more about troubleshooting WordPress.