HEX
Server: LiteSpeed
System: Linux sinope.sitehostingserver.com 5.14.0-611.49.2.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Apr 30 09:05:08 EDT 2026 x86_64
User: aprilnet (1155)
PHP: 7.4.33
Disabled: popen,imap_mail,exec,passthru,system,shell_exec,proc_open,pcntl_exec,eval,allow_url_fopen,allow_url_include,mail,proc_get_status,get_cfg_var,disk_free_space,disk_total_space,diskfreespace,getmygid,getmyinode,getmypid,geymyuid,proc_nice,proc_terminate,proc_close,apache_child_terminate,chown,lchgrp,lchown,link,readlink,highlight_file,show_source,php_strip_whitespace,get_meta_tags,dl,leak,pfsockopen,event_new,pcntl_signal,pcntl_alarm,register_tick_function,apache_setenv,define_syslog_variables,escapeshellarg,escapeshellcmd,ini_alter,ini_restore,inject_code,openlog,syslog,xmlrpc_entity_decode,phpAds_remoteInfo,phpAds_XmlRpc,phpAds_xmlrpcDecode,phpAds_xmlrpcEncode,chgrp,php_eval,safe_dir,root,ftok,egy_perl,symlink,wscript
Upload Files
File: /home/aprilnet/public_html/operationreality.org/wp-content/plugins/imageseo/src/Services/Alt.php
<?php

namespace ImageSeoWP\Services;

if (!defined('ABSPATH')) {
	exit;
}

class Alt
{
	public $reportImageService;
	public $optionServices;
	public $tagsToStringServices;

	public function __construct()
	{
		$this->reportImageService = imageseo_get_service('ReportImage');
		$this->optionServices = imageseo_get_service('Option');
		$this->tagsToStringServices = imageseo_get_service('TagsToString');
	}

	/**
	 * @param int $attachmentId
	 */
	public function generateForAttachmentId($attachmentId, $query = [])
	{
		$report = $this->reportImageService->getReportByAttachmentId($attachmentId);

		if (!$report) {
			try {
				$response = $this->reportImageService->generateReportByAttachmentId($attachmentId, $query);
			} catch (\Exception $e) {
				return [
					'success' => false,
				];
			}

			if (isset($response['error'])) {
				return [
					'success' => false,
					'error' => $response['error']
				];
			}

			$report = $response;
		}

		$this->updateAltAttachmentWithReport($attachmentId);

		return [
			'success' => true,
		];
	}

	/**
	 * @param int   $attachmentId
	 * @param array $report
	 */
	public function updateAltAttachmentWithReport($attachmentId)
	{
		$template = $this->optionServices->getOption('alt_template_default');
		$alt = $this->tagsToStringServices->replace($template, $attachmentId);
		$alt = apply_filters('imageseo_update_alt_attachment_value', $alt, $attachmentId);

		$this->updateAlt($attachmentId, $alt);
	}

	/**
	 * @param int    $attachmentId
	 * @param string $alt
	 */
	public function updateAlt($attachmentId, $alt)
	{
		$currentAlt = $this->getAlt($attachmentId);
		update_post_meta($attachmentId, '_wp_attachment_image_alt', apply_filters('imageseo_update_alt', $alt, $attachmentId));

		// Update counter
		if (empty($currentAlt) && !empty($alt)) { // Empty => Not empty
			$total = get_option('imageseo_get_number_image_non_optimize_alt');
			if ($total) {
				update_option('imageseo_get_number_image_non_optimize_alt', (int) $total - 1, false);
			}
		} elseif (empty($alt)) { // No alt
			$total = get_option('imageseo_get_number_image_non_optimize_alt');
			if ($total) {
				update_option('imageseo_get_number_image_non_optimize_alt', (int) $total + 1, false);
			}
		}
	}

	/**
	 * @param int $id
	 *
	 * @return string
	 */
	public function getAlt($id)
	{
		return get_post_meta($id, '_wp_attachment_image_alt', true);
	}
}