Crazy php plugin. The best way to allow plugins for a PHP application. How to use the function below

The 7th version of PHP was released in recent 2015. A new round in the development of this programming language has brought many opportunities for all those who use PHP. Among the advantages new version speed should be highlighted. So, according to the developers, the speed of scripts in PHP 7, compared to previous versions, has almost doubled. In this regard, many website owners who have older versions of PHP installed want to switch to the new one.

Why check for compatibility?

It should be noted that before changing the PHP version to a newer and faster one in the control panel of your hosting, you need to check the WordPress site for compatibility with it, namely themes and plugins. This need arises because usually in new versions software some functions are added, and some cease to exist altogether. If a plugin or theme uses functions or methods that do not exist in the new version, then this is a sign of an error, which can disrupt the operation of the site as a whole.

How to check for compatibility with PHP 7.0? PHP Compatibility Checker Plugin

The PHP Compatibility Checker plugin allows you to scan the entire site and indicate which of its components (themes, plugins) are not compatible with the selected version of PHP. First you need to install and activate it, then go to the admin panel Tools -> PHP Compatibility.

As you can see, the plugin offers very clear settings. To start checking, you need to select the PHP version with which you want to check the site for compatibility (PHP Version block). A convenient function of the plugin is to select the status of the components being checked. There are two options to choose from: either check among active themes and plugins, or in inactive ones (Plugin / Theme Status field). To start the scan, click the Scan site again button.

The test result can also be downloaded to text file by clicking the Download Report button.

Almost everyone who runs a blog on WordPress and maintains it themselves knows about the existence of a magical functions.php file. It is often used completely for other purposes, which can lead to significant problems. Let's look at this issue together in more detail.

I assure you, after reading this article, you will change your attitude towards plugins and stop adding another code snippet to your functions.php.

Plugins and functions.php

Many WordPress site owners are firmly convinced that plugins will certainly load and slow down the blog. And if you just add the code to functions.php, this will not affect the load in any way. Alas, this is not entirely true...

The fact is that the load is caused not specifically by the plugin, but by its incorrectly written code, which can easily end up in functions.php from the next manual.

Let's look at the main differences between the plugin and functions.php.

The fundamental difference between a plugin and the functions.php file is its purpose and execution order.

It is also unfounded to believe that the code in functions.php will execute faster than in the plugin. The same code in the plugin and in functions.php will be executed with the same speed and load.

Very often, problems with high load arise due to the additional functionality of plugins, and site loading speed suffers from scripts connecting their own styles, scripts and other content. Therefore, it is important to pay attention to the choice of plugin in order to avoid problems in the future.

If you are an ordinary blogger and are far from web development, then when choosing a plugin, be sure to pay attention to the reviews in the WordPress repository and on the blogs of authors or web developers.

If you still have doubts, make a cup of coffee and be sure to read the article by Konstantin Kovshenin on WP Magazine - “The whole truth about functions.php”. The first part simply and clearly explains why you should not believe in myths about functions.php.

Plugin as an alternative to the functions.php file

All additions that you make to the template files (scripts, counters, functions) may be lost when you change the active theme or apply updates to it. To avoid this and not create chaos in functions.php, I suggest you use your own personal plugin.

Let's create our own plugin - an alternative to the functions.php file. Don’t be scared, it will look exactly like your favorite functions.php :) All you need to do is simply add an empty plugin to your site. And then you can insert the necessary code into it, as you used to do with functions.php.

First of all, we need to create a file on our computer called functionsphp.php and add the following code to it:

  • Go to the plugin management settings and activate your new plugin.
  • The title, description and comments to the code can be replaced with your own. Now you can place all the necessary snippets and customization in this plugin. Without fear of losing the functionality of the site when the active theme is changed again.

    We can stop here, but it would not be entirely correct on my part not to mention the so-called. MU plugins.

    MU plugins (Must Use Plugins)

    MU plugins can be very useful in cases where disabling the plugin is unacceptable and could cause critical errors in the operation of the site. For example, on client sites. To avoid incorrect client actions in the site management console.

    MU plugins are required WordPress plugins that are installed in a special directory and are always active. MU plugins are not displayed in the general list of site plugins; there is a separate tab. They can only be disabled by directly deleting the MU plugin file from the directory.

    Benefits of MU plugins
    • MU plugins do not need to be activated, they are always active, they cannot be disabled in the site management console;
    • The MU plugin is connected and activated by simply uploading the plugin file to the mu-plugins directory;
    • MU plugins are loaded in alphabetical order before regular plugins are loaded.

    Please note that subdirectories for MU plugins, unlike regular ones, are not supported. As a last resort, you can create a plugin and write a simple loader in it that will load plugins from directories. Like that:

    Finally

    As you can see, there is nothing fundamentally difficult about using functional plugins. And the advantages of using them are obvious. I have often heard the opinion that plugins create some kind of incredible load on the site. Many users have certain prejudices about the dangers of using plugins. This is not entirely true. Damage can be caused by left-handed plugins, developed by someone unknown and downloaded from unknown sources. Poor optimization of the plugin, use of outdated PHP functions and WordPress. The harm can come from a large number of simultaneously running plugins. Especially with duplicate functionality. A banal conflict between plugins and plugins with the theme is also possible. And with a competent and reasonable approach, plugins will bring exceptional benefits to your site.

    Subscribe to my telegram and be the first to receive new materials, incl. which are not on the site.

    Plugins are a way to extend the functionality of an application without changing its source code. The functions implemented by the plugin continue to work after application updates are installed, when its files are overwritten. Source

    The plugin is formatted in independent files that are only connected to the application.

    Localization

    • Plugin localization is implemented in a completely similar way to application localization (documentation). In the locale folder you should place translation files *.po and *.mo and include the keys in the code as follows: _wp("string") in PHP (instead of the _w() method, which only works with localization of the application
    • , you should use the _wp() method, which loads the plugin localization),

    [`string`] in Smarty templates (no differences here from application localization). Name and description of the plugin (name and description in configuration file

    ) are translated using the default plugin localization, so there is no need to specify "name" => _wp("PLUGIN NAME") - just specify "name" => "PLUGIN NAME" .

    Using localization in static methods In case of calling public static methods

    plugin classes in the external environment, for example, in the theme code, the plugin localization is not automatically included, and the _wp() function does not return a newline as expected. In order to use plugin localization in such methods, you must place all calls to the _wp() function inside a special construct, shown in bold in the example below:

    Class appMyPlugin extends waPlugin ( public static function displayData() ( //in both lines specify the ID of the application and your plugin waLocale::loadByDomain(array("app_id", "plugin_id")); waSystem::pushActivePlugin("plugin_id", " app_id"); $result = _wp("..."); waSystem::popActivePlugin(); return $result; ) )

    Database If the plugin uses its own tables in the database, then the table names should begin with a fragment like __ , for example: shop_ebay_

    tablename.

    Connecting the plugin

    In order for the written plugin to work, you need to connect it in the application system configuration file wa-config/apps/APP_ID/plugins.php, adding the line to it:

    "plugin_id" => true