Is there a tool that will allow me to text-search all php/css files?
October 25, 2017 2:40 PM   Subscribe

I'm finding it difficult to setup & config PHPStorm IDE for Wordpress so I am wondering if there is plugin or a tool that will allow me to do a search for a line of code through various php and css files that live in /wp-admin/ /wp-content/ and the actual root. Maybe there is some SFTP tool that allows for this type of search? Generally, I do Control + F and go file by file within Wordpress Editor, but I just inherited a site that has over 150 php files and 200 css and need to find certain things much faster. Any help is appreciated! Thank you!
posted by cheero to Computers & Internet (10 answers total) 1 user marked this as a favorite
 
If you have command-line access to your hosting server via SSH (and it's *nix-based), the grep command is ideal for this. But honestly, in this situation I'd just download local copies all the relevant site files and use a text editor's file search option to scan the directories.

NotePad++ (free) will do this easily if you're on Windows. BBEdit will do the same on OS X. It's not a free product, but there's a trial period.
posted by figurant at 3:02 PM on October 25, 2017


Seconding Notepad++ for searching across files.
posted by baseballpajamas at 3:04 PM on October 25, 2017


My instinct would be grep for this. If you don't know regular expressions they're definitely worth learning. The command line, in general, is worth the trouble to learn, because there are some things that are just plain efficient with it.
posted by Alensin at 3:17 PM on October 25, 2017


Thirding grep. If you can SFTP, you can SSH (usually). Use grep!
posted by destructive cactus at 3:24 PM on October 25, 2017


Yup - now is the perfect time to learn how to use the command line. This is where it shines. I do these sorts of searches every single day. Your version of sh/bash/whatever may differ.

find . -name '*.css' -type f -exec grep -l 'SEARCH TERM' -l {} \;

will list all the css files containing 'SEARCH TERM', for example

That said... PHPStorm is *usually* pretty good about indexing all the things, as long as it's configured correctly. I dont have it open, so I cant tell you what those configs are, but double-press the Shift button (on OSX at least) and it brings up the magical "Search Everywhere" function. Try that and see if it helps.
posted by cgg at 3:38 PM on October 25, 2017


missed the edit window - delete the second '-l' in the find command above
posted by cgg at 3:50 PM on October 25, 2017


Command line server side stuff is fine, but if you're making changes, you're going to want a local environment.

1. Get a local Wordpress environment going with MAMP. This is very straightforward.

2. Install a wordpress migration tool like this one on both your local site and the production site.

3. Export to file from the production site, import from file on local site.

Now you can access a local version of your site with whatever tools you like, including grep etc. if you like. I use VS Code these days, but any IDE is going to let you search across project files easily. Bonus; you can test whatever changes you want before you deploy them.
posted by Kwine at 4:11 PM on October 25, 2017 [2 favorites]


Agent Ransack is great for this!
https://www.mythicsoft.com/agentransack

I use it often for searching text within code. Its very fast and has a lot of options to help narrow your search.
posted by nalyd at 4:34 PM on October 25, 2017


Seconding Kwine; the fact that you're asking this question suggests to me that you're making modifications to an in-production environment which is generally a bad idea. Download a copy of the site files, use a tool that works on local files to do your searching (I like Agent Ransack myself), ideally test the changes in a local environment, then deploy to your production server. Add a version control system (like git or SVN) to the system and you can even roll back to earlier versions if there's a problem with your change.
posted by Aleyn at 6:00 PM on October 25, 2017


PHPStorm has Find in Path which is exactly what you are looking for. Right-click on the folder of interest and choose "find in path" to search for strings in all files and folders within that folder.
posted by rockindata at 7:07 PM on October 25, 2017


« Older What's the key to a good Halloween party?   |   vegan and carnivore friendly restaurant in Boston... Newer »
This thread is closed to new comments.