What is the correct way to build a widget using OOP

You can simply put your init code within the constructor of the class. For example: class myWidget extends WP_Widget{ function myWidget(){ // Init code here } function widget( $args, $instance ) { // The widget code wp_enqueue_script(…); wp_enqueue_style(…); } // Over methods… } register_widget(‘myWidget’); My preference is to actually put the enqueue calls within the … Read more

Passing boolean values with wp_localize_script

Try this: $options = get_option( ‘theme’ ); wp_localize_script( ‘flexslider’, ‘flex_vars’, array ( ‘flex_auto’ => ($options[‘slide-auto’]) ? ‘true’ : ‘false’, ‘flex_animation’ => $options[‘slide-animation’], ‘flex_direction’ => $options[‘slide-direction’] ) ); Assuming slide-auto is the option you made a boolean. This script isn’t tested, I directly typed it in here.

Is there a JavaScript API? How to access public and private data in JS?

TL;DR There is no JavaScript API in the WordPress core and no one is planned, but actually, there is no need of it. Backend First of all let’s say that, regarding the backend, some useful information can be fetched from already present JavaScript global variables (WordPress loves all global flavors). E.g. ajaxurl for the admin-ajax.php … Read more

How to intercept already localized scripts

wp_localize_script() calls the method localize() on the global variable $wp_scripts. We can set this variable to an instance of a child class of WP_Scripts: class Filterable_Scripts extends WP_Scripts { function localize( $handle, $object_name, $l10n ) { $l10n = apply_filters( ‘script_l10n’, $l10n, $handle, $object_name ); return parent::localize($handle, $object_name, $l10n); } } add_action( ‘wp_loaded’, function() { $GLOBALS[‘wp_scripts’] … Read more

Is it possible to use wp_localize_script to create global JS variables without a specific script handle?

Instead of using wp_localize_script in that case, you can hook your js variables at wp_head, that way it would be available to all js files like: function my_js_variables(){ ?> <script type=”text/javascript”> var ajaxurl=”<?php echo admin_url( “admin-ajax.php” ); ?>”; var ajaxnonce=”<?php echo wp_create_nonce( “itr_ajax_nonce” ); ?>”; </script><?php } add_action ( ‘wp_head’, ‘my_js_variables’ ) Also as suggested … Read more

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