I want to separate the processing of public sites by administrator privileges

Asked 4 months ago, Updated 4 months ago, 8 views

While logged in to the WordPress administration screen with administrator privileges, I would like to separate the items to be displayed from regular users when I open a public site.

The public site tried to retrieve user information using wp_get_current_user, but failed to retrieve the user information.
While logged in to the administration screen, I am browsing with the same browser, but the public site cannot retrieve it.

When I dump it on the management screen, the user information appears, but will it not be handed over to the public site?

Also, if you know how to determine if you are an administrator and sort out the process, I would appreciate it if you could let me know.

My theme is storefront.
https://ja.wordpress.org/themes/storefront/

wp_get_current_user()

object(WP_User)#9332(8){
  ["data"] =>
  object(stdClass)#9345(0){
  }
  "ID" = >
  int(0)
  ["caps"] = >
  array(0){
  }
  ["cap_key"] =>
  Null
  "roles" = >
  array(0){
  }
  "allcaps" = >
  array(0){
  }
  ["filter"] =>
  Null
  ["site_id":"WP_User":private] =>
  int(0)
}

wordpress

2022-09-30 13:59

1 Answers

If it's the wordpress route installed by the public site side, (I'm sorry if it's not correct)
I think what you're looking at is different. If you put the following code at the beginning of the theme index.php, you'll see the logged-in user information.

if(is_user_logged_in()){
    print_r(wp_get_current_user());
    exit;
}

P.S. If require$_SERVER['DOCUMENT_ROOT'].'/wp-config.php'; calls the get_posts function outside of the wordpress directory, you will not be able to read the user information.

add_action('wp_login', 'hoge_login', 10, 2);

I think the only way to do this is to use to set the login information that has been hashed into cookies.


2022-09-30 13:59

If you have any answers or tips


© 2023 OneMinuteCode. All rights reserved.