The theme directory "twentytwelve" does not exist.

This issue comes up for older accounts where their wp_options table has their theme set to twentytwelve. If these accounts time out it does NOT flush the cookie (shit WordPress design) and when you re-visit the SaaS dashboard site (staging or production) you get the error message noted above.

Research

The theme directory … does not exist

This is generated by the WP_Theme class constructor.

\WP_Theme::__construct

		} elseif ( ! file_exists( $this->theme_root . '/' . $theme_file ) ) {
			$this->headers['Name'] = $this->stylesheet;
			if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet ) ) {
				$this->errors = new WP_Error(
					'theme_not_found',
					sprintf(
						/* translators: %s: Theme directory name. */
						__( 'The theme directory "%s" does not exist.' ),
						esc_html( $this->stylesheet )
					)
				);

Likely from users with wp_options set where option_value=’twentytwelve’ for option_name=’template” and option_name=’stylesheet’.

Development

User Switching / Login

As super admin, when switching to a user a sanity check is performed on their wp_options data.

Currently that means the option_values ‘siteurl’ and ‘home’ are checked against the current site.
This is done for production-staging-development server changes so we don’t have to update thousands of records whenever we port production data.
If the root of the domain does not match the current server domain, these values are changed.

Example:
If we are on a local development server using https://local.storelocatorplus.com/ as the hostname and…
option_name=’siteurl’ option-value=’https://dashboard.storelocatorplus.com/<username>’
This is changed to:
option_name=’siteurl’ option-value=’https://local.storelocatorplus.com/<username>’

This happens in \MySLP_Addon::initialize with:

		if ( is_user_logged_in() ) {
			if ( ! $this->myslp->is_production_domain ) {
				$domainSwitcher = MySLP_DomainSwitcher::get_instance();
				add_action( 'init', array( $domainSwitcher, 'updateUserBlogDomain' ) );
			}

This eventually calls \MySLP_DomainSwitcher::performUserBlogUpdates

Task: Update \MySLP_Addon::initialize To Fix User Options

Call this new method on init for users:

	/**
	 * Updates user options to align with the required settings for the plugin version.
	 *
	 * Compares the current plugin version with a specific version and updates
	 * designated options if they are not already set to the expected values.
	 *
	 * @return void
	 */
	private function fix_user_options(): void {
		$user_myslp_version = get_option( 'myslp_version', '0.0.0');

		if ( version_compare( $user_myslp_version, MYSLP_VERSION, '<' ) ) {

			$optionsToChange = [
				'template' => 'myslp-dashboard-theme',
				'stylesheet' => 'myslp-dashboard-theme'
			];

			foreach ( $optionsToChange as $key => $value ) {
				if ( get_option( $key ) !== $value ) {
					update_option( $key, $value );
				}
			}

			update_option( 'myslp_version', MYSLP_VERSION );
		}
	}

Leave a Reply