Ondersteuning » Code oplossingen gezocht » Vreemde waarde class variabele

  • Geen idee waarom, maar deze code werkt niet, althans niet op deze manier. Ik geef hier alleen het relevante deel van de code.

    class Bootstrap_Login_Plugin {
    	public $redirectLogin;
    
    public function __construct() {
    	$this->redirectLogin = 'someValue';
    	// Niet noodzakelijk, maar dan is er een waarde
    	add_filter( 'login_redirect', array( $this, 'redirect_after_login' ), 10, 3 );
    	add_shortcode( 'custom-login-form', array( $this, 'render_login_form' ) );
       }	// function __construct()
     public function render_login_form( $attributes, $content = null ) {
    	 $attributes['redirect'] = '';
    	 if ( isset( $_REQUEST['redirect_to'] ) ) {
    	 	$attributes['redirect'] = wp_validate_redirect( $_REQUEST['redirect_to'], 
    				$attributes['redirect'] );
    	 	$this->redirectLogin = $attributes['redirect'];
    //Output: '[04-Jun-2018 10:32:57 UTC] http://localhost:3000/wp/jhk_story/verhaal-honderd/'
    error_log( print_r( $this->redirectLogin, true ) );
    	 }
    }	// render_login_form()
    public function redirect_after_login( $redirect_to, $requested_redirect_to, $user ) {
    error_log( print_r(function render_login_form(, true ) );
    // Output: '[04-Jun-2018 10:33:09 UTC] someValue'
    }	// redirect_after_login()
    
    }	// class Bootstrap_Login_Plugin
    $bootstrap_login_pages_plugin = new Bootstrap_Login_Plugin();
    
    // Registers the plugin when activated. 
    register_activation_hook( __FILE__, array( 'Bootstrap_Login_Plugin', 'plugin_activated' ) );

    Vraag 1:
    In function render_login_form(…) krijgt $this->redirectLogin een nieuwe waarde. Waarom is dat in function redirect_after_login(…) dan niet meer zo?
    $this->redirectLogin is een publieke class variabele dus dit zou moeten werken… Dacht ik.

    Vraag 2:
    Waar krijgen de parameters van de public function redirect_after_login( $redirect_to, $requested_redirect_to, $user ) een waarde? Niet in of via de ‘hook’, maar waar dan wel?
    Wanneer ik $requested_redirect_to ergens een waarde kan geven ben ik ook uit de brand.
    Suggesties zijn zeer welkom!

1 reactie aan het bekijken (van in totaal 1)
  • Thread starter pagemaecker

    (@pagemaecker)

    Na heel veel zoeken antwoorden op m’n vragen:
    @v-1:
    Ik heb geen idee waarom het niet werkt. Maar wel een oplossing:

    	 public function render_login_form( $attributes, $content = null ) {
    	 	$attributes['redirect'] = '';
    	 	if ( isset( $_REQUEST['redirect_to'] ) ) {
    	 		$attributes['redirect'] = wp_validate_redirect( $_REQUEST['redirect_to'], 
    	 														$attributes['redirect'] );
    	 		// Set a transient that expires in one hour
    	 		set_transient( 'redirectLogin', $attributes['redirect'], HOUR_IN_SECONDS );
    		}	// if
    

    En in de functie waar ik iets met die waarde doe:

    	public function redirect_after_login( $redirect_to, $requested_redirect_to, $user ) {
    
    		/**
    		 * Get the transient value set in render_login_form()
    		 */
    		if ( false === ( $redirectLogin = get_transient( 'redirectLogin' ) ) ) {
         		// this code runs when there is no valid transient set
         		$redirectLogin = home_url( 'member-account' );
    		}
    
    error_log( print_r( $redirectLogin, true ));
    

    En dit werkt!

    @V-2:
    Dat gebeurt in wp_login.php regel 949.

1 reactie aan het bekijken (van in totaal 1)
  • Het onderwerp ‘Vreemde waarde class variabele’ is gesloten voor nieuwe reacties.