Skip to:

Could a plugin developer protect his functions?

  • Shmoo


    I kinda know how filters work right now and I’ve used them a few times to hide or change default bbPress functions.

    As you can see at my screenshot I’ve completely removed the Merge, Split, Move and Reply links from my admin_links() function because I don’t need them. It’s a fun thing to do if you start to understand how it works.

    The only problem is,
    bbp_topic_admin_links(); is just a wrapper for all the links, each link has it’s own function and if you play nice with them you can copy them and use them straight into your page templates and you’ll see your link-/button show up wherever you want them to show up.
    This is great, I’ve done something like this shmoo_bbp_topic_edit_link(); changed and reused the default topic link function and placed it at the top of the content as you can see in my screenshot.

    Great, only thing is, if I try to do the same with a function from a plugin developer it says; Fatal error: Call to undefined function get_topic_report_link()

    Why is this function undefined ??
    The developer has made that function in his plugin file – which hooks straight into my functions.php , why can’t I use his functions the way I do use the Core bbPress functions inside my functions.php file..

    I would like to remove the report link from the admin_links and bring it solo to the top of the content.

Viewing 2 replies - 1 through 2 (of 2 total)

  • John James Jacoby


    A few things to check:

    • Is the plugin active?
    • Are you calling the function correctly (named correctly, etc…)?
    • Cherry picking functions and putting them in your functions.php file can be tedious, since you’re stuck supporting all your own new code rather than letting the plugin do the work. Are you sure you’re comfortable with this?
    • If the function says it’s undefined, it means whatever file you’re putting that code in, isn’t loading. Why not?

    You’ll likely have better results if you filter the results of bbp_after_get_topic_admin_links_parse_args like so:

     * Replace the individual link calls with your own functions
    function foo( $args = array() ) {
        $args['links'] = array(
            'edit'  => bbp_get_topic_edit_link ( $args ),
            'close' => bbp_get_topic_close_link( $args ),
            'stick' => bbp_get_topic_stick_link( $args ),
            'merge' => bbp_get_topic_merge_link( $args ),
            'trash' => bbp_get_topic_trash_link( $args ),
            'spam'  => bbp_get_topic_spam_link ( $args ),
            'reply' => bbp_get_topic_reply_link( $args )
        return $args;
    add_filter( 'bbp_after_get_topic_admin_links_parse_args', 'foo' );

    Keep in mind that each link function accepts its own parameters (including the ability to change the text to anything you want) so you can either pass new parameters, or filter each link and adjust them. This way you can just filter bbPress’s core functionality rather than rewrite everything on your own



    – Yes the plugin is 100% sure active and working because you can see ( red border ) the topic is reported , I’ve even deactivated & activated it again to make sure when I saw that error.

    – It’s a clean copy-/paste from the plugin’s functions file. I’ve even added echo in front of it to check if there was a difference but both with & without echo have the same error.

    Why I ask if a plugin function can be private or protected is, when I take a look inside the plugin function-file I see all functions wrapped inside a class which is pretty standard for making plugins I’ve seen online.

    But I also see something like this:

    	protected $version = '1.0.0';
    	protected $plugin_slug = 'bbpress-report-content';
    	protected static $instance = null;
    	protected $plugin_screen_hook_suffix = null;
    	protected $plugin_path = null;
    	private function __construct() { ....
    	public static function get_instance() {
    		// If the single instance hasn't been set, set it now.
    		if ( null == self::$instance ) {
    			self::$instance = new self;
    		return self::$instance;

    Most functions have public function function_name() and the function I would like to use has only function function_name()

    That made me think maybe my function it’s protected, so I started testing and searching online and did this inside my page template.

    <?php if(function_exists('get_topic_report_link')) {
    echo get_topic_report_link( $args = '' );
    } else {
    echo 'Function does not exists..';

    It takes the ELSE option so there is something wrong right.


    This is what I did to kill for example the Merge link from the admin_links, preventing it would show up something else when called upon.

    function shmoo_kill_topic_merge_link( $r ) {
    	$r = null;
    	return $r;
    add_filter( 'bbp_get_topic_merge_link', 'shmoo_kill_topic_merge_link' );

    I’m a Check Norris fan, when I change stuff it has to be NULL 😉

    I know, I probably add and write too much functions-/codes of my own to alter the bbPress core but at least I’m getting it done right now and starting to understand how it works a little. In a few years I will be better ( hopefully ) and add more logic to my projects.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar