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 filter allowing change to the default file extension expected #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ add_filter( 'acf-flexible-content-extended.images_path', $path );

**NOTE:** The path should not have a trailing beginning or trailing slash!

You can filter the file extension the plugin searches for. By default the plugin expects `jpg`.

```php
add_filter( 'acf-flexible-content-extended.images_extension', $extension );
```

**NOTE:** The extension should not have a leading dot!

Additionally, you could filter all keys and/or images:

```php
Expand Down
13 changes: 11 additions & 2 deletions classes/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,20 @@ public function locate_image( $layout ) {
*/
$path = apply_filters( 'acf-flexible-content-extended.images_path', 'lib/admin/images/acf-flexible-content-extended' );

/**
* Allow to change the file extension expected
*
* @params string $extension : Extension to look for
*
* @return string
*/
$extension = apply_filters( 'acf-flexible-content-extended.images_extension', 'jpg' );

// Rework the tpl
$layout = str_replace( '_', '-', $layout );

$image_path = get_stylesheet_directory() . '/' . $path . '/' . $layout . '.jpg';
$image_uri = get_stylesheet_directory_uri() . '/' . $path . '/' . $layout . '.jpg';
$image_path = get_stylesheet_directory() . '/' . $path . '/' . $layout . '.' . $extension;
$image_uri = get_stylesheet_directory_uri() . '/' . $path . '/' . $layout . '.' . $extension;

// Direct path to custom folder
if ( is_file( $image_path ) ) {
Expand Down
6 changes: 6 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Also note that you can filter this path, but it **MUST** be in your theme:

**NOTE:** The path should not have a trailing beginning or trailing slash!

You can filter the file extension the plugin searches for. By default the plugin expects `jpg`.

`add_filter( \'acf-flexible-content-extended.images_extension\', $extension );`

**NOTE:** The extension should not have a leading dot!

Additionally, you could filter all keys and/or images:

`add_filter( \'acf-flexible-content-extended.images\', $images );`
Expand Down