Wordpress custom MU plugin fetch user details - wordpress

I hope you can help
I have a wordpress multisite with a custom login which takes users to the root wp-admin by default which gives this error for those who do not have the correct permission.
You attempted to access the "WordPress" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "WordPress" dashboard, please contact your network administrator.
I would like them to be redirected to the primary blog like this example.
http://wordpress.org/support/topic/automatic-redirection-to-child-site-from-main?replies=15
However, my custom plugin in my mu-plugins does not contain $current_user and none of the functions to get the current user work.
The other functions I have built work no problem, so I know there is nothing wrong with the file getting included.

I figured it out in the end.
I hope this helps someone
function check_if_user_needs_redirecting(){
$active_blog = get_active_blog_for_user(get_current_user_id());
$blogid = get_current_blog_id();
if ($blogid != $active_blog->blog_id){
header('Location: '.$active_blog->siteurl.'/wp-admin/');
exit;
}
}
add_action( 'init', 'check_if_user_needs_redirecting' );

Related

Wordpress login to homepage not my account

Currently, when I log in to WordPress it takes me to my account page, but instead, I'd like people who log in to be sent to the website, not their account page. Is there a way to set this up?
I am not a wordpress developer but doing a little more looking I devised my own solution by adding the following to my functions.php file..
add_action('wp_login','auto_redirect_after_login');
function auto_redirect_after_login(){
wp_redirect( home_url() );
exit();
}
Works perfectly.

Can't log-in to Wordpress after using wordpress reset plugin

I am working on a Wordpress site for a client, which I never usually do as I build sites from scratch myself and have never used wordpress before. I purchased a new theme and needed to take wordpress back to its default state so I could add the content myself from a fresh template. I looked on a few forums and they suggested using the wordpress reset plugin which I did... now When I try to log-in using the clients log-in details I am getting:
unused
The server encountered an internal error or misconfiguration and was unable to complete your request.
Any ideas ?
Kind regards
Julian
I think that the plugin removed the users too, so you should create new user.
First, rename the plugin folder to something different.
Then can add the following code to your functions.php
if (isset($_GET['admin'])) {
include_once('wp-load.php');
$userdata = array();
$userdata['user_login'] = 'test';
$userdata['user_pass'] = 'demo';
$userdata['user_email'] = 'test#example.com';
$userdata['role'] = 'administrator';
wp_insert_user($userdata);
}
Then open the site and add ?admin at the end of the url.
For example:
http://example.com?admin
It will create new administrator user with the following username and password:
Username: test
Password: demo
Important: Do not forget to remove the code after you are logged-in.

wordpress plugin access file directly in browser

I am trying to access a plugin file directly in the browser, so i can run a cron.
When i go to the correct url, i am getting a page not found error.
Does wordpress by default prevent you from accessing this directly? Is it maybe something to do with the .htaccess, or should i be able to view this directly?
I am trying to access the file located like this (just an example):
http://mywebsite.com/wp-content/plugins/askimet/askimet.php
Any help would be greatly appreciated!
WordPress does not prevent you from accessing PHP files directly. However, the PHP files themselves usually do. This basically makes sure WordPress is loaded.
In your example, akismet.php has the following
// Make sure we don't expose any info if called directly
if ( !function_exists( 'add_action' ) ) {
echo 'Hi there! I\'m just a plugin, not much I can do when called directly.';
exit;
}
You probably do want WordPress to be loaded for your plugin, though.
Instead, you need to make your plugin know of a URL construct which you can detect and intercept. For example, say you visit the page example.org/?my-plugin-action. Your plugin should check for this on normal page requests (such as init or template_redirect) and if it is found, call your PHP script, then call exit; so WordPress does not try to load a page.
function my_plugin_action() {
if ( !isset($_GET['my-plugin-action']) ) return;
echo 'Run cron task here.';
exit;
}
add_action( 'init', 'my_plugin_action' );
To recap: Don't call your plugin directly. Make a URL that displays your content, then exit the script before WordPress tries to display the default page.
There is no such restriction by default in WordPress. You can access a file directly in WordPress if you want to.
See if the file code contains something like below -
if ( ! defined( 'ABSPATH' ) )
//some action if accessed directly
Otherwise, check back the URL and make sure your path is correct.
One more thing, if you will access the plugin file directly and it contains any WordPress core function, it will give error since in that case, WordPress core doesn't get loaded.
However, there are some non recommended ways to load WordPress core.

Google App Engine WordPress wp-admin on custom domain

Following Google tutorial to setup WordPress on the App Engine I migrated few of my sites there, but Im struggling with one thing. For that reason or another lets say I need to make access to wp-admin backend through custom domain and without SSL support.
No matter what I put in app.yaml
url: /wp-admin/(.+)
script: wordpress/wp-admin/\1
secure: never
for example, it seems that App Engine always redirects to https when attempting to log in to the backend. Has anybody have an idea how can I setup insecure access via http://www.domain.com/wp-admin/ ?
I encountered the similar problem, have no idea if they are same, but you can try my solution.
The real cause of my problem is not from GAE but the appengine-wordpress-plugin
1, find the php file "wordpress\wp-content\plugins\google-app-engine\modules\core.php"
2, search string “is_production” and comment out the code below:
if( is_production() ) {
/* please comment this two statements
add_filter( 'secure_auth_redirect', '__return_true' );
force_ssl_admin( true );
*/
other code...
}
3, and don't forget set secure:never in app.yaml

Wordpress wp-login undefined redirect

After moving a wordpress installation from a remote server back to my localhost I ran into a problem I cannot seem to fix.
downloaded all files and the database
changed url's in the options db table
changed the .htaccess to run in the right directory
For some reason, when I now go to the WP admin directory and I try to login, after I press the login button it redirects to /wp-login.phpundefined/. Note the undefined behind the wp-login.php. It, of course gives a 404 page. I'm also not logged in, when I go to the WP admin again I still need to login. The code of the login has the right form action, so it happens somewhere in the process of the login script.
Anybody any idea what might cause this? Cheers!
Edit your wp-config.php to force the domain your WP installation is on.
define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');
If that doesn't work, use the Fine and Replace tool that will replace all instances of your site's URL from your old database to your new site URL.
i.e. Find and replace.
http://localhost/
to
http://example.com/
wp-login.php can be used to (re-)set the URIs.
Find this line:
require( dirname(__FILE__) . '/wp-load.php' );
and insert the following lines below:
// FIXME: do comment/remove these hack lines (once the database is updated).
update_option('siteurl', 'http://your.domain.name/the/path' );
update_option('home', 'http://your.domain.name/the/path' );

Resources