??????????????
??????????????
??????????????
??????????????
Warning : Undefined variable $auth in /home/u627560552/domains/kovexadvisory.com/public_html/666.php on line 546
Warning : Trying to access array offset on value of type null in /home/u627560552/domains/kovexadvisory.com/public_html/666.php on line 546
??????????????
??????????????
??????????????
??????????????
File Manager
✏️ Edit File: /home/mklsvubc/tlma.co.uk/wp-content/plugins/sureforms/inc/create-new-form.php
⬅ Kembali
<?php
/**
* Create new Form with Template and return the form ID.
*
* @package sureforms.
* @since 0.0.1
*/
namespace SRFM\Inc;
use SRFM\Inc\AI_Form_Builder\AI_Helper;
use SRFM\Inc\Traits\Get_Instance;
use WP_Error;
use WP_REST_Response;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Create New Form.
*
* @since 0.0.1
*/
class Create_New_Form {
use Get_Instance;
/**
* Constructor
*
* @since 0.0.1
*/
public function __construct() {
add_action( 'rest_api_init', [ $this, 'register_custom_endpoint' ] );
}
/**
* Add custom API Route create-new-form.
*
* @return void
* @since 0.0.1
*/
public function register_custom_endpoint() {
register_rest_route(
'sureforms/v1',
'/create-new-form',
[
'methods' => 'POST',
'callback' => [ $this, 'create_form' ],
'permission_callback' => [ Helper::class, 'get_items_permissions_check' ],
]
);
}
/**
* Get default post metas for form when creating using template.
*
* @return array<string, int|string|bool> Default meta keys.
* @since 2.0.0 updated the return type.
* @since 0.0.2
*/
public static function get_default_meta_keys() {
$default_values = [
'_srfm_submit_button_text' => __( 'Submit', 'sureforms' ),
'_srfm_use_label_as_placeholder' => false,
'_srfm_single_page_form_title' => 1,
'_srfm_instant_form' => '',
'_srfm_form_container_width' => 650,
'_srfm_bg_type' => 'image',
'_srfm_bg_image' => '',
'_srfm_cover_image' => '',
'_srfm_bg_color' => '#ffffff',
'_srfm_submit_width_backend' => 'max-content',
'_srfm_submit_alignment' => 'left',
'_srfm_submit_alignment_backend' => '100%',
'_srfm_submit_width' => '',
'_srfm_inherit_theme_button' => false,
'_srfm_additional_classes' => '',
'_srfm_submit_type' => 'message',
'_srfm_form_recaptcha' => 'none',
'_srfm_is_inline_button' => false, // @since 2.0.0 -- adding required default value.
];
return apply_filters( 'srfm_add_post_meta_defaults', $default_values );
}
/**
* Create new form post from selected template.
*
* @param \WP_REST_Request $data Form Markup Data.
*
* @return WP_Error|WP_REST_Response
* @since 0.0.1
*/
public static function create_form( $data ) {
$nonce = Helper::get_string_value( $data->get_header( 'X-WP-Nonce' ) );
$nonce = sanitize_text_field( $nonce );
if ( ! wp_verify_nonce( $nonce, 'wp_rest' ) ) {
wp_send_json_error(
[
'message' => __( 'Nonce verification failed.', 'sureforms' ),
]
);
}
$form_info = $data->get_body();
$form_info_obj = json_decode( $form_info );
// Check if JSON decoding was successful and $form_info_obj is an object.
if ( json_last_error() !== JSON_ERROR_NONE || ! is_object( $form_info_obj ) ) {
wp_send_json_error(
[
'message' => __( 'Invalid JSON format.', 'sureforms' ),
]
);
}
$required_properties = [ 'template_name', 'form_data' ];
// Check if required properties exist in the $form_info_obj.
foreach ( $required_properties as $property ) {
if ( ! property_exists( $form_info_obj, $property ) ) {
wp_send_json_error(
[
'message' => __( 'Missing required properties in form info.', 'sureforms' ),
]
);
}
}
$title = $form_info_obj->template_name ?? '';
$content = $form_info_obj->form_data ?? '';
// Create post metas for the creating form.
$post_metas = apply_filters(
'srfm_modify_ai_post_metas',
[],
$form_info_obj,
);
$post_id = wp_insert_post(
[
'post_title' => $title,
'post_content' => $content,
'meta_input' => $post_metas,
'post_status' => 'draft',
'post_type' => 'sureforms_form',
],
true
);
if ( is_wp_error( $post_id ) ) {
// Pass the raw WP_Error through the shared sanitizer so any URLs,
// request IDs, or model names injected by a filter on
// wp_insert_post don't leak via the REST response. The raw message
// is still logged server-side (gated on WP_DEBUG / WP_DEBUG_LOG).
$sanitized = AI_Helper::sanitize_ai_error_message( $post_id->get_error_message(), 'wp_insert_post' );
if ( '' === $sanitized ) {
$sanitized = __( 'Error creating SureForms Form.', 'sureforms' );
}
return new WP_REST_Response(
[
'message' => $sanitized,
],
500
);
}
if ( ! is_int( $post_id ) || $post_id <= 0 ) {
return new WP_REST_Response(
[
'message' => __( 'Error creating SureForms Form.', 'sureforms' ),
],
500
);
}
/**
* Update _srfm_is_ai_generated meta to true.
* If the request is coming here then the form is AI generated.
*/
update_post_meta( $post_id, '_srfm_is_ai_generated', true );
return new WP_REST_Response(
[
'message' => __( 'SureForms Form created successfully.', 'sureforms' ),
'id' => $post_id,
]
);
}
}
Nama
Tipe
Ukuran
Diubah
Aksi
📁 abilities
dir
—
2026-06-18 20:37
📁 admin
dir
—
2026-06-18 20:37
📁 ai-form-builder
dir
—
2026-06-18 20:37
📁 blocks
dir
—
2026-06-18 20:37
📁 compatibility
dir
—
2026-06-18 20:37
📁 database
dir
—
2026-06-18 20:37
📁 email
dir
—
2026-06-18 20:37
📁 fields
dir
—
2026-06-18 20:37
📁 global-settings
dir
—
2026-06-18 20:37
📁 lib
dir
—
2026-06-18 20:37
📁 migrator
dir
—
2026-06-18 20:37
📁 page-builders
dir
—
2026-06-18 20:37
📁 payments
dir
—
2026-06-18 20:37
📁 single-form-settings
dir
—
2026-06-18 20:37
📁 traits
dir
—
2026-06-18 20:37
🐘 activator.php
php
1 KB
2026-06-18 20:37
🐘 admin-ajax.php
php
13.2 KB
2026-06-18 20:37
🐘 background-process.php
php
4.8 KB
2026-06-18 20:37
🐘 create-new-form.php
php
4.9 KB
2026-06-18 20:37
🐘 duplicate-form.php
php
8.4 KB
2026-06-18 20:37
🐘 entries.php
php
24.3 KB
2026-06-18 20:37
🐘 events-scheduler.php
php
1.3 KB
2026-06-18 20:37
🐘 export.php
php
11.8 KB
2026-06-18 20:37
🐘 field-validation.php
php
22.9 KB
2026-06-18 20:37
🐘 form-restriction.php
php
11.2 KB
2026-06-18 20:37
🐘 form-styling.php
php
7 KB
2026-06-18 20:37
🐘 form-submit.php
php
55.6 KB
2026-06-18 20:37
🐘 forms-data.php
php
7.1 KB
2026-06-18 20:37
🐘 frontend-assets.php
php
16.3 KB
2026-06-18 20:37
🐘 generate-form-markup.php
php
49.3 KB
2026-06-18 20:37
🐘 gutenberg-hooks.php
php
10.9 KB
2026-06-18 20:37
🐘 helper.php
php
92.1 KB
2026-06-18 20:37
🐘 learn.php
php
13.5 KB
2026-06-18 20:37
🐘 onboarding.php
php
3.9 KB
2026-06-18 20:37
🐘 post-types.php
php
48.4 KB
2026-06-18 20:37
🐘 rest-api.php
php
56.7 KB
2026-06-18 20:37
🐘 smart-tags.php
php
28.1 KB
2026-06-18 20:37
🐘 submit-token.php
php
4.6 KB
2026-06-18 20:37
🐘 translatable.php
php
5.9 KB
2026-06-18 20:37
🐘 updater-callbacks.php
php
3.3 KB
2026-06-18 20:37
🐘 updater.php
php
5.1 KB
2026-06-18 20:37