diff --git a/inc/rl-collapsible-section-settings.php b/inc/rl-collapsible-section-settings.php new file mode 100644 index 0000000..e3893cb --- /dev/null +++ b/inc/rl-collapsible-section-settings.php @@ -0,0 +1,113 @@ + +
+ 'rl_collapsible_section-default_title_tag' ) + ); + + $default_title_tag_args = array( + 'type' => 'string', + 'default' => 'h2', + 'description' => 'Default tag used for the title of a collapsible section.' + ); + register_setting($settings_page, 'rl_collapsible_section-default_title_tag', $default_title_tag_args); + + add_settings_field( + 'rl_collapsible_section-expand_first_collapsible', + 'Expand First Collapsible', + 'rl_collapsible_section_expand_first_collapsible_callback', + $settings_page, + $settings_section, + array( 'label_for' => 'rl_collapsible_section-expand_first_collapsible' ) + ); + + $expand_first_collapsible_args = array( + 'type' => 'boolean', + 'default' => true, + 'description' => 'Whether or not to expand the first collapsible section.' + ); + register_setting($settings_page, 'rl_collapsible_section-expand_first_collapsible', $expand_first_collapsible_args); +} +add_action( 'admin_init', 'rl_collapsible_section_settings_init' ); + +/** + * Callback function to render settings section html + */ +function rl_collapsible_section_settings_section_main_callback() { + echo ''; +} + +/** + * Callback functions to render settings + */ +function rl_collapsible_section_default_title_tag_callback( $args ) { + $setting_id = 'rl_collapsible_section-default_title_tag'; + $setting_value = esc_attr( get_option( 'rl_collapsible_section-default_title_tag' ) ); + + echo <<{$args[0]}
+setting_html; +} + +function rl_collapsible_section_expand_first_collapsible_callback( $args ) { + $setting_id = 'rl_collapsible_section-expand_first_collapsible'; + $setting_value = esc_attr( get_option( 'rl_collapsible_section-expand_first_collapsible' ) ); + + if ($setting_value) { + $checked = 'checked'; + } else { + $checked = 'unchecked'; + } + + echo <<{$args[0]}
+setting_html; +} diff --git a/rl-collapsible-section.php b/rl-collapsible-section.php index 71fa5b0..9dc6cfb 100644 --- a/rl-collapsible-section.php +++ b/rl-collapsible-section.php @@ -10,6 +10,9 @@ * Version: 0.1.5 */ +// Include our custom settings page for the plugin +require_once plugin_dir_path( __FILE__ ).'/inc/rl-collapsible-section-settings.php'; + // Register styles and scripts to be used later when needed function rl_collapsible_section_register_scripts() { wp_register_style( 'rl-collapsible-section-style', plugin_dir_url( __FILE__ ).'/css/rl-collapsible-section.css', array(), '0.0.7' ); @@ -29,7 +32,7 @@ function rl_collapsible_section_shortcode($atts = [], $content = null) { // override default attributes with user attributes $shortcode_atts = shortcode_atts([ 'title' => 'Collapsible section', - 'title-tag' => 'h1', + 'title-tag' => esc_attr( get_option( 'rl_collapsible_section-default_title_tag', 'h2' ) ), 'collapsed' => 'yes' ], $atts, 'rl_collapsible_section'); @@ -38,9 +41,9 @@ function rl_collapsible_section_shortcode($atts = [], $content = null) { $collapsed = $shortcode_atts['collapsed'] == 'yes'; // Forces the first collapsible section to be expanded - if ($rl_collapsible_section_first_instance) { + $expand_first_collapsible = esc_attr( get_option( 'rl_collapsible_section-expand_first_collapsible', true ) ); + if ($rl_collapsible_section_first_instance && $expand_first_collapsible) { $collapsed = false; - $rl_collapsible_section_first_instance = false; } $collapsible_section_classes = ''; @@ -55,6 +58,9 @@ function rl_collapsible_section_shortcode($atts = [], $content = null) { $output .= "