Reference ACF User Field on Front-End Form #2

Closed
owsleye opened this Issue Mar 20, 2012 · 7 comments

Projects

None yet

2 participants

@owsleye
owsleye commented Mar 20, 2012

Hello,

I am using your user field code to add a new field to the Advanced Custom Fields Wordpress plugin. Works great in the WP admin interface, but I am also trying to use the new front-end form feature in ACF, where you can include ACF forms in page templates. When I display a form containing the custom user field, I receive the following error:

Fatal error: Call to undefined function get_editable_roles() in /nfs/c07/h02/mnt/99917/domains/alert.washingtonandlee.net/html/wp-content/themes/wlualert/fields/users-field.php on line 182

Can you help me to properly define the get_editable_roles() function when used inside the loop?

Thanks,
Eric Owsley

@lewismcarey
Owner

Hi Eric,

I've not had a chance to use this feature yet.

I can only assume get_editable_roles() - which is a wordpress function is not made available on the front end or cannot be used inside the loop. I'm sure there will be a way to register it.

I'll have a look into it as soon as I can. It's a long shot but are you outputting wp_head() in your header.php?

@lewismcarey
Owner

I have found this article: http://wordpress.stackexchange.com/questions/34778/using-admin-functions-on-frontend
The include get_editable_roles() would need is users.php
I can't help but think there will be a better way to do this, but maybe if you could give it a go by adding it into users-field.php and wrapping it in a function check:
if ( !function_exists('get_editable_roles') ) { require_once( ABSPATH . '/wp-admin/includes/user.php' ); }
I won't be able to test this until the weekend. Any input would be really great!

@owsleye
owsleye commented Mar 20, 2012

I did not have wp_head() in the header.php file, but unfortunately that
didn't do the trick. I'll try the function check and let you know how it
goes.

Thanks.

On Tue, Mar 20, 2012 at 4:27 PM, Lewis Carey <
reply@reply.github.com

wrote:

I have found this article:
http://wordpress.stackexchange.com/questions/34778/using-admin-functions-on-frontend
The include get_editable_roles() would need is users.php
I can't help but think there will be a better way to do this, but maybe if
you could give it a go by adding it into users-field.php and wrapping it in
a function check:
if ( !function_exists('get_editable_roles') ) { require_once( ABSPATH .
'/wp-admin/includes/user.php' ); }
I won't be able to test this until the weekend. Any input would be really
great!


Reply to this email directly or view it on GitHub:

#2 (comment)

@owsleye
owsleye commented Mar 20, 2012

Worked like a charm! This is huge. Building a communal checklist for
emergency communications procedures at a small college. This let's users
assign tasks to other users and mark items complete. Thanks, again.

Best,
Eric

On Tue, Mar 20, 2012 at 4:27 PM, Lewis Carey <
reply@reply.github.com

wrote:

I have found this article:
http://wordpress.stackexchange.com/questions/34778/using-admin-functions-on-frontend
The include get_editable_roles() would need is users.php
I can't help but think there will be a better way to do this, but maybe if
you could give it a go by adding it into users-field.php and wrapping it in
a function check:
if ( !function_exists('get_editable_roles') ) { require_once( ABSPATH .
'/wp-admin/includes/user.php' ); }
I won't be able to test this until the weekend. Any input would be really
great!


Reply to this email directly or view it on GitHub:

#2 (comment)

@lewismcarey
Owner

Oh good, I'll see if there is a slicker way to do it before committing the change.
I'll credit you for the spot though.

Thanks Eric!

@lewismcarey
Owner

Current Patch - add to users-field.php:

    if ( !function_exists('get_editable_roles') ) { 
        require_once( ABSPATH . '/wp-admin/includes/user.php' ); 
    }
@lewismcarey
Owner

This has now been included in the latest commit in the admin_head().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment