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/admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/plutus/public_html/wp-content/themes/vrm/inc/admin/cpt-settings.php
<?php

namespace TotalTheme\Admin;

\defined( 'ABSPATH' ) || exit;

/**
 * Adds a Post Type Editor Panel for defined Post Types.
 */
class Cpt_Settings {

	/**
	 * Array of post types to add setting pages to.
	 */
	private $types;

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

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

		return static::$instance;
	}

	/**
	 * Hook into actions and filters.
	 */
	public function init_hooks(): void {
		$types = [
			'portfolio',
			'staff',
			'testimonials',
		];

		/**
		 * Filters the custom post types that have a custom settings screen.
		 *
		 * @param array $post_types
		 */
		$this->types = (array) \apply_filters( 'wpex_post_type_editor_types', $types );

		if ( empty( $this->types ) ) {
			return;
		}

		\add_action( 'admin_menu', array( $this, 'add_submenu_pages' ), 40 );
		\add_action( 'admin_init', array( $this, 'register_page_options' ), 40 );
	}

	/**
	 * Returns current page post type.
	 */
	public function get_post_type(): string {
		return ! empty( $_GET['post_type'] ) ? \sanitize_text_field( $_GET['post_type'] ) : '';
	}

	/**
	 * Enqueue scripts for the Post Type Editor Panel.
	 */
	public function enqueue_scripts(): void {
		\wp_enqueue_style( 'wpex-chosen' );
		\wp_enqueue_script( 'wpex-chosen' );
		\wp_enqueue_script( 'wpex-chosen-icon' );

		\wp_enqueue_style( 'totaltheme-admin-pages' );
		\wp_enqueue_script( 'totaltheme-admin-pages' );
	}

	/**
	 * Return array of settings.
	 */
	public function get_settings( $type ): array {
		return array(
			'page' => array(
				'label' => \esc_html__( 'Main Page', 'total' ),
				'type'  => 'wp_dropdown_pages',
				'description' => \esc_html__( 'Used for theme breadcrumbs when the auto archive is disabled.', 'total' ),
			),
			'admin_icon' => array(
				'label' => \esc_html__( 'Admin Icon', 'total' ),
				'type'  => 'dashicon',
				'default' => array(
					'staff'        => 'businessman',
					'portfolio'    => 'portfolio',
					'testimonials' => 'testimonial',
				),
			),
			'has_archive' => array(
				'label' => \esc_html__( 'Enable Auto Archive?', 'total' ),
				'type'  => 'checkbox',
				'description' => \esc_html__( 'Disabled by default so you can create your archive page using a page builder.', 'total' ),
			),
			'archive_orderby' => array(
				'label' => \esc_html__( 'Archive Orderby', 'total' ),
				'type'  => 'select',
				'choices' => array(
					'' => \esc_html__( 'Default', 'total' ),
					'date' => \esc_html__( 'Date', 'total' ),
					'title' => \esc_html__( 'Title', 'total' ),
					'name' => \esc_html__( 'Name (post slug)', 'total' ),
					'modified' => \esc_html__( 'Modified', 'total' ),
					'author' => \esc_html__( 'Author', 'total' ),
					'parent' => \esc_html__( 'Parent', 'total' ),
					'ID' => \esc_html__( 'ID', 'total' ),
					'comment_count' => \esc_html__( 'Comment Count', 'total' ),
				),

			),
			'archive_order' => array(
				'label' => \esc_html__( 'Archive Order', 'total' ),
				'type'  => 'select',
				'choices' => array(
					'' => \esc_html__( 'Default', 'total' ),
					'DESC' => \esc_html__( 'Descending', 'total' ),
					'ASC' => \esc_html__( 'Ascending', 'total' ),
				),

			),
			'has_single' => array(
				'label' => \esc_html__( 'Enable Single Post?', 'total' ),
				'type'  => 'checkbox',
				'default' => true,
			),
			'show_in_rest' => array(
				'label' => \esc_html__( 'Show in Rest?', 'total' ),
				'type'  => 'checkbox',
				'default' => false,
				'description' => \esc_html__( 'Enables support for the Gutenberg Editor.', 'total' ),
			),
			'custom_sidebar' => array(
				'label' => \esc_html__( 'Enable Custom Sidebar?', 'total' ),
				'type'  => 'checkbox',
				'default' => true,
			),
			'search' => array(
				'label' => \esc_html__( 'Include in Search Results?', 'total' ),
				'type'  => 'checkbox',
				'default' => true,
			),
			'labels' => array(
				'label' => \esc_html__( 'Post Type: Name', 'total' ),
				'type'  => 'text',
			),
			'singular_name' => array(
				'label' => \esc_html__( 'Post Type: Singular Name', 'total' ),
				'type'  => 'text',
			),
			'slug' => array(
				'label' => \esc_html__( 'Post Type: Slug', 'total' ),
				'type'  => 'text',
			),
			'categories' => array(
				'label' => \esc_html__( 'Enable Categories?', 'total' ),
				'type'  => 'checkbox',
				'default' => true,
			),
			'cat_labels' => array(
				'label' => \esc_html__( 'Categories: Label', 'total' ),
				'type'  => 'text',
			),
			'cat_slug' => array(
				'label' => \esc_html__( 'Categories: Slug', 'total' ),
				'type'  => 'text',
			),
			'tags' => array(
				'label' => \esc_html__( 'Enable Tags?', 'total' ),
				'type'  => 'checkbox',
				'default' => true,
				'exclusive' => array( 'portfolio', 'staff' ),
			),
			'tag_labels' => array(
				'label' => \esc_html__( 'Tag: Label', 'total' ),
				'type'  => 'text',
				'conditional' => 'has_tags',
				'exclusive' => array( 'portfolio', 'staff' ),
			),
			'tag_slug' => array(
				'label' => \esc_html__( 'Tag: Slug', 'total' ),
				'type'  => 'text',
				'conditional' => 'has_tags',
				'exclusive' => array( 'portfolio', 'staff' )
			),
		);
	}

	/**
	 * Get default value.
	 */
	public function get_default( $setting_args ) {
		if ( ! empty( $setting_args['default'] ) ) {
			$post_type = $this->get_post_type();
			if ( is_array( $setting_args['default'] ) && isset( $setting_args['default'][ $post_type ] ) ) {
				return $setting_args['default'][ $post_type ];
			}
			return $setting_args['default'];
		}
	}

	/**
	 * Add sub menu page for the Staff Editor.
	 */
	public function add_submenu_pages(): void {
		foreach ( $this->types as $type ) {

			$post_type_obj = \get_post_type_object( $type );

			if ( ! \is_object( $post_type_obj ) ) {
				continue;
			}

			$hook_suffix = \add_submenu_page(
				"edit.php?post_type={$type}",
				$post_type_obj->labels->name . ' ' . \esc_html__( 'Settings', 'total' ),
				\esc_html__( 'Settings', 'total' ),
				'edit_theme_options',
				"wpex-{$type}-editor",
				[ $this, 'create_admin_page' ]
			);

			\add_action( "load-{$hook_suffix}", [ $this, 'on_load' ] );
		}
	}

	/**
	 * On load.
	 */
	public function on_load(): void {
		Theme_Panel::instance()->enable_admin_bar();

		$this->admin_help_tab();
		$this->maybe_flush_rewrite_rules();
	}

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

		if ( ! $screen ) {
			return;
		}

		$post_type = $this->get_post_type();

		$screen->add_help_tab(
			[
				'id'      => 'totaltheme_cpt_settings',
				'title'   => \esc_html__( 'Need More?', 'total' ),
				'content' => '<p>' . \sprintf(
					\esc_html__( 'For greater control you can always disable this post type via the %sTheme Panel%s and re-register it via our %sPost Types Unlimited Plugin%s.', 'total' ),
						'<a href="' . \esc_url( Theme_Panel::get_setting_link( "{$post_type}_enable" ) ) . '" target="_blank">',
						' &#8599;</a>',
						'<a href="https://wordpress.org/plugins/post-types-unlimited/" target="_blank" rel="nofollow noopener noreferrer">',
						' &#8599;</a>'
				) . '</p>'
			]
		);
	}

	/**
	 * Flush re-write rules.
	 */
	public function maybe_flush_rewrite_rules(): void {
		if ( isset( $_GET['settings-updated'] )
			&& wp_validate_boolean( $_GET['settings-updated'] )
			&& in_array( $this->get_post_type(), $this->types )
		) {
			\flush_rewrite_rules();
		}
	}

	/**
	 * Function that will register the staff editor admin page.
	 */
	public function register_page_options(): void {
		foreach ( $this->types as $type ) {
			\register_setting(
				"wpex_{$type}_editor_options",
				"wpex_{$type}_editor",
				[
					'sanitize_callback' => [ $this, 'save_options' ],
					'default' => null,
				]
			);
		}
	}

	/**
	 * Save settings.
	 */
	public function save_options( $options ) {
		if ( empty( $options ) || empty( $options[ 'post_type'] ) ) {
			return;
		}

		$post_type = $options[ 'post_type'];

		if ( ! \in_array( $post_type, $this->types ) ) {
			return;
		}

		$settings = $this->get_settings( $post_type );

		foreach ( $settings as $setting_name => $setting_args ) {

			if ( isset( $setting_args['exclusive'] ) && ! \in_array( $post_type, $setting_args['exclusive'] ) ) {
				continue;
			}

			if ( 'has_single' === $setting_name && 'testimonials' !== $post_type ) {
				continue;
			}

			$mod_name = "{$post_type}_{$setting_name}";
			$setting_type = $setting_args['type'];
			$default = $this->get_default( $setting_args );
			$value = isset( $options[$mod_name] ) ? $options[$mod_name] : '';

			switch ( $setting_type ) {
				case 'checkbox':
					if ( $default ) {
						if ( $value ) {
							\remove_theme_mod( $mod_name );
						} else {
							\set_theme_mod( $mod_name, false );
						}
					} else {
						if ( $value ) {
							\set_theme_mod( $mod_name, true );
						} else {
							\remove_theme_mod( $mod_name );
						}
					}
					break;
				case 'select':
					if ( ! empty( $value )
						&& isset( $setting_args['choices'] )
						&& array_key_exists( $value, $setting_args['choices'] )
					) {
						\set_theme_mod( $mod_name, $value );
					} else {
						\remove_theme_mod( $mod_name );
					}
					break;
				default:
					if ( $value ) {
						\set_theme_mod( $mod_name, $value );
					} else {
						\remove_theme_mod( $mod_name );
					}
					break;
			}

		}

		return ''; // don't save as option.
	}

	/**
	 * Output for the actual Staff Editor admin page.
	 */
	public function create_admin_page(): void {
		$post_type = $this->get_post_type();

		if ( ! $post_type || ! \in_array( $post_type, $this->types ) || ! \current_user_can( 'edit_theme_options' ) ) {
			return;
		}

		$post_type_obj = \get_post_type_object( $post_type );

		$this->enqueue_scripts();

		?>

		<div class="wrap">

			<form method="post" action="options.php">
				<table class="form-table"><?php
					\settings_fields( "wpex_{$post_type}_editor_options" );

					$settings = $this->get_settings( $post_type );

					foreach ( $settings as $field_id => $field ) :

						if ( isset( $field['exclusive'] ) && ! in_array( $post_type, $field['exclusive'] ) ) {
							continue;
						}

						if ( 'has_single' === $field_id && 'testimonials' !== $post_type  ) {
							continue;
						}

						$method = "field_{$field['type']}";

						if ( \method_exists( $this, $method ) ) {

							$mod_name         = "{$post_type}_{$field_id}";
							$field['default'] = $this->get_default( $field );
							$field['id']      = "wpex_{$post_type}_editor[{$mod_name}]";
							$mod_v            = \get_theme_mod( $mod_name, $field['default'] );

							if ( 'checkbox' === $field['type'] ) {
								$field['value'] = ( $mod_v && 'off' !== $mod_v ) ? true : false;
							} else {
								$field['value'] = $mod_v;
							}

							?>

							<tr valign="top">

								<th scope="row"><label for="<?php echo \esc_attr( $field['id'] ); ?>"><?php echo \esc_html( $field['label'] ); ?></label></th>

								<td>
									<?php $this->$method( $field ); ?>
									<?php if ( ! empty( $field['description'] ) ) { ?>
										<?php if ( 'wp_dropdown_pages' === $field['type'] || 'select' === $field['type'] ) { ?>
											<p><span class="description"><?php
												echo \esc_html( $field['description'] );
											?></span></p>
										<?php } else { ?>
											<span class="description" style="margin-left: 5px;"><?php
												echo \esc_html( $field['description'] );
											?></span>
										<?php } ?>

									<?php } ?>
								</td>

							</tr>

						<?php } ?>

					<?php endforeach; ?>

				</table>

				<input type="hidden" name="wpex_<?php echo \esc_attr( $post_type ); ?>_editor[post_type]" value="<?php echo \esc_attr( $post_type ); ?>">

				<?php \submit_button(); ?>

			</form>

		</div>
	<?php }

	/**
	 * Return wp_dropdown_pages field.
	 */
	private function field_wp_dropdown_pages( $field ): void {
		\wp_dropdown_pages( [
			'echo'             => true,
			'selected'         => $field['value'],
			'name'             => $field['id'],
			'id'               => $field['id'],
			'class'            => 'wpex-chosen',
			'show_option_none' => \esc_html__( 'None', 'total' ),
		] );
	}

	/**
	 * Return select field.
	 */
	private function field_select( $field ): void {
		if ( empty( $field['choices'] ) ) {
			return;
		}

		?>

		<select id="<?php echo \esc_attr( $field['id'] ); ?>" name="<?php echo \esc_attr( $field['id'] ); ?>"><?php
			foreach ( $field['choices'] as $ck => $cv ) { ?>
				<option value="<?php echo \esc_attr( $ck ); ?>" <?php \selected( $field['value'], $ck, true ) ?>><?php
					echo \esc_html( $cv );
				?></option>
			<?php }
		?></select>
	<?php }

	/**
	 * Return text field.
	 */
	private function field_text( $field ): void {
		$attributes = [
			'type'  => 'text',
			'id'    => $field['id'],
			'name'  => $field['id'],
			'value' => $field['value'],
		];

		if ( isset( $field['size'] ) ) {
			$attributes['size'] = \absint( $field['size'] );
		}

		echo '<input';
	        foreach ( $attributes as $name => $value ) {
	            echo ' ' . $name . '="' . esc_attr( $value ) . '"';
	        }
	    echo '>';
	}

	/**
	 * Return checkbox field.
	 */
	private function field_checkbox( $field ): void {
		$attributes = [
			'type'  => 'checkbox',
			'id'    => $field['id'],
			'name'  => $field['id'],
		];

		if ( isset( $field['class'] ) ) {
			$attributes['class'] = $field['class'];
		}

		echo '<span class="totaltheme-admin-checkbox"><input';
			foreach ( $attributes as $name => $value ) {
	            echo ' ' . $name . '="' . \esc_attr( $value ) . '"';
	        }
			\checked( $field['value'], true, true );
		echo '><span class="totaltheme-admin-checkbox__track"></span>
			<span class="totaltheme-admin-checkbox__thumb"></span>
		</span>';
	}

	/**
	 * Return dashicon field.
	 *
	 * @param array $field Current field to get dashicon for.
	 *
	 * @return string
	 */
	private function field_dashicon( $field ): void {
		$dashicons = \wpex_get_dashicons_array();
		?>
		<select name="<?php echo \esc_attr( $field['id'] ); ?>"  id="<?php echo \esc_attr( $field['id'] ); ?>" class="wpex-chosen-icon-select"><?php
			foreach ( $dashicons as $k => $v ) {
				$class = ( $field['value'] === $k ) ? 'button-primary' : 'button';
				?>
				<option value="<?php echo \esc_attr( $k ) ; ?>" data-icon="dashicons dashicons-<?php echo \sanitize_html_class( $k ); ?>" <?php \selected( $k, $field['value'], true ); ?>><?php echo \esc_html( $k ); ?></option>
			<?php }
		?></select>
	<?php
	}

}

https://t.me/RX1948 - 2025