Skip to content

Commit

Permalink
feat(api): adds filter for restricting watermark based on image sourc…
Browse files Browse the repository at this point in the history
…e urls
  • Loading branch information
selul committed Mar 10, 2019
1 parent 3250a8d commit 337d7fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 4 additions & 4 deletions inc/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ private function set_defaults() {
/**
* Return transformed url.
*
* @param bool $signed Either will be signed or not.
* @param array $params Either will be signed or not.
*
* @return string Transformed image url.
*/
public function get_url( $signed = false ) {
public function get_url( $params = [] ) {
$path_parts = array();

$path_parts[] = $this->width->toString();
Expand All @@ -108,15 +108,15 @@ public function get_url( $signed = false ) {
$path_parts[] = $this->resize->toString();
}

if ( is_array( self::$watermark->get() ) && isset( self::$watermark->get()['id'] ) && self::$watermark->get()['id'] > 0 ) {
if ( isset( $params['apply_watermark'] ) && $params['apply_watermark'] && is_array( self::$watermark->get() ) && isset( self::$watermark->get()['id'] ) && self::$watermark->get()['id'] > 0 ) {
$path_parts[] = self::$watermark->toString();
}

$path = '/' . $this->source_url;

$path = sprintf( '/%s%s', implode( '/', $path_parts ), $path );

if ( $signed ) {
if ( isset( $params['signed'] ) && $params['signed'] ) {
$path = sprintf( '/%s%s', $this->get_signature( $path ), $path );
}

Expand Down
11 changes: 7 additions & 4 deletions inc/url_replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ public function init() {
*/
public function build_image_url(
$url, $args = array(
'width' => 'auto',
'height' => 'auto',
)
'width' => 'auto',
'height' => 'auto',
)
) {

if ( apply_filters( 'optml_dont_replace_url', false, $url ) ) {
Expand Down Expand Up @@ -184,7 +184,10 @@ public function build_image_url(
$args['height'] = $args['height'] > $this->max_height ? $this->max_height : $args['height'];
}

$new_url = ( new Optml_Image( $url, $args ) )->get_url( $this->settings->use_lazyload() ? false : $this->is_allowed_site );
$new_url = ( new Optml_Image( $url, $args ) )->get_url( [
'signed' => $this->settings->use_lazyload() ? false : $this->is_allowed_site,
'apply_watermark' => apply_filters( 'optml_apply_watermark_for', true, $url )
] );

return $is_slashed ? addcslashes( $new_url, '/' ) : $new_url;
}
Expand Down

0 comments on commit 337d7fa

Please sign in to comment.