Skip to content

Commit

Permalink
Add WPTV URL meta field (#143)
Browse files Browse the repository at this point in the history
* Register and render the meta: wptv_url

* Add wptv_url to ical

* Add wptv_url to sample post data for install hook

* Add View Recording link to modal

* Add View Recording link to list item

* Update testing

* Add aria-label

* Update copy wording

* Fix unit tests

* Fix PHPCS error
  • Loading branch information
renintw committed Apr 26, 2023
1 parent a16b720 commit 96a92e7
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 12 deletions.
22 changes: 15 additions & 7 deletions .github/workflows/phpunit.yml
Expand Up @@ -21,15 +21,23 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v2

- name: Install dependencies
run: composer install --dev --prefer-dist --no-progress --no-suggest

- name: Run phpcs
uses: chekalsky/phpcs-action@v1
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
phpcs_bin_path: './vendor/bin/phpcs'
php-version: '7.4'
coverage: none
tools: composer, cs2pr

- name: Install Composer dependencies
run: |
composer install --prefer-dist --no-suggest --no-progress --no-ansi --no-interaction
- name: Run PHPCS
run: |
vendor/bin/phpcs -q --report=checkstyle src | cs2pr
unit-php:
name: PHP Unit Tests
Expand Down
5 changes: 5 additions & 0 deletions includes/ical-generator-functions.php
Expand Up @@ -45,6 +45,7 @@ function generate_event( $post ) {
$title = $post->post_title;
$location = $post->location;
$link = $post->link;
$wptv_url = $post->wptv_url;
$team = $post->team;
$recurring = $post->recurring;
$sequence = empty( $post->sequence ) ? 0 : intval( $post->sequence );
Expand All @@ -65,6 +66,10 @@ function generate_event( $post ) {
$location = "{$slack_channel} channel on Slack";
}

if ( $wptv_url ) {
$description .= "WordPress.tv link: {$wptv_url}\\n";
}

if ( $link ) {
if ( $slack_channel ) {
$description .= "Slack channel link: https://wordpress.slack.com/messages/{$slack_channel}\\n";
Expand Down
3 changes: 3 additions & 0 deletions includes/wporg-meeting-install.php
Expand Up @@ -23,6 +23,7 @@ function wporg_meeting_install() {
'recurring' => 'weekly',
'link' => 'wordpress.org',
'location' => '#meta',
'wptv_url' => 'https://wordpress.tv',
),
)
);
Expand All @@ -40,6 +41,7 @@ function wporg_meeting_install() {
'recurring' => 'monthly',
'link' => 'wordpress.org',
'location' => '#meta',
'wptv_url' => 'https://wordpress.tv',
),
)
);
Expand All @@ -58,6 +60,7 @@ function wporg_meeting_install() {
'occurrence' => array( 3 ),
'link' => 'wordpress.org',
'location' => '#meta',
'wptv_url' => 'https://wordpress.tv',
),
)
);
Expand Down
25 changes: 24 additions & 1 deletion includes/wporg-meeting-posttype.php
Expand Up @@ -54,7 +54,9 @@ public function meeting_column_width() { ?>
public function meeting_add_custom_columns( $columns ) {
$columns = array_slice( $columns, 0, 1, true )
+ array( 'team' => __( 'Team', 'wporg-meeting-calendar' ) )
+ array_slice( $columns, 1, null, true );
+ array_slice( $columns, 1, -1, true )
+ array( 'wptv_url' => __( 'WPTV URL', 'wporg-meeting-calendar' ) )
+ array_slice( $columns, -1, null, true );
return $columns;
}

Expand All @@ -65,6 +67,12 @@ public function meeting_custom_columns( $column, $post_id ) {
echo esc_html( $team );
break;
}
switch ( $column ) {
case 'wptv_url':
$wptv_url = get_post_meta( $post_id, 'wptv_url', true );
echo esc_html( $wptv_url ?: '—' );
break;
}
}

