Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. <?php
  2. /*
  3. List of available filters in WP Review plugin.
  4. You can use these filterns in your theme in funtions.php file
  5. and set different default settings.
  6. */
  7.  
  8. // Set colors for selected or all reviews
  9. function mts_new_review_colors($colors, $id) {
  10. $colors['bgcolor1'] = '#ff0000';
  11. return $colors;
  12. }
  13. add_filter( 'wp_review_colors', 'mts_new_review_colors', 10, 2 );
  14.  
  15. // Set location for selected or all reviews
  16. function mts_new_review_location($position, $id) {
  17. $position = 'bottom';
  18. return $position;
  19. }
  20. add_filter( 'wp_review_location', 'mts_new_review_location', 10, 2 );
  21.  
  22. // Hide fields in "item" meta box
  23. function mts_hide_item_metabox_fields($fields) {
  24. unset($fields['location'], $fields['fontcolor'], $fields['bordercolor']);
  25. // Or remove all (except features which can't be removed) with:
  26. // $fields = array();
  27. return $fields;
  28. }
  29. add_filter( 'wp_review_metabox_item_fields', 'mts_hide_item_metabox_fields' );
  30.  
  31. // Hide selected review types in metabox dropdown
  32. function mts_hide_review_types($types) {
  33. unset($types['point'], $types['percentage']); // remove types
  34. $types['star'] = __('Enable Reviews'); // Change label
  35. return $types;
  36. }
  37. add_filter( 'wp_review_metabox_types', 'mts_hide_review_types' );
  38.  
  39. // Add default criteria
  40. function mts_add_default_criteria($items) {
  41. $items = array(__('Audio'), __('Visual'), __('UX'), __('Price'));
  42. return $items;
  43. }
  44. add_filter( 'wp_review_default_criteria', 'mts_add_default_criteria' );
  45.  
  46. // Customize wp_review_show_total() output
  47. function mts_custom_review_total($content, $id, $type, $total) {
  48. if (get_the_title($id) == 'Special Post With Blue Rating') {
  49. $color = '#0000FF';
  50. $content = preg_replace('/"review-type-[^"]+"/', '$0 style="background-color: '.$color.';"', $content);
  51. }
  52. return $content;
  53. }
  54. add_filter('wp_review_show_total', 'mts_custom_review_total', 10, 4);
  55.  
  56. // Exclude post types
  57. function mts_wp_review_exclude_post_types($excluded) {
  58. // default: $excluded = array('attachment');
  59. $excluded[] = 'page'; // Don't allow reviews on pages
  60. return $excluded;
  61. }
  62. add_filter( 'wp_review_excluded_post_types', 'mts_wp_review_exclude_post_types' );
  63.  
  64. // Set the review options in your theme
  65. // These will be set as the global options for the plugin upon theme activation
  66. $new_options = array(
  67. 'colors' => array(
  68. 'color' => '#dd3333',
  69. 'fontcolor' => '#555555',
  70. 'bgcolor1' => '#e7e7e7',
  71. 'bgcolor2' => '#ffffff',
  72. 'bordercolor' => '#e7e7e7'
  73. )
  74. );
  75. if ( function_exists( 'wp_review_theme_defaults' )) wp_review_theme_defaults( $new_options );
  76.  
  77. /**
  78. * Add other Thing schema types
  79. *
  80. * @param array $schemas
  81. * @return array
  82. *
  83. * @link https://schema.org/docs/full.html See types under Thing
  84. */
  85. /*function mts_wp_review_add_custom_schema_type( array $schemas ) {
  86. $schemas['VideoGame'] = 'Video Game';
  87.  
  88. return $schemas;
  89. }
  90. add_filter( 'wp_review_schema_types', 'mts_wp_review_add_custom_schema_type', 11 );*/
  91.  
  92. /**
  93. * Editing/overriding the review box template
  94. *
  95. * Create a 'wp-review' directory in your (child) theme folder,
  96. * and make a copy there of /wp-review-pro/box-templates/default.php
  97. * to override it.
  98. *
  99. * Use different file name to add new template, which can be applied using filter:
  100. *
  101. */
  102. add_filter( 'wp_review_get_box_template', 'mts_wp_review_select_box_template', 10, 2 );
  103. function mts_wp_review_select_box_template( $template, $post_id ) {
  104. // Change box template for specific post
  105. if ( $post_id == '128' ) {
  106. $template = 'new-box.php';
  107. // "new-box.php" must be present in one of the template path folders (see below)
  108. }
  109. return $template;
  110. }
  111.  
  112. /**
  113. * Template Path Directories
  114. *
  115. * By default the plugin looks for box templates in:
  116. * 1. wp-review-pro/box-templates
  117. * 2. theme_dir/wp-review
  118. * 3. childtheme_dir/wp-review
  119. * 4... Use filter to add more
  120. *
  121. */
  122. add_filter( 'wp_review_box_template_paths', 'mts_wp_review_add_template_path', 10, 1 );
  123. function mts_wp_review_add_template_path( $paths ) {
  124. // Add a new path where we look for review box template files
  125. // The $paths holds default paths in reversed
  126. $paths[] = '/absolute/path/to/additional/templates/dir';
  127. return $paths;
  128. }
  129.  
  130. /**
  131. * Add new rating types with wp_review_register_rating_type()
  132. *
  133. * Refer to existing rating template files, e.g.
  134. * point-output.php, point-input.php
  135. */
  136. add_action( 'init', 'wp_review_register_additional_rating_types' );
  137. function wp_review_register_additional_rating_types() {
  138. wp_review_register_rating_type( 'star10', array(
  139. 'label' => __('10 Stars', 'wp-review'),
  140. 'max' => 10,
  141. 'decimals' => 1,
  142. 'value_text' => __('%s Stars', 'wp-review'),
  143. 'value_text_singular' => __('%s Star', 'wp-review'),
  144. 'input_template' => WP_REVIEW_DIR . 'rating-types/star10-input.php', // Replace with path to input template
  145. 'output_template' => WP_REVIEW_DIR . 'rating-types/star10-output.php', // Replace with path to output template
  146. ) );
  147. }
  148.  
  149. /**
  150. * Show post title as review heading when the review heading field is empty
  151. */
  152. add_filter( 'wp_review_item_title_fallback', 'wp_review_post_title_fallback', 10, 1 );
  153. function wp_review_post_title_fallback( $paths ) {
  154. return '<h5 class="review-title">'.get_the_title().'</h5>';
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement