• I’m having some issue with the scope of a variable in a plugin I’m trying to create. The plugin is to add support for RSS tracking in Mint. To do this, a Mint include must be added to the RSS file and the links have to be replaced with the tracking code.

    The include needed at the top of the RSS file is:

    <?php
    define('BIRDFEED', 'Feed Name'); include($_SERVER['DOCUMENT_ROOT'].'/feeder/index.php');
    ?>

    The links are supposed to be this:

    <?php $BirdFeeder->seed(get_the_title_rss(), get_permalink()); ?>

    Here’s my plugin at the moment:

    if ( is_feed() ) {
    define('BIRDFEED', 'Articles (RSS)');
    include($_SERVER['DOCUMENT_ROOT'].'/feeder/index.php');
    }
    function rh_bird_feeder_include ($url) {
    if ( is_feed() )
    $url = $BirdFeeder->seed(get_the_title_rss(), $url);
    return $url;
    }
    add_filter ('post_link', 'rh_bird_feeder_include', 1);

    That results in an “Call to a member function on a non-object in …” telling me that the $BirdFeeder variable is not declared. To remedy this, I have tried adding global $BirdFeeder to the function without avail.

    Thinking it might be an issue with the way Mint is including the code, I did a simple test with a basic variable.

    $test = "Global works";
    function rh_bird_feeder_include ($url) {
    global $test;
    if ( is_feed() )
    $url = $test;
    }
    add_filter ('post_link', 'rh_bird_feeder_include', 1);

    Unfortunately that doesn’t work either. How can resolve this scope issue and get the information from $BirdFeeder into the function?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Help With Plugin Scope Issue’ is closed to new replies.