admin
9 years ago
plugins
9 years ago
widget
9 years ago
fixes-archive.php
9 years ago
fixes-archives.php
9 years ago
fixes-calendar.php
9 years ago
fixes-dates.php
9 years ago
fixes-misc.php
9 years ago
fixes-permalinks.php
9 years ago
general.php
9 years ago
install.php
9 years ago
parsidate.php
9 years ago
settings.php
9 years ago
settings.php
621 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Adds settings part to plugin |
| 4 | * Originally, wrote by Pippin Williamson |
| 5 | * |
| 6 | * @author Pippin Williamson |
| 7 | * @author Ehsaan |
| 8 | * @package WP-Parsidate |
| 9 | * @subpackage Admin/Settings |
| 10 | */ |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; |
| 13 | } // No direct access allowed ;) |
| 14 | |
| 15 | add_action( 'admin_menu', 'wpp_add_settings_menu', 11 ); |
| 16 | |
| 17 | /** |
| 18 | * Add WP-Parsidate admin page settings |
| 19 | * */ |
| 20 | function wpp_add_settings_menu() { |
| 21 | global $wpp_settings; |
| 22 | |
| 23 | if ( $wpp_settings['submenu_move'] != 'disable' ) { |
| 24 | add_submenu_page( |
| 25 | 'options-general.php', |
| 26 | __( 'Parsi Settings', 'wp-parsidate' ), |
| 27 | __( 'Parsi Settings', 'wp-parsidate' ), |
| 28 | 'manage_options', |
| 29 | 'wp-parsi-settings', |
| 30 | 'wpp_render_settings' |
| 31 | ); |
| 32 | } else { |
| 33 | add_menu_page( |
| 34 | __( 'Parsi Settings', 'wp-parsidate' ), |
| 35 | __( 'Parsi Settings', 'wp-parsidate' ), |
| 36 | 'manage_options', |
| 37 | 'wp-parsi-settings', |
| 38 | 'wpp_render_settings', |
| 39 | 'dashicons-admin-site' |
| 40 | ); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Gets saved settings from WP core |
| 46 | * |
| 47 | * @since 2.0 |
| 48 | * @return array Parsi Settings |
| 49 | */ |
| 50 | function wp_parsi_get_settings() { |
| 51 | $settings = get_option( 'wpp_settings' ); |
| 52 | if ( empty( $settings ) ) { |
| 53 | update_option( 'wpp_settings', array( |
| 54 | 'admin_lang' => 'enable', |
| 55 | 'user_lang' => 'enable', |
| 56 | 'submenu_move' => 'disable', |
| 57 | 'persian_date' => 'disable', |
| 58 | 'droidsans_editor' => 'enable', |
| 59 | 'droidsans_admin' => 'enable', |
| 60 | 'conv_title' => 'disable', |
| 61 | 'conv_contents' => 'disable', |
| 62 | 'conv_excerpt' => 'disable', |
| 63 | 'conv_comments' => 'disable', |
| 64 | 'conv_comment_count' => 'disable', |
| 65 | 'conv_dates' => 'disable', |
| 66 | 'conv_cats' => 'disable', |
| 67 | 'conv_arabic' => 'disable', |
| 68 | 'conv_permalinks' => 'disable', |
| 69 | 'news_source' => 'parsi' |
| 70 | ) ); |
| 71 | } |
| 72 | |
| 73 | return apply_filters( 'wpp_get_settings', $settings ); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Registers settings in WP core |
| 78 | * |
| 79 | * @since 2.0 |
| 80 | * @return void |
| 81 | */ |
| 82 | function wpp_register_settings() { |
| 83 | if ( false == get_option( 'wpp_settings' ) ) { |
| 84 | add_option( 'wpp_settings' ); |
| 85 | } |
| 86 | |
| 87 | foreach ( wpp_get_registered_settings() as $tab => $settings ) { |
| 88 | add_settings_section( |
| 89 | 'wpp_settings_' . $tab, |
| 90 | __return_null(), |
| 91 | '__return_false', |
| 92 | 'wpp_settings_' . $tab |
| 93 | ); |
| 94 | |
| 95 | foreach ( $settings as $option ) { |
| 96 | $name = isset( $option['name'] ) ? $option['name'] : ''; |
| 97 | |
| 98 | add_settings_field( |
| 99 | 'wpp_settings[' . $option['id'] . ']', |
| 100 | $name, |
| 101 | function_exists( 'wpp_' . $option['type'] . '_callback' ) ? 'wpp_' . $option['type'] . '_callback' : 'wpp_missing_callback', |
| 102 | 'wpp_settings_' . $tab, |
| 103 | 'wpp_settings_' . $tab, |
| 104 | array( |
| 105 | 'id' => isset( $option['id'] ) ? $option['id'] : null, |
| 106 | 'desc' => ! empty( $option['desc'] ) ? $option['desc'] : '', |
| 107 | 'name' => isset( $option['name'] ) ? $option['name'] : null, |
| 108 | 'section' => $tab, |
| 109 | 'size' => isset( $option['size'] ) ? $option['size'] : null, |
| 110 | 'options' => isset( $option['options'] ) ? $option['options'] : '', |
| 111 | 'std' => isset( $option['std'] ) ? $option['std'] : '' |
| 112 | ) |
| 113 | ); |
| 114 | |
| 115 | register_setting( 'wpp_settings', 'wpp_settings', 'wpp_settings_sanitize' ); |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | add_action( 'admin_init', 'wpp_register_settings' ); |
| 121 | |
| 122 | /** |
| 123 | * Gets settings tabs |
| 124 | * |
| 125 | * @since 2.0 |
| 126 | * @return array Tabs list |
| 127 | */ |
| 128 | function wpp_get_tabs() { |
| 129 | $tabs = array( |
| 130 | 'core' => sprintf( __( '%s Core', 'wp-parsidate' ), '<span class="dashicons dashicons-admin-site"></span>' ), |
| 131 | 'conv' => sprintf( __( '%s Converts', 'wp-parsidate' ), '<span class="dashicons dashicons-admin-settings"></span>' ), |
| 132 | 'plugins' => sprintf( __( '%s Plugins compability', 'wp-parsidate' ), '<span class="dashicons dashicons-admin-plugins"></span>' ) |
| 133 | ); |
| 134 | |
| 135 | return $tabs; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Sanitizes and saves settings after submit |
| 140 | * |
| 141 | * @since 2.0 |
| 142 | * |
| 143 | * @param array $input Settings input |
| 144 | * |
| 145 | * @return array New settings |
| 146 | */ |
| 147 | function wpp_settings_sanitize( $input = array() ) { |
| 148 | |
| 149 | global $wpp_settings; |
| 150 | |
| 151 | if ( empty( $_POST['_wp_http_referer'] ) ) { |
| 152 | return $input; |
| 153 | } |
| 154 | |
| 155 | parse_str( $_POST['_wp_http_referer'], $referrer ); |
| 156 | |
| 157 | $settings = wpp_get_registered_settings(); |
| 158 | $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'core'; |
| 159 | |
| 160 | $input = $input ? $input : array(); |
| 161 | $input = apply_filters( 'wpp_settings_' . $tab . '_sanitize', $input ); |
| 162 | |
| 163 | // Loop through each setting being saved and pass it through a sanitization filter |
| 164 | foreach ( $input as $key => $value ) { |
| 165 | |
| 166 | // Get the setting type (checkbox, select, etc) |
| 167 | $type = isset( $settings[ $tab ][ $key ]['type'] ) ? $settings[ $tab ][ $key ]['type'] : false; |
| 168 | |
| 169 | if ( $type ) { |
| 170 | // Field type specific filter |
| 171 | $input[ $key ] = apply_filters( 'wpp_settings_sanitize_' . $type, $value, $key ); |
| 172 | } |
| 173 | |
| 174 | // General filter |
| 175 | $input[ $key ] = apply_filters( 'wpp_settings_sanitize', $value, $key ); |
| 176 | } |
| 177 | |
| 178 | |
| 179 | // Loop through the whitelist and unset any that are empty for the tab being saved |
| 180 | if ( ! empty( $settings[ $tab ] ) ) { |
| 181 | foreach ( $settings[ $tab ] as $key => $value ) { |
| 182 | |
| 183 | // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work |
| 184 | if ( is_numeric( $key ) ) { |
| 185 | $key = $value['id']; |
| 186 | } |
| 187 | |
| 188 | if ( empty( $input[ $key ] ) ) { |
| 189 | unset( $wpp_settings[ $key ] ); |
| 190 | } |
| 191 | |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | // Merge our new settings with the existing |
| 196 | $output = array_merge( $wpp_settings, $input ); |
| 197 | |
| 198 | return $output; |
| 199 | |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Get settings fields |
| 204 | * |
| 205 | * @since 2.0 |
| 206 | * @return array Fields |
| 207 | */ |
| 208 | function wpp_get_registered_settings() { |
| 209 | $options = array( |
| 210 | 'enable' => __( 'Enable', 'wp-parsidate' ), |
| 211 | 'disable' => __( 'Disable', 'wp-parsidate' ) |
| 212 | ); |
| 213 | $settings = apply_filters( 'wpp_registered_settings', array( |
| 214 | 'core' => apply_filters( 'wpp_core_settings', array( |
| 215 | 'admin_lang' => array( |
| 216 | 'id' => 'admin_lang', |
| 217 | 'name' => __( 'Change Locale in admin', 'wp-parsidate' ), |
| 218 | 'type' => 'radio', |
| 219 | 'options' => $options, |
| 220 | 'std' => 'enable', |
| 221 | 'desc' => __( 'This option change WordPress locale in Admin', 'wp-parsidate' ) |
| 222 | ), |
| 223 | 'user_lang' => array( |
| 224 | 'id' => 'user_lang', |
| 225 | 'name' => __( 'Change Locale in theme', 'wp-parsidate' ), |
| 226 | 'type' => 'radio', |
| 227 | 'options' => $options, |
| 228 | 'std' => 'enable', |
| 229 | 'desc' => __( 'This option change WordPress locale in theme', 'wp-parsidate' ) |
| 230 | ), |
| 231 | 'persian_date' => array( |
| 232 | 'id' => 'persian_date', |
| 233 | 'name' => __( 'Shamsi date', 'wp-parsidate' ), |
| 234 | 'type' => 'radio', |
| 235 | 'options' => $options, |
| 236 | 'std' => 'disable', |
| 237 | 'desc' => __( 'By enabling this, Dates will convert to Shamsi (Jalali) dates', 'wp-parsidate' ) |
| 238 | ), |
| 239 | 'submenu_move' => array( |
| 240 | 'id' => 'submenu_move', |
| 241 | 'name' => __( 'Move page to submenu?', 'wp-parsidate' ), |
| 242 | 'type' => 'radio', |
| 243 | 'options' => $options, |
| 244 | 'std' => 'disable', |
| 245 | 'desc' => __( 'With enabling this option, page item will be moved to Settings menu as submenu.', 'wp-parsidate' ) |
| 246 | ), |
| 247 | ) ), |
| 248 | 'conv' => apply_filters( 'wpp_conv_settings', array( |
| 249 | 'conv_nums' => array( |
| 250 | 'id' => 'conv_nums', |
| 251 | 'name' => __( 'Persian digits', 'wp-parsidate' ), |
| 252 | 'type' => 'header' |
| 253 | ), |
| 254 | 'conv_page_title' => array( |
| 255 | 'id' => 'conv_page_title', |
| 256 | 'name' => __( 'Page title', 'wp-parsidate' ), |
| 257 | 'type' => 'radio', |
| 258 | 'options' => $options, |
| 259 | 'std' => 'disable' |
| 260 | ), |
| 261 | 'conv_title' => array( |
| 262 | 'id' => 'conv_title', |
| 263 | 'name' => __( 'Post title', 'wp-parsidate' ), |
| 264 | 'type' => 'radio', |
| 265 | 'options' => $options, |
| 266 | 'std' => 'disable' |
| 267 | ), |
| 268 | 'conv_contents' => array( |
| 269 | 'id' => 'conv_contents', |
| 270 | 'name' => __( 'Post content', 'wp-parsidate' ), |
| 271 | 'type' => 'radio', |
| 272 | 'options' => $options, |
| 273 | 'std' => 'enable' |
| 274 | ), |
| 275 | 'conv_excerpt' => array( |
| 276 | 'id' => 'conv_excerpt', |
| 277 | 'name' => __( 'Post excerpt', 'wp-parsidate' ), |
| 278 | 'type' => 'radio', |
| 279 | 'options' => $options, |
| 280 | 'std' => 'disable' |
| 281 | ), |
| 282 | 'conv_comments' => array( |
| 283 | 'id' => 'conv_comments', |
| 284 | 'name' => __( 'Comments text', 'wp-parsidate' ), |
| 285 | 'type' => 'radio', |
| 286 | 'options' => $options, |
| 287 | 'std' => 'disable' |
| 288 | ), |
| 289 | 'conv_comment_count' => array( |
| 290 | 'id' => 'conv_comment_count', |
| 291 | 'name' => __( 'Comments count', 'wp-parsidate' ), |
| 292 | 'type' => 'radio', |
| 293 | 'options' => $options, |
| 294 | 'std' => 'disable' |
| 295 | ), |
| 296 | 'conv_dates' => array( |
| 297 | 'id' => 'conv_dates', |
| 298 | 'name' => __( 'Dates', 'wp-parsidate' ), |
| 299 | 'type' => 'radio', |
| 300 | 'options' => $options, |
| 301 | 'std' => 'disable' |
| 302 | ), |
| 303 | 'conv_cats' => array( |
| 304 | 'id' => 'conv_cats', |
| 305 | 'name' => __( 'Categories', 'wp-parsidate' ), |
| 306 | 'type' => 'radio', |
| 307 | 'options' => $options, |
| 308 | 'std' => 'disable' |
| 309 | ), |
| 310 | 'sep' => array( |
| 311 | 'id' => 'sep', |
| 312 | 'type' => 'header' |
| 313 | ), |
| 314 | 'conv_arabic' => array( |
| 315 | 'id' => 'conv_arabic', |
| 316 | 'name' => __( 'Fix arabic characters', 'wp-parsidate' ), |
| 317 | 'type' => 'radio', |
| 318 | 'options' => $options, |
| 319 | 'std' => 'disable', |
| 320 | 'desc' => __( 'Fixes arabic characters caused by wrong keyboard layouts', 'wp-parsidate' ) |
| 321 | ), |
| 322 | 'conv_permalinks' => array( |
| 323 | 'id' => 'conv_permalinks', |
| 324 | 'name' => __( 'Fix permalinks dates', 'wp-parsidate' ), |
| 325 | 'type' => 'radio', |
| 326 | 'options' => $options, |
| 327 | 'std' => 'disable', |
| 328 | 'desc' => __( 'By enabling this, dates in permalinks converted to Shamsi (Jalali) date', 'wp-parsidate' ) |
| 329 | ), |
| 330 | 'sep_font' => array( |
| 331 | 'id' => 'sep_font', |
| 332 | 'type' => 'header' |
| 333 | ), |
| 334 | 'droidsans_admin' => array( |
| 335 | 'id' => 'droidsans_admin', |
| 336 | 'name' => __( 'Use Droid Sans font for admin side', 'wp-parsidate' ), |
| 337 | 'type' => 'radio', |
| 338 | 'options' => $options, |
| 339 | 'std' => 'enable', |
| 340 | 'desc' => __( 'Droid Sans Naskh and Roboto font families will be activated in admin side, if this is enabled.', 'wp-parsidate' ) |
| 341 | ), |
| 342 | 'droidsans_editor' => array( |
| 343 | 'id' => 'droidsans_editor', |
| 344 | 'name' => __( 'Use Droid Sans font for editors', 'wp-parsidate' ), |
| 345 | 'type' => 'radio', |
| 346 | 'options' => $options, |
| 347 | 'std' => 'enable', |
| 348 | 'desc' => __( 'Droid Sans Naskh and Roboto font families will be activated in all rich editors in back end.', 'wp-parsidate' ) |
| 349 | ) |
| 350 | ) ), |
| 351 | 'plugins' => apply_filters( 'wpp_plugins_compability_settings', array() ) |
| 352 | ) ); |
| 353 | |
| 354 | return $settings; |
| 355 | } |
| 356 | |
| 357 | /* Form Callbacks Made by EDD Development Team */ |
| 358 | function wpp_header_callback( $args ) { |
| 359 | echo '<hr/>'; |
| 360 | } |
| 361 | |
| 362 | function wpp_checkbox_callback( $args ) { |
| 363 | global $wpp_settings; |
| 364 | |
| 365 | $checked = isset( $wpp_settings[ $args['id'] ] ) ? checked( 1, $wpp_settings[ $args['id'] ], false ) : ''; |
| 366 | $html = '<input type="checkbox" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="1" ' . $checked . '/>'; |
| 367 | $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 368 | |
| 369 | echo $html; |
| 370 | } |
| 371 | |
| 372 | function wpp_multicheck_callback( $args ) { |
| 373 | global $wpp_settings; |
| 374 | |
| 375 | $html = ''; |
| 376 | foreach ( $args['options'] as $key => $value ) { |
| 377 | $option_name = $args['id'] . '-' . $key; |
| 378 | wpp_checkbox_callback( array( |
| 379 | 'id' => $option_name, |
| 380 | 'desc' => $value |
| 381 | ) ); |
| 382 | echo '<br>'; |
| 383 | } |
| 384 | |
| 385 | echo $html; |
| 386 | } |
| 387 | |
| 388 | function wpp_radio_callback( $args ) { |
| 389 | global $wpp_settings; |
| 390 | |
| 391 | foreach ( $args['options'] as $key => $option ) : |
| 392 | $checked = false; |
| 393 | |
| 394 | if ( isset( $wpp_settings[ $args['id'] ] ) && $wpp_settings[ $args['id'] ] == $key ) { |
| 395 | $checked = true; |
| 396 | } elseif ( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpp_settings[ $args['id'] ] ) ) { |
| 397 | $checked = true; |
| 398 | } |
| 399 | |
| 400 | echo '<input name="wpp_settings[' . $args['id'] . ']"" id="wpp_settings[' . $args['id'] . '][' . $key . ']" type="radio" value="' . $key . '" ' . checked( true, $checked, false ) . '/>'; |
| 401 | echo '<label for="wpp_settings[' . $args['id'] . '][' . $key . ']">' . $option . '</label> '; |
| 402 | endforeach; |
| 403 | |
| 404 | echo '<p class="description">' . $args['desc'] . '</p>'; |
| 405 | } |
| 406 | |
| 407 | function wpp_text_callback( $args ) { |
| 408 | global $wpp_settings; |
| 409 | |
| 410 | if ( isset( $wpp_settings[ $args['id'] ] ) ) { |
| 411 | $value = $wpp_settings[ $args['id'] ]; |
| 412 | } else { |
| 413 | $value = isset( $args['std'] ) ? $args['std'] : ''; |
| 414 | } |
| 415 | |
| 416 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
| 417 | $html = '<input type="text" class="' . $size . '-text" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
| 418 | $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 419 | |
| 420 | echo $html; |
| 421 | } |
| 422 | |
| 423 | function wpp_number_callback( $args ) { |
| 424 | global $wpp_settings; |
| 425 | |
| 426 | if ( isset( $wpp_settings[ $args['id'] ] ) ) { |
| 427 | $value = $wpp_settings[ $args['id'] ]; |
| 428 | } else { |
| 429 | $value = isset( $args['std'] ) ? $args['std'] : ''; |
| 430 | } |
| 431 | |
| 432 | $max = isset( $args['max'] ) ? $args['max'] : 999999; |
| 433 | $min = isset( $args['min'] ) ? $args['min'] : 0; |
| 434 | $step = isset( $args['step'] ) ? $args['step'] : 1; |
| 435 | |
| 436 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
| 437 | $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . $size . '-text" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
| 438 | $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 439 | |
| 440 | echo $html; |
| 441 | } |
| 442 | |
| 443 | function wpp_textarea_callback( $args ) { |
| 444 | global $wpp_settings; |
| 445 | |
| 446 | if ( isset( $wpp_settings[ $args['id'] ] ) ) { |
| 447 | $value = $wpp_settings[ $args['id'] ]; |
| 448 | } else { |
| 449 | $value = isset( $args['std'] ) ? $args['std'] : ''; |
| 450 | } |
| 451 | |
| 452 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
| 453 | $html = '<textarea class="large-text" cols="50" rows="5" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
| 454 | $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 455 | |
| 456 | echo $html; |
| 457 | } |
| 458 | |
| 459 | function wpp_password_callback( $args ) { |
| 460 | global $wpp_settings; |
| 461 | |
| 462 | if ( isset( $wpp_settings[ $args['id'] ] ) ) { |
| 463 | $value = $wpp_settings[ $args['id'] ]; |
| 464 | } else { |
| 465 | $value = isset( $args['std'] ) ? $args['std'] : ''; |
| 466 | } |
| 467 | |
| 468 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
| 469 | $html = '<input type="password" class="' . $size . '-text" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr( $value ) . '"/>'; |
| 470 | $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 471 | |
| 472 | echo $html; |
| 473 | } |
| 474 | |
| 475 | function wpp_missing_callback( $args ) { |
| 476 | echo '–'; |
| 477 | |
| 478 | return false; |
| 479 | } |
| 480 | |
| 481 | |
| 482 | function wpp_select_callback( $args ) { |
| 483 | global $wpp_settings; |
| 484 | |
| 485 | if ( isset( $wpp_settings[ $args['id'] ] ) ) { |
| 486 | $value = $wpp_settings[ $args['id'] ]; |
| 487 | } else { |
| 488 | $value = isset( $args['std'] ) ? $args['std'] : ''; |
| 489 | } |
| 490 | |
| 491 | $html = '<select id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']"/>'; |
| 492 | |
| 493 | foreach ( $args['options'] as $option => $name ) : |
| 494 | $selected = selected( $option, $value, false ); |
| 495 | $html .= '<option value="' . $option . '" ' . $selected . '>' . $name . '</option>'; |
| 496 | endforeach; |
| 497 | |
| 498 | $html .= '</select>'; |
| 499 | $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 500 | |
| 501 | echo $html; |
| 502 | } |
| 503 | |
| 504 | function wpp_color_select_callback( $args ) { |
| 505 | global $wpp_settings; |
| 506 | |
| 507 | if ( isset( $wpp_settings[ $args['id'] ] ) ) { |
| 508 | $value = $wpp_settings[ $args['id'] ]; |
| 509 | } else { |
| 510 | $value = isset( $args['std'] ) ? $args['std'] : ''; |
| 511 | } |
| 512 | |
| 513 | $html = '<select id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']"/>'; |
| 514 | |
| 515 | foreach ( $args['options'] as $option => $color ) : |
| 516 | $selected = selected( $option, $value, false ); |
| 517 | $html .= '<option value="' . $option . '" ' . $selected . '>' . $color['label'] . '</option>'; |
| 518 | endforeach; |
| 519 | |
| 520 | $html .= '</select>'; |
| 521 | $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 522 | |
| 523 | echo $html; |
| 524 | } |
| 525 | |
| 526 | function wpp_rich_editor_callback( $args ) { |
| 527 | global $wpp_settings, $wp_version; |
| 528 | |
| 529 | if ( isset( $wpp_settings[ $args['id'] ] ) ) { |
| 530 | $value = $wpp_settings[ $args['id'] ]; |
| 531 | } else { |
| 532 | $value = isset( $args['std'] ) ? $args['std'] : ''; |
| 533 | } |
| 534 | |
| 535 | if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
| 536 | $html = wp_editor( stripslashes( $value ), 'wpp_settings[' . $args['id'] . ']', array( 'textarea_name' => 'wpp_settings[' . $args['id'] . ']' ) ); |
| 537 | } else { |
| 538 | $html = '<textarea class="large-text" rows="10" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
| 539 | } |
| 540 | |
| 541 | $html .= '<br/><label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 542 | |
| 543 | echo $html; |
| 544 | } |
| 545 | |
| 546 | function wpp_upload_callback( $args ) { |
| 547 | global $wpp_settings; |
| 548 | |
| 549 | if ( isset( $wpp_settings[ $args['id'] ] ) ) { |
| 550 | $value = $wpp_settings[ $args['id'] ]; |
| 551 | } else { |
| 552 | $value = isset( $args['std'] ) ? $args['std'] : ''; |
| 553 | } |
| 554 | |
| 555 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
| 556 | $html = '<input type="text" class="' . $size . '-text wpp_upload_field" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
| 557 | $html .= '<span> <input type="button" class="wpp_settings_upload_button button-secondary" value="' . __( 'Upload File', 'wpp' ) . '"/></span>'; |
| 558 | $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 559 | |
| 560 | echo $html; |
| 561 | } |
| 562 | |
| 563 | function wpp_color_callback( $args ) { |
| 564 | global $wpp_settings; |
| 565 | |
| 566 | if ( isset( $wpp_settings[ $args['id'] ] ) ) { |
| 567 | $value = $wpp_settings[ $args['id'] ]; |
| 568 | } else { |
| 569 | $value = isset( $args['std'] ) ? $args['std'] : ''; |
| 570 | } |
| 571 | |
| 572 | $default = isset( $args['std'] ) ? $args['std'] : ''; |
| 573 | |
| 574 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
| 575 | $html = '<input type="text" class="wpp-color-picker" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
| 576 | $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 577 | |
| 578 | echo $html; |
| 579 | } |
| 580 | |
| 581 | function wpp_render_settings() { |
| 582 | global $wpp_settings; |
| 583 | $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], wpp_get_tabs() ) ? $_GET['tab'] : 'core'; |
| 584 | |
| 585 | ob_start(); |
| 586 | ?> |
| 587 | <div class="wrap wpp-settings-wrap"> |
| 588 | <h2><?php _e( 'Parsi Settings', 'wp-parsidate' ) ?></h2> |
| 589 | <h2 class="nav-tab-wrapper"> |
| 590 | <?php |
| 591 | foreach ( wpp_get_tabs() as $tab_id => $tab_name ) { |
| 592 | |
| 593 | $tab_url = add_query_arg( array( |
| 594 | 'settings-updated' => false, |
| 595 | 'tab' => $tab_id |
| 596 | ) ); |
| 597 | |
| 598 | $active = $active_tab == $tab_id ? ' nav-tab-active' : ''; |
| 599 | |
| 600 | echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">'; |
| 601 | echo $tab_name; |
| 602 | echo '</a>'; |
| 603 | } |
| 604 | ?> |
| 605 | </h2> |
| 606 | <?php settings_errors( 'wpp-notices' ); ?> |
| 607 | <div id="tab_container"> |
| 608 | <form method="post" action="options.php"> |
| 609 | <table class="form-table"> |
| 610 | <?php |
| 611 | settings_fields( 'wpp_settings' ); |
| 612 | do_settings_fields( 'wpp_settings_' . $active_tab, 'wpp_settings_' . $active_tab ); |
| 613 | ?> |
| 614 | </table> |
| 615 | <?php submit_button(); ?> |
| 616 | </form> |
| 617 | </div><!-- #tab_container--> |
| 618 | </div><!-- .wrap --> |
| 619 | <?php |
| 620 | echo ob_get_clean(); |
| 621 | } |