WordPress has a useful function called
plugins_url (codex documentation) : This function provides a URL for a file or folder within your WordPress plugins directory, it’s best to use this rather than guess that the plugins directory is within the wp-content directory, which is within the main WordPress directory as this is not always correct.
wp_enqueue_script they will also only include it once… not including libraries multiple times saves an awful lot of bandwidth).
wp_localize_script (codex documentation) : If you’ve included a script using
wp_enqueue_script then you can add arbitrary data and translated strings to it using this function, which is the crux of this demo.
The one assumption that my demo plugin does make is that the plugin is installed in directory within plugins, and that that directory is called demo-wpls… given this is so vital we ought to check it’s a correct assumption. My plugin function Update: Awesome suggestion from Otto in the comments below, no need for assumptions… this can only be good.
dwpls_admin_notices checks the directory name and shows a notice in the admin area if the name is unexpected.