Plugin Directory

Changeset 2529500


Ignore:
Timestamp:
05/11/2021 06:50:15 AM (4 years ago)
Author:
lukasznowicki
Message:

Few other updates, move some variables to constants

File:
1 edited

Legend:

Unmodified
Added
Removed
  • postpage-specific-custom-css/tags/0.2.2/post-page-specific-custom-css.php

    r2529282 r2529500  
    2828    const OPTION_NAME = 'ppcs_settings_name';
    2929
     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
    3039    const POST_META_CSS = '_phylax_ppsccss_css';
    3140    const POST_META_SINGLE = '_phylax_ppsccss_single_only';
     
    3342
    3443    const NONCE_HIDE_BIRTHDAY = 'ppscc_hide_birthday';
    35     const NONCE_VALIDATE_CSS = 'ppscc_validate_css';
    3644
    3745    private $isBirthday = false;
     
    93101        $field = '';
    94102        if ( ( $screen->id === 'post' ) && ( $screen->post_type === 'post' ) ) {
    95             $field = 'enable_highlighting_in_posts';
     103            $field = self::POST_ENABLE_HIGHLIGHTING;
    96104        }
    97105        if ( ( $screen->id === 'page' ) && ( $screen->post_type === 'page' ) ) {
    98             $field = 'enable_highlighting_in_pages';
     106            $field = self::PAGE_ENABLE_HIGHLIGHTING;
    99107        }
    100108        if ( '' === $field ) {
     
    147155    public function bigger_textarea() {
    148156        $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 );
    151158        ?>
    152159        <fieldset>
     
    154161                <span><?php echo __( 'Make input boxes bigger', 'postpage-specific-custom-css' ); ?></span>
    155162            </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; ?>]"
    160168                       value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Make input boxes on Posts and Pages bigger', 'postpage-specific-custom-css' ); ?>
    161169            </label>
     
    166174    public function enable_highlighting_in() {
    167175        $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 );
    170177        ?>
    171178        <fieldset>
     
    173180                <span><?php echo __( 'Enable code highlighting', 'postpage-specific-custom-css' ); ?></span>
    174181            </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; ?>]"
    179187                       value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Enable code highlighting for fields on settings page', 'postpage-specific-custom-css' ); ?>
    180188            </label>
    181189            <br>
    182190            <?php
    183             $field = 'enable_highlighting_in_posts';
    184             $value = (int) ( $settings[ $field ] ?? 0 );
     191            $value = (int) ( $settings[ self::POST_ENABLE_HIGHLIGHTING ] ?? 0 );
    185192            ?>
    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; ?>]"
    190198                       value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Enable code highlighting for Posts fields', 'postpage-specific-custom-css' ); ?>
    191199            </label>
    192200            <br>
    193201            <?php
    194             $field = 'enable_highlighting_in_pages';
    195             $value = (int) ( $settings[ $field ] ?? 0 );
     202            $value = (int) ( $settings[ self::PAGE_ENABLE_HIGHLIGHTING ] ?? 0 );
    196203            ?>
    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; ?>]"
    201209                       value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Enable code highlighting for Pages fields', 'postpage-specific-custom-css' ); ?>
    202210            </label>
     
    208216    public function control_user_editor() {
    209217        $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 );
    212219        ?>
    213220        <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; ?>]"
    218226                       value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Allow Editors to edit CSS code for posts and pages.', 'postpage-specific-custom-css' ); ?>
    219227            </label>
     
    224232    public function default_post_css() {
    225233        $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 ] ?? '' );
    228235        $errors      = $this->validateCSS( $value );
    229236        $error_count = count( $errors );
     
    235242            <p>
    236243                <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; ?>]"
    238245                                                          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>
    240247            </p>
    241248            <?php $this->view_errors( $errors ); ?>
     
    375382    public function default_page_css() {
    376383        $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 ] ?? '' );
    379385        $errors      = $this->validateCSS( $value );
    380386        $error_count = count( $errors );
     
    386392            <p>
    387393                <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; ?>]"
    389395                                                          class="large-text code" rows="10"
    390                                                           cols="50"><?php echo $value; ?></textarea></label>
     396                                                          cols="50"><?php echo esc_textarea( $value ); ?></textarea></label>
    391397            </p>
    392398            <?php $this->view_errors( $errors ); ?>
     
    611617        ] );
    612618        $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 );
    615620        if ( 1 === $value ) {
    616621            add_action( 'load-' . $sub_menu_suffix, [
     
    635640        <?php
    636641        $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 );
    639643        if ( 1 === $value ) :
    640644            ?>
     
    720724    public function allowedToView() {
    721725        $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 );
    723727        if (
    724728            current_user_can( 'manage_options' ) ||
     
    776780    ) {
    777781        wp_nonce_field( 'phylax_ppsccss', 'phylax_ppsccss_nonce' );
    778         $screen   = $field = $dField = '';
     782        $screen   = $theField = $defaultField = '';
    779783        $settings = (array) get_option( self::OPTION_NAME );
    780784        switch ( $post->post_type ) {
    781785            case 'post':
    782                 $field  = 'enable_highlighting_in_posts';
    783                 $dField = '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' );
    785789                break;
    786790            case 'page':
    787                 $field  = 'enable_highlighting_in_pages';
    788                 $dField = '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' );
    790794                break;
    791795        }
    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 );
    796800        $post_meta           = get_post_meta( $post->ID );
    797801        $brand_new           = false;
     
    801805        $phylax_ppsccss_css = get_post_meta( $post->ID, self::POST_META_CSS, true );
    802806        if ( ( '' === $phylax_ppsccss_css ) && ( true === $brand_new ) ) {
    803             $phylax_ppsccss_css .= $settings[ $dField ];
     807            $phylax_ppsccss_css .= $settings[ $defaultField ];
    804808        }
    805809        $phylax_ppsccss_single_only = get_post_meta( $post->ID, self::POST_META_SINGLE, true );
     
    812816            $checked = '';
    813817        }
    814         $biggerBox = (int) ( $settings['bigger_textarea'] ?? 0 );
     818        $biggerBox = (int) ( $settings[ self::OPT_BIGGER_TEXTAREA ] ?? 0 );
    815819        $errors    = $this->validateCSS( $phylax_ppsccss_css );
    816820        ?>
Note: See TracChangeset for help on using the changeset viewer.