Load plugin scripts and styles only on plugin page

When you register a plugin option page you get a hook from the registration function: $hook = add_menu_page( ‘T5 Demo’, // page title ‘T5 Demo’, // menu title ‘manage_options’, // capability ‘t5-demo’, // menu slug ‘my_render_page’ // callback function ); Use this hook to enqueue the scripts and styles: add_action( “admin_print_styles-$hook”, “my_enqueue_style” ); add_action( “admin_print_scripts-$hook”, … Read more

dynamically add scripts to WP_Widget widget() method

I’m plucking this code out of my Total Widget Control plugin, so it might throw an error or two. I dunno, just let me know if it does. This is basically the widget code that I use for everything that I build. if (!function_exists(“register_multiwidget”)): /** * Register a widget * * @param $widget */ function … Read more

Add a script as a dependency to a registered script

Digging through https://github.com/WordPress/WordPress/blob/3.5.1/wp-includes/class.wp-dependencies.php all registered scripts are stored in the global $wp_scripts. You can access them directly through that, but I prefer to use the API when it exists. In this case, $wp_scripts->query() returns a particular registered script (a _WP_Dependency object – see source). A _WP_Dependency object stores the dependencies as an array of handles, … Read more

Correct Method to run scripts with dependencies without enqueue?

function script_that_requires_jquery() { wp_register_script( ‘script-with-dependency’, ‘http://www.example.com/script-with-dependency.js’, array( ‘jquery’ ), ‘1.0.0’, true ); wp_enqueue_script( ‘script-with-dependency’ ); } add_action( ‘wp_enqueue_scripts’, ‘script_that_requires_jquery’ ); This is the correct method to enqueue scripts (and styles for that matter). You should always be using wp_enqueue_scripts to hook scripts and styles to. There are a few thing here to check when you … Read more

How can I create a bash install script for my WordPress sites setup (WP+plugins+theme)?

To always get latest plugin take for example my plugin: http://wordpress.org/extend/plugins/wordpress-file-monitor-plus/ the download link for the latest is: http://downloads.wordpress.org/plugin/wordpress-file-monitor-plus.1.1.zip but if you remove the version from the download link you always get the latest version: http://downloads.wordpress.org/plugin/wordpress-file-monitor-plus.zip EDIT: Have you considered keeping a folder of the latest wordpress and plugins unpacked? Then as soon as a … Read more

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

How to properly dequeue scripts and styles in child theme?

You are very nearer to the solution, because you are on the right path. Just to tweak a little bit: There are two such action hooks: wp_print_scripts, and wp_print_styles So the way you can do it, is: hook ’em differently: //Dequeue Styles function project_dequeue_unnecessary_styles() { wp_dequeue_style( ‘bootstrap-map’ ); wp_deregister_style( ‘bootstrap-map’ ); } add_action( ‘wp_print_styles’, ‘project_dequeue_unnecessary_styles’ … Read more

How can I get a list of all enqueued scripts and styles?

do_action doesn’t quite work like that. When you call do_action(‘crunchify_print_scripts_styles’) WP looks at its list of registered actions and filters for any that are attached to a hook called crunchify_print_scripts_styles and then runs those functions. And you probably want to remove this: add_action( ‘wp_enqueue_scripts’, ‘crunchify_print_scripts_styles’); … because you aren’t able to get the return result … Read more

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