From 87d74c8e461c9b2d193f79b034f4e38d899ad1c5 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Mon, 8 Aug 2016 09:36:55 +0200 Subject: [PATCH] Add ability to filter the source URL in the references. --- gp-includes/things/project.php | 16 +++++++++++++++- gp-templates/helper-functions.php | 3 +-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/gp-includes/things/project.php b/gp-includes/things/project.php index d3f48e7065..011e9c8f9d 100644 --- a/gp-includes/things/project.php +++ b/gp-includes/things/project.php @@ -234,7 +234,21 @@ public function regenerate_paths( $parent_project_id = null ) { public function source_url( $file, $line ) { if ( $this->source_url_template() ) { - return str_replace( array('%file%', '%line%'), array($file, $line), $this->source_url_template() ); + $source_url = str_replace( array( '%file%', '%line%' ), array( $file, $line ), $this->source_url_template() ); + + /** + * 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 + */ + return apply_filters( 'gp_reference_source_url', $source_url, $this, $file, $line ); } return false; } diff --git a/gp-templates/helper-functions.php b/gp-templates/helper-functions.php index e1f4c58b5e..ee9a817b1f 100644 --- a/gp-templates/helper-functions.php +++ b/gp-templates/helper-functions.php @@ -140,8 +140,7 @@ function references( $project, $entry ) { references as $reference ): list( $file, $line ) = array_pad( explode( ':', $reference ), 2, 0 ); - // TODO: allow the user to override the project setting - if ( $source_url = $project->source_url( $file, $line ) ): + if ( $project->source_url( $file, $line ) ) : ?>