Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Sep 13, 2016

Conversation

@akirk
Copy link
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
Copy link
Member

ocean90 commented Sep 4, 2016

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

@akirk akirk force-pushed the akirk:filter/reference_source_url branch 2 times, most recently from 87d74c8 to 94105f7 Sep 8, 2016
@akirk
Copy link
Contributor Author

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 force-pushed the akirk:filter/reference_source_url branch 2 times, most recently from 459dd45 to 4187974 Sep 8, 2016
@akirk akirk force-pushed the akirk:filter/reference_source_url branch from 4187974 to 2abd269 Sep 8, 2016
* @param string $file The referenced file name.
* @param string $line The line number in the referenced file.
*
* @return string|false

This comment has been minimized.

@ocean90

ocean90 Sep 8, 2016 Member

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

* @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.

This comment has been minimized.

@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.

@ocean90 ocean90 merged commit b895ce0 into GlotPress:develop Sep 13, 2016
1 of 2 checks passed
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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.