Home › Forums › General Issues › Cannot access acf fields on user login
I need to get_field() in a plugin i have working.
I have tried using the wp_login-hook, the set_current_user-hook.
Code underneath for reference.
defined('ABSPATH') or die('Unathorized Access');
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
add_action( 'wp_login', 'media_uploader_with_ending', 10, 2 );
add_action( 'set_current_user', 'does_file_exists');
// include_once(MY_ACF_PATH . 'acf.php' );
// Define path and URL to the ACF plugin.
define( 'MY_ACF_PATH', plugin_dir_path(__FILE__) . '/includes/acf/' );
define( 'MY_ACF_URL', plugin_dir_path(__FILE__) . '/includes/acf/' );
// Include the ACF plugin.
include_once( MY_ACF_PATH . 'acf.php' ); // line 24
// Customize the url setting to fix incorrect asset URLs.
add_filter('acf/settings/url', 'my_acf_settings_url');
function my_acf_settings_url( $url ) {
return MY_ACF_URL;
}
// (Optional) Hide the ACF admin menu item.
add_filter('acf/settings/show_admin', 'my_acf_settings_show_admin');
function my_acf_settings_show_admin( $show_admin ) {
return true;
}
$user_id = get_current_user_id();
$user_field = get_field('field_61f54de40ed41', 'user_' . $user_id); // line 42
function does_file_exists($user_field, $user_id){
$user_field = get_field('field_61f54de40ed41', 'user_' . $user_id);
if ($user_field && isset($user_field["url"]) && $user_field["url"] != "") {
return true;
} else {
return false;
}
}
if (does_file_exists($user_id, $user_field)){
media_uploader_with_ending();
}
Error messages
Warning: include_once(C:\Users\helloworld\Local Sites\imagefromapiutenauth0\app\public\wp-content\plugins\MediaUploaderWithEnding//includes/acf/acf.php): failed to open stream: No such file or directory in C:\Users\helloworld\Local Sites\imagefromapiutenauth0\app\public\wp-content\plugins\MediaUploaderWithEnding\MediaUploaderWithEnding.php on line 24
Warning: include_once(): Failed opening ‘C:\Users\helloworld\Local Sites\imagefromapiutenauth0\app\public\wp-content\plugins\MediaUploaderWithEnding//includes/acf/acf.php’ for inclusion (include_path=’.:/usr/share/php:/www/wp-content/pear’) in C:\Users\hellworld\Local Sites\imagefromapiutenauth0\app\public\wp-content\plugins\MediaUploaderWithEnding\MediaUploaderWithEnding.php on line 24
( ! ) Fatal error: Uncaught Error: Call to undefined function get_field() in C:\Users\helloworld\Local Sites\imagefromapiutenauth0\app\public\wp-content\plugins\MediaUploaderWithEnding\MediaUploaderWithEnding.php on line 42
( ! ) Error: Call to undefined function get_field() in C:\Users\helloworld\Local Sites\imagefromapiutenauth0\app\public\wp-content\plugins\MediaUploaderWithEnding\MediaUploaderWithEnding.php on line 42
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
ACF’s Repeater field is a versatile solution for repeating content in #WordPress.
— Advanced Custom Fields (@wp_acf) December 29, 2022
What’s your favorite use case for the Repeater field?
What’s the weirdest thing you’ve ever used it for?
Let us know!👇
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.