Ever have a client that can’t give you FTP access? Usually not a big deal if you’re using WP, because you can use the Theme Editor to edit your files. But then, surely you’ve noticed, the WP Theme Editor doesn’t allow you to edit JS files… (Though, really annoyingly, you can edit JS files via the Plugin Editor… whaaaat theeee…??)
I finally got sick of this and decided to figure out how to fix this issue. I mean, it might even be as simple as some regex somewhere that was blocking anything with .js, right?
Well, actually, yes, that’s almost exactly what it is. But unfortunately all the restriction takes place inside WP Core files, which I would really rather not edit, for obvious reasons, and I cannot find any hooks that will do the job…
I’ve found three solutions that do not satisfy me:
- In
wp-includes/themes.php, insideget_themes()on line 352, editif ( preg_match('|\.css$|', $file) )so it also allows.js. - In
wp-admin/theme-editor.php, on line 58, just before$allowed_filesis defined, add$themes[$theme]['Stylesheet Files'][] = TEMPLATEPATH.'/scripts.js';. - Put my
scripts.jsfile into a folder insidewp-content/pluginsso WP will think it’s a plug-in, allowing me to jump over the Plug-in Editor to edit it.
Any better ideas out there? Would love to hear them…
Atg
You can create a template file with the standard Template Name header and serve that as a JS file in PHP by altering the header(“Content-type: text/javascript”);
Downfall — you won’t be able to use register/enqueue scripts. But you can probably write a hook to load your PHP-fake js file after enqueue scripts occur
@ DavidOSomething: Right, and I’d have to link to that file as a
.phpfile, because the WP Core code is actually filtering on.cssand.php; no other file extensions are permitted into the list of files you can select to edit. This isn’t terrible, and it’s another good option, thanks!very nice
i like it ;) thanks
Hi! For your 3 solutions, wouldn’t you still need FTP access to implement those solutions? It doesn’t seem like the files you mentioned are editable through the CMS…
PS: How dumb that you can’t edit JS but you can edit PHP. You’re much more likely to make a horrible mistake editing the PHP!!
@Heather: No, no FTP required, the above three solutions would all allow me to edit JS files via the WP Admin GUI, I just don’t like any of the solutions, they’re all less than ideal… :-)
Cheers,
Atg
Hi ATG,
Not a big wordpress fan, but Im still confused how you would add/install the scripts.js ‘plugin’ from the GUI ??
@Erick: No, you’re absolutely right, aside from submitting your JS “plugin” to the WP Repository, then adding that plugin via the admin GUI, there is no way. I was really only thinking about editing…
yeah, but without ftp I can’t edit the core files that you refer to in your solution. correct?
@John: also correct… sadly… you cannot (and should not) edit the core files, yet cannot add new files or edit JS files via the editor.