• We run a large multisite installation where individuals can create new sites at any time. Recently we noticed our logs were filling with errors during site creation. After looking into this some more, it appears to be related to the maybe_activate_ssl_in_new_blog() method within the plugin. We were able to replicate this locally and with a brand new multisite installation. Here are the steps to replicate the problem:

    1. Create a new multisite installation.
    2. Turn on debug logging using define( 'WP_DEBUG', true );, define( 'WP_DEBUG_LOG', true ); and define( 'WP_DEBUG_DISPLAY', false ); within wp-config.php.
    3. Install the Really Simple SSL plugin and set it to run network-wide.
    4. Visit /wp-admin/network/site-new.php and create a new site.
    5. Check the debug.log file within wp-content and you’ll find the database errors.

    Here is an example of the errors we’re seeing:

    
    [05-Aug-2020 22:03:27 UTC] WordPress database error Table 'local.wp_2_options' doesn't exist for query SHOW FULL COLUMNS FROM <code>wp_2_options</code> made by wpmu_create_blog, wp_insert_site, do_action('wp_insert_site'), WP_Hook->do_action, WP_Hook->apply_filters, rsssl_multisite->maybe_activate_ssl_in_new_blog, rsssl_admin->activate_ssl, rsssl_admin->set_siteurl_to_ssl, update_option, sanitize_option
    [05-Aug-2020 22:03:27 UTC] WordPress database error Table 'local.wp_2_options' doesn't exist for query INSERT INTO <code>wp_2_options</code> (<code>option_name</code>, <code>option_value</code>, <code>autoload</code>) VALUES ('siteurl', 'O:8:\"WP_Error\":2:{s:6:\"errors\";a:1:{s:30:\"wpdb_get_table_charset_failure\";a:1:{i:0;s:0:\"\";}}s:10:\"error_data\";a:0:{}}', 'yes') ON DUPLICATE KEY UPDATE <code>option_name</code> = VALUES(<code>option_name</code>), <code>option_value</code> = VALUES(<code>option_value</code>), <code>autoload</code> = VALUES(<code>autoload</code>) made by wpmu_create_blog, wp_insert_site, do_action('wp_insert_site'), WP_Hook->do_action, WP_Hook->apply_filters, rsssl_multisite->maybe_activate_ssl_in_new_blog, rsssl_admin->activate_ssl, rsssl_admin->set_siteurl_to_ssl, update_option, add_option
    [05-Aug-2020 22:03:27 UTC] WordPress database error Table 'local.wp_2_options' doesn't exist for query SHOW FULL COLUMNS FROM <code>wp_2_options</code> made by wpmu_create_blog, wp_insert_site, do_action('wp_insert_site'), WP_Hook->do_action, WP_Hook->apply_filters, rsssl_multisite->maybe_activate_ssl_in_new_blog, rsssl_admin->activate_ssl, rsssl_admin->set_siteurl_to_ssl, update_option, sanitize_option
    [05-Aug-2020 22:03:27 UTC] WordPress database error Table 'local.wp_2_options' doesn't exist for query INSERT INTO <code>wp_2_options</code> (<code>option_name</code>, <code>option_value</code>, <code>autoload</code>) VALUES ('home', 'O:8:\"WP_Error\":2:{s:6:\"errors\";a:1:{s:30:\"wpdb_get_table_charset_failure\";a:1:{i:0;s:0:\"\";}}s:10:\"error_data\";a:0:{}}', 'yes') ON DUPLICATE KEY UPDATE <code>option_name</code> = VALUES(<code>option_name</code>), <code>option_value</code> = VALUES(<code>option_value</code>), <code>autoload</code> = VALUES(<code>autoload</code>) made by wpmu_create_blog, wp_insert_site, do_action('wp_insert_site'), WP_Hook->do_action, WP_Hook->apply_filters, rsssl_multisite->maybe_activate_ssl_in_new_blog, rsssl_admin->activate_ssl, rsssl_admin->set_siteurl_to_ssl, update_option, add_option
    [05-Aug-2020 22:03:27 UTC] WordPress database error Table 'local.wp_2_options' doesn't exist for query SELECT autoload FROM wp_2_options WHERE option_name = '_transient_rsssl_plusone_count' made by wpmu_create_blog, wp_insert_site, do_action('wp_insert_site'), WP_Hook->do_action, WP_Hook->apply_filters, rsssl_multisite->maybe_activate_ssl_in_new_blog, rsssl_admin->activate_ssl, rsssl_admin->save_options, delete_transient, delete_option
    [05-Aug-2020 22:03:27 UTC] WordPress database error Table 'local.wp_2_options' doesn't exist for query INSERT INTO <code>wp_2_options</code> (<code>option_name</code>, <code>option_value</code>, <code>autoload</code>) VALUES ('rlrsssl_options', 'a:17:{s:12:\"site_has_ssl\";b:1;s:25:\"ssl_success_message_shown\";b:0;s:22:\"htaccess_warning_shown\";b:0;s:19:\"review_notice_shown\";b:0;s:17:\"plugin_db_version\";s:5:\"3.3.4\";s:11:\"ssl_enabled\";b:1;s:9:\"debug_log\";s:0:\"\";s:21:\"dismiss_review_notice\";b:0;s:4:\"hsts\";b:0;s:19:\"javascript_redirect\";b:0;s:11:\"wp_redirect\";b:1;s:26:\"autoreplace_insecure_links\";b:1;s:5:\"debug\";b:0;s:20:\"do_not_edit_htaccess\";b:0;s:31:\"switch_mixed_content_fixer_hook\";b:0;s:19:\"dismiss_all_notices\";b:0;s:17:\"htaccess_redirect\";b:0;}', 'yes') ON DUPLICATE KEY UPDATE <code>option_name</code> = VALUES(<code>option_name</code>), <code>option_value</code> = VALUES(<code>option_value</code>), <code>autoload</code> = VALUES(<code>autoload</code>) made by wpmu_create_blog, wp_insert_site, do_action('wp_insert_site'), WP_Hook->do_action, WP_Hook->apply_filters, rsssl_multisite->maybe_activate_ssl_in_new_blog, rsssl_admin->activate_ssl, rsssl_admin->save_options, update_option, add_option
    

    Let me know if I can provide any other information that would be helpful. And most importantly, thanks for making a great plugin.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Mark

    (@markwolters)

    Hi @jg-visual,

    this seems to happen because the function is ran before the database tables for the new site have been created. I’ve been able to fix this error by increasing the priority for the maybe_activate_ssl_in_new_blog hook. Currently it’s

    add_action('wp_insert_site', array($this, 'maybe_activate_ssl_in_new_blog'), 20, 1);

    increasing the priority from 20 to 90 seems to resolve the issue:

    add_action('wp_insert_site', array($this, 'maybe_activate_ssl_in_new_blog'), 90, 1);

    This line can be found on line 66 of the class-multisite.php file. Could you try to make this change and see if it resolves the issue for you? If so, we’ll include this in the next update.

    Mark

    Thread Starter Jonathan Goldford

    (@jg-visual)

    Thanks for the quick reply Mark. Unfortunately, using the priority to run the code later didn’t work for me. I changed the priority to 90 and then to 9999. In both cases, the errors still appeared. To run the tests I used a fresh multisite install with only the Really Simple SSL plugin installed.

    Plugin Author Mark

    (@markwolters)

    We’ll investigate this issue further and get back you.

    Thread Starter Jonathan Goldford

    (@jg-visual)

    That sounds good. Thanks a ton for taking a look Mark.

    Plugin Author Mark

    (@markwolters)

    @jg-visual could you try to replace the ‘wp_insert_site’ hook with the ‘wp_initialize_site’ hook like this:

    add_action('wp_initialize_site', array($this, 'maybe_activate_ssl_in_new_blog'), 20, 1);

    on line 66 in class-multisite.php.

    Let me know if that resolves the issue.

    Mark

    Thread Starter Jonathan Goldford

    (@jg-visual)

    Thanks Mark. I tested this and the errors no longer appear, which is great.

    I did notice that the new hook, wp_initialize_site, passes two arguments. Should the code be modified to be:

    add_action('wp_initialize_site', array($this, 'maybe_activate_ssl_in_new_blog'), 20, 2);

    And then I would assume that maybe_activate_ssl_in_new_blog() would need to be modified as well. Do you think that makes sense?

    Thanks again for all the help Mark.

    Plugin Author Mark

    (@markwolters)

    Glad to hear that solved the issue. The second argument is an optional array of arguments, therefore it’s not required. We’ll look into this and update the plugin accordingly.

    Mark

    Thread Starter Jonathan Goldford

    (@jg-visual)

    Thanks Mark. I appreciate you all spending some more time on it. Have a nice weekend.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘WordPress Multisite: Table Doesn’t Exist Database Errors’ is closed to new replies.