How do I call wp_get_current_user() in a plugin when plugins are loaded before pluggable.php?

To add to @EAMann’s answer, you need to wrap your wp_get_current_user() call (or any call that tries to access a function defined within pluggable.php) within the ‘plugins_loaded’ action. So, if you’re putting this inside your functions.php file, do it like this: add_action( ‘plugins_loaded’, ‘get_user_info’ ); function get_user_info(){ $current_user = wp_get_current_user(); if ( !($current_user instanceof WP_User) … Read more

What is This esc_html_e() i wordpress php?

It’s a combination of _e(), which echoes a translatable string, and esc_html() which is for outputting text so that the text is not interpreted as HTML. You would use it to prevent HTML being smuggled into a translation and breaking your markup or causing security issues. For example, if your theme had: _e( ‘My translatable … Read more

Excluding iPad from wp_is_mobile

t f’s answer got me thinking. Actually, I can use the core function and adapt it as I like but just put everything in a new function. So here goes: function my_wp_is_mobile() { static $is_mobile; if ( isset($is_mobile) ) return $is_mobile; if ( empty($_SERVER[‘HTTP_USER_AGENT’]) ) { $is_mobile = false; } elseif ( strpos($_SERVER[‘HTTP_USER_AGENT’], ‘Android’) !== … Read more

How many times can I hook into the same action?

WordPress hooks work like Hollywood: you don’t call them, they call you. But unlike Hollywood, they keep calling everyone on the list. It’s normal for an action or a filter to have multiple functions hooked to it, from different plugins, or even just different functions in the WordPress core that all do something specific. It … Read more

How to make a image-size selected by default in Media upload – WP v3.5

Try this out. Your add_filter()’s second argument is a function, that will affect the current option via a return: function theme_default_image_size() { return ‘custom-image-size-2’; } add_filter( ‘pre_option_image_default_size’, ‘theme_default_image_size’ ); You could also look into the pre_update_option_{$option} filter, and update the value once, so you don’t need to run this filter every time (may save 0.01s, … Read more

File not found.