| 1 | <?php |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 2 | /** |
||
|
0 ignored issues
–
show
|
|||
| 3 | * @author Podlove <[email protected]> |
||
| 4 | * @copyright Copyright (c) 2014-2018, Podlove |
||
| 5 | * @license https://github.com/podlove/podlove-subscribe-button-wp-plugin/blob/master/LICENSE MIT |
||
| 6 | * @package Podlove\PodloveSubscribeButton |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace PodloveSubscribeButton; |
||
| 10 | |||
| 11 | class Options { |
||
|
0 ignored issues
–
show
|
|||
| 12 | |||
| 13 | public static function register_settings() { |
||
|
0 ignored issues
–
show
|
|||
| 14 | |||
| 15 | $args = array( |
||
| 16 | 'description' => '', |
||
| 17 | 'sanitize_callback' => array( __CLASS__, 'sanitize_settings' ), |
||
| 18 | ); |
||
| 19 | |||
| 20 | register_setting( |
||
| 21 | 'podlove-psb', |
||
| 22 | 'podlove_psb_defaults', |
||
| 23 | $args |
||
| 24 | ); |
||
| 25 | |||
| 26 | add_settings_section( |
||
| 27 | 'podlove-psb-defaults', |
||
| 28 | __( 'Default Settings', 'podlove-subscribe-button' ), |
||
| 29 | '__return_empty_string', |
||
| 30 | 'podlove-psb' |
||
| 31 | ); |
||
| 32 | |||
| 33 | add_settings_field( |
||
| 34 | 'size', |
||
| 35 | __( 'Size', 'podlove-subscribe-button' ), |
||
| 36 | array( __CLASS__, 'field' ), |
||
| 37 | 'podlove-psb', |
||
| 38 | 'podlove-psb-defaults', |
||
| 39 | array( |
||
| 40 | 'label_for' => 'size', |
||
| 41 | 'type' => 'select', |
||
| 42 | ) |
||
| 43 | ); |
||
| 44 | |||
| 45 | add_settings_field( |
||
| 46 | 'autowidth', |
||
| 47 | __( 'Autowidth', 'podlove-subscribe-button' ), |
||
| 48 | array( __CLASS__, 'field' ), |
||
| 49 | 'podlove-psb', |
||
| 50 | 'podlove-psb-defaults', |
||
| 51 | array( |
||
| 52 | 'label_for' => 'autowidth', |
||
| 53 | 'type' => 'checkbox', |
||
| 54 | ) |
||
| 55 | ); |
||
| 56 | |||
| 57 | add_settings_field( |
||
| 58 | 'color', |
||
| 59 | __( 'Color', 'podlove-subscribe-button' ), |
||
| 60 | array( __CLASS__, 'field' ), |
||
| 61 | 'podlove-psb', |
||
| 62 | 'podlove-psb-defaults', |
||
| 63 | array( |
||
| 64 | 'label_for' => 'color', |
||
| 65 | 'type' => 'color', |
||
| 66 | ) |
||
| 67 | ); |
||
| 68 | |||
| 69 | add_settings_field( |
||
| 70 | 'style', |
||
| 71 | __( 'Style', 'podlove-subscribe-button' ), |
||
| 72 | array( __CLASS__, 'field' ), |
||
| 73 | 'podlove-psb', |
||
| 74 | 'podlove-psb-defaults', |
||
| 75 | array( |
||
| 76 | 'label_for' => 'style', |
||
| 77 | 'type' => 'select', |
||
| 78 | ) |
||
| 79 | ); |
||
| 80 | |||
| 81 | add_settings_field( |
||
| 82 | 'format', |
||
| 83 | __( 'Format', 'podlove-subscribe-button' ), |
||
| 84 | array( __CLASS__, 'field' ), |
||
| 85 | 'podlove-psb', |
||
| 86 | 'podlove-psb-defaults', |
||
| 87 | array( |
||
| 88 | 'label_for' => 'format', |
||
| 89 | 'type' => 'select', |
||
| 90 | ) |
||
| 91 | ); |
||
| 92 | |||
| 93 | add_settings_field( |
||
| 94 | 'language', |
||
| 95 | __( 'Language', 'podlove-subscribe-button' ), |
||
| 96 | array( __CLASS__, 'field' ), |
||
| 97 | 'podlove-psb', |
||
| 98 | 'podlove-psb-defaults', |
||
| 99 | array( |
||
| 100 | 'label_for' => 'language', |
||
| 101 | 'type' => 'language', |
||
| 102 | ) |
||
| 103 | ); |
||
| 104 | |||
| 105 | } |
||
| 106 | |||
| 107 | public static function field( $args ) { |
||
|
0 ignored issues
–
show
|
|||
| 108 | |||
| 109 | if ( is_network_admin() ) { |
||
| 110 | $option = get_site_option( 'podlove_psb_defaults' ); |
||
| 111 | } else { |
||
| 112 | $option = get_option( 'podlove_psb_defaults' ); |
||
| 113 | } |
||
| 114 | |||
| 115 | switch ( $args['type'] ) { |
||
| 116 | case 'checkbox': |
||
| 117 | ?> |
||
| 118 | <input type="checkbox" name="<?php echo "podlove_psb_defaults[{$args['label_for']}]"; ?>" |
||
|
0 ignored issues
–
show
|
|||
| 119 | id="<?php echo "podlove_psb_defaults[{$args['label_for']}]"; ?>" <?php checked( $option[ $args['label_for'] ], 'on' ); ?> /> |
||
|
0 ignored issues
–
show
|
|||
| 120 | <?php |
||
| 121 | break; |
||
| 122 | |||
| 123 | case 'color': |
||
| 124 | ?> |
||
| 125 | <input id="podlove_psb_defaults[color]" name="podlove_psb_defaults[color]" class="podlove_subscribe_button_color" |
||
| 126 | value="<?php echo $option['color'] ?>"/> |
||
|
0 ignored issues
–
show
|
|||
| 127 | <?php |
||
| 128 | break; |
||
| 129 | |||
| 130 | case 'language': |
||
| 131 | ?> |
||
| 132 | <select name="podlove_psb_defaults[language]" id="podlove_psb_defaults[language]"> |
||
| 133 | <?php foreach ( Defaults::button( 'language' ) as $value ) : ?> |
||
| 134 | <option value="<?php echo $value; ?>" <?php selected( $option['language'], $value ); ?>><?php echo $value; ?></option> |
||
| 135 | <?php endforeach; ?> |
||
| 136 | </select> |
||
| 137 | <?php |
||
| 138 | break; |
||
| 139 | |||
|
0 ignored issues
–
show
|
|||
| 140 | |||
| 141 | case 'select': |
||
| 142 | ?> |
||
| 143 | <select name="podlove_psb_defaults[<?php echo $args['label_for']; ?>]" id="podlove_psb_defaults[<?php echo $args['label_for']; ?>]"> |
||
|
0 ignored issues
–
show
|
|||
| 144 | <?php foreach ( Defaults::button( $args['label_for'] ) as $value => $description ) { ?> |
||
| 145 | <option value="<?php echo $value; ?>" <?php selected( $option[ $args['label_for'] ], $value ); ?>><?php echo $description; ?></option> |
||
|
0 ignored issues
–
show
|
|||
| 146 | <?php } ?> |
||
| 147 | </select> |
||
| 148 | <?php break; |
||
|
0 ignored issues
–
show
|
|||
| 149 | |||
| 150 | } |
||
| 151 | } |
||
|
0 ignored issues
–
show
|
|||
| 152 | |||
| 153 | public static function sanitize_settings( $input = null ) { |
||
|
0 ignored issues
–
show
|
|||
| 154 | |||
| 155 | $output = $input; |
||
| 156 | |||
| 157 | if ( ! array_key_exists('autowidth', $input ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 158 | $output['autowidth'] = 'off'; |
||
| 159 | } |
||
| 160 | |||
| 161 | return $output; |
||
| 162 | } |
||
|
0 ignored issues
–
show
|
|||
| 163 | |||
| 164 | } // END class |
||
| 165 |