HEX
Server: Apache/2.4.65 (Debian)
System: Linux web6 5.10.0-36-amd64 #1 SMP Debian 5.10.244-1 (2025-09-29) x86_64
User: innocamp (1028)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /home/thwoodlg/public_html/wp-content/plugins/w3-total-cache/Util_AttachToActions.php
<?php
namespace W3TC;

/**
 * Attaches to wp actions related to content change, which should fire
 * flushes of html content
 */
class Util_AttachToActions {
	/**
	 * Flush actions.
	 *
	 * @return void
	 */
	public static function flush_posts_on_actions() {
		static $attached = false;
		if ( $attached ) {
			return;
		}

		$attached = true;

		$o = new Util_AttachToActions();

		// posts.
		add_action( 'pre_post_update', array( $o, 'on_pre_post_update' ), 0, 2 );
		add_action( 'save_post', array( $o, 'on_post_change' ), 0, 2 );
		add_action( 'wp_trash_post', array( $o, 'on_post_change' ), 0, 2 );

		// comments.
		add_action( 'comment_post', array( $o, 'on_comment_change' ), 0 );
		add_action( 'edit_comment', array( $o, 'on_comment_change' ), 0 );
		add_action( 'delete_comment', array( $o, 'on_comment_change' ), 0 );
		add_action( 'wp_set_comment_status', array( $o, 'on_comment_status' ), 0, 2 );
		add_action( 'trackback_post', array( $o, 'on_comment_change' ), 0 );
		add_action( 'pingback_post', array( $o, 'on_comment_change' ), 0 );

		// theme.
		add_action( 'switch_theme', array( $o, 'on_change' ), 0 );

		// navigation menu.
		add_action( 'wp_update_nav_menu', array( $o, 'on_change' ), 0 );

		// user profile.
		add_action( 'edit_user_profile_update', array( $o, 'on_change' ), 0 );

		// terms.
		add_action( 'edited_term', array( $o, 'on_change' ), 0 );
		add_action( 'delete_term', array( $o, 'on_change' ), 0 );

		// multisite.
		if ( Util_Environment::is_wpmu() ) {
			add_action( 'delete_blog', array( $o, 'on_change' ), 0 );
		}
	}

	/**
	 * Pre-Post changed action for published post changed to draft which invalidates the published URL.
	 *
	 * @link https://developer.wordpress.org/reference/hooks/pre_post_update/
	 *
	 * @param integer $post_id Post ID.
	 * @param array   $data    Array of unslashed post data.
	 *
	 * @return void
	 */
	public function on_pre_post_update( $post_id, $data = null ) {
		if ( is_null( $data ) ) {
			$data = get_post( $post_id, ARRAY_A );
		}

		// if attachment changed - parent post has to be flushed
		// since there are usually attachments content like title
		// on the page (gallery).
		if ( 'attachment' === $data['post_type'] ) {
			$post_id = $data['post_parent'];
			$data    = get_post( $post_id, ARRAY_A );
		}

		if ( 'draft' !== $data['post_status'] ) {
			return;
		}

		$cacheflush = Dispatcher::component( 'CacheFlush' );
		$cacheflush->flush_post( $post_id );
	}

	/**
	 * Post changed action
	 *
	 * @link https://developer.wordpress.org/reference/hooks/save_post/
	 *
	 * @param integer $post_id Post ID.
	 * @param WP_Post $post    Post.
	 *
	 * @return void
	 */
	public function on_post_change( $post_id, $post = null ) {
		if ( is_null( $post ) ) {
			$post = get_post( $post_id );
		}

		// if attachment changed - parent post has to be flushed
		// since there are usually attachments content like title
		// on the page (gallery).
		if ( 'attachment' === $post->post_type ) {
			$post_id = $post->post_parent;
			$post    = get_post( $post_id );
		}

		if ( ! Util_Environment::is_flushable_post( $post, 'posts', Dispatcher::config() ) ) {
			return;
		}

		$cacheflush = Dispatcher::component( 'CacheFlush' );
		$cacheflush->flush_post( $post_id );
	}

	/**
	 * Comment change action
	 *
	 * @param integer $comment_id Comment ID.
	 */
	public function on_comment_change( $comment_id ) {
		$post_id = 0;

		if ( $comment_id ) {
			$comment = get_comment( $comment_id, ARRAY_A );
			$post_id = ( ! empty( $comment['comment_post_ID'] ) ? (int) $comment['comment_post_ID'] : 0 );
		}

		$this->on_post_change( $post_id );
	}

	/**
	 * Comment status action
	 *
	 * @param integer $comment_id Comment ID.
	 * @param string  $status Status.
	 */
	public function on_comment_status( $comment_id, $status ) {
		$this->on_comment_change( $comment_id );
	}

	/**
	 * Change action
	 */
	public function on_change() {
		$cacheflush = Dispatcher::component( 'CacheFlush' );
		$cacheflush->flush_posts();
	}
}