Sometimes it is so important to find any string in plugin or theme directory files. Or to find where the given function is situated. You have to edit some plugin hook, but you don’t know in which file it is.
It is more needed when the project is not yours, the code is not yours (for own codes there are native OS feature, desktop softwares, IDE, server commands for that).
I am using my own solution for that.
If i start working on fixing some issue on client’s live website, first i install this plugin, then use it when it is needed. It is very helpful when you don’t know how client’s theme/plugin built.
The plugin is lightweight and contains just one single file.
So, which steps we have followed to create this plugin:
Create empty plugin and activate it. (here is how to do it)
Register wp-admin submenu for the plugin’s action/settings page. (here is how to do it)
Create simple html form to submit data.
Write the needed backend code which does iterative file search in specified directory and displays the results.
With simple plugin we can create responsive adsense ad shortcode and put it anywhere inside our WordPress post.
Here is how to create it.
The usage is easy. Just put [responsive_adsense] anywhere inside your post, and responsive adsense ad will appear there.
Another shortcode in our code – [responsive_adsense_single] is for cases if you want those ads to appear only in single page (not in another pages where post content shown)
There are obviously a lot of ways to block our WordPress admin area login page from attackers, there are a lot of plugins for that.
But what if we want to build own logic – the secret key which changes itself daily, but we always know it, because we know its built logic.
For example what about if our secret key to wp-admin is today’s date + any custom string? Funny yeah? Or md5 encrypt of today’s date + any custom string – in this case nobody will recognize how this keys are generated.
Let’s write a little 2 functions which fulfill this solution.
In this sample our logic is ” secret key is current date + sesame” , so for example if today is 2016-10-10, our secret key would be 2016-10-10-sesame.
So yoursite.com/wp-admin?call=2016-10-10-sesame will work, yoursite.com/wp-admin will give 404 error.
You can also build your own funny logic which changes keywords by the current date, last post name or any other dynamic data. Or to hide how your key is built you can use md5 encryption for that.
For that purpose just use $secretstring = md5(date(‘Y-m-d’) . ‘-sesame’) in the code above.
If you want to check this inside the some hook, which runs after plugins_loaded hook, it is very simple. Just check some plugin specific constant or function exists or not.
For example, to check WooCommerce we will need to check any WOO constant is defined or not. Or it is enough to check if class WooCommerce exists or not.
But what if you want it to check it before the plugins loaded? In this case you will not be able to check some constant,function, class of the plugin is defined or not, because they are not loaded yet. So we will need some additional trick for that. We can check $wpdb->options table and get the list of active plugins, process it and get the results. Let’s see how it works.