public function meeting_archive_page_query( $query ) {
Expand Down Expand Up @@ -292,6 +300,7 @@ public function register_meta() {
'recurring',
'link',
'location',
'wptv_url',
);
foreach ( $meta_keys as $key ) {
register_meta(
Expand Down Expand Up @@ -370,6 +379,7 @@ public function get_occurrences_for_period( $request ) {
'link' => $meeting->link,
'title' => wp_specialchars_decode( $meeting->post_title, ENT_QUOTES ),
'location' => $meeting->location,
'wptv_url' => $meeting->wptv_url,
'recurring' => $meeting->recurring,
'occurrence' => $meeting->occurrence,
'status' => ( $this->is_meeting_cancelled( $meeting->ID, $occurrence ) ? 'cancelled' : 'active' ),
Expand Down Expand Up @@ -496,6 +506,7 @@ public function render_meta_boxes( $post ) {
$occurrence = isset( $meta['occurrence'][0] ) ? unserialize( $meta['occurrence'][0] ) : array();
$link = isset( $meta['link'][0] ) ? $meta['link'][0] : '';
$location = isset( $meta['location'][0] ) ? $meta['location'][0] : '';
$wptv_url = isset( $meta['wptv_url'][0] ) ? $meta['wptv_url'][0] : '';
wp_nonce_field( 'save_meeting_meta_' . $post->ID, 'meeting_nonce' );
?>

Expand Down Expand Up @@ -569,6 +580,17 @@ public function render_meta_boxes( $post ) {
<input type="text" name="location" id="location" class="regular-text wide" value="<?php echo esc_attr( $location ); ?>">
</label>
</p>
<p>
<label for="wptv_url"><?php esc_html_e( 'WordPress.tv URL: ', 'wporg-meeting-calendar' ); ?></label>
<input
type="url"
name="wptv_url"
id="wptv_url"
class="regular-text wide"
value="<?php echo esc_url( $wptv_url ); ?>"
/>
</p>

<script>
jQuery(document).ready( function($) {
$('.date').datepicker({
Expand Down Expand Up @@ -715,6 +737,7 @@ public function save_meta_boxes( $post_id ) {
? array_map( 'intval', $_POST['occurrence'] ) : array() );
$meta['link'] = ( isset( $_POST['link'] ) ? esc_url( $_POST['link'] ) : '' );
$meta['location'] = ( isset( $_POST['location'] ) ? esc_textarea( $_POST['location'] ) : '' );
$meta['wptv_url'] = ( isset( $_POST['wptv_url'] ) ? esc_url( $_POST['wptv_url'] ) : '' );

foreach ( $meta as $key => $value ) {
update_post_meta( $post->ID, $key, $value );
Expand Down
7 changes: 7 additions & 0 deletions src/frontend/calendar/modal.js
Expand Up @@ -73,6 +73,13 @@ function EventModal( { event, onRequestClose } ) {
{ __( 'Add to Google Calendar', 'wporg-meeting-calendar' ) }
</a>
</p>
{ !! event.wptv_url && (
<p>
<a aria-label={ __( 'WordPress.tv URL for the meeting recording', 'wporg-meeting-calendar' ) } href={ event.wptv_url }>
{ __( 'View Recording', 'wporg-meeting-calendar' ) }
</a>
</p>
) }
</Modal>
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/list/list-item.js
Expand Up @@ -89,6 +89,9 @@ function ListItem( { date, events } ) {
{ __( 'Location: ', 'wporg-meeting-calendar' ) }
{ getSlackLink( event.location ) }
</p>
<p className="wporg-meeting-calendar__list-event-copy">
<a aria-label={ __( 'WordPress.tv URL for the meeting recording', 'wporg-meeting-calendar' ) } href={ event.wptv_url }>{ __( 'View Recording', 'wporg-meeting-calendar' ) }</a>
</p>
</div>
</div>
</article>
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/events-with-cancel.ics
Expand Up @@ -17,7 +17,7 @@ SEQUENCE:0
STATUS:CONFIRMED
TRANSP:OPAQUE
LOCATION:#meta channel on Slack
DESCRIPTION:Slack channel link: https://wordpress.slack.com/messages/#meta\nFor more information visit wordpress.org
DESCRIPTION:WordPress.tv link: https://wordpress.tv\nSlack channel link: https://wordpress.slack.com/messages/#meta\nFor more information visit wordpress.org
RRULE:FREQ=WEEKLY
EXDATE:%EXDATE%
END:VEVENT
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/events.ics
Expand Up @@ -17,7 +17,7 @@ SEQUENCE:0
STATUS:CONFIRMED
TRANSP:OPAQUE
LOCATION:#meta channel on Slack
DESCRIPTION:Slack channel link: https://wordpress.slack.com/messages/#meta\nFor more information visit wordpress.org
DESCRIPTION:WordPress.tv link: https://wordpress.tv\nSlack channel link: https://wordpress.slack.com/messages/#meta\nFor more information visit wordpress.org
RRULE:FREQ=WEEKLY
END:VEVENT
BEGIN:VEVENT
Expand All @@ -32,7 +32,7 @@ SEQUENCE:0
STATUS:CONFIRMED
TRANSP:OPAQUE
LOCATION:#meta channel on Slack
DESCRIPTION:Slack channel link: https://wordpress.slack.com/messages/#meta\nFor more information visit wordpress.org
DESCRIPTION:WordPress.tv link: https://wordpress.tv\nSlack channel link: https://wordpress.slack.com/messages/#meta\nFor more information visit wordpress.org
RRULE:FREQ=MONTHLY
END:VEVENT
BEGIN:VEVENT
Expand All @@ -47,7 +47,7 @@ SEQUENCE:0
STATUS:CONFIRMED
TRANSP:OPAQUE
LOCATION:#meta channel on Slack
DESCRIPTION:Slack channel link: https://wordpress.slack.com/messages/#meta\nFor more information visit wordpress.org
DESCRIPTION:WordPress.tv link: https://wordpress.tv\nSlack channel link: https://wordpress.slack.com/messages/#meta\nFor more information visit wordpress.org
RRULE:FREQ=MONTHLY;BYDAY=3WE
END:VEVENT
END:VCALENDAR
16 changes: 16 additions & 0 deletions tests/test-api.php
Expand Up @@ -70,6 +70,7 @@ public function test_meeting_weekly() {
$this->assertEquals( '14:00:00', $meeting['meta']['time'] );
$this->assertEquals( 'weekly', $meeting['meta']['recurring'] );
$this->assertEquals( 'wordpress.org', $meeting['meta']['link'] );
$this->assertEquals( 'https://wordpress.tv', $meeting['meta']['wptv_url'] );
$this->assertEquals( array(), $meeting['meta']['occurrence'] );

$this->assertTrue( is_array( $meeting['future_occurrences'] ) );
Expand Down Expand Up @@ -116,6 +117,7 @@ public function test_meeting_monthly() {
$this->assertEquals( '15:00:00', $meeting['meta']['time'] );
$this->assertEquals( 'monthly', $meeting['meta']['recurring'] );
$this->assertEquals( 'wordpress.org', $meeting['meta']['link'] );
$this->assertEquals( 'https://wordpress.tv', $meeting['meta']['wptv_url'] );
$this->assertEquals( array(), $meeting['meta']['occurrence'] );

$this->assertTrue( is_array( $meeting['future_occurrences'] ) );
Expand Down Expand Up @@ -159,6 +161,7 @@ public function test_meeting_third_wednesday() {
$this->assertEquals( '16:00:00', $meeting['meta']['time'] );
$this->assertEquals( 'occurrence', $meeting['meta']['recurring'] );
$this->assertEquals( 'wordpress.org', $meeting['meta']['link'] );
$this->assertEquals( 'https://wordpress.tv', $meeting['meta']['wptv_url'] );
$this->assertEquals( array( 3 ), $meeting['meta']['occurrence'] );

$this->assertTrue( is_array( $meeting['future_occurrences'] ) );
Expand Down Expand Up @@ -201,6 +204,7 @@ public function _january_meetings() {
'datetime' => '2020-01-01T14:00:00+00:00',
'team' => 'Team-A',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'title' => 'A weekly meeting',
'location' => '#meta',
'recurring' => 'weekly',
Expand All @@ -217,6 +221,7 @@ public function _january_meetings() {
'datetime' => '2020-01-01T15:00:00+00:00',
'team' => 'Team-B',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'title' => 'A monthly meeting',
'location' => '#meta',
'recurring' => 'monthly',
Expand All @@ -233,6 +238,7 @@ public function _january_meetings() {
'datetime' => '2020-01-08T14:00:00+00:00',
'team' => 'Team-A',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'title' => 'A weekly meeting',
'location' => '#meta',
'recurring' => 'weekly',
Expand All @@ -249,6 +255,7 @@ public function _january_meetings() {
'datetime' => '2020-01-15T14:00:00+00:00',
'team' => 'Team-A',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'title' => 'A weekly meeting',
'location' => '#meta',
'recurring' => 'weekly',
Expand All @@ -265,6 +272,7 @@ public function _january_meetings() {
'datetime' => '2020-01-15T16:00:00+00:00',
'team' => 'Team-C',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'title' => 'Third Wednesday of each month',
'location' => '#meta',
'recurring' => 'occurrence',
Expand All @@ -284,6 +292,7 @@ public function _january_meetings() {
'datetime' => '2020-01-22T14:00:00+00:00',
'team' => 'Team-A',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'title' => 'A weekly meeting',
'location' => '#meta',
'recurring' => 'weekly',
Expand All @@ -300,6 +309,7 @@ public function _january_meetings() {
'datetime' => '2020-01-29T14:00:00+00:00',
'team' => 'Team-A',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'title' => 'A weekly meeting',
'location' => '#meta',
'recurring' => 'weekly',
Expand All @@ -316,6 +326,7 @@ public function _january_meetings() {
'datetime' => '2020-02-01T15:00:00+00:00',
'team' => 'Team-B',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'title' => 'A monthly meeting',
'location' => '#meta',
'recurring' => 'monthly',
Expand All @@ -332,6 +343,7 @@ public function _january_meetings() {
'datetime' => '2020-02-05T14:00:00+00:00',
'team' => 'Team-A',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'title' => 'A weekly meeting',
'location' => '#meta',
'recurring' => 'weekly',
Expand All @@ -348,6 +360,7 @@ public function _january_meetings() {
'datetime' => '2020-02-12T14:00:00+00:00',
'team' => 'Team-A',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'title' => 'A weekly meeting',
'location' => '#meta',
'recurring' => 'weekly',
Expand All @@ -364,6 +377,7 @@ public function _january_meetings() {
'datetime' => '2020-02-19T14:00:00+00:00',
'team' => 'Team-A',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'title' => 'A weekly meeting',
'location' => '#meta',
'recurring' => 'weekly',
Expand All @@ -380,6 +394,7 @@ public function _january_meetings() {
'datetime' => '2020-02-19T16:00:00+00:00',
'team' => 'Team-C',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'title' => 'Third Wednesday of each month',
'location' => '#meta',
'recurring' => 'occurrence',
Expand All @@ -399,6 +414,7 @@ public function _january_meetings() {
'datetime' => '2020-02-26T14:00:00+00:00',
'team' => 'Team-A',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'title' => 'A weekly meeting',
'location' => '#meta',
'recurring' => 'weekly',
Expand Down
4 changes: 4 additions & 0 deletions tests/test-meetingposttype.php
Expand Up @@ -38,6 +38,7 @@ function test_single_meeting() {
'time' => '01:00',
'recurring' => '',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'location' => '#meta',
),
)
Expand Down Expand Up @@ -67,6 +68,7 @@ function test_invalid_time() {
'time' => '0100 UTC', // Some production data is formatted like this
'recurring' => '',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'location' => '#meta',
),
)
Expand Down Expand Up @@ -98,6 +100,7 @@ function test_encoding() {
'time' => '01:00',
'recurring' => '',
'link' => '&wordpress.org',
'wptv_url' => '&https://wordpress.tv',
'location' => '&meta',
),
)
Expand All @@ -111,6 +114,7 @@ function test_encoding() {
++$found;
$this->assertEquals( 'Team-A&B', $meeting['team'] );
$this->assertEquals( '&wordpress.org', $meeting['link'] );
$this->assertEquals( '&https://wordpress.tv', $meeting['wptv_url'] );
$this->assertEquals( '&meta', $meeting['location'] );
$this->assertEquals( 'A & B meeting', $meeting['title'] );
}
Expand Down
3 changes: 3 additions & 0 deletions tests/test-shortcode.php
Expand Up @@ -38,6 +38,7 @@ function test_shortcode_simple() {
'time' => '01:00',
'recurring' => '',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'location' => '#meta',
),
)
Expand All @@ -56,6 +57,7 @@ function test_shortcode_simple() {
'time' => '02:00',
'recurring' => 'weekly',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'location' => '#meta',
),
)
Expand Down Expand Up @@ -87,6 +89,7 @@ function test_shortcode_cancelled() {
'time' => '01:00',
'recurring' => 'weekly',
'link' => 'wordpress.org',
'wptv_url' => 'https://wordpress.tv',
'location' => '#meta',
),
)
Expand Down

0 comments on commit 96a92e7

Please sign in to comment.