Add ability to filter the source URL in the references #522

Merged
merged 2 commits into from Sep 13, 2016

Projects

None yet

3 participants

@akirk
Contributor
akirk commented Aug 8, 2016

This allows to create a filter that modifies the URLs for the files listed under References.

Example usage:

add_filter( 'gp_reference_source_url', function( $source_url, $project, $file, $line ) {
// Libraries don't reside in our repo but we have them translatable through GlotPress.
if ( preg_match( '#^lib/#', $file ) ) {
     return false; 
}
return $source_url;
}, 10, 4 );

Possible uses:

  • for projects that include strings from different sources
  • for only partially linkable source texts

This fixes a TODO source line.

I have already used @since 2.2.0 for the docs but this can of course be changed depending on which version this lands with.

@toolstack toolstack added this to the 2.2 milestone Aug 8, 2016
@ocean90 ocean90 removed the ready for merge label Sep 4, 2016
@ocean90
Member
ocean90 commented Sep 4, 2016

Why is the filter in the template and not in GP_Project::source_url()?

@akirk
Contributor
akirk commented Sep 8, 2016

@ocean90 Fair point. I've moved it. I didn't think much to put it somewhere else because of the TODO comment.

@akirk akirk Add ability to filter the source URL in the references.
2abd269
@ocean90 ocean90 commented on an outdated diff Sep 8, 2016
gp-includes/things/project.php
}
- return false;
+
+ /**
+ * Allows per-reference overriding of the source URL defined as project setting.
+ *
+ * @since 2.2.0
+ *
+ * @param string $source_url The originally generated source URL.
+ * @param GP_Project $project The current project.
+ * @param string $file The referenced file name.
+ * @param string $line The line number in the referenced file.
+ *
+ * @return string|false
@ocean90
ocean90 Sep 8, 2016 Member

We don't use @return tags for hook docs.

@ocean90 ocean90 commented on an outdated diff Sep 8, 2016
gp-includes/things/project.php
}
- return false;
+
+ /**
+ * Allows per-reference overriding of the source URL defined as project setting.
+ *
+ * @since 2.2.0
+ *
+ * @param string $source_url The originally generated source URL.
+ * @param GP_Project $project The current project.
+ * @param string $file The referenced file name.
+ * @param string $line The line number in the referenced file.
@ocean90
ocean90 Sep 8, 2016 Member

There should be only one space between GP_Project and $project. Same for $source_url and its descriptions. The other parameters should be aligned accordingly.

$source_url can be false too:
@param string|false $source_url The originally generated source URL, or false if no URL is available.

@akirk akirk Update doc block
e05c5cb
@ocean90 ocean90 merged commit b895ce0 into GlotPress:develop Sep 13, 2016

1 of 2 checks passed

codecov/project 35.64% (-0.01%) compared to e06e768
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment