Forum Replies Created

Viewing 2 posts - 16 through 17 (of 17 total)
  • Author
    Posts
  • in reply to: Include a file within Piklist #1853
    egnsh98
    Member

    Still having some trouble, OOP is still new to me. I am trying to call a Class method from outside my main plugin class. My get_user() call works fine inside of my “Main” class, but when trying to call it from outside, NULL is returned. Here is what I have done so far, I have included only the code I thought was relevant to the problem and have put comments where necessary.

    <?php
    
    class Main {
    	
    	protected $user = null;
    	
    	public function __construct() {
    		
    		// Init and admin init action hooks
    		
    	}
    	
    	public function init() {
    		
    		// Check for piklist plugin
    		// Enqeue admin styles and scripts
    		// Action hook on authenticate function
    
    	}
    	
    	public function authenticate() {
    		
    		$this->set_user( "John Smith" );
    
    	}
    	
    	public function set_user( $new_user ) {
    		$this->user = $new_user;
    	}
    	
    	public function get_user() {
    		return $this->user;
    	}
    	
    }
    
    /* ------------------------------------------------
     * Code from /parts/settings/twitter.php
     * ------------------------------------------------*/
     
    	$instance = Main::get_instance();
    	$user = $instance->get_user();
    	
    	var_dump ( $user );
    
    	// Hidden field gets the username and registers it as a setting in the database
    	piklist('field', array(
    		'type' => 'hidden'
    		,'field' => 'user_name'
    		,'value' => $user
    	));
    
    ?>
    in reply to: Include a file within Piklist #1851
    egnsh98
    Member

    Thank you that seemed to do the trick! How would I go about passing data from my main class, to a PHP file within /parts/. It is not in the same class so I can’t use “$this” and I don’t to use super globals.

Viewing 2 posts - 16 through 17 (of 17 total)