Changeset 2072651
- Timestamp:
- 04/22/2019 03:25:41 PM (6 years ago)
- Location:
- better-reviews-for-woocommerce
- Files:
-
- 84 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
better-reviews-for-woocommerce/trunk/CHANGELOG.md
r2064761 r2072651 5 5 This project adheres to [Semantic Versioning](http://semver.org/). 6 6 7 ##[0.2.0] 8 9 * adding CLI command for converting existing reviews. 10 * including review data in WooCommerce structured data. 11 * removed duplicate queries, general cleanup. 12 7 13 ## [0.1.0] 8 14 -
better-reviews-for-woocommerce/trunk/includes/admin/admin-assets.php
r2064761 r2072651 7 7 8 8 // Declare our namespace. 9 namespace LiquidWeb\WooBetterReviews\Admin \AdminAssets;9 namespace LiquidWeb\WooBetterReviews\AdminAssets; 10 10 11 11 // Set our aliases. -
better-reviews-for-woocommerce/trunk/includes/admin/admin-notices.php
r2064761 r2072651 7 7 8 8 // Declare our namespace. 9 namespace LiquidWeb\WooBetterReviews\Admin \AdminNotices;9 namespace LiquidWeb\WooBetterReviews\AdminNotices; 10 10 11 11 // Set our aliases. -
better-reviews-for-woocommerce/trunk/includes/admin/admin-pages.php
r2064761 r2072651 7 7 8 8 // Declare our namespace. 9 namespace LiquidWeb\WooBetterReviews\Admin \AdminPages;9 namespace LiquidWeb\WooBetterReviews\AdminPages; 10 10 11 11 // Set our aliases. -
better-reviews-for-woocommerce/trunk/includes/admin/menu-items.php
r2064761 r2072651 12 12 use LiquidWeb\WooBetterReviews as Core; 13 13 use LiquidWeb\WooBetterReviews\Helpers as Helpers; 14 use LiquidWeb\WooBetterReviews\Admin \AdminPages as AdminPages;14 use LiquidWeb\WooBetterReviews\AdminPages as AdminPages; 15 15 16 16 // And pull in any other namespaces. -
better-reviews-for-woocommerce/trunk/includes/display/form-data.php
r2064761 r2072651 7 7 8 8 // Declare our namespace. 9 namespace LiquidWeb\WooBetterReviews\ Display\FormData;9 namespace LiquidWeb\WooBetterReviews\FormData; 10 10 11 11 // Set our aliases. -
better-reviews-for-woocommerce/trunk/includes/display/form-fields.php
r2064761 r2072651 7 7 8 8 // Declare our namespace. 9 namespace LiquidWeb\WooBetterReviews\ Display\FormFields;9 namespace LiquidWeb\WooBetterReviews\FormFields; 10 10 11 11 // Set our aliases. -
better-reviews-for-woocommerce/trunk/includes/display/view-output.php
r2064761 r2072651 7 7 8 8 // Declare our namespace. 9 namespace LiquidWeb\WooBetterReviews\ Display\ViewOutput;9 namespace LiquidWeb\WooBetterReviews\ViewOutput; 10 10 11 11 // Set our aliases. … … 14 14 use LiquidWeb\WooBetterReviews\Utilities as Utilities; 15 15 use LiquidWeb\WooBetterReviews\Queries as Queries; 16 use LiquidWeb\WooBetterReviews\ Display\FormFields as FormFields;17 use LiquidWeb\WooBetterReviews\ Display\LayoutReviewList as LayoutReviewList;18 use LiquidWeb\WooBetterReviews\ Display\LayoutReviewAggregate as LayoutReviewAggregate;19 use LiquidWeb\WooBetterReviews\ Display\LayoutNewReviewForm as LayoutNewReviewForm;20 use LiquidWeb\WooBetterReviews\ Display\LayoutSingleReview as LayoutSingleReview;16 use LiquidWeb\WooBetterReviews\FormFields as FormFields; 17 use LiquidWeb\WooBetterReviews\Layout\ReviewList as LayoutReviewList; 18 use LiquidWeb\WooBetterReviews\Layout\ReviewAggregate as LayoutReviewAggregate; 19 use LiquidWeb\WooBetterReviews\Layout\NewReviewForm as LayoutNewReviewForm; 20 use LiquidWeb\WooBetterReviews\Layout\SingleReview as LayoutSingleReview; 21 21 22 22 // And pull in any other namespaces. … … 254 254 $build .= '<div id="' . sanitize_html_class( 'woo-better-reviews-single-' . absint( $single_review['review_id'] ) ) . '" class="' . esc_attr( $class ) . '">'; 255 255 256 // Handle the "before" display. 257 $build .= apply_filters( Core\HOOK_PREFIX . 'before_single_review_output', null, $single_review, $product_id ); 258 256 259 // Output the title. 257 260 $build .= LayoutSingleReview\set_single_review_header_view( $single_review ); … … 265 268 // Output the author characteristics. 266 269 $build .= LayoutSingleReview\set_single_review_author_charstcs_view( $single_review ); 270 271 // Handle the "after" display. 272 $build .= apply_filters( Core\HOOK_PREFIX . 'after_single_review_output', null, $single_review, $product_id ); 267 273 268 274 // Close the single review div. -
better-reviews-for-woocommerce/trunk/includes/process/admin-process.php
r2064761 r2072651 7 7 8 8 // Declare our namespace. 9 namespace LiquidWeb\WooBetterReviews\Admin \AdminProcess;9 namespace LiquidWeb\WooBetterReviews\AdminProcess; 10 10 11 11 // Set our aliases. -
better-reviews-for-woocommerce/trunk/includes/process/cli-commands.php
r2064761 r2072651 15 15 use LiquidWeb\WooBetterReviews\Queries as Queries; 16 16 use LiquidWeb\WooBetterReviews\Database as Database; 17 use LiquidWeb\WooBetterReviews\ConvertExisting as ConvertExisting; 17 18 18 19 // Pull in the CLI items. … … 248 249 249 250 /** 251 * Convert the existing comment-based reviews. 252 * 253 * ## OPTIONS 254 * 255 * [--cleanup] 256 * : How to handle the cleanup of the existing. 257 * --- 258 * default: convert 259 * options: 260 * - convert 261 * - purge 262 * --- 263 * 264 * ## EXAMPLES 265 * 266 * wp woo-better-reviews convert 267 * wp woo-better-reviews convert --cleanup=convert 268 * wp woo-better-reviews convert --cleanup=purge 269 * 270 * @when after_wp_load 271 */ 272 function convert( $args = array(), $assoc_args = array() ) { 273 274 // Parse out the associatives. 275 $parse_cli_args = wp_parse_args( $assoc_args, array( 276 'cleanup' => 'convert', 277 )); 278 279 // Make sure the cleanup argument exists. 280 if ( empty( $parse_cli_args['cleanup'] ) ) { 281 WP_CLI::error( __( 'The required cleanup type was missing. Please try again.', 'woo-better-reviews' ) ); 282 } 283 284 // Make sure the cleanup argument is valid. 285 if ( ! in_array( esc_attr( $parse_cli_args['cleanup'] ), array( 'convert', 'purge' ) ) ) { 286 WP_CLI::error( __( 'An invalid cleanup type was requested. Please try again.', 'woo-better-reviews' ) ); 287 } 288 289 // Check for the purge and convert flags. 290 $maybe_do_type = 'convert' === esc_attr( $parse_cli_args['cleanup'] ) ? true : false; 291 $maybe_do_purge = 'purge' === esc_attr( $parse_cli_args['cleanup'] ) ? true : false; 292 293 // Handle a confirm for the purge flag. 294 if ( false !== $maybe_do_purge ) { 295 WP_CLI::confirm( __( 'Are you sure you want to purge the existing reviews? THIS CANNOT BE UNDONE.', 'woo-better-reviews' ), $assoc_args ); 296 } 297 298 // The function itself is a single function, since 299 // this is just a wrapper for the conversion function. 300 $maybe_convert = ConvertExisting\attempt_existing_review_conversion( $maybe_do_type, $maybe_do_purge ); 301 302 // First look for the 'no-reviews' string. If is 303 // exists, display the 'none' message and halt. 304 if ( 'no-reviews' === esc_attr( $maybe_convert ) ) { 305 WP_CLI::line( __( 'No existing reviews exist to convert.', 'woo-better-reviews' ) ); 306 WP_CLI::halt( 0 ); 307 } 308 309 // If we have an actual empty return, display 310 // the blank error message and halt. 311 if ( empty( $maybe_convert ) ) { 312 WP_CLI::error( __( 'The attempted conversion returned an empty result.', 'woo-better-reviews' ) ); 313 } 314 315 // Handle a WP_Error object return. 316 if ( is_wp_error( $maybe_convert ) ) { 317 318 // Get my error code and message. 319 $wp_error_code = $maybe_convert->get_error_code(); 320 $wp_error_text = $maybe_convert->get_error_message(); 321 322 // Build my return message. 323 $return_message = sprintf( __( '%1$s | ERR_CODE %2$s', 'woo-better-reviews' ), esc_attr( $error_text ), esc_attr( $error_code ) ); 324 325 // Display the formatted error message. 326 WP_CLI::error( esc_attr( $return_message ) ); 327 } 328 329 // If we have the success flag, return that. 330 if ( ! empty( $maybe_convert['success'] ) ) { 331 332 // Determine the message. 333 $return_message = ! empty( $maybe_convert['message'] ) ? $maybe_convert['message'] : __( 'The existing reviews have been converted.', 'woo-better-reviews' ); 334 335 // Show the result and bail. 336 WP_CLI::success( esc_attr( $return_message ) ); 337 WP_CLI::halt( 0 ); 338 } 339 340 // Display our "unknown" error. 341 WP_CLI::error( __( 'The conversion has completed but there was no results returned. Please check the status manually.', 'woo-better-reviews' ) ); 342 } 343 344 /** 250 345 * This is a placeholder function for testing. 251 346 * -
better-reviews-for-woocommerce/trunk/includes/process/convert-existing.php
r2064761 r2072651 7 7 8 8 // Declare our namespace. 9 namespace LiquidWeb\WooBetterReviews\ Display\ConvertExisting;9 namespace LiquidWeb\WooBetterReviews\ConvertExisting; 10 10 11 11 // Set our aliases. … … 22 22 * Convert the existing comment-based reviews to our new ones. 23 23 * 24 * @param boolean $convert_type Whether to convert the type the existing. 25 * @param boolean $purge_existing Whether to actually purge the existing. 26 * 24 27 * @return mixed 25 28 */ 26 function process_existing_review_conversion() { 29 function attempt_existing_review_conversion( $convert_type = true, $purge_existing = false ) { 30 31 // If both the convert AND purge flags are set to "false", error out. 32 if ( false === $convert_type && false === $purge_existing ) { 33 return new WP_Error( 'invalid-conversion-args', __( 'The existing reviews must either be converted or purged. Please select one.', 'woo-better-reviews' ) ); 34 } 35 36 // If both the convert AND purge flags are set to "true", error out. 37 if ( false !== $convert_type && false !== $purge_existing ) { 38 return new WP_Error( 'invalid-conversion-args', __( 'The existing reviews can either be converted or purged, not both. Please choose one.', 'woo-better-reviews' ) ); 39 } 27 40 28 41 // Set my lookup args. … … 36 49 $maybe_cmns = get_comments( $setup_args ); 37 50 38 // Bail and fail without.51 // Bail with a 'no-reviews' string to look for later. 39 52 if ( empty( $maybe_cmns ) ) { 40 return new WP_Error( 'no-existing-reviews', __( 'There are no existing reviews to convert.', 'woo-better-reviews' ) );53 return 'no-reviews'; 41 54 } 42 55 … … 137 150 } 138 151 152 // Set and sanitize my product ID array. 153 $product_id_array = array_unique( $pids ); 154 139 155 // Handle our functions related to the product ID array. 140 update_products_post_conversion( $p ids);156 update_products_post_conversion( $product_id_array, $convert_type, $purge_existing ); 141 157 142 158 // Now delete my big list of review data cached. … … 146 162 $return_msg = sprintf( _n( '%d review converted.', '%d reviews converted.', absint( $ccount ), 'woo-better-reviews' ), absint( $ccount ) ); 147 163 148 die( $return_msg ); // @@todo what are we gonna do here? 164 // Return an array with a success flag included. 165 return array( 166 'success' => 1, 167 'message' => $return_msg, 168 'count' => $ccount, 169 'product-ids' => $product_id_array, 170 ); 149 171 } 150 172 … … 383 405 * Run all the various cleanup and recalculating functions on products. 384 406 * 385 * @param array $product_ids All the product IDs. 407 * @param array $product_ids All the product IDs. 408 * @param boolean $convert_type Whether to convert the comment type. 409 * @param boolean $purge_existing Whether to actually purge the existing. 386 410 * 387 411 * @return void 388 412 */ 389 function update_products_post_conversion( $product_ids = array() ) {413 function update_products_post_conversion( $product_ids = array(), $convert_type = true, $purge_existing = false ) { 390 414 391 415 // Bail if we don't have product IDs. … … 394 418 } 395 419 396 // Make sure we have unique IDs.397 $unique_ids = array_unique( $product_ids );398 399 420 // Update all my counts. 400 Utilities\update_product_review_count( $ unique_ids );421 Utilities\update_product_review_count( $product_ids ); 401 422 402 423 // Loop the product IDs and run our functions. 403 foreach ( $ unique_ids as $unique_id ) {424 foreach ( $product_ids as $product_id ) { 404 425 405 426 // If we don't have the correct product type, skip. 406 if ( 'product' !== get_post_type( $ unique_id ) ) {427 if ( 'product' !== get_post_type( $product_id ) ) { 407 428 continue; 408 429 } 409 430 410 431 // Convert the existing comment review IDs. 411 $converted = convert_legacy_review_ids( $unique_id ); 432 if ( false !== $convert_type ) { 433 convert_legacy_review_ids( $product_id ); 434 } 435 436 // Purge the existing review IDs. 437 if ( false !== $purge_existing ) { 438 purge_legacy_review_ids( $product_id ); 439 } 412 440 413 441 // Recalculate the total score on each. 414 Utilities\calculate_total_review_scoring( $ unique_id );442 Utilities\calculate_total_review_scoring( $product_id ); 415 443 416 444 // Handle purging product and author related transients. 417 Utilities\purge_transients( null, 'products', array( 'ids' => (array) $ unique_id ) );418 Utilities\purge_transients( null, 'authors', array( 'ids' => (array) $ unique_id ) );445 Utilities\purge_transients( null, 'products', array( 'ids' => (array) $product_id ) ); 446 Utilities\purge_transients( null, 'authors', array( 'ids' => (array) $product_id ) ); 419 447 } 420 448 … … 454 482 do_action( Core\HOOK_PREFIX . 'before_legacy_review_converted', $existing_id ); 455 483 456 // Set the individual update args. 457 // This oddapproval flag hides them without deleting.484 // Set the individual update args. This odd 485 // approval flag hides them without deleting. 458 486 $setup_args = array( 459 487 'comment_ID' => absint( $existing_id ), … … 481 509 return $update; 482 510 } 511 512 /** 513 * Get all the stored legacy IDs and purge the original comment. 514 * 515 * @param integer $product_id The product ID being related to. 516 * 517 * @return void 518 */ 519 function purge_legacy_review_ids( $product_id = 0 ) { 520 521 // Bail if parts are missing. 522 if ( empty( $product_id ) ) { 523 return; 524 } 525 526 // Get my existing items. 527 $existing_ids = get_post_meta( $product_id, Core\META_PREFIX . 'legacy_review_ids', true ); 528 529 // Bail if no legacy IDs exist. 530 if ( empty( $existing_ids ) ) { 531 return; 532 } 533 534 // Set a delete count. 535 $delete = 0; 536 537 // Loop and set our update args. 538 foreach ( $existing_ids as $existing_id ) { 539 540 // Include a 'before' hook. 541 do_action( Core\HOOK_PREFIX . 'before_legacy_review_purge', $existing_id ); 542 543 // Run the actual comment delete. 544 $run_update = wp_delete_comment( $existing_id, true ); 545 546 // Increment the count if we had success. 547 if ( false !== $run_update ) { 548 $delete++; 549 } 550 551 // Include an 'after' hook. 552 do_action( Core\HOOK_PREFIX . 'after_legacy_review_purge', $existing_id ); 553 554 // @@todo maybe do some error checking here. 555 } 556 557 // Return the total deleted count. 558 return $delete; 559 } -
better-reviews-for-woocommerce/trunk/includes/process/form-process.php
r2064761 r2072651 7 7 8 8 // Declare our namespace. 9 namespace LiquidWeb\WooBetterReviews\ Display\FormProcess;9 namespace LiquidWeb\WooBetterReviews\FormProcess; 10 10 11 11 // Set our aliases. -
better-reviews-for-woocommerce/trunk/includes/queries.php
r2064761 r2072651 880 880 881 881 /** 882 * Get some recent reviews for a given product ID. 883 * 884 * @param integer $product_id Which product ID we are looking up. 885 * @param string $return_type What type of return we want. Accepts "counts", "objects", or fields. 886 * @param boolean $date_order If the date order should be maintained on the field returns. 887 * @param boolean $purge Optional to purge the cache'd version before looking up. 888 * 889 * @return mixed 890 */ 891 function get_recent_reviews_for_product( $product_id = 0, $return_type = 'objects', $date_order = true, $purge = false ) { 892 893 // Bail without a product ID. 894 if ( empty( $product_id ) ) { 895 return new WP_Error( 'missing_product_id', __( 'A product ID is required.', 'woo-better-reviews' ) ); 896 } 897 898 // Set the key to use in our transient. 899 $ky = Core\HOOK_PREFIX . 'recent_reviews_for_product_' . absint( $product_id ); 900 901 // If we don't want the cache'd version, delete the transient first. 902 if ( defined( 'WP_DEBUG' ) && WP_DEBUG || ! empty( $purge ) ) { 903 delete_transient( $ky ); 904 } 905 906 // Attempt to get the reviews from the cache. 907 $cached_dataset = get_transient( $ky ); 908 909 // If we have none, do the things. 910 if ( false === $cached_dataset ) { 911 912 // Call the global database. 913 global $wpdb; 914 915 // Set our table name. 916 $table_name = $wpdb->prefix . Core\TABLE_PREFIX . 'content'; 917 918 // Set up our query. 919 $query_args = $wpdb->prepare(" 920 SELECT * 921 FROM $table_name 922 WHERE product_id = '%d' 923 AND review_status = '%s' 924 ORDER BY review_date DESC 925 LIMIT 5 926 ", absint( $product_id ), esc_attr( 'approved' ) ); 927 928 // Process the query. 929 $query_run = $wpdb->get_results( $query_args ); 930 931 // Bail without any reviews. 932 if ( empty( $query_run ) ) { 933 return false; 934 } 935 936 // Set our transient with our data. 937 set_transient( $ky, $query_run, HOUR_IN_SECONDS ); 938 939 // And change the variable to do the things. 940 $cached_dataset = $query_run; 941 } 942 943 // Now switch between my return types. 944 switch ( sanitize_text_field( $return_type ) ) { 945 946 case 'counts' : 947 return count( $cached_dataset ); 948 break; 949 950 case 'objects' : 951 return $cached_dataset; 952 break; 953 954 case 'display' : 955 return merge_review_object_taxonomies( $cached_dataset ); 956 break; 957 958 case 'ids' : 959 960 // Set my query list. 961 $query_list = wp_list_pluck( $cached_dataset, 'review_id', null ); 962 963 // Sort my list assuming we didn't want date order. 964 if ( ! $date_order ) { 965 sort( $query_list ); 966 } 967 968 // Return my list, sorted. 969 return $query_list; 970 break; 971 972 case 'slugs' : 973 974 // Set my query list. 975 $query_list = wp_list_pluck( $cached_dataset, 'review_slug', 'review_id' ); 976 977 // Sort my list assuming we didn't want date order. 978 if ( ! $date_order ) { 979 ksort( $query_list ); 980 } 981 982 // Return my list, sorted. 983 return $query_list; 984 break; 985 986 case 'titles' : 987 988 // Set my query list. 989 $query_list = wp_list_pluck( $cached_dataset, 'review_title', 'review_id' ); 990 991 // Sort my list assuming we didn't want date order. 992 if ( ! $date_order ) { 993 ksort( $query_list ); 994 } 995 996 // Return my list, sorted. 997 return $query_list; 998 break; 999 1000 case 'content' : 1001 1002 // Set my query list. 1003 $query_list = wp_list_pluck( $cached_dataset, 'review_content', 'review_id' ); 1004 1005 // Sort my list assuming we didn't want date order. 1006 if ( ! $date_order ) { 1007 ksort( $query_list ); 1008 } 1009 1010 // Return my list, sorted. 1011 return $query_list; 1012 break; 1013 1014 case 'authors' : 1015 1016 // Set my query list. 1017 $query_list = wp_list_pluck( $cached_dataset, 'author_id', 'review_id' ); 1018 1019 // Sort my list assuming we didn't want date order. 1020 if ( ! $date_order ) { 1021 ksort( $query_list ); 1022 } 1023 1024 // Return my list, sorted. 1025 return $query_list; 1026 break; 1027 1028 // No more case breaks, no more return types. 1029 } 1030 1031 // No reason we should get down this far but here we go. 1032 return false; 1033 } 1034 1035 /** 882 1036 * Get all the verified reviews. 883 1037 * … … 1445 1599 break; 1446 1600 1601 case 'indexed' : 1602 1603 // First get the IDs. 1604 $id_index = wp_list_pluck( $cached_dataset, 'attribute_id', null ); 1605 1606 // Return it with our IDs as the index. 1607 return array_combine( $id_index, $cached_dataset ); 1608 break; 1609 1447 1610 case 'display' : 1448 1611 return Utilities\format_attribute_display_data( $cached_dataset ); … … 1519 1682 } 1520 1683 1684 // Get all my attributes. 1685 $all_attributes = get_all_attributes( 'indexed' ); 1686 1521 1687 // Set my empty. 1522 1688 $query_list = array(); … … 1525 1691 foreach ( $maybe_attributes as $attribute_id ) { 1526 1692 1527 // Get the single attribute data.1528 $attribute_data = get_single_attribute( $attribute_id );1529 1530 1693 // Skip the empty data. 1531 if ( empty( $a ttribute_data) ) {1694 if ( empty( $all_attributes[ $attribute_id ] ) ) { 1532 1695 continue; 1533 1696 } 1534 1697 1535 1698 // Add the data to the list. 1536 $query_list[] = $a ttribute_data;1699 $query_list[] = $all_attributes[ $attribute_id ]; 1537 1700 } 1538 1701 … … 1978 2141 1979 2142 /** 2143 * Get the data for the aggregate structured schema data. 2144 * 2145 * @param integer $product_id Which product ID we are looking up. 2146 * @param boolean $purge Optional to purge the cache'd version before looking up. 2147 * 2148 * @return mixed 2149 */ 2150 function get_schema_data_for_product( $product_id = 0, $purge = false ) { 2151 2152 // Bail without a product ID. 2153 if ( empty( $product_id ) ) { 2154 return new WP_Error( 'missing_product_id', __( 'A product ID is required.', 'woo-better-reviews' ) ); 2155 } 2156 2157 // Set the key to use in our transient. 2158 $ky = Core\HOOK_PREFIX . 'schema_product' . absint( $product_id ); 2159 2160 // If we don't want the cache'd version, delete the transient first. 2161 if ( defined( 'WP_DEBUG' ) && WP_DEBUG || ! empty( $purge ) ) { 2162 delete_transient( $ky ); 2163 } 2164 2165 // Attempt to get the reviews from the cache. 2166 $cached_dataset = get_transient( $ky ); 2167 2168 // If we have none, do the things. 2169 if ( false === $cached_dataset ) { 2170 2171 // Grab the entire post object. 2172 $product_object = get_post( $product_id ); 2173 2174 // Start pulling out various pieces we need. 2175 $product_name = $product_object->post_title; 2176 $product_desc = $product_object->post_excerpt; 2177 $product_image = get_the_post_thumbnail_url( $product_id, 'medium' ); 2178 2179 // Pull out the averages and total review count. 2180 $average_score = get_post_meta( $product_id, Core\META_PREFIX . 'average_rating', true ); 2181 $review_count = Helpers\get_admin_review_count( $product_id, false ); 2182 2183 // Set up the schema arguments. 2184 $schema_args = array( 2185 '@context' => 'http://schema.org/', 2186 '@type' => 'Product', 2187 'name' => esc_attr( $product_name ), 2188 'image' => esc_url( $product_image ), 2189 'description' => wp_strip_all_tags( $product_desc, true ), 2190 'aggregateRating' => array( 2191 '@type' => 'AggregateRating', 2192 'ratingValue' => esc_attr( $average_score ), 2193 'bestRating' => '7', 2194 'worstRating' => '1', 2195 'ratingCount' => esc_attr( $review_count ), 2196 ), 2197 ); 2198 2199 // Set our transient with our data. 2200 set_transient( $ky, $schema_args, HOUR_IN_SECONDS ); 2201 2202 // And change the variable to do the things. 2203 $cached_dataset = $schema_args; 2204 } 2205 2206 // Return the raw dataset, we will format it later. 2207 return $cached_dataset; 2208 } 2209 2210 /** 1980 2211 * Take the review object array and merge the taxonomies. 1981 2212 * -
better-reviews-for-woocommerce/trunk/includes/uninstall.php
r2064761 r2072651 40 40 */ 41 41 function delete_initial_options() { 42 delete_option( Core\OPTION_PREFIX . 'allow_anonymous' , 'no');43 delete_option( Core\OPTION_PREFIX . 'global_attributes' , 'yes');42 delete_option( Core\OPTION_PREFIX . 'allow_anonymous' ); 43 delete_option( Core\OPTION_PREFIX . 'global_attributes' ); 44 44 } -
better-reviews-for-woocommerce/trunk/includes/utilities.php
r2064761 r2072651 124 124 } 125 125 126 // Get all my attributes. 127 $all_attributes = Queries\get_all_attributes( 'indexed' ); 128 126 129 // Parse out some labels. 127 130 $label_set = wp_list_pluck( $attribute_set[0], 'label', 'id' ); … … 153 156 foreach ( $setup as $attribute_id => $score_string ) { 154 157 158 // Now get my matching setup. 159 $attribute_item = $all_attributes[ $attribute_id ]; 160 161 // Set my various classes and labels. 162 $set_min_label = ! empty( $attribute_item->min_label ) ? esc_attr( $attribute_item->min_label ) : __( 'Min.', 'woo-better-reviews' ); 163 $set_max_label = ! empty( $attribute_item->max_label ) ? esc_attr( $attribute_item->max_label ) : __( 'Max.', 'woo-better-reviews' ); 164 165 // Get my labels if possible. 166 $attribute_lbls = array( 'min' => $set_min_label, 'max' => $set_max_label ); 167 155 168 // Set my scoring array up. 156 169 $scoring_array = explode( ',', $score_string ); … … 158 171 // And calculate the average. 159 172 $attribute_avg = array_sum( $scoring_array ) / count( $scoring_array ); 160 161 // Get my labels if possible.162 $attribute_lbls = Queries\get_single_attribute( $attribute_id, 'labels' );163 173 164 174 // Add my two values. … … 178 188 179 189 /** 190 * Take our review and format it for schema insertion. 191 * 192 * @param object $review The entire review object. 193 * 194 * @return array 195 */ 196 function format_review_data_for_schema( $review ) { 197 198 // Bail without any content. 199 if ( empty( $review ) ) { 200 return; 201 } 202 203 // Parse out the easy pieces we want first. 204 $review_title = esc_attr( $review->review_title ); 205 $review_dstamp = strtotime( $review->review_date ); 206 $review_score = absint( $review->rating_total_score ); 207 $review_author = esc_attr( $review->author_name ); 208 209 // De-tag the content first. 210 $stripped_text = wp_strip_all_tags( $review->review_content, true ); 211 212 // Set my variables for the content trimming. 213 $set_trim_count = apply_filters( Core\HOOK_PREFIX . 'schema_content_trim_count', 20, $review ); 214 $set_trim_more = apply_filters( Core\HOOK_PREFIX . 'schema_content_trim_more', '...', $review ); 215 216 // Now trim the actual words. 217 $review_content = wp_trim_words( $stripped_text, $set_trim_count, $set_trim_more ); 218 219 // Set up the arguments to return. 220 $schema_setup = array( 221 'title' => $review_title, 222 'content' => $review_content, 223 'date' => date( 'Y-m-d', $review_dstamp ), 224 'score' => $review_score, 225 'author' => $review_author, 226 ); 227 228 // Return the possibly filtered text. 229 return apply_filters( Core\HOOK_PREFIX . 'schema_formatted_review_data', $schema_setup, $review ); 230 } 231 232 /** 180 233 * Take the potentially values and format a nice list. 181 234 * … … 463 516 if ( isset( $review['rating_attributes'] ) ) { 464 517 518 // Get all my attributes. 519 $all_attributes = Queries\get_all_attributes( 'indexed' ); 520 465 521 // Pull out the attributes. 466 $ attributes = maybe_unserialize( $review['rating_attributes'] );522 $set_attributes = maybe_unserialize( $review['rating_attributes'] ); 467 523 468 524 // Our scoring data has 3 pieces. 469 foreach ( $ attributes as $attribute_id => $attribute_score ) {525 foreach ( $set_attributes as $attribute_id => $attribute_score ) { 470 526 471 527 // Pull my attribute data. 472 $attribute_data = Queries\get_single_attribute( $attribute_id );528 $attribute_data = $all_attributes[ $attribute_id ]; 473 529 474 530 // Now set the array accordingly. 475 531 $setup['rating_attributes'][] = array( 476 532 'id' => $attribute_id, 477 'label' => $attribute_data ['attribute_name'],533 'label' => $attribute_data->attribute_name, 478 534 'value' => $attribute_score, 479 535 ); -
better-reviews-for-woocommerce/trunk/readme.txt
r2064761 r2072651 5 5 Tested up to: 5.1.1 6 6 Requires PHP: 5.6.0 7 Stable tag: 0. 1.07 Stable tag: 0.2.0 8 8 License: MIT 9 9 License URI: https://opensource.org/licenses/MIT … … 73 73 == Changelog == 74 74 75 = 0.2.0 = 76 * adding CLI command for converting existing reviews. 77 * including review data in WooCommerce structured data. 78 * removed duplicate queries, general cleanup. 79 75 80 = 0.1.0 = 76 81 * Initial release -
better-reviews-for-woocommerce/trunk/templates/single-product-reviews.php
r2064761 r2072651 21 21 <div id="reviews" class="woocommerce-Reviews woo-better-reviews-display-wrapper"> 22 22 23 <?php \LiquidWeb\WooBetterReviews\ Display\ViewOutput\display_review_template_messages( $product->get_id() ); ?>23 <?php \LiquidWeb\WooBetterReviews\ViewOutput\display_review_template_messages( $product->get_id() ); ?> 24 24 25 25 <div id="comments" class="woo-better-reviews-display-block woo-better-reviews-existing-block"> 26 26 27 <?php \LiquidWeb\WooBetterReviews\ Display\ViewOutput\display_review_template_title( $product->get_id() ); ?>27 <?php \LiquidWeb\WooBetterReviews\ViewOutput\display_review_template_title( $product->get_id() ); ?> 28 28 29 <?php \LiquidWeb\WooBetterReviews\ Display\ViewOutput\display_review_template_visual_aggregate( $product->get_id() ); ?>29 <?php \LiquidWeb\WooBetterReviews\ViewOutput\display_review_template_visual_aggregate( $product->get_id() ); ?> 30 30 31 <?php \LiquidWeb\WooBetterReviews\ Display\ViewOutput\display_review_template_sorting( $product->get_id() ); ?>31 <?php \LiquidWeb\WooBetterReviews\ViewOutput\display_review_template_sorting( $product->get_id() ); ?> 32 32 33 <?php \LiquidWeb\WooBetterReviews\ Display\ViewOutput\display_existing_reviews( $product->get_id() ); ?>33 <?php \LiquidWeb\WooBetterReviews\ViewOutput\display_existing_reviews( $product->get_id() ); ?> 34 34 35 35 </div> 36 36 37 <?php \LiquidWeb\WooBetterReviews\ Display\ViewOutput\display_new_review_form( $product->get_id() ); ?>37 <?php \LiquidWeb\WooBetterReviews\ViewOutput\display_new_review_form( $product->get_id() ); ?> 38 38 39 39 <div class="clear"></div> -
better-reviews-for-woocommerce/trunk/woo-better-reviews.php
r2064761 r2072651 4 4 * Plugin URI: https://github.com/liquidweb/woo-better-reviews 5 5 * Description: Like reviews, only way better. 6 * Version: 0. 1.06 * Version: 0.2.0 7 7 * Author: Liquid Web 8 8 * Author URI: https://www.liquidweb.com 9 9 * Text Domain: woo-better-reviews 10 10 * Domain Path: /languages 11 * WC requires at least: 3.5.0 12 * WC tested up to: 3.6.0 11 13 * License: MIT 12 14 * License URI: https://opensource.org/licenses/MIT … … 25 27 26 28 // Define our plugin version. 27 define( __NAMESPACE__ . '\VERS', '0. 1.0' );29 define( __NAMESPACE__ . '\VERS', '0.2.0' ); 28 30 29 31 // Plugin root file. … … 67 69 // Load the database and custom table items. 68 70 require_once __DIR__ . '/includes/database.php'; 69 require_once __DIR__ . '/includes/ tables/data-content.php';70 require_once __DIR__ . '/includes/ tables/data-ratings.php';71 require_once __DIR__ . '/includes/ tables/data-authormeta.php';72 require_once __DIR__ . '/includes/ tables/tax-attributes.php';73 require_once __DIR__ . '/includes/ tables/tax-characteristics.php';71 require_once __DIR__ . '/includes/db-tables/data-content.php'; 72 require_once __DIR__ . '/includes/db-tables/data-ratings.php'; 73 require_once __DIR__ . '/includes/db-tables/data-authormeta.php'; 74 require_once __DIR__ . '/includes/db-tables/tax-attributes.php'; 75 require_once __DIR__ . '/includes/db-tables/tax-characteristics.php'; 74 76 75 77 // Load my query logic plugin-wide. … … 83 85 require_once __DIR__ . '/includes/admin/admin-notices.php'; 84 86 require_once __DIR__ . '/includes/admin/admin-pages.php'; 85 require_once __DIR__ . '/includes/admin/list-reviews.php';86 require_once __DIR__ . '/includes/admin/list-attributes.php';87 require_once __DIR__ . '/includes/admin/list-charstcs.php';88 87 require_once __DIR__ . '/includes/admin/product-meta.php'; 89 require_once __DIR__ . '/includes/admin/woo-settings.php'; 88 require_once __DIR__ . '/includes/list-tables/list-reviews.php'; 89 require_once __DIR__ . '/includes/list-tables/list-attributes.php'; 90 require_once __DIR__ . '/includes/list-tables/list-charstcs.php'; 91 require_once __DIR__ . '/includes/woo/settings.php'; 90 92 require_once __DIR__ . '/includes/process/admin-process.php'; 91 93 } … … 96 98 require_once __DIR__ . '/includes/display/form-data.php'; 97 99 require_once __DIR__ . '/includes/display/form-fields.php'; 98 require_once __DIR__ . '/includes/display/layout-review-list.php';99 require_once __DIR__ . '/includes/display/layout-review-aggregate.php';100 require_once __DIR__ . '/includes/display/layout-single-review.php';101 require_once __DIR__ . '/includes/display/layout-new-review-form.php';102 100 require_once __DIR__ . '/includes/display/view-output.php'; 103 require_once __DIR__ . '/includes/display/woo-filters.php'; 101 require_once __DIR__ . '/includes/display/schema-markup.php'; 102 require_once __DIR__ . '/includes/layout/review-list.php'; 103 require_once __DIR__ . '/includes/layout/review-aggregate.php'; 104 require_once __DIR__ . '/includes/layout/single-review.php'; 105 require_once __DIR__ . '/includes/layout/new-review-form.php'; 106 require_once __DIR__ . '/includes/woo/filters.php'; 104 107 require_once __DIR__ . '/includes/process/form-process.php'; 105 108 }
Note: See TracChangeset
for help on using the changeset viewer.