HEX
Server: LiteSpeed
System: Linux sarajevo.maychu.cloud 5.14.0-503.40.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Mon May 5 06:06:04 EDT 2025 x86_64
User: inqua407 (1189)
PHP: 8.3.17
Disabled: exec,execl,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,ini_alter,proc_open,dl,popen,show_source,posix_getpwuid,getpwuid,posix_geteuid,posix_getegid,posix_getgrgid,open_basedir,safe_mode_include_dir,pcntl_exec,pcntl_fork,proc_get_status,proc_nice,proc_terminate,pclose,virtual,openlog,popen,pclose,virtual,openlog,escapeshellcmd,escapeshellarg,dl,show_source,symlink,mail
Upload Files
File: /home/inqua407/public_html/wp-content/plugins/wpseo-woocommerce/classes/woocommerce-twitter.php
<?php
/**
 * WooCommerce Yoast SEO plugin file.
 *
 * @package WPSEO/WooCommerce
 */

use Yoast\WP\SEO\Presentations\Indexable_Presentation;

/**
 * Class WPSEO_WooCommerce_Twitter
 */
class WPSEO_WooCommerce_Twitter {

	/**
	 * Register hooks.
	 *
	 * @return void
	 */
	public function register_hooks() {
		add_filter( 'wpseo_twitter_image', [ $this, 'fallback_to_product_gallery_image' ], 10, 2 );
	}

	/**
	 * Lets the twitter image fall back to the first image in the product gallery.
	 *
	 * @param string                 $twitter_image The current twitter image.
	 * @param Indexable_Presentation $presentation  The indexable presentation.
	 *
	 * @return string The image fallback.
	 */
	public function fallback_to_product_gallery_image( $twitter_image, $presentation ) {
		// Do not fall back to product gallery image when open graph is enabled, or we already have a twitter image.
		if ( $presentation->context->open_graph_enabled || $twitter_image ) {
			return $twitter_image;
		}

		$object = $presentation->model;

		// This method only provides a fallback for products.
		if ( $object->object_type !== 'post' || $object->object_sub_type !== 'product' ) {
			return $twitter_image;
		}

		$product = wc_get_product( $object->object_id );

		if ( $product ) {
			// Fall back to the first image in the product gallery.
			$gallery_image_ids      = $product->get_gallery_image_ids();
			$first_gallery_image_id = reset( $gallery_image_ids );

			if ( $first_gallery_image_id ) {
				return YoastSEO()->helpers->twitter->image->get_by_id( $first_gallery_image_id );
			}
		}

		return $twitter_image;
	}
}