It can be used for pre-filled fields or custom functionality with filterning and updating values.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
function wpm_custom_date_shortcode_handler($tag) { if ( ! is_array( $tag ) ) return ''; $name = $tag['name']; if ( empty( $name ) ) return ''; $next_week = date('Y-m-d', time() + (60*60*24*7)); $html = '<input type="text" name="' . $name . '" value="' . $next_week . '" />'; return $html; } wpcf7_add_shortcode( 'custom_date', 'wpm_custom_date_shortcode_handler', true ); |
1 2 3 4 5 |
function wpm_seo_metabox_priority() { //* Accepts 'high', 'default', 'low'. Default is 'high'. return 'low'; } add_filter( 'wpseo_metabox_prio', 'wpm_seo_metabox_priority' ); |
There are a lot of ways to create options page in WordPress. This is one of them:
1 2 3 4 5 6 7 8 9 10 11 |
function wpm_admin_menu() { add_options_page( 'Page Title', 'Menu Element Name', 8, //access right to settings page 'plugin_option_slug', 'wpm_option_page' ); } add_action( 'admin_menu', 'wpm_admin_menu' ); |
In callback function you can include a file with your options fields:
1 2 3 |
function wpm_option_page() { include 'options.php'; } |
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.
1 2 3 4 5 6 7 |
/* Plugin Name: Subfolders Collections Description: Adds Collection Name to the begining url Version: 1.1 Author: Vyacheslav Gordeev Author URI: https://www.wpmonsters.org */ |