Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6213825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:45:59+00:00 2026-05-24T06:45:59+00:00

So, i am developing a Plugin, and I am using a main Class so

  • 0

So, i am developing a Plugin, and I am using a main Class so it can be more easily managed:

class MyPlugin{
   function __construct(){
      //my add_actions here
      add_action('template_redirect', array($this, 'template_redirect'));
   }

   //my_class_methods here
   function template_redirect(){}
}

Up until now, this is all working just fine. But as the plot thickens, I need to add more and more complexity in the plugin so I would like to do something like:

  • create a new Class Comment
  • in MyPlugin’s __construct instantiate $comment = new Comment()
  • delegate, in my template_redirect(), an action to a method in $comment like:

    add_action(‘wp_insert_comment’, array($this->comment,’wp_insert_comment’));

or:

  • create a new Class Comment
  • in MyPlugin’s __construct instantiate $comment = new Comment()
  • in my Class Comment’s __construct add the action to it’s method comment_method:
add_action('wp_insert_comment', array($this, 'comment_method'));

Is this even possible? in either way, my behaviour isn’t being called.
Thanks for your help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:46:00+00:00Added an answer on May 24, 2026 at 6:46 am

    Yes, it’s possible, but you should probably add most actions and filters with the plugins_loaded hook rather than using the template_redirect hook, which probably is not called at all when a comment is posted (the form goes to wp-comments-post.php, wordpress deals with request, then redirects the user back to the page where the comment form was before the template is needed.)

    class MyPlugin{
        function __construct(){
            add_action("plugins_loaded", array($this,"_action_plugins_loaded"));
        }
        function _action_plugins_loaded(){
             //add actions & filters here...
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am developing a eclipse plugin . In this plugin i am using reflection
I'm using the RESTful authentication Rails plugin for an app I'm developing. I'm having
We're developing a Qt project using the Code::Blocks IDE with the QtWorkbench plugin. We'd
I am developing a firefox plugin. When i am using debug mode dll ,it
I'm developing a Grails (Version 1.3.3) Web-Application using the Grails Spring-Security Plugin, Spring-Security-Core-1.0.1 (which,
I'm developing a plugin UI for an existing application using PyQt4. The window is
I am using ruby 1.8.7 and rails 2.3.4 . I am developing a plugin
I'm currently developing an application in which I'm using a plugin system. For providing
I'm looking to experiment with developing an Outlook plugin. I'm using the express edition
I'm developing some plugins to my application using the JEDI Plugin tecnology, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.