I am using wordpress multisite to create blog in my main site. Wordpress multisite allows us to signup for either user or blog, but i need to create a blog and a user at the same time and the user created need to be assigned as the admin of the blog created. Well i created a user and set it as administrator by changing it's metadata (wp_capabilities, wp_user_level) but when i tried to login to the admin of the blog created then it says you don't have sufficient priviledge. Do anyone know what do i missing?
Thanks in advance.
You have to create a custom registration. Create a new page: registration. In the theme folder make a page-registration.php file, and in the file create your form and the registration function, that should go something like this:
if($_POST)
{
$data=$_POST;
$validateuser=wpmu_validate_user_signup($data['user_name'],$data['user_email']);
$validateblog=wpmu_validate_blog_signup($data['user_name'],$data['blog_title']);
$usererrors=$validateuser['errors']->errors;
$blogerrors=$validateblog['errors']->errors;
if(!$usererrors && !$blogerrors)
{
$meta = array ('lang_id' => 1,'public' => 1);
$meta = apply_filters( 'add_signup_meta', $meta );
$path='/'.$data['user_name'].'/';
wpmu_signup_blog($domain,$path,$data['blog_title'],$data['user_name'],$data['user_email'], $meta);
}
}
note: this is only an example where the new blogname is the same as your username
leave a comment if you need more detailed instructions or have any additional questions
Related
I have a member only area for my website and naturally, this requires the user to log in.
The problem is that the plugin did not come with a custom login page. so when someone tries to access this page, they are then directed to 'mysite.com/wp-login.php'
I have added custom login plugins in the hope that they would override the redirect but no joy.
I am intending on changing the wp-login slug to something else for security reasons and would like the plugin to redirect users to a different login page.
I have been searching online and cannot find anything, only redirects after login. I have also raised the question on the plugin authors support page and got no reply
I was hoping someone here could help.
The plugin I am using is called WP Customer Area.
So basically, to summarise...
I would like the plugin to stop directing customers to 'mysite.com/wp-login.php' and instead change it to something like 'mysite.com/customer-login'.
code I believe handles the redirect
public function login_then_redirect_to_url($redirect_to = '')
{
$login_url = apply_filters('cuar/routing/login-url', null, $redirect_to);
if ($login_url == null) {
$login_url = wp_login_url($redirect_to);
}
wp_redirect($login_url);
exit;
}
I managed to solve the issue by amending the wp_login_url($redirect_to);
I added the below code to functions.php:
add_filter( 'login_url', 'my_login_page', 10, 3 );
function my_login_page( $login_url, $redirect, $force_reauth ) {
return home_url( '/my-login-page/?redirect_to=' . $redirect );
}
I have the following code in my PHP code that is done outside WordPress in another CMS that uses WordPress for the Blog section.
$user_info = get_logged_in_user_info($_SERVER['REMOTE_USER']);
define("USERINFO_MEMBERID", $user_info['memberid']);
define("USERINFO_USERNAME", $user_info['username']);
define("USERINFO_EMAIL", $user_info['email']);
define("USERINFO_TRIAL", $user_info['trial']);
I would like to use this info to log the user into WordPress when they get to the WordPress page.
Caveat is if this info isn't set, just leave them not logged in.
Thanks in advance.
you can use the wp_get_current_user() to get logged in user information.
$user_info = wp_get_current_user();
if($user_info->exists()){
define("USERINFO_MEMBERID", $user_info->memberid);
define("USERINFO_USERNAME", $user_info->username);
define("USERINFO_EMAIL", $user_info->email);
define("USERINFO_TRIAL", $user_info->trial);
}
I am trying to input a dashboard (simple html & css) above the page title on my wordpress site but only for the pages with the ID 777, 880 and 374.
I am assuming I need to make a function using is_page and then add that function to my page.php file but I can't seem to work it out.
Thanks for any help,
Scott
You could add logic like this to your page.php
<?php
if(is_page(777) || is_page(880) || is_page(374)) {
// Special Page Content Goes Here...
}
?>
** This will only work if the ID's are actually pages and not posts. Otherwise the conditional logic would be different.
Hold an array somewhere in your application with the allowed users (if just a few and not growing):
$allowedUsers = array('777' => true, '880' => true, '374' => true);
$userId = [current user id];
if($allowedUsers[$userId]) {
// Display dashboard content
}
If you have a more advanced user management system you should instead have priviliges and/or roles set for each specific user.
I need for user to register on a wordpress site only with username and password .
So a new user comes , wants to register and he is asked to choose a username and a password, no email verification nothing.
Does anyone have any ideea ?
I think this codex entry might be what you're looking for: http://codex.wordpress.org/Function_Reference/wp_new_user_notification
You could overwrite it to simply do nothing, that way the user won't be receiving an e-mail.
If you're unfamiliar with PHP or coding for WordPress it would be helpful to read up on the basics of Theme development here: http://codex.wordpress.org/Theme_Development
In your case, all that needs to be done is this code should be added to the functions.php file of your currently active Theme:
if ( !function_exists('wp_new_user_notification') ) {
function wp_new_user_notification( ) {}
}
I'm building a small web app to sit within an existing Wordpress membership site.
At the moment, all of the content is protected using Digital Access Pass, which handles user authentication and content protection.
I'm thinking of using Yii for this, and installing it into a subdirectory of the Wordpress site.
My plan is to have this layout:
www.site.com (wordpress blog)
www.site.com/members (content protected with the Digital Access Pass membership solution, set up in Wordpress)
www.site.com/members/app (yii folder - protected by DAP, but not set up in Wordpress)
I don't want to do a full integration, as I'm using a lot of Ajax and that doesn't look like it will work too well from the examples I've seen.
What I'd like is to use DAP to protect the pages and handle authentication, and also to pass the logged- in userid to Yii so I can use as a key to store user preferences, user data, etc.
The way DAP works is that you just insert the following code into any page you want to protect, and then you can access a User object that contains the info I need.
<?php
include_once "../dap/dap-config.php";
$user = null;
if( !Dap_Session::isLoggedIn() ) {
//send viewer to login page
header("Location:".SITE_URL_DAP.Dap_Config::get("LOGIN_URL"));
exit;
}
else if( Dap_Session::isLoggedIn() ) {
//get userid
$session = Dap_Session::getSession();
$user = $session->getUser();
$user = Dap_User::loadUserById($user->getId()); //reload User object
if(!isset($user)) {
//send viewer to login page
header("Location:".SITE_URL_DAP.Dap_Config::get("LOGIN_URL"));
exit;
} else {
$userProducts = Dap_UsersProducts::loadProducts($user->getId());
}
}
?>
How do I go about implementing this in Yii?
I'd start by taking a look at Yii Filters
You should be able to put your code in the filter and then have it run (much like the built-in Access Control Filter)
And then, if you're going to build your app truly Yii-like, you might want to work on wrapping the DapUser in a CUserIdentity class and making it work well with the CWebUser object. It would take a bit of work, but then you'd truly have easy access to the user info in all Yii objects.
Good luck!