Skip to content

Commit

Permalink
WCPT: Accept NextGen URL format in wordcamp post type
Browse files Browse the repository at this point in the history
  • Loading branch information
iandunn committed Jul 18, 2023
1 parent 8edecd8 commit 3ea133d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Expand Up @@ -76,6 +76,13 @@ public function data_url_matches_expected_format() {
2342,
true,
),

'events.wordpress.org url are also valid' => array(
'events.wordpress.test',
'/rome/2023/training/',
2342,
true,
),
);
}
}
Expand Up @@ -6,7 +6,7 @@

use function WordCamp\Sunrise\get_top_level_domain;

use const WordCamp\Sunrise\PATTERN_CITY_SLASH_YEAR_DOMAIN_PATH;
use const WordCamp\Sunrise\{ PATTERN_CITY_SLASH_YEAR_DOMAIN_PATH, PATTERN_CITY_YEAR_TYPE_PATH };

class WordCamp_New_Site {
protected $new_site_id;
Expand Down Expand Up @@ -78,7 +78,7 @@ public function render_site_url_field( $key, $field_type, $object_name ) {
<br /><br />

<span class="notice notice-large notice-warning">
Warning: This URL doesn't match the expected <code>city.wordcamp.org/year</code> format.
Warning: This URL doesn't match the expected format. It should be either <code>city.wordcamp.org/year/</code> or <code>events.wordpress.org/city/year/type/</code>.
</span>
<?php endif; ?>
<?php endif; // User can manage sites. ?>
Expand Down Expand Up @@ -127,7 +127,7 @@ public function save_site_url_field( $key, $field_type, $wordcamp_id ) {
$parsed_url = wp_parse_url( $url );

if ( ! self::url_matches_expected_format( $parsed_url['host'], $parsed_url['path'], $wordcamp_id ) ) {
wp_die( 'The URL does not match the expected <code>city.wordcamp.org/year/</code> format. Please press the back button and update it.' );
wp_die( "The URL doesn't match the expected format. It should be either <code>city.wordcamp.org/year/</code> or <code>events.wordpress.org/city/year/type/</code>. Please press the back button and update it." );
}

update_post_meta( $wordcamp_id, $key, esc_url( $url ) );
Expand Down Expand Up @@ -155,15 +155,21 @@ public static function url_matches_expected_format( $domain, $path, $wordcamp_id
$tld = get_top_level_domain();
$last_permitted_external_domain = 2341;
$external_domain_exceptions = array( 169459 );
$is_external_domain = ! preg_match( "@ \.wordcamp\.$tld | \.buddycamp\.$tld @ix", $domain );
$is_external_domain = ! preg_match( "@ \.wordcamp\.$tld | \.buddycamp\.$tld | events\.wordpress\.$tld @ix", $domain );
$can_have_external_domain = $wordcamp_id <= $last_permitted_external_domain || in_array( $wordcamp_id, $external_domain_exceptions );

if ( $is_external_domain && $can_have_external_domain ) {
// Many old camps had external websites.
return true;
}

return 1 === preg_match( PATTERN_CITY_SLASH_YEAR_DOMAIN_PATH, $domain . $path );
if ( "events.wordpress.$tld" === $domain ) {
$match = preg_match( PATTERN_CITY_YEAR_TYPE_PATH, $path );
} else {
$match = preg_match( PATTERN_CITY_SLASH_YEAR_DOMAIN_PATH, $domain . $path );
}

return 1 === $match;
}

/**
Expand Down

0 comments on commit 3ea133d

Please sign in to comment.