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

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/wp-conte.../plugins/wpforms-.../src/Forms
File: Locator.php
*
[1000] Fix | Delete
* @return void
[1001] Fix | Delete
*/
[1002] Fix | Delete
private function add_locations( $locations_to_add ) {
[1003] Fix | Delete
[1004] Fix | Delete
foreach ( $locations_to_add as $location_to_add ) {
[1005] Fix | Delete
$locations = get_post_meta( $location_to_add['form_id'], self::LOCATIONS_META, true );
[1006] Fix | Delete
[1007] Fix | Delete
if ( ! $locations ) {
[1008] Fix | Delete
$locations = [];
[1009] Fix | Delete
}
[1010] Fix | Delete
[1011] Fix | Delete
$locations[] = $location_to_add;
[1012] Fix | Delete
[1013] Fix | Delete
update_post_meta( $location_to_add['form_id'], self::LOCATIONS_META, $locations );
[1014] Fix | Delete
}
[1015] Fix | Delete
}
[1016] Fix | Delete
[1017] Fix | Delete
/**
[1018] Fix | Delete
* Update form locations on widget update.
[1019] Fix | Delete
*
[1020] Fix | Delete
* @since 1.7.4
[1021] Fix | Delete
*
[1022] Fix | Delete
* @param mixed $old_value The old option value.
[1023] Fix | Delete
* @param mixed $value The new option value.
[1024] Fix | Delete
* @param string $option Option name.
[1025] Fix | Delete
*/
[1026] Fix | Delete
public function update_option( $old_value, $value, $option ) {
[1027] Fix | Delete
[1028] Fix | Delete
switch ( $option ) {
[1029] Fix | Delete
case self::WPFORMS_WIDGET_OPTION:
[1030] Fix | Delete
$old_locations = $this->search_in_wpforms_widgets( $old_value );
[1031] Fix | Delete
$new_locations = $this->search_in_wpforms_widgets( $value );
[1032] Fix | Delete
break;
[1033] Fix | Delete
[1034] Fix | Delete
case self::TEXT_WIDGET_OPTION:
[1035] Fix | Delete
$old_locations = $this->search_in_text_widgets( $old_value );
[1036] Fix | Delete
$new_locations = $this->search_in_text_widgets( $value );
[1037] Fix | Delete
break;
[1038] Fix | Delete
[1039] Fix | Delete
case self::BLOCK_WIDGET_OPTION:
[1040] Fix | Delete
$old_locations = $this->search_in_block_widgets( $old_value );
[1041] Fix | Delete
$new_locations = $this->search_in_block_widgets( $value );
[1042] Fix | Delete
break;
[1043] Fix | Delete
[1044] Fix | Delete
default:
[1045] Fix | Delete
// phpcs:ignore WPForms.Formatting.EmptyLineBeforeReturn.AddEmptyLineBeforeReturnStatement
[1046] Fix | Delete
return;
[1047] Fix | Delete
}
[1048] Fix | Delete
[1049] Fix | Delete
$this->remove_locations( $this->array_udiff( $old_locations, $new_locations ) );
[1050] Fix | Delete
$this->add_locations( $this->array_udiff( $new_locations, $old_locations ) );
[1051] Fix | Delete
}
[1052] Fix | Delete
[1053] Fix | Delete
/**
[1054] Fix | Delete
* Delete locations and schedule new rescan on change of permalink structure.
[1055] Fix | Delete
*
[1056] Fix | Delete
* @since 1.7.4
[1057] Fix | Delete
*
[1058] Fix | Delete
* @param string $old_permalink_structure The previous permalink structure.
[1059] Fix | Delete
* @param string $permalink_structure The new permalink structure.
[1060] Fix | Delete
*
[1061] Fix | Delete
* @noinspection PhpUnusedParameterInspection
[1062] Fix | Delete
*/
[1063] Fix | Delete
public function permalink_structure_changed( $old_permalink_structure, $permalink_structure ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
[1064] Fix | Delete
[1065] Fix | Delete
/**
[1066] Fix | Delete
* Run Forms Locator delete action.
[1067] Fix | Delete
*
[1068] Fix | Delete
* @since 1.7.4
[1069] Fix | Delete
*/
[1070] Fix | Delete
do_action( FormsLocatorScanTask::DELETE_ACTION ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
[1071] Fix | Delete
[1072] Fix | Delete
/**
[1073] Fix | Delete
* Run Forms Locator scan action.
[1074] Fix | Delete
*
[1075] Fix | Delete
* @since 1.7.4
[1076] Fix | Delete
*/
[1077] Fix | Delete
do_action( FormsLocatorScanTask::RESCAN_ACTION ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
[1078] Fix | Delete
}
[1079] Fix | Delete
[1080] Fix | Delete
/**
[1081] Fix | Delete
* Update form locations metas.
[1082] Fix | Delete
*
[1083] Fix | Delete
* @since 1.7.4
[1084] Fix | Delete
* @since 1.8.2.3 Added `$post_before` parameter.
[1085] Fix | Delete
*
[1086] Fix | Delete
* @param WP_Post|null $post_before The post before the update.
[1087] Fix | Delete
* @param WP_Post $post_after The post after the update.
[1088] Fix | Delete
* @param array $form_ids_before Form IDs before the update.
[1089] Fix | Delete
* @param array $form_ids_after Form IDs after the update.
[1090] Fix | Delete
*/
[1091] Fix | Delete
private function update_form_locations_metas( $post_before, $post_after, $form_ids_before, $form_ids_after ) {
[1092] Fix | Delete
[1093] Fix | Delete
// Determine which locations to remove and which to add.
[1094] Fix | Delete
$form_ids_to_remove = array_diff( $form_ids_before, $form_ids_after );
[1095] Fix | Delete
$form_ids_to_add = array_diff( $form_ids_after, $form_ids_before );
[1096] Fix | Delete
[1097] Fix | Delete
// Loop through each form ID to remove the locations' meta.
[1098] Fix | Delete
foreach ( $form_ids_to_remove as $form_id ) {
[1099] Fix | Delete
update_post_meta(
[1100] Fix | Delete
$form_id,
[1101] Fix | Delete
self::LOCATIONS_META,
[1102] Fix | Delete
$this->get_locations_without_current_post( $form_id, $post_after->ID )
[1103] Fix | Delete
);
[1104] Fix | Delete
}
[1105] Fix | Delete
[1106] Fix | Delete
// Determine the titles and slugs.
[1107] Fix | Delete
$old_title = $post_before->post_title ?? '';
[1108] Fix | Delete
$old_slug = $post_before->post_name ?? '';
[1109] Fix | Delete
$new_title = $post_after->post_title;
[1110] Fix | Delete
$new_slug = $post_after->post_name;
[1111] Fix | Delete
[1112] Fix | Delete
// If the title and slug are the same and there are no form IDs to add, bail.
[1113] Fix | Delete
if ( empty( $form_ids_to_add ) && $old_title === $new_title && $old_slug === $new_slug ) {
[1114] Fix | Delete
return;
[1115] Fix | Delete
}
[1116] Fix | Delete
[1117] Fix | Delete
// Merge the form IDs and remove duplicates.
[1118] Fix | Delete
$form_ids = array_unique( array_merge( $form_ids_to_add, $form_ids_after ) );
[1119] Fix | Delete
[1120] Fix | Delete
$this->save_location_meta( $form_ids, $post_after->ID, $post_after );
[1121] Fix | Delete
}
[1122] Fix | Delete
[1123] Fix | Delete
/**
[1124] Fix | Delete
* Save the location meta.
[1125] Fix | Delete
*
[1126] Fix | Delete
* @since 1.8.2.3
[1127] Fix | Delete
*
[1128] Fix | Delete
* @param array $form_ids Form IDs.
[1129] Fix | Delete
* @param int $post_id Post ID.
[1130] Fix | Delete
* @param WP_Post $post_after Post after the update.
[1131] Fix | Delete
*/
[1132] Fix | Delete
private function save_location_meta( $form_ids, $post_id, $post_after ) {
[1133] Fix | Delete
[1134] Fix | Delete
// Build the URL.
[1135] Fix | Delete
$url = get_permalink( $post_id );
[1136] Fix | Delete
$url = ( $url === false || is_wp_error( $url ) ) ? '' : $url;
[1137] Fix | Delete
$url = str_replace( $this->home_url, '', $url );
[1138] Fix | Delete
[1139] Fix | Delete
// Loop through each Form ID and save the location meta.
[1140] Fix | Delete
foreach ( $form_ids as $form_id ) {
[1141] Fix | Delete
[1142] Fix | Delete
$locations = $this->get_locations_without_current_post( $form_id, $post_id );
[1143] Fix | Delete
[1144] Fix | Delete
$locations[] = [
[1145] Fix | Delete
'type' => $post_after->post_type,
[1146] Fix | Delete
'title' => $post_after->post_title,
[1147] Fix | Delete
'form_id' => $form_id,
[1148] Fix | Delete
'id' => $post_id,
[1149] Fix | Delete
'status' => $post_after->post_status,
[1150] Fix | Delete
'url' => $url,
[1151] Fix | Delete
];
[1152] Fix | Delete
[1153] Fix | Delete
update_post_meta( $form_id, self::LOCATIONS_META, $locations );
[1154] Fix | Delete
}
[1155] Fix | Delete
}
[1156] Fix | Delete
[1157] Fix | Delete
/**
[1158] Fix | Delete
* Get post types for search in.
[1159] Fix | Delete
*
[1160] Fix | Delete
* @since 1.7.4
[1161] Fix | Delete
*
[1162] Fix | Delete
* @return string[]
[1163] Fix | Delete
*/
[1164] Fix | Delete
public function get_post_types() {
[1165] Fix | Delete
[1166] Fix | Delete
$args = [
[1167] Fix | Delete
'public' => true,
[1168] Fix | Delete
'publicly_queryable' => true,
[1169] Fix | Delete
];
[1170] Fix | Delete
$post_types = get_post_types( $args, 'names', 'or' );
[1171] Fix | Delete
[1172] Fix | Delete
unset( $post_types['attachment'] );
[1173] Fix | Delete
[1174] Fix | Delete
$post_types[] = self::WP_TEMPLATE;
[1175] Fix | Delete
$post_types[] = self::WP_TEMPLATE_PART;
[1176] Fix | Delete
[1177] Fix | Delete
return $post_types;
[1178] Fix | Delete
}
[1179] Fix | Delete
[1180] Fix | Delete
/**
[1181] Fix | Delete
* Get post statuses for search in.
[1182] Fix | Delete
*
[1183] Fix | Delete
* @since 1.7.4
[1184] Fix | Delete
*
[1185] Fix | Delete
* @return string[]
[1186] Fix | Delete
*/
[1187] Fix | Delete
public function get_post_statuses() {
[1188] Fix | Delete
[1189] Fix | Delete
return [ 'publish', 'pending', 'draft', 'future', 'private' ];
[1190] Fix | Delete
}
[1191] Fix | Delete
[1192] Fix | Delete
/**
[1193] Fix | Delete
* Get form ids from the content.
[1194] Fix | Delete
*
[1195] Fix | Delete
* @since 1.7.4
[1196] Fix | Delete
*
[1197] Fix | Delete
* @param string $content Content.
[1198] Fix | Delete
*
[1199] Fix | Delete
* @return int[]
[1200] Fix | Delete
*/
[1201] Fix | Delete
public function get_form_ids( $content ) {
[1202] Fix | Delete
[1203] Fix | Delete
$form_ids = [];
[1204] Fix | Delete
[1205] Fix | Delete
if (
[1206] Fix | Delete
preg_match_all(
[1207] Fix | Delete
/**
[1208] Fix | Delete
* Extract id from conventional wpforms shortcode or wpforms block.
[1209] Fix | Delete
* Examples:
[1210] Fix | Delete
* [wpforms id="32" title="true" description="true"]
[1211] Fix | Delete
* <!-- wp:wpforms/form-selector {"clientId":"b5f8e16a-fc28-435d-a43e-7c77719f074c", "formId":"32","displayTitle":true,"displayDesc":true} /-->
[1212] Fix | Delete
* In both, we should find 32.
[1213] Fix | Delete
*/
[1214] Fix | Delete
'#\[\s*wpforms.+id\s*=\s*"(\d+?)".*]|<!-- wp:wpforms/form-selector {.*?"formId":"(\d+?)".*?} /-->#',
[1215] Fix | Delete
$content,
[1216] Fix | Delete
$matches
[1217] Fix | Delete
)
[1218] Fix | Delete
) {
[1219] Fix | Delete
array_shift( $matches );
[1220] Fix | Delete
$form_ids = array_map(
[1221] Fix | Delete
'intval',
[1222] Fix | Delete
array_unique( array_filter( array_merge( ...$matches ) ) )
[1223] Fix | Delete
);
[1224] Fix | Delete
}
[1225] Fix | Delete
[1226] Fix | Delete
return $form_ids;
[1227] Fix | Delete
}
[1228] Fix | Delete
[1229] Fix | Delete
/**
[1230] Fix | Delete
* Get form locations without a current post.
[1231] Fix | Delete
*
[1232] Fix | Delete
* @since 1.7.4
[1233] Fix | Delete
*
[1234] Fix | Delete
* @param int $form_id Form id.
[1235] Fix | Delete
* @param int $post_id Post id.
[1236] Fix | Delete
*
[1237] Fix | Delete
* @return array
[1238] Fix | Delete
*/
[1239] Fix | Delete
private function get_locations_without_current_post( $form_id, $post_id ) {
[1240] Fix | Delete
[1241] Fix | Delete
$locations = get_post_meta( $form_id, self::LOCATIONS_META, true );
[1242] Fix | Delete
[1243] Fix | Delete
if ( ! is_array( $locations ) ) {
[1244] Fix | Delete
$locations = [];
[1245] Fix | Delete
}
[1246] Fix | Delete
[1247] Fix | Delete
return array_filter(
[1248] Fix | Delete
$locations,
[1249] Fix | Delete
static function ( $location ) use ( $post_id ) {
[1250] Fix | Delete
[1251] Fix | Delete
return $location['id'] !== $post_id;
[1252] Fix | Delete
}
[1253] Fix | Delete
);
[1254] Fix | Delete
}
[1255] Fix | Delete
[1256] Fix | Delete
/**
[1257] Fix | Delete
* Determine whether a post is visible.
[1258] Fix | Delete
*
[1259] Fix | Delete
* @since 1.7.4
[1260] Fix | Delete
*
[1261] Fix | Delete
* @param array $location Post location.
[1262] Fix | Delete
*
[1263] Fix | Delete
* @return bool
[1264] Fix | Delete
*/
[1265] Fix | Delete
private function is_post_visible( $location ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
[1266] Fix | Delete
[1267] Fix | Delete
$edit_cap = 'edit_post';
[1268] Fix | Delete
$read_cap = 'read_post';
[1269] Fix | Delete
$post_id = $location['id'];
[1270] Fix | Delete
[1271] Fix | Delete
if ( ! get_post_type_object( $location['type'] ) ) {
[1272] Fix | Delete
// Post type is not registered.
[1273] Fix | Delete
return false;
[1274] Fix | Delete
}
[1275] Fix | Delete
[1276] Fix | Delete
$post_status_obj = get_post_status_object( $location['status'] );
[1277] Fix | Delete
[1278] Fix | Delete
if ( ! $post_status_obj ) {
[1279] Fix | Delete
// Post status is not registered, assume it's not public.
[1280] Fix | Delete
return current_user_can( $edit_cap, $post_id );
[1281] Fix | Delete
}
[1282] Fix | Delete
[1283] Fix | Delete
if ( $post_status_obj->public ) {
[1284] Fix | Delete
return true;
[1285] Fix | Delete
}
[1286] Fix | Delete
[1287] Fix | Delete
if ( ! is_user_logged_in() ) {
[1288] Fix | Delete
// User must be logged in to view unpublished posts.
[1289] Fix | Delete
return false;
[1290] Fix | Delete
}
[1291] Fix | Delete
[1292] Fix | Delete
if ( $post_status_obj->protected ) {
[1293] Fix | Delete
// User must have edit permissions on the draft to preview.
[1294] Fix | Delete
return current_user_can( $edit_cap, $post_id );
[1295] Fix | Delete
}
[1296] Fix | Delete
[1297] Fix | Delete
if ( $post_status_obj->private ) {
[1298] Fix | Delete
return current_user_can( $read_cap, $post_id );
[1299] Fix | Delete
}
[1300] Fix | Delete
[1301] Fix | Delete
return false;
[1302] Fix | Delete
}
[1303] Fix | Delete
[1304] Fix | Delete
/**
[1305] Fix | Delete
* Build a standalone location.
[1306] Fix | Delete
*
[1307] Fix | Delete
* @since 1.8.7
[1308] Fix | Delete
*
[1309] Fix | Delete
* @param int $form_id The form ID.
[1310] Fix | Delete
* @param array $form_data Form data.
[1311] Fix | Delete
* @param string $status Form status.
[1312] Fix | Delete
*
[1313] Fix | Delete
* @return array Location.
[1314] Fix | Delete
*/
[1315] Fix | Delete
public function build_standalone_location( int $form_id, array $form_data, string $status = 'publish' ): array {
[1316] Fix | Delete
[1317] Fix | Delete
if ( empty( $form_id ) || empty( $form_data ) ) {
[1318] Fix | Delete
return [];
[1319] Fix | Delete
}
[1320] Fix | Delete
[1321] Fix | Delete
// Form templates should not have any locations.
[1322] Fix | Delete
if ( get_post_type( $form_id ) === 'wpforms-template' ) {
[1323] Fix | Delete
return [];
[1324] Fix | Delete
}
[1325] Fix | Delete
[1326] Fix | Delete
foreach ( self::STANDALONE_LOCATION_TYPES as $location_type ) {
[1327] Fix | Delete
if ( empty( $form_data['settings'][ "{$location_type}_enable" ] ) ) {
[1328] Fix | Delete
continue;
[1329] Fix | Delete
}
[1330] Fix | Delete
[1331] Fix | Delete
return $this->build_standalone_location_type( $location_type, $form_id, $form_data, $status );
[1332] Fix | Delete
}
[1333] Fix | Delete
[1334] Fix | Delete
return [];
[1335] Fix | Delete
}
[1336] Fix | Delete
[1337] Fix | Delete
/**
[1338] Fix | Delete
* Build a standalone location.
[1339] Fix | Delete
*
[1340] Fix | Delete
* @since 1.8.8
[1341] Fix | Delete
*
[1342] Fix | Delete
* @param string $location_type Standalone location type.
[1343] Fix | Delete
* @param int $form_id The form ID.
[1344] Fix | Delete
* @param array $form_data Form data.
[1345] Fix | Delete
* @param string $status Form status.
[1346] Fix | Delete
*
[1347] Fix | Delete
* @return array Location.
[1348] Fix | Delete
*/
[1349] Fix | Delete
private function build_standalone_location_type( string $location_type, int $form_id, array $form_data, string $status ): array {
[1350] Fix | Delete
[1351] Fix | Delete
$title_key = "{$location_type}_title";
[1352] Fix | Delete
$slug_key = "{$location_type}_page_slug";
[1353] Fix | Delete
$title = $form_data['settings'][ $title_key ] ?? '';
[1354] Fix | Delete
$slug = $form_data['settings'][ $slug_key ] ?? '';
[1355] Fix | Delete
[1356] Fix | Delete
// Return the location array.
[1357] Fix | Delete
return [
[1358] Fix | Delete
'type' => $location_type,
[1359] Fix | Delete
'title' => $title,
[1360] Fix | Delete
'form_id' => (int) $form_data['id'],
[1361] Fix | Delete
'id' => $form_id,
[1362] Fix | Delete
'status' => $status,
[1363] Fix | Delete
'url' => '/' . $slug . '/',
[1364] Fix | Delete
];
[1365] Fix | Delete
}
[1366] Fix | Delete
[1367] Fix | Delete
/**
[1368] Fix | Delete
* Add standalone form locations to post meta.
[1369] Fix | Delete
*
[1370] Fix | Delete
* Post meta is used to store all forms' locations,
[1371] Fix | Delete
* which is displayed on the WPForms Overview page.
[1372] Fix | Delete
*
[1373] Fix | Delete
* @since 1.8.7
[1374] Fix | Delete
*
[1375] Fix | Delete
* @param int $form_id Form ID.
[1376] Fix | Delete
* @param array $data Form data.
[1377] Fix | Delete
*/
[1378] Fix | Delete
public function add_standalone_location_to_locations_meta( int $form_id, array $data ) {
[1379] Fix | Delete
[1380] Fix | Delete
// Build standalone location.
[1381] Fix | Delete
$location = $this->build_standalone_location( $form_id, $data );
[1382] Fix | Delete
[1383] Fix | Delete
// No location? Bail.
[1384] Fix | Delete
if ( empty( $location ) ) {
[1385] Fix | Delete
return;
[1386] Fix | Delete
}
[1387] Fix | Delete
[1388] Fix | Delete
// Setup data.
[1389] Fix | Delete
$new_location[] = $location;
[1390] Fix | Delete
$post_meta = get_post_meta( $form_id, self::LOCATIONS_META, true );
[1391] Fix | Delete
[1392] Fix | Delete
// If there is post meta, merge it with the new location.
[1393] Fix | Delete
if ( ! empty( $post_meta ) ) {
[1394] Fix | Delete
[1395] Fix | Delete
// Remove any previously set standalone locations.
[1396] Fix | Delete
$post_meta = $this->remove_standalone_location_from_array( $form_id, $post_meta );
[1397] Fix | Delete
[1398] Fix | Delete
// Merge locations and remove duplicates.
[1399] Fix | Delete
$new_location = array_unique( array_merge( $post_meta, $new_location ), SORT_REGULAR );
[1400] Fix | Delete
}
[1401] Fix | Delete
[1402] Fix | Delete
// Update post meta.
[1403] Fix | Delete
update_post_meta( $form_id, self::LOCATIONS_META, $new_location );
[1404] Fix | Delete
}
[1405] Fix | Delete
[1406] Fix | Delete
/**
[1407] Fix | Delete
* Remove a form page from an array.
[1408] Fix | Delete
*
[1409] Fix | Delete
* @since 1.8.7
[1410] Fix | Delete
*
[1411] Fix | Delete
* @param int $form_id The form ID.
[1412] Fix | Delete
* @param array $post_meta The post meta.
[1413] Fix | Delete
*
[1414] Fix | Delete
* @return array $post_meta Filtered post meta.
[1415] Fix | Delete
*/
[1416] Fix | Delete
private function remove_standalone_location_from_array( int $form_id, array $post_meta ): array {
[1417] Fix | Delete
[1418] Fix | Delete
// No form ID or post meta? Bail.
[1419] Fix | Delete
if ( empty( $form_id ) || empty( $post_meta ) ) {
[1420] Fix | Delete
return [];
[1421] Fix | Delete
}
[1422] Fix | Delete
[1423] Fix | Delete
// Loop over all locations.
[1424] Fix | Delete
foreach ( $post_meta as $key => $location ) {
[1425] Fix | Delete
[1426] Fix | Delete
// Verify the location keys exist.
[1427] Fix | Delete
if ( ! isset( $location['form_id'], $location['type'] ) ) {
[1428] Fix | Delete
continue;
[1429] Fix | Delete
}
[1430] Fix | Delete
[1431] Fix | Delete
// If the form ID and location type match.
[1432] Fix | Delete
if ( $location['form_id'] === $form_id && $this->is_standalone( $location['type'] ) ) {
[1433] Fix | Delete
[1434] Fix | Delete
// Unset the form page location.
[1435] Fix | Delete
unset( $post_meta[ $key ] );
[1436] Fix | Delete
}
[1437] Fix | Delete
}
[1438] Fix | Delete
[1439] Fix | Delete
return $post_meta;
[1440] Fix | Delete
}
[1441] Fix | Delete
}
[1442] Fix | Delete
[1443] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function