/modules/after-the-deadline/config-options.php

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