*/ protected function input_properties(): array { return array_merge( parent::input_properties(), array( 'force' => array( 'type' => 'boolean', 'default' => false, 'description' => __( 'Required to change the version of the currently active theme, whose appearance changes for visitors as soon as the files are replaced.', 'acrossai-abilities-manager' ), ), ) ); } /** * @since 0.0.45 * @return array */ protected function output_properties(): array { return array_merge( parent::output_properties(), array( 'stylesheet' => array( 'type' => 'string' ), 'is_active_theme' => array( 'type' => 'boolean' ), ) ); } /** * Refuse the active theme without `force`. * * A separate flag from `confirm` on purpose: `confirm` says "I accept a version change", and * `force` says "I accept that this one is live". Folding them together would let a caller who * meant to tidy a dormant theme change the site's appearance with the same single flag. * * @since 0.0.45 * @param array $asset Resolved asset. * @param array $input Caller input. * @return \WP_Error|null */ protected function guard_asset( array $asset, array $input ) { $stylesheet = (string) $asset['slug']; if ( get_stylesheet() !== $stylesheet || ! empty( $input['force'] ) ) { return null; } return new \WP_Error( 'active_theme_requires_force', sprintf( /* translators: %s: theme name */ __( '"%s" is the active theme, so replacing its files changes what visitors see as soon as this returns. Pass force: true as well as confirm: true to proceed.', 'acrossai-abilities-manager' ), (string) $asset['name'] ) ); } /** * @since 0.0.45 * @param array $asset Resolved asset. * @return array */ protected function before_install( array $asset ): array { return array( 'is_active' => get_stylesheet() === (string) $asset['slug'] ); } /** * @since 0.0.45 * @param array $asset Resolved asset. * @param array $state State from before_install(). * @param string $version Version now installed. * @return array */ protected function after_install( array $asset, array $state, string $version ): array { $is_active = ! empty( $state['is_active'] ); $message = sprintf( /* translators: 1: theme name, 2: version */ __( '"%1$s" is now on version %2$s.', 'acrossai-abilities-manager' ), (string) $asset['name'], $version ); if ( $is_active ) { $message .= ' ' . __( 'It is the active theme, so this is live for visitors now.', 'acrossai-abilities-manager' ); } return array( 'stylesheet' => (string) $asset['slug'], 'is_active_theme' => $is_active, 'message' => $message, ); } }