We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Help Building First Plugin

Development and Programming

H Media Webmaster's avatar
H Media Webmaster
119 posts
15 years ago
H Media Webmaster's avatar H Media Webmaster

Forgive me if this is a noob question.

I built a simple plugin to scratch an itch, but can’t get it working.

The plugin shows up as installed in Cp > Addons > Plugins

But when I try to use the tags

{exp:myplugin}{/exp:myplugin}

I get an error that says ‘the module is not installed’

any idea why I’m getting this? here’s the precise error

Error

The following tag cannot be processed:

{exp:get_iframe_src}

Please check that the ‘get_iframe_src’ module is installed and that ‘get_iframe_src’ is an available method of the module
       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
15 years ago
Pascal Kriete's avatar Pascal Kriete

Seems to have trouble finding the file, class, or method.

You use two examples above - once myplugin and once get_iframe_src.

I won’t make any assumptions, so let’s start with the basics:

What is the plugin called and where did you place it? What is the file name, and what is the class name?

       
H Media Webmaster's avatar
H Media Webmaster
119 posts
15 years ago
H Media Webmaster's avatar H Media Webmaster

ya, I should be more precise sorry

the plugin is caled Getiframesrc

it’s a quick and dirty way for me to pull the src attribute out of some video embed code

at first I was trying to return the value from the constructor function, but that didn’t seem to work

I added another method and called that and it does seem to return a value

don’t laugh when you see it though

<?php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$plugin_info = array(
    'pi_name' => 'Get Iframe SRC',
    'pi_version' => '1.0',
    'pi_author' => 'Mike Moreau',
    'pi_author_url' => 'http://harvestmedia.com',
    'pi_description' => 'Looks for the src attribute of an iframe and returns it.'
);

class Getiframesrc
{
    
    function __construct()
    {
        $this->EE =& get_instance();
    }
    
    function do_it()
    {
        
        $input = $this->EE->TMPL->tagdata;
        $sx = simplexml_load_string('<xml>'.$input.'</xml>');
        
        if($sx)
        {
            if($sx->iframe['src'])
            {
                return $sx->iframe['src'];
            }
            else
            {
                return 'could not find src attribute';
            }
        }
        else
        {
            return 'could not parse url from embed code';
        }    
    }
}
/* End of file pi.get_iframe_src.php */ 
/* Location: ./system/expressionengine/third_party/getiframesrc/pi.getiframesrc.php */
       
the3mus1can's avatar
the3mus1can
426 posts
15 years ago
the3mus1can's avatar the3mus1can

To return something from the constructor you must assign the value to $this->return_data; This is because a constructor returns an instance of the class and thereby cannot return another value to be inserted into the template.

The class name of your plugin is Getiframesrc so you need to call the plugin in the template with the same name - no unerscores. Ex:

{exp:getiframesrc}...{/exp:getiframesrc}
       
H Media Webmaster's avatar
H Media Webmaster
119 posts
15 years ago
H Media Webmaster's avatar H Media Webmaster

thanks for the help, got it working!

I also ended up using the xml parser library that’s built into EE rather than the php’s simplexml_load_string() function

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.