*/ protected function input_properties(): array { return array( 'hash' => array( 'type' => 'string', 'minLength' => 1, 'description' => __( 'The share code from the WPCode library link.', 'acrossai-abilities-manager' ), ), ); } /** * @since 0.0.34 * @return array */ protected function required_input(): array { return array( 'hash' ); } /** * @since 0.0.34 * @return array */ protected function output_properties(): array { return array( 'snippet' => array( 'type' => 'object', 'additionalProperties' => true ), 'in_cache' => array( 'type' => 'boolean' ), 'safe_mode' => array( 'type' => 'boolean' ), ); } /** * @since 0.0.34 * @return array */ protected function annotations(): array { return array( 'readonly' => false, 'destructive' => false, 'idempotent' => false ); } /** * @since 0.0.34 * @return bool */ protected function requires_confirmation(): bool { return true; } /** * @since 0.0.34 * @return string */ protected function confirmation_message(): string { return __( 'This installs code shared by someone else onto this site. It will be installed inactive and will not run until you activate it. Pass confirm: true to proceed.', 'acrossai-abilities-manager' ); } /** * @since 0.0.34 * @return array> */ protected function suggested_abilities(): array { return array( array( 'slug' => 'snippets/get-snippet', 'reason' => __( 'Read the installed code before activating it. A shared snippet is someone else\'s code and arrives switched off on purpose.', 'acrossai-abilities-manager' ), ), array( 'slug' => 'snippets/activate-snippet', 'reason' => __( 'Switch it on once you have read it. For php this test-runs the code first and refuses if it errors.', 'acrossai-abilities-manager' ), ), ); } /** * @since 0.0.34 * @param array $input Input. * @return array|WP_Error */ protected function run( array $input ) { $installed = Library_Repository::install_shared( (string) ( $input['hash'] ?? '' ) ); if ( is_wp_error( $installed ) ) { return $installed; } return array( 'snippet' => $installed, 'in_cache' => $installed['in_cache'], 'safe_mode' => WPCode_Guard::safe_mode(), 'message' => __( 'Shared snippet installed and left inactive. Review the code, then call activate-snippet.', 'acrossai-abilities-manager' ), ); } }