https://t.me/RX1948
Server : Apache
System : Linux server.lienzindia.com 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64
User : plutus ( 1007)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /home/plutus/public_html/wp-content/themes/vrm/inc/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/plutus/public_html/wp-content/themes/vrm/inc/custom-actions.php
<?php

namespace TotalTheme;

use TotalTheme\Replace_Vars;

\defined( 'ABSPATH' ) || exit;

/**
 * Custom user actions panel.
 */
class Custom_Actions {

	/**
	 * Class instance.
	 *
	 * @access private
	 * @var object Class object.
	 */
	private static $instance;

	/**
	 * Create or retrieve the instance of Custom_Actions.
	 */
	public static function instance() {
		if ( \is_null( static::$instance ) ) {
			static::$instance = new self();
			static::$instance->init_hooks();
		}
		return static::$instance;
	}

	/**
	 * Start things up.
	 */
	public function init_hooks() {
		if ( \wpex_is_request( 'admin' ) ) {
			\add_action( 'admin_menu', [ $this, 'add_admin_page' ], 40 );
			\add_action( 'admin_init', [ $this, 'register_settings' ] );
		}
		if ( \wpex_is_request( 'frontend' ) ) {
			\add_action( 'init', [ $this, 'render_actions' ] );
		}
	}

	/**
	 * Add sub menu page.
	 */
	public function add_admin_page() {
		$hook_suffix = \add_submenu_page(
			\WPEX_THEME_PANEL_SLUG,
			\esc_html__( 'Custom Actions', 'total' ),
			\esc_html__( 'Custom Actions', 'total' ),
			$this->get_user_capability(),
			\WPEX_THEME_PANEL_SLUG . '-user-actions',
			[ $this, 'render_admin_page' ]
		);

		\add_action( "load-{$hook_suffix}", [ $this, 'admin_help_tab' ] );
		\add_action( "admin_print_styles-{$hook_suffix}", [ $this, 'enqueue_styles' ] );
		\add_action( "admin_print_scripts-{$hook_suffix}", [ $this, 'enqueue_scripts' ] );
	}

	/**
	 * Add admin help tab.
	 */
	public function admin_help_tab() {
		$screen = \get_current_screen();

		if ( ! $screen ) {
			return;
		}

		$screen->add_help_tab(
			[
				'id'      => 'totaltheme_custom_actions',
				'title'   => \esc_html__( 'Overview', 'total' ),
				'content' => '<p>' . esc_html__( 'Here you can insert HTML code into any section of the theme. PHP code is not allowed for security reasons. If you wish to insert PHP code into a theme action you will want to use a child theme or shortcodes in the fields below.', 'total' ) . '</p>'
			]
		);
	}

	/**
	 * Returns user capability for this admin page.
	 */
	protected function get_user_capability() {
		return (string) \apply_filters( 'totaltheme/custom_actions/user_capability', 'edit_theme_options' );
	}

	/**
	 * Register a setting and its sanitization callback.
	 */
	public function register_settings() {
		\register_setting(
			'wpex_custom_actions',
			'wpex_custom_actions',
			[ $this, 'sanitize_callback' ]
		);
	}

	/**
	 * Sanitization callback.
	 */
	public function sanitize_callback( $options ) {
		if ( empty( $options ) || ! \is_array( $options ) ) {
			return;
		}
		foreach ( $options as $key => $val ) {
			if ( empty( $val['action'] ) || \ctype_space( $val['action'] ) ) {
				unset( $options[$key] );
			} else {
				// Sanitize action @todo don't allow javascript anymore?
				//$options[$key]['action'] = wp_kses_post( $val['action'] );
				// Priority must be a number.
				if ( ! empty( $val['priority'] ) ) {
					$options[$key]['priority'] = \intval( $val['priority'] );
				}
			}
		}
		return $options;
	}

	/**
	 * Panel scripts.
	 */
	public function enqueue_scripts() {
		\wp_enqueue_script(
			'totaltheme-admin-custom-actions',
			\get_theme_file_uri( '/assets/js/admin/custom-actions.min.js' ),
			[ 'jquery' ],
			\WPEX_THEME_VERSION,
			false
		);
	}

	/**
	 * Panel styles.
	 */
	public function enqueue_styles() {
		\wp_enqueue_style(
			'totaltheme-admin-custom-actions',
			\get_theme_file_uri( '/assets/css/admin/custom-actions.css' ),
			[],
			\WPEX_THEME_VERSION,
			'all'
		);
	}

