• Hi Paul, we have the following functions linking the InboundNow plugin to Site Review which you kindly wrote for us, but appears to be broken following a recent plugin update.
    Please can you suggest the fix – thanks.

    // START site reviews functions ======================================================================
    /** Site Reviews */
    /**
     * @param array $reviewValues
     *     author => the reviewer's name
     *     email => the reviewer's email
     *     assigned_to => the post_id of the page the review is assigned to
     *     content => the review text
     *     rating => the review rating (1-5)
     *     title => the review title
     * @param string $reviewCategory The taxonomy ID or slug
     * @return int|false
     */
    function glsr_create_site_review( array $reviewValues, $reviewCategory = '' ) {
    	if( !function_exists( 'glsr_resolve' ))return;
    	$database = glsr_resolve( 'Database' );
    	$user = wp_get_current_user();
    	$review = wp_parse_args( $reviewValues, [
    		'assigned_to' => '',
    		'author' => $user->exists() ? $user->display_name : '',
    		'content' => '',
    		'date' => '',
    		'email' => $user->exists() ? $user->user_email : '',
    		'ip_address' => glsr_resolve( 'Helper' )->getIpAddress(),
    		'rating' => '0',
    		'review_type' => 'local',
    		'title' => '',
    	]);
    	$review['avatar'] = get_avatar_url( $review['email'] );
    	if( $post_id = $database->createReview( $review, (object)['blacklisted' => false] )) {
    		$database->setReviewMeta( $post_id, $reviewCategory );
    		return $post_id;
    	}
    	glsr_log( 'This review was not created: '.print_r( $review, true ));
    	return false;
    }
    /**
     * Create a new review from the information submitted by an Inbound Forms plugin form
     * @param array $lead
     * @return void
     */
    add_action( 'inbound_store_lead_post', function( $lead ) {
        if( !function_exists( 'glsr_create_site_review' )) return;
        if( isset( $lead['raw_params'] )) {
            parse_str( $lead['raw_params'], $parsedLead );
            if( !array_key_exists( 'inbound_form_n', $parsedLead )
                || !array_key_exists( 'review_recommend_friends_family', $parsedLead )
            )return;
        }
        $categorySlug = strtolower( str_replace( ' - Review', '', $parsedLead['inbound_form_n'] ));
        $requiredFields = [
            'email', 'ip_address', 'review_date', 'review_recommend_friends_family', 'review_summary',
            'review_text', 'wpleads_name',
        ];
        $data = wp_parse_args( (array)$lead, array_fill_keys( $requiredFields, '' ));
        $date = empty( $data['review_date'] )
            ? current_time( 'mysql' )
            : date( 'Y-m-d H:i:s', strtotime( $data['review_date'] ));
        // turn on logging in the SiteReviews "Get Help -> System Info" page
        // and uncomment to following line to see all the available field values in $data:
        glsr_log( $data );
        $postId = glsr_create_site_review([
            'author' => trim( $data['wpleads_name'] ),
            'content' => $data['review_text'],
            'date' => $date,
            'email' => $data['email'],
            'ip_address' => $data['ip_address'],
            'rating' => $data['review_recommend_friends_family'],
            'title' => $data['review_summary'],
        ], $categorySlug );
        if( $postId && !empty( $data['id'] )) {
            add_post_meta( $data['id'], 'site_review_post_id', $postId );
            add_post_meta( $postId, 'wp_lead_post_id', $data['id'] );
        }
    });
     
    /**
     * Display the author's name as initials
     * @param object $review
     * @return object
     */
    add_filter( 'site-reviews/get/review', function( $review ) {
    	if( !is_admin() ) {
    		preg_match_all( '/(?<=\s|\b)\pL/u', $review->author, $matches );
    		$initials = implode( '. ', $matches[0] ).'.';
    		$review->author = strtoupper( $initials );
    	}
    	return $review;
    });
    /**
     * Removes any review-to-lead connections when a lead is deleted
     * @param int $postId
     * @return void
     */
    add_action( 'before_delete_post', function( $postId ) {
    	$lead = get_post( $postId );
    	if( !( $lead instanceof WP_Post ) || $lead->post_type != 'wp-lead' )return;
    	$reviewIds = get_post_meta( $lead->ID, 'site_review_post_id' );
    	foreach( $reviewIds as $reviewId ) {
    		delete_post_meta( $reviewId, 'wp_lead_post_id' );
    	}
    });
    // END site-review plugin ============================================================================

    This is an extract of the Site Review log:

    (
        [email] => [email protected]
        [ip_address] => x.x.x.x
        [review_date] => 2019-01-16
        [review_recommend_friends_family] => 5
        [review_summary] => Test 190118 0227
        [review_text] => Text 190118 0227
        [wpleads_name] => Christopher Hilling
        [user_ID] => 0
        [wordpress_date_time] => 2019-01-18 2:28:01 UTC
        [page_id] => 10013820
        [page_views] => {\"10013820\":[\"2019/01/18 02:26:39\"]}
        [raw_params] => review_recommend_friends_family=5&review_ratings_appointments=5&review_ratings_dignity_respect=5&review_ratings_involvement=5&review_ratings_information=5&review_ratings_outcome=5&review_summary=Test%20190118%200227&review_text=Text%20190118%200227&review_date=2019-01-16&wpleads_first_name=Christopher&wpleads_last_name=Hilling&your-email-address=christopher%40xxxx.org.uk&inbound_form_n=Tewkesbury%20-%20Review&inbound_form_lists=1007407&inbound_form_id=10016438&inbound_current_page_url=http%3A%2F%2Fwww.spadental.co.uk%2Ftewkesbury%2Ffeedback%2F&page_id=10013820&inbound_furl=aHR0cHM6Ly93d3cuc3BhZGVudGFsLmNvLnVrL3Rld2tlc2J1cnkvdGhhbmsteW91Lw%3D%3D&inbound_notify=dGV3a2VzYnVyeUBzcGFkZW50YWwuY28udWs%3D&inbound_nonce=9aad2aab20
        [inbound_form_id] => 10016438
        [mapped_params] => review_recommend_friends_family=5&review_ratings_appointments=5&review_ratings_dignity_respect=5&review_ratings_involvement=5&review_ratings_information=5&review_ratings_outcome=5&review_summary=Test%20190118%200227&review_text=Text%20190118%200227&review_date=2019-01-16&wpleads_first_name=Christopher&wpleads_last_name=Hilling&email=christopher%40xxxx.org.uk&inbound_form_lists=1007407
        [url_params] => {}
        [variation] => 0
        [form_id] => 10016438
        [source] => Direct Traffic
        [wp_lead_status] => 
        [review_ratings_appointments] => 5
        [review_ratings_dignity_respect] => 5
        [review_ratings_involvement] => 5
        [review_ratings_information] => 5
        [review_ratings_outcome] => 5
        [wpleads_first_name] => Christopher
        [wpleads_last_name] => Hilling
        [inbound_form_lists] => 1007407
        [lead_lists] => Array
            (
                [0] => 1007407
            )
    
        [lead_tags] => 
        [id] => 10016440
        [form_name] => 
    )

    Chris

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    Apologies Chris!

    I forgot to write you a followup email after the release of v3.0.

    v3.0 was a major rewrite of the plugin to address some fundamental limitations of v2. Due to the rewrite, the custom glsr_create_site_review function in your code will no longer work.

    Unfortunately I do not have time at this moment, but I will send you some updated code tomorrow that will work in v3.

    Thread Starter Christopher Hilling

    (@chilling)

    H Paul, thanks for the confirmation that the issue we are having is due to the v3.0 update. I was struggling to find the problem.

    Amazing response time as ever for an excellent Plugin.
    Thanks
    Chris

    Plugin Author Gemini Labs

    (@geminilabs)

    1. Please remove the entire glsr_create_site_review custom function as this is no longer needed.

    2. Finally, change the “inbound_store_lead_post” hook to the one below. Everything else can stay as is.

    /**
     * Create a new review from the information submitted by an Inbound Forms plugin form
     * @param array $lead
     * @return void
     */
    add_action( 'inbound_store_lead_post', function( $lead ) {
        if( isset( $lead['raw_params'] )) {
            parse_str( $lead['raw_params'], $parsedLead );
            if( !array_key_exists( 'inbound_form_n', $parsedLead )
                || !array_key_exists( 'review_recommend_friends_family', $parsedLead )
            )return;
        }
        $categorySlug = strtolower( str_replace( ' - Review', '', $parsedLead['inbound_form_n'] ));
        $requiredFields = [
            'email', 'ip_address', 'review_date', 'review_recommend_friends_family', 'review_summary',
            'review_text', 'wpleads_name',
        ];
        $data = wp_parse_args( (array)$lead, array_fill_keys( $requiredFields, '' ));
        $date = empty( $data['review_date'] )
            ? current_time( 'mysql' )
            : date( 'Y-m-d H:i:s', strtotime( $data['review_date'] ));
        $review = apply_filters( 'glsr_create_review', null, [
            'category' => $categorySlug,
            'content' => $data['review_text'],
            'date' => $date,
            'email' => $data['email'],
            'ip_address' => $data['ip_address'],
            'name' => trim( $data['wpleads_name'] ),
            'rating' => $data['review_recommend_friends_family'],
            'title' => $data['review_summary'],
        ]);
        if( isset( $review->ID ) && !empty( $data['id'] )) {
            add_post_meta( $data['id'], 'site_review_post_id', $review->ID );
            add_post_meta( $review->ID, 'wp_lead_post_id', $data['id'] );
        }
    });

    Let me know how it goes.

    • This reply was modified 6 years, 2 months ago by Gemini Labs.
    Plugin Author Gemini Labs

    (@geminilabs)

    @chilling Did that work for you?

    Plugin Author Gemini Labs

    (@geminilabs)

    @chilling I have not had a response in a week so will mark this as resolved.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Update to Plugin appears to have broken link from InboundNow’ is closed to new replies.