admin
1 year ago
plugins
1 year ago
views
1 year ago
widget
1 year ago
fixes-archive.php
1 year ago
fixes-archives.php
1 year ago
fixes-calendar.php
1 year ago
fixes-dates.php
1 year ago
fixes-misc.php
1 year ago
fixes-permalinks.php
1 year ago
general.php
1 year ago
install.php
1 year ago
parsidate.php
1 year ago
settings.php
1 year ago
tools.php
1 year ago
settings.php
765 lines
| 1 | <?php |
| 2 | defined( 'ABSPATH' ) or exit( 'No direct script access allowed' ); |
| 3 | |
| 4 | /** |
| 5 | * Adds settings part to plugin |
| 6 | * Originally, wrote by Pippin Williamson |
| 7 | * |
| 8 | * @author Pippin Williamson |
| 9 | * @author Hamid Reza Yazdani |
| 10 | * @author Ehsaan |
| 11 | * @author Morteza Geransayeh |
| 12 | * @author Mobin Ghasempoor |
| 13 | * @package WP-Parsidate |
| 14 | * @subpackage Admin/Settings |
| 15 | */ |
| 16 | |
| 17 | /** |
| 18 | * Add WP-Parsidate admin page settings |
| 19 | **/ |
| 20 | function wpp_add_settings_menu() { |
| 21 | if ( wpp_is_active( 'submenu_move' ) ) { |
| 22 | add_submenu_page( |
| 23 | 'options-general.php', |
| 24 | __( 'Parsi Settings', 'wp-parsidate' ), |
| 25 | __( 'Parsi Settings', 'wp-parsidate' ), |
| 26 | 'manage_options', |
| 27 | 'wp-parsi-settings', |
| 28 | 'wpp_render_settings' |
| 29 | ); |
| 30 | } else { |
| 31 | add_menu_page( |
| 32 | __( 'Parsi Settings', 'wp-parsidate' ), |
| 33 | __( 'Parsi Settings', 'wp-parsidate' ), |
| 34 | 'manage_options', |
| 35 | 'wp-parsi-settings', |
| 36 | 'wpp_render_settings', |
| 37 | 'dashicons-admin-site' |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | add_action( 'admin_enqueue_scripts', 'wpp_enqueue_setting_page_style' ); |
| 42 | } |
| 43 | |
| 44 | add_action( 'admin_menu', 'wpp_add_settings_menu', 11 ); |
| 45 | |
| 46 | /** |
| 47 | * Gets saved settings from WP core |
| 48 | * |
| 49 | * @return array Parsi Settings |
| 50 | * @since 2.0 |
| 51 | */ |
| 52 | function wp_parsi_get_settings() { |
| 53 | $settings = get_option( 'wpp_settings' ); |
| 54 | |
| 55 | if ( empty( $settings ) ) { |
| 56 | update_option( 'wpp_settings', array( |
| 57 | 'admin_lang' => 'disable', |
| 58 | 'user_lang' => 'disable', |
| 59 | 'persian_date' => 'disable', |
| 60 | 'disable_widget_block' => 'disable', |
| 61 | 'submenu_move' => 'disable', |
| 62 | 'dev_mode' => 'disable', |
| 63 | 'enable_fonts' => 'disable', |
| 64 | 'conv_title' => 'disable', |
| 65 | 'conv_contents' => 'disable', |
| 66 | 'conv_excerpt' => 'disable', |
| 67 | 'conv_comments' => 'disable', |
| 68 | 'conv_comment_count' => 'disable', |
| 69 | 'conv_dates' => 'disable', |
| 70 | 'conv_cats' => 'disable', |
| 71 | 'conv_arabic' => 'disable', |
| 72 | 'conv_permalinks' => 'disable', |
| 73 | 'news_source' => 'parsi' |
| 74 | ) ); |
| 75 | } |
| 76 | |
| 77 | return apply_filters( 'wpp_get_settings', $settings ); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Registers settings in WP core |
| 82 | * |
| 83 | * @return void |
| 84 | * @since 2.0 |
| 85 | */ |
| 86 | function wpp_register_settings() { |
| 87 | if ( false === get_option( 'wpp_settings' ) ) { |
| 88 | add_option( 'wpp_settings', array() ); |
| 89 | } |
| 90 | |
| 91 | foreach ( wpp_get_registered_settings() as $tab => $settings ) { |
| 92 | add_settings_section( |
| 93 | 'wpp_settings_' . $tab, |
| 94 | __return_null(), |
| 95 | '__return_false', |
| 96 | 'wpp_settings_' . $tab |
| 97 | ); |
| 98 | |
| 99 | foreach ( $settings as $option ) { |
| 100 | $name = $option['name'] ?? ''; |
| 101 | |
| 102 | add_settings_field( |
| 103 | 'wpp_settings[' . $option['id'] . ']', |
| 104 | $name, |
| 105 | function_exists( 'wpp_' . $option['type'] . '_callback' ) ? 'wpp_' . $option['type'] . '_callback' : 'wpp_missing_callback', |
| 106 | 'wpp_settings_' . $tab, |
| 107 | 'wpp_settings_' . $tab, |
| 108 | array( |
| 109 | 'id' => $option['id'] ?? null, |
| 110 | 'desc' => ! empty( $option['desc'] ) ? $option['desc'] : '', |
| 111 | 'name' => $option['name'] ?? null, |
| 112 | 'section' => $tab, |
| 113 | 'size' => $option['size'] ?? null, |
| 114 | 'options' => $option['options'] ?? '', |
| 115 | 'std' => $option['std'] ?? '' |
| 116 | ) |
| 117 | ); |
| 118 | |
| 119 | register_setting( 'wpp_settings', 'wpp_settings', 'wpp_settings_sanitize' ); |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | add_action( 'admin_init', 'wpp_register_settings' ); |
| 125 | |
| 126 | /** |
| 127 | * Gets settings tabs |
| 128 | * |
| 129 | * @return array Tabs list |
| 130 | * @since 2.0 |
| 131 | */ |
| 132 | function wpp_get_tabs() { |
| 133 | return array( |
| 134 | 'core' => sprintf( __( '%s Core', 'wp-parsidate' ), '<span class="dashicons dashicons-admin-site"></span>' ), |
| 135 | 'conv' => sprintf( __( '%s Converts', 'wp-parsidate' ), '<span class="dashicons dashicons-admin-settings"></span>' ), |
| 136 | 'tools' => sprintf( __( '%s Tools', 'wp-parsidate' ), '<span class="dashicons dashicons-admin-tools"></span>' ), |
| 137 | 'plugins' => sprintf( __( '%s Plugins compatibility', 'wp-parsidate' ), '<span class="dashicons dashicons-admin-plugins"></span>' ), |
| 138 | 'about' => sprintf( __( '%s About', 'wp-parsidate' ), '<span class="dashicons dashicons-info"></span>' ), |
| 139 | ); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Sanitizes and saves settings after submit |
| 144 | * |
| 145 | * @param array $input Settings input |
| 146 | * |
| 147 | * @return array New settings |
| 148 | * @since 2.0 |
| 149 | * |
| 150 | */ |
| 151 | function wpp_settings_sanitize( $input = array() ) { |
| 152 | global $wpp_settings; |
| 153 | |
| 154 | if ( empty( $_POST['_wp_http_referer'] ) ) { |
| 155 | return $input; |
| 156 | } |
| 157 | |
| 158 | parse_str( $_POST['_wp_http_referer'], $referrer ); |
| 159 | |
| 160 | $settings = wpp_get_registered_settings(); |
| 161 | $tab = $referrer['tab'] ?? 'core'; |
| 162 | $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 | // Get the setting type (checkbox, select, etc.) |
| 168 | $type = $settings[ $tab ][ $key ]['type'] ?? false; |
| 169 | |
| 170 | if ( $type ) { |
| 171 | // Field type specific filter |
| 172 | $input[ $key ] = apply_filters( 'wpp_settings_sanitize_' . $type, $value, $key ); |
| 173 | } |
| 174 | |
| 175 | // General filter |
| 176 | $input[ $key ] = apply_filters( 'wpp_settings_sanitize', $value, $key ); |
| 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 | // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work |
| 183 | if ( is_numeric( $key ) ) { |
| 184 | $key = $value['id']; |
| 185 | } |
| 186 | |
| 187 | if ( ! isset( $input[ $key ] ) ) { |
| 188 | unset( $wpp_settings[ $key ] ); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | // Merge our new settings with the existing |
| 194 | return array_merge( $wpp_settings, $input ); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Get settings fields |
| 199 | * |
| 200 | * @return array Fields |
| 201 | * @since 2.0 |
| 202 | */ |
| 203 | function wpp_get_registered_settings() { |
| 204 | return apply_filters( 'wpp_registered_settings', array( |
| 205 | 'core' => apply_filters( 'wpp_core_settings', array( |
| 206 | 'admin_lang' => array( |
| 207 | 'id' => 'admin_lang', |
| 208 | 'name' => __( 'Change Locale in admin', 'wp-parsidate' ), |
| 209 | 'type' => 'checkbox', |
| 210 | 'options' => 'enable', |
| 211 | 'std' => 0, |
| 212 | 'desc' => __( 'This option change WordPress locale to Persian in Admin', 'wp-parsidate' ), |
| 213 | ), |
| 214 | 'user_lang' => array( |
| 215 | 'id' => 'user_lang', |
| 216 | 'name' => __( 'Change Locale in theme', 'wp-parsidate' ), |
| 217 | 'type' => 'checkbox', |
| 218 | 'options' => 'enable', |
| 219 | 'std' => 0, |
| 220 | 'desc' => __( 'This option change WordPress locale to Persian in theme', 'wp-parsidate' ), |
| 221 | ), |
| 222 | 'persian_date' => array( |
| 223 | 'id' => 'persian_date', |
| 224 | 'name' => __( 'Shamsi date', 'wp-parsidate' ), |
| 225 | 'type' => 'checkbox', |
| 226 | 'options' => 'enable', |
| 227 | 'std' => 0, |
| 228 | 'desc' => __( 'By enabling this, Dates will convert to Shamsi (Jalali) dates', 'wp-parsidate' ), |
| 229 | ), |
| 230 | 'months_name_type' => array( |
| 231 | 'id' => 'months_name_type', |
| 232 | 'name' => __( 'Months name type', 'wp-parsidate' ), |
| 233 | 'type' => 'select', |
| 234 | 'options' => array( |
| 235 | 'persian' => __( 'Persian', 'wp-parsidate' ), |
| 236 | 'dari' => __( 'Dari', 'wp-parsidate' ), |
| 237 | 'kurdish' => __( 'Kurdish', 'wp-parsidate' ), |
| 238 | 'pashto' => __( 'Pashto', 'wp-parsidate' ), |
| 239 | ), |
| 240 | 'std' => 0, |
| 241 | ), |
| 242 | 'disable_widget_block' => array( |
| 243 | 'id' => 'disable_widget_block', |
| 244 | 'name' => __( 'Disable Widget Block', 'wp-parsidate' ), |
| 245 | 'type' => 'checkbox', |
| 246 | 'options' => 'enable', |
| 247 | 'std' => 0, |
| 248 | 'desc' => __( 'By enabling this, Widget Block Editor disabled', 'wp-parsidate' ), |
| 249 | ), |
| 250 | 'submenu_move' => array( |
| 251 | 'id' => 'submenu_move', |
| 252 | 'name' => __( 'Move page to submenu?', 'wp-parsidate' ), |
| 253 | 'type' => 'checkbox', |
| 254 | 'options' => 'enable', |
| 255 | 'std' => 0, |
| 256 | 'desc' => __( 'By enabling this option, page item will be moved to Settings menu as submenu.', 'wp-parsidate' ), |
| 257 | ), |
| 258 | 'dev_mode' => array( |
| 259 | 'id' => 'dev_mode', |
| 260 | 'name' => __( 'Debug Mode', 'wp-parsidate' ), |
| 261 | 'type' => 'checkbox', |
| 262 | 'options' => 'enable', |
| 263 | 'std' => 0, |
| 264 | 'desc' => __( 'By enabling this option, the uncompressed version of the JS and CSS files will be loaded.', 'wp-parsidate' ), |
| 265 | ), |
| 266 | 'enable_fonts' => array( |
| 267 | 'id' => 'enable_fonts', |
| 268 | 'name' => __( 'Vazir Font', 'wp-parsidate' ), |
| 269 | 'type' => 'checkbox', |
| 270 | 'options' => 'enable', |
| 271 | 'std' => 0, |
| 272 | 'desc' => __( 'By enabling this option, the Vazir font will be enable in whole admin area.', 'wp-parsidate' ), |
| 273 | ), |
| 274 | ) ), |
| 275 | 'conv' => apply_filters( 'wpp_conv_settings', array( |
| 276 | 'conv_nums' => array( |
| 277 | 'id' => 'conv_nums', |
| 278 | 'name' => __( 'Persian digits', 'wp-parsidate' ), |
| 279 | 'type' => 'header', |
| 280 | ), |
| 281 | 'conv_page_title' => array( |
| 282 | 'id' => 'conv_page_title', |
| 283 | 'name' => __( 'Page title', 'wp-parsidate' ), |
| 284 | 'type' => 'checkbox', |
| 285 | 'options' => 'enable', |
| 286 | 'std' => 0, |
| 287 | 'desc' => __( 'Active', 'wp-parsidate' ), |
| 288 | ), |
| 289 | 'conv_title' => array( |
| 290 | 'id' => 'conv_title', |
| 291 | 'name' => __( 'Post title', 'wp-parsidate' ), |
| 292 | 'type' => 'checkbox', |
| 293 | 'options' => 'enable', |
| 294 | 'std' => 0, |
| 295 | 'desc' => __( 'Active', 'wp-parsidate' ), |
| 296 | ), |
| 297 | 'conv_contents' => array( |
| 298 | 'id' => 'conv_contents', |
| 299 | 'name' => __( 'Post content', 'wp-parsidate' ), |
| 300 | 'type' => 'checkbox', |
| 301 | 'options' => 'enable', |
| 302 | 'std' => 'enable', |
| 303 | 'desc' => __( 'Active', 'wp-parsidate' ), |
| 304 | ), |
| 305 | 'conv_excerpt' => array( |
| 306 | 'id' => 'conv_excerpt', |
| 307 | 'name' => __( 'Post excerpt', 'wp-parsidate' ), |
| 308 | 'type' => 'checkbox', |
| 309 | 'options' => 'enable', |
| 310 | 'std' => 0, |
| 311 | 'desc' => __( 'Active', 'wp-parsidate' ), |
| 312 | ), |
| 313 | 'conv_comments' => array( |
| 314 | 'id' => 'conv_comments', |
| 315 | 'name' => __( 'Comments text', 'wp-parsidate' ), |
| 316 | 'type' => 'checkbox', |
| 317 | 'options' => 'enable', |
| 318 | 'std' => 0, |
| 319 | 'desc' => __( 'Active', 'wp-parsidate' ), |
| 320 | ), |
| 321 | 'conv_comment_count' => array( |
| 322 | 'id' => 'conv_comment_count', |
| 323 | 'name' => __( 'Comments count', 'wp-parsidate' ), |
| 324 | 'type' => 'checkbox', |
| 325 | 'options' => 'enable', |
| 326 | 'std' => 0, |
| 327 | 'desc' => __( 'Active', 'wp-parsidate' ), |
| 328 | ), |
| 329 | 'conv_dates' => array( |
| 330 | 'id' => 'conv_dates', |
| 331 | 'name' => __( 'Dates', 'wp-parsidate' ), |
| 332 | 'type' => 'checkbox', |
| 333 | 'options' => 'enable', |
| 334 | 'std' => 0, |
| 335 | 'desc' => __( 'Active', 'wp-parsidate' ), |
| 336 | ), |
| 337 | 'conv_cats' => array( |
| 338 | 'id' => 'conv_cats', |
| 339 | 'name' => __( 'Categories', 'wp-parsidate' ), |
| 340 | 'type' => 'checkbox', |
| 341 | 'options' => 'enable', |
| 342 | 'std' => 0, |
| 343 | 'desc' => __( 'Active', 'wp-parsidate' ), |
| 344 | ), |
| 345 | 'sep' => array( |
| 346 | 'id' => 'sep', |
| 347 | 'type' => 'header', |
| 348 | ), |
| 349 | 'conv_arabic' => array( |
| 350 | 'id' => 'conv_arabic', |
| 351 | 'name' => __( 'Fix arabic characters', 'wp-parsidate' ), |
| 352 | 'type' => 'checkbox', |
| 353 | 'options' => 'enable', |
| 354 | 'std' => 'disable', |
| 355 | 'desc' => __( 'Fixes arabic characters caused by wrong keyboard layouts', 'wp-parsidate' ), |
| 356 | ), |
| 357 | 'conv_permalinks' => array( |
| 358 | 'id' => 'conv_permalinks', |
| 359 | 'name' => __( 'Fix permalinks dates', 'wp-parsidate' ), |
| 360 | 'type' => 'checkbox', |
| 361 | 'options' => 'enable', |
| 362 | 'std' => 0, |
| 363 | 'desc' => __( 'By enabling this, dates in permalinks converted to Shamsi (Jalali) date', 'wp-parsidate' ), |
| 364 | ), |
| 365 | 'sep_font' => array( |
| 366 | 'id' => 'sep_font', |
| 367 | 'type' => 'header', |
| 368 | ), |
| 369 | ) ), |
| 370 | 'tools' => apply_filters( 'wpp_tools_settings', array( |
| 371 | 'advanced_tools' => array( |
| 372 | 'id' => 'advanced_tools', |
| 373 | 'name' => __( 'Advanced Tools', 'wp-parsidate' ), |
| 374 | 'type' => 'header' |
| 375 | ), |
| 376 | 'date_in_admin_bar' => array( |
| 377 | 'id' => 'date_in_admin_bar', |
| 378 | 'name' => __( "Display date in the admin bar", 'wp-parsidate' ), |
| 379 | 'type' => 'checkbox', |
| 380 | 'options' => 'enable', |
| 381 | 'std' => 'disable', |
| 382 | 'desc' => __( "Display today's Jalali date in the WordPress admin bar.", 'wp-parsidate' ), |
| 383 | ), |
| 384 | 'sep_admin_bar_ate' => array( |
| 385 | 'id' => 'sep_admin_bar_ate', |
| 386 | 'type' => 'header', |
| 387 | ), |
| 388 | 'disable_copy' => array( |
| 389 | 'id' => 'disable_copy', |
| 390 | 'name' => __( 'Prevent users from copying site content', 'wp-parsidate' ), |
| 391 | 'type' => 'checkbox', |
| 392 | 'options' => 'enable', |
| 393 | 'std' => 'disable', |
| 394 | 'desc' => __( "Simply protect your site's content from those who want to copy it.", 'wp-parsidate' ), |
| 395 | ), |
| 396 | 'disable_right_click' => array( |
| 397 | 'id' => 'disable_right_click', |
| 398 | 'name' => __( 'Disable right click on website pages', 'wp-parsidate' ), |
| 399 | 'type' => 'checkbox', |
| 400 | 'options' => 'enable', |
| 401 | 'std' => 0, |
| 402 | 'desc' => __( "Don't worry about downloading website images and other files anymore, this option prevents users from right clicking", 'wp-parsidate' ), |
| 403 | ), |
| 404 | ) ), |
| 405 | 'plugins' => apply_filters( 'wpp_plugins_compatibility_settings', array() ), |
| 406 | ) ); |
| 407 | } |
| 408 | |
| 409 | /* Form Callbacks Made by EDD Development Team */ |
| 410 | /** |
| 411 | * @param $args |
| 412 | */ |
| 413 | function wpp_header_callback( $args ) { |
| 414 | echo '<hr/>'; |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * Generates checkbox field |
| 419 | * |
| 420 | * @param $args |
| 421 | */ |
| 422 | function wpp_checkbox_callback( $args ) { |
| 423 | global $wpp_settings; |
| 424 | |
| 425 | if ( isset( $wpp_settings[ $args['id'] ] ) ) { |
| 426 | $checked = ! is_array( $wpp_settings[ $args['id'] ] ) ? checked( 'enable', $wpp_settings[ $args['id'] ], false ) : checked( 'enable', $wpp_settings[ $args['parent'] ][ $args['id'] ], false ); |
| 427 | } else { |
| 428 | $checked = ''; |
| 429 | } |
| 430 | $is_multiple = ! empty( $args['is_multiple'] ) ? ' checkbox-list' : ''; |
| 431 | $html = sprintf( '<input type="checkbox" id="wpp_settings%1$s" name="wpp_settings%1$s" value="enable" %2$s/>' . |
| 432 | '<label for="wpp_settings%1$s" class="wpp-checkbox-label %3$s %4$s"><span></span> %5$s</label>', |
| 433 | ! $is_multiple ? '[' . $args['id'] . ']' : '[' . $args['parent'] . '][' . $args['id'] . ']', |
| 434 | $checked, |
| 435 | empty( $args['desc'] ) ? 'empty-label' : '', |
| 436 | $is_multiple, |
| 437 | $args['desc'], |
| 438 | ); |
| 439 | |
| 440 | echo $html; |
| 441 | } |
| 442 | |
| 443 | /** |
| 444 | * Generates multiple checkboxes fields |
| 445 | * |
| 446 | * @param $args |
| 447 | */ |
| 448 | function wpp_multicheck_callback( $args ) { |
| 449 | global $wpp_settings; |
| 450 | |
| 451 | $html = '<ul class="wpp-settings-multicheck">'; |
| 452 | $value = $wpp_settings[ $args['id'] ] ?? $args['std'] ?? array(); |
| 453 | |
| 454 | foreach ( $args['options'] as $key => $option ) { |
| 455 | $html .= sprintf( |
| 456 | '<li><input name="wpp_settings[%1$s][%2$s]" id="wpp_settings[%1$s][%2$s]" type="checkbox" value="%2$s" %3$s/><label for="wpp_settings[%1$s][%2$s]" class="wpp-checkbox-label multicheck">%4$s<span></span> %5$s</label></li>', |
| 457 | $args['id'], |
| 458 | $key, |
| 459 | in_array( $key, $value ) ? 'checked="checked"' : '', |
| 460 | $option, |
| 461 | $args['desc'] |
| 462 | ); |
| 463 | } |
| 464 | |
| 465 | echo $html . '</ul>'; |
| 466 | } |
| 467 | |
| 468 | /** |
| 469 | * @param $args |
| 470 | */ |
| 471 | function wpp_radio_callback( $args ) { |
| 472 | global $wpp_settings; |
| 473 | |
| 474 | foreach ( $args['options'] as $key => $option ) : |
| 475 | $checked = false; |
| 476 | |
| 477 | if ( isset( $wpp_settings[ $args['id'] ] ) && $wpp_settings[ $args['id'] ] == $key ) { |
| 478 | $checked = true; |
| 479 | } elseif ( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpp_settings[ $args['id'] ] ) ) { |
| 480 | $checked = true; |
| 481 | } |
| 482 | |
| 483 | echo '<input name="wpp_settings[' . $args['id'] . ']"" id="wpp_settings[' . $args['id'] . '][' . $key . ']" type="radio" value="' . $key . '" ' . checked( true, $checked, false ) . '/>'; |
| 484 | echo '<label for="wpp_settings[' . $args['id'] . '][' . $key . ']">' . $option . '</label> '; |
| 485 | endforeach; |
| 486 | |
| 487 | echo '<p class="description">' . $args['desc'] . '</p>'; |
| 488 | } |
| 489 | |
| 490 | /** |
| 491 | * @param $args |
| 492 | */ |
| 493 | function wpp_text_callback( $args ) { |
| 494 | global $wpp_settings; |
| 495 | |
| 496 | $value = $wpp_settings[ $args['id'] ] ?? $args['std'] ?? ''; |
| 497 | $size = ( isset( $args['size'] ) ) ? $args['size'] : 'regular'; |
| 498 | $html = '<input type="text" class="' . $size . '-text" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
| 499 | $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 500 | |
| 501 | echo $html; |
| 502 | } |
| 503 | |
| 504 | /** |
| 505 | * @param $args |
| 506 | */ |
| 507 | function wpp_number_callback( $args ) { |
| 508 | global $wpp_settings; |
| 509 | |
| 510 | $value = $wpp_settings[ $args['id'] ] ?? $args['std'] ?? ''; |
| 511 | $max = $args['max'] ?? 999999; |
| 512 | $min = $args['min'] ?? 0; |
| 513 | $step = $args['step'] ?? 1; |
| 514 | $size = ( isset( $args['size'] ) ) ? $args['size'] : 'regular'; |
| 515 | $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 ) ) . '"/>'; |
| 516 | $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 517 | |
| 518 | echo $html; |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * @param $args |
| 523 | */ |
| 524 | function wpp_textarea_callback( $args ) { |
| 525 | global $wpp_settings; |
| 526 | |
| 527 | $value = $wpp_settings[ $args['id'] ] ?? $args['std'] ?? ''; |
| 528 | $size = ( isset( $args['size'] ) ) ? $args['size'] : 'regular'; |
| 529 | $html = '<textarea class="large-text" cols="50" rows="5" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
| 530 | $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 531 | |
| 532 | echo $html; |
| 533 | } |
| 534 | |
| 535 | /** |
| 536 | * @param $args |
| 537 | */ |
| 538 | function wpp_password_callback( $args ) { |
| 539 | global $wpp_settings; |
| 540 | |
| 541 | $value = $wpp_settings[ $args['id'] ] ?? $args['std'] ?? ''; |
| 542 | $size = ( isset( $args['size'] ) ) ? $args['size'] : 'regular'; |
| 543 | $html = '<input type="password" class="' . $size . '-text" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']" value="' . esc_attr( $value ) . '"/>'; |
| 544 | $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 545 | |
| 546 | echo $html; |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * @param $args |
| 551 | * |
| 552 | * @return false |
| 553 | */ |
| 554 | function wpp_missing_callback( $args ) { |
| 555 | echo '–'; |
| 556 | |
| 557 | return false; |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * @param $args |
| 562 | */ |
| 563 | function wpp_select_callback( $args ) { |
| 564 | global $wpp_settings; |
| 565 | |
| 566 | $value = $wpp_settings[ $args['id'] ] ?? $args['std'] ?? ''; |
| 567 | $html = '<select id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']"/>'; |
| 568 | |
| 569 | foreach ( $args['options'] as $option => $name ) : |
| 570 | $selected = selected( $option, $value, false ); |
| 571 | $html .= '<option value="' . $option . '" ' . $selected . '>' . $name . '</option>'; |
| 572 | endforeach; |
| 573 | |
| 574 | $html .= '</select>'; |
| 575 | $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 576 | |
| 577 | echo $html; |
| 578 | } |
| 579 | |
| 580 | /** |
| 581 | * @param $args |
| 582 | */ |
| 583 | function wpp_color_select_callback( $args ) { |
| 584 | global $wpp_settings; |
| 585 | |
| 586 | $value = $wpp_settings[ $args['id'] ] ?? $args['std'] ?? ''; |
| 587 | $html = '<select id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']"/>'; |
| 588 | |
| 589 | foreach ( $args['options'] as $option => $color ) : |
| 590 | $selected = selected( $option, $value, false ); |
| 591 | $html .= '<option value="' . $option . '" ' . $selected . '>' . $color['label'] . '</option>'; |
| 592 | endforeach; |
| 593 | |
| 594 | $html .= '</select>'; |
| 595 | $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 596 | |
| 597 | echo $html; |
| 598 | } |
| 599 | |
| 600 | /** |
| 601 | * @param $args |
| 602 | */ |
| 603 | function wpp_rich_editor_callback( $args ) { |
| 604 | global $wpp_settings, $wp_version; |
| 605 | |
| 606 | $value = $wpp_settings[ $args['id'] ] ?? $args['std'] ?? ''; |
| 607 | |
| 608 | if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
| 609 | ob_start(); |
| 610 | |
| 611 | wp_editor( stripslashes( $value ), 'wpp_settings[' . $args['id'] . ']', array( 'textarea_name' => 'wpp_settings[' . $args['id'] . ']' ) ); |
| 612 | |
| 613 | $html = ob_get_contents(); |
| 614 | |
| 615 | ob_end_clean(); |
| 616 | } else { |
| 617 | $html = '<textarea class="large-text" rows="10" id="wpp_settings[' . $args['id'] . ']" name="wpp_settings[' . $args['id'] . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
| 618 | } |
| 619 | |
| 620 | $html .= '<br/><label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 621 | |
| 622 | echo $html; |
| 623 | } |
| 624 | |
| 625 | /** |
| 626 | * @param $args |
| 627 | */ |
| 628 | function wpp_upload_callback( $args ) { |
| 629 | global $wpp_settings; |
| 630 | |
| 631 | $value = $wpp_settings[ $args['id'] ] ?? $args['std'] ?? ''; |
| 632 | $size = ( isset( $args['size'] ) ) ? $args['size'] : 'regular'; |
| 633 | $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 ) ) . '"/>'; |
| 634 | $html .= '<span> <input type="button" class="wpp_settings_upload_button button-secondary" value="' . __( 'Upload File', 'wpp' ) . '"/></span>'; |
| 635 | $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 636 | |
| 637 | echo $html; |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * @param $args |
| 642 | */ |
| 643 | function wpp_color_callback( $args ) { |
| 644 | global $wpp_settings; |
| 645 | |
| 646 | $value = $wpp_settings[ $args['id'] ] ?? $args['std'] ?? ''; |
| 647 | $default = $args['std'] ?? ''; |
| 648 | $size = ( isset( $args['size'] ) ) ? $args['size'] : 'regular'; |
| 649 | $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 ) . '" />'; |
| 650 | $html .= '<label for="wpp_settings[' . $args['id'] . ']"> ' . $args['desc'] . '</label>'; |
| 651 | |
| 652 | echo $html; |
| 653 | } |
| 654 | |
| 655 | function wpp_render_settings() { |
| 656 | $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], wpp_get_tabs() ) ? $_GET['tab'] : 'core'; |
| 657 | |
| 658 | ob_start(); |
| 659 | ?> |
| 660 | <?php settings_errors( 'wpp-notices' ); ?> |
| 661 | <div class="wrapp wpp-settings-wrap"> |
| 662 | <h2><?php _e( 'Parsi Settings', 'wp-parsidate' ) ?></h2> |
| 663 | <h2 class="nav-tab-wrapper"> |
| 664 | <?php |
| 665 | foreach ( wpp_get_tabs() as $tab_id => $tab_name ) { |
| 666 | |
| 667 | $tab_url = add_query_arg( array( |
| 668 | 'settings-updated' => false, |
| 669 | 'tab' => $tab_id, |
| 670 | ) ); |
| 671 | |
| 672 | $active = $active_tab == $tab_id ? ' nav-tab-active' : ''; |
| 673 | |
| 674 | echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( strip_tags( $tab_name ) ) . '" class="nav-tab' . $active . '">'; |
| 675 | echo $tab_name; |
| 676 | echo '</a>'; |
| 677 | } |
| 678 | ?> |
| 679 | </h2> |
| 680 | <div id="tab_container"> |
| 681 | <?php if ( 'about' !== $active_tab ) : ?> |
| 682 | <form method="post" action="options.php"> |
| 683 | <table class="form-table"> |
| 684 | <?php |
| 685 | settings_fields( 'wpp_settings' ); |
| 686 | do_settings_fields( 'wpp_settings_' . $active_tab, 'wpp_settings_' . $active_tab ); |
| 687 | ?> |
| 688 | </table> |
| 689 | <?php submit_button(); ?> |
| 690 | </form> |
| 691 | <?php else : ?> |
| 692 | <?php include WP_PARSI_DIR . 'includes/views/html-about.php'; ?> |
| 693 | <?php endif; ?> |
| 694 | </div><!-- #tab_container--> |
| 695 | </div><!-- .wrap --> |
| 696 | <?php |
| 697 | echo ob_get_clean(); |
| 698 | } |
| 699 | |
| 700 | /** |
| 701 | * Gets an option name and check that option is active or not |
| 702 | * |
| 703 | * @param $option_name |
| 704 | * |
| 705 | * @return bool |
| 706 | * @since 4.0.0 |
| 707 | */ |
| 708 | function wpp_is_active( $option_name ) { |
| 709 | global $wpp_settings; |
| 710 | |
| 711 | return ! empty( $wpp_settings[ $option_name ] ) && 'enable' === $wpp_settings[ $option_name ]; |
| 712 | } |
| 713 | |
| 714 | /** |
| 715 | * Gets an option name and returns the value |
| 716 | * |
| 717 | * @param $option_name |
| 718 | * |
| 719 | * @return string |
| 720 | * @since 4.0.1 |
| 721 | */ |
| 722 | function wpp_get_option( $option_name ) { |
| 723 | global $wpp_settings; |
| 724 | |
| 725 | return ! empty( $wpp_settings[ $option_name ] ) ? $wpp_settings[ $option_name ] : ''; |
| 726 | } |
| 727 | |
| 728 | /** |
| 729 | * Enqueue setting page style |
| 730 | * |
| 731 | * @param $hook |
| 732 | * |
| 733 | * @since 4.0.0 |
| 734 | */ |
| 735 | function wpp_enqueue_setting_page_style( $hook ) { |
| 736 | if ( ! in_array( $hook, array( 'toplevel_page_wp-parsi-settings', 'settings_page_wp-parsi-settings' ) ) ) { |
| 737 | return; |
| 738 | } |
| 739 | |
| 740 | $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) || wpp_is_active( 'dev_mode' ) ? '' : '.min'; |
| 741 | |
| 742 | wp_enqueue_style( 'wpp_option_page', WP_PARSI_URL . "assets/css/settings$suffix.css", null, WP_PARSI_VER ); |
| 743 | } |
| 744 | |
| 745 | function wpp_multilingual_compatibility_option( $old_settings ) { |
| 746 | if ( WP_Parsidate::wpp_multilingual_is_active() ) { |
| 747 | $settings = array( |
| 748 | 'wpp_multilingual_support' => array( |
| 749 | 'id' => 'wpp_multilingual_support', |
| 750 | 'name' => __( 'Multilingual compatibility', 'wp-parsidate' ), |
| 751 | 'type' => 'checkbox', |
| 752 | 'options' => 1, |
| 753 | 'std' => 0, |
| 754 | 'desc' => __( 'By enabling this, ParsiDate options only work in persian locale', 'wp-parsidate' ) |
| 755 | ), |
| 756 | ); |
| 757 | |
| 758 | return array_merge( $old_settings, $settings ); |
| 759 | } |
| 760 | |
| 761 | return $old_settings; |
| 762 | } |
| 763 | |
| 764 | add_filter( 'wpp_core_settings', 'wpp_multilingual_compatibility_option' ); |
| 765 |