Call to undefined method -- which isn't even on that line

LPH

Well-known member
I have a class, which sits outside of XenForo, and is called to change an author url link in WordPress. Today I decided to work on building the link using XenForo methods rather than manually building. However, I'm getting something REALLY strange.

Here is the class:

PHP:
class Author_Link {

    public function __construct() {
        add_filter( 'author_link', array( $this, 'xenword_author_link' ), 100 );
    }

    public function xenword_author_link() {

        global $post;

        $thread_id = get_post_meta( $post->ID, 'thread_id', true );

        $threadModel = XenForo_Model::create('XenForo_Model_Post');
        $thread = $threadModel->getThreadById($thread_id);

        $xf_author_link = XenWord::getBoardUrl() . '/' . XenForo_Link::buildPublicLink('members', $thread);
        return $xf_author_link;
    }
}

new Author_Link();

Line 44 is the getThreadById.

The error being returned is ...

Code:
An exception occurred: Call to undefined method Dark_PostRating_Model_Post::getThreadById()

As you can see, Dark_PostRating_Model isn't being called. I'm stumped. Any ideas?
 
Oh my. This is embarrassing. The Model is not Post but should be Thread.

This works.

PHP:
    public function xenword_author_link() {

        global $post;

        $thread_id = get_post_meta( $post->ID, 'thread_id', true );
        $thread = XenForo_Model::create('XenForo_Model_Thread')->getThreadById( $thread_id );

        $xf_author_link = XenWord::getBoardUrl() . '/' . XenForo_Link::buildPublicLink('canonical:members', $thread);

        return $xf_author_link;
    }

Why it didn't tell me in the error that the function didn't exist in XenForo_Model_Post is really wild.
 
Why it didn't tell me in the error that the function didn't exist in XenForo_Model_Post is really wild.
It's because you're using another add-on that extends the XenForo_Model_Post class (Post Ratings). That's how the class proxy system works, it chains them together so that they all extend one another until a cumulative class is formed.
 
Last edited:
By statically instantiating the base classes from XenForo, you'll never load any of those addons that extend them. It would be best if you could implement a function similar to the existing one from XenForo that fetches the respective class from Cache, then you make sure to get all addon extensions, otherwise you might cause some incompatibilities.
 
it chains them together so that they all extend one another until a cumulative class is formed.

Does it start looking in XenForo_Model_Post then looks at the extensions or vice versa? Just curious now that you've explained this !

It would be best if you could implement a function similar to the existing one from XenForo that fetches the respective class from Cache,

I'm not sure what you mean. I struggle with OOP because WordPress and OOP aren't best friends and flipping between procedural and OOP gets me in trouble at times.

I have a main class named XenWord. In it is a method that initializes XenForo, etc. Are you suggesting this class extends XFCP_XenForo_ ?
 
By statically instantiating the base classes from XenForo, you'll never load any of those addons that extend them. It would be best if you could implement a function similar to the existing one from XenForo that fetches the respective class from Cache, then you make sure to get all addon extensions, otherwise you might cause some incompatibilities.
@LPH is already using the static create() method to instantiate models. This will include all add-on extensions already. You would be right if he were using this though:
PHP:
$model = new \XenForo_Model_Post;


Does it start looking in XenForo_Model_Post then looks at the extensions or vice versa? Just curious now that you've explained this !
Since XenForo core models would be the root class, they are the last class "checked." Depending on execution order and the number of add-ons extending a particular class, you get things like:
  • Jrahmy_Cool_Model_Post extends Dark_PostRating_Model_Post
  • Dark_PostRating_Model_Post extends XenForo_Model_Post
 
Last edited:
Back
Top Bottom