Skip to content

Commit 4974847

Browse files
committed
add styles for settings page
1 parent 30d7783 commit 4974847

File tree

10 files changed

+68
-15
lines changed

10 files changed

+68
-15
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ build/*
55
!build/index.asset.php
66
!build/index.css
77
!build/style-index.css
8+
!build/settings.asset.php
9+
!build/settings.css
810
composer.phar
911
/release

build/index.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-polyfill'), 'version' => 'cf92ca1107eaa6b155568ac252b7a6aa');
1+
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-polyfill'), 'version' => '0a10a24d77ed5fdd2bd5bb61fe42189b');

build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/settings.asset.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php return array('dependencies' => array('wp-polyfill'), 'version' => '0b18bb470230f9532065a7cacf482637');

build/settings.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#wp-bootstrap-blocks_settings .constant-notice{font-weight:600}
2+

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
"prettier": "npm:wp-prettier@^2.0.5"
3838
},
3939
"scripts": {
40-
"start": "wp-scripts start",
40+
"start": "wp-scripts start src/index.js src/settings/settings.js",
4141
"dev": "npm run start",
4242
"prebuild": "npm run check-engines",
43-
"build": "wp-scripts build",
43+
"build": "wp-scripts build src/index.js src/settings/settings.js",
4444
"wp-env": "wp-env",
4545
"check-engines": "wp-scripts check-engines",
4646
"check-licenses": "wp-scripts check-licenses",

src/class-wp-bootstrap-blocks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function __construct() {
7979
$this->includes();
8080
$this->init_hooks();
8181
$this->register_block_types();
82-
Settings::init();
82+
Settings::init( $this->assets_dir, $this->assets_url );
8383
}
8484

8585
/**

src/settings/class-settings.php

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ class Settings {
4646
*/
4747
const MENU_SLUG = 'wp-bootstrap-blocks_settings';
4848

49+
/**
50+
* The plugin assets directory.
51+
*
52+
* @var string
53+
*/
54+
public static $assets_dir = '';
55+
56+
/**
57+
* The plugin assets URL.
58+
*
59+
* @var string
60+
*/
61+
public static $assets_url = '';
62+
4963
/**
5064
* True if settings are already initialized.
5165
*
@@ -55,9 +69,15 @@ class Settings {
5569

5670
/**
5771
* Settings constructor.
72+
*
73+
* @param string $assets_dir The plugin assets directory.
74+
* @param string $assets_url The plugin assets URL.
5875
*/
59-
public static function init() {
76+
public static function init( $assets_dir, $assets_url ) {
6077
if ( ! self::$initialized ) {
78+
self::$assets_dir = $assets_dir;
79+
self::$assets_url = $assets_url;
80+
6181
// Add settings page to menu
6282
add_action( 'admin_menu', array( __CLASS__, 'add_menu_item' ) );
6383

@@ -76,10 +96,35 @@ public static function init() {
7696
// Filter saving of bootstrap version
7797
add_filter( 'pre_update_option_' . self::OPTION_PREFIX . 'bootstrap_version', array( __CLASS__, 'pre_update_option_bootstrap_version' ), 10, 2 );
7898

99+
// Enqueue settings stylesheet
100+
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_styles' ) );
101+
79102
self::$initialized = true;
80103
}
81104
}
82105

106+
/**
107+
* Enqueue settings specific styles.
108+
*
109+
* @param string $hook Hook of current screen.
110+
*/
111+
public static function enqueue_styles( $hook ) {
112+
if ( 'settings_page_' . self::MENU_SLUG !== $hook ) {
113+
return;
114+
}
115+
116+
$settings_styles_path = self::$assets_dir . 'settings.css';
117+
$settings_styles_url = esc_url( self::$assets_url ) . 'settings.css';
118+
$settings_asset_file = self::$assets_dir . 'settings.asset.php';
119+
$settings_asset = file_exists( $settings_asset_file )
120+
? require_once $settings_asset_file
121+
: null;
122+
$settings_version = isset( $settings_asset['version'] ) ? $settings_asset['version'] : filemtime( $settings_styles_path );
123+
124+
wp_register_style( self::MENU_SLUG . '_styles', $settings_styles_url, false, $settings_version );
125+
wp_enqueue_style( self::MENU_SLUG . '_styles' );
126+
}
127+
83128
/**
84129
* Add settings page to admin menu.
85130
*/
@@ -112,6 +157,7 @@ public static function register_settings() {
112157
array(
113158
'id' => 'bootstrap_version',
114159
'label' => __( 'Bootstrap Version (experimental)', 'wp-bootstrap-blocks' ),
160+
'description' => __( 'Depending on the selected Bootstrap version the blocks will be rendered accordingly and version specific features will be available in the editor.', 'wp-bootstrap-blocks' ),
115161
'type' => 'select',
116162
'default' => self::BOOTSTRAP_VERSION_DEFAULT_VALUE,
117163
'options' => array(
@@ -284,21 +330,17 @@ public static function display_field( $data = array() ) {
284330
break;
285331

286332
default:
287-
$html .= '<div><span class="description">' . $field['description'] . '</span></div>' . "\n";
333+
$html .= '<p class="description">' . $field['description'] . '</p>' . "\n";
288334
break;
289335
}
290336
}
291337

292338
if ( $is_option_constant_set ) {
293-
$html .= '<div class="constant-notice">' . sprintf(
294-
// translators: %s contains constant name
295-
esc_html_x(
296-
'Option disabled because %s constant is set.',
297-
'%s contains constant name',
339+
$html .= '<p class="description constant-notice">' .
340+
esc_html__(
341+
'Option is defined in the following constant',
298342
'wp-bootstrap-blocks'
299-
),
300-
esc_html( $data['constant_name'] )
301-
) . '</div>' . "\n";
343+
) . ': <code>' . esc_html( $data['constant_name'] ) . '</code></p>' . "\n";
302344
}
303345

304346
// @codingStandardsIgnoreStart

src/settings/settings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './settings.scss';

src/settings/settings.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#wp-bootstrap-blocks_settings {
2+
.constant-notice {
3+
font-weight: 600;
4+
}
5+
}

0 commit comments

Comments
 (0)