Plugin Directory

Changeset 2815356


Ignore:
Timestamp:
11/09/2022 04:24:00 PM (3 years ago)
Author:
ircary
Message:

2022.10

*Release Date - 09 November 2022*

  • WP v6.1 Ready
  • Added:
    • lct_acf_public_choices{}pretty_state_abbr_value_list()
    • lct_acf_public_choices{}pretty_state_abbr_value_list_data()
    • lct_acf_is_field_repeater()
    • lct_acf_is_field_clone()
    • lct_acf_is_field_seamless_clone()
    • P_R_loop()
    • lct_acf_get_POST_key_selector_map()
    • add_filter( 'acf/clone_field', [ $this, 'clone_field_update_choices' ], 999, 2 );
  • Updated:
    • lct_acf_get_POST_values_w_selector_key()
    • P_R()
    • [lct_get_the_title]
  • Improved:
    • lct_acf_loaded{}prepare_fields_for_import()
    • lct_acf_get_POST_value()
    • lct_acf_get_selector()
    • lct_clean_acf_repeater()
  • Removed:
    • lct_acf_is_selector_repeater()
    • add_filter( 'acf/load_field/type=clone', [ $this, 'load_field_update_choices_clone' ] );
Location:
lct-useful-shortcodes-functions/trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • lct-useful-shortcodes-functions/trunk/code/api/class.php

    r2800229 r2815356  
    825825            ! empty( $field['taxonomy'] ) &&
    826826            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' &&
    829829            ( $status = get_term( $value, $field['taxonomy'] ) ) &&
    830830            ! lct_is_wp_error( $status ) &&
     
    884884            ! empty( $field['taxonomy'] ) &&
    885885            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' &&
    888888            ( $post_status = get_post_status( $post_id ) ) &&
    889889            strpos( $post_status, '_' ) !== false
     
    983983
    984984        //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' ] );
    987987
    988988
     
    10271027            if (
    10281028                $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'
    10311031            ) {
    10321032                $terms     = [];
  • lct-useful-shortcodes-functions/trunk/code/api/debug.php

    r2782154 r2815356  
    8888     * @return bool|string
    8989     * @since    0.0
    90      * @verified 2016.11.29
     90     * @verified 2022.10.21
    9191     */
    9292    function P_R( $var, $name = 'Name Not Set', $return = false ) {
    9393        $skip = [ 'HTTP_COOKIE' ];
    9494        $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;">';
    9897        $h .= '<tr><th class="' . $c . '" colspan="2">' . $name . '</th></tr>';
    9998
     
    114113            $h .= '<td class="' . $c . '">';
    115114
    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 );
    144116
    145117            $h .= '</td>';
     
    167139
    168140        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;
    169189    }
    170190}
  • lct-useful-shortcodes-functions/trunk/code/features/shortcodes/sort.php

    r2642123 r2815356  
    281281     * @return string
    282282     * @since    5.36
    283      * @verified 2016.11.04
     283     * @verified 2022.11.03
    284284     */
    285285    function get_the_title( $a ) {
     
    293293        else if ( ! empty( $post ) )
    294294            $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 ) )
    300314            $title = get_the_title( $post_id );
    301315
  • lct-useful-shortcodes-functions/trunk/code/plugins/acf/_loaded.php

    r2771323 r2815356  
    107107     * @return array
    108108     * @since        2019.2
    109      * @verified     2020.02.26
     109     * @verified     2022.10.19
    110110     */
    111111    function prepare_fields_for_import( $fields ) {
     
    125125
    126126        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
    127153            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 ) ||
    137155                (
    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
    140158                ) ||
    141159                (
    142                     strpos( $field['key'], '_' ) === 0 &&
    143                     $field['name'] === $field['key']
     160                    strpos( $field_key, '_' ) === 0 &&
     161                    $field_name === $field_key
    144162                ) ||
    145163                apply_filters( 'lct_acf_loaded/prepare_fields_for_import/ignore', false, $field, $this->references['keys'] )
     
    149167
    150168
    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;
    154172        }
    155173
     
    322340        $is_comment   = false;
    323341        $keys         = [];
    324         $info         = acf_decode_post_id( $post_id );
     342        $decoded      = acf_decode_post_id( $post_id );
    325343        $taxonomy     = null;
    326344
     
    371389            }
    372390        } else {
    373             switch ( $info['type'] ) {
     391            switch ( $decoded['type'] ) {
    374392                case 'term':
    375393                    if (
     
    386404                case 'user':
    387405                    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'] ] ) )
    390408                    ) {
    391409                        foreach ( $groups as $group ) {
     
    544562
    545563
    546                 switch ( $info['type'] ) {
     564                switch ( $decoded['type'] ) {
    547565                    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';
    550568                        break;
    551569
    552570
    553571                    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';
    556574                        break;
    557575
    558576
    559577                    case 'comment':
    560                         $info['type_match']      = [ 'comment' ];
    561                         $info['type_match_root'] = 'comment';
     578                        $decoded['type_match']      = [ 'comment' ];
     579                        $decoded['type_match_root'] = 'comment';
    562580                        break;
    563581
    564582
    565583                    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';
    568586
    569587
     
    620638                        foreach ( $locations as $choices ) {
    621639                            if (
    622                                 ! in_array( $choices['param'], $info['type_match'] ) &&
     640                                ! in_array( $choices['param'], $decoded['type_match'] ) &&
    623641                                ( $unset_key = array_search( $key, $keys ) ) !== false
    624642                            ) {
     
    626644                            } else if (
    627645                                ! $new_post &&
    628                                 $info['type_match_root'] === 'post_type' &&
     646                                $decoded['type_match_root'] === 'post_type' &&
    629647                                $choices['operator'] === '!=' &&
    630648                                $choices['value'] === $post_type &&
    631649                                ( $unset_key = array_search( $key, $keys ) ) !== false &&
    632                                 in_array( $choices['param'], $info['type_match'] )
     650                                in_array( $choices['param'], $decoded['type_match'] )
    633651                            ) {
    634652                                $unset = true;
    635653                            } else if (
    636654                                ! $new_post &&
    637                                 $info['type_match_root'] === 'post_type' &&
     655                                $decoded['type_match_root'] === 'post_type' &&
    638656                                $choices['operator'] === '==' &&
    639657                                $choices['value'] !== $post_type &&
    640658                                ( $unset_key = array_search( $key, $keys ) ) !== false &&
    641                                 in_array( $choices['param'], $info['type_match'] )
     659                                in_array( $choices['param'], $decoded['type_match'] )
    642660                            ) {
    643661                                $unset = true;
    644662                            } else if (
    645663                                ! $new_post &&
    646                                 $info['type_match_root'] === 'taxonomy' &&
     664                                $decoded['type_match_root'] === 'taxonomy' &&
    647665                                $choices['value'] !== $taxonomy &&
    648666                                ( $unset_key = array_search( $key, $keys ) ) !== false &&
    649                                 in_array( $choices['param'], $info['type_match'] )
     667                                in_array( $choices['param'], $decoded['type_match'] )
    650668                            ) {
    651669                                $unset = true;
    652670                            } else if (
    653671                                ! $new_post &&
    654                                 $info['type_match_root'] === 'user' &&
     672                                $decoded['type_match_root'] === 'user' &&
    655673                                $choices['param'] === 'user_role' &&
    656                                 ! empty( $info['id'] ) &&
    657                                 ( $user = get_userdata( $info['id'] ) ) &&
     674                                ! empty( $decoded['id'] ) &&
     675                                ( $user = get_userdata( $decoded['id'] ) ) &&
    658676                                ! lct_is_wp_error( $user ) &&
    659677                                $choices['value'] !== 'all' &&
     
    666684                                $choices['value'] !== $new_post &&
    667685                                ( $unset_key = array_search( $key, $keys ) ) !== false &&
    668                                 in_array( $choices['param'], $info['type_match'] )
     686                                in_array( $choices['param'], $decoded['type_match'] )
    669687                            ) {
    670688                                $unset = true;
     
    676694                                    ( $unique_post_types = apply_filters( 'lct/acf/load_reference/unique_post_types', null ) ) &&
    677695                                    ! $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'] ) &&
    680698                                    in_array( $choices['value'], $unique_post_types )
    681699                                ) {
  • lct-useful-shortcodes-functions/trunk/code/plugins/acf/api/_helpers.php

    r2679272 r2815356  
    862862/**
    863863 * 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 *
    869867 * @return array
    870868 * @since    2020.5
    871  * @verified 2020.02.07
    872  */
    873 function lct_clean_acf_repeater( array $array ) {
     869 * @verified 2022.10.24
     870 */
     871function lct_clean_acf_repeater( $array ) {
     872    if ( ! is_array( $array ) )
     873        return $array;
     874
     875
    874876    foreach ( $array as $k => $v ) {
    875877        if ( $k === 'acfcloneindex' )
  • lct-useful-shortcodes-functions/trunk/code/plugins/acf/api/get.php

    r2800229 r2815356  
    687687/**
    688688 * Get the ACF group of a field
     689 * Don't use this
    689690 *
    690691 * @param string|array $field_parent
     
    11451146 * @return mixed|null
    11461147 * @since    2019.4
    1147  * @verified 2021.03.09
     1148 * @verified 2022.10.20
    11481149 */
    11491150function lct_acf_get_POST_value( $selector, $post_id = null, $format_value = false, $double_check = true ) {
     
    12091210
    12101211
    1211         if ( lct_acf_is_selector_repeater( $selector ) ) {
     1212        if ( lct_acf_is_field_repeater( $selector ) ) {
    12121213            $r = lct_acf_get_POST_values_w_selector_key( $r, false, true );
    12131214        } else if (
     
    12621263
    12631264
    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 )
    12651266        return $r;
    12661267
     
    12971298 *
    12981299 * @param array       $post
    1299  * @param bool        $return_field
    1300  * @param bool|string $repeater
     1300 * @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
    13011302 *
    13021303 * @return array
    13031304 * @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 */
     1307function lct_acf_get_POST_values_w_selector_key( $post = null, $return_field = false, $special_process = false ) {
     1308    /**
     1309     * Vars
     1310     */
    13071311    $r = [];
    13081312
    1309 
    1310     if ( $post === null )
     1313    if ( $post === null && isset( $_POST ) )
    13111314        $post = $_POST;
    13121315
    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 ) {
    13211326        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            ) {
    13231355                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' ) );
    13331363        }
    13341364
     
    13381368
    13391369
     1370    /**
     1371     * Swap out keys --TO-- selectors
     1372     */
    13401373    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 ) )
    13431394                $v = lct_acf_get_POST_values_w_selector_key( $v, $return_field, true );
    13441395
    13451396
     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             */
    13461407            if ( $return_field ) {
    1347                 // get field
    1348                 $field = acf_get_field( $k );
    1349 
    1350 
    1351                 // continue if no field
     1408                //continue if no field
    13521409                if ( ! $field ) {
    1353                     $r[ $k ] = $v;
     1410                    $r[ $key ] = $v;
    13541411
    13551412
     
    13581415
    13591416
    1360                 // update array
     1417                //Add the value to the field array
    13611418                $field['value'] = $v;
    13621419
    13631420
    1364                 $r[ $field['name'] ] = $field;
     1421                $r[ $selector ] = $field;
     1422
     1423
     1424                /**
     1425                 * Return just the value
     1426                 */
    13651427            } 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 */
     1469function 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 ] );
    13701591            }
    13711592        }
     
    14261647 * Get the selector when you know the key
    14271648 *
    1428  * @param string $key
    1429  * @param bool   $return_key
     1649 * @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
    14301651 *
    14311652 * @return string|null
    14321653 * @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 */
     1656function lct_acf_get_selector( $key, $strict = true ) {
     1657    /**
     1658     * Vars
     1659     */
     1660    if ( $strict )
     1661        $selector = null;
    14381662    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 ) ) {
    14461670        if ( ! empty( $answer['_name'] ) )
    1447             $r = $answer['_name'];
     1671            $selector = $answer['_name'];
    14481672        else if ( ! empty( $answer['name'] ) )
    1449             $r = $answer['name'];
     1673            $selector = $answer['name'];
    14501674    } else if (
    14511675        acf_get_store( lct_key_reference() ) &&
     
    14531677    ) {
    14541678        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 repeater field
    1465  *
    1466  * @param $key
     1679            $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
    14671691 *
    14681692 * @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 */
     1697function lct_acf_is_field_repeater( $key ) {
     1698    /**
     1699     * Check the type
     1700     */
    14801701    if (
    1481         ( $answer = acf_get_store( 'fields' )->get( $key ) ) &&
     1702        ( $answer = acf_get_field( $key ) ) &&
    14821703        $answer['type'] === 'repeater'
    14831704    ) {
    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 */
     1723function 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 */
     1749function 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;
    14891764}
    14901765
  • lct-useful-shortcodes-functions/trunk/code/plugins/acf/field_settings.php

    r2800229 r2815356  
    7878        add_filter( 'acf/load_field/type=select', [ $this, 'load_field_update_choices' ] );
    7979
     80
    8081        /**
    8182         * clone
    82          * //TODO: cs - Need to fix this when we start using it again - 9/29/2022 9:56 PM
    8383         */
    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 );
    8585
    8686
     
    504504     * Add the items of preset_choices to $field['choices']
    505505     *
    506      * @param $field
    507      *
    508      * @return mixed
     506     * @param array $field
     507     *
     508     * @return array
    509509     * @since    7.29
    510510     * @verified 2021.04.30
     
    555555
    556556    /**
    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        }
    610574
    611575        return $field;
  • lct-useful-shortcodes-functions/trunk/code/plugins/acf/instant_save.php

    r2782154 r2815356  
    172172
    173173        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' )
    182182                $this->vars['post_id'] = (int) $this->vars['post_id'];
    183183        }
     
    565565
    566566        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' )
    575575                $vars['post_id'] = (int) $vars['post_id'];
    576576        }
  • lct-useful-shortcodes-functions/trunk/code/plugins/acf/public_choices.php

    r2253752 r2815356  
    6666                'pretty_acf_fields_list'           => 'List of ACF Fields',
    6767                'pretty_state_list'                => 'List of the US states',
     68                'pretty_state_abbr_value_list'     => 'List of the US states (with abbr. as value)',
    6869                'pretty_wp_roles'                  => 'WordPress Roles',
    6970                'pretty_wp_caps'                   => 'WordPress Capabilities',
     
    193194
    194195    /**
     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    /**
    195286     * Full list of ACF field groups
    196287     *
  • lct-useful-shortcodes-functions/trunk/lct-useful-shortcodes-functions.php

    r2800229 r2815356  
    44 * Plugin URI: https://www.simplesmithmedia.com
    55 * Description: Shortcodes & Functions that will help make your life easier.
    6  * Version: 2022.9
     6 * Version: 2022.10
    77 * Author: SimpleSmithMedia
    88 * Author URI: https://www.simplesmithmedia.com
  • lct-useful-shortcodes-functions/trunk/readme.txt

    r2800229 r2815356  
    33Tags: Functions, Shortcodes
    44Requires at least: 5.0
    5 Tested up to: 6.0.2
     5Tested up to: 6.1
    66Requires PHP: 7.4
    77License: GPLv2 or later
     
    3333
    3434== 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
    3561= 2022.9 =
    3662*Release Date - 17 October 2022*
Note: See TracChangeset for help on using the changeset viewer.