Skip to content

Instantly share code, notes, and snippets.

@GarySwift
Created May 9, 2018 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GarySwift/bcb2d49abfc8b4475c1acfdd101aec61 to your computer and use it in GitHub Desktop.
Save GarySwift/bcb2d49abfc8b4475c1acfdd101aec61 to your computer and use it in GitHub Desktop.
Unfinished notes for saving ACF field groups into post content. #WordPress #ACF
<?php
if ( ! function_exists('write_log')) {
function write_log ( $log ) {
if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ) );
} else {
error_log( $log );
}
}
}
add_action( 'save_post','wpse46583_save', 10, 2 );
function wpse46583_save( $post_id, $post ) {
// verify this is not an auto save routine.
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return;
// You should check nonces and permissions here
if ( ! current_user_can( 'edit_page', $post_id ) )
return;
// only for debugging, get an list of all templates for pages
write_log( get_page_templates() );
write_log($_REQUEST);
if ( esc_attr( $_REQUEST['page_template'] ) === 'page-templates/page-about.php' ) {
// No page template assigned - do something here.
// wp_die( 'wrong template' );
write_log('page-about.php');
$update_post = array(
'ID' => $post_id,
'post_content' => "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Error dolores autem dolorum voluptatum veritatis fugiat nihil vitae quas quia! Sequi deleniti sint labore suscipit expedita, praesentium eum nihil quod alias. ",
);
}
return;
}
function html_callout( $title, $content, $class = '' ) {
?>
<div class="callout-banner <?php echo $class ?>">
<div class="main-title-bar"><div><?php echo $title ?></div></div>
<div class="content">
<div class="cell-content bold"><?php echo $content ?></div>
</div>
</div>
<?php
}
function check_values($post_ID, $post_after, $post_before){
write_log( 'Post ID:');
write_log($post_ID);
write_log( 'Post Object AFTER update:');
write_log($post_after);
write_log( 'Post Object BEFORE update:');
write_log($post_before);
if ($post_ID === 19) {
$post_content = page_about_html( $post_ID );
// Update post 19
$update_post = array(
'ID' => $post_ID,
'post_content' => $post_content,
);
// Update the post into the database
// wp_update_post( $update_post );
}
}
// add_action( 'post_updated', 'check_values', 10, 3 ); //don't forget the last argument to allow all three arguments of the function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment