Changeset 2815356
- Timestamp:
- 11/09/2022 04:24:00 PM (3 years ago)
- Location:
- lct-useful-shortcodes-functions/trunk
- Files:
-
- 11 edited
-
code/api/class.php (modified) (4 diffs)
-
code/api/debug.php (modified) (3 diffs)
-
code/features/shortcodes/sort.php (modified) (2 diffs)
-
code/plugins/acf/_loaded.php (modified) (11 diffs)
-
code/plugins/acf/api/_helpers.php (modified) (1 diff)
-
code/plugins/acf/api/get.php (modified) (9 diffs)
-
code/plugins/acf/field_settings.php (modified) (3 diffs)
-
code/plugins/acf/instant_save.php (modified) (2 diffs)
-
code/plugins/acf/public_choices.php (modified) (2 diffs)
-
lct-useful-shortcodes-functions.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lct-useful-shortcodes-functions/trunk/code/api/class.php
r2800229 r2815356 825 825 ! empty( $field['taxonomy'] ) && 826 826 empty( $field['multiple'] ) && 827 ( $ info= acf_decode_post_id( $post_id ) ) &&828 $ info['type'] === 'post' &&827 ( $decoded = acf_decode_post_id( $post_id ) ) && 828 $decoded['type'] === 'post' && 829 829 ( $status = get_term( $value, $field['taxonomy'] ) ) && 830 830 ! lct_is_wp_error( $status ) && … … 884 884 ! empty( $field['taxonomy'] ) && 885 885 empty( $field['multiple'] ) && 886 ( $ info= acf_decode_post_id( $post_id ) ) &&887 $ info['type'] === 'post' &&886 ( $decoded = acf_decode_post_id( $post_id ) ) && 887 $decoded['type'] === 'post' && 888 888 ( $post_status = get_post_status( $post_id ) ) && 889 889 strpos( $post_status, '_' ) !== false … … 983 983 984 984 //get terms 985 $ info = acf_get_post_id_info( $post_id );986 $term_ids = wp_get_object_terms( $ info['id'], $field['taxonomy'], [ 'fields' => 'ids' ] );985 $decoded = acf_decode_post_id( $post_id ); 986 $term_ids = wp_get_object_terms( $decoded['id'], $field['taxonomy'], [ 'fields' => 'ids' ] ); 987 987 988 988 … … 1027 1027 if ( 1028 1028 $value && 1029 ( $ info= acf_decode_post_id( $post_id ) ) &&1030 $ info['type'] === 'post'1029 ( $decoded = acf_decode_post_id( $post_id ) ) && 1030 $decoded['type'] === 'post' 1031 1031 ) { 1032 1032 $terms = []; -
lct-useful-shortcodes-functions/trunk/code/api/debug.php
r2782154 r2815356 88 88 * @return bool|string 89 89 * @since 0.0 90 * @verified 20 16.11.2990 * @verified 2022.10.21 91 91 */ 92 92 function P_R( $var, $name = 'Name Not Set', $return = false ) { 93 93 $skip = [ 'HTTP_COOKIE' ]; 94 94 $c = 'odd'; 95 $c2 = 'even'; 96 97 $h = '<table class="P_R" style="max-width: 1000px;width: 100%;margin: 0 auto;">'; 95 96 $h = '<table class="P_R" style="max-width: 1200px;width: 100%;margin: 0 auto;">'; 98 97 $h .= '<tr><th class="' . $c . '" colspan="2">' . $name . '</th></tr>'; 99 98 … … 114 113 $h .= '<td class="' . $c . '">'; 115 114 116 if ( is_array( $v ) ) { 117 $h .= '<table style="width:100%;margin:0 auto;">'; 118 foreach ( $v as $k2 => $v2 ) { 119 if ( $c2 == 'even' ) 120 $c2 = 'odd'; 121 else 122 $c2 = 'even'; 123 124 $h .= '<tr>'; 125 $h .= '<td class="' . $c2 . '">'; 126 $h .= $k2; 127 $h .= '</td>'; 128 $h .= '<td class="' . $c2 . '">'; 129 130 if ( is_array( $v2 ) ) { 131 $h .= '<pre>'; 132 $h .= print_r( $v2, true ); 133 $h .= '</pre>'; 134 } else 135 $h .= $v2; 136 137 $h .= '</td>'; 138 $h .= '</tr>'; 139 } 140 141 $h .= '</table>'; 142 } else 143 $h .= $v; 115 $h .= P_R_loop( $v ); 144 116 145 117 $h .= '</td>'; … … 167 139 168 140 return false; 141 } 142 143 144 /** 145 * Loop thru the table 146 * 147 * @param string|array $loop 148 * 149 * @return string 150 * @date 2022.10.21 151 * @since 2022.10 152 * @verified 2022.10.21 153 */ 154 function P_R_loop( $loop ) { 155 $h = ''; 156 $c = 'even'; 157 158 159 if ( is_array( $loop ) ) { 160 $h .= '<table style="width:100%;margin:0 auto;">'; 161 foreach ( $loop as $k => $v ) { 162 if ( $c == 'even' ) 163 $c = 'odd'; 164 else 165 $c = 'even'; 166 167 $h .= '<tr>'; 168 $h .= '<td class="' . $c . '">'; 169 $h .= $k; 170 $h .= '</td>'; 171 $h .= '<td class="' . $c . '">'; 172 173 if ( is_array( $v ) ) { 174 $h .= P_R_loop( $v ); 175 } else 176 $h .= $v; 177 178 $h .= '</td>'; 179 $h .= '</tr>'; 180 } 181 182 $h .= '</table>'; 183 } else { 184 $h .= $loop; 185 } 186 187 188 return $h; 169 189 } 170 190 } -
lct-useful-shortcodes-functions/trunk/code/features/shortcodes/sort.php
r2642123 r2815356 281 281 * @return string 282 282 * @since 5.36 283 * @verified 20 16.11.04283 * @verified 2022.11.03 284 284 */ 285 285 function get_the_title( $a ) { … … 293 293 else if ( ! empty( $post ) ) 294 294 $post_id = $post->ID; 295 else 296 $post_id = ''; 297 298 299 if ( $post_id ) 295 else { 296 global $term, $taxonomy; 297 298 299 /** 300 * Check for a term page 301 */ 302 if ( 303 ! empty( $term ) && 304 ! empty( $taxonomy ) && 305 ( $term_obj = get_term_by( 'slug', $term, $taxonomy ) ) && 306 ! lct_is_wp_error( $term_obj ) 307 ) { 308 $title = $term_obj->name; 309 } 310 } 311 312 313 if ( ! empty( $post_id ) ) 300 314 $title = get_the_title( $post_id ); 301 315 -
lct-useful-shortcodes-functions/trunk/code/plugins/acf/_loaded.php
r2771323 r2815356 107 107 * @return array 108 108 * @since 2019.2 109 * @verified 202 0.02.26109 * @verified 2022.10.19 110 110 */ 111 111 function prepare_fields_for_import( $fields ) { … … 125 125 126 126 foreach ( $fields as $field ) { 127 $field_key = $field['key']; 128 $field_name = null; 129 if ( isset( $field['name'] ) ) 130 $field_name = $field['name']; 131 132 133 if ( acf_is_field_group_key( $field['parent'] ) ) { 134 $group_key = $field['parent']; 135 } else if ( acf_is_field_key( $field['parent'] ) ) { 136 continue; 137 } else if ( 138 is_numeric( $field['parent'] ) && 139 ( $group_obj = acf_get_field_group( $field['parent'] ) ) && 140 isset( $group_obj['key'] ) && 141 acf_is_field_group_key( $group_obj['key'] ) 142 ) { 143 $group_key = $group_obj['key']; 144 } else { 145 continue; 146 } 147 148 149 if ( empty( $this->references['groups'][ $group_key ] ) ) 150 $this->references['groups'][ $group_key ] = []; 151 152 127 153 if ( 128 isset( $field['parent'] ) && 129 empty( $this->references['groups'][ $field['parent'] ] ) 130 ) { 131 $this->references['groups'][ $field['parent'] ] = []; 132 } 133 134 135 if ( 136 empty( $field['name'] ) || 154 empty( $field_name ) || 137 155 ( 138 ! empty( $this->references['groups'][ $ field['parent'] ][ $field['key']] ) &&139 $this->references['groups'][ $ field['parent'] ][ $field['key'] ] === $field['name']156 ! empty( $this->references['groups'][ $group_key ][ $field_key ] ) && 157 $this->references['groups'][ $group_key ][ $field_key ] === $field_name 140 158 ) || 141 159 ( 142 strpos( $field ['key'], '_' ) === 0 &&143 $field ['name'] === $field['key']160 strpos( $field_key, '_' ) === 0 && 161 $field_name === $field_key 144 162 ) || 145 163 apply_filters( 'lct_acf_loaded/prepare_fields_for_import/ignore', false, $field, $this->references['keys'] ) … … 149 167 150 168 151 $this->references['groups'][ $ field['parent'] ][ $field['key'] ] = $field['name'];152 $this->references['keys'][] = $field['key'];153 $this->references['names'][] = $field['name'];169 $this->references['groups'][ $group_key ][ $field_key ] = $field_name; 170 $this->references['keys'][] = $field_key; 171 $this->references['names'][] = $field_name; 154 172 } 155 173 … … 322 340 $is_comment = false; 323 341 $keys = []; 324 $ info= acf_decode_post_id( $post_id );342 $decoded = acf_decode_post_id( $post_id ); 325 343 $taxonomy = null; 326 344 … … 371 389 } 372 390 } else { 373 switch ( $ info['type'] ) {391 switch ( $decoded['type'] ) { 374 392 case 'term': 375 393 if ( … … 386 404 case 'user': 387 405 if ( 388 ! empty( $ info['id'] ) &&389 ( $groups = acf_get_field_groups( [ 'user_id' => $ info['id'] ] ) )406 ! empty( $decoded['id'] ) && 407 ( $groups = acf_get_field_groups( [ 'user_id' => $decoded['id'] ] ) ) 390 408 ) { 391 409 foreach ( $groups as $group ) { … … 544 562 545 563 546 switch ( $ info['type'] ) {564 switch ( $decoded['type'] ) { 547 565 case 'term': 548 $ info['type_match'] = [ 'taxonomy', 'post_taxonomy' ];549 $ info['type_match_root'] = 'taxonomy';566 $decoded['type_match'] = [ 'taxonomy', 'post_taxonomy' ]; 567 $decoded['type_match_root'] = 'taxonomy'; 550 568 break; 551 569 552 570 553 571 case 'user': 554 $ info['type_match'] = [ 'current_user', 'current_user_role', 'user_form', 'user_role' ];555 $ info['type_match_root'] = 'user';572 $decoded['type_match'] = [ 'current_user', 'current_user_role', 'user_form', 'user_role' ]; 573 $decoded['type_match_root'] = 'user'; 556 574 break; 557 575 558 576 559 577 case 'comment': 560 $ info['type_match'] = [ 'comment' ];561 $ info['type_match_root'] = 'comment';578 $decoded['type_match'] = [ 'comment' ]; 579 $decoded['type_match_root'] = 'comment'; 562 580 break; 563 581 564 582 565 583 default: 566 $ info['type_match'] = [ 'post_type', 'post', 'page_type', 'page' ];567 $ info['type_match_root'] = 'post_type';584 $decoded['type_match'] = [ 'post_type', 'post', 'page_type', 'page' ]; 585 $decoded['type_match_root'] = 'post_type'; 568 586 569 587 … … 620 638 foreach ( $locations as $choices ) { 621 639 if ( 622 ! in_array( $choices['param'], $ info['type_match'] ) &&640 ! in_array( $choices['param'], $decoded['type_match'] ) && 623 641 ( $unset_key = array_search( $key, $keys ) ) !== false 624 642 ) { … … 626 644 } else if ( 627 645 ! $new_post && 628 $ info['type_match_root'] === 'post_type' &&646 $decoded['type_match_root'] === 'post_type' && 629 647 $choices['operator'] === '!=' && 630 648 $choices['value'] === $post_type && 631 649 ( $unset_key = array_search( $key, $keys ) ) !== false && 632 in_array( $choices['param'], $ info['type_match'] )650 in_array( $choices['param'], $decoded['type_match'] ) 633 651 ) { 634 652 $unset = true; 635 653 } else if ( 636 654 ! $new_post && 637 $ info['type_match_root'] === 'post_type' &&655 $decoded['type_match_root'] === 'post_type' && 638 656 $choices['operator'] === '==' && 639 657 $choices['value'] !== $post_type && 640 658 ( $unset_key = array_search( $key, $keys ) ) !== false && 641 in_array( $choices['param'], $ info['type_match'] )659 in_array( $choices['param'], $decoded['type_match'] ) 642 660 ) { 643 661 $unset = true; 644 662 } else if ( 645 663 ! $new_post && 646 $ info['type_match_root'] === 'taxonomy' &&664 $decoded['type_match_root'] === 'taxonomy' && 647 665 $choices['value'] !== $taxonomy && 648 666 ( $unset_key = array_search( $key, $keys ) ) !== false && 649 in_array( $choices['param'], $ info['type_match'] )667 in_array( $choices['param'], $decoded['type_match'] ) 650 668 ) { 651 669 $unset = true; 652 670 } else if ( 653 671 ! $new_post && 654 $ info['type_match_root'] === 'user' &&672 $decoded['type_match_root'] === 'user' && 655 673 $choices['param'] === 'user_role' && 656 ! empty( $ info['id'] ) &&657 ( $user = get_userdata( $ info['id'] ) ) &&674 ! empty( $decoded['id'] ) && 675 ( $user = get_userdata( $decoded['id'] ) ) && 658 676 ! lct_is_wp_error( $user ) && 659 677 $choices['value'] !== 'all' && … … 666 684 $choices['value'] !== $new_post && 667 685 ( $unset_key = array_search( $key, $keys ) ) !== false && 668 in_array( $choices['param'], $ info['type_match'] )686 in_array( $choices['param'], $decoded['type_match'] ) 669 687 ) { 670 688 $unset = true; … … 676 694 ( $unique_post_types = apply_filters( 'lct/acf/load_reference/unique_post_types', null ) ) && 677 695 ! $new_post && 678 $ info['type_match_root'] === 'post_type' &&679 in_array( $choices['param'], $ info['type_match'] ) &&696 $decoded['type_match_root'] === 'post_type' && 697 in_array( $choices['param'], $decoded['type_match'] ) && 680 698 in_array( $choices['value'], $unique_post_types ) 681 699 ) { -
lct-useful-shortcodes-functions/trunk/code/plugins/acf/api/_helpers.php
r2679272 r2815356 862 862 /** 863 863 * Clean up the ACF repeater 864 * http://uk1.php.net/array_walk_recursive implementation that is used to remove nodes from the array. 865 * 866 * @param array The input array. 867 * 868 * @unused param callable $callback Function must return boolean value indicating whether to remove the node. 864 * 865 * @param array $array The input array. 866 * 869 867 * @return array 870 868 * @since 2020.5 871 * @verified 2020.02.07 872 */ 873 function lct_clean_acf_repeater( array $array ) { 869 * @verified 2022.10.24 870 */ 871 function lct_clean_acf_repeater( $array ) { 872 if ( ! is_array( $array ) ) 873 return $array; 874 875 874 876 foreach ( $array as $k => $v ) { 875 877 if ( $k === 'acfcloneindex' ) -
lct-useful-shortcodes-functions/trunk/code/plugins/acf/api/get.php
r2800229 r2815356 687 687 /** 688 688 * Get the ACF group of a field 689 * Don't use this 689 690 * 690 691 * @param string|array $field_parent … … 1145 1146 * @return mixed|null 1146 1147 * @since 2019.4 1147 * @verified 202 1.03.091148 * @verified 2022.10.20 1148 1149 */ 1149 1150 function lct_acf_get_POST_value( $selector, $post_id = null, $format_value = false, $double_check = true ) { … … 1209 1210 1210 1211 1211 if ( lct_acf_is_ selector_repeater( $selector ) ) {1212 if ( lct_acf_is_field_repeater( $selector ) ) { 1212 1213 $r = lct_acf_get_POST_values_w_selector_key( $r, false, true ); 1213 1214 } else if ( … … 1262 1263 1263 1264 1264 if ( ( $parent_value = lct_acf_get_POST_value( $selector, $post_id , false) ) === null )1265 if ( ( $parent_value = lct_acf_get_POST_value( $selector, $post_id ) ) === null ) 1265 1266 return $r; 1266 1267 … … 1297 1298 * 1298 1299 * @param array $post 1299 * @param bool $return_field 1300 * @param bool|string $ repeater1300 * @param bool $return_field //Return the full ACF field array or just the value 1301 * @param bool|string $special_process //false | true (repeater field_type) | looping | clone_{key} | maintain_seamless_clones 1301 1302 * 1302 1303 * @return array 1303 1304 * @since 2019.6 1304 * @verified 2019.09.19 1305 */ 1306 function lct_acf_get_POST_values_w_selector_key( $post = null, $return_field = false, $repeater = false ) { 1305 * @verified 2022.10.24 1306 */ 1307 function lct_acf_get_POST_values_w_selector_key( $post = null, $return_field = false, $special_process = false ) { 1308 /** 1309 * Vars 1310 */ 1307 1311 $r = []; 1308 1312 1309 1310 if ( $post === null ) 1313 if ( $post === null && isset( $_POST ) ) 1311 1314 $post = $_POST; 1312 1315 1313 1314 if ( 1315 $repeater === true && 1316 ! empty( $post ) 1317 ) { 1318 $ki = 0; 1319 1320 1316 if ( empty( $post ) ) 1317 return $r; 1318 1319 $post = lct_clean_acf_repeater( $post ); 1320 1321 1322 /** 1323 * Special processing for a repeater field 1324 */ 1325 if ( $special_process === true ) { 1321 1326 foreach ( $post as $k => $v ) { 1322 if ( $k === 'acfcloneindex' ) 1327 $send = [ 'acf' => $v ]; 1328 1329 1330 $r[ $k ] = lct_acf_get_POST_values_w_selector_key( $send, $return_field, 'looping' ); 1331 } 1332 1333 1334 return $r; 1335 1336 1337 /** 1338 * Special processing for a clone field 1339 */ 1340 } else if ( 1341 str_starts_with( $special_process, 'clone_' ) && 1342 is_array( $post ) 1343 ) { 1344 $key = substr( $special_process, 6 ); //remove clone_ 1345 1346 1347 foreach ( $post as $k => $v ) { 1348 $clone_key = substr( $k, strlen( $key ) + 1 ); 1349 1350 1351 if ( 1352 ! acf_is_field_key( $k ) || 1353 ! acf_is_field_key( $clone_key ) 1354 ) { 1323 1355 continue; 1324 1325 1326 $send = [ 'acf' => $v ]; 1327 1328 1329 $r[ $ki ] = lct_acf_get_POST_values_w_selector_key( $send, $return_field, 'looping' ); 1330 1331 1332 $ki ++; 1356 } 1357 1358 1359 $send = [ 'acf' => [ $clone_key => $v ] ]; 1360 1361 1362 $r = array_merge( $r, lct_acf_get_POST_values_w_selector_key( $send, $return_field, 'looping' ) ); 1333 1363 } 1334 1364 … … 1338 1368 1339 1369 1370 /** 1371 * Swap out keys --TO-- selectors 1372 */ 1340 1373 if ( ! empty( $post['acf'] ) ) { 1341 foreach ( $post['acf'] as $k => $v ) { 1342 if ( lct_acf_is_selector_repeater( $k ) ) 1374 foreach ( $post['acf'] as $key => $v ) { 1375 /** 1376 * Skip any non-ACF elements 1377 * This should ever happen 1378 */ 1379 if ( ! acf_is_field_key( $key ) ) 1380 continue; 1381 1382 1383 /** 1384 * Vars 1385 */ 1386 $field = acf_get_field( $key ); 1387 $selector = lct_acf_get_selector( $key, false ); 1388 1389 1390 /** 1391 * Loop thru a repeater 1392 */ 1393 if ( lct_acf_is_field_repeater( $key ) ) 1343 1394 $v = lct_acf_get_POST_values_w_selector_key( $v, $return_field, true ); 1344 1395 1345 1396 1397 /** 1398 * Loop thru clones 1399 */ 1400 if ( lct_acf_is_field_clone( $key ) ) 1401 $v = lct_acf_get_POST_values_w_selector_key( $v, $return_field, 'clone_' . $key ); 1402 1403 1404 /** 1405 * Return the full ACF field array 1406 */ 1346 1407 if ( $return_field ) { 1347 // get field 1348 $field = acf_get_field( $k ); 1349 1350 1351 // continue if no field 1408 //continue if no field 1352 1409 if ( ! $field ) { 1353 $r[ $k ] = $v;1410 $r[ $key ] = $v; 1354 1411 1355 1412 … … 1358 1415 1359 1416 1360 // updatearray1417 //Add the value to the field array 1361 1418 $field['value'] = $v; 1362 1419 1363 1420 1364 $r[ $field['name'] ] = $field; 1421 $r[ $selector ] = $field; 1422 1423 1424 /** 1425 * Return just the value 1426 */ 1365 1427 } else { 1366 $key = lct_acf_get_selector( $k, true ); 1367 1368 1369 $r[ $key ] = $v; 1428 $r[ $selector ] = $v; 1429 } 1430 1431 1432 /** 1433 * Flatten clones 1434 */ 1435 if ( 1436 lct_acf_is_field_seamless_clone( $key ) && 1437 $special_process !== 'maintain_seamless_clones' && 1438 ! empty( $r[ $selector ] ) && 1439 is_array( $r[ $selector ] ) 1440 ) { 1441 if ( $return_field ) 1442 $r = array_merge( $r, $r[ $selector ]['value'] ); 1443 else 1444 $r = array_merge( $r, $r[ $selector ] ); 1445 1446 1447 unset( $r[ $selector ] ); 1448 } 1449 } 1450 } 1451 1452 1453 return $r; 1454 } 1455 1456 1457 /** 1458 * When you are saving an ACF form they store the values in an array with the field_key as the array key. 1459 * This function allows you to look up a value by the selector as well 1460 * 1461 * @param array $post 1462 * @param bool|string $special_process //false | true (repeater field_type) | looping | clone_{key} | maintain_seamless_clones 1463 * 1464 * @return array 1465 * @date 2022.10.21 1466 * @since 2022.10 1467 * @verified 2022.10.24 1468 */ 1469 function lct_acf_get_POST_key_selector_map( $post = null, $special_process = false ) { 1470 /** 1471 * Vars 1472 */ 1473 $r = []; 1474 1475 if ( $post === null && isset( $_POST ) ) 1476 $post = $_POST; 1477 1478 if ( empty( $post ) ) 1479 return $r; 1480 1481 $post = lct_clean_acf_repeater( $post ); 1482 1483 1484 /** 1485 * Special processing for a repeater field 1486 */ 1487 if ( $special_process === true ) { 1488 foreach ( $post as $v ) { 1489 $send = [ 'acf' => $v ]; 1490 1491 1492 $r = lct_acf_get_POST_key_selector_map( $send, 'looping' ); 1493 1494 1495 break; 1496 } 1497 1498 1499 return $r; 1500 1501 1502 /** 1503 * Special processing for a clone field 1504 */ 1505 } else if ( 1506 str_starts_with( $special_process, 'clone_' ) && 1507 is_array( $post ) 1508 ) { 1509 $key = substr( $special_process, 6 ); //remove clone_ 1510 1511 1512 foreach ( $post as $k => $v ) { 1513 $clone_key = substr( $k, strlen( $key ) + 1 ); 1514 1515 1516 if ( 1517 ! acf_is_field_key( $k ) || 1518 ! acf_is_field_key( $clone_key ) 1519 ) { 1520 continue; 1521 } 1522 1523 1524 $send = [ 'acf' => [ $clone_key => $v ] ]; 1525 1526 1527 $r = array_merge( $r, lct_acf_get_POST_key_selector_map( $send, 'looping' ) ); 1528 } 1529 1530 1531 return $r; 1532 } 1533 1534 1535 /** 1536 * Set selectors for each key 1537 */ 1538 if ( ! empty( $post['acf'] ) ) { 1539 foreach ( $post['acf'] as $key => $v ) { 1540 /** 1541 * Skip any non-ACF elements 1542 * This should ever happen 1543 */ 1544 if ( ! acf_is_field_key( $key ) ) { 1545 $r[ $key ] = $key; 1546 1547 1548 continue; 1549 } 1550 1551 1552 /** 1553 * Vars 1554 */ 1555 $selector = lct_acf_get_selector( $key, false ); 1556 1557 1558 /** 1559 * Loop thru a repeater 1560 */ 1561 if ( lct_acf_is_field_repeater( $key ) ) 1562 $selector = [ $selector => lct_acf_get_POST_key_selector_map( $v, true ) ]; 1563 1564 1565 /** 1566 * Loop thru clones 1567 */ 1568 if ( lct_acf_is_field_clone( $key ) ) 1569 $selector = lct_acf_get_POST_key_selector_map( $v, 'clone_' . $key ); 1570 1571 1572 /** 1573 * Return just the value 1574 */ 1575 $r[ $key ] = $selector; 1576 1577 1578 /** 1579 * Flatten clones 1580 */ 1581 if ( 1582 lct_acf_is_field_seamless_clone( $key ) && 1583 $special_process !== 'maintain_seamless_clones' && 1584 ! empty( $r[ $key ] ) && 1585 is_array( $r[ $key ] ) 1586 ) { 1587 $r = array_merge( $r, $r[ $key ] ); 1588 1589 1590 unset( $r[ $key ] ); 1370 1591 } 1371 1592 } … … 1426 1647 * Get the selector when you know the key 1427 1648 * 1428 * @param string $key 1429 * @param bool $ return_key1649 * @param string $key //Must be a field_key, or you may get the wrong field returned 1650 * @param bool $strict //Return the found selector OR null ONLY if true, return the provided key if false and selector is not found 1430 1651 * 1431 1652 * @return string|null 1432 1653 * @since 2019.4 1433 * @verified 2019.03.21 1434 */ 1435 function lct_acf_get_selector( $key, $return_key = false ) { 1436 if ( $return_key ) 1437 $r = $key; 1654 * @verified 2022.10.24 1655 */ 1656 function lct_acf_get_selector( $key, $strict = true ) { 1657 /** 1658 * Vars 1659 */ 1660 if ( $strict ) 1661 $selector = null; 1438 1662 else 1439 $ r = null;1440 1441 if ( ! acf_get_store( 'fields' ) ) 1442 return $r;1443 1444 1445 if ( $answer = acf_get_ store( 'fields' )->get( $key ) ) {1663 $selector = $key; 1664 1665 1666 /** 1667 * Search for the selector 1668 */ 1669 if ( $answer = acf_get_field( $key ) ) { 1446 1670 if ( ! empty( $answer['_name'] ) ) 1447 $ r = $answer['_name'];1671 $selector = $answer['_name']; 1448 1672 else if ( ! empty( $answer['name'] ) ) 1449 $ r = $answer['name'];1673 $selector = $answer['name']; 1450 1674 } else if ( 1451 1675 acf_get_store( lct_key_reference() ) && … … 1453 1677 ) { 1454 1678 if ( key_exists( $key, $keys ) ) 1455 $ r = $keys[ $key ];1456 } 1457 1458 1459 return $ r;1460 } 1461 1462 1463 /** 1464 * Check if the selector is a repeaterfield1465 * 1466 * @param $key1679 $selector = $keys[ $key ]; 1680 } 1681 1682 1683 return $selector; 1684 } 1685 1686 1687 /** 1688 * Check if the field is a repeater type field 1689 * 1690 * @param string $key //Should be a key, You can use a selector as well, but you may get the wrong field returned 1467 1691 * 1468 1692 * @return bool 1469 * @since 2019.8 1470 * @verified 2019.04.18 1471 */ 1472 function lct_acf_is_selector_repeater( $key ) { 1473 $r = false; 1474 1475 1476 if ( ! acf_get_store( 'fields' ) ) 1477 return $r; 1478 1479 1693 * @date 2022.10.20 1694 * @since 2022.10 1695 * @verified 2022.10.24 1696 */ 1697 function lct_acf_is_field_repeater( $key ) { 1698 /** 1699 * Check the type 1700 */ 1480 1701 if ( 1481 ( $answer = acf_get_ store( 'fields' )->get( $key ) ) &&1702 ( $answer = acf_get_field( $key ) ) && 1482 1703 $answer['type'] === 'repeater' 1483 1704 ) { 1484 $r = true; 1485 } 1486 1487 1488 return $r; 1705 return true; 1706 } 1707 1708 1709 return false; 1710 } 1711 1712 1713 /** 1714 * Check if the field is a clone type field 1715 * 1716 * @param string $key //Should be a key, You can use a selector as well, but you may get the wrong field returned 1717 * 1718 * @return bool 1719 * @date 2022.10.20 1720 * @since 2022.10 1721 * @verified 2022.10.24 1722 */ 1723 function lct_acf_is_field_clone( $key ) { 1724 /** 1725 * Check the type 1726 */ 1727 if ( 1728 ( $answer = acf_get_field( $key ) ) && 1729 $answer['type'] === 'clone' 1730 ) { 1731 return true; 1732 } 1733 1734 1735 return false; 1736 } 1737 1738 1739 /** 1740 * Check if the field is a seamless clone type field 1741 * 1742 * @param string $key //Should be a key, You can use a selector as well, but you may get the wrong field returned 1743 * 1744 * @return bool 1745 * @date 2022.10.20 1746 * @since 2022.10 1747 * @verified 2022.10.20 1748 */ 1749 function lct_acf_is_field_seamless_clone( $key ) { 1750 /** 1751 * Check the display 1752 */ 1753 if ( 1754 lct_acf_is_field_clone( $key ) && 1755 ( $answer = acf_get_field( $key ) ) && 1756 ! empty( $answer['display'] ) && 1757 $answer['display'] === 'seamless' 1758 ) { 1759 return true; 1760 } 1761 1762 1763 return false; 1489 1764 } 1490 1765 -
lct-useful-shortcodes-functions/trunk/code/plugins/acf/field_settings.php
r2800229 r2815356 78 78 add_filter( 'acf/load_field/type=select', [ $this, 'load_field_update_choices' ] ); 79 79 80 80 81 /** 81 82 * clone 82 * //TODO: cs - Need to fix this when we start using it again - 9/29/2022 9:56 PM83 83 */ 84 //add_filter( 'acf/load_field/type=clone', [ $this, 'load_field_update_choices_clone' ]);84 add_filter( 'acf/clone_field', [ $this, 'clone_field_update_choices' ], 999, 2 ); 85 85 86 86 … … 504 504 * Add the items of preset_choices to $field['choices'] 505 505 * 506 * @param $field507 * 508 * @return mixed506 * @param array $field 507 * 508 * @return array 509 509 * @since 7.29 510 510 * @verified 2021.04.30 … … 555 555 556 556 /** 557 * Add the items of preset_choices to $field['choices'] 558 * 559 * @param $field 560 * 561 * @return mixed 562 * @since 2018.64 563 * @verified 2021.04.30 564 */ 565 function load_field_update_choices_clone( $field ) { 566 if ( lct_acf_is_field_group_editing_page() ) //Don't load on ACf edit pages 567 return $field; 568 569 570 if ( ! empty( $field['clone'] ) ) { 571 foreach ( $field['clone'] as $clone ) { 572 if ( 573 ( $clone_field = get_field_object( $clone ) ) && 574 in_array( $clone_field['type'], $this->check_when_cloned ) 575 ) { 576 if ( 577 ( $tmp = get_cnst( 'preset_choices' ) ) && 578 isset( $clone_field[ $tmp ] ) && 579 ( $preset_choice = $clone_field[ $tmp ] ) 580 ) { 581 if ( strpos( $preset_choice, zxzd() ) !== false ) { 582 $parts = explode( zxzd(), $preset_choice ); 583 $plugin = $parts[0]; 584 $preset_choice = $parts[1]; 585 586 587 if ( $class_set = lct_get_later( $plugin . '_acf_public_choices' ) ) 588 $class = $class_set; 589 else 590 $class = $plugin()->acf_public_choices; 591 592 593 add_filter( 'acf/prepare_field/name=' . $clone_field['name'], [ $class, $preset_choice ] ); 594 595 596 } else if ( 597 isset( $GLOBALS['lct_mu']->action ) && 598 strpos( $GLOBALS['lct_mu']->action, 'acf/' ) === 0 && 599 strpos( $GLOBALS['lct_mu']->action, '/query' ) !== false 600 ) { 601 add_filter( 'acf/load_field/name=' . $clone_field['name'], [ lct()->acf_public_choices, $preset_choice ] ); 602 } else { 603 add_filter( 'acf/prepare_field/name=' . $clone_field['name'], [ lct()->acf_public_choices, $preset_choice ] ); 604 } 605 } 606 } 607 } 608 } 609 557 * Add the items of preset_choices to $field['choices'] for clone fields 558 * 559 * @param array $field 560 * @param array $clone_field 561 * 562 * @return array 563 * @date 2022.10.24 564 * @since 2022.10 565 * @verified 2022.10.24 566 */ 567 function clone_field_update_choices( $field, $clone_field ) { 568 if ( 569 ! empty( $field['type'] ) && 570 in_array( $field['type'], $this->check_when_cloned ) 571 ) { 572 $field = $this->load_field_update_choices( $field ); 573 } 610 574 611 575 return $field; -
lct-useful-shortcodes-functions/trunk/code/plugins/acf/instant_save.php
r2782154 r2815356 172 172 173 173 if ( $this->vars['post_id'] !== null ) { 174 $ info= acf_decode_post_id( $this->vars['post_id'] );175 176 177 $this->vars['info_id'] = (int) $ info['id'];178 $this->vars['info_type'] = $ info['type'];179 180 181 if ( $ info['type'] === 'post' )174 $decoded = acf_decode_post_id( $this->vars['post_id'] ); 175 176 177 $this->vars['info_id'] = (int) $decoded['id']; 178 $this->vars['info_type'] = $decoded['type']; 179 180 181 if ( $decoded['type'] === 'post' ) 182 182 $this->vars['post_id'] = (int) $this->vars['post_id']; 183 183 } … … 565 565 566 566 if ( $vars['post_id'] !== null ) { 567 $ info= acf_decode_post_id( $vars['post_id'] );568 569 570 $vars['info_id'] = (int) $ info['id'];571 $vars['info_type'] = $ info['type'];572 573 574 if ( $ info['type'] === 'post' )567 $decoded = acf_decode_post_id( $vars['post_id'] ); 568 569 570 $vars['info_id'] = (int) $decoded['id']; 571 $vars['info_type'] = $decoded['type']; 572 573 574 if ( $decoded['type'] === 'post' ) 575 575 $vars['post_id'] = (int) $vars['post_id']; 576 576 } -
lct-useful-shortcodes-functions/trunk/code/plugins/acf/public_choices.php
r2253752 r2815356 66 66 'pretty_acf_fields_list' => 'List of ACF Fields', 67 67 'pretty_state_list' => 'List of the US states', 68 'pretty_state_abbr_value_list' => 'List of the US states (with abbr. as value)', 68 69 'pretty_wp_roles' => 'WordPress Roles', 69 70 'pretty_wp_caps' => 'WordPress Capabilities', … … 193 194 194 195 /** 196 * Array of US states with the lowercase abbr. as the value 197 * 198 * @return array 199 * @date 2022.10.19 200 * @since 2022.10 201 * @verified 2022.10.19 202 */ 203 function pretty_state_abbr_value_list_data() { 204 $states = [ 205 'al' => 'Alabama', 206 'ak' => 'Alaska', 207 'az' => 'Arizona', 208 'ar' => 'Arkansas', 209 'ca' => 'California', 210 'co' => 'Colorado', 211 'ct' => 'Connecticut', 212 'de' => 'Delaware', 213 'dc' => 'District of Columbia', 214 'fl' => 'Florida', 215 'ga' => 'Georgia', 216 'hi' => 'Hawaii', 217 'id' => 'Idaho', 218 'il' => 'Illinois', 219 'in' => 'Indiana', 220 'ia' => 'Iowa', 221 'ks' => 'Kansas', 222 'ky' => 'Kentucky', 223 'la' => 'Louisiana', 224 'me' => 'Maine', 225 'md' => 'Maryland', 226 'ma' => 'Massachusetts', 227 'mi' => 'Michigan', 228 'mn' => 'Minnesota', 229 'ms' => 'Mississippi', 230 'mo' => 'Missouri', 231 'mt' => 'Montana', 232 'ne' => 'Nebraska', 233 'nv' => 'Nevada', 234 'nh' => 'New Hampshire', 235 'nj' => 'New Jersey', 236 'nm' => 'New Mexico', 237 'ny' => 'New York', 238 'nc' => 'North Carolina', 239 'nd' => 'North Dakota', 240 'oh' => 'Ohio', 241 'ok' => 'Oklahoma', 242 'or' => 'Oregon', 243 'pa' => 'Pennsylvania', 244 'ri' => 'Rhode Island', 245 'sc' => 'South Carolina', 246 'sd' => 'South Dakota', 247 'tn' => 'Tennessee', 248 'tx' => 'Texas', 249 'ut' => 'Utah', 250 'vt' => 'Vermont', 251 'va' => 'Virginia', 252 'wa' => 'Washington', 253 'wv' => 'West Virginia', 254 'wi' => 'Wisconsin', 255 'wy' => 'Wyoming', 256 ]; 257 258 259 return $states; 260 } 261 262 263 /** 264 * Add US states to choices with the lowercase abbr. as the value 265 * Call: 266 * add_filter( 'acf/prepare_field/name=' . zxzacf( 'field' ), [ lct()->acf_public_choices, 'pretty_state_abbr_value_list' ] ); 267 * 268 * @param $field 269 * 270 * @return array 271 * @date 2022.10.19 272 * @since 2022.10 273 * @verified 2022.10.19 274 */ 275 function pretty_state_abbr_value_list( $field ) { 276 $field['placeholder'] = 'Choose a State...'; 277 278 $field['choices'] = $this->pretty_state_abbr_value_list_data(); 279 280 281 return $field; 282 } 283 284 285 /** 195 286 * Full list of ACF field groups 196 287 * -
lct-useful-shortcodes-functions/trunk/lct-useful-shortcodes-functions.php
r2800229 r2815356 4 4 * Plugin URI: https://www.simplesmithmedia.com 5 5 * Description: Shortcodes & Functions that will help make your life easier. 6 * Version: 2022. 96 * Version: 2022.10 7 7 * Author: SimpleSmithMedia 8 8 * Author URI: https://www.simplesmithmedia.com -
lct-useful-shortcodes-functions/trunk/readme.txt
r2800229 r2815356 3 3 Tags: Functions, Shortcodes 4 4 Requires at least: 5.0 5 Tested up to: 6. 0.25 Tested up to: 6.1 6 6 Requires PHP: 7.4 7 7 License: GPLv2 or later … … 33 33 34 34 == Changelog == 35 = 2022.10 = 36 *Release Date - 09 November 2022* 37 38 * WP v6.1 Ready 39 * Added: 40 * lct_acf_public_choices{}pretty_state_abbr_value_list() 41 * lct_acf_public_choices{}pretty_state_abbr_value_list_data() 42 * lct_acf_is_field_repeater() 43 * lct_acf_is_field_clone() 44 * lct_acf_is_field_seamless_clone() 45 * P_R_loop() 46 * lct_acf_get_POST_key_selector_map() 47 * add_filter( 'acf/clone_field', [ $this, 'clone_field_update_choices' ], 999, 2 ); 48 * Updated: 49 * lct_acf_get_POST_values_w_selector_key() 50 * P_R() 51 * [lct_get_the_title] 52 * Improved: 53 * lct_acf_loaded{}prepare_fields_for_import() 54 * lct_acf_get_POST_value() 55 * lct_acf_get_selector() 56 * lct_clean_acf_repeater() 57 * Removed: 58 * lct_acf_is_selector_repeater() 59 * add_filter( 'acf/load_field/type=clone', [ $this, 'load_field_update_choices_clone' ] ); 60 35 61 = 2022.9 = 36 62 *Release Date - 17 October 2022*
Note: See TracChangeset
for help on using the changeset viewer.