You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

282 lines
7.4KB

  1. <?php // Prismatic - Settings Callbacks
  2. if (!defined('ABSPATH')) exit;
  3. function prismatic_section_general() {
  4. echo '<p>'. esc_html__('Thank you for using the free version of Prismatic.', 'prismatic') .'</p>';
  5. }
  6. function prismatic_section_prism() {
  7. echo '<p>'. esc_html__('Settings for syntax highlighting via', 'prismatic') .' <a target="_blank" href="http://prismjs.com/">'. esc_html__('Prism.js', 'prismatic') .'</a>.';
  8. }
  9. function prismatic_section_prism_code() {
  10. echo '<p>'. esc_html__('Settings for code escaping when Prism.js is enabled.', 'prismatic');
  11. }
  12. function prismatic_section_highlight() {
  13. echo '<p>'. esc_html__('Settings for syntax highlighting via', 'prismatic') .' <a target="_blank" href="https://highlightjs.org/">'. esc_html__('Highlight.js', 'prismatic') .'</a>.';
  14. }
  15. function prismatic_section_highlight_code() {
  16. echo '<p>'. esc_html__('Settings for code escaping when Highlight.js is enabled.', 'prismatic');
  17. }
  18. function prismatic_section_plain() {
  19. echo '<p>'. esc_html__('Settings for code escaping without syntax highlighting.', 'prismatic') .'</p>';
  20. }
  21. function prismatic_library() {
  22. $library = array(
  23. 'prism' => array(
  24. 'value' => 'prism',
  25. 'label' => esc_html__('Prism.js', 'prismatic'),
  26. ),
  27. 'highlight' => array(
  28. 'value' => 'highlight',
  29. 'label' => esc_html__('Highlight.js', 'prismatic'),
  30. ),
  31. 'plain' => array(
  32. 'value' => 'plain',
  33. 'label' => esc_html__('Plain Flavor', 'prismatic'),
  34. ),
  35. 'none' => array(
  36. 'value' => 'none',
  37. 'label' => esc_html__('None (Disable)', 'prismatic'),
  38. ),
  39. );
  40. return $library;
  41. }
  42. function prismatic_location() {
  43. $array = array(
  44. 'front' => array(
  45. 'value' => 'front',
  46. 'label' => esc_html__('Frontend only', 'prismatic'),
  47. ),
  48. 'admin' => array(
  49. 'value' => 'admin',
  50. 'label' => esc_html__('Admin Area only', 'prismatic'),
  51. ),
  52. 'both' => array(
  53. 'value' => 'both',
  54. 'label' => esc_html__('Frontend &amp; Admin Area', 'prismatic'),
  55. ),
  56. 'none' => array(
  57. 'value' => 'none',
  58. 'label' => esc_html__('None (Disable)', 'prismatic'),
  59. ),
  60. );
  61. return $array;
  62. }
  63. function prismatic_prism_theme() {
  64. $theme = array(
  65. 'coy' => array(
  66. 'value' => 'coy',
  67. 'label' => esc_html__('Coy', 'prismatic'),
  68. ),
  69. 'dark' => array(
  70. 'value' => 'dark',
  71. 'label' => esc_html__('Dark', 'prismatic'),
  72. ),
  73. 'default' => array(
  74. 'value' => 'default',
  75. 'label' => esc_html__('Default', 'prismatic'),
  76. ),
  77. 'funky' => array(
  78. 'value' => 'funky',
  79. 'label' => esc_html__('Funky', 'prismatic'),
  80. ),
  81. 'okaidia' => array(
  82. 'value' => 'okaidia',
  83. 'label' => esc_html__('Okaidia', 'prismatic'),
  84. ),
  85. 'solarized' => array(
  86. 'value' => 'solarized',
  87. 'label' => esc_html__('Solarized', 'prismatic'),
  88. ),
  89. 'twilight' => array(
  90. 'value' => 'twilight',
  91. 'label' => esc_html__('Twilight', 'prismatic'),
  92. ),
  93. );
  94. return $theme;
  95. }
  96. function prismatic_highlight_theme() {
  97. require_once PRISMATIC_DIR .'lib/highlight/themes.php';
  98. return $theme;
  99. }
  100. function prismatic_callback_select($args) {
  101. $id = isset($args['id']) ? $args['id'] : '';
  102. $label = isset($args['label']) ? $args['label'] : '';
  103. $section = isset($args['section']) ? $args['section'] : '';
  104. $setting = 'prismatic_options_'. $section;
  105. global ${$setting};
  106. $options = ${$setting};
  107. $value = isset($options[$id]) ? sanitize_text_field($options[$id]) : '';
  108. $options_array = array();
  109. if ($id === 'library') {
  110. $options_array = prismatic_library();
  111. } elseif ($id === 'filter_content' || $id === 'filter_excerpts' || $id === 'filter_comments') {
  112. $options_array = prismatic_location();
  113. } elseif ($id === 'prism_theme') {
  114. $options_array = prismatic_prism_theme();
  115. } elseif ($id === 'highlight_theme') {
  116. $options_array = prismatic_highlight_theme();
  117. }
  118. echo '<select name="'. $setting .'['. $id .']">';
  119. foreach ($options_array as $option) {
  120. echo '<option '. selected($option['value'], $value, false) .' value="'. $option['value'] .'">'. $option['label'] .'</option>';
  121. }
  122. echo '</select> <label class="prismatic-label inline-block" for="'. $setting .'['. $id .']">'. $label .'</label>';
  123. }
  124. function prismatic_callback_text($args) {
  125. $id = isset($args['id']) ? $args['id'] : '';
  126. $label = isset($args['label']) ? $args['label'] : '';
  127. $section = isset($args['section']) ? $args['section'] : '';
  128. $setting = 'prismatic_options_'. $section;
  129. global ${$setting};
  130. $options = ${$setting};
  131. $value = isset($options[$id]) ? sanitize_text_field($options[$id]) : '';
  132. echo '<input name="'. $setting .'['. $id .']" type="text" size="40" value="'. $value .'"> ';
  133. echo '<label for="'. $setting .'['. $id .']" class="prismatic-label">'. $label .'</label>';
  134. }
  135. function prismatic_callback_textarea($args) {
  136. $id = isset($args['id']) ? $args['id'] : '';
  137. $label = isset($args['label']) ? $args['label'] : '';
  138. $section = isset($args['section']) ? $args['section'] : '';
  139. $setting = 'prismatic_options_'. $section;
  140. global ${$setting};
  141. $options = ${$setting};
  142. $allowed_tags = wp_kses_allowed_html('post');
  143. $value = isset($options[$id]) ? wp_kses(stripslashes_deep($options[$id]), $allowed_tags) : '';
  144. echo '<textarea name="'. $setting .'['. $id .']" rows="3" cols="50">'. $value .'</textarea> ';
  145. echo '<label for="'. $setting .'['. $id .']" class="prismatic-label" >'. $label .'</label>';
  146. }
  147. function prismatic_callback_checkbox($args) {
  148. $id = isset($args['id']) ? $args['id'] : '';
  149. $label = isset($args['label']) ? $args['label'] : '';
  150. $section = isset($args['section']) ? $args['section'] : '';
  151. $setting = 'prismatic_options_'. $section;
  152. global ${$setting};
  153. $options = ${$setting};
  154. $checked = isset($options[$id]) ? checked($options[$id], 1, false) : '';
  155. echo '<input name="'. $setting .'['. $id .']" value="1" type="checkbox" '. $checked .'> ';
  156. echo '<label for="'. $setting .'['. $id .']" class="prismatic-label inline-block">'. $label .'</label>';
  157. }
  158. function prismatic_callback_number($args) {
  159. $id = isset($args['id']) ? $args['id'] : '';
  160. $label = isset($args['label']) ? $args['label'] : '';
  161. $section = isset($args['section']) ? $args['section'] : '';
  162. $setting = 'prismatic_options_'. $section;
  163. global ${$setting};
  164. $options = ${$setting};
  165. $value = isset($options[$id]) ? sanitize_text_field($options[$id]) : '';
  166. $min = 0;
  167. $max = 999;
  168. echo '<input name="'. $setting .'['. $id .']" type="number" min="'. $min .'" max="'. $max .'" value="'. $value .'"> ';
  169. echo '<label for="'. $setting .'['. $id .']" class="prismatic-label inline-block">'. $label .'</label>';
  170. }
  171. function prismatic_callback_reset($args) {
  172. $nonce = wp_create_nonce('prismatic_reset_options');
  173. $url = admin_url('options-general.php?page=prismatic');
  174. $href = esc_url(add_query_arg(array('reset-options-verify' => $nonce), $url));
  175. echo '<a class="prismatic-reset-options" href="'. $href .'">'. esc_html__('Restore default plugin options', 'prismatic') .'</a>';
  176. }
  177. function prismatic_callback_rate($args) {
  178. $href = 'https://wordpress.org/support/plugin/'. PRISMATIC_SLUG .'/reviews/?rate=5#new-post';
  179. $title = esc_attr__('Help keep Prismatic going strong! A huge THANK YOU for your support!', 'prismatic');
  180. $text = isset($args['label']) ? $args['label'] : esc_html__('Show support with a 5-star rating &raquo;', 'prismatic');
  181. echo '<a target="_blank" class="prismatic-rate-plugin" href="'. $href .'" title="'. $title .'">'. $text .'</a>';
  182. }