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:
1 |
if( !class_exists( 'your class name' ) ) |
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:
1 2 3 4 5 6 7 8 9 10 |
<?php /** * Plugin Name: WPM override VK connect * Description: Override VK class * Version: 1.0.80 * Author: WordPress Monsters * Author URI: http://wpmonsters.org */ require_once( 'vk.php' ); |
But there is a little problem, you will see a Fatal Error after activation:
1 |
PHP Fatal error: Cannot declare class WOO_Slg_Social_VK, because the name is already in use in /home/space/workspace/cabinet/wp-content/themes/cabinet/includes/classes/vk.php on line 14 |
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:
1 |
a:8:{i:0;s:31:"query-monitor/query-monitor.php";i:1;s:34:"advanced-custom-fields-pro/acf.php";i:2;s:22:"cyr3lat/cyr-to-lat.php";i:3;s:51:"parent-category-toggler/parent-category-toggler.php";i:4;s:37:"woo-social-login/woo-social-login.php";i:5;s:91:"woocommerce-gateway-paypal-express-checkout/woocommerce-gateway-paypal-express-checkout.php";i:6;s:27:"woocommerce/woocommerce.php";i:7;s:17:"wpm-vk/wpm-vk.php";} |
It is a serialised array. Lets unserialize it:
1 2 3 4 5 6 7 8 9 10 11 |
Array ( [0] => query-monitor/query-monitor.php [1] => advanced-custom-fields-pro/acf.php [2] => cyr3lat/cyr-to-lat.php [3] => parent-category-toggler/parent-category-toggler.php [4] => woo-social-login/woo-social-login.php [5] => woocommerce-gateway-paypal-express-checkout/woocommerce-gateway-paypal-express-checkout.php [6] => woocommerce/woocommerce.php [7] => wpm-vk/wpm-vk.php ) |
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.