Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8734843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:55:35+00:00 2026-06-13T09:55:35+00:00

I’m working on a plugin that does device detection based on an external library.

  • 0

I’m working on a plugin that does device detection based on an external library.

This is what I have so far:

class Deetector {

// public $return_data;

/**
 * Constructor
 */
public function __construct()
{
    $this->EE =& get_instance();
    $this->EE->load->add_package_path(PATH_THIRD.'/deetector');
    $this->EE->load->library('detector');
    $this->return_data = "";
}

public function deetector()
{
    return $ua->ua;
}

public function user_agent()
{
    return $ua->ua;
}

// ----------------------------------------------------------------

/**
 * Plugin Usage
 */
public static function usage()
{
    ob_start();

    $buffer = ob_get_contents();
    ob_end_clean();
    return $buffer;
}
}

If I call {exp:deetector} I get no output in the template. If I call {exp:deetector:user_agent} I get Undefined variable: ua.

Ultimately I don’t plan on setting up different functions for each of the variables that the Detector library returns but am just trying to get it to output something at the moment.

I had originally started doing this as an extension which added the Detector library’s variables to the global variables array and that was working fine; it’s only since trying to do it as a plugin that I’ve run into problems.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:55:36+00:00Added an answer on June 13, 2026 at 9:55 am

    You haven’t set $this->ua to anything. I assume it’s a variable of the detector library you loaded, so you probably want to do something like this:

    class Deetector {
        public function __construct()
        {
            $this->EE =& get_instance();
    
            // remove this line, it's probably not doing anything
            // $this->EE->load->add_package_path(PATH_THIRD.'/deetector');
    
            $this->EE->load->library('detector');
    
            // note you use $this->return_data instead of "return blah" in the constructor
            $this->return_data = $this->EE->detector->ua;
        }
    
        // remove this, you can't have both __construct() and deetector(), they mean the same thing
        // public function deetector()
        // {
        //     return $ua->ua;
        // }
    
        public function user_agent()
        {
            return $this->EE->detector->ua;
        }
    }
    

    UPDATE:

    I took a look at the Detector docs, and it doesn’t follow normal library conventions (it defines the $ua variable when you include the file). For that reason you should ignore the standard EE load functions, and include the file directly:

    class Deetector {
        public function __construct()
        {
            $this->EE =& get_instance();
    
            // manually include the detector library
            include(PATH_THIRD.'/deetector/libraries/detector.php');
    
            // save the local $ua variable so we can use it in other functions further down
            $this->ua = $ua;
    
            // output the user agent in our template
            $this->return_data = $this->ua->ua;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a small JavaScript validation script that validates inputs based on Regex. I
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.