2

I have one system (built in Laravel 4.2) and I want to integrate it with Wordpress.

Only authenticaed users can access this blog.

I think in 2 options:

1 -> In routes.php include something like

Route::group(array('before' => 'auth')), function() {
    Route::get("wordpress", function() {
         require_once public_path() . '/blog/wp-load.php';
         exit;
    });
});

Only auth users can see blogs routes. If someone try to access without login, It will show 404 error (this code doesn't work, only one example).

2 -> Integrate Laravel with Wordpress. When create a new user in Laravel, It will create also in Wordpress. When access blog, It will automatically log user into Wordpress.

Andre Trevas
  • 51
  • 10
  • You can also ask this question at their forum. As both laravel and Wordpress uses their own routing and folder structure. – Niklesh Raut Mar 08 '17 at 04:05

2 Answers2

0

To create a union user system, I suggest that you use WordPress REST API & OAuth (Authentication System) it has a WordPress plugin you can use the data for both sides, Laravel & WordPress.

To authenticate users from Laravel application to allow them to view WordPress specific directory, you should generate WordPress authentication cookies from Laravel then redirect.

I think these articles may help you to start:

How to use WordPress as a backend for a Laravel Application

Using the WordPress REST API / Authentication

WordPress REST API - OAuth 1.0a Server

Mahmoud Kassem
  • 409
  • 5
  • 9
0

Mahmoud, thank you.

I solved this problem with the function wp_set_auth_cookie($user_id, true);

After log-in in my system I call one function that use wp_set_auth_cookie and login the user into Wordpress.

Andre Trevas
  • 51
  • 10
  • This does **not** answer the question in a useful way. _why_ do you believe this is the answer? _how_ does it work? Simply telling someone to _change their code_ without any context or meaning does not help them learn what they did wrong. – GrumpyCrouton Jun 10 '17 at 03:53
  • I used the second option. Create a Wordpress user is easy, you can find it. (I answered my own question, so I marked it as answer). After create the user, I did: require("/pathToWpLoad/wp-load.php"); $user_id = username_exists($email); $userdata = get_userdata($user_id); $user = set_current_user($user_id,$username); wp_set_auth_cookie($user_id, true); – Andre Trevas Jun 11 '17 at 18:56