Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 83 additions & 1 deletion src/css/settings.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@use 'common/editor';

$sections: general, editor, debug;
$sections: general, editor, debug, version-switch;

p.submit {
display: flex;
Expand Down Expand Up @@ -128,3 +128,85 @@ body.js {
.cloud-settings tbody tr:nth-child(n+5) {
display: none;
}

// Version Switch Styles
.code-snippets-version-switch {
.current-version {
font-family: monospace;
font-size: 1.1em;
font-weight: bold;
color: #0073aa;
background: #f0f6fc;
padding: 2px 8px;
border-radius: 3px;
border: 1px solid #c3c4c7;
}

#target_version {
min-width: 200px;
margin-inline-start: 8px;
}

#switch-version-btn {
&[disabled] {
opacity: 0.6;
cursor: not-allowed;
background-color: #f0f0f1 !important;
color: #a7aaad !important;
border-color: #dcdcde !important;
}
}

// Warning box styling
#version-switch-warning {
margin-top: 20px !important;
padding: 12px 16px;
border-left: 4px solid #dba617;
background: #fff8e5;
border-radius: 4px;

p {
margin: 0;
color: #8f6914;

strong {
color: #8f6914;
}
}
}

#version-switch-result {
margin-block-start: 12px;

&.notice {
padding: 8px 12px;
border-radius: 4px;
}
}

.notice {
&.notice-success {
border-left-color: #00a32a;
}

&.notice-error {
border-left-color: #d63638;
}

&.notice-warning {
border-left-color: #dba617;
}

&.notice-info {
border-left-color: #72aee6;
}
}
}

.version-switch-settings {
.form-table {
th {
width: 180px;
}
}
}
1 change: 1 addition & 0 deletions src/php/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function load_plugin() {
// Settings component.
require_once $includes_path . '/settings/settings-fields.php';
require_once $includes_path . '/settings/editor-preview.php';
require_once $includes_path . '/settings/version-switch.php';
require_once $includes_path . '/settings/settings.php';

// Cloud List Table shared functions.
Expand Down
6 changes: 5 additions & 1 deletion src/php/settings/class-setting-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ public function render() {
* Render a callback field.
*/
public function render_callback_field() {
call_user_func( $this->render_callback );
if ( ! is_callable( $this->render_callback ) ) {
return;
}

call_user_func( $this->render_callback, $this->args );
}

/**
Expand Down
21 changes: 21 additions & 0 deletions src/php/settings/settings-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ function get_default_settings(): array {
'keymap' => 'default',
'theme' => 'default',
],
'version-switch' => [
'selected_version' => '',
],
];

$defaults = apply_filters( 'code_snippets_settings_defaults', $defaults );
Expand Down Expand Up @@ -81,6 +84,24 @@ function get_settings_fields(): array {
],
];

$fields['version-switch'] = [
'version_switcher' => [
'name' => __( 'Switch Version', 'code-snippets' ),
'type' => 'callback',
'render_callback' => 'Code_Snippets\Settings\VersionSwitch\render_version_switch_field',
],
'refresh_versions' => [
'name' => __( 'Refresh Versions', 'code-snippets' ),
'type' => 'callback',
'render_callback' => 'Code_Snippets\Settings\VersionSwitch\render_refresh_versions_field',
],
'version_warning' => [
'name' => '',
'type' => 'callback',
'render_callback' => 'Code_Snippets\Settings\VersionSwitch\render_version_switch_warning',
],
];

$fields['general'] = [
'activate_by_default' => [
'name' => __( 'Activate by Default', 'code-snippets' ),
Expand Down
7 changes: 4 additions & 3 deletions src/php/settings/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ function update_setting( string $section, string $field, $new_value ): bool {
*/
function get_settings_sections(): array {
$sections = array(
'general' => __( 'General', 'code-snippets' ),
'editor' => __( 'Code Editor', 'code-snippets' ),
'debug' => __( 'Debug', 'code-snippets' ),
'general' => __( 'General', 'code-snippets' ),
'editor' => __( 'Code Editor', 'code-snippets' ),
'debug' => __( 'Debug', 'code-snippets' ),
'version-switch' => __( 'Version', 'code-snippets' ),
);

return apply_filters( 'code_snippets_settings_sections', $sections );
Expand Down
Loading