Skip to content

Commit c65544d

Browse files
committed
Setting of type WYSIWYG editor added
1 parent d17f278 commit c65544d

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

class-cliowp-settings-page.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,20 @@ public function add_settings() {
326326
)
327327
);
328328

329+
// MultiSelect field --------------------------------------------------.
330+
add_settings_field(
331+
'cliowp_sp_multiselect1',
332+
__( 'MultiSelect1 Label', 'cliowp-settings-page' ),
333+
array( $this, 'multiselect1_html' ),
334+
$this->menu_slug,
335+
'cliowp_settings_page_section2'
336+
);
337+
338+
register_setting(
339+
$this->option_group,
340+
'cliowp_sp_multiselect1',
341+
);
342+
329343
// Textarea field -----------------------------------------------------.
330344
add_settings_field(
331345
'cliowp_sp_textarea1',
@@ -361,6 +375,23 @@ public function add_settings() {
361375
'cliowp_sp_color1',
362376
);
363377

378+
// WYSIWYG editor field -----------------------------------------------.
379+
add_settings_field(
380+
'cliowp_sp_editor1',
381+
__( 'Editor1 Label', 'cliowp-settings-page' ),
382+
array( $this, 'editor1_html' ),
383+
$this->menu_slug,
384+
'cliowp_settings_page_section2',
385+
);
386+
387+
register_setting(
388+
$this->option_group,
389+
'cliowp_sp_editor1',
390+
array(
391+
'sanitize_callback' => 'wp_kses_post',
392+
)
393+
);
394+
364395
}
365396

366397
/**
@@ -486,6 +517,41 @@ public function checkbox1_html() {
486517
<?php
487518
}
488519

520+
/**
521+
* Create HTML for multiselect1 field
522+
*/
523+
public function multiselect1_html() {
524+
$selected_values = get_option( 'cliowp_sp_multiselect1' );
525+
?>
526+
<select name="cliowp_sp_multiselect1[]" multiple>
527+
<option value="1" <?php echo esc_html( $this->cliowp_multiselected( $selected_values, '1' ) ); ?>><?php esc_attr_e( 'MultiSelect Option1', 'cliowp-settings-page' ); ?></option>
528+
<option value="2" <?php echo esc_html( $this->cliowp_multiselected( $selected_values, '2' ) ); ?>><?php esc_attr_e( 'MultiSelect Option2', 'cliowp-settings-page' ); ?></option>
529+
<option value="3" <?php echo esc_html( $this->cliowp_multiselected( $selected_values, '3' ) ); ?>><?php esc_attr_e( 'MultiSelect Option3', 'cliowp-settings-page' ); ?></option>
530+
<option value="4" <?php echo esc_html( $this->cliowp_multiselected( $selected_values, '4' ) ); ?>><?php esc_attr_e( 'MultiSelect Option4', 'cliowp-settings-page' ); ?></option>
531+
<option value="5" <?php echo esc_html( $this->cliowp_multiselected( $selected_values, '5' ) ); ?>><?php esc_attr_e( 'MultiSelect Option5', 'cliowp-settings-page' ); ?></option>
532+
</select>
533+
<?php
534+
}
535+
536+
/**
537+
* Utility function to check if value is selected
538+
*
539+
* @param array|string $selected_values Array (or empty string) returned by get_option().
540+
* @param string $current_value Value to check if it is selected.
541+
*
542+
* @return string
543+
*/
544+
private function cliowp_multiselected(
545+
$selected_values,
546+
string $current_value
547+
): string {
548+
if ( is_array( $selected_values ) && in_array( $current_value, $selected_values, true ) ) {
549+
return 'selected';
550+
}
551+
552+
return '';
553+
}
554+
489555
/**
490556
* Create HTML for textarea1 field
491557
*
@@ -509,6 +575,16 @@ public function color1_html() {
509575
<?php
510576
}
511577

578+
/**
579+
* Create HTML for editor1 field
580+
*/
581+
public function editor1_html() {
582+
wp_editor(
583+
wp_kses_post( get_option( 'cliowp_sp_editor1' ) ),
584+
'cliowp_sp_editor1',
585+
);
586+
}
587+
512588
/**
513589
* Create Settings Page HTML
514590
*/

0 commit comments

Comments
 (0)