Plugin Directory

Changeset 2072651


Ignore:
Timestamp:
04/22/2019 03:25:41 PM (6 years ago)
Author:
norcross
Message:

adding banner images and updating icon files for repository assets

Location:
better-reviews-for-woocommerce
Files:
84 added
20 edited

Legend:

Unmodified
Added
Removed
  • better-reviews-for-woocommerce/trunk/CHANGELOG.md

    r2064761 r2072651  
    55This project adheres to [Semantic Versioning](http://semver.org/).
    66
     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
    713## [0.1.0]
    814
  • better-reviews-for-woocommerce/trunk/includes/admin/admin-assets.php

    r2064761 r2072651  
    77
    88// Declare our namespace.
    9 namespace LiquidWeb\WooBetterReviews\Admin\AdminAssets;
     9namespace LiquidWeb\WooBetterReviews\AdminAssets;
    1010
    1111// Set our aliases.
  • better-reviews-for-woocommerce/trunk/includes/admin/admin-notices.php

    r2064761 r2072651  
    77
    88// Declare our namespace.
    9 namespace LiquidWeb\WooBetterReviews\Admin\AdminNotices;
     9namespace LiquidWeb\WooBetterReviews\AdminNotices;
    1010
    1111// Set our aliases.
  • better-reviews-for-woocommerce/trunk/includes/admin/admin-pages.php

    r2064761 r2072651  
    77
    88// Declare our namespace.
    9 namespace LiquidWeb\WooBetterReviews\Admin\AdminPages;
     9namespace LiquidWeb\WooBetterReviews\AdminPages;
    1010
    1111// Set our aliases.
  • better-reviews-for-woocommerce/trunk/includes/admin/menu-items.php

    r2064761 r2072651  
    1212use LiquidWeb\WooBetterReviews as Core;
    1313use LiquidWeb\WooBetterReviews\Helpers as Helpers;
    14 use LiquidWeb\WooBetterReviews\Admin\AdminPages as AdminPages;
     14use LiquidWeb\WooBetterReviews\AdminPages as AdminPages;
    1515
    1616// And pull in any other namespaces.
  • better-reviews-for-woocommerce/trunk/includes/display/form-data.php

    r2064761 r2072651  
    77
    88// Declare our namespace.
    9 namespace LiquidWeb\WooBetterReviews\Display\FormData;
     9namespace LiquidWeb\WooBetterReviews\FormData;
    1010
    1111// Set our aliases.
  • better-reviews-for-woocommerce/trunk/includes/display/form-fields.php

    r2064761 r2072651  
    77
    88// Declare our namespace.
    9 namespace LiquidWeb\WooBetterReviews\Display\FormFields;
     9namespace LiquidWeb\WooBetterReviews\FormFields;
    1010
    1111// Set our aliases.
  • better-reviews-for-woocommerce/trunk/includes/display/view-output.php

    r2064761 r2072651  
    77
    88// Declare our namespace.
    9 namespace LiquidWeb\WooBetterReviews\Display\ViewOutput;
     9namespace LiquidWeb\WooBetterReviews\ViewOutput;
    1010
    1111// Set our aliases.
     
    1414use LiquidWeb\WooBetterReviews\Utilities as Utilities;
    1515use 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;
     16use LiquidWeb\WooBetterReviews\FormFields as FormFields;
     17use LiquidWeb\WooBetterReviews\Layout\ReviewList as LayoutReviewList;
     18use LiquidWeb\WooBetterReviews\Layout\ReviewAggregate as LayoutReviewAggregate;
     19use LiquidWeb\WooBetterReviews\Layout\NewReviewForm as LayoutNewReviewForm;
     20use LiquidWeb\WooBetterReviews\Layout\SingleReview as LayoutSingleReview;
    2121
    2222// And pull in any other namespaces.
     
    254254        $build .= '<div id="' . sanitize_html_class( 'woo-better-reviews-single-' . absint( $single_review['review_id'] ) ) . '" class="' . esc_attr( $class ) . '">';
    255255
     256            // Handle the "before" display.
     257            $build .= apply_filters( Core\HOOK_PREFIX . 'before_single_review_output', null, $single_review, $product_id );
     258
    256259            // Output the title.
    257260            $build .= LayoutSingleReview\set_single_review_header_view( $single_review );
     
    265268            // Output the author characteristics.
    266269            $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 );
    267273
    268274        // Close the single review div.
  • better-reviews-for-woocommerce/trunk/includes/process/admin-process.php

    r2064761 r2072651  
    77
    88// Declare our namespace.
    9 namespace LiquidWeb\WooBetterReviews\Admin\AdminProcess;
     9namespace LiquidWeb\WooBetterReviews\AdminProcess;
    1010
    1111// Set our aliases.
  • better-reviews-for-woocommerce/trunk/includes/process/cli-commands.php

    r2064761 r2072651  
    1515use LiquidWeb\WooBetterReviews\Queries as Queries;
    1616use LiquidWeb\WooBetterReviews\Database as Database;
     17use LiquidWeb\WooBetterReviews\ConvertExisting as ConvertExisting;
    1718
    1819// Pull in the CLI items.
     
    248249
    249250    /**
     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    /**
    250345     * This is a placeholder function for testing.
    251346     *
  • better-reviews-for-woocommerce/trunk/includes/process/convert-existing.php

    r2064761 r2072651  
    77
    88// Declare our namespace.
    9 namespace LiquidWeb\WooBetterReviews\Display\ConvertExisting;
     9namespace LiquidWeb\WooBetterReviews\ConvertExisting;
    1010
    1111// Set our aliases.
     
    2222 * Convert the existing comment-based reviews to our new ones.
    2323 *
     24 * @param  boolean $convert_type    Whether to convert the type the existing.
     25 * @param  boolean $purge_existing  Whether to actually purge the existing.
     26 *
    2427 * @return mixed
    2528 */
    26 function process_existing_review_conversion() {
     29function 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    }
    2740
    2841    // Set my lookup args.
     
    3649    $maybe_cmns = get_comments( $setup_args );
    3750
    38     // Bail and fail without.
     51    // Bail with a 'no-reviews' string to look for later.
    3952    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';
    4154    }
    4255
     
    137150    }
    138151
     152    // Set and sanitize my product ID array.
     153    $product_id_array   = array_unique( $pids );
     154
    139155    // Handle our functions related to the product ID array.
    140     update_products_post_conversion( $pids );
     156    update_products_post_conversion( $product_id_array, $convert_type, $purge_existing );
    141157
    142158    // Now delete my big list of review data cached.
     
    146162    $return_msg = sprintf( _n( '%d review converted.', '%d reviews converted.', absint( $ccount ), 'woo-better-reviews' ), absint( $ccount ) );
    147163
    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    );
    149171}
    150172
     
    383405 * Run all the various cleanup and recalculating functions on products.
    384406 *
    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.
    386410 *
    387411 * @return void
    388412 */
    389 function update_products_post_conversion( $product_ids = array() ) {
     413function update_products_post_conversion( $product_ids = array(), $convert_type = true, $purge_existing = false ) {
    390414
    391415    // Bail if we don't have product IDs.
     
    394418    }
    395419
    396     // Make sure we have unique IDs.
    397     $unique_ids = array_unique( $product_ids );
    398 
    399420    // Update all my counts.
    400     Utilities\update_product_review_count( $unique_ids );
     421    Utilities\update_product_review_count( $product_ids );
    401422
    402423    // Loop the product IDs and run our functions.
    403     foreach ( $unique_ids as $unique_id ) {
     424    foreach ( $product_ids as $product_id ) {
    404425
    405426        // 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 ) ) {
    407428            continue;
    408429        }
    409430
    410431        // 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        }
    412440
    413441        // Recalculate the total score on each.
    414         Utilities\calculate_total_review_scoring( $unique_id );
     442        Utilities\calculate_total_review_scoring( $product_id );
    415443
    416444        // 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 ) );
    419447    }
    420448
     
    454482        do_action( Core\HOOK_PREFIX . 'before_legacy_review_converted', $existing_id );
    455483
    456         // Set the individual update args.
    457         // This odd approval flag hides them without deleting.
     484        // Set the individual update args. This odd
     485        // approval flag hides them without deleting.
    458486        $setup_args = array(
    459487            'comment_ID'       => absint( $existing_id ),
     
    481509    return $update;
    482510}
     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 */
     519function 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  
    77
    88// Declare our namespace.
    9 namespace LiquidWeb\WooBetterReviews\Display\FormProcess;
     9namespace LiquidWeb\WooBetterReviews\FormProcess;
    1010
    1111// Set our aliases.
  • better-reviews-for-woocommerce/trunk/includes/queries.php

    r2064761 r2072651  
    880880
    881881/**
     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 */
     891function 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/**
    8821036 * Get all the verified reviews.
    8831037 *
     
    14451599            break;
    14461600
     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
    14471610        case 'display' :
    14481611            return Utilities\format_attribute_display_data( $cached_dataset );
     
    15191682        }
    15201683
     1684        // Get all my attributes.
     1685        $all_attributes = get_all_attributes( 'indexed' );
     1686
    15211687        // Set my empty.
    15221688        $query_list = array();
     
    15251691        foreach ( $maybe_attributes as $attribute_id ) {
    15261692
    1527             // Get the single attribute data.
    1528             $attribute_data = get_single_attribute( $attribute_id );
    1529 
    15301693            // Skip the empty data.
    1531             if ( empty( $attribute_data ) ) {
     1694            if ( empty( $all_attributes[ $attribute_id ] ) ) {
    15321695                continue;
    15331696            }
    15341697
    15351698            // Add the data to the list.
    1536             $query_list[] = $attribute_data;
     1699            $query_list[] = $all_attributes[ $attribute_id ];
    15371700        }
    15381701
     
    19782141
    19792142/**
     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 */
     2150function 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/**
    19802211 * Take the review object array and merge the taxonomies.
    19812212 *
  • better-reviews-for-woocommerce/trunk/includes/uninstall.php

    r2064761 r2072651  
    4040 */
    4141function 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' );
    4444}
  • better-reviews-for-woocommerce/trunk/includes/utilities.php

    r2064761 r2072651  
    124124    }
    125125
     126    // Get all my attributes.
     127    $all_attributes = Queries\get_all_attributes( 'indexed' );
     128
    126129    // Parse out some labels.
    127130    $label_set  = wp_list_pluck( $attribute_set[0], 'label', 'id' );
     
    153156    foreach ( $setup as $attribute_id => $score_string ) {
    154157
     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
    155168        // Set my scoring array up.
    156169        $scoring_array  = explode( ',', $score_string );
     
    158171        // And calculate the average.
    159172        $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' );
    163173
    164174        // Add my two values.
     
    178188
    179189/**
     190 * Take our review and format it for schema insertion.
     191 *
     192 * @param  object  $review  The entire review object.
     193 *
     194 * @return array
     195 */
     196function 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/**
    180233 * Take the potentially values and format a nice list.
    181234 *
     
    463516    if ( isset( $review['rating_attributes'] ) ) {
    464517
     518        // Get all my attributes.
     519        $all_attributes = Queries\get_all_attributes( 'indexed' );
     520
    465521        // Pull out the attributes.
    466         $attributes = maybe_unserialize( $review['rating_attributes'] );
     522        $set_attributes = maybe_unserialize( $review['rating_attributes'] );
    467523
    468524        // Our scoring data has 3 pieces.
    469         foreach ( $attributes as $attribute_id => $attribute_score ) {
     525        foreach ( $set_attributes as $attribute_id => $attribute_score ) {
    470526
    471527            // Pull my attribute data.
    472             $attribute_data = Queries\get_single_attribute( $attribute_id );
     528            $attribute_data = $all_attributes[ $attribute_id ];
    473529
    474530            // Now set the array accordingly.
    475531            $setup['rating_attributes'][] = array(
    476532                'id'    => $attribute_id,
    477                 'label' => $attribute_data['attribute_name'],
     533                'label' => $attribute_data->attribute_name,
    478534                'value' => $attribute_score,
    479535            );
  • better-reviews-for-woocommerce/trunk/readme.txt

    r2064761 r2072651  
    55Tested up to: 5.1.1
    66Requires PHP: 5.6.0
    7 Stable tag: 0.1.0
     7Stable tag: 0.2.0
    88License: MIT
    99License URI: https://opensource.org/licenses/MIT
     
    7373== Changelog ==
    7474
     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
    7580= 0.1.0 =
    7681* Initial release
  • better-reviews-for-woocommerce/trunk/templates/single-product-reviews.php

    r2064761 r2072651  
    2121<div id="reviews" class="woocommerce-Reviews woo-better-reviews-display-wrapper">
    2222
    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() ); ?>
    2424
    2525    <div id="comments" class="woo-better-reviews-display-block woo-better-reviews-existing-block">
    2626
    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() ); ?>
    2828
    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() ); ?>
    3030
    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() ); ?>
    3232
    33         <?php \LiquidWeb\WooBetterReviews\Display\ViewOutput\display_existing_reviews( $product->get_id() ); ?>
     33        <?php \LiquidWeb\WooBetterReviews\ViewOutput\display_existing_reviews( $product->get_id() ); ?>
    3434
    3535    </div>
    3636
    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() ); ?>
    3838
    3939    <div class="clear"></div>
  • better-reviews-for-woocommerce/trunk/woo-better-reviews.php

    r2064761 r2072651  
    44 * Plugin URI:  https://github.com/liquidweb/woo-better-reviews
    55 * Description: Like reviews, only way better.
    6  * Version:     0.1.0
     6 * Version:     0.2.0
    77 * Author:      Liquid Web
    88 * Author URI:  https://www.liquidweb.com
    99 * Text Domain: woo-better-reviews
    1010 * Domain Path: /languages
     11 * WC requires at least: 3.5.0
     12 * WC tested up to: 3.6.0
    1113 * License:     MIT
    1214 * License URI: https://opensource.org/licenses/MIT
     
    2527
    2628// Define our plugin version.
    27 define( __NAMESPACE__ . '\VERS', '0.1.0' );
     29define( __NAMESPACE__ . '\VERS', '0.2.0' );
    2830
    2931// Plugin root file.
     
    6769// Load the database and custom table items.
    6870require_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';
     71require_once __DIR__ . '/includes/db-tables/data-content.php';
     72require_once __DIR__ . '/includes/db-tables/data-ratings.php';
     73require_once __DIR__ . '/includes/db-tables/data-authormeta.php';
     74require_once __DIR__ . '/includes/db-tables/tax-attributes.php';
     75require_once __DIR__ . '/includes/db-tables/tax-characteristics.php';
    7476
    7577// Load my query logic plugin-wide.
     
    8385    require_once __DIR__ . '/includes/admin/admin-notices.php';
    8486    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';
    8887    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';
    9092    require_once __DIR__ . '/includes/process/admin-process.php';
    9193}
     
    9698    require_once __DIR__ . '/includes/display/form-data.php';
    9799    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';
    102100    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';
    104107    require_once __DIR__ . '/includes/process/form-process.php';
    105108}
Note: See TracChangeset for help on using the changeset viewer.