Skip to content

Commit

Permalink
updated ACF Image Support
Browse files Browse the repository at this point in the history
This is an update to #123 - credits to @laneparton

I've only changed the bootstrapping of the ACF relevant part to be
fired after the theme is loaded - in case ACF is loaded within the
theme.
  • Loading branch information
felly committed Nov 25, 2021
1 parent 8b73c08 commit 0ac1a73
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/ACF/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class Image
*/
private $siteSwitcher;

/**
* @var \ACF_Data
*/
private $store;

/**
* Image constructor
*
Expand Down
17 changes: 10 additions & 7 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ public function onLoad()

add_filter('register_post_type_args', [$rest, 'registerPostTypeArgs'], 10, 2);
add_filter('rest_request_after_callbacks', [$rest, 'restRequestAfterCallbacks'], 10, 3);


if (\function_exists('wc')) {
$this->wcBootstrap($site, $singleSwitcher);
}

if (\function_exists('acf')) {
$this->acfBootstrap($site, $singleSwitcher);
}
$this->acfBootstrap($site, $singleSwitcher);
}

/**
Expand All @@ -92,8 +90,13 @@ public function wcBootstrap(Site $site, SingleSwitcher $siteSwitcher)
*/
public function acfBootstrap(Site $site, SingleSwitcher $siteSwitcher)
{
$acfImage = new ACF\Image($site, $siteSwitcher);

add_filter('acf/load_value/type=image', array($acfImage, 'acfLoadValue'), 10, 3);
// ACF can be included within a theme too - check in after_setup_theme action
// https://www.advancedcustomfields.com/resources/including-acf-within-a-plugin-or-theme/
add_action('after_setup_theme', function() use ($site, $siteSwitcher) {
if (\function_exists('get_field')) {
$acfImage = new ACF\Image($site, $siteSwitcher);
add_filter('acf/load_value/type=image', array($acfImage, 'acfLoadValue'), 10, 3);
}
});
}
}

0 comments on commit 0ac1a73

Please sign in to comment.