WordPress.org

Ready to get started?Download WordPress

Forums

WP Quadratum
[resolved] Venue details in filter (7 posts)

  1. rudomilov
    Member
    Posted 10 months ago #

    I would like to show city by filter:
    add_filter ('wp_quadratum_strapline', 'format_strapline', 10, 2);

    I found a venue-name and venue-id parameters, but I have to get location. Due to https://developer.foursquare.com/docs/responses/venue it is "location" and I am tried to get "venue-location" - it does not work.

    Is there any possibility to get venue location?

    http://wordpress.org/plugins/wp-quadratum/

  2. vicchi
    Member
    Plugin Author

    Posted 10 months ago #

    Is there any possibility to get venue location?

    In the current version of the plugin, no. In the next version of the plugin, there's a new filter available which allows you to get the entire JSON Checkin Response object which the Foursquare API returned, which should give you what you need.

    The next version is ready to be released and will be pushed to the WordPress plugin repository either later today, if I get time, or tomorrow.

    -Gary

  3. vicchi
    Member
    Plugin Author

    Posted 10 months ago #

    The latest version of WP Quadratum (v1.3.0 and not v1.2.1 as previously mentioned; there were sufficient changes to warrant upping the minor version number) has been pushed to the WordPress plugin subversion repository this morning and should now be available for upgrading from v1.2.0.

    Amongst other bug fixes and changes, this now adds a new filter, wp_quadratum_checkin that gives you access to the entire checkin object that the Foursquare API returns. This new filter is called prior to wp_quadratum_strapline so you can store the information you need (venue metadata) prior to the strapline filter being invoked.

    -Gary

  4. rudomilov
    Member
    Posted 10 months ago #

    Thanks for the update! However, I am not so good in WP and I have a trouble in mixing wp_quadratum_checkin and wp_quadratum_strapline filters.

    Wp_quadratum_strapline example from http://wordpress.org/plugins/wp-quadratum/other_notes/ works great, but I can not connect it with wp_quadratum_checkin example.

    So, I am trying to run:

    $last_checkin = null;
    add_filter('wp_quadratum_checkin', store_last_checkin, 10, 1);
    function store_last_checkin($checkin) {
        $last_checkin = $checkin;
    }
    
    add_filter('wp_quadratum_strapline', 'format_strapline', 10, 2);
    function format_strapline($content, $params) {
    
        $strapline = '<h5>Last seen at <a href="' . $params['venue-url'] . '">' . $params['venue-name'] . '</a> in ' . $last_checkin['venue']['location']['city'] . '</h5>';
        return $strapline;
    }

    Where is a mistake?

  5. vicchi
    Member
    Plugin Author

    Posted 10 months ago #

    So there's a couple of things to correct.

    Firstly, the sample code in the plugin's documentation isn't quite right. The second parameter in the call to add_filter needs to be quoted, so that it looks like this ...

    add_filter('wp_quadratum_checkin', 'store_last_checkin', 10, 1);

    Secondly, due to PHP's rules on variable scoping, you need to declare references to the $last_checkin variable as global otherwise PHP thinks you're declaring another $last_checkin variable with local scope to the function(s) it's being referenced in.

    Both of these are errors/omissions in the plugin's documentation, which I'll correct.

    But thirdly, you can't rely on the venue's location object always having a member called city. If you look at the Foursquare API documentation for a checkin's venue, it says that ...

    (location is) an object containing none, some, or all of address (street address), crossStreet, city, state, postalCode, country, lat, lng, and distance.

    If the venue you last checked into doesn't have a city associated with it then your code will break as the city member won't be present. So you'll need to check the location hierarchy and use the lowest granularity location that's provided, falling back to the default is there's no location metadata beyond the coordinates.

    Also, the checkin object is just that, an object, so you'll need to use object syntax, such as $last_checkin->venue->location to reference the location object and not array syntax, such as $last_checkin['venue']['location'].

    Putting all of this together, the following code should work (I've just written this and tested it out on my local WordPress install) ...

    <?php
    
    $last_checkin = null;
    
    add_filter('wp_quadratum_checkin', 'store_last_checkin', 10, 1);
    function store_last_checkin($checkin) {
    	global $last_checkin;
    	$last_checkin = $checkin;
    }
    
    add_filter('wp_quadratum_strapline', 'format_strapline', 10, 2);
    function format_strapline($content, $params) {
    	global $last_checkin;
    
    	$location = $last_checkin->venue->location;
    	$locality = null;
    
    	if (isset($location->city)) {
    		$locality = $location->city;
    	}
    	else if (isset($location->state)) {
    		$locality = $location->state;
    	}
    	else if (isset($location->country)) {
    		$locality = $location->country;
    	}
    
    	if ($locality !== null) {
    		return sprintf('<h5>Last seen at <a href="%s">%s</a> in %s',
    			$params['venue-url'],
    			$params['venue-name'],
    			$locality);
    	}
    
    	return $content;
    }
    ?>

    Hope this helps

    -Gary

  6. rudomilov
    Member
    Posted 10 months ago #

    Thank you! I have made a couple of changes and it fits pretty well.

  7. vicchi
    Member
    Plugin Author

    Posted 10 months ago #

    Excellent, great to hear.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.