Advertisement
BratokHR

Untitled

Sep 27th, 2020
1,412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 21.60 KB | None | 0 0
  1. <?php
  2.  
  3. defined( 'ABSPATH' ) || die();
  4.  
  5. function test()
  6. {
  7.   wp_enqueue_style( 'wp-color-picker' );
  8.   wp_enqueue_script( 'hrcode-pagination-color-picker', plugins_url( '/js/hrcode-pagination-color-picker.js', __FILE__ ), array('wp-color-picker'), false, true );
  9. }
  10. add_action('admin_enqueue_scripts', 'test');
  11.  
  12. class HRCode_Plagin_Pagination_Option {
  13.   private static $hrcode_pagination_settings = array();
  14.  
  15.   public function __construct() {
  16.     // Подключение стилей страницы настроек плагина
  17.     add_action('admin_init', array( $this, 'hrcode_pagination_init'));
  18.     // Подключение стилей кастомайзера страницы настроек плагина
  19.     add_action('wp_enqueue_scripts', array( $this, 'hrcode_pagination_page_style'));
  20.     // Создание страницы настроек плагина
  21.     add_action( 'admin_menu', array( $this, 'hrcode_pagination_menu' ));
  22.     // Настройки страницы опций
  23.     add_action( 'admin_init', array( $this, 'hrcode_pagination_setting' ));
  24.  
  25.     self::init_settings();
  26.  
  27.     self::check_option();
  28.   }
  29.  
  30.   // Проверяет option в wp, при необходимости создает его
  31.   public function check_option()
  32.   {
  33.     if ( !get_option( 'hrcode-pagination-section' ) )
  34.     {
  35.       register_setting( 'hrcode-pagination-section', 'hrcode-pagination-section' );
  36.  
  37.       $h = array();
  38.      
  39.       foreach( self::$hrcode_pagination_settings as $opt )
  40.         $h[$opt['id']] = $opt['std'];
  41.  
  42.       update_option( 'hrcode-pagination-section', $h );
  43.     }
  44.   }
  45.  
  46.   // Инициализирует массив
  47.   public function init_settings()
  48.   {
  49.     // Массив настроек
  50.     self::$hrcode_pagination_settings = array(
  51.  
  52.       // ---------- Настройка элементов ----------
  53.       array(
  54.         'section'   => '1',
  55.         'name'      => esc_html__('На одну страницу вперед', 'hrcode-pagination-option'),
  56.         'type'      => 'text',
  57.         'id'        => 'hrcode-pagination-next-page',
  58.         'desc'      => 'По умолчанию:  [ Следующая ]',
  59.         // 'label_for' => 'my_text',
  60.         'std'       => 'Следующая'
  61.       ),
  62.       array(
  63.         'section'   => '1',
  64.         'name'      => esc_html__('На одну страницу назад', 'hrcode-pagination-option'),
  65.         'type'      => 'text',
  66.         'id'        => 'hrcode-pagination-previous-page',
  67.         'desc'      => 'По умолчанию:  [ Предыдущая ]',
  68.         // 'label_for' => 'my_text',
  69.         'std'       => 'Предыдущая'
  70.       ),
  71.       array(
  72.         'section'   => '1',
  73.         'name'      => esc_html__('Перейти к последней странице', 'hrcode-pagination-option'),
  74.         'type'      => 'text',
  75.         'id'        => 'hrcode-pagination-next-full',
  76.         'desc'      => 'По умолчанию:  [ >> ]',
  77.         // 'label_for' => 'my_text',
  78.         'std'       => '>>'
  79.       ),
  80.       array(
  81.         'section'   => '1',
  82.         'name'      => esc_html__('Перейти к первой странице', 'hrcode-pagination-option'),
  83.         'type'      => 'text',
  84.         'id'        => 'hrcode-pagination-previous-full',
  85.         'desc'      => 'По умолчанию:  [ << ]',
  86.         // 'label_for' => 'my_text',
  87.         'std'       => '<<'
  88.       ),
  89.       /// ---------- Настройка цвета ----------
  90.       array(
  91.         'section'   => '2',
  92.         'name'      => esc_html__('Фон номера текущей страницы', 'hrcode-pagination-option'),
  93.         'type'      => 'color',
  94.         'id'        => 'hrcode-pagination-current-page-bg',
  95.         'desc'      => 'По умолчанию: [ #F7F7F7, #495464 ]',
  96.         // 'label_for' => 'my_text',
  97.         'std'       => '#495464'
  98.       ),
  99.       array(
  100.         'section'   => '2',
  101.         'name'      => esc_html__('Цвет номера текущей страницы', 'hrcode-pagination-option'),
  102.         'type'      => 'color',
  103.         'id'        => 'hrcode-pagination-current-page-color',
  104.         'desc'      => 'По умолчанию: [ #999, #F7F7F7 ]',
  105.         // 'label_for' => 'my_text',
  106.         'std'       => '#F7F7F7'
  107.       ),
  108.       array(
  109.         'section'   => '2',
  110.         'name'      => esc_html__('Фон всех элементов', 'hrcode-pagination-option'),
  111.         'type'      => 'color',
  112.         'id'        => 'hrcode-pagination-text-bg',
  113.         'desc'      => 'По умолчанию: [ #F7F7F7, #BBBFCA ] ',
  114.         // 'label_for' => 'my_text',
  115.         'std'       => '#BBBFCA '
  116.       ),
  117.       array(
  118.         'section'   => '2',
  119.         'name'      => esc_html__('Цвет всех элементов', 'hrcode-pagination-option'),
  120.         'type'      => 'color',
  121.         'id'        => 'hrcode-pagination-text-color',
  122.         'desc'      => 'По умолчанию: [ #777, #F7F7F7] ',
  123.         // 'label_for' => 'my_text',
  124.         'std'       => '#F7F7F7'
  125.       ),
  126.       array(
  127.         'section'   => '2',
  128.         'name'      => esc_html__('Фон элемента при наведении', 'hrcode-pagination-option'),
  129.         'type'      => 'color',
  130.         'id'        => 'hrcode-pagination-text-hover-bg',
  131.         'desc'      => 'По умолчанию: [ #F7F7F7, #BBBBBE ]',
  132.         // 'label_for' => 'my_text',
  133.         'std'       => '#BBBBBE'
  134.       ),
  135.       array(
  136.         'section'   => '2',
  137.         'name'      => esc_html__('Цвет элемента при наведении', 'hrcode-pagination-option'),
  138.         'type'      => 'color',
  139.         'id'        => 'hrcode-pagination-text-hover-color',
  140.         'desc'      => 'По умолчанию: [ #555, #F7F7F7 ]',
  141.         // 'label_for' => 'my_text',
  142.         'std'       => '#F7F7F7'
  143.       ),
  144.     // ---------- Настройка шрифта ----------
  145.       array(
  146.         'section'   => '3',
  147.         'name'      => esc_html__('Размер шрифта текста (px)', 'hrcode-pagination-option'),
  148.         'type'      => 'number',
  149.         'id'        => 'hrcode-fontsize__text',
  150.         'desc'      => 'По умолчанию: 16px',
  151.         // 'label_for' => 'my_text',
  152.         'std'       => '16'
  153.       )
  154.     );
  155.   }
  156.  
  157.   // Подключение стилей страницы настроек плагина
  158.   public function hrcode_pagination_init() {
  159.     wp_enqueue_style( 'hrcode-pagination-style', plugins_url( '/css/hrcode-pagination-style.css', __FILE__ ) );
  160.     // wp_enqueue_style( 'hrcode-default-style', plugins_url( '/css/hrcode-default-style.css', __FILE__ ) );
  161.     // wp_enqueue_style( 'hrcode-pagination-page-style', plugins_url( 'css/hrcode-pagination-page-style.css', __FILE__ ));
  162.   }
  163.  
  164.  
  165.   // Подключение стилей кастомайзера страницы настроек плагина
  166.   public function hrcode_pagination_page_style() {
  167.     // wp_enqueue_style( 'hrcode-pagination-page-style', plugins_url( '/css/hrcode-pagination-page-style.css', __FILE__ ) );
  168.  
  169.     wp_enqueue_style( 'hrcode-pagination-page-styles-customizer', self::hrcode_pagination_page_styles_customizer() );
  170.   }
  171.  
  172.  
  173.  
  174.   // Создание страницы настроек плагина
  175.   public function hrcode_pagination_menu(){
  176.     // add_menu_page( $page_title, $menu_title, $capability, $menu_slug, callable $function = '', string $icon_url = '', int $position = null )
  177.  
  178.     add_menu_page(
  179.       'Основные настройки HRCode-Pagination',     // Заголовок на странице настроек
  180.       'HRC-Pagination',                           // Заголовок в меню админ-панели
  181.       'manage_options',                           // Пользователь
  182.       'hrcode-pagination-option',                 // Название меню опций, которое отображается в адресной строке, сейчас такое же, как и название файла опций
  183.       array( $this, 'hrcode_pagination_page' ),   //  Название функции, которая показывает страницу настроек(опций)
  184.       'dashicons-leftright',                      // Название иконки, которая отображается рядом с названием меню опций
  185.       93                                          // Номер согласно которого меню располагается в списке остальных меню
  186.       );
  187.   }
  188.  
  189.  
  190.  
  191.   // Настройки страницы опций
  192.   public function hrcode_pagination_setting() {
  193.  
  194.     //  add_settings_section( $id, $title, $callback, $page );
  195.     //  register_setting( $option_group, $option_name, $args = array() );
  196.  
  197.     // Настройка секции с опциями
  198.     add_settings_section (
  199.       'hrcode-pagination-section_1', // id секции
  200.       'Настройка элементов', // Заголовок секции
  201.       '', // Функция, отображающая любое содержимое в верхней части раздела (между заголовком и полями)
  202.       'hrcode-pagination-option'  // Название страницы с опциями
  203.     );
  204.  
  205.     add_settings_section (
  206.       'hrcode-pagination-section_2', // id секции
  207.       'Настройка цвета', // Заголовок секции
  208.       '', // Функция, отображающая любое содержимое в верхней части раздела (между заголовком и полями)
  209.       'hrcode-pagination-option'  // Название страницы с опциями
  210.     );
  211.  
  212.     add_settings_section (
  213.       'hrcode-pagination-section_3', // id секции
  214.       'Настройка шрифта', // Заголовок секции
  215.       '', // Функция, отображающая любое содержимое в верхней части раздела (между заголовком и полями)
  216.       'hrcode-pagination-option'  // Название страницы с опциями
  217.     );
  218.  
  219.     $count = 0;
  220.     foreach( self::$hrcode_pagination_settings as $opt )
  221.     {
  222.       if ( $opt['section'] == '1' )
  223.       {
  224.         add_settings_field(
  225.           'id_field' . $count, // id поля
  226.           $opt['name'], // Название поля
  227.           array($this, 'hrcode_pagination_display_settings'), // Название функции с входными данными
  228.           'hrcode-pagination-option', // Название страницы с опциями
  229.           'hrcode-pagination-section_1', // Раздел страницы настроек
  230.           $opt
  231.         );
  232.       }
  233.       else if ( $opt['section'] == '2' )
  234.       {
  235.         add_settings_field(
  236.           'id_field' . $count, // id поля
  237.           $opt['name'], // Название поля
  238.           array($this, 'hrcode_pagination_display_settings'), // Название функции с входными данными
  239.           'hrcode-pagination-option', // Название страницы с опциями
  240.           'hrcode-pagination-section_2', // Раздел страницы настроек
  241.           $opt
  242.         );
  243.       }
  244.       else if ( $opt['section'] == '3' )
  245.       {
  246.         add_settings_field(
  247.           'id_field' . $count, // id поля
  248.           $opt['name'], // Название поля
  249.           array($this, 'hrcode_pagination_display_settings'), // Название функции с входными данными
  250.           'hrcode-pagination-option', // Название страницы с опциями
  251.           'hrcode-pagination-section_3', // Раздел страницы настроек
  252.           $opt
  253.         );
  254.       }
  255.  
  256.       $count++;
  257.     }
  258.  
  259.     if ( isset( $_REQUEST['reset'] ) )
  260.     {
  261.       $h = get_option( 'hrcode-pagination-section' );
  262.  
  263.       if ( is_array($h) )
  264.       {
  265.         foreach( self::$hrcode_pagination_settings as $opt )
  266.         {
  267.           if ( isset( $opt['std'] ) )
  268.           {
  269.             $h[$opt['id']] = $opt['std'];
  270.           }
  271.         }
  272.       update_option( 'hrcode-pagination-section', $h );
  273.       }
  274.     }
  275.   }
  276.  
  277.   // Показываем страницу настроек
  278.   public function hrcode_pagination_page(){
  279.  
  280.     if (!current_user_can('manage_options')) {
  281.       wp_die( __('У вас нет доступа к просмотру этой страницы.') );
  282.     }
  283.   settings_errors();
  284. ?>
  285.     <div class="hrcode-pagination-wrap">
  286.       <div class="hrcode-pagination-main-block">
  287.         <div class="hrcode-pagination-left-block">
  288.           <div class="hrcode-pagination-header">
  289.             <div class="logo-img__left hide-on-small-screen">
  290.               <img src="/wp-content/plugins/hrcode-pagination/img/logo-pagination-plagin.png" alt="logo_hrcode_plg">
  291.             </div>
  292.             <!-- /.logo-img__left -->
  293.             <h2 class="hrcode-pagination-header__title">
  294.               Плагин HRCode-Pagination
  295.             </h2>
  296.             <div class="logo-img__right hide-on-small-screen">
  297.               <img src="/wp-content/plugins/hrcode-pagination/img/logo-hrcode-plagin.png" alt="logo_pwc_plg">
  298.             </div>
  299.             <!-- /.logo-img__right -->
  300.           </div>
  301.           <!-- /.hrcode-pagination-header -->
  302.  
  303.           <div class="hrcode-pagination-install">
  304.             <h2 class="hrcode-pagination-install__title">Установка плагина HRCode-Pagination</h2>
  305.             <div class="hrcode-pagination-description">
  306.               <p>Плагин HR-Pagination автоматически добавляет пользовательскую пагинацию на страницы блога.</br>
  307.               Если у вас установлена тема от HRCode, то плагин будет работать сразу после его активации.</br>
  308.               Вам только нужно настроить его внешний вид под дизайн вашего сайта.</br></br>
  309.               Если вы пользуетесь шаблоном не от компании HRCode, то для нормальной работы плагина нужно вставить на страницу, например <em>index.php</em>, в то место, где вы хотите увидеть пагинацию страниц, следующий код:</p>
  310.  
  311.             </div>
  312.             <!-- /.hrcode-pagination-description -->
  313.             <div class="hrcode-pagination-code">
  314.               <span>
  315.                   &lt;?php if (isset (&#36;hrcode_pagination )) { echo do_shortcode ( '[hrcode-pagination]' ) ; } ?>
  316.               </span>
  317.             </div>
  318.             <!--/.hrcode-pagination-code  -->
  319.           </div>
  320.           <!--/.hrcode-pagination-install  -->
  321.  
  322.           <div class="hrcode-pagination-setting">
  323.             <h2 class="hrcode-pagination-setting__title">
  324.               Настройка плагина HRCode-Pagination
  325.             </h2>
  326.             <form method="post" action="options.php" class="hrcode-pagination__form">
  327. <?php
  328.               settings_fields ('hrcode-pagination-section');
  329.               do_settings_sections ('hrcode-pagination-option');
  330.               submit_button();
  331. ?>
  332.             </form>
  333.             <form method='post' class="hrcode-pagination-reset__form">
  334.               <input type='submit' class='reset-button button-secondary' name='reset' value='Сбросить по умолчанию'>
  335.             </form>
  336.           </div>
  337.           <!-- /.hrcode-pagination-setting -->
  338.         </div>
  339.         <!-- /.hrcode-pagination-left-block -->
  340.  
  341.         <div class="hrcode-pagination-right-block">
  342.           <div class="hrcode-pagination-version">
  343.             <h4 class="hrcode-pagination-right-block__title">Информация</h4>
  344.               <p>Версия программы: v.1.0</p>
  345.           </div>
  346.  
  347.           <div class="hrcode-pagination-autor">
  348.             <h4 class="hrcode-pagination-right-block__title">Авторы плагина</h4>
  349.             <div class="hrcode-pagination-autor-link-block">
  350.               <a href="#" target="_blank" class="hrcode-pagination-autor-link">
  351.                 HRCode
  352.               </a>
  353.               <a href="#" target="_blank" class="hrcode-pagination-autor-link">
  354.                 LibCode
  355.               </a>
  356.               <a href="#" target="_blank" class="hrcode-pagination-autor-link">
  357.                 ProWebCode
  358.               </a>
  359.             </div>
  360.             <!-- /.hrcode-pagination-autor-link-block -->
  361.           </div>
  362.           <!-- /.hrcode-pagination-autor -->
  363.  
  364.           <div class="hrcode-pagination-instruction">
  365.             <h4 class="hrcode-pagination-right-block__title">Инструкция по настройке плагина</h4>
  366.               <p>Если что то не понятно по настройке плагина, вы всегда сможете посмотреть дополнительную информацию в инструкции.</p>
  367.               <a href="#" target="_blank">
  368.                 Посмотреть инструкцию
  369.               </a>
  370.           </div>
  371.           <!-- /.hrcode-pagination-instruction -->
  372.         </div>
  373.         <!-- /.hrcode-pagination-right-block -->
  374.       </div>
  375.       <!-- /.hrcode-pagination-main-block -->
  376.     </div>
  377.     <!-- /.wrap .hr-option-wrap -->
  378. <?php
  379. }
  380.  
  381.   // Отображение настроек в инпутах
  382.   public function hrcode_pagination_display_settings($args) {
  383.     extract( $args );
  384.  
  385.     $option_name = 'hrcode-pagination-section';
  386.  
  387.     $h = get_option( $option_name );
  388.  
  389.     switch ( $type ) {
  390.       case 'text':
  391.         if ( isset($h[$id]) )
  392.           $h[$id] = esc_attr( stripslashes($h[$id]) );
  393.     ?>
  394.         <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];} ?>' />
  395.     <?php
  396.         // echo "<input class='regular-text' type='text' id='$id' name='" . $option_name . "[$id]' value='".($h[$id] =='') ? $std : $h[$id]."' />";
  397.         echo (isset ($desc)) ? "<span class='hrcode-pagination-option-description'>$desc</span>" : "";
  398.  
  399.       break;
  400.       case 'number':
  401.         if ( isset($h[$id]) )
  402.           $h[$id] = esc_attr( stripslashes($h[$id]) );
  403.     ?>
  404.         <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];} ?>' />
  405.     <?php
  406.         echo (isset ($desc)) ? "<span class='hrcode-pagination-option-description'>$desc</span>" : "";
  407.  
  408.       break;
  409.       case 'color':
  410.         if ( isset($h[$id]) )
  411.           $h[$id] = esc_attr( stripslashes($h[$id]) );
  412.     ?>
  413.         <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];} ?>' />
  414.     <?php
  415.         echo (isset ($desc)) ? "<span class='hrcode-pagination-option-description'>$desc</span>" : "";
  416.  
  417.       break;
  418.  
  419.   }
  420.   }
  421.     //  Стили внешнего вида плагина HRCode-Pagination
  422.   public function hrcode_pagination_page_styles_customizer() {
  423.     $hrcode_pagination_setting = get_option('hrcode-pagination-section');
  424.   ?>
  425.     <style type="text/css">
  426.  
  427.       .hrcode-pagination-next-page .hrcode-pagination-page-numbers li {
  428.         background: <?php  if ( $hrcode_pagination_setting ['hrcode-pagination-text-bg'] ) { echo $hrcode_pagination_setting ['hrcode-pagination-text-bg']; }?>;
  429.       }
  430.       .hrcode-pagination-next-page .hrcode-pagination-page-numbers li a  {
  431.         color: <?php  if ( $hrcode_pagination_setting ['hrcode-pagination-text-color'] ) { echo $hrcode_pagination_setting ['hrcode-pagination-text-color']; }?>;
  432.       }
  433.       .hrcode-pagination-next-page .hrcode-pagination-page-numbers .hrcode-pagination-active {
  434.         background: <?php  if ( $hrcode_pagination_setting ['hrcode-pagination-current-page-bg'] ) { echo $hrcode_pagination_setting ['hrcode-pagination-current-page-bg']; }?>;
  435.         color: <?php if ( $hrcode_pagination_setting ['hrcode-pagination-current-page-color'] ) { echo $hrcode_pagination_setting ['hrcode-pagination-current-page-color']; }?>;
  436.       }
  437.       .hrcode-pagination-next-page .hrcode-pagination-page-numbers .hrcode-pagination-active:hover {
  438.         background: <?php  if ( $hrcode_pagination_setting ['hrcode-pagination-current-page-bg'] ) { echo $hrcode_pagination_setting ['hrcode-pagination-current-page-bg']; }?>;
  439.       }
  440.       .hrcode-pagination-page-numbers li,
  441.       .hrcode-pagination-page-numbers li a {
  442.         font-size: <?php if ( $hrcode_pagination_setting ['hrcode-fontsize__text'] ) { echo $hrcode_pagination_setting ['hrcode-fontsize__text']; }?>px;
  443.       }
  444.       .hrcode-pagination-next-page .hrcode-pagination-page-numbers li:hover {
  445.         background: <?php  if ( $hrcode_pagination_setting ['hrcode-pagination-text-hover-bg'] ) { echo $hrcode_pagination_setting ['hrcode-pagination-text-hover-bg']; }?>;
  446.       }
  447.       .hrcode-pagination-next-page .hrcode-pagination-page-numbers li a:hover {
  448.         color: <?php  if ( $hrcode_pagination_setting ['hrcode-pagination-text-hover-color'] ) { echo $hrcode_pagination_setting ['hrcode-pagination-text-hover-color']; }?>;
  449.       }
  450.  
  451.     </style>
  452.   <?php
  453.   } // End hr_styles_customizer_method  hrcode-pagination-text-hover-color .hrcode-pagination-page-numbers li a:hover  .hrcode-pagination-page-numbers li:hover
  454.  
  455.  
  456. } // End Class
  457.  
  458. new HRCode_Plagin_Pagination_Option ();
  459.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement