meta_value in the exact shape * the form post meta expects. Only includes keys where the admin has actually * configured global settings — missing options are omitted so the form falls * back to the hardcoded defaults from register_post_meta(). * * Consumed by (a) the block editor localization to seed new-form defaults, * and (b) the save_post hook to write defaults on first save. * * @return array Map of meta_key => meta_value. * @since 2.9.0 */ public static function get_global_defaults_as_form_meta() { $meta = []; $email_meta = self::build_email_notification_meta(); if ( null !== $email_meta ) { $meta['_srfm_email_notification'] = $email_meta; } $confirmation_meta = self::build_form_confirmation_meta(); if ( null !== $confirmation_meta ) { $meta['_srfm_form_confirmation'] = $confirmation_meta; } $compliance_meta = self::build_compliance_meta(); if ( null !== $compliance_meta ) { $meta['_srfm_compliance'] = $compliance_meta; } $restriction_meta = self::build_form_restriction_meta(); if ( null !== $restriction_meta ) { // Form restriction meta is stored as a JSON string (register_meta type 'string'). $meta['_srfm_form_restriction'] = wp_json_encode( $restriction_meta ); } return $meta; } /** * Build email notification form meta from global settings. * * @return array>|null Form meta array or null if no global settings configured. * @since 2.9.0 */ private static function build_email_notification_meta() { $global_settings = get_option( 'srfm_email_notification_settings_options', [] ); if ( empty( $global_settings ) || ! is_array( $global_settings ) ) { return null; } return [ [ 'id' => 1, 'status' => true, 'is_raw_format' => false, 'name' => __( 'Admin Notification Email', 'sureforms' ), 'email_to' => ! empty( $global_settings['email_to'] ) ? $global_settings['email_to'] : '{admin_email}', 'email_reply_to' => ! empty( $global_settings['email_reply_to'] ) ? $global_settings['email_reply_to'] : '{admin_email}', 'from_name' => ! empty( $global_settings['from_name'] ) ? $global_settings['from_name'] : '{site_title}', 'from_email' => ! empty( $global_settings['from_email'] ) ? $global_settings['from_email'] : '{admin_email}', 'email_cc' => ! empty( $global_settings['email_cc'] ) ? $global_settings['email_cc'] : '{admin_email}', 'email_bcc' => ! empty( $global_settings['email_bcc'] ) ? $global_settings['email_bcc'] : '{admin_email}', 'subject' => ! empty( $global_settings['subject'] ) ? $global_settings['subject'] : sprintf( /* translators: %s: Form title smart tag */ __( 'New Form Submission - %s', 'sureforms' ), '{form_title}' ), 'email_body' => ! empty( $global_settings['email_body'] ) ? $global_settings['email_body'] : '{all_data}', ], ]; } /** * Build form confirmation form meta from global settings. * * @return array>|null Form meta array or null if no global settings configured. * @since 2.9.0 */ private static function build_form_confirmation_meta() { $global_settings = get_option( 'srfm_form_confirmation_settings_options', [] ); if ( empty( $global_settings ) || ! is_array( $global_settings ) ) { return null; } $default_confirmation_message = Global_Settings::get_default_confirmation_message(); return [ [ 'id' => 1, 'confirmation_type' => ! empty( $global_settings['confirmation_type'] ) ? $global_settings['confirmation_type'] : 'same page', 'page_url' => ! empty( $global_settings['page_url'] ) ? $global_settings['page_url'] : '', 'custom_url' => ! empty( $global_settings['custom_url'] ) ? $global_settings['custom_url'] : '', 'message' => ! empty( $global_settings['message'] ) ? $global_settings['message'] : $default_confirmation_message, 'submission_action' => ! empty( $global_settings['submission_action'] ) ? $global_settings['submission_action'] : 'hide form', 'enable_query_params' => ! empty( $global_settings['enable_query_params'] ), 'query_params' => ! empty( $global_settings['query_params'] ) && is_array( $global_settings['query_params'] ) ? $global_settings['query_params'] : [], ], ]; } /** * Build compliance form meta from global settings. * * @return array>|null Form meta array or null if no global settings configured. * @since 2.9.0 */ private static function build_compliance_meta() { $global_settings = get_option( 'srfm_compliance_settings_options', [] ); if ( empty( $global_settings ) || ! is_array( $global_settings ) ) { return null; } return [ [ 'id' => 'gdpr', 'gdpr' => ! empty( $global_settings['gdpr'] ) ? (bool) $global_settings['gdpr'] : false, 'do_not_store_entries' => ! empty( $global_settings['do_not_store_entries'] ) ? (bool) $global_settings['do_not_store_entries'] : false, 'auto_delete_entries' => ! empty( $global_settings['auto_delete_entries'] ) ? (bool) $global_settings['auto_delete_entries'] : false, 'auto_delete_days' => isset( $global_settings['auto_delete_days'] ) ? strval( $global_settings['auto_delete_days'] ) : '', ], ]; } /** * Build form restriction form meta from global settings. * * Global settings are organized by restriction type (max_entries, ip_restriction, etc.) * while form-level settings are flat. Only max_entries is mapped — form-level meta * has a simpler structure focused on entry limits and scheduling. * * @return array|null Form meta array (unencoded) or null if no global settings configured. * @since 2.9.0 */ private static function build_form_restriction_meta() { $global_settings = get_option( 'srfm_form_restriction_settings_options', [] ); if ( empty( $global_settings ) || ! is_array( $global_settings ) ) { return null; } $max_entries = isset( $global_settings['max_entries'] ) && is_array( $global_settings['max_entries'] ) ? $global_settings['max_entries'] : []; return [ 'status' => ! empty( $max_entries['status'] ) ? (bool) $max_entries['status'] : false, 'maxEntries' => isset( $max_entries['maxEntries'] ) ? absint( $max_entries['maxEntries'] ) : 0, 'date' => '', 'hours' => '12', 'minutes' => '00', 'meridiem' => 'AM', 'message' => ! empty( $max_entries['message'] ) ? $max_entries['message'] : __( "This form is now closed as we've received all the entries.", 'sureforms' ), // Form Scheduling meta - not part of global settings, use defaults. 'schedulingStatus' => false, 'startDate' => '', 'startHours' => '12', 'startMinutes' => '00', 'startMeridiem' => 'AM', 'schedulingNotStartedMessage' => __( 'This form is not yet available. Please check back after the scheduled start time.', 'sureforms' ), 'schedulingEndedMessage' => __( 'This form is no longer accepting submissions. The submission period has ended.', 'sureforms' ), ]; } }