[Solved] WordPress Update Not Working

I was having trouble updating plugins are the Wordress core.

Symptoms:

  • WordPress not updating to the latest version. The lastest version is 5.0.3. After the one-click update, WordPress would say “Welcome to WordPress 5.0.2”
  • Updated Yoast from version 9.3 to 9.4. But Yoast is still trying to load all of the js assets from 9.3 which do not exist anymore.

Clearing the Cache

There are couple other blog posts detailing how to clear various caches including:

  • Browser cache
  • Cloudflare cache
  • WP Cache plugin

None of these worked. After some trial and error, I found the files were cached in the PHP opcache. In some versions of PHP, byte code is cached.

To clear the byte code, simple add this line to the function.php file of one of your plugins:

opcache_reset();

Reload the page once, then remove that line. You should be good to go.

Solved: WordPress wp_insert_post problem with post_status and tax_input keys

wp_insert_post is the WordPress functions used to create new post. I used the function to create a plugin with a front end to allow anyone (anonymous users) to create posts. The function appeared to ignore several documented parameters. wp_insert_post would create the post but would not set the Category and Tags fields when anonymous users ran the code. The offending code:

$post = array(
	'post_title'    => $title,
	'post_name'     => $slug,
	'post_author'   => $poster_id,
	'post_content'  => $content,
	'post_type'     => 'music',
	'post_status'   => 'publish',
	'tags_input'    => $tags,
	'tax_input'     => array('genre' => $term)
);
$new_post_id = wp_insert_post($post);

It turns out that the post_type and tax_input keys only works if you user running the code is an administrator. If the user is not an administrator then all subsequent keys after the offending key will be ignored. To solve this problem, use wp_publish_post and wp_set_object_terms functions instead of using post_status and tax_input keys, respectively. These functions will work properly regardless of users’ permissions.

This code will allow anonymous users to create and publish posts:

$post = array(
	'post_title'    => $title,
	'post_name'     => $slug,
	'post_author'   => $poster_id,
	'post_content'  => $content,
	'post_type'     => 'music',
	'tags_input'    => $tags
);
$new_post_id = wp_insert_post($post);
wp_set_object_terms( $new_post_id, array($term), 'genre' );
wp_publish_post( $new_post_id );

If you omit the wp_publish_post then the post’s status is subject to the current user’s permissions (Reference). Anonymous users will create pending posts.

This behavior is not undocumented in the codex. Additionally, the behavior seems to be unintended. The function fails ungracefully by simply breaking when a permissions error is encountered rather than processing the remaining keys.