Skip to content

Commit

Permalink
Merge pull request #27 from jonwaldstein/develop
Browse files Browse the repository at this point in the history
v1.1.0
  • Loading branch information
jonwaldstein authored May 20, 2021
2 parents 3740311 + 31bbe1d commit 1e514a0
Show file tree
Hide file tree
Showing 14 changed files with 23,091 additions and 137 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ node_modules/

# dotenv environment variables file
.env

# IDE specifics
.idea
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.0]
- Add button text field (#25)
- Add pageSize attribute / event number limit field (#26)

## [1.0.10]

- Fix CSS classnames (#21)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ Managing events on WordPress can be a challenge. These days we have many great s
- Utilizes Eventbrite's _embedded checkout_ experience meaning if your website is secure with an SSL, the sign up button will let users pay and/or signup without leaving your website.
- Provides an event _status_ selector to choose between live, draft, and all events.
- Provides an _order by_ selector to choose the order you would like your events to be displayed in.
- Provides ability to change the _sign up_ button color
- Provides ability to change the _sign up_ button color & text
- Provides an _event name filter_ to filter by event title keywords
- Provides an _event number limit_ field to only display a specific number of events
- Gives users ability to view event description summary by clicking _details_
- Gives users ability to click on title and navigate to appropriate Eventbrite url
- Saves events in WordPress cache (transients) every 1 minute upon page request.
Expand Down
110 changes: 21 additions & 89 deletions blocks-for-eventbrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Plugin Name: Blocks for Eventbrite
* Description: Gutenberg blocks that display eventbrite events
* Version: 1.0.10
* Version: 1.1.0
* Author: Jon Waldstein
* Author URI: https://jonwaldstein.com
* License: GPL-2.0-or-later
Expand All @@ -17,11 +17,13 @@
}

// Setup constants
define('BLOCKS_FOR_EVENTBRITE_SCRIPT_ASSET_PATH', dirname(__FILE__) . '/build/index.asset.php');
define('BLOCKS_FOR_EVENTBRITE_SCRIPT_ASSET', require(BLOCKS_FOR_EVENTBRITE_SCRIPT_ASSET_PATH));
define('BLOCKS_FOR_EVENTBRITE_INDEX_JS', 'build/index.js');
define('BLOCKS_FOR_EVENTBRITE_LOCALIZED_SCRIPT_NAME', 'blocksForEventbrite');
define('BLOCKS_FOR_EVENTBRITE_SCRIPT_NAME', 'blocks-for-eventbrite-script');
const BLOCKS_FOR_EVENTBRITE_SCRIPT_ASSET_PATH = __DIR__ . '/build/index.asset.php';
define("BLOCKS_FOR_EVENTBRITE_SCRIPT_ASSET", require(BLOCKS_FOR_EVENTBRITE_SCRIPT_ASSET_PATH));
const BLOCKS_FOR_EVENTBRITE_INDEX_JS = 'build/index.js';
const BLOCKS_FOR_EVENTBRITE_LOCALIZED_SCRIPT_NAME = 'blocksForEventbrite';
const BLOCKS_FOR_EVENTBRITE_SCRIPT_NAME = 'blocks-for-eventbrite-script';
// include class with no auto-loading
include_once('src/api/RenderBlocksForEventbriteCard.php');

/**
* Registers all block assets so that they can be enqueued through the block editor
Expand Down Expand Up @@ -88,6 +90,14 @@
'type' => 'string',
'default' => get_option('time_format')
],
'signUpButtonText' => [
'type' => 'string',
'default' => 'Sign Up'
],
'pageSize' => [
'type' => 'number',
'default' => 50
],
]
));
});
Expand Down Expand Up @@ -116,91 +126,13 @@
});

/**
* Render callback for eventbrite blocks event card
*
* @param object $attributes
* Register block type callback render_callback
*
* @param $attributes
* @return false|string|void
*/
function render_blocks_for_eventbrite_card($attributes)
{
// do not render in the backend
if (is_admin()) return;

// set transient key based on the individual blocks
$TRANSIENT_KEY = "blocks_for_eventbrite_{$attributes['id']}";

// get transient based on current transient key
$transient = get_transient($TRANSIENT_KEY);

// if transient is empty or attributes have changed
if (!$transient || $transient['attributes'] !== $attributes) {

$status = !empty($attributes['status']) ? $attributes['status'] : 'live';
$orderBy = !empty($attributes['orderBy']) ? $attributes['orderBy'] : 'start_asc';
$nameFilter = !empty($attributes['nameFilter']) ? $attributes['nameFilter'] : null;

// make GET request to eventbrite api to get the user's organization ID
$userResponse = wp_remote_get("https://www.eventbriteapi.com/v3/users/me/organizations?token={$attributes['apiKey']}");

// decode fetched data to json
$userData = json_decode(wp_remote_retrieve_body($userResponse), true);

// get the organization id
$userOrganization = $userData['organizations'][0]['id'];

// build api call url
$organizationEventsUrl = urldecode("https://www.eventbriteapi.com/v3/organizations/{$userOrganization}/events/?" . http_build_query(
[
'token' => $attributes['apiKey'],
'expand' => 'ticket_classes,venue',
'status' => $status,
'order_by' => $orderBy,
'time_filter' => 'current_future',
'name_filter' => $nameFilter
],
'',
'&'
));

// make GET request to eventbrite api based on user's attribute settings
$response = wp_remote_get($organizationEventsUrl);

// decode fetched data to json
$data = json_decode(wp_remote_retrieve_body($response), true);

// set transient data with current transient key for 1 minute
set_transient($TRANSIENT_KEY, [
'events' => $data['events'],
'attributes' => $attributes,
'date' => date('Y-m-d'),
], 60);

// get transient based on current block
$transient = get_transient($TRANSIENT_KEY);
}

// remove apiKey from attributes so it's not accessible on the front-end
if (!empty($transient['attributes']['apiKey'])) {
unset($transient['attributes']['apiKey']);
}

// enqueue our script for the front-end
wp_enqueue_script(BLOCKS_FOR_EVENTBRITE_SCRIPT_NAME);

// access our transient data in js
wp_localize_script(
BLOCKS_FOR_EVENTBRITE_SCRIPT_NAME,
BLOCKS_FOR_EVENTBRITE_LOCALIZED_SCRIPT_NAME,
[
'events' => $transient['events'],
'attributes' => $transient['attributes'],
]
);

ob_start();

// use js to render events in this div
echo '<div id="root-blocks-for-eventbrite" class="blocks-for-eventbrite blocks-for-eventbrite-css-wrapper"></div>';

return ob_get_clean();
$blocks = new RenderBlocksForEventbriteCard($attributes);
return $blocks->render();
}
2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => '563e7517e9360406fa4bff7cf1d8dc9f');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-date', 'wp-dom-ready', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => 'c17b2ebfd7e2d5b350a1840699ee3d08');
Loading

0 comments on commit 1e514a0

Please sign in to comment.