← All changes
|
frameworks/codestar-framework/samples/widget-options.php
+182
-182
2.3.4
→
2.4.0
View file →
| @@ -1,182 +1,182 @@ | ||
| 1 | -<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. | |
| 2 | - | |
| 3 | -// | |
| 4 | -// Create a widget 1 | |
| 5 | -// | |
| 6 | -CSF::createWidget( 'csf_widget_example_1', array( | |
| 7 | - 'title' => 'Codestar Widget Example 1', | |
| 8 | - 'classname' => 'csf-widget-classname', | |
| 9 | - 'description' => 'A description for widget example 1', | |
| 10 | - 'fields' => array( | |
| 11 | - | |
| 12 | - array( | |
| 13 | - 'id' => 'title', | |
| 14 | - 'type' => 'text', | |
| 15 | - 'title' => 'Title', | |
| 16 | - ), | |
| 17 | - | |
| 18 | - array( | |
| 19 | - 'id' => 'opt-text', | |
| 20 | - 'type' => 'text', | |
| 21 | - 'title' => 'Text', | |
| 22 | - 'default' => 'Default text value' | |
| 23 | - ), | |
| 24 | - | |
| 25 | - array( | |
| 26 | - 'id' => 'opt-color', | |
| 27 | - 'type' => 'color', | |
| 28 | - 'title' => 'Color', | |
| 29 | - ), | |
| 30 | - | |
| 31 | - array( | |
| 32 | - 'id' => 'opt-upload', | |
| 33 | - 'type' => 'upload', | |
| 34 | - 'title' => 'Upload', | |
| 35 | - ), | |
| 36 | - | |
| 37 | - array( | |
| 38 | - 'id' => 'opt-textarea', | |
| 39 | - 'type' => 'textarea', | |
| 40 | - 'title' => 'Textarea', | |
| 41 | - 'help' => 'The help text of the field.', | |
| 42 | - ), | |
| 43 | - | |
| 44 | - ) | |
| 45 | -) ); | |
| 46 | - | |
| 47 | -// | |
| 48 | -// Front-end display of widget example 1 | |
| 49 | -// Attention: This function named considering above widget base id. | |
| 50 | -// | |
| 51 | -if ( ! function_exists( 'csf_widget_example_1' ) ) { | |
| 52 | - function csf_widget_example_1( $args, $instance ) { | |
| 53 | - | |
| 54 | - echo $args['before_widget']; | |
| 55 | - | |
| 56 | - // if ( ! empty( $instance['title'] ) ) { | |
| 57 | - // echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title']; | |
| 58 | - // } | |
| 59 | - | |
| 60 | - echo '<div style="padding: 20px; background-color: #f7f7f7;">'; | |
| 61 | - echo '<h3>Codestar Widget Example 1</h3>'; | |
| 62 | - echo '<p><strong>Title:</strong> '. $instance['title'] .'</p>'; | |
| 63 | - echo '<p><strong>Text:</strong> '. $instance['opt-text'] .'</p>'; | |
| 64 | - echo '<p><strong>Color:</strong> '. $instance['opt-color'] .'</p>'; | |
| 65 | - echo '<p><strong>Upload:</strong> '. $instance['opt-upload'] .'</p>'; | |
| 66 | - echo '<p><strong>Textarea:</strong> '. $instance['opt-textarea'] .'</p>'; | |
| 67 | - echo '</div>'; | |
| 68 | - | |
| 69 | - echo $args['after_widget']; | |
| 70 | - | |
| 71 | - } | |
| 72 | -} | |
| 73 | - | |
| 74 | -// | |
| 75 | -// Create a widget 2 | |
| 76 | -// | |
| 77 | -CSF::createWidget( 'csf_widget_example_2', array( | |
| 78 | - 'title' => 'Codestar Widget Example 2', | |
| 79 | - 'classname' => 'csf-widget-classname', | |
| 80 | - 'description' => 'A description for widget example 2', | |
| 81 | - 'fields' => array( | |
| 82 | - | |
| 83 | - array( | |
| 84 | - 'id' => 'title', | |
| 85 | - 'type' => 'text', | |
| 86 | - 'title' => 'Title', | |
| 87 | - ), | |
| 88 | - | |
| 89 | - array( | |
| 90 | - 'id' => 'opt-text', | |
| 91 | - 'type' => 'text', | |
| 92 | - 'title' => 'Text', | |
| 93 | - 'default' => 'Default text value' | |
| 94 | - ), | |
| 95 | - | |
| 96 | - array( | |
| 97 | - 'id' => 'opt-color', | |
| 98 | - 'type' => 'color', | |
| 99 | - 'title' => 'Color', | |
| 100 | - ), | |
| 101 | - | |
| 102 | - array( | |
| 103 | - 'id' => 'opt-switcher', | |
| 104 | - 'type' => 'switcher', | |
| 105 | - 'title' => 'Switcher', | |
| 106 | - 'label' => 'The label text of the switcher.', | |
| 107 | - ), | |
| 108 | - | |
| 109 | - array( | |
| 110 | - 'id' => 'opt-checkbox', | |
| 111 | - 'type' => 'checkbox', | |
| 112 | - 'title' => 'Checkbox', | |
| 113 | - 'label' => 'The label text of the checkbox.', | |
| 114 | - ), | |
| 115 | - | |
| 116 | - array( | |
| 117 | - 'id' => 'opt-select', | |
| 118 | - 'type' => 'select', | |
| 119 | - 'title' => 'Select', | |
| 120 | - 'placeholder' => 'Select an option', | |
| 121 | - 'options' => array( | |
| 122 | - 'opt-1' => 'Option 1', | |
| 123 | - 'opt-2' => 'Option 2', | |
| 124 | - 'opt-3' => 'Option 3', | |
| 125 | - ), | |
| 126 | - ), | |
| 127 | - | |
| 128 | - array( | |
| 129 | - 'id' => 'opt-radio', | |
| 130 | - 'type' => 'radio', | |
| 131 | - 'title' => 'Radio', | |
| 132 | - 'options' => array( | |
| 133 | - 'yes' => 'Yes, Please.', | |
| 134 | - 'no' => 'No, Thank you.', | |
| 135 | - ), | |
| 136 | - 'default' => 'yes', | |
| 137 | - ), | |
| 138 | - array( | |
| 139 | - 'type' => 'notice', | |
| 140 | - 'style' => 'success', | |
| 141 | - 'content' => 'A <strong>notice</strong> field with <strong>success</strong> style.', | |
| 142 | - ), | |
| 143 | - | |
| 144 | - array( | |
| 145 | - 'id' => 'opt-textarea', | |
| 146 | - 'type' => 'textarea', | |
| 147 | - 'title' => 'Textarea', | |
| 148 | - 'help' => 'The help text of the field.', | |
| 149 | - ), | |
| 150 | - | |
| 151 | - ) | |
| 152 | -) ); | |
| 153 | - | |
| 154 | -// | |
| 155 | -// Front-end display of widget example 2 | |
| 156 | -// Attention: This function named considering above widget base id. | |
| 157 | -// | |
| 158 | -if ( ! function_exists( 'csf_widget_example_2' ) ) { | |
| 159 | - function csf_widget_example_2( $args, $instance ) { | |
| 160 | - | |
| 161 | - echo $args['before_widget']; | |
| 162 | - | |
| 163 | - // if ( ! empty( $instance['title'] ) ) { | |
| 164 | - // echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title']; | |
| 165 | - // } | |
| 166 | - | |
| 167 | - echo '<div style="padding: 20px; background-color: #f7f7f7;">'; | |
| 168 | - echo '<h3>Codestar Widget Example 2</h3>'; | |
| 169 | - echo '<p><strong>Title:</strong> '. $instance['title'] .'</p>'; | |
| 170 | - echo '<p><strong>Text:</strong> '. $instance['opt-text'] .'</p>'; | |
| 171 | - echo '<p><strong>Color:</strong> '. $instance['opt-color'] .'</p>'; | |
| 172 | - echo '<p><strong>Switcher:</strong> '. $instance['opt-switcher'] .'</p>'; | |
| 173 | - echo '<p><strong>Checkbox:</strong> '. $instance['opt-checkbox'] .'</p>'; | |
| 174 | - echo '<p><strong>Select:</strong> '. $instance['opt-select'] .'</p>'; | |
| 175 | - echo '<p><strong>Radio:</strong> '. $instance['opt-radio'] .'</p>'; | |
| 176 | - echo '<p><strong>Textarea:</strong> '. $instance['opt-textarea'] .'</p>'; | |
| 177 | - echo '</div>'; | |
| 178 | - | |
| 179 | - echo $args['after_widget']; | |
| 180 | - | |
| 181 | - } | |
| 182 | -} | |
| 1 | +<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. | |
| 2 | + | |
| 3 | +// | |
| 4 | +// Create a widget 1 | |
| 5 | +// | |
| 6 | +CSF::createWidget( 'csf_widget_example_1', array( | |
| 7 | + 'title' => 'Codestar Widget Example 1', | |
| 8 | + 'classname' => 'csf-widget-classname', | |
| 9 | + 'description' => 'A description for widget example 1', | |
| 10 | + 'fields' => array( | |
| 11 | + | |
| 12 | + array( | |
| 13 | + 'id' => 'title', | |
| 14 | + 'type' => 'text', | |
| 15 | + 'title' => 'Title', | |
| 16 | + ), | |
| 17 | + | |
| 18 | + array( | |
| 19 | + 'id' => 'opt-text', | |
| 20 | + 'type' => 'text', | |
| 21 | + 'title' => 'Text', | |
| 22 | + 'default' => 'Default text value' | |
| 23 | + ), | |
| 24 | + | |
| 25 | + array( | |
| 26 | + 'id' => 'opt-color', | |
| 27 | + 'type' => 'color', | |
| 28 | + 'title' => 'Color', | |
| 29 | + ), | |
| 30 | + | |
| 31 | + array( | |
| 32 | + 'id' => 'opt-upload', | |
| 33 | + 'type' => 'upload', | |
| 34 | + 'title' => 'Upload', | |
| 35 | + ), | |
| 36 | + | |
| 37 | + array( | |
| 38 | + 'id' => 'opt-textarea', | |
| 39 | + 'type' => 'textarea', | |
| 40 | + 'title' => 'Textarea', | |
| 41 | + 'help' => 'The help text of the field.', | |
| 42 | + ), | |
| 43 | + | |
| 44 | + ) | |
| 45 | +) ); | |
| 46 | + | |
| 47 | +// | |
| 48 | +// Front-end display of widget example 1 | |
| 49 | +// Attention: This function named considering above widget base id. | |
| 50 | +// | |
| 51 | +if ( ! function_exists( 'csf_widget_example_1' ) ) { | |
| 52 | + function csf_widget_example_1( $args, $instance ) { | |
| 53 | + | |
| 54 | + echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 55 | + | |
| 56 | + // if ( ! empty( $instance['title'] ) ) { | |
| 57 | + // echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title']; | |
| 58 | + // } | |
| 59 | + | |
| 60 | + echo '<div style="padding: 20px; background-color: #f7f7f7;">'; | |
| 61 | + echo '<h3>Codestar Widget Example 1</h3>'; | |
| 62 | + echo '<p><strong>Title:</strong> '. esc_html( $instance['title'] ) .'</p>'; | |
| 63 | + echo '<p><strong>Text:</strong> '. esc_html( $instance['opt-text'] ) .'</p>'; | |
| 64 | + echo '<p><strong>Color:</strong> '. esc_attr( $instance['opt-color'] ) .'</p>'; | |
| 65 | + echo '<p><strong>Upload:</strong> '. esc_url( $instance['opt-upload'] ) .'</p>'; | |
| 66 | + echo '<p><strong>Textarea:</strong> '. wp_kses_post( $instance['opt-textarea'] ) .'</p>'; | |
| 67 | + echo '</div>'; | |
| 68 | + | |
| 69 | + echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 70 | + | |
| 71 | + } | |
| 72 | +} | |
| 73 | + | |
| 74 | +// | |
| 75 | +// Create a widget 2 | |
| 76 | +// | |
| 77 | +CSF::createWidget( 'csf_widget_example_2', array( | |
| 78 | + 'title' => 'Codestar Widget Example 2', | |
| 79 | + 'classname' => 'csf-widget-classname', | |
| 80 | + 'description' => 'A description for widget example 2', | |
| 81 | + 'fields' => array( | |
| 82 | + | |
| 83 | + array( | |
| 84 | + 'id' => 'title', | |
| 85 | + 'type' => 'text', | |
| 86 | + 'title' => 'Title', | |
| 87 | + ), | |
| 88 | + | |
| 89 | + array( | |
| 90 | + 'id' => 'opt-text', | |
| 91 | + 'type' => 'text', | |
| 92 | + 'title' => 'Text', | |
| 93 | + 'default' => 'Default text value' | |
| 94 | + ), | |
| 95 | + | |
| 96 | + array( | |
| 97 | + 'id' => 'opt-color', | |
| 98 | + 'type' => 'color', | |
| 99 | + 'title' => 'Color', | |
| 100 | + ), | |
| 101 | + | |
| 102 | + array( | |
| 103 | + 'id' => 'opt-switcher', | |
| 104 | + 'type' => 'switcher', | |
| 105 | + 'title' => 'Switcher', | |
| 106 | + 'label' => 'The label text of the switcher.', | |
| 107 | + ), | |
| 108 | + | |
| 109 | + array( | |
| 110 | + 'id' => 'opt-checkbox', | |
| 111 | + 'type' => 'checkbox', | |
| 112 | + 'title' => 'Checkbox', | |
| 113 | + 'label' => 'The label text of the checkbox.', | |
| 114 | + ), | |
| 115 | + | |
| 116 | + array( | |
| 117 | + 'id' => 'opt-select', | |
| 118 | + 'type' => 'select', | |
| 119 | + 'title' => 'Select', | |
| 120 | + 'placeholder' => 'Select an option', | |
| 121 | + 'options' => array( | |
| 122 | + 'opt-1' => 'Option 1', | |
| 123 | + 'opt-2' => 'Option 2', | |
| 124 | + 'opt-3' => 'Option 3', | |
| 125 | + ), | |
| 126 | + ), | |
| 127 | + | |
| 128 | + array( | |
| 129 | + 'id' => 'opt-radio', | |
| 130 | + 'type' => 'radio', | |
| 131 | + 'title' => 'Radio', | |
| 132 | + 'options' => array( | |
| 133 | + 'yes' => 'Yes, Please.', | |
| 134 | + 'no' => 'No, Thank you.', | |
| 135 | + ), | |
| 136 | + 'default' => 'yes', | |
| 137 | + ), | |
| 138 | + array( | |
| 139 | + 'type' => 'notice', | |
| 140 | + 'style' => 'success', | |
| 141 | + 'content' => 'A <strong>notice</strong> field with <strong>success</strong> style.', | |
| 142 | + ), | |
| 143 | + | |
| 144 | + array( | |
| 145 | + 'id' => 'opt-textarea', | |
| 146 | + 'type' => 'textarea', | |
| 147 | + 'title' => 'Textarea', | |
| 148 | + 'help' => 'The help text of the field.', | |
| 149 | + ), | |
| 150 | + | |
| 151 | + ) | |
| 152 | +) ); | |
| 153 | + | |
| 154 | +// | |
| 155 | +// Front-end display of widget example 2 | |
| 156 | +// Attention: This function named considering above widget base id. | |
| 157 | +// | |
| 158 | +if ( ! function_exists( 'csf_widget_example_2' ) ) { | |
| 159 | + function csf_widget_example_2( $args, $instance ) { | |
| 160 | + | |
| 161 | + echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 162 | + | |
| 163 | + // if ( ! empty( $instance['title'] ) ) { | |
| 164 | + // echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title']; | |
| 165 | + // } | |
| 166 | + | |
| 167 | + echo '<div style="padding: 20px; background-color: #f7f7f7;">'; | |
| 168 | + echo '<h3>Codestar Widget Example 2</h3>'; | |
| 169 | + echo '<p><strong>Title:</strong> '. esc_html( $instance['title'] ) .'</p>'; | |
| 170 | + echo '<p><strong>Text:</strong> '. esc_html( $instance['opt-text'] ) .'</p>'; | |
| 171 | + echo '<p><strong>Color:</strong> '. esc_attr( $instance['opt-color'] ) .'</p>'; | |
| 172 | + echo '<p><strong>Switcher:</strong> '. esc_html( $instance['opt-switcher'] ) .'</p>'; | |
| 173 | + echo '<p><strong>Checkbox:</strong> '. esc_html( $instance['opt-checkbox'] ) .'</p>'; | |
| 174 | + echo '<p><strong>Select:</strong> '. esc_html( $instance['opt-select'] ) .'</p>'; | |
| 175 | + echo '<p><strong>Radio:</strong> '. esc_html( $instance['opt-radio'] ) .'</p>'; | |
| 176 | + echo '<p><strong>Textarea:</strong> '. wp_kses_post( $instance['opt-textarea'] ) .'</p>'; | |
| 177 | + echo '</div>'; | |
| 178 | + | |
| 179 | + echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 180 | + | |
| 181 | + } | |
| 182 | +} | |