Changeset 2979825
- Timestamp:
- 10/17/2023 01:45:32 AM (2 years ago)
- Location:
- show-current-width
- Files:
-
- 17 added
- 4 edited
-
tags/1.2.1 (added)
-
tags/1.2.1/LICENSE.txt (added)
-
tags/1.2.1/assets (added)
-
tags/1.2.1/assets/show-current-width.css (added)
-
tags/1.2.1/assets/show-current-width.css.map (added)
-
tags/1.2.1/assets/show-current-width.js (added)
-
tags/1.2.1/assets/show-current-width.min.css (added)
-
tags/1.2.1/assets/show-current-width.min.js (added)
-
tags/1.2.1/assets/show-current-width.scss (added)
-
tags/1.2.1/class (added)
-
tags/1.2.1/class/class-showcurrentwidth-admin.php (added)
-
tags/1.2.1/class/class-showcurrentwidth-core.php (added)
-
tags/1.2.1/class/trait-singleton.php (added)
-
tags/1.2.1/readme.txt (added)
-
tags/1.2.1/show-current-width.php (added)
-
tags/1.2.1/uninstall.php (added)
-
tags/1.2.1/w83-show-current-width.php (added)
-
trunk/class/class-showcurrentwidth-admin.php (modified) (6 diffs)
-
trunk/class/class-showcurrentwidth-core.php (modified) (4 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/w83-show-current-width.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
show-current-width/trunk/class/class-showcurrentwidth-admin.php
r2973725 r2979825 139 139 add_settings_section( 140 140 ShowCurrentWidth_Core::PLUGIN_PREFIX . '-section2', 141 __( ' Admin pagesettings', 'show-current-width' ),141 __( 'Display condition settings', 'show-current-width' ), 142 142 array( $this, 'register_section2_html' ), 143 143 ShowCurrentWidth_Core::PLUGIN_PREFIX … … 152 152 array( 153 153 'label_for' => ShowCurrentWidth_Core::PLUGIN_PREFIX . '_admin_show', 154 ), 155 ); 156 // Add field 2-2 (Role condition). 157 add_settings_field( 158 ShowCurrentWidth_Core::PLUGIN_PREFIX . '_condition_role', 159 __( 'Role condition', 'show-current-width' ), 160 array( $this, 'register_field_condition_role_html' ), 161 ShowCurrentWidth_Core::PLUGIN_PREFIX, 162 ShowCurrentWidth_Core::PLUGIN_PREFIX . '-section2', 163 array( 164 'label_for' => ShowCurrentWidth_Core::PLUGIN_PREFIX . '_condition_role', 154 165 ), 155 166 ); … … 304 315 */ 305 316 public function register_section2_html() { 306 echo esc_html__( 'Setting about admin page', 'show-current-width' );317 echo esc_html__( 'Setting about display condition', 'show-current-width' ); 307 318 } 308 319 … … 331 342 332 343 /** 344 * Field 2-2 HTML. 345 * 346 * @return void 347 */ 348 public function register_field_condition_role_html() { 349 global $wp_roles; 350 $roles = $wp_roles->roles; 351 echo esc_html__( 'Display width only for the user who has one of the following roles.', 'show-current-width' ); 352 echo '<ul>'; 353 foreach ( $roles as $role_key => $role_value ) { 354 echo '<li>'; 355 printf( 356 '<input type="checkbox" name="%s_condition_role[]" id="%s_condition_role_%s" value="%s" %s />', 357 esc_attr( ShowCurrentWidth_Core::PLUGIN_PREFIX ), 358 esc_attr( ShowCurrentWidth_Core::PLUGIN_PREFIX ), 359 esc_attr( $role_key ), 360 esc_attr( $role_key ), 361 checked( in_array( $role_key, get_option( ShowCurrentWidth_Core::PLUGIN_PREFIX . '_condition_role' ), true ), true, false ), 362 ); 363 printf( 364 '<label for="%s_condition_role_%s">%s</label>', 365 esc_attr( ShowCurrentWidth_Core::PLUGIN_PREFIX ), 366 esc_attr( $role_key ), 367 esc_attr( translate_user_role( $role_value['name'] ) ) 368 ); 369 echo '</li>'; 370 } 371 } 372 373 /** 333 374 * Section 3 HTML. 334 375 * … … 429 470 register_setting( 430 471 ShowCurrentWidth_Core::PLUGIN_PREFIX . '-field1', 472 ShowCurrentWidth_Core::PLUGIN_PREFIX . '_condition_role', 473 array( 474 'type' => 'array', 475 'sanitize_callback' => array( $this, 'sanitize_array' ), 476 ), 477 ); 478 register_setting( 479 ShowCurrentWidth_Core::PLUGIN_PREFIX . '-field1', 431 480 ShowCurrentWidth_Core::PLUGIN_PREFIX . '_other_init', 432 481 'esc_attr', … … 437 486 'esc_attr', 438 487 ); 488 } 489 490 /** 491 * Sanitize array. 492 * 493 * @param array $args array to be sanitized. 494 * @return array array sanitized. 495 */ 496 public function sanitize_array( $args ) { 497 $args = isset( $args ) ? (array) $args : array(); 498 $args = array_map( 'esc_attr', $args ); 499 return $args; 439 500 } 440 501 -
show-current-width/trunk/class/class-showcurrentwidth-core.php
r2973725 r2979825 23 23 * Plugin constant. 24 24 */ 25 const PLUGIN_VERSION = '1.2. 0';25 const PLUGIN_VERSION = '1.2.1'; 26 26 const PLUGIN_PREFIX = 'show-current-width'; 27 27 const PLUGIN_PREFIX_DEPRECATED = 'w83-show-current-width'; … … 42 42 const OPTION_DEFAULT_ANIMATION_SHOW = 1; 43 43 const OPTION_DEFAULT_ADMIN_SHOW = 0; 44 const OPTION_DEFAULT_CONDITION_ROLE = array( 'administrator' ); 44 45 const OPTION_DEFAULT_OTHER_INIT = 0; 45 46 const OPTION_DEFAULT_OTHER_UNINSTALL = 0; … … 59 60 'animation_show' => self::OPTION_DEFAULT_ANIMATION_SHOW, 60 61 'admin_show' => self::OPTION_DEFAULT_ADMIN_SHOW, 62 'condition_role' => self::OPTION_DEFAULT_CONDITION_ROLE, 61 63 'other_init' => self::OPTION_DEFAULT_OTHER_INIT, 62 64 'other_uninstall' => self::OPTION_DEFAULT_OTHER_UNINSTALL, … … 182 184 */ 183 185 public function display_width( $wp_admin_bar ) { 184 if ( ! is_admin() || get_option( self::PLUGIN_PREFIX . '_admin_show' ) ) { 185 if ( get_option( self::PLUGIN_PREFIX . '_breakpoints_show' ) ) { 186 // Display breakpoint. 187 $breakpoints_definition = str_replace( 188 array( "\r\n", "\r", "\n" ), 189 "\n", 190 get_option( self::PLUGIN_PREFIX . '_breakpoints_definition' ) 191 ); 192 $breakpoints = explode( "\n", $breakpoints_definition ); 193 foreach ( $breakpoints as $breakpoint_key => $breakpoint_value ) { 194 $breakpoints[ $breakpoint_key ] = explode( ',', $breakpoint_value ); 195 } 196 186 // Return if not allowed in admin page. 187 if ( is_admin() && ! get_option( self::PLUGIN_PREFIX . '_admin_show' ) ) { 188 return; 189 } 190 191 // Return if not having an appropriate user role. 192 $roles = get_option( self::PLUGIN_PREFIX . '_condition_role' ); 193 if ( 0 === count( array_intersect( wp_get_current_user()->roles, $roles ) ) ) { 194 return; 195 } 196 197 if ( get_option( self::PLUGIN_PREFIX . '_breakpoints_show' ) ) { 198 // Display breakpoint. 199 $breakpoints_definition = str_replace( 200 array( "\r\n", "\r", "\n" ), 201 "\n", 202 get_option( self::PLUGIN_PREFIX . '_breakpoints_definition' ) 203 ); 204 $breakpoints = explode( "\n", $breakpoints_definition ); 205 foreach ( $breakpoints as $breakpoint_key => $breakpoint_value ) { 206 $breakpoints[ $breakpoint_key ] = explode( ',', $breakpoint_value ); 207 } 208 209 $wp_admin_bar->add_node( 210 array( 211 'id' => self::PLUGIN_PREFIX, 212 'class' => 'menupop', 213 'title' => '<span class="ab-icon" aria-hidden="true"><span class="width">0</span></span>' . 214 '<span class="ab-label">' . 215 '<span class="width-wrap"><span class="width">0</span>px</span>' . 216 '<span class="breakpoint-wrap">(<span class="breakpoint"></span>)</span>' . 217 '</span>', 218 'parent' => '', 219 'href' => '#', 220 ) 221 ); 222 $wp_admin_bar->add_node( 223 array( 224 'id' => self::PLUGIN_PREFIX . '-breakpoint', 225 'title' => '<span class="label">' . esc_html__( 'Breakpoint:', 'show-current-width' ) . '</span>' . 226 '<span class="breakpoint-wrap"><span class="breakpoint"></span></span>', 227 'parent' => self::PLUGIN_PREFIX, 228 'href' => '#', 229 ) 230 ); 231 $breakpoint_index = 0; 232 foreach ( $breakpoints as $breakpoint ) { 197 233 $wp_admin_bar->add_node( 198 234 array( 199 'id' => self::PLUGIN_PREFIX, 200 'class' => 'menupop', 201 'title' => '<span class="ab-icon" aria-hidden="true"><span class="width">0</span></span>' . 202 '<span class="ab-label">' . 203 '<span class="width-wrap"><span class="width">0</span>px</span>' . 204 '<span class="breakpoint-wrap">(<span class="breakpoint"></span>)</span>' . 205 '</span>', 206 'parent' => '', 207 'href' => '#', 208 ) 209 ); 210 $wp_admin_bar->add_node( 211 array( 212 'id' => self::PLUGIN_PREFIX . '-breakpoint', 213 'title' => '<span class="label">' . esc_html__( 'Breakpoint:', 'show-current-width' ) . '</span>' . 214 '<span class="breakpoint-wrap"><span class="breakpoint"></span></span>', 235 'id' => self::PLUGIN_PREFIX . '-breakpoint-' . $breakpoint_index, 236 'title' => 237 sprintf( 238 '<span class="icon"></span>' . 239 '<span class="name">%s:</span>' . 240 '<span class="range">%s ≤ %s < %s</span>', 241 $breakpoint[3], 242 $breakpoint[0], 243 $breakpoint[2], 244 $breakpoint[1] 245 ), 215 246 'parent' => self::PLUGIN_PREFIX, 216 247 'href' => '#', 217 248 ) 218 249 ); 219 $breakpoint_index = 0; 220 foreach ( $breakpoints as $breakpoint ) { 221 $wp_admin_bar->add_node( 222 array( 223 'id' => self::PLUGIN_PREFIX . '-breakpoint-' . $breakpoint_index, 224 'title' => 225 sprintf( 226 '<span class="icon"></span>' . 227 '<span class="name">%s:</span>' . 228 '<span class="range">%s ≤ %s < %s</span>', 229 $breakpoint[3], 230 $breakpoint[0], 231 $breakpoint[2], 232 $breakpoint[1] 233 ), 234 'parent' => self::PLUGIN_PREFIX, 235 'href' => '#', 236 ) 237 ); 238 $breakpoint_index++; 239 } 240 } else { 241 // No display breakpoint. 242 $wp_admin_bar->add_node( 243 array( 244 'id' => self::PLUGIN_PREFIX, 245 'class' => 'menupop', 246 'title' => '<span class="ab-icon" aria-hidden="true"><span class="width">0</span></span>' . 247 '<span class="ab-label">' . 248 '<span class="width-wrap"><span class="width">0</span>px</span>' . 249 '</span>', 250 'parent' => '', 251 'href' => '#', 252 ) 253 ); 254 } 250 $breakpoint_index++; 251 } 252 } else { 253 // No display breakpoint. 254 $wp_admin_bar->add_node( 255 array( 256 'id' => self::PLUGIN_PREFIX, 257 'class' => 'menupop', 258 'title' => '<span class="ab-icon" aria-hidden="true"><span class="width">0</span></span>' . 259 '<span class="ab-label">' . 260 '<span class="width-wrap"><span class="width">0</span>px</span>' . 261 '</span>', 262 'parent' => '', 263 'href' => '#', 264 ) 265 ); 255 266 } 256 267 } -
show-current-width/trunk/readme.txt
r2973725 r2979825 1 1 === Show Current Width === 2 2 Contributors: web83info 3 Tags: admin,width,developement 3 Tags: admin,width,developement,design 4 4 Requires at least: 6.2 5 Tested up to: 6.3. 15 Tested up to: 6.3.2 6 6 Requires PHP: 7.4 7 Stable tag: 1.2. 07 Stable tag: 1.2.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 19 19 20 20 == Changelog == 21 22 = 1.2.1 - 2023-10-17 = 23 * Add: Option to display width only for the user who has the specific roles. 21 24 22 25 = 1.2.0 - 2023-10-02 = -
show-current-width/trunk/w83-show-current-width.php
r2973725 r2979825 4 4 * Plugin URI: 5 5 * Description: This plugin shows a current screen width on WP adminbar. 6 * Version: 1.2. 06 * Version: 1.2.1 7 7 * Requires at least: 6.0 8 * Tested up to: 6.3. 18 * Tested up to: 6.3.2 9 9 * Requires PHP: 7.4 10 10 * Author: web83info <[email protected]>
Note: See TracChangeset
for help on using the changeset viewer.