Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: HR Forms
- Plugin URI: http://prowebcode.ru/
- Description: Форма обратной связи.
- Version: 1.0b
- Author: HRCode
- Author URI: http://hrcode.ru/
- */
- /* Copyright 2020 HRCode (email: hrcode@gmail.com)
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
- // Регистрация хука, который вызывается при загрузке админ панели
- add_action( 'admin_menu', 'hr_register_submenu_page' );
- add_action( 'admin_init', 'register_my_cool_plugin_settings' );
- // Добавление шорткода
- add_shortcode( 'hrform', 'hr_shortcode' );
- function hr_register_submenu_page()
- {
- // Добавления подпункта меню в "Страницы"
- add_submenu_page( 'edit.php?post_type=page', 'Contact form', 'Contact form', 'manage_options', 'hr-contact-form-options', 'hr_plugin_options_callback' );
- }
- function register_my_cool_plugin_settings() {
- //register our settings
- register_setting( 'my-cool-plugin-settings-group', 'new_option_name' );
- register_setting( 'my-cool-plugin-settings-group', 'some_other_option' );
- register_setting( 'my-cool-plugin-settings-group', 'option_etc' );
- }
- // Вывод страницы настройки формы
- function hr_plugin_options_callback()
- {
- ?>
- <div class="wrap">
- <h1>Your Plugin Name</h1>
- <form method="post" action="options.php">
- <?php settings_fields( 'my-cool-plugin-settings-group' ); ?>
- <?php do_settings_sections( 'my-cool-plugin-settings-group' ); ?>
- <table class="form-table">
- <tr valign="top">
- <th scope="row">New Option Name</th>
- <td><input type="text" name="new_option_name" value="<?php echo esc_attr( get_option('new_option_name') ); ?>" /></td>
- </tr>
- <tr valign="top">
- <th scope="row">Some Other Option</th>
- <td><input type="text" name="some_other_option" value="<?php echo esc_attr( get_option('some_other_option') ); ?>" /></td>
- </tr>
- <tr valign="top">
- <th scope="row">Options, Etc.</th>
- <td><input type="text" name="option_etc" value="<?php echo esc_attr( get_option('option_etc') ); ?>" /></td>
- </tr>
- </table>
- <?php submit_button(); ?>
- </form>
- </div>
- <?php
- }
- function hr_shortcode( $arr )
- {
- if ( $_REQUEST['action'] == 'edit' )
- return;
- ?>
- <script type="text/javascript">
- let url_hrtheme = '<?php echo get_template_directory_uri(); ?>';
- </script>
- <?php
- include ( 'contacts.php' );
- }
- // Добавление кнопки вставки шорткода в редакторе страницы
- // Хуки
- function true_add_mce_button() {
- // проверяем права пользователя - может ли он редактировать посты и страницы
- if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
- return; // если не может, то и кнопка ему не понадобится, в этом случае выходим из функции
- }
- // проверяем, включен ли визуальный редактор у пользователя в настройках (если нет, то и кнопку подключать незачем)
- if ( 'true' == get_user_option( 'rich_editing' ) ) {
- add_filter( 'mce_external_plugins', 'true_add_tinymce_script' );
- add_filter( 'mce_buttons', 'true_register_mce_button' );
- }
- }
- add_action('admin_head', 'true_add_mce_button');
- // В этом функции указываем ссылку на JavaScript-файл кнопки
- function true_add_tinymce_script( $plugin_array ) {
- $plugin_array['true_mce_button'] = plugin_dir_url( __FILE__ ) .'/editor_button.js'; // true_mce_button - идентификатор кнопки
- return $plugin_array;
- }
- // Регистрируем кнопку в редакторе
- function true_register_mce_button( $buttons ) {
- array_push( $buttons, 'true_mce_button' ); // true_mce_button - идентификатор кнопки
- return $buttons;
- }
- ?>
Add Comment
Please, Sign In to add comment