GFCommon::is_preview and wp-cli

Hi, can someone fix behaviour of GFCommon::is_preview() for wp-cli please? :slight_smile:

We have a lot of warnings in logs because of this :slight_smile:

When it’s called in console mode, RGFormsModel::get_current_page_url() returns URLs without “/” at the end because REQUEST_URI is an empty string for wp-cli (we have multisite, if it matters). In this case parse_url doesn’t return “path” component, and PHP throws “Notice: Undefined index: path” all the time.

	public static function is_preview() {
		$url_info  = parse_url( RGFormsModel::get_current_page_url() );
		$file_name = basename( $url_info['path'] );

		return $file_name == 'preview.php' || rgget( 'gf_page', $_GET ) == 'preview';
	}

Something like this should be enough, well depending on your required PHP version:

$file_name = basename( $url_info['path'] ?? '' );

Or you can always return false for wp-cli.

if ('cli' === PHP_SAPI) { return false; }

Thanks!

You may also want to fix RGFormsModel::get_current_page_url() to have the same behaviour for webpages, where REQUEST_URI equals “/”, and console commands, when it’s “” (but sometimes can be “/” too) :slight_smile:

Bugs should be reported via the technical support form so they will be routed to the product team: Log In ‹ Gravity Forms — WordPress

1 Like

Thanks, I didn’t have credentials for the company account before. Today I contacted the support.