Changeset 2529500
- Timestamp:
- 05/11/2021 06:50:15 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
postpage-specific-custom-css/tags/0.2.2/post-page-specific-custom-css.php
r2529282 r2529500 28 28 const OPTION_NAME = 'ppcs_settings_name'; 29 29 30 const OPTION_ENABLE_HIGHLIGHTING = 'enable_highlighting_in_settings'; 31 const POST_ENABLE_HIGHLIGHTING = 'enable_highlighting_in_posts'; 32 const PAGE_ENABLE_HIGHLIGHTING = 'enable_highlighting_in_pages'; 33 34 const OPT_CONTROL_USER_EDITOR = 'control_user_editor'; 35 const OPT_DEFAULT_POST_CSS = 'default_post_css'; 36 const OPT_DEFAULT_PAGE_CSS = 'default_page_css'; 37 const OPT_BIGGER_TEXTAREA = 'bigger_textarea'; 38 30 39 const POST_META_CSS = '_phylax_ppsccss_css'; 31 40 const POST_META_SINGLE = '_phylax_ppsccss_single_only'; … … 33 42 34 43 const NONCE_HIDE_BIRTHDAY = 'ppscc_hide_birthday'; 35 const NONCE_VALIDATE_CSS = 'ppscc_validate_css';36 44 37 45 private $isBirthday = false; … … 93 101 $field = ''; 94 102 if ( ( $screen->id === 'post' ) && ( $screen->post_type === 'post' ) ) { 95 $field = 'enable_highlighting_in_posts';103 $field = self::POST_ENABLE_HIGHLIGHTING; 96 104 } 97 105 if ( ( $screen->id === 'page' ) && ( $screen->post_type === 'page' ) ) { 98 $field = 'enable_highlighting_in_pages';106 $field = self::PAGE_ENABLE_HIGHLIGHTING; 99 107 } 100 108 if ( '' === $field ) { … … 147 155 public function bigger_textarea() { 148 156 $settings = (array) get_option( self::OPTION_NAME ); 149 $field = 'bigger_textarea'; 150 $value = (int) ( $settings[ $field ] ?? 0 ); 157 $value = (int) ( $settings[ self::OPT_BIGGER_TEXTAREA ] ?? 0 ); 151 158 ?> 152 159 <fieldset> … … 154 161 <span><?php echo __( 'Make input boxes bigger', 'postpage-specific-custom-css' ); ?></span> 155 162 </legend> 156 <input type="hidden" name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" value="0"> 157 <label for="item_<?php echo $field; ?>"> 158 <input id="item_<?php echo $field; ?>" type="checkbox" 159 name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" 163 <input type="hidden" name="<?php echo self::OPTION_NAME; ?>[<?php echo self::OPT_BIGGER_TEXTAREA; ?>]" 164 value="0"> 165 <label for="item_<?php echo self::OPT_BIGGER_TEXTAREA; ?>"> 166 <input id="item_<?php echo self::OPT_BIGGER_TEXTAREA; ?>" type="checkbox" 167 name="<?php echo self::OPTION_NAME; ?>[<?php echo self::OPT_BIGGER_TEXTAREA; ?>]" 160 168 value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Make input boxes on Posts and Pages bigger', 'postpage-specific-custom-css' ); ?> 161 169 </label> … … 166 174 public function enable_highlighting_in() { 167 175 $settings = (array) get_option( self::OPTION_NAME ); 168 $field = 'enable_highlighting_in_settings'; 169 $value = (int) ( $settings[ $field ] ?? 0 ); 176 $value = (int) ( $settings[ self::OPTION_ENABLE_HIGHLIGHTING ] ?? 0 ); 170 177 ?> 171 178 <fieldset> … … 173 180 <span><?php echo __( 'Enable code highlighting', 'postpage-specific-custom-css' ); ?></span> 174 181 </legend> 175 <input type="hidden" name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" value="0"> 176 <label for="item_<?php echo $field; ?>"> 177 <input id="item_<?php echo $field; ?>" type="checkbox" 178 name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" 182 <input type="hidden" 183 name="<?php echo self::OPTION_NAME; ?>[<?php echo self::OPTION_ENABLE_HIGHLIGHTING; ?>]" value="0"> 184 <label for="item_<?php echo self::OPTION_ENABLE_HIGHLIGHTING; ?>"> 185 <input id="item_<?php echo self::OPTION_ENABLE_HIGHLIGHTING; ?>" type="checkbox" 186 name="<?php echo self::OPTION_NAME; ?>[<?php echo self::OPTION_ENABLE_HIGHLIGHTING; ?>]" 179 187 value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Enable code highlighting for fields on settings page', 'postpage-specific-custom-css' ); ?> 180 188 </label> 181 189 <br> 182 190 <?php 183 $field = 'enable_highlighting_in_posts'; 184 $value = (int) ( $settings[ $field ] ?? 0 ); 191 $value = (int) ( $settings[ self::POST_ENABLE_HIGHLIGHTING ] ?? 0 ); 185 192 ?> 186 <input type="hidden" name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" value="0"> 187 <label for="item_<?php echo $field; ?>"> 188 <input id="item_<?php echo $field; ?>" type="checkbox" 189 name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" 193 <input type="hidden" name="<?php echo self::OPTION_NAME; ?>[<?php echo self::POST_ENABLE_HIGHLIGHTING; ?>]" 194 value="0"> 195 <label for="item_<?php echo self::POST_ENABLE_HIGHLIGHTING; ?>"> 196 <input id="item_<?php echo self::POST_ENABLE_HIGHLIGHTING; ?>" type="checkbox" 197 name="<?php echo self::OPTION_NAME; ?>[<?php echo self::POST_ENABLE_HIGHLIGHTING; ?>]" 190 198 value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Enable code highlighting for Posts fields', 'postpage-specific-custom-css' ); ?> 191 199 </label> 192 200 <br> 193 201 <?php 194 $field = 'enable_highlighting_in_pages'; 195 $value = (int) ( $settings[ $field ] ?? 0 ); 202 $value = (int) ( $settings[ self::PAGE_ENABLE_HIGHLIGHTING ] ?? 0 ); 196 203 ?> 197 <input type="hidden" name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" value="0"> 198 <label for="item_<?php echo $field; ?>"> 199 <input id="item_<?php echo $field; ?>" type="checkbox" 200 name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" 204 <input type="hidden" name="<?php echo self::OPTION_NAME; ?>[<?php echo self::PAGE_ENABLE_HIGHLIGHTING; ?>]" 205 value="0"> 206 <label for="item_<?php echo self::PAGE_ENABLE_HIGHLIGHTING; ?>"> 207 <input id="item_<?php echo self::PAGE_ENABLE_HIGHLIGHTING; ?>" type="checkbox" 208 name="<?php echo self::OPTION_NAME; ?>[<?php echo self::PAGE_ENABLE_HIGHLIGHTING; ?>]" 201 209 value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Enable code highlighting for Pages fields', 'postpage-specific-custom-css' ); ?> 202 210 </label> … … 208 216 public function control_user_editor() { 209 217 $settings = (array) get_option( self::OPTION_NAME ); 210 $field = 'control_user_editor'; 211 $value = (int) ( $settings[ $field ] ?? 0 ); 218 $value = (int) ( $settings[ self::OPT_CONTROL_USER_EDITOR ] ?? 0 ); 212 219 ?> 213 220 <fieldset> 214 <input type="hidden" name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" value="0"> 215 <label for="item_<?php echo $field; ?>"> 216 <input id="item_<?php echo $field; ?>" type="checkbox" 217 name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" 221 <input type="hidden" name="<?php echo self::OPTION_NAME; ?>[<?php echo self::OPT_CONTROL_USER_EDITOR; ?>]" 222 value="0"> 223 <label for="item_<?php echo self::OPT_CONTROL_USER_EDITOR; ?>"> 224 <input id="item_<?php echo self::OPT_CONTROL_USER_EDITOR; ?>" type="checkbox" 225 name="<?php echo self::OPTION_NAME; ?>[<?php echo self::OPT_CONTROL_USER_EDITOR; ?>]" 218 226 value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Allow Editors to edit CSS code for posts and pages.', 'postpage-specific-custom-css' ); ?> 219 227 </label> … … 224 232 public function default_post_css() { 225 233 $settings = (array) get_option( self::OPTION_NAME ); 226 $field = 'default_post_css'; 227 $value = wp_unslash( $settings[ $field ] ?? '' ); 234 $value = wp_unslash( $settings[ self::OPT_DEFAULT_POST_CSS ] ?? '' ); 228 235 $errors = $this->validateCSS( $value ); 229 236 $error_count = count( $errors ); … … 235 242 <p> 236 243 <label class="ppsc_screen_wide"><textarea id="defaultPostCSS" 237 name=" <?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]"244 name=" <?php echo self::OPTION_NAME; ?>[<?php echo self::OPT_DEFAULT_POST_CSS; ?>]" 238 245 class="ppsc_css_source large-text code" rows="10" 239 cols="50"><?php echo $value; ?></textarea></label>246 cols="50"><?php echo esc_textarea( $value ); ?></textarea></label> 240 247 </p> 241 248 <?php $this->view_errors( $errors ); ?> … … 375 382 public function default_page_css() { 376 383 $settings = (array) get_option( self::OPTION_NAME ); 377 $field = 'default_page_css'; 378 $value = wp_unslash( $settings[ $field ] ?? '' ); 384 $value = wp_unslash( $settings[ self::OPT_DEFAULT_PAGE_CSS ] ?? '' ); 379 385 $errors = $this->validateCSS( $value ); 380 386 $error_count = count( $errors ); … … 386 392 <p> 387 393 <label class="ppsc_screen_wide"><textarea id="defaultPageCSS" 388 name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]"394 name="<?php echo self::OPTION_NAME; ?>[<?php echo self::OPT_DEFAULT_PAGE_CSS; ?>]" 389 395 class="large-text code" rows="10" 390 cols="50"><?php echo $value; ?></textarea></label>396 cols="50"><?php echo esc_textarea( $value ); ?></textarea></label> 391 397 </p> 392 398 <?php $this->view_errors( $errors ); ?> … … 611 617 ] ); 612 618 $settings = (array) get_option( self::OPTION_NAME ); 613 $field = 'enable_highlighting_in_settings'; 614 $value = (int) ( $settings[ $field ] ?? 0 ); 619 $value = (int) ( $settings[ self::OPTION_ENABLE_HIGHLIGHTING ] ?? 0 ); 615 620 if ( 1 === $value ) { 616 621 add_action( 'load-' . $sub_menu_suffix, [ … … 635 640 <?php 636 641 $settings = (array) get_option( self::OPTION_NAME ); 637 $field = 'enable_highlighting_in_settings'; 638 $value = (int) ( $settings[ $field ] ?? 0 ); 642 $value = (int) ( $settings[ self::OPTION_ENABLE_HIGHLIGHTING ] ?? 0 ); 639 643 if ( 1 === $value ) : 640 644 ?> … … 720 724 public function allowedToView() { 721 725 $settings = (array) get_option( self::OPTION_NAME ); 722 $allow_editors = (bool) ( $settings[ 'control_user_editor'] ?? 0 );726 $allow_editors = (bool) ( $settings[ self::OPT_CONTROL_USER_EDITOR ] ?? 0 ); 723 727 if ( 724 728 current_user_can( 'manage_options' ) || … … 776 780 ) { 777 781 wp_nonce_field( 'phylax_ppsccss', 'phylax_ppsccss_nonce' ); 778 $screen = $ field = $dField = '';782 $screen = $theField = $defaultField = ''; 779 783 $settings = (array) get_option( self::OPTION_NAME ); 780 784 switch ( $post->post_type ) { 781 785 case 'post': 782 $ field = 'enable_highlighting_in_posts';783 $d Field = 'default_page_css';784 $screen = __( 'Post custom CSS', 'postpage-specific-custom-css' );786 $theField = self::POST_ENABLE_HIGHLIGHTING; 787 $defaultField = self::OPT_DEFAULT_PAGE_CSS; 788 $screen = __( 'Post custom CSS', 'postpage-specific-custom-css' ); 785 789 break; 786 790 case 'page': 787 $ field = 'enable_highlighting_in_pages';788 $d Field = 'default_post_css';789 $screen = __( 'Page custom CSS', 'postpage-specific-custom-css' );791 $theField = self::PAGE_ENABLE_HIGHLIGHTING; 792 $defaultField = self::OPT_DEFAULT_POST_CSS; 793 $screen = __( 'Page custom CSS', 'postpage-specific-custom-css' ); 790 794 break; 791 795 } 792 if ( '' === $ field ) {793 return; 794 } 795 $enable_highlighting = (int) ( $settings[ $ field ] ?? 0 );796 if ( '' === $theField ) { 797 return; 798 } 799 $enable_highlighting = (int) ( $settings[ $theField ] ?? 0 ); 796 800 $post_meta = get_post_meta( $post->ID ); 797 801 $brand_new = false; … … 801 805 $phylax_ppsccss_css = get_post_meta( $post->ID, self::POST_META_CSS, true ); 802 806 if ( ( '' === $phylax_ppsccss_css ) && ( true === $brand_new ) ) { 803 $phylax_ppsccss_css .= $settings[ $d Field ];807 $phylax_ppsccss_css .= $settings[ $defaultField ]; 804 808 } 805 809 $phylax_ppsccss_single_only = get_post_meta( $post->ID, self::POST_META_SINGLE, true ); … … 812 816 $checked = ''; 813 817 } 814 $biggerBox = (int) ( $settings[ 'bigger_textarea'] ?? 0 );818 $biggerBox = (int) ( $settings[ self::OPT_BIGGER_TEXTAREA ] ?? 0 ); 815 819 $errors = $this->validateCSS( $phylax_ppsccss_css ); 816 820 ?>
Note: See TracChangeset
for help on using the changeset viewer.