Unit testing for plugin development

As an ex-software engineer building large business types who landed in an interactive agency let me give you a few thoughts on testing when developing for WordPress: Your Unit Testing should test the smallest amount of behavior that a class can perform. Each class should be able to be tested independently of WordPress. If you … Read more

Is get_option function cached?

When in doubt, look at the source code. Digging in to get_option(), you’ll see (abbreviated): $value = wp_cache_get( $option, ‘options’ ); if ( false === $value ) { $row = $wpdb->get_row( $wpdb->prepare( “SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1”, $option ) ); // Has to be get_row instead of get_var because of … Read more

How to redirect to settings page once the plugin is activated?

Maybe using the wp_redirect() function in the activation hook. In the following example myplugin_settings is a placeholder. Normally this simply is the $hook_suffix you get back from $hook_suffix = add_menu_page( /* etc. */ ); and similar functions. THIS CODE DOESN’T WORK, READ BELOW register_activation_hook(__FILE__, ‘cyb_activation’); function cyb_activation() {     // Don’t forget to exit() … Read more

How to enqueue JavaScripts in a plugin

Your code seems correct, but it will load the script only in admin area beacuse you are enqueuing the script in admin_enqueue_scripts action. To load the script in frontend, use wp_enqueue_scripts action (which is not the same that wp_enqueue_script() function): function Zumper_widget_enqueue_script() { wp_enqueue_script( ‘my_custom_script’, plugin_dir_url( __FILE__ ) . ‘js/jquery.repeatable.js’ ); } add_action(‘wp_enqueue_scripts’, ‘Zumper_widget_enqueue_script’); Also, … Read more

What should I use instead of WP_CONTENT_DIR and WP_PLUGIN_DIR?

Reference file in current path or deeper nested To reference the current path plugin_dir_path( __FILE__ ).”further/nesting/here.css”; which works in Plugins and Themes. Reference URl/URi in a plugin To point to a plugin or theme file, use plugins_url( “path/to/file”, __FILE__ ); which works only in plugins Reference URl/URi in wp-admin folder Always point them to admin_url( … Read more

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