Passing Additional Parameters to add_filter Callable

The second parameter in add_filter is a function with accepted arguments, not returned values. This is an example how I pass my custom array $args to change an existing array $filter_args: add_filter( ‘woocommerce_dropdown_variation_attribute_options_args’, function( $filter_args ) use ( $args ) { return eswc_var_dropdown_args( $filter_args, $args ); } ); function eswc_var_dropdown_args( $filter_args, $args ) { $filter_args[‘show_option_none’] … Read more

WP Multisite: Adding pages on blog creation by default

The hook is not the problem – your code runs in the context of the current site, not the one just created! The following code isn’t tested, but it should at least highlight the problem: function wpse_71863_default_pages( $new_site ) { $default_pages = array( ‘Impress’, ‘Contact’, ); switch_to_blog( $new_site->id ); if ( $current_pages = get_pages() ) … Read more

how to limit edit_form_after_title hook to page and post edit only?

Personally I’d use a different approach, because @Shazzad‘s solution seems too much global dependent, and @s_ha_dum‘s needs 2 hooks instead of one. I’d use get_current_screen function to get a WP_Screen object, then I’d look at its property to run (or not) something after the title: function do_something_after_title() { $scr = get_current_screen(); if ( ( $scr->base … Read more

Adding onload to body

And here’s a jQuery solution (as Mike suggested in his first comment). function add_my_scripts() { wp_enqueue_script( ‘jquery’ ); wp_enqueue_script( ‘my_init_script’, SCRIPTSRC, ‘jquery’, ‘1.0’ ); } add_action( ‘init’, ‘add_my_scripts’ ); Then add a script to your plug-in that does this: jQuery.noConflict(); jQuery(document).ready(function($) { init(); }); This will start jQuery in no conflict mode (if it isn’t … Read more

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