Changeset 2529282
- Timestamp:
- 05/10/2021 07:28:25 PM (4 years ago)
- Location:
- postpage-specific-custom-css/tags/0.2.2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
postpage-specific-custom-css/tags/0.2.2/post-page-specific-custom-css.php
r2528049 r2529282 10 10 * Requires PHP: 7.0 11 11 * Tested up to: 5.7 12 * Text Domain: p hylaxppsccss12 * Text Domain: postpage-specific-custom-css 13 13 * Domain Path: /languages 14 14 */ … … 16 16 namespace Phylax\WPPlugin\PPCustomCSS; 17 17 18 if ( ! defined( 'ABSPATH' ) ) { 19 die; 20 } # famous cheatin', huh? 21 22 const TEXT_DOMAIN = 'phylaxppsccss'; 18 use const DOING_AUTOSAVE; 19 20 defined( 'ABSPATH' ) or exit; 23 21 24 22 class Plugin { 25 23 26 public $menu_slug = 'post-page-custom-css'; 27 public $menu_parent_slug = 'options-general.php'; 28 public $option_group = 'ppcs_settings_group'; 29 public $option_name = 'ppcs_settings_name'; 24 const USER_META_STRING = 'ppscc_birthday_message'; 25 const MENU_SLUG = 'post-page-custom-css'; 26 const PARENT_MENU_SLUG = 'options-general.php'; 27 const OPTION_GROUP = 'ppcs_settings_group'; 28 const OPTION_NAME = 'ppcs_settings_name'; 29 30 const POST_META_CSS = '_phylax_ppsccss_css'; 31 const POST_META_SINGLE = '_phylax_ppsccss_single_only'; 32 const POST_META_VALID = '_phylax_ppsccss_valid'; 33 34 const NONCE_HIDE_BIRTHDAY = 'ppscc_hide_birthday'; 35 const NONCE_VALIDATE_CSS = 'ppscc_validate_css'; 30 36 31 37 private $isBirthday = false; 32 38 private $isDayBefore = false; 33 private $isWeekAfter = false; 34 35 private $newPlugin = true; 36 private $flagUrl; 37 private $myTransient; 39 private $isDayAfter = false; 40 41 private $flagsURLs; 38 42 39 43 public function __construct() { … … 45 49 $this, 46 50 'the_content', 47 ] );51 ], 999 ); 48 52 if ( is_admin() ) { 49 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), [ 50 $this, 51 'page_settings_link_filter', 52 ] ); 53 add_action( 'add_meta_boxes', [ 54 $this, 55 'add_meta_boxes', 56 ] ); 57 add_action( 'save_post', [ 58 $this, 59 'save_post', 60 ] ); 61 add_action( 'admin_menu', [ 62 $this, 63 'add_options_page', 64 ] ); 65 add_action( 'admin_init', [ 66 $this, 67 'register_settings', 68 ] ); 69 add_action( 'admin_init', [ 70 $this, 71 'pluginInfo' 72 ] ); 73 add_action( 'admin_enqueue_scripts', [ 74 $this, 75 'admin_enqueue_scripts', 76 ] ); 77 } 78 add_action( 'admin_notices', [ $this, 'adminNotices' ] ); 79 80 add_action( 'after_setup_theme', function () { 81 if ( is_admin() ) { 82 $current_user = wp_get_current_user(); 83 $this->myTransient = 'ppsc_lastview_' . $current_user->ID . '_' . date( 'Ymd' ); 84 $dayBefore = 'ppsc_lastview_' . $current_user->ID . '_' . date( 'Ymd', time() - DAY_IN_SECONDS ); 85 delete_transient( $dayBefore ); 86 } 87 if ( isset( $_GET['ppscTransient'] ) && ( $_GET['ppscTransient'] === 'true' ) ) { 88 delete_transient( $this->myTransient ); 89 } 90 } ); 91 92 $today = date( 'md' ); 93 $birtday = '0502'; 94 if ( $birtday === $today ) { 95 $this->isBirthday = true; 96 } 97 $daybefore = '0501'; 98 if ( $daybefore === $today ) { 99 $this->isDayBefore = true; 100 } 101 $today = (int) $today; 102 $daynext = (int) '0503'; 103 $daylast = (int) '0510'; 104 if ( ( $today >= $daynext ) && ( $today <= $daylast ) ) { 105 $this->isWeekAfter = true; 53 $this->startInAdmin(); 54 } 55 } 56 57 public function startInAdmin() { 58 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), [ $this, 'page_settings_link_filter' ] ); 59 add_action( 'add_meta_boxes', [ $this, 'add_meta_boxes' ] ); 60 add_action( 'save_post', [ $this, 'save_post' ] ); 61 add_action( 'admin_menu', [ $this, 'add_options_page' ] ); 62 add_action( 'admin_init', [ $this, 'register_settings' ] ); 63 add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] ); 64 $today = date( 'md' ); 65 switch ( $today ) { 66 case '0501': 67 $this->isDayBefore = true; 68 break; 69 case '0502': 70 $this->isBirthday = true; 71 break; 72 case '0503': 73 $this->isDayAfter = true; 74 break; 75 } 76 if ( $this->isDayBefore || $this->isBirthday || $this->isDayAfter ) { 77 add_action( 'admin_notices', [ $this, 'adminNotices' ] ); 106 78 } 107 79 } … … 111 83 } 112 84 113 public function admin_enqueue_scripts( $hook) {85 public function admin_enqueue_scripts() { 114 86 $screen = get_current_screen(); 115 87 if ( false === is_a( $screen, 'WP_Screen' ) ) { … … 129 101 return; 130 102 } 131 $settings = (array) get_option( $this->option_name);103 $settings = (array) get_option( self::OPTION_NAME ); 132 104 $value = (int) ( $settings[ $field ] ?? 0 ); 133 105 if ( 1 === $value ) { … … 142 114 143 115 public function register_settings() { 144 register_setting( $this->option_group, $this->option_name);145 add_settings_section( 'plugin-behavior', __( 'Options', TEXT_DOMAIN), [116 register_setting( self::OPTION_GROUP, self::OPTION_NAME ); 117 add_settings_section( 'plugin-behavior', __( 'Options', 'postpage-specific-custom-css' ), [ 146 118 $this, 147 119 'section_plugin_behavior', 148 ], $this->menu_slug ); 149 add_settings_section( 'default-values', __( 'Default values', TEXT_DOMAIN ), [ 120 ], self::MENU_SLUG ); 121 add_settings_field( 'control-user', __( 'User control', 'postpage-specific-custom-css' ), [ 122 $this, 123 'control_user_editor' 124 ], self::MENU_SLUG, 'plugin-behavior' ); 125 add_settings_section( 'default-values', __( 'Default values', 'postpage-specific-custom-css' ), [ 150 126 $this, 151 127 'section_default_values', 152 ], $this->menu_slug);153 add_settings_field( 'default_post_css', __( 'Default stylesheet for new posts', TEXT_DOMAIN), [128 ], self::MENU_SLUG ); 129 add_settings_field( 'default_post_css', __( 'Default stylesheet for new posts', 'postpage-specific-custom-css' ), [ 154 130 $this, 155 131 'default_post_css', 156 ], $this->menu_slug, 'default-values' );157 add_settings_field( 'default_page_css', __( 'Default stylesheet for new pages', TEXT_DOMAIN), [132 ], self::MENU_SLUG, 'default-values' ); 133 add_settings_field( 'default_page_css', __( 'Default stylesheet for new pages', 'postpage-specific-custom-css' ), [ 158 134 $this, 159 135 'default_page_css', 160 ], $this->menu_slug, 'default-values' );161 add_settings_field( 'enable_highlighting_in', __( 'Code highlight', TEXT_DOMAIN), [136 ], self::MENU_SLUG, 'default-values' ); 137 add_settings_field( 'enable_highlighting_in', __( 'Code highlight', 'postpage-specific-custom-css' ), [ 162 138 $this, 163 139 'enable_highlighting_in', 164 ], $this->menu_slug, 'plugin-behavior' );165 add_settings_field( 'bigger_textarea', __( 'Bigger input field', TEXT_DOMAIN), [140 ], self::MENU_SLUG, 'plugin-behavior' ); 141 add_settings_field( 'bigger_textarea', __( 'Bigger input field', 'postpage-specific-custom-css' ), [ 166 142 $this, 167 143 'bigger_textarea', 168 ], $this->menu_slug, 'plugin-behavior' );144 ], self::MENU_SLUG, 'plugin-behavior' ); 169 145 } 170 146 171 147 public function bigger_textarea() { 172 $settings = (array) get_option( $this->option_name);148 $settings = (array) get_option( self::OPTION_NAME ); 173 149 $field = 'bigger_textarea'; 174 150 $value = (int) ( $settings[ $field ] ?? 0 ); … … 176 152 <fieldset> 177 153 <legend class="screen-reader-text"> 178 <span><?php echo __( 'Make input boxes bigger', TEXT_DOMAIN); ?></span>154 <span><?php echo __( 'Make input boxes bigger', 'postpage-specific-custom-css' ); ?></span> 179 155 </legend> 180 <input type="hidden" name="<?php echo $this->option_name; ?>[<?php echo $field; ?>]" value="0">156 <input type="hidden" name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" value="0"> 181 157 <label for="item_<?php echo $field; ?>"> 182 158 <input id="item_<?php echo $field; ?>" type="checkbox" 183 name="<?php echo $this->option_name; ?>[<?php echo $field; ?>]"184 value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Make input boxes on Posts and Pages bigger', TEXT_DOMAIN); ?>159 name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" 160 value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Make input boxes on Posts and Pages bigger', 'postpage-specific-custom-css' ); ?> 185 161 </label> 186 162 </fieldset> … … 189 165 190 166 public function enable_highlighting_in() { 191 $settings = (array) get_option( $this->option_name);167 $settings = (array) get_option( self::OPTION_NAME ); 192 168 $field = 'enable_highlighting_in_settings'; 193 169 $value = (int) ( $settings[ $field ] ?? 0 ); … … 195 171 <fieldset> 196 172 <legend class="screen-reader-text"> 197 <span><?php echo __( 'Enable code highlighting', TEXT_DOMAIN); ?></span>173 <span><?php echo __( 'Enable code highlighting', 'postpage-specific-custom-css' ); ?></span> 198 174 </legend> 199 <input type="hidden" name="<?php echo $this->option_name; ?>[<?php echo $field; ?>]" value="0">175 <input type="hidden" name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" value="0"> 200 176 <label for="item_<?php echo $field; ?>"> 201 177 <input id="item_<?php echo $field; ?>" type="checkbox" 202 name="<?php echo $this->option_name; ?>[<?php echo $field; ?>]"203 value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Enable code highlighting for fields on settings page', TEXT_DOMAIN); ?>178 name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" 179 value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Enable code highlighting for fields on settings page', 'postpage-specific-custom-css' ); ?> 204 180 </label> 205 181 <br> … … 208 184 $value = (int) ( $settings[ $field ] ?? 0 ); 209 185 ?> 210 <input type="hidden" name="<?php echo $this->option_name; ?>[<?php echo $field; ?>]" value="0">186 <input type="hidden" name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" value="0"> 211 187 <label for="item_<?php echo $field; ?>"> 212 188 <input id="item_<?php echo $field; ?>" type="checkbox" 213 name="<?php echo $this->option_name; ?>[<?php echo $field; ?>]"214 value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Enable code highlighting for Posts fields', TEXT_DOMAIN); ?>189 name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" 190 value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Enable code highlighting for Posts fields', 'postpage-specific-custom-css' ); ?> 215 191 </label> 216 192 <br> … … 219 195 $value = (int) ( $settings[ $field ] ?? 0 ); 220 196 ?> 221 <input type="hidden" name="<?php echo $this->option_name; ?>[<?php echo $field; ?>]" value="0">197 <input type="hidden" name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" value="0"> 222 198 <label for="item_<?php echo $field; ?>"> 223 199 <input id="item_<?php echo $field; ?>" type="checkbox" 224 name="<?php echo $this->option_name; ?>[<?php echo $field; ?>]"225 value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Enable code highlighting for Pages fields', TEXT_DOMAIN); ?>200 name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" 201 value="1"<?php echo( ( $value === 1 ) ? ' checked="checked"' : '' ); ?>> <?php echo __( 'Enable code highlighting for Pages fields', 'postpage-specific-custom-css' ); ?> 226 202 </label> 227 203 </fieldset> 228 <p class="description"><?php echo __( '<strong>Warning</strong> Please consider that on weaker computers, enabling CSS highlighting may slow you down.', TEXT_DOMAIN ); ?></p> 204 <p class="description"><?php echo __( '<strong>Warning</strong> Please consider that on weaker computers, enabling CSS highlighting may slow you down.', 'postpage-specific-custom-css' ); ?></p> 205 <?php 206 } 207 208 public function control_user_editor() { 209 $settings = (array) get_option( self::OPTION_NAME ); 210 $field = 'control_user_editor'; 211 $value = (int) ( $settings[ $field ] ?? 0 ); 212 ?> 213 <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; ?>]" 218 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 </label> 220 </fieldset> 229 221 <?php 230 222 } 231 223 232 224 public function default_post_css() { 233 $settings = (array) get_option( $this->option_name ); 234 $field = 'default_post_css'; 235 $value = wp_unslash( $settings[ $field ] ?? '' ); 236 ?> 237 <fieldset> 238 <legend class="screen-reader-text"> 239 <span><?php echo __( 'Default stylesheet for new posts', TEXT_DOMAIN ); ?></span> 225 $settings = (array) get_option( self::OPTION_NAME ); 226 $field = 'default_post_css'; 227 $value = wp_unslash( $settings[ $field ] ?? '' ); 228 $errors = $this->validateCSS( $value ); 229 $error_count = count( $errors ); 230 ?> 231 <fieldset class="<?php echo( ( 0 !== $error_count ) ? 'ppsc_validate_errors' : '' ); ?>"> 232 <legend class="screen - reader - text"> 233 <span><?php echo __( 'Default stylesheet for new posts', 'postpage-specific-custom-css' ); ?></span> 240 234 </legend> 241 235 <p> 242 <textarea id="defaultPostCSS" name="<?php echo $this->option_name; ?>[<?php echo $field; ?>]" 243 class="large-text code" rows="10" cols="50"><?php echo $value; ?></textarea> 236 <label class="ppsc_screen_wide"><textarea id="defaultPostCSS" 237 name=" <?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" 238 class="ppsc_css_source large-text code" rows="10" 239 cols="50"><?php echo $value; ?></textarea></label> 244 240 </p> 241 <?php $this->view_errors( $errors ); ?> 245 242 </fieldset> 246 243 <?php 247 244 } 248 245 246 public function validateCSS( string $css ): array { 247 $errors = []; 248 $imbalanced = false; 249 if ( preg_match( '#</?\w+#', $css ) ) { 250 $errors[] = __( 'Markup is not allowed in CSS.', 'postpage-specific-custom-css' ); 251 } 252 if ( ! $this->validate_balanced_characters( '{', '}', $css ) ) { 253 $errors[] = sprintf( 254 /* translators: 1: {}, 2: }, 3: { */ 255 __( 'Your curly brackets %1$s are imbalanced. Make sure there is a closing %2$s for every opening %3$s.', 'postpage-specific-custom-css' ), 256 '<code>{}</code>', 257 '<code>}</code>', 258 '<code>{</code>' 259 ); 260 $imbalanced = true; 261 } 262 if ( ! $this->validate_balanced_characters( '[', ']', $css ) ) { 263 $errors[] = sprintf( 264 /* translators: 1: {}, 2: }, 3: { */ 265 __( 'Your brackets %1$s are imbalanced. Make sure there is a closing %2$s for every opening %3$s.', 'postpage-specific-custom-css' ), 266 '<code>[]</code>', 267 '<code>]</code>', 268 '<code>[</code>' 269 ); 270 $imbalanced = true; 271 } 272 if ( ! $this->validate_balanced_characters( '(', ')', $css ) ) { 273 $errors[] = sprintf( 274 /* translators: 1: {}, 2: }, 3: { */ 275 __( 'Your parentheses %1$s are imbalanced. Make sure there is a closing %2$s for every opening %3$s.', 'postpage-specific-custom-css' ), 276 '<code>()</code>', 277 '<code>)</code>', 278 '<code>(</code>' 279 ); 280 $imbalanced = true; 281 } 282 if ( ! $this->validate_equal_characters( '"', $css ) ) { 283 $errors[] = sprintf( 284 /* translators: 1: " (double quote) */ 285 __( 'Your double quotes %1$s are uneven. Make sure there is a closing %1$s for every opening %1$s.', 'postpage-specific-custom-css' ), 286 '<code>"</code>' 287 ); 288 $imbalanced = true; 289 } 290 $unclosed_comment_count = $this->validate_count_unclosed_comments( $css ); 291 if ( 0 < $unclosed_comment_count ) { 292 $errors[] = sprintf( 293 /* translators: 1: number of unclosed comments, 2: */ */ 294 _n( 295 'There is %1$s unclosed code comment. Close each comment with %2$s.', 296 'There are %1$s unclosed code comments. Close each comment with %2$s.', 297 $unclosed_comment_count, 298 'postpage-specific-custom-css' 299 ), 300 $unclosed_comment_count, 301 '<code>*/</code>' 302 ); 303 $imbalanced = true; 304 } elseif ( ! $this->validate_balanced_characters( '/*', '*/', $css ) ) { 305 $errors[] = sprintf( 306 /* translators: 1: */, 2: /* */ 307 __( 'There is an extra %1$s, indicating an end to a comment. Be sure that there is an opening %2$s for every closing %1$s.', 'postpage-specific-custom-css' ), 308 '<code>*/</code>', 309 '<code>/*</code>' 310 ); 311 $imbalanced = true; 312 } 313 if ( $imbalanced && $this->is_possible_content_error( $css ) ) { 314 $errors[] = sprintf( 315 /* translators: %s: content: ""; */ 316 __( 'Imbalanced/unclosed character errors can be caused by %s declarations. You may need to remove this or add it to a custom CSS file.', 'postpage-specific-custom-css' ), 317 '<code>content: "";</code>' 318 ); 319 } 320 321 return $errors; 322 } 323 324 private function validate_balanced_characters( string $opening_char, string $closing_char, string $css ): bool { 325 return substr_count( $css, $opening_char ) === substr_count( $css, $closing_char ); 326 } 327 328 private function validate_equal_characters( string $char, string $css ): bool { 329 $char_count = substr_count( $css, $char ); 330 331 return ( 0 === $char_count % 2 ); 332 } 333 334 private function validate_count_unclosed_comments( string $css ): int { 335 $count = 0; 336 $comments = explode( '/*', $css ); 337 338 if ( ! is_array( $comments ) || ( 1 >= count( $comments ) ) ) { 339 return $count; 340 } 341 342 unset( $comments[0] ); // The first item is before the first comment. 343 foreach ( $comments as $comment ) { 344 if ( false === strpos( $comment, '*/' ) ) { 345 $count ++; 346 } 347 } 348 349 return $count; 350 } 351 352 private function is_possible_content_error( string $css ): bool { 353 $found = preg_match( '/\bcontent\s*:/', $css ); 354 if ( ! empty( $found ) ) { 355 return true; 356 } 357 358 return false; 359 } 360 361 public function view_errors( array $errors ) { 362 $error_count = count( $errors ); 363 if ( 0 === $error_count ) { 364 return; 365 } 366 ?> 367 <ul class="errors"> 368 <?php foreach ( $errors as $error ) : ?> 369 <li><?php echo $error; ?></li> 370 <?php endforeach; ?> 371 </ul> 372 <?php 373 } 374 249 375 public function default_page_css() { 250 $settings = (array) get_option( $this->option_name ); 251 $field = 'default_page_css'; 252 $value = wp_unslash( $settings[ $field ] ?? '' ); 253 ?> 254 <fieldset> 376 $settings = (array) get_option( self::OPTION_NAME ); 377 $field = 'default_page_css'; 378 $value = wp_unslash( $settings[ $field ] ?? '' ); 379 $errors = $this->validateCSS( $value ); 380 $error_count = count( $errors ); 381 ?> 382 <fieldset class="<?php echo( ( 0 !== $error_count ) ? 'ppsc_validate_errors' : '' ); ?>"> 255 383 <legend class="screen-reader-text"> 256 <span><?php echo __( 'Default stylesheet for new pages', TEXT_DOMAIN); ?></span>384 <span><?php echo __( 'Default stylesheet for new pages', 'postpage-specific-custom-css' ); ?></span> 257 385 </legend> 258 386 <p> 259 <textarea id="defaultPageCSS" name="<?php echo $this->option_name; ?>[<?php echo $field; ?>]" 260 class="large-text code" rows="10" cols="50"><?php echo $value; ?></textarea> 387 <label class="ppsc_screen_wide"><textarea id="defaultPageCSS" 388 name="<?php echo self::OPTION_NAME; ?>[<?php echo $field; ?>]" 389 class="large-text code" rows="10" 390 cols="50"><?php echo $value; ?></textarea></label> 261 391 </p> 392 <?php $this->view_errors( $errors ); ?> 262 393 </fieldset> 263 394 <?php … … 266 397 public function section_default_values() { 267 398 ?> 399 <style> 400 fieldset label.ppsc_screen_wide { 401 width: 100%; 402 } 403 404 fieldset.ppsc_validate_errors ul { 405 color: #a00; 406 } 407 </style> 268 408 <p> 269 <?php echo __( 'You can set the pre-filled content for your newly created posts or pages. ', TEXT_DOMAIN); ?>409 <?php echo __( 'You can set the pre-filled content for your newly created posts or pages. Warning: improper CSS will be stored but not attached.', 'postpage-specific-custom-css' ); ?> 270 410 </p> 271 411 <?php … … 273 413 274 414 public function section_plugin_behavior() { 275 if ( $this->isBirthday || $this->isDayBefore || $this->isWeekAfter ) { 276 $this->adminNotices( true ); 277 } 278 } 279 280 public function adminNotices( $forceShow = false ) { 281 if ( ! current_user_can( 'manage_options' ) ) { 282 return; 283 } 284 $ppscc_birthday = (string) ( $_COOKIE['ppscc_birthday'] ?? '' ); 285 if ( $ppscc_birthday === 'hide' ) { 286 return; 287 } 288 if ( ! $forceShow ) { 289 if ( ! $this->isBirthday && ! $this->isDayBefore && ! $this->isWeekAfter ) { 290 return; 291 } 292 } 293 $current_user = wp_get_current_user(); 294 $transient = 'ppsc_lastview_' . $current_user->ID . '_' . date( 'Ymd' ); 295 $tValue = get_transient( $transient ); 296 if ( ( false !== $tValue ) && ! $forceShow ) { 297 return; 298 } 299 //set_transient( $transient, '1', 6 * HOUR_IN_SECONDS ); 415 ?> 416 <p><?php echo __( 'Be careful. Allowing editors to edit your CSS may crash your site layout if in wrong hands.', 'postpage-specific-custom-css' ); ?></p> 417 <?php 418 } 419 420 public function adminNotices( $show_on_demand = false ) { 421 if ( ! $show_on_demand && $this->current_user_already_seen_message() ) { 422 return; 423 } 300 424 add_action( 'admin_print_footer_scripts', function () { 301 $expires = date( 'D, j M H:i:s e', time() + MONTH_IN_SECONDS );302 425 ?> 303 426 <script> 304 427 jQuery(function ($) { 305 $(document).on('click', '#ppscc_birthday_notice > button.notice-dismiss', function (event) { 306 document.cookie = "ppscc_birthday=hide; SameSite=Lax; expires=<?php echo $expires; ?>"; 307 console.log('Cookie set'); 428 $(document).on('click', '#ppscc_birthday_notice > button.notice-dismiss', function () { 429 $.post(ajaxurl, { 430 url: ajaxurl, 431 action: "ppscc_hide", 432 ppscc_nonce: "<?php echo wp_create_nonce( self::NONCE_HIDE_BIRTHDAY ); ?>", 433 }, function (response) { 434 }); 308 435 }); 309 436 $(document).on('click', '.ppsc_show', function (event) { 310 437 event.preventDefault(); 311 varid = '#acinfofor_' + $(this).data('ppsc');438 const id = '#acinfofor_' + $(this).data('ppsc'); 312 439 $('.ppsc_hide_all').hide(0); 313 440 $(id).show(0); 314 441 }); 315 console.clear();316 console.log('DOM is READY');317 442 }); 318 443 </script> 319 444 <style> 445 .ppsc_screen_wide { 446 width: 100%; 447 } 448 320 449 .ppsc_hide_all { 321 450 margin: 1rem 0; … … 343 472 text-align: center; 344 473 font-weight: bold; 345 letter-spacing: .5px;474 letter-spacing: 1px; 346 475 } 347 476 </style> 348 477 <?php 349 478 } ); 350 $this->flagUrl = plugins_url( '/assets/flags/', __FILE__ ); 351 $flagList = [ 'us', 'gb', 'eu', 'ch', 'pl' ]; 479 $this->flagsURLs = plugins_url( '/assets/flags/', __FILE__ ); 480 $flagList = [ 'us', 'gb', 'eu', 'ch', 'pl' ]; 481 $current_user = wp_get_current_user(); 352 482 ?> 353 483 <div id="ppscc_birthday_notice" class="notice notice-success is-dismissible"> 354 484 <p><span class="dashicons dashicons-buddicons-groups" 355 485 style="font-size:120px;width: 120px;height: 120px;float:left;color:#0a0;"></span> 356 <strong><?php echo sprintf( __( 'Hello %s!', TEXT_DOMAIN), $current_user->display_name ); ?></strong>486 <strong><?php echo sprintf( __( 'Hello %s!', 'postpage-specific-custom-css' ), $current_user->display_name ); ?></strong> 357 487 </p> 358 488 <p> 359 489 <?php 360 490 if ( $this->isBirthday ) { 361 echo __( 'Today is my birthday.', TEXT_DOMAIN) . ' ';362 echo sprintf( __( 'I hope I just turned <strong>%d</strong>.', TEXT_DOMAIN), ( (int) date( 'Y' ) ) - 1977 ) . ' ';491 echo __( 'Today is my birthday.', 'postpage-specific-custom-css' ) . ' '; 492 echo sprintf( __( 'I hope I just turned <strong>%d</strong>.', 'postpage-specific-custom-css' ), ( (int) date( 'Y' ) ) - 1977 ) . ' '; 363 493 } 364 494 if ( $this->isDayBefore ) { 365 echo __( 'Tomorrow will be my birthday.', TEXT_DOMAIN) . ' ';366 echo sprintf( __( 'I hope I will turn <strong>%d</strong> tomorrow.', TEXT_DOMAIN), ( (int) date( 'Y' ) ) - 1977 ) . ' ';495 echo __( 'Tomorrow will be my birthday.', 'postpage-specific-custom-css' ) . ' '; 496 echo sprintf( __( 'I hope I will turn <strong>%d</strong> tomorrow.', 'postpage-specific-custom-css' ), ( (int) date( 'Y' ) ) - 1977 ) . ' '; 367 497 } 368 if ( $this->is WeekAfter ) {369 echo __( ' This week were my birthday.', TEXT_DOMAIN) . ' ';370 echo sprintf( __( 'I hope I turned <strong>%d</strong>...', TEXT_DOMAIN), ( (int) date( 'Y' ) ) - 1977 ) . ' ';498 if ( $this->isDayAfter ) { 499 echo __( 'Yesterday were my birthday.', 'postpage-specific-custom-css' ) . ' '; 500 echo sprintf( __( 'I hope I turned <strong>%d</strong>...', 'postpage-specific-custom-css' ), ( (int) date( 'Y' ) ) - 1977 ) . ' '; 371 501 } 372 echo sprintf( __( 'I just think, maybe you want to <a href="%s">give me a review</a> for my plugin?', TEXT_DOMAIN), 'https://wordpress.org/support/plugin/postpage-specific-custom-css/reviews/#new-post' ) . ' ';373 echo __( 'Or maybe you have such a good situation that you would like to consider a small donation? Click on the currency flag and the account number will show if you would like to repay my work. <strong>I do not insist!</strong> It would be just nice to get a birthday present.', TEXT_DOMAIN) . '<br>';502 echo sprintf( __( 'I just think, maybe you want to <a href="%s">give me a review</a> for my plugin?', 'postpage-specific-custom-css' ), 'https://wordpress.org/support/plugin/postpage-specific-custom-css/reviews/#new-post' ) . ' '; 503 echo __( 'Or maybe you have such a good situation that you would like to consider a small donation? Click on the currency flag and the account number will show if you would like to repay my work. <strong>I do not insist!</strong> It would be just nice to get a birthday present.', 'postpage-specific-custom-css' ) . '<br>'; 374 504 ?> 375 505 </p> 376 506 <p class="ppsc_story"><?php 377 echo __( 'Or maybe you would like to know my story? I weighed 230.6 kg (508.5lb), I couldn\'t move, I almost became a cripple. Thanks to my fiancee I started to lose weight. I\'m halfway there. Currently, I weigh about 165kg (363lb). Or maybe less?', TEXT_DOMAIN) . ' ';378 echo __( '<a href="%s">Follow me on Instagram</a> and <a href="%s">follow the Facebook page</a>. You can also send me wishes there if you like, thank you :)', TEXT_DOMAIN) . ' ';507 echo __( 'Or maybe you would like to know my story? I weighed 230.6 kg (508.5lb), I couldn\'t move, I almost became a cripple. Thanks to my fiancee I started to lose weight. I\'m halfway there. Currently, I weigh about 165kg (363lb). Or maybe less?', 'postpage-specific-custom-css' ) . ' '; 508 echo __( '<a href="%s">Follow me on Instagram</a> and <a href="%s">follow the Facebook page</a>. You can also send me wishes there if you like, thank you :)', 'postpage-specific-custom-css' ) . ' '; 379 509 ?></p> 380 <p style="text-align: center"><?php echo __( 'Click on the flag to see account details. For every, even the smallest payment - thank you a lot!', TEXT_DOMAIN); ?></p>510 <p style="text-align: center"><?php echo __( 'Click on the flag to see account details. For every, even the smallest payment - thank you a lot!', 'postpage-specific-custom-css' ); ?></p> 381 511 <p style="text-align: center"> 382 512 <?php foreach ( $flagList as $code ) : ?> … … 394 524 ]; 395 525 $currency = [ 396 'us' => __( 'United States dollar - USD', TEXT_DOMAIN),397 'gb' => __( 'Pound sterling - GBP', TEXT_DOMAIN),398 'eu' => __( 'Euro - EUR', TEXT_DOMAIN),399 'ch' => __( 'Swiss franc - CHF', TEXT_DOMAIN),400 'pl' => __( 'Polish złoty - PLN', TEXT_DOMAIN),526 'us' => __( 'United States dollar - USD', 'postpage-specific-custom-css' ), 527 'gb' => __( 'Pound sterling - GBP', 'postpage-specific-custom-css' ), 528 'eu' => __( 'Euro - EUR', 'postpage-specific-custom-css' ), 529 'ch' => __( 'Swiss franc - CHF', 'postpage-specific-custom-css' ), 530 'pl' => __( 'Polish złoty - PLN', 'postpage-specific-custom-css' ), 401 531 ]; 402 532 foreach ( $flagList as $code ) { … … 408 538 } 409 539 410 public function flag( $code ) { 540 public function current_user_already_seen_message(): bool { 541 if ( ! current_user_can( 'manage_options' ) ) { 542 // Always return true for non-administrators 543 return true; 544 } 545 $value = (array) ( get_user_meta( get_current_user_id(), self::USER_META_STRING, true ) ?? [] ); 546 547 return (bool) ( $value[ date( 'Y' ) ] ?? false ); 548 } 549 550 public function flag( 551 $code 552 ): string { 411 553 $alt = ''; 412 554 switch ( $code ) { 413 555 case 'us': 414 $alt = __( 'United States dollar - USD', TEXT_DOMAIN);556 $alt = __( 'United States dollar - USD', 'postpage-specific-custom-css' ); 415 557 break; 416 558 case 'gb': 417 $alt = __( 'Pound sterling - GBP', TEXT_DOMAIN);559 $alt = __( 'Pound sterling - GBP', 'postpage-specific-custom-css' ); 418 560 break; 419 561 case 'eu': 420 $alt = __( 'Euro - EUR', TEXT_DOMAIN);562 $alt = __( 'Euro - EUR', 'postpage-specific-custom-css' ); 421 563 break; 422 564 case 'ch': 423 $alt = __( 'Swiss franc - CHF', TEXT_DOMAIN);565 $alt = __( 'Swiss franc - CHF', 'postpage-specific-custom-css' ); 424 566 break; 425 567 case 'pl': 426 $alt = __( 'Polish złoty - PLN', TEXT_DOMAIN);568 $alt = __( 'Polish złoty - PLN', 'postpage-specific-custom-css' ); 427 569 break; 428 570 } 429 571 430 return '<img src="' . $this->flagUrl . $code . '.png' . '" alt="' . $alt . '" title="' . $alt . '" style="width:32px;height:22px;">'; 431 } 432 433 public function accountLine( $code, $account, $currency ) { 572 return '<img src="' . $this->flagsURLs . $code . '.png' . '" alt="' . $alt . '" title="' . $alt . '" style="width:32px;height:22px;">'; 573 } 574 575 public function accountLine( 576 $code, $account, $currency 577 ) { 434 578 ?> 435 579 <div class="ppsc_hide_all" id="acinfofor_<?php echo $code; ?>"> 436 <div class="ppsc_info_line"><?php echo __( 'BIC/SWIFT:', TEXT_DOMAIN); ?>580 <div class="ppsc_info_line"><?php echo __( 'BIC/SWIFT:', 'postpage-specific-custom-css' ); ?> 437 581 <span>ALBPPLPW</span> 438 <?php echo __( 'Currency:', TEXT_DOMAIN) . ' <span> ' . $currency; ?></span></div>439 <div class="ppsc_info_line"><?php echo __( 'Account number:', TEXT_DOMAIN); ?>582 <?php echo __( 'Currency:', 'postpage-specific-custom-css' ) . ' <span> ' . $currency; ?></span></div> 583 <div class="ppsc_info_line"><?php echo __( 'Account number:', 'postpage-specific-custom-css' ); ?> 440 584 <span><?php echo $account; ?></span></div> 441 585 </div> … … 443 587 } 444 588 445 public function page_settings_link_filter( $links ) { 589 public function page_settings_link_filter( 590 $links 591 ) { 446 592 if ( ! is_array( $links ) ) { 447 593 $links = []; 448 594 } 449 $links[] = '<a href="' . $this->build_settings_link() . '">' . __( 'Settings', TEXT_DOMAIN) . '</a>';450 if ( $this->isBirthday || $this->isDayBefore || $this->is WeekAfter ) {451 $links[] = '<a href="' . get_admin_url() . 'options-general.php?page=post-page-custom-css">' . __( 'My birthday!', TEXT_DOMAIN) . '</a>';595 $links[] = '<a href="' . $this->build_settings_link() . '">' . __( 'Settings', 'postpage-specific-custom-css' ) . '</a>'; 596 if ( $this->isBirthday || $this->isDayBefore || $this->isDayAfter ) { 597 $links[] = '<a href="' . get_admin_url() . 'options-general.php?page=post-page-custom-css">' . __( 'My birthday!', 'postpage-specific-custom-css' ) . '</a>'; 452 598 } 453 599 … … 456 602 457 603 private function build_settings_link() { 458 return admin_url( $this->menu_parent_slug . '?page=' . $this->menu_slug);604 return admin_url( self::PARENT_MENU_SLUG . '?page=' . self::MENU_SLUG ); 459 605 } 460 606 461 607 public function add_options_page() { 462 $sub_menu_suffix = add_submenu_page( $this->menu_parent_slug, __( 'Post/Page specific custom CSS', TEXT_DOMAIN ), __( 'Post/Page CSS', TEXT_DOMAIN ), 'manage_options', $this->menu_slug, [608 $sub_menu_suffix = add_submenu_page( self::PARENT_MENU_SLUG, __( 'Post/Page specific custom CSS', 'postpage-specific-custom-css' ), __( 'Post/Page CSS', 'postpage-specific-custom-css' ), 'manage_options', self::MENU_SLUG, [ 463 609 $this, 464 610 'options_page_view', 465 611 ] ); 466 $settings = (array) get_option( $this->option_name);612 $settings = (array) get_option( self::OPTION_NAME ); 467 613 $field = 'enable_highlighting_in_settings'; 468 614 $value = (int) ( $settings[ $field ] ?? 0 ); … … 476 622 477 623 public function options_page_view() { 478 479 624 ?> 480 625 <div class="wrap"> 481 <h1><?php echo __( 'Post/Page Custom CSS', TEXT_DOMAIN); ?></h1>626 <h1><?php echo __( 'Post/Page Custom CSS', 'postpage-specific-custom-css' ); ?></h1> 482 627 <form action="options.php" method="POST"> 483 <?php settings_fields( $this->option_group); ?>628 <?php settings_fields( self::OPTION_GROUP ); ?> 484 629 <div> 485 <?php do_settings_sections( $this->menu_slug); ?>630 <?php do_settings_sections( self::MENU_SLUG ); ?> 486 631 </div> 487 632 <?php submit_button(); ?> … … 489 634 </div> 490 635 <?php 491 $settings = (array) get_option( $this->option_name);636 $settings = (array) get_option( self::OPTION_NAME ); 492 637 $field = 'enable_highlighting_in_settings'; 493 638 $value = (int) ( $settings[ $field ] ?? 0 ); … … 496 641 <script> 497 642 jQuery(function ($) { 498 var defaultPageCSS = $('#defaultPageCSS'); 499 var defaultPostCSS = $('#defaultPostCSS'); 500 var editorSettings; 501 var editor; 643 const defaultPageCSS = $('#defaultPageCSS'); 644 const defaultPostCSS = $('#defaultPostCSS'); 645 let editorSettings; 502 646 if (defaultPageCSS.length === 1) { 503 647 editorSettings = wp.codeEditor.defaultSettings ? _.clone(wp.codeEditor.defaultSettings) : {}; … … 505 649 indentUnit: 2, tabSize: 2, mode: 'css', 506 650 }); 507 editor =wp.codeEditor.initialize(defaultPageCSS, editorSettings);651 wp.codeEditor.initialize(defaultPageCSS, editorSettings); 508 652 } 509 653 if (defaultPostCSS.length === 1) { … … 512 656 indentUnit: 2, tabSize: 2, mode: 'css', 513 657 }); 514 editor =wp.codeEditor.initialize(defaultPostCSS, editorSettings);658 wp.codeEditor.initialize(defaultPostCSS, editorSettings); 515 659 } 516 660 }); … … 520 664 } 521 665 522 public function the_content( $content ) { 523 if ( isset( $GLOBALS['post'] ) ) { 524 $post_id = $GLOBALS['post']->ID; 525 $phylax_ppsccss_single_only = get_post_meta( $post_id, '_phylax_ppsccss_single_only', true ); 526 $phylax_ppsccss_css = get_post_meta( $post_id, '_phylax_ppsccss_css', true ); 527 if ( '' != $phylax_ppsccss_css ) { 528 # mamy css! 529 if ( is_single() || is_page() ) { 530 $content = $this->join( $content, $phylax_ppsccss_css ); 531 } elseif ( '0' == $phylax_ppsccss_single_only ) { 532 $content = $this->join( $content, $phylax_ppsccss_css ); 666 public function the_content( 667 string $content 668 ): string { 669 global $post; 670 if ( ! isset( $post ) || ! is_a( $post, 'WP_Post' ) ) { 671 return $content; 672 } 673 /** @var \WP_Post $post */ 674 $phylax_ppsccss_single_only = get_post_meta( $post->ID, self::POST_META_SINGLE, true ); 675 $phylax_ppsccss_css = get_post_meta( $post->ID, self::POST_META_CSS, true ); 676 if ( '' != $phylax_ppsccss_css ) { 677 678 $phylax_valid_css = (string) ( get_post_meta( $post->ID, self::POST_META_VALID, true ) ?? '' ); 679 if ( '' === $phylax_valid_css ) { 680 $errors = $this->validateCSS( $phylax_ppsccss_css ); 681 if ( 0 === count( $errors ) ) { 682 $phylax_valid_css = '1'; 683 } else { 684 $phylax_valid_css = '0'; 533 685 } 686 update_post_meta( $post->ID, self::POST_META_VALID, $phylax_valid_css ); 534 687 } 688 if ( '1' !== $phylax_valid_css ) { 689 return $content; 690 } 691 692 if ( is_single() || is_page() ) { 693 $content = $this->join( $content, $phylax_ppsccss_css ); 694 } elseif ( '0' == $phylax_ppsccss_single_only ) { 695 $content = $this->join( $content, $phylax_ppsccss_css ); 696 } 535 697 } 536 698 … … 538 700 } 539 701 540 public function join( $content, $css ) { 541 return '<!-- ' . __( 'Added by Post/Page specific custom CSS plugin, thank you for using!', TEXT_DOMAIN ) . ' -->' . PHP_EOL . '<style type="text/css">' . $css . '</style>' . PHP_EOL . $content; 702 public function join( 703 $content, $css 704 ): string { 705 return '<!-- ' . __( 'Added by Post/Page specific custom CSS plugin, thank you for using!', 'postpage-specific-custom-css' ) . ' -->' . PHP_EOL . '<style>' . $css . '</style>' . PHP_EOL . $content; 542 706 } 543 707 544 708 public function add_meta_boxes() { 545 if ( current_user_can( 'manage_options') ) {546 add_meta_box( 'phylax_ppsccss', __( 'Custom CSS', TEXT_DOMAIN), [709 if ( $this->allowedToView() ) { 710 add_meta_box( 'phylax_ppsccss', __( 'Custom CSS', 'postpage-specific-custom-css' ), [ 547 711 $this, 548 712 'render_phylax_ppsccss', … … 554 718 } 555 719 556 public function save_post( $post_id ) { 557 $test_id = (int) $post_id; 558 if ( $test_id < 1 ) { 559 return $post_id; 560 } 561 if ( ! isset( $_POST['phylax_ppsccss_nonce'] ) ) { 562 return $post_id; 563 } 564 $nonce = $_POST['phylax_ppsccss_nonce']; 565 if ( ! wp_verify_nonce( $nonce, 'phylax_ppsccss' ) ) { 566 return $post_id; 720 public function allowedToView() { 721 $settings = (array) get_option( self::OPTION_NAME ); 722 $allow_editors = (bool) ( $settings['control_user_editor'] ?? 0 ); 723 if ( 724 current_user_can( 'manage_options' ) || 725 ( 726 $allow_editors && 727 current_user_can( 'edit_others_pages' ) 728 ) 729 ) { 730 return true; 731 } 732 733 return false; 734 } 735 736 public function save_post( 737 int $post_id 738 ) { 739 $post_id = abs( $post_id ); 740 if ( 0 === $post_id ) { 741 return; 742 } 743 $nonce_value = (string) ( $_POST['phylax_ppsccss_nonce'] ?? '' ); 744 if ( '' === $nonce_value ) { 745 return; 746 } 747 if ( ! wp_verify_nonce( $nonce_value, 'phylax_ppsccss' ) ) { 748 return; 567 749 } 568 750 if ( ( 'page' != $_POST['post_type'] ) && ( 'post' != $_POST['post_type'] ) ) { 569 return $post_id; 570 } 571 if ( ( 'post' == $_POST['post_type'] ) && ! current_user_can( 'edit_post', $post_id ) ) { 572 return $post_id; 573 } 574 if ( ( 'page' == $_POST['post_type'] ) && ! current_user_can( 'edit_page', $post_id ) ) { 575 return $post_id; 576 } 577 if ( defined( 'DOING_AUTOSAVE' ) && \DOING_AUTOSAVE ) { 578 return $post_id; 751 return; 752 } 753 if ( ! $this->allowedToView() ) { 754 return; 755 } 756 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 757 return; 579 758 } 580 759 $phylax_ppsccss_css = trim( strip_tags( $_POST['phylax_ppsccss_css'] ) ); … … 583 762 $phylax_ppsccss_single_only = 0; 584 763 } 585 update_post_meta( $post_id, '_phylax_ppsccss_css', $phylax_ppsccss_css ); 586 update_post_meta( $post_id, '_phylax_ppsccss_single_only', $phylax_ppsccss_single_only ); 587 } 588 589 public function render_phylax_ppsccss( $post ) { 764 $errors = $this->validateCSS( $phylax_ppsccss_css ); 765 $phylax_valid_css = '0'; 766 if ( 0 === count( $errors ) ) { 767 $phylax_valid_css = '1'; 768 } 769 update_post_meta( $post_id, self::POST_META_CSS, $phylax_ppsccss_css ); 770 update_post_meta( $post_id, self::POST_META_SINGLE, $phylax_ppsccss_single_only ); 771 update_post_meta( $post_id, self::POST_META_VALID, $phylax_valid_css ); 772 } 773 774 public function render_phylax_ppsccss( 775 $post 776 ) { 590 777 wp_nonce_field( 'phylax_ppsccss', 'phylax_ppsccss_nonce' ); 591 $screen = '';592 $settings = (array) get_option( $this->option_name);778 $screen = $field = $dField = ''; 779 $settings = (array) get_option( self::OPTION_NAME ); 593 780 switch ( $post->post_type ) { 594 781 case 'post': 595 782 $field = 'enable_highlighting_in_posts'; 596 783 $dField = 'default_page_css'; 597 $screen = __( 'Post custom CSS', TEXT_DOMAIN);784 $screen = __( 'Post custom CSS', 'postpage-specific-custom-css' ); 598 785 break; 599 786 case 'page': 600 787 $field = 'enable_highlighting_in_pages'; 601 788 $dField = 'default_post_css'; 602 $screen = __( 'Page custom CSS', TEXT_DOMAIN);789 $screen = __( 'Page custom CSS', 'postpage-specific-custom-css' ); 603 790 break; 604 791 } 605 if ( '' == $screen) {792 if ( '' === $field ) { 606 793 return; 607 794 } … … 609 796 $post_meta = get_post_meta( $post->ID ); 610 797 $brand_new = false; 611 if ( false === isset( $post_meta[ '_phylax_ppsccss_css'] ) ) {798 if ( false === isset( $post_meta[ self::POST_META_CSS ] ) ) { 612 799 $brand_new = true; 613 800 } 614 $phylax_ppsccss_css = get_post_meta( $post->ID, '_phylax_ppsccss_css', true );801 $phylax_ppsccss_css = get_post_meta( $post->ID, self::POST_META_CSS, true ); 615 802 if ( ( '' === $phylax_ppsccss_css ) && ( true === $brand_new ) ) { 616 $phylax_ppsccss_css .= (string) ( $settings[ $dField ] );617 } 618 $phylax_ppsccss_single_only = get_post_meta( $post->ID, '_phylax_ppsccss_single_only', true );803 $phylax_ppsccss_css .= $settings[ $dField ]; 804 } 805 $phylax_ppsccss_single_only = get_post_meta( $post->ID, self::POST_META_SINGLE, true ); 619 806 if ( '' == $phylax_ppsccss_single_only ) { 620 807 $phylax_ppsccss_single_only = 0; … … 626 813 } 627 814 $biggerBox = (int) ( $settings['bigger_textarea'] ?? 0 ); 815 $errors = $this->validateCSS( $phylax_ppsccss_css ); 628 816 ?> 629 817 <p class="post-attributes-label-wrapper"> 630 818 <label for="phylax_ppsccss_css"><?php echo $screen; ?></label> 631 819 </p> 820 <style> 821 ul.errors { 822 color: #a00; 823 } 824 </style> 825 <?php $this->view_errors( $errors ); ?> 632 826 <div id="phylax_ppsccss_css_outer"> 633 827 <textarea name="phylax_ppsccss_css" id="phylax_ppsccss_css" class="widefat textarea" … … 638 832 value="0"><input type="checkbox" 639 833 name="phylax_ppsccss_single_only" value="1" 640 id="phylax_ppsccss_single_only"<?php echo $checked; ?>> <?php echo __( 'Attach this CSS code only on single page view', TEXT_DOMAIN); ?>834 id="phylax_ppsccss_single_only"<?php echo $checked; ?>> <?php echo __( 'Attach this CSS code only on single page view', 'postpage-specific-custom-css' ); ?> 641 835 </label> 642 836 </p> 643 837 <p> 644 838 <?php 645 echo __( 'Please add only valid CSS code, it will be placed between <style> tags.', TEXT_DOMAIN); ?>839 echo __( 'Please add only valid CSS code, it will be placed between <style> tags.', 'postpage-specific-custom-css' ); ?> 646 840 </p> 647 841 <?php … … 650 844 <script> 651 845 jQuery(function ($) { 652 varphylaxCSSEditorDOM = $('#phylax_ppsccss_css');653 varphylaxCSSEditorSettings;654 varphylaxCSSEditorInstance;846 const phylaxCSSEditorDOM = $('#phylax_ppsccss_css'); 847 let phylaxCSSEditorSettings; 848 let phylaxCSSEditorInstance; 655 849 if (phylaxCSSEditorDOM.length === 1) { 656 850 phylaxCSSEditorSettings = wp.codeEditor.defaultSettings ? _.clone(wp.codeEditor.defaultSettings) : {}; … … 681 875 } 682 876 683 public function pluginInfo() {684 /** TODO: see if there is a new plugin, now there is not. */685 }686 687 877 public function init() { 688 load_plugin_textdomain( TEXT_DOMAIN, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 689 } 690 691 private function text() { 692 __( 'Post/Page specific custom CSS will allow you to add cascade stylesheet to specific posts/pages. It will give you special area in the post/page edit field to attach your CSS. It will also let you decide if this CSS has to be added in multi-page/post view (like archive posts) or only in a single view.', TEXT_DOMAIN ); 878 load_plugin_textdomain( 'postpage-specific-custom-css', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 879 if ( current_user_can( 'manage_options' ) ) { 880 $ppscc_birthday = (string) ( get_user_meta( get_current_user_id(), 'ppscc_birthday', true ) ?? '' ); 881 if ( 'hide' === $ppscc_birthday ) { 882 return; 883 } 884 add_action( 'wp_ajax_ppscc_hide', function () { 885 $ppscc_nonce = (string) ( $_POST['ppscc_nonce'] ?? '' ); 886 if ( '' === $ppscc_nonce ) { 887 exit; 888 } 889 if ( false === wp_verify_nonce( $ppscc_nonce, self::NONCE_HIDE_BIRTHDAY ) ) { 890 exit; 891 } 892 if ( ! current_user_can( 'manage_options' ) ) { 893 exit; 894 } 895 $this->update_user_meta(); 896 echo json_encode( [ 'error' => 0 ] ); 897 exit; 898 } ); 899 } 900 } 901 902 public function update_user_meta() { 903 if ( ! current_user_can( 'manage_options' ) ) { 904 return; 905 } 906 $current_user_id = get_current_user_id(); 907 $value = (array) ( get_user_meta( $current_user_id, self::USER_META_STRING, true ) ?? [] ); 908 $value[ date( 'Y' ) ] = 1; 909 update_user_meta( $current_user_id, self::USER_META_STRING, $value ); 910 } 911 912 /** 913 * This text is used for readme and header translation 914 */ 915 private function _text() { 916 __( 'Post/Page specific custom CSS will allow you to add cascade stylesheet to specific posts/pages. It will give you special area in the post/page edit field to attach your CSS. It will also let you decide if this CSS has to be added in multi-page/post view (like archive posts) or only in a single view.', 'postpage-specific-custom-css' ); 693 917 } 694 918 -
postpage-specific-custom-css/tags/0.2.2/readme.txt
r2528049 r2529282 48 48 49 49 = 0.2.2 = 50 * Release date: 2020-05-07 50 * Release date: 2020-05-10 51 * Lot of fixes, to stay up to date with WordPress code rules 51 52 * Birthday banner visible only for administrators 52 53 * Birthday banner now can be hidden for the next year 54 + Now it's possible to let editors edit CSS 53 55 54 56 = 0.2.1 =
Note: See TracChangeset
for help on using the changeset viewer.