setting page with minimum and maximum title length checking
-
here is some update for whom it can be interesting. I made setting page with minimum and maximum title length checking
<?php /* Plugin Name: Force Post Title Plugin URI: https://www.jpsays.com Description: Forces user to assign a Title to a post before publishing Contributors: j_p_s Author: Jatinder Pal Singh Version: 1.2 Author URI: https://www.jpsays.com/ */ function force_post_title_init() { wp_enqueue_script('jquery'); } function force_post_title() { $min=get_option('title_page_fields')[title_min]; $max=get_option('title_page_fields')[title_max]; echo "<script type='text/javascript'>\n"; echo " window.onload = function() { jQuery('.editor-post-publish-panel__toggle').mouseover(function(){ console.log('run'); var testervar = jQuery('.editor-post-title__input')[0]; if (testervar.value.length >= ".$min." && testervar.value.length<=".$max.") { jQuery('.editor-post-publish-panel__toggle')[0].disabled=false; //console.log('return true '+testervar.value.length); } else { jQuery('.editor-post-publish-panel__toggle')[0].disabled=true; alert('Заголовок должен быть от ".$min." до ".$max." символов.\\nСейчас '+testervar.value.length); //console.log('return false'); } }); }"; echo "</script>\n"; } function page_settings() { echo '<nodiv class="wrap"><h2>Настройка заголовка</h2>'; echo '<form method="post" action="options.php">'; settings_fields('title_page_fields'); do_settings_sections('force_post_title_settings.php'); submit_button(); echo '</form>'; echo '</nodiv>'; } add_action('admin_init', 'force_post_title_init'); add_action('add_meta_boxes', 'force_post_title'); add_action('admin_menu', 'add_admin_menu'); function add_admin_menu() { add_options_page( 'Настройка заголовка', 'Настройки заголовка', 'edit_posts', 'force_post_title_settings.php', 'page_settings' ); } function title_page_fields() { register_setting('title_page_fields', 'title_page_fields','validate_settings'); add_settings_section( 'snap_section_id', 'Настройки плагина force title page', '', 'force_post_title_settings.php' ); add_settings_field( 'title_max', 'Максимальный размер заголовка', 'custom_html_file_callback', 'force_post_title_settings.php', 'snap_section_id', array( 'id' => 'title_max', 'title' => 'Максимальный размер заголовка', 'option_name' => 'title_page_fields', 'title_max' =>'' ) ); add_settings_field( 'title_min', 'Минимальный размер заголовка', 'custom_html_file_callback', 'force_post_title_settings.php', 'snap_section_id', array( 'id' => 'title_min', 'title' => 'Минимальный размер заголовка', 'option_name' => 'title_page_fields', 'title_min' =>'' ) ); } add_action('admin_init', 'title_page_fields'); function custom_html_file_callback($val) { extract( $val ); $option_name = 'title_page_fields'; $o = get_option( $option_name ); $o[$id] = esc_attr( stripslashes($o[$id]) ); echo "<input type='text' name='".$option_name."[$id]' id='$id' value='$o[$id]' /> <br>"; } /* * Функция проверки правильности вводимых полей */ function theme_validate_settings($input) { return $input; } ?>
- The topic ‘setting page with minimum and maximum title length checking’ is closed to new replies.