Woocommerce move welcome message on navigation - woocommerce

I want to move the welcome message that appear on my account dashboard on the navigation menu. I cut the printF function from dashboard.php to navigation.php. The issue is that it returns "Hello" without the name of the user.
Must i call some method before ?

Did you define $current_user?
Like this:
$current_user = wp_get_current_user();

Related

Restrict frontend view to post author (and administrator)

I have a custom post type (audits). I am trying to make the each post only viewable in the frontend by the post author, and the administrator. So, essentially a private post only for logged in users that match the post author id and admin.
I've seen many answers for how to restrict the posts in the admin dashboard, but none for front end, since most posts are usually public.
Any help is greatly appreciated!
I would say that the approach depends on what you want the user to see if they are denied access to the post. Would you want to display a message saying you cannot view this post? Or throw a 404?
If you wanted to throw a 404, you could use the template_redirect action hook.
add_action('template_redirect', 'hide_from_unauth_users');
function hide_from_unauth_users() {
$author = get_the_author();
$user = wp_get_current_user();
$is_author = "some logic to determine if this is the author";
if( current_user_can('administrator') || ! is_user_logged_in() || ! $is_author ) {
//throw 404 and include 404.php template
}
}
If you wanted to display a message to the user, then you would simply run the exact same logic above on the actual single.php template and display an authorized message instead of the post title, content, etc.
Hope this points you in the right direction.

hide popup maker plugin link from wordpress

I installed pop up maker and capabilities plugin in wordpress for my website. I want to create one user who is not able to see the link for pop up maker. I tried with adding user with some capability but I am not able to hide pop up maker link.
How can I achieve this? Do I need to use another capability plugin?
You can use the remove_menu_page() function called via the admin_menu action hook. If you just want to remove the link for a single user, check the current user's ID first with wp_get_current_user().
function remove_admin_menu_item_for_user() {
$user = wp_get_current_user();
// Check to see if the current user's ID is the one we want to remove the page for
if ( $user->ID == ??? ){
// Use the $menu_slug for the page you want to remove
remove_menu_page( $menu_slug );
}
}
add_action( 'admin_menu', 'remove_admin_menu_item_for_user' );
If you would prefer to use a plugin Admin Menu Editor should work as well, though you may need the Pro version.

Custom action on user_register hook in WordPress

I try to implement a custom function/action after a new user profile has been created in WordPress. To test the code I try to write a text in a file as proof of function execution.
Here is the code that I have inserted at the end of the active theme's functions.php file
if ( ! function_exists( 'register_for_cmsa' ) ) :
function register_for_cmsa($user_id) {
// write in an external file
// writeLogWP($msg) is a function from a file I have included in index.php
writeLogWP("A new user is: " . $user_id);
}
add_action('user_register', 'register_for_cmsa');
endif;
Therefore, I added a new user through the admin panel. As soon as I validate the standard WP add user form (wp-admin/user-new.php) I get a blank page, meaning that the above code is in trouble. But the user is added in the database (it is visible in the users' list if I comment my function). The trouble here is when executing the writeLogWP("A new user is: " . $user_id) statement inside the register_for_cmsa() function.
I tried to see if the statement works outside of the function, while always inside the functions.php file. And I noticed that it writes the message to the external file when I navigate in the WP site, BUT it publishes blank page as soon as I get into the admin dashboard section.
My code is accepted in 'site' side but it is in error in the 'admin' one.
The code is however not executed in the 'site' side because the hook is not triggered. It is triggered only if I go to the 'wp-admin/user-new.php' but ... I can' test it, as per the above reason.
I am really confused, glad to have your comments and, why not, solution.
Thanks
The index.php is not loaded when accessing the WordPress admin, hence the writeLogWP function is not being called in that case. Moving it to functions.php should solve the issue.

How to create a wordpress custom settings page for a subscriber

Please let me first try to explain what I want to accomplish:
I am building a wordpress website for a small, local, but public swimming pool. The pool is only open when the weather is 'fine'. The lifeguard decides in the morning whether the pool will be open or not. This information should be easily maintained and be visible on the website.
I created a widget that displays whether the pool is open or not. The widget recieves the data from a custom table in de wordpress database. The background of the widget will be green when open, red when closed and orange if the lifeguard has not made a decission yet.
So far no problem. For the lifeguard I made an useraccount to login. The only thing he should be able to set/modify, is whether the pool is open today. He should not be allowed to edit/publish pages/posts or see anything else on the dashboard.
So my thoughts are to make the lifeguard a 'subscriber'. But now I am struggling how he can access an settingspage for the 'open or not option'. And where to make this settingspage?
First idea: Make it availaible in backend, but how can I assure it's available for a subcriber?
Second idea: Make it availaible in the frontend. But then, how can I do this?
Has anyone done such a thing? Can anyone point me to a solution for this?
Thanks!
Luc
To make things as clean as possible, I'd register a new custom lifeguard role and an open_pool capability that gets assigned to that role. You would give all your lifeguards the lifeguard role.
You could then add a dialog to either the front or back end using:
if (current_user_can ( 'open_pool' ) {
print $pool_open_close_form;
}
To get you started, take a look at this WPSE thread and the Roles and Capabilities section of the Codex.
Instead of basing this off a subscription, you could base if off a single log in using wp_get_current_user();
For example, in your functions.php file you could place the following.
$current_user = wp_get_current_user();
if($current_user->user_login == 'User1') {
function example_add_dashboard_widgets() {
wp_add_dashboard_widget(
'example_dashboard_widget', // Widget slug.
'Example Dashboard Widget', // Title.
'example_dashboard_widget_function' // Display function.
);
}
add_action( 'wp_dashboard_setup', 'example_add_dashboard_widgets' );
function example_dashboard_widget_function() {
// Display whatever it is you want to show.
echo "Hello World, I'm a great Dashboard Widget";
}
}
This would check the username matches 'User1', then would add a dashboard widget, meaning it would be the first thing the lifeguard sees when they log in. Of course this does mean potentially having a shared log if there are multiple lifeguards.
Sources:
http://codex.wordpress.org/Function_Reference/wp_get_current_user
http://codex.wordpress.org/Dashboard_Widgets_API
You could use a plugin like Adminimize (https://wordpress.org/plugins/adminimize/) to only display the lifeguard some menu function to change the status for the pool and remove all other posts/pages related menu items.

Wordpress plugins function code

I am trying to make a simple plugin that displays some info in the users profile page ( I have managed this part) but what I am not getting to work is I want to add a function that will check to see if a file exists on in a folder ( I can do this part ) but when I add a function into the plugin code it does not work or stops the page from showing up.
Any help would be great I just need to trigger the function on load of user looking at there profile.
function check_file(){
if($file == 'me.jpg'){
//do something
}
else{}
}
check_file();
Found the answer
add_action( 'show_user_profile', 'check_file' );
Above line will run the check_file function when user will see the profile.

Resources