WordPress.org

Ready to get started?Download WordPress

Forums

Help With Plugin Scope Issue (2 posts)

  1. cavemonkey50
    Member
    Posted 7 years ago #

    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?

  2. cavemonkey50
    Member
    Posted 7 years ago #

    Does anyone have any ideas on what's the problem? I can provide more information if needed.

Topic Closed

This topic has been closed to new replies.

About this Topic