	/**
	 * Settings page.
	 */
	public function render_admin_page() {
		if ( ! \current_user_can( $this->get_user_capability() ) ) {
			return;
		}

		?>

		<div class="wrap totaltheme-custom-actions">
			<form method="post" action="options.php">
				<?php \settings_fields( 'wpex_custom_actions' ); ?>
				<div class="totaltheme-custom-actions__inner">
					<div class="totaltheme-custom-actions__list">
						<?php
						// Get hooks.
						$wp_hooks = [
							'wp_hooks' => [
								'label' => 'WordPress',
								'hooks' => [
									'wp_head',
									'wp_body_open',
									'wp_footer',
								],
							],
							'html' => [
								'label' => 'HTML',
								'hooks' => [ 'wpex_hook_after_body_tag' ]
							]
						];

						// Theme hooks.
						$theme_hooks = \wpex_theme_hooks();

						// Remove header hooks if builder is enabled.
						if ( wpex_header_builder_id() ) {
							unset( $theme_hooks['header'] );
							unset( $theme_hooks['header_logo'] );
							unset( $theme_hooks['main_menu'] );
						}

						// Combine hooks.
						$hooks = ( $wp_hooks + $theme_hooks );

						// Loop through sections.
						foreach ( $hooks as $section ) : ?>

							<div class="totaltheme-custom-actions__group">

								<h2><?php echo \esc_html( $section['label'] ); ?></h2>

								<?php foreach ( $section['hooks'] as $hook ) :

									$action = $this->get_hook_action( $hook );
									$priority = isset( $options[$hook]['priority'] ) ? \intval( $options[$hook]['priority'] ) : 10;
									$not_empty = ( $action && ! \ctype_space( $action ) ) ? true : false;

									?>

										<div class="totaltheme-custom-actions-item" data-state="closed" data-has-content="<?php echo $not_empty ? 'true' : 'false'; ?>">
											<div class="totaltheme-custom-actions-item__heading">
												<h3><?php
													$hook_name = $hook;
													if ( 'wpex_mobile_menu_top' === $hook_name || 'wpex_mobile_menu_bottom' === $hook_name ) {
														$hook_name = $hook_name . ' (' . \esc_html( 'deprecated', 'total' ) . ')';
													}
													echo \wp_strip_all_tags( $hook_name );
												?></span></h3>
												<div class="hide-if-no-js">
													<button class="totaltheme-custom-actions-item__toggle" aria-expanded="false">
														<span class="screen-reader-text"><?php \esc_html_e( 'Toggle fields for action hook:', 'total' ); ?> <?php echo \wp_strip_all_tags( $hook ); ?></span>
														<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" role="img" aria-hidden="true" focusable="false"><path d="M17.5 11.6L12 16l-5.5-4.4.9-1.2L12 14l4.5-3.6 1 1.2z"></path></svg></span>
													</button>
												</div>
											</div>

											<div class="totaltheme-custom-actions-item__fields">
												<p>
													<label for="wpex_custom_actions[<?php echo \esc_attr( $hook ); ?>][action]"><?php \esc_html_e( 'Code', 'total' ); ?></label>
													<textarea id="wpex_custom_actions[<?php echo \esc_attr( $hook ); ?>][action]" placeholder="<?php esc_attr_e( 'Enter your custom action here&hellip;', 'total' ); ?>" name="wpex_custom_actions[<?php echo \esc_attr( $hook ); ?>][action]" rows="10" cols="50" style="width:100%;"><?php echo \esc_textarea( $action ); ?></textarea>
												</p>
												<p class="wpex-clr">
													<label for="wpex_custom_actions[<?php echo \esc_attr( $hook ); ?>][priority]"><?php \esc_html_e( 'Priority', 'total' ); ?></label>
													<input id="wpex_custom_actions[<?php echo \esc_attr( $hook ); ?>][priority]" name="wpex_custom_actions[<?php echo \esc_attr( $hook ); ?>][priority]" type="number" value="<?php echo \esc_attr( $priority ); ?>">
												</p>
											</div>
										</div>

								<?php endforeach; ?>

							</div>

						<?php endforeach; ?>

					</div>
					<div class="totaltheme-custom-actions__sidebar">
						<div class="totaltheme-custom-actions-widget">
							<h3><?php \esc_html_e( 'Save Your Actions', 'total' ); ?></h3>
							<div class="totaltheme-custom-actions-widget__content">
								<p><?php \esc_html_e( 'Click the button below to save your custom actions.', 'total' ); ?></p>
								<?php \submit_button(); ?>
							</div>
						</div>
					</div>
				</div>
			</form>
		</div>

	<?php }

	/**
	 * Outputs code on the front-end.
	 */
	public function render_actions() {
		$actions = \get_option( 'wpex_custom_actions' );
		if ( empty( $actions ) ) {
			return;
		}
		foreach ( $actions as $key => $val ) {
			if ( ! empty( $val['action'] ) ) {
				$priority = isset( $val['priority'] ) ? \intval( $val['priority'] ) : 10;
				\add_action( $key, [ $this, 'execute_action' ], $priority );
			}
		}
	}

	/**
	 * Used to execute an action.
	 *
	 * @todo should the output pass through wpex_the_content?
	 */
	public function execute_action() {
		$hook    = \current_filter();
		$actions = \get_option( 'wpex_custom_actions' );
		$output  = $actions[$hook]['action'] ?? '';
		if ( $output && is_string( $output ) && empty( $actions[$hook]['php'] ) ) {
			// @todo can we add some sanitization but still allow scripts?
			//$output = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $output ); // remove script tags
			//$output = wp_kses_post( $output );
			echo (new Replace_Vars)->replace( \do_shortcode( \do_blocks( $output ) ) );
		}
	}

	/**
	 * Hook action.
	 */
	protected function get_hook_action( $hook = '' ) {
		$options = \get_option( 'wpex_custom_actions' );
		if ( empty( $options ) || ! \is_array( $options ) ) {
			return '';
		}
		$action = $options[$hook]['action'] ?? '';
		if ( ! $action && ( 'wpex_hook_outer_wrap_before' === $hook || 'wpex_hook_outer_wrap_after' === $hook ) ) {
			$hook = \str_replace( 'wpex_hook_outer', 'wpex_outer', $hook );
			$action = $options[$hook]['action'] ?? '';
		}
		return $action;
	}

}

https://t.me/RX1948 - 2025