Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined( 'ABSPATH' ) || die();
- function test()
- {
- wp_enqueue_style( 'wp-color-picker' );
- wp_enqueue_script( 'hrcode-pagination-color-picker', plugins_url( '/js/hrcode-pagination-color-picker.js', __FILE__ ), array('wp-color-picker'), false, true );
- }
- add_action('admin_enqueue_scripts', 'test');
- class HRCode_Plagin_Pagination_Option {
- private static $hrcode_pagination_settings = array();
- public function __construct() {
- // Подключение стилей страницы настроек плагина
- add_action('admin_init', array( $this, 'hrcode_pagination_init'));
- // Подключение стилей кастомайзера страницы настроек плагина
- add_action('wp_enqueue_scripts', array( $this, 'hrcode_pagination_page_style'));
- // Создание страницы настроек плагина
- add_action( 'admin_menu', array( $this, 'hrcode_pagination_menu' ));
- // Настройки страницы опций
- add_action( 'admin_init', array( $this, 'hrcode_pagination_setting' ));
- self::init_settings();
- self::check_option();
- }
- // Проверяет option в wp, при необходимости создает его
- public function check_option()
- {
- if ( !get_option( 'hrcode-pagination-section' ) )
- {
- register_setting( 'hrcode-pagination-section', 'hrcode-pagination-section' );
- $h = array();
- foreach( self::$hrcode_pagination_settings as $opt )
- $h[$opt['id']] = $opt['std'];
- update_option( 'hrcode-pagination-section', $h );
- }
- }
- // Инициализирует массив
- public function init_settings()
- {
- // Массив настроек
- self::$hrcode_pagination_settings = array(
- // ---------- Настройка элементов ----------
- array(
- 'section' => '1',
- 'name' => esc_html__('На одну страницу вперед', 'hrcode-pagination-option'),
- 'type' => 'text',
- 'id' => 'hrcode-pagination-next-page',
- 'desc' => 'По умолчанию: [ Следующая ]',
- // 'label_for' => 'my_text',
- 'std' => 'Следующая'
- ),
- array(
- 'section' => '1',
- 'name' => esc_html__('На одну страницу назад', 'hrcode-pagination-option'),
- 'type' => 'text',
- 'id' => 'hrcode-pagination-previous-page',
- 'desc' => 'По умолчанию: [ Предыдущая ]',
- // 'label_for' => 'my_text',
- 'std' => 'Предыдущая'
- ),
- array(
- 'section' => '1',
- 'name' => esc_html__('Перейти к последней странице', 'hrcode-pagination-option'),
- 'type' => 'text',
- 'id' => 'hrcode-pagination-next-full',
- 'desc' => 'По умолчанию: [ >> ]',
- // 'label_for' => 'my_text',
- 'std' => '>>'
- ),
- array(
- 'section' => '1',
- 'name' => esc_html__('Перейти к первой странице', 'hrcode-pagination-option'),
- 'type' => 'text',
- 'id' => 'hrcode-pagination-previous-full',
- 'desc' => 'По умолчанию: [ << ]',
- // 'label_for' => 'my_text',
- 'std' => '<<'
- ),
- /// ---------- Настройка цвета ----------
- array(
- 'section' => '2',
- 'name' => esc_html__('Фон номера текущей страницы', 'hrcode-pagination-option'),
- 'type' => 'color',
- 'id' => 'hrcode-pagination-current-page-bg',
- 'desc' => 'По умолчанию: [ #F7F7F7, #495464 ]',
- // 'label_for' => 'my_text',
- 'std' => '#495464'
- ),
- array(
- 'section' => '2',
- 'name' => esc_html__('Цвет номера текущей страницы', 'hrcode-pagination-option'),
- 'type' => 'color',
- 'id' => 'hrcode-pagination-current-page-color',
- 'desc' => 'По умолчанию: [ #999, #F7F7F7 ]',
- // 'label_for' => 'my_text',
- 'std' => '#F7F7F7'
- ),
- array(
- 'section' => '2',
- 'name' => esc_html__('Фон всех элементов', 'hrcode-pagination-option'),
- 'type' => 'color',
- 'id' => 'hrcode-pagination-text-bg',
- 'desc' => 'По умолчанию: [ #F7F7F7, #BBBFCA ] ',
- // 'label_for' => 'my_text',
- 'std' => '#BBBFCA '
- ),
- array(
- 'section' => '2',
- 'name' => esc_html__('Цвет всех элементов', 'hrcode-pagination-option'),
- 'type' => 'color',
- 'id' => 'hrcode-pagination-text-color',
- 'desc' => 'По умолчанию: [ #777, #F7F7F7] ',
- // 'label_for' => 'my_text',
- 'std' => '#F7F7F7'
- ),
- array(
- 'section' => '2',
- 'name' => esc_html__('Фон элемента при наведении', 'hrcode-pagination-option'),
- 'type' => 'color',
- 'id' => 'hrcode-pagination-text-hover-bg',
- 'desc' => 'По умолчанию: [ #F7F7F7, #BBBBBE ]',
- // 'label_for' => 'my_text',
- 'std' => '#BBBBBE'
- ),
- array(
- 'section' => '2',
- 'name' => esc_html__('Цвет элемента при наведении', 'hrcode-pagination-option'),
- 'type' => 'color',
- 'id' => 'hrcode-pagination-text-hover-color',
- 'desc' => 'По умолчанию: [ #555, #F7F7F7 ]',
- // 'label_for' => 'my_text',
- 'std' => '#F7F7F7'
- ),
- // ---------- Настройка шрифта ----------
- array(
- 'section' => '3',
- 'name' => esc_html__('Размер шрифта текста (px)', 'hrcode-pagination-option'),
- 'type' => 'number',
- 'id' => 'hrcode-fontsize__text',
- 'desc' => 'По умолчанию: 16px',
- // 'label_for' => 'my_text',
- 'std' => '16'
- )
- );
- }
- // Подключение стилей страницы настроек плагина
- public function hrcode_pagination_init() {
- wp_enqueue_style( 'hrcode-pagination-style', plugins_url( '/css/hrcode-pagination-style.css', __FILE__ ) );
- // wp_enqueue_style( 'hrcode-default-style', plugins_url( '/css/hrcode-default-style.css', __FILE__ ) );
- // wp_enqueue_style( 'hrcode-pagination-page-style', plugins_url( 'css/hrcode-pagination-page-style.css', __FILE__ ));
- }
- // Подключение стилей кастомайзера страницы настроек плагина
- public function hrcode_pagination_page_style() {
- // wp_enqueue_style( 'hrcode-pagination-page-style', plugins_url( '/css/hrcode-pagination-page-style.css', __FILE__ ) );
- wp_enqueue_style( 'hrcode-pagination-page-styles-customizer', self::hrcode_pagination_page_styles_customizer() );
- }
- // Создание страницы настроек плагина
- public function hrcode_pagination_menu(){
- // add_menu_page( $page_title, $menu_title, $capability, $menu_slug, callable $function = '', string $icon_url = '', int $position = null )
- add_menu_page(
- 'Основные настройки HRCode-Pagination', // Заголовок на странице настроек
- 'HRC-Pagination', // Заголовок в меню админ-панели
- 'manage_options', // Пользователь
- 'hrcode-pagination-option', // Название меню опций, которое отображается в адресной строке, сейчас такое же, как и название файла опций
- array( $this, 'hrcode_pagination_page' ), // Название функции, которая показывает страницу настроек(опций)
- 'dashicons-leftright', // Название иконки, которая отображается рядом с названием меню опций
- 93 // Номер согласно которого меню располагается в списке остальных меню
- );
- }
- // Настройки страницы опций
- public function hrcode_pagination_setting() {
- // add_settings_section( $id, $title, $callback, $page );
- // register_setting( $option_group, $option_name, $args = array() );
- // Настройка секции с опциями
- add_settings_section (
- 'hrcode-pagination-section_1', // id секции
- 'Настройка элементов', // Заголовок секции
- '', // Функция, отображающая любое содержимое в верхней части раздела (между заголовком и полями)
- 'hrcode-pagination-option' // Название страницы с опциями
- );
- add_settings_section (
- 'hrcode-pagination-section_2', // id секции
- 'Настройка цвета', // Заголовок секции
- '', // Функция, отображающая любое содержимое в верхней части раздела (между заголовком и полями)
- 'hrcode-pagination-option' // Название страницы с опциями
- );
- add_settings_section (
- 'hrcode-pagination-section_3', // id секции
- 'Настройка шрифта', // Заголовок секции
- '', // Функция, отображающая любое содержимое в верхней части раздела (между заголовком и полями)
- 'hrcode-pagination-option' // Название страницы с опциями
- );
- $count = 0;
- foreach( self::$hrcode_pagination_settings as $opt )
- {
- if ( $opt['section'] == '1' )
- {
- add_settings_field(
- 'id_field' . $count, // id поля
- $opt['name'], // Название поля
- array($this, 'hrcode_pagination_display_settings'), // Название функции с входными данными
- 'hrcode-pagination-option', // Название страницы с опциями
- 'hrcode-pagination-section_1', // Раздел страницы настроек
- $opt
- );
- }
- else if ( $opt['section'] == '2' )
- {
- add_settings_field(
- 'id_field' . $count, // id поля
- $opt['name'], // Название поля
- array($this, 'hrcode_pagination_display_settings'), // Название функции с входными данными
- 'hrcode-pagination-option', // Название страницы с опциями
- 'hrcode-pagination-section_2', // Раздел страницы настроек
- $opt
- );
- }
- else if ( $opt['section'] == '3' )
- {
- add_settings_field(
- 'id_field' . $count, // id поля
- $opt['name'], // Название поля
- array($this, 'hrcode_pagination_display_settings'), // Название функции с входными данными
- 'hrcode-pagination-option', // Название страницы с опциями
- 'hrcode-pagination-section_3', // Раздел страницы настроек
- $opt
- );
- }
- $count++;
- }
- if ( isset( $_REQUEST['reset'] ) )
- {
- $h = get_option( 'hrcode-pagination-section' );
- if ( is_array($h) )
- {
- foreach( self::$hrcode_pagination_settings as $opt )
- {
- if ( isset( $opt['std'] ) )
- {
- $h[$opt['id']] = $opt['std'];
- }
- }
- update_option( 'hrcode-pagination-section', $h );
- }
- }
- }
- // Показываем страницу настроек
- public function hrcode_pagination_page(){
- if (!current_user_can('manage_options')) {
- wp_die( __('У вас нет доступа к просмотру этой страницы.') );
- }
- settings_errors();
- ?>
- <div class="hrcode-pagination-wrap">
- <div class="hrcode-pagination-main-block">
- <div class="hrcode-pagination-left-block">
- <div class="hrcode-pagination-header">
- <div class="logo-img__left hide-on-small-screen">
- <img src="/wp-content/plugins/hrcode-pagination/img/logo-pagination-plagin.png" alt="logo_hrcode_plg">
- </div>
- <!-- /.logo-img__left -->
- <h2 class="hrcode-pagination-header__title">
- Плагин HRCode-Pagination
- </h2>
- <div class="logo-img__right hide-on-small-screen">
- <img src="/wp-content/plugins/hrcode-pagination/img/logo-hrcode-plagin.png" alt="logo_pwc_plg">
- </div>
- <!-- /.logo-img__right -->
- </div>
- <!-- /.hrcode-pagination-header -->
- <div class="hrcode-pagination-install">
- <h2 class="hrcode-pagination-install__title">Установка плагина HRCode-Pagination</h2>
- <div class="hrcode-pagination-description">
- <p>Плагин HR-Pagination автоматически добавляет пользовательскую пагинацию на страницы блога.</br>
- Если у вас установлена тема от HRCode, то плагин будет работать сразу после его активации.</br>
- Вам только нужно настроить его внешний вид под дизайн вашего сайта.</br></br>
- Если вы пользуетесь шаблоном не от компании HRCode, то для нормальной работы плагина нужно вставить на страницу, например <em>index.php</em>, в то место, где вы хотите увидеть пагинацию страниц, следующий код:</p>
- </div>
- <!-- /.hrcode-pagination-description -->
- <div class="hrcode-pagination-code">
- <span>
- <?php if (isset ($hrcode_pagination )) { echo do_shortcode ( '[hrcode-pagination]' ) ; } ?>
- </span>
- </div>
- <!--/.hrcode-pagination-code -->
- </div>
- <!--/.hrcode-pagination-install -->
- <div class="hrcode-pagination-setting">
- <h2 class="hrcode-pagination-setting__title">
- Настройка плагина HRCode-Pagination
- </h2>
- <form method="post" action="options.php" class="hrcode-pagination__form">
- <?php
- settings_fields ('hrcode-pagination-section');
- do_settings_sections ('hrcode-pagination-option');
- submit_button();
- ?>
- </form>
- <form method='post' class="hrcode-pagination-reset__form">
- <input type='submit' class='reset-button button-secondary' name='reset' value='Сбросить по умолчанию'>
- </form>
- </div>
- <!-- /.hrcode-pagination-setting -->
- </div>
- <!-- /.hrcode-pagination-left-block -->
- <div class="hrcode-pagination-right-block">
- <div class="hrcode-pagination-version">
- <h4 class="hrcode-pagination-right-block__title">Информация</h4>
- <p>Версия программы: v.1.0</p>
- </div>
- <div class="hrcode-pagination-autor">
- <h4 class="hrcode-pagination-right-block__title">Авторы плагина</h4>
- <div class="hrcode-pagination-autor-link-block">
- <a href="#" target="_blank" class="hrcode-pagination-autor-link">
- HRCode
- </a>
- <a href="#" target="_blank" class="hrcode-pagination-autor-link">
- LibCode
- </a>
- <a href="#" target="_blank" class="hrcode-pagination-autor-link">
- ProWebCode
- </a>
- </div>
- <!-- /.hrcode-pagination-autor-link-block -->
- </div>
- <!-- /.hrcode-pagination-autor -->
- <div class="hrcode-pagination-instruction">
- <h4 class="hrcode-pagination-right-block__title">Инструкция по настройке плагина</h4>
- <p>Если что то не понятно по настройке плагина, вы всегда сможете посмотреть дополнительную информацию в инструкции.</p>
- <a href="#" target="_blank">
- Посмотреть инструкцию
- </a>
- </div>
- <!-- /.hrcode-pagination-instruction -->
- </div>
- <!-- /.hrcode-pagination-right-block -->
- </div>
- <!-- /.hrcode-pagination-main-block -->
- </div>
- <!-- /.wrap .hr-option-wrap -->
- <?php
- }
- // Отображение настроек в инпутах
- public function hrcode_pagination_display_settings($args) {
- extract( $args );
- $option_name = 'hrcode-pagination-section';
- $h = get_option( $option_name );
- switch ( $type ) {
- case 'text':
- if ( isset($h[$id]) )
- $h[$id] = esc_attr( stripslashes($h[$id]) );
- ?>
- <input type='text' id='<?php echo $id ?>' name='<?php echo $option_name . '[' . $id . ']' ?>' value='<?php if (!isset($h[$id])) {echo $std;} else {echo $h[$id];} ?>' />
- <?php
- // echo "<input class='regular-text' type='text' id='$id' name='" . $option_name . "[$id]' value='".($h[$id] =='') ? $std : $h[$id]."' />";
- echo (isset ($desc)) ? "<span class='hrcode-pagination-option-description'>$desc</span>" : "";
- break;
- case 'number':
- if ( isset($h[$id]) )
- $h[$id] = esc_attr( stripslashes($h[$id]) );
- ?>
- <input type='number' id='<?php echo $id ?>' name='<?php echo $option_name . '[' . $id . ']' ?>' value='<?php if (!isset($h[$id])) {echo $std;} else {echo $h[$id];} ?>' />
- <?php
- echo (isset ($desc)) ? "<span class='hrcode-pagination-option-description'>$desc</span>" : "";
- break;
- case 'color':
- if ( isset($h[$id]) )
- $h[$id] = esc_attr( stripslashes($h[$id]) );
- ?>
- <input type='text' class="hrcolor_input" color-data="<?php echo $std ?>" id='<?php echo $id ?>' name='<?php echo $option_name . '[' . $id . ']' ?>' value='<?php if (!isset($h[$id])) {echo $std;} else {echo $h[$id];} ?>' />
- <?php
- echo (isset ($desc)) ? "<span class='hrcode-pagination-option-description'>$desc</span>" : "";
- break;
- }
- }
- // Стили внешнего вида плагина HRCode-Pagination
- public function hrcode_pagination_page_styles_customizer() {
- $hrcode_pagination_setting = get_option('hrcode-pagination-section');
- ?>
- <style type="text/css">
- .hrcode-pagination-next-page .hrcode-pagination-page-numbers li {
- background: <?php if ( $hrcode_pagination_setting ['hrcode-pagination-text-bg'] ) { echo $hrcode_pagination_setting ['hrcode-pagination-text-bg']; }?>;
- }
- .hrcode-pagination-next-page .hrcode-pagination-page-numbers li a {
- color: <?php if ( $hrcode_pagination_setting ['hrcode-pagination-text-color'] ) { echo $hrcode_pagination_setting ['hrcode-pagination-text-color']; }?>;
- }
- .hrcode-pagination-next-page .hrcode-pagination-page-numbers .hrcode-pagination-active {
- background: <?php if ( $hrcode_pagination_setting ['hrcode-pagination-current-page-bg'] ) { echo $hrcode_pagination_setting ['hrcode-pagination-current-page-bg']; }?>;
- color: <?php if ( $hrcode_pagination_setting ['hrcode-pagination-current-page-color'] ) { echo $hrcode_pagination_setting ['hrcode-pagination-current-page-color']; }?>;
- }
- .hrcode-pagination-next-page .hrcode-pagination-page-numbers .hrcode-pagination-active:hover {
- background: <?php if ( $hrcode_pagination_setting ['hrcode-pagination-current-page-bg'] ) { echo $hrcode_pagination_setting ['hrcode-pagination-current-page-bg']; }?>;
- }
- .hrcode-pagination-page-numbers li,
- .hrcode-pagination-page-numbers li a {
- font-size: <?php if ( $hrcode_pagination_setting ['hrcode-fontsize__text'] ) { echo $hrcode_pagination_setting ['hrcode-fontsize__text']; }?>px;
- }
- .hrcode-pagination-next-page .hrcode-pagination-page-numbers li:hover {
- background: <?php if ( $hrcode_pagination_setting ['hrcode-pagination-text-hover-bg'] ) { echo $hrcode_pagination_setting ['hrcode-pagination-text-hover-bg']; }?>;
- }
- .hrcode-pagination-next-page .hrcode-pagination-page-numbers li a:hover {
- color: <?php if ( $hrcode_pagination_setting ['hrcode-pagination-text-hover-color'] ) { echo $hrcode_pagination_setting ['hrcode-pagination-text-hover-color']; }?>;
- }
- </style>
- <?php
- } // End hr_styles_customizer_method hrcode-pagination-text-hover-color .hrcode-pagination-page-numbers li a:hover .hrcode-pagination-page-numbers li:hover
- } // End Class
- new HRCode_Plagin_Pagination_Option ();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement