HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
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,
Upload Files
File: /var/www/html/ielts-store/wp-content/plugins/automatewoo/includes/Communication_Account_Tab.php
<?php
// phpcs:ignoreFile

namespace AutomateWoo;

/**
 * @class Communication_Account_Endpoint
 */
class Communication_Account_Tab {

	/** @var string */
	public static $endpoint;


	static function init() {
		$self = 'AutomateWoo\Communication_Account_Tab'; /** @var $self Communication_Account_Tab (for IDE) */

		self::$endpoint = apply_filters( 'automatewoo/communication_tab/endpoint', 'communication-preferences' );

		add_rewrite_endpoint( self::$endpoint, EP_PAGES );

		add_filter( 'query_vars', [ $self, 'add_query_vars' ], 0 );

		if ( Options::communication_account_tab_enabled() ) {
			add_filter( 'the_title', [ $self, 'endpoint_title' ] );
			add_filter( 'woocommerce_account_menu_items', [ $self, 'new_menu_items' ] );
			add_action( 'woocommerce_account_' . self::$endpoint .  '_endpoint', [ $self, 'endpoint_content' ] );
		}
	}


	/**
	 * @return string
	 */
	static function get_page_title() {
		return apply_filters( 'automatewoo/communication_tab/page_title', __( 'Communication preferences', 'automatewoo' ) );
	}


	/**
	 * @return string
	 */
	static function get_menu_title() {
		return apply_filters( 'automatewoo/communication_tab/menu_title', __( 'Communication', 'automatewoo' ) );
	}


	/**
	 * @param array $vars
	 * @return array
	 */
	static function add_query_vars( $vars ) {
		$vars[] = self::$endpoint;
		return $vars;
	}


	/**
	 * Insert the new endpoint into the My Account menu.
	 *
	 * @param array $items
	 * @return array
	 */
	static function new_menu_items( $items ) {

		$logout_item = false;

		if ( isset( $items['customer-logout'] ) ) {
			$logout_item = $items['customer-logout'];
			unset( $items['customer-logout'] );
		}

		$items[ self::$endpoint ] = self::get_menu_title();

		if ( $logout_item ) {
			$items['customer-logout'] = $logout_item;
		}

		return $items;
	}


	/**
	 * Set endpoint title.
	 *
	 * @param string $title
	 * @return string
	 */
	static function endpoint_title( $title ) {
		global $wp_query;

		if ( isset( $wp_query->query_vars[ self::$endpoint ] ) && ! is_admin() && is_main_query() && in_the_loop() && is_account_page() && is_user_logged_in() ) {
			$title = self::get_page_title();
			remove_filter( 'the_title', [ __CLASS__, 'endpoint_title' ] );
		}

		return $title;
	}


	/**
	 * Endpoint HTML content
	 */
	static function endpoint_content() {
		$customer = Customer_Factory::get_by_user_id( get_current_user_id() );
		Communication_Page::output_preferences_form( $customer );
	}


}