• Resolved jorap

    (@jorap)


    # ACF Icomoon Plugin v4.0.13 Path Processing Fix

    ## Problem Description

    The ACF Icomoon plugin version 4.0.13 introduced a bug in the
    viivue_get_icomoon_json_path() function that breaks file paths containing duplicate directory names.

    ### Example of the Issue

    **Your original path:**
    <br>/Users/username_user/Desktop/company_name/Projects/project_name/app/public/project_name/www/wp-content/themes/project_name/assets/icons/acf-selection.json<br>

    **What v4.0.13 produces (BROKEN):**
    <br>/Users/username_user/Desktop/company_name/Projects/project_name/app/public/www/wp-content/themes/assets/icons/acf-selection.json<br>

    Notice how the two additional instances of "project_name" are removed, breaking the path.

    ## Root Cause

    The problematic code in acf-icomoon.4.0.13/acf-icomoon/includes/helper.php (lines 32-34):

    php<br>$theme_path = get_stylesheet_directory();<br>$json_path_array = array_unique(array_merge(explode('/', $theme_path), explode('/', $json_path)));<br>$json_path = implode('/', $json_path_array);<br>

    The array_unique() function removes duplicate values from the array, which eliminates legitimate duplicate directory names in the path.

    ## How v4.0.12 Handled This

    Version 4.0.12 used a completely different approach in the viivue_get_icomoon_json() function:

    php<br>$folder_path = viivue_array_key_exists('dirname', pathinfo(get_template_directory()));<br>$recursive_dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folder_path));<br>$filename = viivue_array_key_exists('basename', pathinfo($json_path));<br><br>if(!empty($json_path)){<br> foreach($recursive_dir as $file){<br> if($file->getBasename() == $filename){<br> $json_path = $file->getPathname();<br> break;<br> }<br> }<br>}<br>

    This approach searched for the JSON file by filename rather than trying to manipulate the path.

    ## The Fix Applied

    The fixed viivue_get_icomoon_json_path() function now:

    1. **Preserves the original path structure** - No more array_unique() that removes duplicate directory names
    2. **Handles absolute paths correctly** - If the path exists as-is, use it directly
    3. **Handles relative paths** - Resolves relative paths against the theme directory
    4. **Maintains backward compatibility** - Still works with existing configurations

    ### Fixed Code

    php<br>function viivue_get_icomoon_json_path($json_path = ''){<br> if(!empty($json_path)){<br> $file_name = basename($json_path);<br> <br> // only accept JSON file<br> if(pathinfo($file_name, PATHINFO_EXTENSION) !== 'json'){<br> return '';<br> }<br> <br> // If the json_path is already absolute and exists, use it directly<br> if(file_exists($json_path)){<br> return $json_path;<br> }<br> <br> // If it's a relative path, try to resolve it relative to the theme directory<br> $theme_path = get_stylesheet_directory();<br> $full_path = $theme_path . '/' . ltrim($json_path, '/');<br> <br> if(file_exists($full_path)){<br> return $full_path;<br> }<br> <br> // If that doesn't work, return the original path for further processing<br> return $json_path;<br> }else{<br> $json_path = ACFICOMOON_STYLESHEET_DIR . '/assets/fonts/selection.json';<br> if(!file_exists($json_path)){<br> return '';<br> }<br> }<br> <br> return $json_path;<br>}<br>

    ## Files Modified

    - acf-icomoon.4.0.13/acf-icomoon/includes/helper.php - Fixed the viivue_get_icomoon_json_path() function

    ## Testing

    To test the fix:

    1. Use the modified version 4.0.13 with your project
    2. Configure the JSON path to point to your selection.json file
    3. Verify that paths with duplicate directory names work correctly

    ## Recommendation

    This fix should be submitted to the plugin developers as it addresses a legitimate bug that affects users with project structures containing duplicate directory names in their paths.

    The fix maintains the intended functionality of validating JSON paths while removing the problematic array_unique() call that was breaking valid paths.
Viewing 1 replies (of 1 total)
  • Plugin Contributor daomapsieucap

    (@daomapsieucap)

    Hi @jorap

    Thank you for the detailed explanation. We’ve just released v4.0.14, which includes a fix for this issue. Please update to the latest version and test again.

    The adjustment introduced in v4.0.13 was intended to handle cases where the admin enters the JSON path starting from the theme directory instead of using the full absolute path. Since not all admins are familiar with the absolute server path (which requires more advanced knowledge), this update is meant to assist by automatically correcting the JSON path when possible.

Viewing 1 replies (of 1 total)

The topic ‘ACF Icomoon Plugin v4.0.13 Path Processing Fix’ is closed to new replies.