JFIF $ d d 7 * Z qn )ZP 0 !1 A "#a$2Qr D8 a Ri [f \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H ~ , l s / 9 ć: [=/#f ; ) x { ٛE Q )~ = 𘙲r*2~ a _V = ' ku m F D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq 1dđ #̩ ͑ 0 ; H ] u 搂 @:~ ו K L N s h } O I R* 8 :2 ! lD JV o ( 3 = M ( z Ȱ+i *N A r6K n S l ) ! J J Ӂ* % ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c P A\IL Nj! J ۱+ O\ ͔ ] ޒ S J ȧ c%A N ol ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0 'G=i 2N +0 e 2 ]] 9 VT P O 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P < 0 x < !1AQ "Raq 02Br #S CTb ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV YT D I 6 2 '8Y2 7'\T P.6 d &˦ @V q i |8 -O Ε ] ʔ U= T L 8= ;6c | !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U#6w + +s &r+n ڐ { @ 29gL u " T Ù M=6 (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 ! OS r D 5 7 % | ?x> L | / nD 6?/8 w # [ ) L 7 +6〼T A T g ! %5 Mm Z /c -{1_Je "| ^$ 'O & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@ u6 BԒ i YN * f 0 _ GhKW u lT <nj- 0{ M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q $ H8o Q˼EV ~ k 0 h' L Pp M -M" m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @~p # !1QAa q ? AL0L x LU 4 d ; x " 16ad0 7.\ߋ 0 = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X &Q З non]я u ג./ ; gZ$ M QР 2M ]h ni 0 P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _ 1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3 6 #Ik+ v { v i ( ވ ? a e) X xy/*@Q Ǽ Ծ ) $ IWO l c G; !i k{ gOŀ L ('x T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ) X 5 c QɎMy W ? Q *!R > 6=7)Xj 5`J ] e 8%t ! + ' ! 1Q 5 !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $ v , ,m 㵜5u bV =sY+ @d { N ! dn O < .- B; _w J t 6;Q Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш e黅X ۢ F :)[ F G X ƹ / w _c MeD ,ʡc c . W D tA $ j@ : ) - #u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P 6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L ! ~ y5 g9T̅J kbM' +s :S +B) v @ M j e C f j E 0 Y\Qn z G 1 д~ W o{T 9?` Rm yhsy3 !HAD ] m c1 ~ 2 L S u7x T ;j$ `} 4-> L# vzŏ I L S ֭ T { r jGK C ; b pU= - ` Bs K. S F w4 M q] Z dH S 0 ) tLg
<?php
namespace Code_Snippets\Admin\Menus;
use Code_Snippets\Settings\Settings_Fields;
use function Code_Snippets\code_snippets;
use function Code_Snippets\Settings\are_settings_unified;
use function Code_Snippets\Utils\enqueue_code_editor;
use function Code_Snippets\Utils\get_editor_themes;
use const Code_Snippets\PLUGIN_FILE;
use const Code_Snippets\PLUGIN_VERSION;
use const Code_Snippets\Settings\OPTION_GROUP;
use const Code_Snippets\Settings\OPTION_NAME;
use const Code_Snippets\Settings\CACHE_KEY;
/**
* This class handles the settings admin menu.
*
* @package Code_Snippets
*/
class Settings_Menu extends Admin_Menu {
/**
* Settings page name as registered with the Settings API.
*/
public const SETTINGS_PAGE = 'code-snippets';
/**
* Constructor.
*/
public function __construct() {
parent::__construct(
'settings',
_x( 'Settings', 'menu label', 'code-snippets' ),
__( 'Snippets Settings', 'code-snippets' )
);
}
/**
* Executed when the admin page is loaded
*/
public function load() {
parent::load();
if ( is_network_admin() ) {
if ( are_settings_unified() ) {
$this->update_network_options();
} else {
wp_safe_redirect( code_snippets()->get_menu_url( 'settings', 'admin' ) );
exit;
}
}
}
/**
* Enqueue the stylesheet for the settings menu
*/
public function enqueue_assets() {
$this->enqueue_codemirror();
$handle = 'code-snippets-settings';
wp_enqueue_style(
$handle,
plugins_url( 'dist/settings.css', PLUGIN_FILE ),
array_merge( self::$style_deps, [ 'code-editor' ] ),
PLUGIN_VERSION
);
wp_enqueue_script(
$handle,
plugins_url( 'dist/settings.js', PLUGIN_FILE ),
array_merge( self::$script_deps, [ 'code-snippets-code-editor' ] ),
PLUGIN_VERSION,
true
);
wp_set_script_translations( $handle, 'code-snippets' );
code_snippets()->localize_script( $handle );
$this->add_codemirror_settings_script( $handle );
// Provide configuration and simple i18n for the version switch JS module.
wp_localize_script(
$handle,
'code_snippets_version_switch',
[
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce_switch' => wp_create_nonce( 'code_snippets_version_switch' ),
'nonce_refresh' => wp_create_nonce( 'code_snippets_refresh_versions' ),
]
);
wp_localize_script(
$handle,
'__code_snippets_i18n',
[
'selectDifferent' => esc_html__( 'Please select a different version to switch to.', 'code-snippets' ),
'switching' => esc_html__( 'Switching…', 'code-snippets' ),
'processing' => esc_html__( 'Processing version switch. Please wait…', 'code-snippets' ),
'error' => esc_html__( 'An error occurred.', 'code-snippets' ),
'errorSwitch' => esc_html__( 'An error occurred while switching versions. Please try again.', 'code-snippets' ),
'refreshing' => esc_html__( 'Refreshing…', 'code-snippets' ),
'refreshed' => esc_html__( 'Refreshed!', 'code-snippets' ),
]
);
}
/**
* Enqueue the CodeMirror scripts and styles, including all themes.
*
* @return void
*/
protected function enqueue_codemirror() {
enqueue_code_editor( 'php' );
$themes = get_editor_themes();
foreach ( $themes as $theme ) {
wp_enqueue_style(
'code-snippets-editor-theme-' . $theme,
plugins_url( "dist/editor-themes/$theme.css", PLUGIN_FILE ),
[ 'code-editor' ],
PLUGIN_VERSION
);
}
}
/**
* Load the CodeMirror settings as an inline script variable.
*
* @param string $handle The handle of the script to which the settings will be added.
*
* @return void
*/
protected function add_codemirror_settings_script( string $handle ) {
$field_definitions = Settings_Fields::get_field_definitions();
$editor_fields = [];
foreach ( $field_definitions['editor'] as $name => $field ) {
if ( empty( $field['codemirror'] ) ) {
continue;
}
$editor_fields[] = [
'name' => $name,
'type' => $field['type'],
'codemirror' => addslashes( $field['codemirror'] ),
];
}
// Pass the saved options to the external JavaScript file.
$inline_script = 'var code_snippets_editor_settings = ' . wp_json_encode( $editor_fields ) . ';';
wp_add_inline_script( $handle, $inline_script, 'before' );
}
/**
* Retrieve the list of settings sections.
*
* @return array<string, array<string, mixed>>
*/
private function get_sections(): array {
global $wp_settings_sections;
if ( ! isset( $wp_settings_sections[ self::SETTINGS_PAGE ] ) ) {
return array();
}
return (array) $wp_settings_sections[ self::SETTINGS_PAGE ];
}
/**
* Retrieve the name of the settings section currently being viewed.
*
* @param string $default_section Name of the default tab displayed.
*
* @return string
*/
public function get_current_section( string $default_section = 'general' ): string {
$sections = $this->get_sections();
if ( ! $sections ) {
return $default_section;
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Value is matched to registered sections.
$active_tab = isset( $_REQUEST['section'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['section'] ) ) : $default_section;
return isset( $sections[ $active_tab ] ) ? $active_tab : $default_section;
}
/**
* Render the admin screen
*/
public function render() {
$this->render_navigation();
$update_url = is_network_admin() ? add_query_arg( 'update_site_option', true ) : admin_url( 'options.php' );
$current_section = $this->get_current_section();
?>
<div class="wrap code-snippets-settings" data-active-tab="<?php echo esc_attr( $current_section ); ?>">
<?php $this->render_section_tabs(); ?>
<div class="snippets-page-header">
<h1><?php esc_html_e( 'Snippets Settings', 'code-snippets' ); ?></h1>
</div>
<?php
if ( code_snippets()->is_compact_menu() ) {
$actions = [
_x( 'Manage', 'snippets', 'code-snippets' ) => code_snippets()->get_menu_url(),
_x( 'Add New', 'snippet', 'code-snippets' ) => code_snippets()->get_menu_url( 'add' ),
_x( 'Import', 'snippets', 'code-snippets' ) => code_snippets()->get_menu_url( 'import' ),
];
echo '<p class="settings-page-actions">';
foreach ( $actions as $label => $url ) {
printf(
'<a href="%s" class="page-title-action">%s</a>',
esc_url( $url ),
esc_html( $label )
);
}
echo '</p>';
}
?>
<hr class="wp-header-end" />
<?php settings_errors( OPTION_NAME ); ?>
<form action="<?php echo esc_url( $update_url ); ?>" method="post">
<input type="hidden" name="section" value="<?php echo esc_attr( $current_section ); ?>">
<?php
settings_fields( OPTION_GROUP );
$this->render_settings_sections();
?>
<p class="submit">
<?php
submit_button( null, 'primary', 'submit', false );
submit_button(
__( 'Reset to Default', 'code-snippets' ),
'secondary',
sprintf( '%s[%s]', OPTION_NAME, 'reset_settings' ),
false
);
?>
</p>
</form>
</div>
<?php
}
/**
* Output the settings section subnavigation bar, styled to match the
* subnavigation on the snippet management pages, followed by the slot
* that adopts the Screen Options and Help tabs.
*/
protected function render_section_tabs() {
$sections = $this->get_sections();
$active_tab = $this->get_current_section();
echo '<div class="snippet-type-nav-wrapper settings-type-nav-wrapper"><nav class="snippet-type-nav settings-type-nav" id="settings-sections-tabs" aria-label="' . esc_attr__( 'Settings tabs', 'code-snippets' ) . '"><ul>';
foreach ( $sections as $section ) {
printf(
'<li><a class="snippet-type-link%s" data-section="%s" href="%s"><span>%s</span></a></li>',
esc_attr( $active_tab ) === $section['id'] ? ' active-type' : '',
esc_attr( $section['id'] ),
esc_url( add_query_arg( 'section', $section['id'] ) ),
esc_html( $section['title'] )
);
}
echo '</ul></nav></div>';
echo '<div id="snippets-screen-meta-slot" class="snippets-screen-meta-slot"></div>';
}
/**
* Output snippet settings sections.
*/
protected function render_settings_sections() {
$sections = $this->get_sections();
foreach ( $sections as $section ) {
if ( 'license' === $section['id'] ) {
continue;
}
if ( $section['title'] ) {
printf(
'<h2 id="%s-settings" class="settings-section-title">%s</h2>' . "\n",
esc_attr( $section['id'] ),
esc_html( $section['title'] )
);
}
if ( $section['callback'] ) {
call_user_func( $section['callback'], $section );
}
printf( '<div class="settings-section %s-settings"><table class="form-table">', esc_attr( $section['id'] ) );
do_settings_fields( self::SETTINGS_PAGE, $section['id'] );
echo '</table></div>';
}
}
/**
* Fill in for the Settings API in the Network Admin
*/
public function update_network_options() {
// Ensure the settings have been saved.
if ( empty( $_GET['update_site_option'] ) || empty( $_POST[ OPTION_NAME ] ) ) {
return;
}
check_admin_referer( 'code-snippets-options' );
// Retrieve the saved options and save them to the database.
$value = map_deep( wp_unslash( $_POST[ OPTION_NAME ] ), 'sanitize_key' );
update_site_option( OPTION_NAME, $value );
wp_cache_delete( CACHE_KEY );
// Add an updated notice.
if ( ! count( get_settings_errors() ) ) {
add_settings_error( 'general', 'settings_updated', __( 'Settings saved.', 'code-snippets' ), 'updated' );
}
set_transient( 'settings_errors', get_settings_errors(), 30 );
// Redirect back to the settings menu.
$redirect = add_query_arg( 'settings-updated', 'true', remove_query_arg( 'update_site_option', wp_get_referer() ) );
wp_safe_redirect( esc_url_raw( $redirect ) );
exit;
}
}