Conditionally enqueue a widget’s script/stylesheet in HEAD (only when present on page!)

WordPress as a nice function is_active_widget that you can use in your __construct and test if the widget is present in the current page and add your scripts/styles based on that ex: function __construct() { parent::__construct(__CLASS__, ‘BasicWidget’, array( ‘classname’ => __CLASS__, ‘description’ => “This is a basic widget template that outputs text to the sidebar” … Read more

Changing WooCommerce Display Price Based on User Role & Category [closed]

Yes there is, you can use the woocommerce_get_price filter hook to filter the value based on user role and return a price accordingly e.g: add_filter(‘woocommerce_get_price’, ‘custom_price_WPA111772’, 10, 2); /** * custom_price_WPA111772 * * filter the price based on category and user role * @param $price * @param $product * @return */ function custom_price_WPA111772($price, $product) { … Read more

“Add Media” button in custom plugin

If you want to add a add media button to your admin panels: You need to use wp_enqueue_media(); add_action ( ‘admin_enqueue_scripts’, function () { if (is_admin ()) wp_enqueue_media (); } ); Then use this js: jQuery(document).ready(function() { var $ = jQuery; if ($(‘.set_custom_images’).length > 0) { if ( typeof wp !== ‘undefined’ && wp.media && … Read more

How I prevent a plugin to be loaded when doing WP-CLI?

One of the first things WordPress does to load plugins is get the active plugins as saved in the database: $active_plugins = (array) get_option( ‘active_plugins’, array() ); Since it uses get_option() we can use the option_active_plugins filter to modify the list of active plugins on the fly. function wpse_301282_disable_plugin( $active_plugins ) { if ( defined( … Read more

How to check if a theme is active?

You can use wp_get_theme: <?php $theme = wp_get_theme(); // gets the current theme if ( ‘Twenty Twelve’ == $theme->name || ‘Twenty Twelve’ == $theme->parent_theme ) { // if you’re here Twenty Twelve is the active theme or is // the current theme’s parent theme } Or, you can simply check if a function in twentytwelve … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)