BratokHR

Untitled

Aug 4th, 2020 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.75 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.   Plugin Name: HR Forms
  5.   Plugin URI: http://prowebcode.ru/
  6.   Description: Форма обратной связи.
  7.   Version: 1.0b
  8.   Author: HRCode
  9.   Author URI: http://hrcode.ru/
  10. */
  11.  
  12. /*  Copyright 2020  HRCode  (email: hrcode@gmail.com)
  13.  
  14.     This program is free software; you can redistribute it and/or modify
  15.     it under the terms of the GNU General Public License as published by
  16.     the Free Software Foundation; either version 2 of the License, or
  17.     (at your option) any later version.
  18.  
  19.     This program is distributed in the hope that it will be useful,
  20.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22.     GNU General Public License for more details.
  23.  
  24.     You should have received a copy of the GNU General Public License
  25.     along with this program; if not, write to the Free Software
  26.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  27. */
  28.  
  29. // Регистрация хука, который вызывается при загрузке админ панели
  30. add_action( 'admin_menu', 'hr_register_submenu_page' );
  31. add_action( 'admin_init', 'register_my_cool_plugin_settings' );
  32. // Добавление шорткода
  33. add_shortcode( 'hrform', 'hr_shortcode' );
  34.  
  35. function hr_register_submenu_page()
  36. {
  37.   // Добавления подпункта меню в "Страницы"
  38.   add_submenu_page( 'edit.php?post_type=page', 'Contact form', 'Contact form', 'manage_options', 'hr-contact-form-options', 'hr_plugin_options_callback' );
  39. }
  40.  
  41.  
  42.  function register_my_cool_plugin_settings() {
  43.      //register our settings
  44.      register_setting( 'my-cool-plugin-settings-group', 'new_option_name' );
  45.      register_setting( 'my-cool-plugin-settings-group', 'some_other_option' );
  46.      register_setting( 'my-cool-plugin-settings-group', 'option_etc' );
  47.  }
  48.  
  49. // Вывод страницы настройки формы
  50. function hr_plugin_options_callback()
  51. {
  52.   ?>
  53.  <div class="wrap">
  54.  <h1>Your Plugin Name</h1>
  55.  
  56.  <form method="post" action="options.php">
  57.      <?php settings_fields( 'my-cool-plugin-settings-group' );  ?>
  58.      <?php do_settings_sections( 'my-cool-plugin-settings-group' );  ?>
  59.      <table class="form-table">
  60.          <tr valign="top">
  61.          <th scope="row">New Option Name</th>
  62.          <td><input type="text" name="new_option_name" value="<?php echo esc_attr( get_option('new_option_name') ); ?>" /></td>
  63.          </tr>
  64.  
  65.          <tr valign="top">
  66.          <th scope="row">Some Other Option</th>
  67.          <td><input type="text" name="some_other_option" value="<?php echo esc_attr( get_option('some_other_option') ); ?>" /></td>
  68.          </tr>
  69.  
  70.          <tr valign="top">
  71.          <th scope="row">Options, Etc.</th>
  72.          <td><input type="text" name="option_etc" value="<?php echo esc_attr( get_option('option_etc') ); ?>" /></td>
  73.          </tr>
  74.      </table>
  75.  
  76.      <?php submit_button();  ?>
  77.  
  78.  </form>
  79.  </div>
  80.  <?php
  81. }
  82.  
  83. function hr_shortcode( $arr )
  84. {
  85.   if (  $_REQUEST['action'] == 'edit' )
  86.     return;
  87.  
  88.   ?>
  89.   <script type="text/javascript">
  90.     let url_hrtheme = '<?php echo get_template_directory_uri(); ?>';
  91.   </script>
  92.   <?php
  93.  
  94.   include ( 'contacts.php' );
  95. }
  96.  
  97. // Добавление кнопки вставки шорткода в редакторе страницы
  98. // Хуки
  99. function true_add_mce_button() {
  100.     // проверяем права пользователя - может ли он редактировать посты и страницы
  101.     if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
  102.         return; // если не может, то и кнопка ему не понадобится, в этом случае выходим из функции
  103.     }
  104.     // проверяем, включен ли визуальный редактор у пользователя в настройках (если нет, то и кнопку подключать незачем)
  105.     if ( 'true' == get_user_option( 'rich_editing' ) ) {
  106.         add_filter( 'mce_external_plugins', 'true_add_tinymce_script' );
  107.         add_filter( 'mce_buttons', 'true_register_mce_button' );
  108.     }
  109. }
  110. add_action('admin_head', 'true_add_mce_button');
  111.  
  112. // В этом функции указываем ссылку на JavaScript-файл кнопки
  113. function true_add_tinymce_script( $plugin_array ) {
  114.     $plugin_array['true_mce_button'] = plugin_dir_url( __FILE__ ) .'/editor_button.js'; // true_mce_button - идентификатор кнопки
  115.     return $plugin_array;
  116. }
  117.  
  118. // Регистрируем кнопку в редакторе
  119. function true_register_mce_button( $buttons ) {
  120.     array_push( $buttons, 'true_mce_button' ); // true_mce_button - идентификатор кнопки
  121.     return $buttons;
  122. }
  123.  
  124. ?>
  125.  
Add Comment
Please, Sign In to add comment