fix: Proactively create webfonts directories on admin init#130
Open
kausaralm wants to merge 1 commit intooceanwp:masterfrom
Open
fix: Proactively create webfonts directories on admin init#130kausaralm wants to merge 1 commit intooceanwp:masterfrom
kausaralm wants to merge 1 commit intooceanwp:masterfrom
Conversation
Fixes oceanwp#127 - Ensures oceanwp-webfonts and oceanwp-webfonts-css directories exist before they are needed by calling wp_mkdir_p() on admin_init hook. This minimal approach (~15 lines) silently creates the folders when any admin visits the dashboard, preventing the issue where folders don't exist when custom fonts are loaded.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes #127 by proactively creating the required
oceanwp-webfontsandoceanwp-webfonts-cssdirectories when an admin visits any WordPress admin page.Problem
Currently, the plugin creates these directories on-demand when Google Fonts are loaded locally. However, if the directories do not exist before the font loading process begins, users encounter errors. This is especially problematic for:
Solution
Added a lightweight
admin_inithook that checks for the existence of both directories and creates them if missing. This approach was chosen for the following reasons:ocean.phpfileis_dir()check is extremely fast when folders existwp_mkdir_p()function already used elsewhere in the codebaseCode Changes
Before
The directories were only created when
oceanwp_get_local_webfonts_data_dir()oroceanwp_get_local_webfonts_css_data_dir()functions were called during font loading. If the font loading process failed before reaching these functions, the directories would never be created.After
Why This Helps Non-Technical Users
Before this fix, users without FTP/SSH access had no way to resolve the missing folder issue on their own. They would need to:
With this fix, the problem simply does not occur. The folders are created automatically the first time any admin visits the WordPress dashboard. Users will never see folder-related errors, and the plugin becomes more plug-and-play friendly.
Testing
To verify this fix works correctly:
oceanwp-webfontsandoceanwp-webfonts-cssfolders from/wp-content/uploads//wp-content/uploads/Checklist
function_exists()check for compatibility@sinceand@seetagswp_upload_dir(),wp_mkdir_p(),trailingslashit())