How to Link External jQuery/Javascript files with WordPress

From the wording of your question, you must be adding scripts by writing <script> tags in your template. Add your own scripts via wp_enqueue_script() in your template’s functions.php, appropriately setting dependences on jQuery, and wp_head() will add the scripts for you. function my_scripts() { wp_enqueue_script( ‘my-sweet-script’, get_bloginfo(‘template_directory’) . ‘/script.js’, array(‘jquery’) ); } add_action(‘template_redirect’, ‘my_scripts’); See … Read more

Data sanitization: Best Practices with code examples

This codex page explains it pretty well I think. The most important and commonly used function is probably esc_attr. Take this example: <a href=”https://wordpress.stackexchange.com/questions/48660/<?php print $author_url; ?>” title=”<?php print $author_name; ?>”> <?php print $author_name; ?> </a> If $author_name contains a ” character you get your attribute closed, and if that character is followed by onclick=”do_something();” … Read more

Best way to abort plugin in case of insufficient PHP version?

This function and activation hook prevents the plugin from activating and allows you to check for both a minimum PHP and WordPress version. register_activation_hook( __FILE__, array( ‘Your_Plugin_Class_Name’, ‘activate’ ) ); /** * Plugin Activation hook function to check for Minimum PHP and WordPress versions * @param string $wp Minimum version of WordPress required for this … Read more

New WP_Customize API – how does it work under the hood?

There’s a few bits here that apply, but the short of it is this code in customize-preview.js: this.body.on( ‘click.preview’, ‘a’, function( event ) { event.preventDefault(); self.send( ‘scroll’, 0 ); self.send( ‘url’, $(this).prop(‘href’) ); }); The event.preventDefault prevents the links from actually working. The following code then sends a message back upwards telling it to a) … Read more

Multiple Inputs in a Customizer Control

This plugin demonstrates how to do it. Of note, the steps involved are: Register each setting to update/change When creating the control, pass an array as the setting argument When rendering the inputs, pass in the settings key to link and value The settings key is not the name of the setting, but the indices … Read more

Is there a action hook for the “Empty Trash” button?

I don’t think there exist one, but you could create your own, wpse_empty_trash, with something like this: /** * Add a custom hook ‘wpse_empty_trash’ */ add_action( ‘load-edit.php’, function() { add_action( ‘before_delete_post’, function ( $post_id ) { if ( ‘trash’ === get_post_status( $post_id ) && filter_input( INPUT_GET, ‘delete_all’ ) && 1 === did_action( ‘before_delete_post ‘ ) … Read more

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