HEX
Server: Apache
System: Linux hvh16.mirohost.net 6.14.0-29-generic #29~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Aug 14 16:52:50 UTC 2 x86_64
User: likoholding (1037)
PHP: 7.3.33-25+0~20250707.133+debian12~1.gbp70fb14
Disabled: apache_child_terminate, dl, exec, imap_body, imap_createmailbox, imap_deletemailbox, imap_list, imap_open, imap_renamemailbox, inject_code, mb_send_mail, passthru, pcntl_alarm, pcntl_async_signals, pcntl_errno, pcntl_exec, pcntl_fork, pcntl_get_last_error, pcntl_getpriority, pcntl_setpriority, pcntl_signal, pcntl_signal_dispatch, pcntl_signal_get_handler, pcntl_sigprocmask, pcntl_sigtimedwait, pcntl_sigwaitinfo, pcntl_strerror, pcntl_wait, pcntl_waitpid, pcntl_wexitstatus, pcntl_wifcontinued, pcntl_wifexited, pcntl_wifsignaled, pcntl_wifstopped, pcntl_wstopsig, pcntl_wtermsig, popen, posix_getpwuid, posix_kill, posix_mkfifo, posix_setpgid, posix_setsid, posix_setuid, proc_close, proc_get_status, proc_nice, proc_open, proc_terminate, set_time_limit, shell_exec, symlink, system
Upload Files
File: /var/www/likoholding/liko-holding.com.ua/wp-content/plugins/polylang-pro/modules/metabox-button.php
<?php

/**
 * Abstract class for features needing a button in the language metabox
 *
 * @since 2.1
 */
abstract class PLL_Metabox_Button {
	public $id, $args;

	/**
	 * Constructor
	 *
	 * @since 2.1
	 *
	 * Parameters must be provided by the child class.
	 *
	 * List of parameters accepted in $args:
	 *
	 * activate   => string displayed to activate the button
	 * deactivate => string displayed to deactivate the button
	 * class      => classes to display the icon
	 *
	 * @param string $id   Id used for css class
	 * @param array  $args
	 */
	public function __construct( $id, $args ) {
		$this->id   = $id;
		$this->args = $args;

		add_action( 'pll_' . $args['position'], array( $this, 'add_icon' ) );
		add_action( 'wp_ajax_toggle_' . $id, array( $this, 'toggle' ) );
	}

	/**
	 * Tells whether the button is active or not
	 *
	 * @since 2.1
	 *
	 * @return bool
	 */
	abstract public function is_active();

	/**
	 * Saves the button state
	 *
	 * @since 2.1
	 *
	 * @param string $post_type Current post type
	 * @param bool   $active    New requested button state
	 * @return bool Whether the new button state is accepted or not
	 */
	protected function toggle_option( $post_type, $active ) {
		return true;
	}

	/**
	 * Displays the button
	 *
	 * @since 2.1
	 *
	 * @param string $post_type
	 */
	public function add_icon( $post_type ) {
		if ( 'attachment' !== $post_type ) {
			echo $this->get_html( $this->is_active() );
		}
	}

	/**
	 * Ajax response to a clic on the button
	 *
	 * @since 2.1
	 */
	public function toggle() {
		check_ajax_referer( 'pll_language', '_pll_nonce' );

		$is_active = 'false' === $_POST['value'];
		if ( post_type_exists( $post_type = $_POST['post_type'] ) && $this->toggle_option( $post_type, $is_active ) ) {
			$x = new WP_Ajax_Response( array( 'what' => 'icon', 'data' => $this->get_text( $is_active ) ) );
			$x->send();
		}
		wp_die( -1 );
	}

	/**
	 * Get the text for the button title depending on its state
	 *
	 * @since 2.1
	 *
	 * @param bool $is_active
	 * @return string
	 */
	protected function get_text( $is_active ) {
		return $is_active ? $this->args['deactivate'] : $this->args['activate'];
	}

	/**
	 * Returns the html to display the button
	 *
	 * @since 2.1
	 *
	 * @param bool $is_active Whether the button is already active or not
	 * @return string
	 */
	protected function get_html( $is_active ) {
		$text = $this->get_text( $is_active );
		return sprintf(
			'%6$s<button type="button" id="%1$s" class="pll-button %2$s" title="%3$s"><span class="screen-reader-text">%4$s</span></button><input name="%1$s" type="hidden" value="%5$s" />%7$s',
			$this->id,
			$is_active ? "{$this->args['class']} wp-ui-text-highlight" : $this->args['class'],
			esc_attr( $text ),
			esc_html( $text ),
			$is_active ? 'true' : 'false',
			empty( $this->args['before'] ) ? '' : $this->args['before'],
			empty( $this->args['after'] ) ? '' : $this->args['after']
		);
	}
}