setting => whether changing it needs confirmation. */ public const WRITABLE_SETTINGS = array( 'demo_mode' => true, 'skip_mail' => true, 'subscribers_only' => false, 'acceptance_as_validation' => false, ); /** * Private constructor — static-only (DEC-UTILITY-STATIC-ONLY). */ private function __construct() {} /** * Load one form. * * @since 0.0.34 * @param int $form_id Post ID. * @return WPCF7_ContactForm|WP_Error */ public static function get( int $form_id ) { if ( $form_id < 1 ) { return new WP_Error( 'invalid_input', __( 'A form id is required.', 'acrossai-abilities-manager' ) ); } $form = WPCF7_ContactForm::get_instance( $form_id ); if ( ! $form instanceof WPCF7_ContactForm ) { return new WP_Error( 'form_not_found', sprintf( /* translators: %d: form id */ __( 'No contact form with id %d.', 'acrossai-abilities-manager' ), $form_id ) ); } return $form; } /** * Summarise every form. * * @since 0.0.34 * @param string $search Optional title substring. * @param int $limit Maximum rows. * @param int $offset Rows to skip. * @return array> */ public static function list_all( string $search = '', int $limit = 100, int $offset = 0 ): array { $args = array( 'posts_per_page' => -1 ); if ( '' !== $search ) { $args['s'] = $search; } $forms = WPCF7_ContactForm::find( $args ); $rows = array(); foreach ( array_slice( $forms, $offset, $limit ) as $form ) { $rows[] = self::summarise( $form ); } return $rows; } /** * Compact description of a form, for list views. * * @since 0.0.34 * @param WPCF7_ContactForm $form Form. * @return array */ public static function summarise( WPCF7_ContactForm $form ): array { return array( 'form_id' => (int) $form->id(), 'title' => (string) $form->title(), 'slug' => (string) $form->name(), 'hash' => (string) $form->hash(), 'locale' => (string) $form->locale(), 'shortcode' => (string) $form->shortcode(), 'field_count' => count( Form_Tag_Repository::tags( $form ) ), 'config_errors' => self::count_config_errors( $form ), ); } /** * Full description of a form, for single reads. * * @since 0.0.34 * @param WPCF7_ContactForm $form Form. * @return array */ public static function describe( WPCF7_ContactForm $form ): array { return array_merge( self::summarise( $form ), array( 'form' => (string) $form->prop( 'form' ), 'mail' => (array) $form->prop( 'mail' ), 'mail_2' => (array) $form->prop( 'mail_2' ), 'messages' => (array) $form->prop( 'messages' ), 'additional_settings' => (string) $form->prop( 'additional_settings' ), ) ); } /** * Create or update a form. * * Every write in the suite funnels here. Note the deliberate `wpcf7_kses()` call on the two * fields CF7 only sanitises for users *without* `unfiltered_html`: on a single-site install an * administrator holds that capability, so CF7's own guard would let `