Should messages in WP_Error already be html escaped?

No, escaping should happen at the moment of output ( late escaping ) so that we know that it only occurs once. Double escaping can allow specially crafted output to break out. By escaping, we’re talking about functions such as esc_html, wp_kses_post, esc_url, etc. Sanitizing functions and validating functions are not the same, e.g. sanitize_textfield. … Read more

Why on Earth am I getting “undefined_index” errors?

It’s a common PHP error, usually when you try to access an array member with a non-existent key; $array = array( ‘hello’ => ‘world’ ); echo $array[‘foobar’]; // undefined index You should check for the key first with isset( $array[‘foobar’] ); UPDATE: In this case, I would chuck in a loop that sets-up the variables … Read more

Fatal error: Call to undefined function post_exists()

The files in wp-admin are only loaded when you’re in the admin area… when you’re looking at pages or posts those functions aren’t loaded. In that case you’d need to require the file first, so you’d want to do something like this in your function: if ( ! is_admin() ) { require_once( ABSPATH . ‘wp-admin/includes/post.php’ … Read more

WSOD but WP_DEBUG not giving any errors

Make things simpler by using this in wp-config.php: define( ‘WP_DEBUG’, true ); /** debug on */ define( ‘WP_DEBUG_LOG’, true ); /** log enabled */ define( ‘WP_DEBUG_DISPLAY’, true); /** display enabled */ The @ini_set(‘display_errors’, 0); may be breaking the WP_DEBUG error display and logging by calling the native PHP error reporting at the same time.

Showing WP_Error message with admin_notice action hook

You can use function add_settings_error. More details can be found in the WordPress documentation. I have edited your previous answer to include that: function wpse_189722_limit_tag_words( $term, $taxonomy ) { if ($taxonomy === ‘post_tag’) { if ( count( preg_split( ‘/\s+/’, trim( $term ) ) ) > 2 ) { add_settings_error(‘term_too_many_words’, ‘term_too_many_words’, ‘Maximum of 2 words allowed, … Read more

Is it possible to disable caching of an option when using w3 total cache?

okay, here we go. try this: in your functions.php modify the behaviour of ai1ec_options: $ai1ec_options = get_option(‘ai1ec_options’); delete_option(‘ai1ec_options’); add_option(‘ai1ec_options’, $ai1ec_options, ”, ‘no’); // thanks for your suggestion 🙂 be careful though, as you might lose your set options, so be sure to get them from the database first. or create a backup option. afterwards, clear … Read more

How to use WP_Error $data argument?

$this->error_data[$code] … the WP_Error object holds $data in an array and $code is the key. The add_data method clearly states: The error code can only contain one error data. But the $data (mixed) can be an array or an object and carry as many keys/properties as you need. It’s up to your handlers how they … Read more