add some acf functionality
This commit is contained in:
parent
c9ee301100
commit
d05b7d76bf
1 changed files with 42 additions and 0 deletions
|
@ -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 );
|
||||
|
||||
?>
|
Loading…
Reference in a new issue