Backward compatibility

includes/compatible.php is missing a legacy fallback for getWebsitesByUserId():
Call to undefined method MainWP_DB::getWebsitesByUserId()

Legacy fallbacks for updateWebsiteOption() and getWebsiteOption() missing as well. I guess this will break a lot of extensions.

Hi @mensmaximus, thanks for reporting this. As per our testing, 4.1 is compatible with all currently released extensions. However, I will have our dev team check this report.

I will let you know as soon as I get more info from them.

As for now I have written my own methods to be compatible with both mainwp dashboard versions:

	public static function main_wp_db_data() {
		$main_wp_namespace = true;
		if ( class_exists('\MainWP\Dashboard\MainWP_DB') ){
			$main_wp_db = new \MainWP\Dashboard\MainWP_DB;
		} else {
			$main_wp_db = new MainWP_DB;
			$main_wp_namespace = false;
		}
		return array( 'main_wp_db' => $main_wp_db, 'main_wp_namespace' => $main_wp_namespace );
	}

	public static function get_websites_by_user_id( $user_id ){
		$main_wp_db_data = self::main_wp_db_data();
		$main_wp_db = $main_wp_db_data['main_wp_db'];
		if ( true === $main_wp_db_data['main_wp_namespace'] ) {
			$websites = $main_wp_db->get_websites_by_user_id( $user_id );
		} else {
			$websites = $main_wp_db->getWebsitesByUserId( $user_id );
		}
		return $websites;
	}

	public static function get_website_by_id( $id, $selectGroups = false ){
		$main_wp_db_data = self::main_wp_db_data();
		$main_wp_db = $main_wp_db_data['main_wp_db'];
		if ( true === $main_wp_db_data['main_wp_namespace'] ) {
			$website = $main_wp_db->get_website_by_id( $id, $selectGroups );
		} else {
			$website = $main_wp_db->getWebsiteById( $id );
		}
		return $website;
	}

	public static function get_website_option( $website, $option ) {
		$main_wp_db_data = self::main_wp_db_data();
		$main_wp_db = $main_wp_db_data['main_wp_db'];
		if ( true === $main_wp_db_data['main_wp_namespace'] ) {
			$option = $main_wp_db->get_website_option( $website, $option );
		} else {
			$option = $main_wp_db->getWebsiteOption( $website, $option );
		}
		return $option;
	}

	public static function update_website_option( $website, $option, $value ) {
		$main_wp_db_data = self::main_wp_db_data();
		$main_wp_db = $main_wp_db_data['main_wp_db'];
		if ( true === $main_wp_db_data['main_wp_namespace'] ) {
			$main_wp_db->update_website_option( $website, $option, $value );
		} else {
			$main_wp_db->updateWebsiteOption( $website, $option, $value );
		}
	}
1 Like

Fixed in the version 4.1-beta2

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.