HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: /home/mirz4654/www/wp-content/plugins/wordpress-seo/src/helpers/attachment-cleanup-helper.php
<?php

namespace Yoast\WP\SEO\Helpers;

use Yoast\WP\Lib\Model;

/**
 * A helper object for the cleanup of attachments.
 */
class Attachment_Cleanup_Helper {

	/**
	 * Removes all indexables for attachments.
	 *
	 * @param bool $suppress_errors Whether to suppress db errors when running the cleanup query.
	 *
	 * @return void
	 */
	public function remove_attachment_indexables( $suppress_errors ) {
		global $wpdb;

		if ( $suppress_errors ) {
			// If migrations haven't been completed successfully the following may give false errors. So suppress them.
			$show_errors       = $wpdb->show_errors;
			$wpdb->show_errors = false;
		}

		$indexable_table = Model::get_table_name( 'Indexable' );

		$delete_query = "DELETE FROM $indexable_table WHERE object_type = 'post' AND object_sub_type = 'attachment'";

		// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
		// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
		// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared -- Reason: Is it prepared already.
		$wpdb->query( $delete_query );
		// phpcs:enable

		if ( $suppress_errors ) {
			$wpdb->show_errors = $show_errors;
		}
	}

	/**
	 * Cleans all attachment links in the links table from target indexable ids.
	 *
	 * @param bool $suppress_errors Whether to suppress db errors when running the cleanup query.
	 *
	 * @return void
	 */
	public function clean_attachment_links_from_target_indexable_ids( $suppress_errors ) {
		global $wpdb;

		if ( $suppress_errors ) {
			// If migrations haven't been completed successfully the following may give false errors. So suppress them.
			$show_errors       = $wpdb->show_errors;
			$wpdb->show_errors = false;
		}

		$links_table = Model::get_table_name( 'SEO_Links' );

		$query = "UPDATE $links_table SET target_indexable_id = NULL WHERE type = 'image-in'";

		// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
		// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
		// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared -- Reason: Is it prepared already.
		$wpdb->query( $query );
		// phpcs:enable

		if ( $suppress_errors ) {
			$wpdb->show_errors = $show_errors;
		}
	}
}