Class – WordPress Monsters

Tag: Class

Override any class from plugin

If you faced with situation when plugins classes hardcoded some data, you can override those for your theme. The main condition is a presence of special function before that class:

After that you should copy a file with this class. Then you create yourself plugin for example: wpm-vk-override-class. Copy a file ( for ex. it is vk.php ) with class in a plugin directory. A plugin main file will be like this:

But there is a little problem, you will see a Fatal Error after activation:

To understand this situation we have to know how the WordPress saveing an activated plugins in DataBase. Go to wp_options table and find a field – active_plugins. Lets have a look on value of this field:

It is a serialised array. Lets unserialize it:

Here you can set an order of activated plugins. But for our situation the better move would be deactivate conflict plugin (main plugin where we got a class). For me it is – woo-social-login. After deactivation you can activate your own plugin. There will be no errors, you can be sure. And activate a main plugin at the end. That’s all! Now your functionality have been overrided successfully!

There are no known methods to do the same result in your theme. You can override it in theme only if the class located in parent theme.

contact form 7 plugins