model = $model;
}
/**
* Enqueue scripts.
* Add data for specific store by overriding this method.
*
* @return void
*/
public function scripts() {
\SureCart::assets()->enqueueComponents();
wp_localize_script(
'surecart-components',
'sc',
[
'store' => (object) [],
]
);
}
/**
* Handle fetching error.
*
* @param \WP_Error $wp_error WP Error.
*
* @return void
*/
public function handleError( \WP_Error $wp_error ): void {
$data = (array) $wp_error->get_error_data();
if ( 404 === ( $data['status'] ?? null ) ) {
$this->notFound();
}
wp_die( esc_html( implode( ' ', $wp_error->get_error_messages() ) ) );
}
/**
* Handle not found error.
*
* @return void
*/
public function notFound(): void {
global $wp_query;
$wp_query->set_404();
status_header( 404 );
get_template_part( 404 );
exit();
}
/**
* Handle filters.
*
* @return void
*/
public function filters(): void {
// set the document title.
add_filter( 'document_title_parts', [ $this, 'documentTitle' ] );
// disallow pre title filter.
add_filter( 'pre_get_document_title', [ $this, 'disallowPreTitle' ], 214748364 );
// add scripts.
add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ] );
// preload image.
add_action( 'wp_head', [ $this, 'preloadImage' ] );
// add meta title and description.
add_action( 'wp_head', [ $this, 'addSeoMetaData' ] );
}
/**
* Add meta title and description.
*
* @return void
*/
public function addSeoMetaData(): void {
?>
model->getImageUrl( 800 ) ) ) { ?>
model->image_url ) ) {
return;
}
?>
model->page_title ?? $parts['title'] ) );
return $parts;
}
/**
* Disallow the pre title.
*
* @param string $title The title.
*
* @return string
*/
public function disallowPreTitle( $title ) {
if ( ! empty( $this->model->id ) ) {
return '';
}
return $title;
}
}