generated from pascalmartineau/wp-skeleton
wip: dynamic preview
This commit is contained in:
30
wp-content/themes/ccat/includes/vendors/acf.php
vendored
30
wp-content/themes/ccat/includes/vendors/acf.php
vendored
@@ -1,5 +1,35 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// Override template file path for ACF previews
|
||||||
|
add_filter( 'acfe/flexible/render/template', 'ccat_acfe_flexible_render_template', 10, 4 );
|
||||||
|
function ccat_acfe_flexible_render_template( $file, $field, $layout, $is_preview ) {
|
||||||
|
if ( ! $is_preview ) {
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
// Return relative path - ACF Extended Pro will use acfe_locate_file_path() to find it
|
||||||
|
return 'layouts/preview.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable caching for preview requests
|
||||||
|
add_action( 'acfe/flexible/render/before_template', 'ccat_disable_cache_for_preview', 1, 3 );
|
||||||
|
function ccat_disable_cache_for_preview( $field, $layout, $is_preview ) {
|
||||||
|
if ( ! $is_preview ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable WordPress object cache for this request
|
||||||
|
wp_cache_flush();
|
||||||
|
|
||||||
|
// Send no-cache headers
|
||||||
|
nocache_headers();
|
||||||
|
|
||||||
|
// Disable ACF cache if function exists
|
||||||
|
if ( function_exists( 'acf_get_store' ) ) {
|
||||||
|
acf_get_store( 'fields' )->reset();
|
||||||
|
acf_get_store( 'field-groups' )->reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Disable ACF / ACFE modules
|
// Disable ACF / ACFE modules
|
||||||
add_action( 'acf/init', 'ccat_acf_init' );
|
add_action( 'acf/init', 'ccat_acf_init' );
|
||||||
function ccat_acf_init() {
|
function ccat_acf_init() {
|
||||||
|
|||||||
1
wp-content/themes/ccat/layouts/preview.php
Normal file
1
wp-content/themes/ccat/layouts/preview.php
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<pre><?php var_dump( get_row( true ) ); ?></pre>
|
||||||
3
wp-content/themes/ccat/server/api/acf-preview.post.ts
Normal file
3
wp-content/themes/ccat/server/api/acf-preview.post.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export default defineEventHandler(() => {
|
||||||
|
return `<div>TODO: Preview from Nuxt API endpoint</div>`;
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user