Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wpforms-.../includes/admin
File: ajax-actions.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Ajax actions used in by admin.
[2] Fix | Delete
*
[3] Fix | Delete
* @since 1.0.0
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[7] Fix | Delete
exit;
[8] Fix | Delete
}
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Save a form.
[12] Fix | Delete
*
[13] Fix | Delete
* @since 1.0.0
[14] Fix | Delete
*/
[15] Fix | Delete
function wpforms_save_form() {
[16] Fix | Delete
[17] Fix | Delete
// Run a security check.
[18] Fix | Delete
if ( ! check_ajax_referer( 'wpforms-builder', 'nonce', false ) ) {
[19] Fix | Delete
wp_send_json_error( esc_html__( 'Your session expired. Please reload the builder.', 'wpforms-lite' ) );
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
// Check for permissions.
[23] Fix | Delete
if ( ! wpforms_current_user_can( 'edit_forms' ) ) {
[24] Fix | Delete
wp_send_json_error( esc_html__( 'You are not allowed to perform this action.', 'wpforms-lite' ) );
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
// Check for form data.
[28] Fix | Delete
if ( empty( $_POST['data'] ) ) {
[29] Fix | Delete
wp_send_json_error( esc_html__( 'Something went wrong while performing this action.', 'wpforms-lite' ) );
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
[33] Fix | Delete
$form_post = json_decode( wp_unslash( $_POST['data'] ) );
[34] Fix | Delete
$data = [
[35] Fix | Delete
'fields' => [],
[36] Fix | Delete
];
[37] Fix | Delete
[38] Fix | Delete
if ( $form_post ) {
[39] Fix | Delete
foreach ( $form_post as $post_input_data ) {
[40] Fix | Delete
// For input names that are arrays (e.g. `menu-item-db-id[3][4][5]`),
[41] Fix | Delete
// derive the array path keys via regex and set the value in $_POST.
[42] Fix | Delete
preg_match( '#([^\[]*)(\[(.+)\])?#', $post_input_data->name, $matches );
[43] Fix | Delete
[44] Fix | Delete
$array_bits = [ $matches[1] ];
[45] Fix | Delete
[46] Fix | Delete
if ( isset( $matches[3] ) ) {
[47] Fix | Delete
$array_bits = array_merge( $array_bits, explode( '][', $matches[3] ) );
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
$new_post_data = [];
[51] Fix | Delete
[52] Fix | Delete
// Build the new array value from leaf to trunk.
[53] Fix | Delete
for ( $i = count( $array_bits ) - 1; $i >= 0; $i -- ) {
[54] Fix | Delete
if ( $i === count( $array_bits ) - 1 ) {
[55] Fix | Delete
$new_post_data[ $array_bits[ $i ] ] = wp_slash( $post_input_data->value );
[56] Fix | Delete
} else {
[57] Fix | Delete
$new_post_data = [
[58] Fix | Delete
$array_bits[ $i ] => $new_post_data,
[59] Fix | Delete
];
[60] Fix | Delete
}
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
$data = array_replace_recursive( $data, $new_post_data );
[64] Fix | Delete
}
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
// Get form tags.
[68] Fix | Delete
$form_tags = isset( $data['settings']['form_tags_json'] ) ? json_decode( wp_unslash( $data['settings']['form_tags_json'] ), true ) : [];
[69] Fix | Delete
[70] Fix | Delete
// Clear not needed data.
[71] Fix | Delete
unset( $data['settings']['form_tags_json'] );
[72] Fix | Delete
[73] Fix | Delete
// Store tags labels in the form settings.
[74] Fix | Delete
$data['settings']['form_tags'] = wp_list_pluck( $form_tags, 'label' );
[75] Fix | Delete
[76] Fix | Delete
// Update form data.
[77] Fix | Delete
$form_id = wpforms()->get( 'form' )->update( $data['id'], $data, [ 'context' => 'save_form' ] );
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Fires after updating form data.
[81] Fix | Delete
*
[82] Fix | Delete
* @since 1.4.0
[83] Fix | Delete
*
[84] Fix | Delete
* @param int $form_id Form ID.
[85] Fix | Delete
* @param array $data Form data.
[86] Fix | Delete
*/
[87] Fix | Delete
do_action( 'wpforms_builder_save_form', $form_id, $data );
[88] Fix | Delete
[89] Fix | Delete
if ( ! $form_id ) {
[90] Fix | Delete
wp_send_json_error( esc_html__( 'Something went wrong while saving the form.', 'wpforms-lite' ) );
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
// Update form tags.
[94] Fix | Delete
wp_set_post_terms(
[95] Fix | Delete
$form_id,
[96] Fix | Delete
wpforms()->get( 'forms_tags_ajax' )->get_processed_tags( $form_tags ),
[97] Fix | Delete
WPForms_Form_Handler::TAGS_TAXONOMY
[98] Fix | Delete
);
[99] Fix | Delete
[100] Fix | Delete
$response_data = [
[101] Fix | Delete
'form_name' => esc_html( $data['settings']['form_title'] ),
[102] Fix | Delete
'form_desc' => $data['settings']['form_desc'],
[103] Fix | Delete
'redirect' => admin_url( 'admin.php?page=wpforms-overview' ),
[104] Fix | Delete
];
[105] Fix | Delete
[106] Fix | Delete
/**
[107] Fix | Delete
* Allows filtering ajax response data after form was saved.
[108] Fix | Delete
*
[109] Fix | Delete
* @since 1.5.1
[110] Fix | Delete
*
[111] Fix | Delete
* @param array $response_data The data to be sent in the response.
[112] Fix | Delete
* @param int $form_id Form ID.
[113] Fix | Delete
* @param array $data Form data.
[114] Fix | Delete
*/
[115] Fix | Delete
$response_data = apply_filters(
[116] Fix | Delete
'wpforms_builder_save_form_response_data',
[117] Fix | Delete
$response_data,
[118] Fix | Delete
$form_id,
[119] Fix | Delete
$data
[120] Fix | Delete
);
[121] Fix | Delete
[122] Fix | Delete
wp_send_json_success( $response_data );
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
add_action( 'wp_ajax_wpforms_save_form', 'wpforms_save_form' );
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* Create a new form.
[129] Fix | Delete
*
[130] Fix | Delete
* @since 1.0.0
[131] Fix | Delete
*/
[132] Fix | Delete
function wpforms_new_form() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
[133] Fix | Delete
[134] Fix | Delete
check_ajax_referer( 'wpforms-builder', 'nonce' );
[135] Fix | Delete
[136] Fix | Delete
// Prevent second form creating if user has no licence set.
[137] Fix | Delete
// Redirect will lead to the warning page.
[138] Fix | Delete
if ( wpforms()->is_pro() && empty( wpforms_get_license_type() ) && wp_count_posts( 'wpforms' )->publish >= 1 ) {
[139] Fix | Delete
wp_send_json_success( [ 'redirect' => admin_url( 'admin.php?page=wpforms-builder&view=setup' ) ] );
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
if ( empty( $_POST['title'] ) ) {
[143] Fix | Delete
wp_send_json_error(
[144] Fix | Delete
[
[145] Fix | Delete
'error_type' => 'missing_form_title',
[146] Fix | Delete
'message' => esc_html__( 'No Form Name Provided', 'wpforms-lite' ),
[147] Fix | Delete
]
[148] Fix | Delete
);
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
$form_title = sanitize_text_field( wp_unslash( $_POST['title'] ) );
[152] Fix | Delete
$form_template = empty( $_POST['template'] ) ? 'blank' : sanitize_text_field( wp_unslash( $_POST['template'] ) );
[153] Fix | Delete
$category = empty( $_POST['category'] ) ? 'all' : sanitize_text_field( wp_unslash( $_POST['category'] ) );
[154] Fix | Delete
$subcategory = empty( $_POST['subcategory'] ) ? 'all' : sanitize_text_field( wp_unslash( $_POST['subcategory'] ) );
[155] Fix | Delete
[156] Fix | Delete
if ( ! wpforms()->get( 'builder_templates' )->is_valid_template( $form_template ) ) {
[157] Fix | Delete
wp_send_json_error(
[158] Fix | Delete
[
[159] Fix | Delete
'error_type' => 'invalid_template',
[160] Fix | Delete
'message' => esc_html__( 'The template you selected is currently not available, but you can try again later. If you continue to have trouble, please reach out to support.', 'wpforms-lite' ),
[161] Fix | Delete
]
[162] Fix | Delete
);
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
$title_query = new WP_Query(
[166] Fix | Delete
[
[167] Fix | Delete
'post_type' => 'wpforms',
[168] Fix | Delete
'title' => $form_title,
[169] Fix | Delete
'posts_per_page' => 1,
[170] Fix | Delete
'fields' => 'ids',
[171] Fix | Delete
'update_post_meta_cache' => false,
[172] Fix | Delete
'update_post_term_cache' => false,
[173] Fix | Delete
'no_found_rows' => true,
[174] Fix | Delete
]
[175] Fix | Delete
);
[176] Fix | Delete
$title_exists = $title_query->post_count > 0;
[177] Fix | Delete
$form_id = wpforms()->get( 'form' )->add(
[178] Fix | Delete
$form_title,
[179] Fix | Delete
[],
[180] Fix | Delete
[
[181] Fix | Delete
'template' => $form_template,
[182] Fix | Delete
'category' => $category,
[183] Fix | Delete
'subcategory' => $subcategory,
[184] Fix | Delete
]
[185] Fix | Delete
);
[186] Fix | Delete
[187] Fix | Delete
if ( $title_exists ) {
[188] Fix | Delete
[189] Fix | Delete
// Skip creating a revision for this action.
[190] Fix | Delete
remove_action( 'post_updated', 'wp_save_post_revision' );
[191] Fix | Delete
[192] Fix | Delete
wp_update_post(
[193] Fix | Delete
[
[194] Fix | Delete
'ID' => $form_id,
[195] Fix | Delete
'post_title' => $form_title . ' (ID #' . $form_id . ')',
[196] Fix | Delete
]
[197] Fix | Delete
);
[198] Fix | Delete
[199] Fix | Delete
// Restore the initial revisions state.
[200] Fix | Delete
add_action( 'post_updated', 'wp_save_post_revision', 10, 1 );
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
if ( ! $form_id ) {
[204] Fix | Delete
wp_send_json_error(
[205] Fix | Delete
[
[206] Fix | Delete
'error_type' => 'cant_create_form',
[207] Fix | Delete
'message' => esc_html__( 'Error Creating Form', 'wpforms-lite' ),
[208] Fix | Delete
]
[209] Fix | Delete
);
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
if ( wpforms_current_user_can( 'edit_form_single', $form_id ) ) {
[213] Fix | Delete
wp_send_json_success(
[214] Fix | Delete
[
[215] Fix | Delete
'id' => $form_id,
[216] Fix | Delete
'redirect' => add_query_arg(
[217] Fix | Delete
[
[218] Fix | Delete
'view' => 'fields',
[219] Fix | Delete
'form_id' => $form_id,
[220] Fix | Delete
'newform' => '1',
[221] Fix | Delete
],
[222] Fix | Delete
admin_url( 'admin.php?page=wpforms-builder' )
[223] Fix | Delete
),
[224] Fix | Delete
]
[225] Fix | Delete
);
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
if ( wpforms_current_user_can( 'view_forms' ) ) {
[229] Fix | Delete
wp_send_json_success( [ 'redirect' => admin_url( 'admin.php?page=wpforms-overview' ) ] );
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
wp_send_json_success( [ 'redirect' => admin_url() ] );
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
add_action( 'wp_ajax_wpforms_new_form', 'wpforms_new_form' );
[236] Fix | Delete
[237] Fix | Delete
/**
[238] Fix | Delete
* Update form template.
[239] Fix | Delete
*
[240] Fix | Delete
* @since 1.0.0
[241] Fix | Delete
*/
[242] Fix | Delete
function wpforms_update_form_template() {
[243] Fix | Delete
[244] Fix | Delete
// Run a security check.
[245] Fix | Delete
check_ajax_referer( 'wpforms-builder', 'nonce' );
[246] Fix | Delete
[247] Fix | Delete
// Check for form ID.
[248] Fix | Delete
if ( empty( $_POST['form_id'] ) ) {
[249] Fix | Delete
wp_send_json_error(
[250] Fix | Delete
[
[251] Fix | Delete
'error_type' => 'invalid_form_id',
[252] Fix | Delete
'message' => esc_html__( 'No Form ID Provided', 'wpforms-lite' ),
[253] Fix | Delete
]
[254] Fix | Delete
);
[255] Fix | Delete
}
[256] Fix | Delete
[257] Fix | Delete
// Set initial variables.
[258] Fix | Delete
$form_id = absint( $_POST['form_id'] );
[259] Fix | Delete
$form_template = empty( $_POST['template'] ) ? 'blank' : sanitize_text_field( wp_unslash( $_POST['template'] ) );
[260] Fix | Delete
$category = empty( $_POST['category'] ) ? 'all' : sanitize_text_field( wp_unslash( $_POST['category'] ) );
[261] Fix | Delete
$subcategory = empty( $_POST['subcategory'] ) ? 'all' : sanitize_text_field( wp_unslash( $_POST['subcategory'] ) );
[262] Fix | Delete
[263] Fix | Delete
// Check for valid template.
[264] Fix | Delete
if ( ! wpforms()->get( 'builder_templates' )->is_valid_template( $form_template ) ) {
[265] Fix | Delete
wp_send_json_error(
[266] Fix | Delete
[
[267] Fix | Delete
'error_type' => 'invalid_template',
[268] Fix | Delete
'message' => esc_html__( 'The template you selected is currently not available, but you can try again later. If you continue to have trouble, please reach out to support.', 'wpforms-lite' ),
[269] Fix | Delete
]
[270] Fix | Delete
);
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
// Get current form data.
[274] Fix | Delete
$data = wpforms()->get( 'form' )->get(
[275] Fix | Delete
$form_id,
[276] Fix | Delete
[
[277] Fix | Delete
'content_only' => true,
[278] Fix | Delete
]
[279] Fix | Delete
);
[280] Fix | Delete
[281] Fix | Delete
// Get the cached data from the form template JSON.
[282] Fix | Delete
$template_data = wpforms()->get( 'builder_templates' )->get_template( $form_template );
[283] Fix | Delete
[284] Fix | Delete
// If the template title is set, use it. Otherwise, clear the form title.
[285] Fix | Delete
$template_title = ! empty( $template_data['name'] ) ? $template_data['name'] : '';
[286] Fix | Delete
[287] Fix | Delete
// If the form title is set, use it. Otherwise, use the template title.
[288] Fix | Delete
$form_title = ! empty( $_POST['title'] ) ? sanitize_text_field( wp_unslash( $_POST['title'] ) ) : $template_title;
[289] Fix | Delete
[290] Fix | Delete
// Check if the current form title is equal to the previous template name.
[291] Fix | Delete
// If so, set the form title equal to the new template name.
[292] Fix | Delete
$prev_template_slug = $data['meta']['template'] ?? '';
[293] Fix | Delete
$prev_template = wpforms()->get( 'builder_templates' )->get_template( $prev_template_slug );
[294] Fix | Delete
$form_title = isset( $prev_template['name'] ) && $prev_template['name'] === $form_title ? $template_title : $form_title;
[295] Fix | Delete
[296] Fix | Delete
// If the these template titles are empty, use the form title.
[297] Fix | Delete
$form_pages_title = $template_title ? $template_title : $form_title;
[298] Fix | Delete
$form_conversational_title = ! empty( $template_data['data']['settings']['conversational_forms_title'] ) ? $template_data['data']['settings']['conversational_forms_title'] : $form_title;
[299] Fix | Delete
[300] Fix | Delete
// If these template slugs are empty, use the form title.
[301] Fix | Delete
$form_conversational_slug = ! empty( $template_data['data']['settings']['conversational_forms_page_slug'] ) ? $template_data['data']['settings']['conversational_forms_page_slug'] : $form_title;
[302] Fix | Delete
$form_pages_slug = ! empty( $template_data['data']['settings']['form_pages_page_slug'] ) ? $template_data['data']['settings']['form_pages_page_slug'] : $form_title;
[303] Fix | Delete
[304] Fix | Delete
// Loop over notifications.
[305] Fix | Delete
$notifications = isset( $template_data['data']['settings']['notifications'] ) ? $template_data['data']['settings']['notifications'] : [];
[306] Fix | Delete
[307] Fix | Delete
foreach ( $notifications as $key => $notification ) {
[308] Fix | Delete
// If the subject is empty, set it to an empty string.
[309] Fix | Delete
$notification_subject = ! empty( $notification['subject'] ) ? sanitize_text_field( $notification['subject'] ) : '';
[310] Fix | Delete
[311] Fix | Delete
$data['settings']['notifications'][ $key ]['subject'] = $notification_subject;
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
// Loop over confirmations.
[315] Fix | Delete
$confirmations = isset( $template_data['data']['settings']['confirmations'] ) ? $template_data['data']['settings']['confirmations'] : [];
[316] Fix | Delete
[317] Fix | Delete
foreach ( $confirmations as $key => $confirmation ) {
[318] Fix | Delete
[319] Fix | Delete
// If the message is empty, set it to an empty string.
[320] Fix | Delete
$confirmation_message = ! empty( $confirmation['message'] ) ? wp_kses_post( $confirmation['message'] ) : '';
[321] Fix | Delete
[322] Fix | Delete
$data['settings']['confirmations'][ $key ]['message'] = $confirmation_message;
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
// Set updated form titles.
[326] Fix | Delete
$data['settings']['form_title'] = sanitize_text_field( $form_title );
[327] Fix | Delete
$data['settings']['form_pages_title'] = sanitize_text_field( $form_pages_title );
[328] Fix | Delete
$data['settings']['conversational_forms_title'] = sanitize_text_field( $form_conversational_title );
[329] Fix | Delete
[330] Fix | Delete
// Set updated form slugs.
[331] Fix | Delete
$data['settings']['form_pages_page_slug'] = sanitize_title( $form_pages_slug );
[332] Fix | Delete
$data['settings']['conversational_forms_page_slug'] = sanitize_title( $form_conversational_slug );
[333] Fix | Delete
[334] Fix | Delete
// Try to update the form.
[335] Fix | Delete
$updated = (bool) wpforms()->get( 'form' )->update(
[336] Fix | Delete
$form_id,
[337] Fix | Delete
$data,
[338] Fix | Delete
[
[339] Fix | Delete
'template' => $form_template,
[340] Fix | Delete
'category' => $category,
[341] Fix | Delete
'subcategory' => $subcategory,
[342] Fix | Delete
]
[343] Fix | Delete
);
[344] Fix | Delete
[345] Fix | Delete
// If the form was updated, return the form ID and redirect to the form builder.
[346] Fix | Delete
if ( $updated ) {
[347] Fix | Delete
wp_send_json_success(
[348] Fix | Delete
[
[349] Fix | Delete
'id' => $form_id,
[350] Fix | Delete
'redirect' => add_query_arg(
[351] Fix | Delete
[
[352] Fix | Delete
'view' => 'fields',
[353] Fix | Delete
'form_id' => $form_id,
[354] Fix | Delete
],
[355] Fix | Delete
admin_url( 'admin.php?page=wpforms-builder' )
[356] Fix | Delete
),
[357] Fix | Delete
]
[358] Fix | Delete
);
[359] Fix | Delete
}
[360] Fix | Delete
[361] Fix | Delete
// Otherwise, return an error.
[362] Fix | Delete
wp_send_json_error(
[363] Fix | Delete
[
[364] Fix | Delete
'error_type' => 'cant_update',
[365] Fix | Delete
'message' => esc_html__( 'Error Updating Template', 'wpforms-lite' ),
[366] Fix | Delete
]
[367] Fix | Delete
);
[368] Fix | Delete
}
[369] Fix | Delete
[370] Fix | Delete
add_action( 'wp_ajax_wpforms_update_form_template', 'wpforms_update_form_template' );
[371] Fix | Delete
[372] Fix | Delete
/**
[373] Fix | Delete
* Form Builder update next field ID.
[374] Fix | Delete
*
[375] Fix | Delete
* @since 1.2.9
[376] Fix | Delete
*/
[377] Fix | Delete
function wpforms_builder_increase_next_field_id() {
[378] Fix | Delete
[379] Fix | Delete
// Run a security check.
[380] Fix | Delete
check_ajax_referer( 'wpforms-builder', 'nonce' );
[381] Fix | Delete
[382] Fix | Delete
// Check for permissions.
[383] Fix | Delete
if ( ! wpforms_current_user_can( 'edit_forms' ) ) {
[384] Fix | Delete
wp_send_json_error();
[385] Fix | Delete
}
[386] Fix | Delete
[387] Fix | Delete
// Check for required items.
[388] Fix | Delete
if ( empty( $_POST['form_id'] ) ) {
[389] Fix | Delete
wp_send_json_error();
[390] Fix | Delete
}
[391] Fix | Delete
[392] Fix | Delete
$args = [];
[393] Fix | Delete
[394] Fix | Delete
// In the case of duplicating the Layout field that contains a bunch of fields,
[395] Fix | Delete
// we need to set the next `field_id` to the desired value which is passed via POST argument.
[396] Fix | Delete
if ( ! empty( $_POST['field_id'] ) ) {
[397] Fix | Delete
$args['field_id'] = sanitize_text_field( wp_unslash( $_POST['field_id'] ) );
[398] Fix | Delete
}
[399] Fix | Delete
[400] Fix | Delete
wpforms()->get( 'form' )->next_field_id( absint( $_POST['form_id'] ), $args );
[401] Fix | Delete
[402] Fix | Delete
wp_send_json_success();
[403] Fix | Delete
}
[404] Fix | Delete
[405] Fix | Delete
add_action( 'wp_ajax_wpforms_builder_increase_next_field_id', 'wpforms_builder_increase_next_field_id' );
[406] Fix | Delete
[407] Fix | Delete
/**
[408] Fix | Delete
* Form Builder Dynamic Choices option toggle.
[409] Fix | Delete
*
[410] Fix | Delete
* This can be triggered with select/radio/checkbox fields.
[411] Fix | Delete
*
[412] Fix | Delete
* @since 1.2.8
[413] Fix | Delete
*/
[414] Fix | Delete
function wpforms_builder_dynamic_choices() {
[415] Fix | Delete
[416] Fix | Delete
// Run a security check.
[417] Fix | Delete
check_ajax_referer( 'wpforms-builder', 'nonce' );
[418] Fix | Delete
[419] Fix | Delete
// Check for permissions.
[420] Fix | Delete
if ( ! wpforms_current_user_can( 'edit_forms' ) ) {
[421] Fix | Delete
wp_send_json_error();
[422] Fix | Delete
}
[423] Fix | Delete
[424] Fix | Delete
// Check for valid/required items.
[425] Fix | Delete
if ( ! isset( $_POST['field_id'] ) || empty( $_POST['type'] ) || ! in_array( $_POST['type'], [ 'post_type', 'taxonomy' ], true ) ) {
[426] Fix | Delete
wp_send_json_error();
[427] Fix | Delete
}
[428] Fix | Delete
[429] Fix | Delete
$type = sanitize_key( $_POST['type'] );
[430] Fix | Delete
$id = sanitize_text_field( wp_unslash( $_POST['field_id'] ) );
[431] Fix | Delete
[432] Fix | Delete
// Fetch the option row HTML to be returned to the builder.
[433] Fix | Delete
$field = new WPForms_Field_Select( false );
[434] Fix | Delete
$field_args = [
[435] Fix | Delete
'id' => $id,
[436] Fix | Delete
'dynamic_choices' => $type,
[437] Fix | Delete
];
[438] Fix | Delete
$option_row = $field->field_option( 'dynamic_choices_source', $field_args, [], false );
[439] Fix | Delete
[440] Fix | Delete
wp_send_json_success(
[441] Fix | Delete
[
[442] Fix | Delete
'markup' => $option_row,
[443] Fix | Delete
]
[444] Fix | Delete
);
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
add_action( 'wp_ajax_wpforms_builder_dynamic_choices', 'wpforms_builder_dynamic_choices' );
[448] Fix | Delete
[449] Fix | Delete
/**
[450] Fix | Delete
* Form Builder Dynamic Choices Source option toggle.
[451] Fix | Delete
*
[452] Fix | Delete
* This can be triggered with select/radio/checkbox fields.
[453] Fix | Delete
*
[454] Fix | Delete
* @since 1.2.8
[455] Fix | Delete
*/
[456] Fix | Delete
function wpforms_builder_dynamic_source() {
[457] Fix | Delete
[458] Fix | Delete
// Run a security check.
[459] Fix | Delete
check_ajax_referer( 'wpforms-builder', 'nonce' );
[460] Fix | Delete
[461] Fix | Delete
// Check for permissions.
[462] Fix | Delete
if ( ! wpforms_current_user_can( 'edit_forms' ) ) {
[463] Fix | Delete
wp_send_json_error();
[464] Fix | Delete
}
[465] Fix | Delete
[466] Fix | Delete
// Check for required items.
[467] Fix | Delete
if ( ! isset( $_POST['field_id'] ) || empty( $_POST['form_id'] ) || empty( $_POST['type'] ) || empty( $_POST['source'] ) ) {
[468] Fix | Delete
wp_send_json_error();
[469] Fix | Delete
}
[470] Fix | Delete
[471] Fix | Delete
$type = sanitize_key( $_POST['type'] );
[472] Fix | Delete
$source = sanitize_key( $_POST['source'] );
[473] Fix | Delete
$id = sanitize_text_field( wp_unslash( $_POST['field_id'] ) );
[474] Fix | Delete
$form_id = absint( $_POST['form_id'] );
[475] Fix | Delete
$items = [];
[476] Fix | Delete
$total = 0;
[477] Fix | Delete
$source_name = '';
[478] Fix | Delete
$type_name = '';
[479] Fix | Delete
[480] Fix | Delete
if ( $type === 'post_type' ) {
[481] Fix | Delete
[482] Fix | Delete
$type_name = esc_html__( 'post type', 'wpforms-lite' );
[483] Fix | Delete
$args = [
[484] Fix | Delete
'post_type' => $source,
[485] Fix | Delete
'posts_per_page' => 20,
[486] Fix | Delete
'orderby' => 'title',
[487] Fix | Delete
'order' => 'ASC',
[488] Fix | Delete
];
[489] Fix | Delete
$posts = wpforms_get_hierarchical_object(
[490] Fix | Delete
apply_filters(
[491] Fix | Delete
'wpforms_dynamic_choice_post_type_args',
[492] Fix | Delete
$args,
[493] Fix | Delete
[
[494] Fix | Delete
'id' => $id,
[495] Fix | Delete
],
[496] Fix | Delete
$form_id
[497] Fix | Delete
),
[498] Fix | Delete
true
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function