Requiring Sign-In For Shortcode-Based Plugin - wordpress

Developing a plugin for personal use that adds data-driven content to WordPress pages through shortcodes. In the current implementation, the shortcode php checks if the visitor is authorized (specifically, if the visitor is me), displays the data-driven content if authorized, and displays a message if not.
Instead of a message, I'd like to do an auth_redirect. But by the time my shortcode is parsed, WordPress has already begun sending content to the client, so the redirect doesn't happen.
Is there a (simple) way to get auth_redirect behavior from shortcodes? For instance, can I somehow pass the return URL to the wp-login page? Or do the authorization check earlier in the page processing?

It's much simpler than I thought: I can simply href to the login page and pass the current page's url as parameter:
esc_url(wp_login_url( get_permalink()))
Hyperlinking to this sends me to the wp login page, and the get_permalink parameter ensures I return to the calling page after login.

Related

Callback URL - Social Logins

Can someone explain what the Callback URL is and what exactly it's used for?
I'm setting up Social login for my WordPress website and in Facebook and Twitter it asks for a callback URL.
At the moment i have left these blank and it works fine but was wondering what exactly are they used for?
I've read on other websites that it should be set like this:
http://mywebsite.com/user/facebook/login
But I don't understand what to use it for.
Is it to redirect the user to your site after they login via their social accounts? If that's the case, doesn't it do that without a callback URL?
Is it to redirect the user to your site after they login via their social accounts?
Yes.
If that's the case, doesn't it do that without a callback URL?
How would it know where to redirect back to, if that information wasn’t passed to it in the first place?
The callback URL is passed as a parameter in the login dialog call. That allows the login provider to a) redirect back to the app, and b) check if the app is even allowed to perform login under that URL.

Redirection not working with JQuery Mobile

I am running a DNN7.1 website. I have a regular website. I added a page which acts as login page for mobile users. I am using JQuery Mobile 1.3.2 on the mobile pages including this mobile login page. If the user navigates to that page and enters username and password, it works correctly and redirects them to the correct page sent on the url using a querystring, example:
http://localhost/Mobilelogin?url=http://localhost/somePage
it correctly redirects to
http://localhost/somePage
Now I want to add capability where user can directly send his username and password along with the url that he wants to navigate, the login page should authenticate using the username and password provided and once successful redirect it to the url (using asp.net Response.Redirect method), in the format
http://localhost/Mobilelogin?u=username&p=password&url=http://localhost/somePage
The issue is, it works fine if the user is not logged in but if he is already logged in and then uses the same url, (which has username and password) redirection doesn't work. I tried disabling the ajax using following code, as I read redirection and JQM doesn't work well.
$(document).on("mobileinit", function () {
$.extend($.mobile, {
linkBindingEnabled: false,
ajaxEnabled: false
});
});
But it still is not working. Can anyone please let me know what I need to do to make this work.
I tried debugging the login module, which is written in c#, when the user enters the url when not logged in, it calls the page load and hits the break point but when logged in and enters the url the break point is never hit. It looks like browser is not even contacting the server. I am new to JQM, I thought disabling the ajax globally will always hit the server to get the information. Is that not how it works? How can I make the redirection work in my case. Any help is greatly appreciated.
You need to be aware that by default, jQuery Mobile uses AJAX to load page content and does not "redirect" as per normal.
You should read the FAQ's as these provide useful information: -
http://view.jquerymobile.com/1.3.2/dist/demos/faq/
Specifically: -
.. it will only inject the contents of the response's body element (or
more specifically the data-role="page" element, if it's provided),
meaning nothing in the head of the page will be used
http://view.jquerymobile.com/1.3.2/dist/demos/faq/scripts-and-styles-not-loading.html
This might explain why your script doesn't execute, as if it's in the <head> it's not being loaded.

Facebook tab app - alternative landing page for "liked" users

I have developed one Facebook Application.
In facebook, page tab url I have specified a landing url, it is landing safely no issues.
Now I want if I click on like button, it should call another landing page.
What can be best solution for this ?
What you will have to do is read the signed_request passed to your tab application.
The signed_request will contain information on whether or not the current user "liked" the page that the app is on. Once you know if the user "liked" the page or not, in the even that s/he has already liked the page, you can redirect them to whatever URL you wish.
I see you have specified asp.net of which I have no knowledge, but I can tell you that the signed_request is passed to your application as a POST request. From there you need to parse the signed request and then you can read it's contents.
Here is a simple JavaScript redirect (in PHP) -
echo "<script language=javascript>";
echo "window.location.href ='".$url."';";
echo "</script>";

Facebook like frontpage for anonymous users

I'm currently building a site where I want anonymous users to see a page which talks about what the site is about, but shows no content. It only offers two options
Register
Login (username & password field)
Once the user logs in, they should be redirected to a specific frontpage.
I tried using drupal/front module, but that did not work. Anynmous access was always shown as access denied
I think I could LoginToboggan to redirect authenticated users but not sure what to do about the frontpage.
thanks
When you say that you want the front page to show now content you really just mean you only want to show static copy right?
One way to do this is with views and the context module.
Create blocks with views of the content that you want to hide.
Create some regular blocks from the blocks menu.
The magic happens with the context module. It lets you set up custom rules for which blocks to display where and when. You can set it so that some blocks show up for anon users and other blocks show up for authenticated.
Set it up so that the static copy that talks about the site shows up for anon users along with the login block.
You can tell context module load whatever content you need on the home page with views generated with blocks.
Set up context module to load all of your blocks for you instead of drupal's core block system.
I'm sure you could do this somehow with panels too, but I couldn't tell you how.
Make sure that the page you are redirecting to is accessible for anonymous users. The most likely reason for your acess denied message is that anonymous users do not have permission for that page.
You could also try the Rules module to redirect after login.
Checkout my response to a similar question answered on Drupal.org. I'll repost here as well:
http://drupal.org/node/1962546
I also used Context but with a few other items to help.
I've done this, not with Facebook or LinkedIn however but with another
login based site.
Required modules: Omega theme Context Delta Views Some type of access
control Custom version of r4032login
How I did it: All content is locked down. r4032login redirects all non
logged in users to login, even if they try to get to a certain page.
Create a new delta: In here I have create a content region and shown
only what I need (custom login page).
Context Checks User Role must be anonymous user It then has a rule to
activate a delta, which is basically a copy of your theme
functionality: (Homepage login)
The login is set to forward the user to /frontpage which is a view, it
requires authenticated permissions to view. Once a user is logged in,
the redirect module forwards to the /frontpage (main page) and
permissions are verified and they're in.
If you need more details let me know. This is more of a complex
implementation I have in place but I'm sure there are also others
interesting in doing it.

Changing Location of user Login Page in WordPress

I have a login form setup for my WordPress site, but when a user types in the wrong user/pass it directs them to the WP login screen. Is there any way that I can change this without hacking WPMU core?
You will have to use below filter to change the login url.
add_filter('login_url','wdm_login_url',10,2);
function wdm_login_url($login_url, $redirect)
{
$login_url = home_url().'/your-page-slug/';
return $login_url;
}
So every time, request goes to wp login screen, it will get redirected to your page
You should use a plugin. A search for "login" on WP Plugins can be helpful, maybe check out this plugin.
you can make the login form (wp-login.php), redirect them back by providing a hidden input text name 'redirect_to' in form that you have written. by using 'redirect_to', Wordpress understand that you want after login user will send to the link
forexample :
[pre]http://xxx.xxx/wp-login.php?redirect_to='http://xxx.xxx' [pre]

Resources