Skip to content

Commit

Permalink
Merge pull request #200 from PRX/segment_redirect
Browse files Browse the repository at this point in the history
Add file url filter
  • Loading branch information
rpeterman-gp authored Apr 16, 2024
2 parents 06b9efb + 83949be commit c778f8f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions wp-content/plugins/tw-endpoint-helper/tw-endpoint-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,20 @@ function _peh_get_object_by_wp_fg_redirect_db( $slug ) {
/**
* Get post id from wp_fg_redirect table.
*
* @param array $slug string
* @param string $slug string
* @return bool|int
*/
function _peh_get_object_by_wp_migrated_legacy_alias_db( $slug ) {

global $wpdb;

$row = $wpdb->get_row( $wpdb->prepare( "SELECT `source`, `alias` FROM `wp_migrated_legacy_url_alias` WHERE `alias` = '%s' LIMIT 1;", $slug ) );
// Check if it starts with media/ to try to select file alias as well.
if ( 0 === strpos( $slug, 'media/' ) ) {
$slug_file = str_replace( 'media/', 'file/', $slug );
$row = $wpdb->get_row( $wpdb->prepare( "SELECT `source`, `alias` FROM `wp_migrated_legacy_url_alias` WHERE `alias` IN ('%s', '%s') LIMIT 1;", $slug, $slug_file ) );
} else {
$row = $wpdb->get_row( $wpdb->prepare( "SELECT `source`, `alias` FROM `wp_migrated_legacy_url_alias` WHERE `alias` = '%s' LIMIT 1;", $slug ) );
}

if (
isset( $row->source ) && $row->source
Expand Down Expand Up @@ -386,6 +392,8 @@ function _peh_get_object_by_wp_migrated_legacy_alias_db( $slug ) {

$type = $matches ? $matches[0] : $row->alias;
$id = str_replace( $check['replace'], '', $row->source );
// stop lookin for other types.
break;
}
}

Expand All @@ -408,6 +416,7 @@ function _peh_get_object_by_wp_migrated_legacy_alias_db( $slug ) {
break;

case 'media':
case 'file':
$wp_type = 'segment';
$wp_meta_key = 'fid';
break;
Expand Down

0 comments on commit c778f8f

Please sign in to comment.