add some acf functionality

This commit is contained in:
Evan Mullins 2019-03-08 08:36:51 -07:00
parent c9ee301100
commit d05b7d76bf

View file

@ -20,4 +20,46 @@ add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
// set_theme_mod( 'page_layout', 'one-column' );
// Allow front end acf form edits
// https://usersinsights.com/acf-user-profile/
function my_acf_user_form_func( $atts ) {
$a = shortcode_atts( array(
'field_group' => ''
), $atts );
$uid = get_current_user_id();
if ( ! empty ( $a['field_group'] ) && ! empty ( $uid ) ) {
$options = array(
'post_id' => 'user_'.$uid,
'field_groups' => array( intval( $a['field_group'] ) ),
'return' => add_query_arg( 'updated', 'true', get_permalink() )
);
ob_start();
acf_form( $options );
$form = ob_get_contents();
ob_end_clean();
}
return $form;
}
add_shortcode( 'my_acf_user_form', 'my_acf_user_form_func' );
//adding AFC form head
function add_acf_form_head(){
global $post;
if ( !empty($post) && has_shortcode( $post->post_content, 'my_acf_user_form' ) ) {
acf_form_head();
}
}
add_action( 'wp_head', 'add_acf_form_head', 7 );
?>