Ayuda con gestión de sesiones y redirecciones WordPress

Iniciado por gontzal240, Junio 28, 2017, 07:37:08 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Junio 28, 2017, 07:37:08 PM Ultima modificación: Junio 29, 2017, 01:03:10 PM por HATI
Hola, soy novato en esto y llevo bastantes horas dándole vueltas, el caso es que llevo bastante rato y no consigo dar con la solución, lo que quiero hacer es, cuando un usuario no esté logueado en mi web WordPress y navegue por la web, le redireccione siempre al index (www.dominio.com) tal cual, antes de ver cualquier contenido, sólo podrá ver el index (ahí hay un login), y si se logea, pueda navegar y ver el resto de la web.

He estado jugando con la función is_user_logged_in() pero lo único que he conseguido es que se redireccione, pero se crea un bucle en el index ya que redirecciona también el propio index a él mismo.

Esto es lo que he podido hacer, el caso es que sigue el bucle:

Código: php
if(!is_user_logged_in() && get_site_url() != 'http://dominio.com/index.php') {
    wp_redirect( 'http://dominio.com', 302 );
    exit;
}

el get_site_url(), te trae el path completo?? o solo la Url base? (es decir con index.php)

You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
el get_site_url(), te trae el path completo?? o solo la Url base? (es decir con index.php)

Por lo que veo solo trae URL BASE

You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login


Código: php
<?php echo get_site_url(); ?>
Results in the full site URL being displayed:

http://www.example.com


Supongo que es por esto que no esta funcionando
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login


Junio 28, 2017, 09:10:41 PM #3 Ultima modificación: Junio 28, 2017, 09:17:16 PM por gontzal240
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
el get_site_url(), te trae el path completo?? o solo la Url base? (es decir con index.php)

Por lo que veo solo trae URL BASE

You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login


Código: php
<?php echo get_site_url(); ?>
Results in the full site URL being displayed:

http://www.example.com


Supongo que es por esto que no esta funcionando

Entiendo, y cómo podría hacerlo?, he intentado con una variable y añadiendo el index.php al get_home_url, pero estamos en las mismas.

no tengo wordpress a mano, pero podrías probar con get_permalink(); ??

o bien podrias traerlo con php, $_server['SERVER_NAME'].$_server['REQUEST_URI'];

You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
no tengo wordpress a mano, pero podrías probar con get_permalink(); ??

o bien podrias traerlo con php, $_server['SERVER_NAME'].$_server['REQUEST_URI'];

Como podría integrar $_server['SERVER_NAME'].$_server['REQUEST_URI'] ¿?, gracias por la ayuda, apenas se nada.

You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
no tengo wordpress a mano, pero podrías probar con get_permalink(); ??

o bien podrias traerlo con php, $_server['SERVER_NAME'].$_server['REQUEST_URI'];

Lo que comenta, puedes encontrar una mejor descripción acá You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

Puedes utilizar una variable como esta $url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]

para que te devuelva la PATH, son ejecutadas en PHP, por lo tanto puedes incluirla antes del IF
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login


You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
no tengo wordpress a mano, pero podrías probar con get_permalink(); ??

o bien podrias traerlo con php, $_server['SERVER_NAME'].$_server['REQUEST_URI'];

Como podría integrar $_server['SERVER_NAME'].$_server['REQUEST_URI'] ¿?, gracias por la ayuda, apenas se nada.

Bueno como lo menciona rush, debería quedarte así:
Código: text
$url = 'http://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];


Por cierto, no te funcionó el get_permalink(); ??

A ver si esto te ayuda:


You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login

You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login



Jugar o perder