As all know, adding snippet on Theme’s functions.php
or Child Theme’s functions.php
is not good. Here is a WordPress Plugin to Avoid Snippet on Theme’s functions.php. In this new version you can drop the snippets as PHP files from SFTP. In Our Previous Article and Release of Previous Version We Discussed Why That is Bad.
WordPress Plugin to Avoid Snippet on Theme’s functions.php
First read the previous guide and understand how that old version worked. We have WordPress Template for Plugins. In my GitHub repo, you will get all kind of templates.
This current one has added one PHP function. We have a subdirectory inside the plugin named snippets
. With PHP function, we are fetching the php
files from that :
---
1 2 3 4 | foreach (glob("snippets/*.php") as $filename) { include $filename; } |
Here is the Plugin on GitHub repo, you can download and install it.
Previously, as example if you were following this guide to remove WordPress post image linking, you were adding this kind of snippet :
1 2 3 4 5 6 7 8 9 10 11 | function k99_image_link_void( $content ) { $content = preg_replace( array('{<a(.*?)(wp-att|wp-content\/uploads)[^>]*><img}', '{ wp-image-[0-9]*" /></a>}'), array('<img','" />'), $content ); return $content; } add_filter( 'the_content', 'k99_image_link_void' ); |
With this plugin, you can save this snippet as PHP file with a meaningful name like remove-image-link.php
and directly drop inside the /snippets/
directory of the plugin.
Instead of using :
1 | include dirname(__FILE__)."/example.php"; |
we are fetching all the files from the snippets directory. Many use this in WordPress development :
1 | include "./common.php"; |
like lines. That most likely to fail when the script is invoking include when it is actually being included by another script in another directory. Our snippet is slightly different. It will avoid to load one single PHP when it has dependency on other files. It is tricky usage to avoid collision. We have lot of such useful WordPress snippets.
Those who are new WordPress users, they should not use that method. They should activate the Plugin. Go to Plugins > Editor and select our Plugin. Thereafter select the included default.php
file inside snippets
directory. Then paste the PHP code, and save the file. That is shown in this screenshot :
Report Bug Against This WordPress Plugin to Avoid Snippet on Theme’s functions.php
So far, we have no target to make the plugin available in WordPress Repo. When we develop for official repo, we have to add more lines for near perfect coding. Our FTP to Zip WordPress Backup Plugin. There are newbie “white hackers”. They open security issue without reading the details. It is for helping to somehow rescue from a bad shared host. It is a wastage of time to argue and show point. Many developers are keeping advanced plugins in GitHub or own server. Additionally SVN (which WordPress uses) is a painful system to update. SVN via Git has problems too.