/wp-content/plugins/jetpack/modules/after-the-deadline/config-options.php

https://gitlab.com/juanito.abelo/nlmobile · PHP · 128 lines · 85 code · 22 blank · 21 comment · 10 complexity · 039a9325fa7a1b95aff8a9dcf50bec18 MD5 · raw file

  1. <?php
  2. /*
  3. * Display the configuration options for AtD
  4. */
  5. /*
  6. * A convienence function to display the HTML for an AtD option
  7. */
  8. function AtD_print_option( $name, $value, $options ) {
  9. // Attribute-safe version of $name
  10. $attr_name = sanitize_title($name); // Using sanitize_title since there's no comparable function for attributes
  11. ?>
  12. <input type="checkbox" id="atd_<?php echo esc_attr( $attr_name ) ?>" name="<?php echo esc_attr( $options['name'] ); ?>[<?php echo esc_attr( $name ); ?>]" value="1" <?php checked( '1', isset( $options[$name] ) ? $options[$name] : false ); ?>> <label for="atd_<?php echo esc_attr( $attr_name ); ?>"><?php echo esc_html( $value ); ?></label>
  13. <?php
  14. }
  15. /*
  16. * Save AtD options
  17. */
  18. function AtD_process_options_update() {
  19. $user = wp_get_current_user();
  20. if ( ! $user || $user->ID == 0 )
  21. return;
  22. AtD_update_options( $user->ID, 'AtD_options' );
  23. AtD_update_options( $user->ID, 'AtD_check_when' );
  24. AtD_update_options( $user->ID, 'AtD_guess_lang' );
  25. }
  26. /*
  27. * Display the various AtD options
  28. */
  29. function AtD_display_options_form() {
  30. /* grab our user and validate their existence */
  31. $user = wp_get_current_user();
  32. if ( ! $user || $user->ID == 0 )
  33. return;
  34. $options_show_types = AtD_get_options( $user->ID, 'AtD_options' );
  35. $options_check_when = AtD_get_options( $user->ID, 'AtD_check_when' );
  36. $options_guess_lang = AtD_get_options( $user->ID, 'AtD_guess_lang' );
  37. ?>
  38. <table class="form-table">
  39. <tr valign="top">
  40. <th scope="row"> <a id="atd"></a> <?php _e( 'Proofreading', 'jetpack' ); ?></th>
  41. <td>
  42. <p><?php _e( 'Automatically proofread content when:', 'jetpack' ); ?>
  43. <p><?php
  44. AtD_print_option( 'onpublish', __('a post or page is first published', 'jetpack'), $options_check_when );
  45. echo '<br />';
  46. AtD_print_option( 'onupdate', __('a post or page is updated', 'jetpack'), $options_check_when );
  47. ?></p>
  48. <p style="font-weight: bold"><?php _e('English Options', 'jetpack'); ?></font>
  49. <p><?php _e('Enable proofreading for the following grammar and style rules when writing posts and pages:', 'jetpack'); ?></p>
  50. <p><?php
  51. AtD_print_option( 'Bias Language', __('Bias Language', 'jetpack'), $options_show_types );
  52. echo '<br />';
  53. AtD_print_option( 'Cliches', __('Clich&eacute;s', 'jetpack'), $options_show_types );
  54. echo '<br />';
  55. AtD_print_option( 'Complex Expression', __('Complex Phrases', 'jetpack'), $options_show_types );
  56. echo '<br />';
  57. AtD_print_option( 'Diacritical Marks', __('Diacritical Marks', 'jetpack'), $options_show_types );
  58. echo '<br />';
  59. AtD_print_option( 'Double Negative', __('Double Negatives', 'jetpack'), $options_show_types );
  60. echo '<br />';
  61. AtD_print_option( 'Hidden Verbs', __('Hidden Verbs', 'jetpack'), $options_show_types );
  62. echo '<br />';
  63. AtD_print_option( 'Jargon Language', __('Jargon', 'jetpack'), $options_show_types );
  64. echo '<br />';
  65. AtD_print_option( 'Passive voice', __('Passive Voice', 'jetpack'), $options_show_types );
  66. echo '<br />';
  67. AtD_print_option( 'Phrases to Avoid', __('Phrases to Avoid', 'jetpack'), $options_show_types );
  68. echo '<br />';
  69. AtD_print_option( 'Redundant Expression', __('Redundant Phrases', 'jetpack'), $options_show_types );
  70. ?></p>
  71. <p><?php printf( __( '<a href="%s">Learn more</a> about these options.', 'jetpack' ), 'http://support.wordpress.com/proofreading/' );
  72. ?></p>
  73. <p style="font-weight: bold"><?php _e( 'Language', 'jetpack' ); ?></font>
  74. <p><?php
  75. _e( 'The proofreader supports English, French, German, Portuguese, and Spanish. Your user interface language (see above) is the default proofreading language.', 'jetpack' );
  76. ?></p>
  77. <p><?php
  78. AtD_print_option( 'true', __('Use automatically detected language to proofread posts and pages', 'jetpack' ), $options_guess_lang );
  79. ?></p>
  80. <?php
  81. }
  82. /*
  83. * Returns an array of AtD user options specified by $name
  84. */
  85. function AtD_get_options( $user_id, $name ) {
  86. $options_raw = AtD_get_setting( $user_id, $name, 'single' );
  87. $options = array();
  88. $options['name'] = $name;
  89. if ( $options_raw )
  90. foreach ( explode( ',', $options_raw ) as $option )
  91. $options[ $option ] = 1;
  92. return $options;
  93. }
  94. /*
  95. * Saves set of user options specified by $name from POST data
  96. */
  97. function AtD_update_options( $user_id, $name ) {
  98. /* We should probably run $_POST[name] through an esc_*() function... */
  99. if ( isset( $_POST[$name] ) && is_array( $_POST[$name] ) ) {
  100. $copy = array_map( 'strip_tags', array_keys( $_POST[$name] ) );
  101. AtD_update_setting( $user_id, AtD_sanitize( $name ), implode( ',', $copy ) );
  102. } else {
  103. AtD_update_setting( $user_id, AtD_sanitize( $name ), '');
  104. }
  105. return;
  106. }