Redirect user to login if not logged in, on specific pages

You can do it like this in admin section- add_action( ‘admin_init’, ‘redirect_non_logged_users_to_specific_page’ ); function redirect_non_logged_users_to_specific_page() { if ( !is_user_logged_in() && is_page(‘add page slug or i.d here’) && $_SERVER[‘PHP_SELF’] != ‘/wp-admin/admin-ajax.php’ ) { wp_redirect( ‘http://www.example.dev/page/’ ); exit; } And for frontend- add_action( ‘template_redirect’, ‘redirect_to_specific_page’ ); function redirect_to_specific_page() { if ( is_page(‘slug’) && ! is_user_logged_in() ) { … Read more

List all users and current week entries

If by “made an entry” you mean “has published at least 1 post”, then following will do it (with the proviso given below): $args = array ( ‘role’ => ‘spectator’, ) ; $spectators = new WP_User_Query ($args) ; $users_with_recent_posts = array () ; foreach ($spectators->get_results () as $user) { $args = array ( // if … Read more

How to set default’ => $current_user->user_login

Your question is not very clear to me but here’s a version of your code which you may try: <?php global $current_user; get_currentuserinfo(); return array( ‘author’ => array( ‘label’ => __(‘Author’, ‘ait-toolkit’), ‘type’ => ‘select-dynamic’, ‘dataFunction’ => ‘AitItemCpt::fillAuthorMetabox’, ‘default’ => $current_user->ID, // or try changing it to $current_user->user_login if it doesn’t work ‘capabilities’ => true, … Read more

Redirect users after login

I have tried your code with little modification in 2 Page Templates and it seems to be working. The only change I did was in the redirect parameter. Below is the updated code with the redirect parameter. You need to provide absolute path in redirect parameter. Please check the function reference of wp_login_form on following … Read more

Automatic Website user password generation

In Settings -> General -> Membership check the box Anyone can register. This setting allows new user to register and receive an e-mail with a link to reset his password. This method does not involve the administrator and it is secure, because no passwords are being send via e-mail.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)