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

  • SEARCH
  • Home
  • 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 6878905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:46:51+00:00 2026-05-27T04:46:51+00:00

How do you impliment a hook system in a PHP application to change the

  • 0

How do you impliment a hook system in a PHP application to change the code before or after it executes. How would the basic architecture of a hookloader class be for a PHP CMS (or even a simple application). How then could this be extended into a full plugins/modules loader?

(Also, are there any books or tutorials on a CMS hook system?)

  • 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-27T04:46:52+00:00Added an answer on May 27, 2026 at 4:46 am

    You can build an events system as simple or complex as you want it.

    /**
     * Attach (or remove) multiple callbacks to an event and trigger those callbacks when that event is called.
     *
     * @param string $event name
     * @param mixed $value the optional value to pass to each callback
     * @param mixed $callback the method or function to call - FALSE to remove all callbacks for event
     */
    function event($event, $value = NULL, $callback = NULL)
    {
        static $events;
    
        // Adding or removing a callback?
        if($callback !== NULL)
        {
            if($callback)
            {
                $events[$event][] = $callback;
            }
            else
            {
                unset($events[$event]);
            }
        }
        elseif(isset($events[$event])) // Fire a callback
        {
            foreach($events[$event] as $function)
            {
                $value = call_user_func($function, $value);
            }
            return $value;
        }
    }
    

    Add an event

    event('filter_text', NULL, function($text) { return htmlspecialchars($text); });
    // add more as needed
    event('filter_text', NULL, function($text) { return nl2br($text); });
    // OR like this
    //event('filter_text', NULL, 'nl2br');
    

    Then call it like this

    $text = event('filter_text', $_POST['text']);
    

    Or remove all callbacks for that event like this

    event('filter_text', null, false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To implement data access code in our application we need some framework to wrap
I am trying to develop a util (using system-hook) for that works like an
I have a WinForms application with some business objects which implement INotifyPropertyChanged and hook
In a Drupal 7 (and Drupal 6?) system, what kicks off the hook calling
If two modules implement the same hook in Drupal, does the system have a
I'd like to implent the System.ComponentModel.INotifyPropertyChanged interface for a property on a base class,
I am trying to 1) implement the hook menu and variable_set in the block
I've been given a requirement to impliment some google tracking on an RSS feed.
I'm about to implement a feature in our application that allows the user to
I'm looking at porting a custom-written PHP CMS into Django. One of the features

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.