Changing Plugin Load Order
Don’t touch the load order, change the activation order instead. A working example can be found in this answer.
Don’t touch the load order, change the activation order instead. A working example can be found in this answer.
The script_loader_tag filter, added in version 4.1, addresses this issue. To add an async attribute to an enqueued script you can do: /** * Add an aysnc attribute to an enqueued script * * @param string $tag Tag for the enqueued script. * @param string $handle The script’s registered handle. * @return string Script tag … Read more
Is object injection really necessary? To be fully testable in isolation, code should avoid to instantiate classes directly, and inject any object that is needed inside objects. However, there are at least two exceptions to this rule: The class is a language class, e.g. ArrayObject The class is a proper “value object”. No need to … Read more
The WordPress way to access PHP variables with JavaScript is to use wp_localize_script(). function wpse_enqueue_scripts(){ wp_enqueue_script( ‘wpse’, PATH_TO . ‘script.js’ ); wp_localize_script( ‘wpse’, ‘credentials’, $credentials ); } add_action( ‘wp_enqueue_scripts’, ‘wpse_enqueue_scripts’ ); Then in your JavaScript, you can access the credentials like console.log( credentials );
Start from a working code base.. add_action(‘in_admin_header’, ‘my_ajax_button’); function my_ajax_button() { echo ‘<a href=”#ajaxthing” class=”myajax”>Test</a>’; } add_action(‘admin_head’, ‘my_action_javascript’); function my_action_javascript() { ?> <script type=”text/javascript” > jQuery(document).ready(function($) { $(‘.myajax’).click(function(){ var data = { action: ‘my_action’, whatever: 1234 }; // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php $.post(ajaxurl, data, function(response) … Read more
In WordPress, nonces are specific to the user, the action being performed, and the time. With regards to time, a nonce is valid for 24 hours, and changes every 12 hours. This is considered an acceptable trade-off, since using a real number-used-once would involve adding a tracking system and having storage of the used nonces. … Read more
There is a very important programming principle: DRY – Don’t repeat yourself. Whenever you realize you are repeating almost the same job try to write an abstraction. For your pad* shortcodes this means: function get_padding( $atts ) { $args = shortcode_atts( array( ‘num’ => 10 ), $atts ); return str_repeat( ‘ ‘, (int) $args[‘num’] ); … Read more
Solved! Not sure if this is the correct method, but after hours of console logging I discovered that this code: acf.media.content.get().options.selection.multiple = false will update the multiple option and therefore change how many images can be selected in the new uploader. If someone finds a nicer way, I’d love to hear it
Yes, there is: https://make.wordpress.org/core/2012/11/30/new-color-picker-in-wp-3-5/ 1. You should enqueue scripts and styles… add_action( ‘admin_enqueue_scripts’, ‘mw_enqueue_color_picker’ ); function mw_enqueue_color_picker( $hook_suffix ) { // first check that $hook_suffix is appropriate for your admin page wp_enqueue_style( ‘wp-color-picker’ ); wp_enqueue_script( ‘my-script-handle’, plugins_url(‘my-script.js’, __FILE__ ), array( ‘wp-color-picker’ ), false, true ); } 2. … add an input… <input type=”text” value=”#bada55″ class=”my-color-field” … Read more
We can use the show_avatars option to remove the Profile Picture section. We can visit /wp-admin/options.php to turn it off manually. Or update it with: update_option( ‘show_avatars’, 0 ); Or modify it through a filter: add_filter( ‘option_show_avatars’, ‘__return_false’ ); We could also restrict it to the profile.php page: add_action( ‘load-profile.php’, function() { add_filter( ‘option_show_avatars’, ‘__return_false’ … Read more