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