I had a small breakthough today. I was able to add features without touching the codebase AT ALL.
SNGINE unfortunately does not have a hook system like wordpress .. which allows developers to "hook in" to others work without overwriting.
However, it requires making code changes that will get overwritten when Zamblek comes out with the next version. Zamblek's answer to this is a using DIFF tool. Really? How about adding some well placed hooks for us, Z? Well, I use Github Desktop .. it makes things a bit easier .. but still merge conflicts are still gonna happen. With 1 or 2 mods this is no big deal ... but if you want to add 20, 30 or more mods .. version updates are going to be real bear every 3-4 months. Now imagine if you have a huge community to deal with on top of this.
So after many rounds with Perplexity AI .. i came up with 2 methods to minimize, and even eliminate ever having to modify the core sngine code when adding features.
Before we begin ... as you probably know .. clone your theme so you are not editing your "default" theme. Most of you already know this, but I had to add this for those who didn't know they should.
Magic Method #1: Add Features without Changing the Core
After scourging through days of AI credits on Windsurf, I was finally able to add a very cool feature of geotagging user sessions. What does this mean .. simply using IP addresses to find out where my users login from instead of relying on them to say "yes" to browser location. The amazing part was .. I was able to do this without changing a single line of Zamblek's code.
I did this by using "Auto-prepend" and using PHP extend and wrap as the article above pointed out. By using Auto-prepend, I could hook into the Bootstrap process itself and add a "prepend.php" to every php execution. While you can always hook into "bootstrap.php" yourself, you would be making a core change. So .. This is how I did it:
In .htaccess add this line:php_value auto_prepend_file "${DOCUMENT_ROOT}/custom/prepend.php"
Now, every time php executes, my prepend.php runs first. Then all I do, is extend and wrap existing classes. ask AI how to do this, and it will show you. Basically, it allows your code to run when let's say the "user class" is executed. Then I registered a shutdown function and had it add my geolocation data to the database.
Magic Method #2: Last Resort Hooks
Unfortunately, Method #1 only works with public functions and methods .. however, sngine has many private functions too. What do you do then? Well, then if you must, you most likely have hook in the old fashioned way. Of course, you could write down every hook and every line number so you remember next Sngine version what to reinstall .. but it's very likely the line numbers will be different in the next version.
Enter Hooks.json ... a simple json file to tell AI how re-apply all of your last resort hooks as such:
{
"hooks": [
{
"id": "custom_login_hook",
"file": "auth/login.php",
"anchor": "function processLogin",
"approximateLine": 150,
"textbefore": "if (validateCredentials($username, $password)) {",
"textafter": "// Perform login actions",
"hookLogic": "// Custom authentication code\n$customAuth = performCustomAuth($username, $password);\nif (!$customAuth) { return false; }",
"description": "Add custom authentication logic"
},
{
"id": "product_display_hook",
"file": "products/display.php",
"anchor": "public function render()",
"approximateLine": 75,
"textbefore": "$output = '<div class=\"product\">';",
"textafter": "return $output;",
"hookLogic": "// Modify product display\n$output = $this->addCustomProductInfo($output);",
"description": "Modify product display output"
}
]
}
Using this type of file, AI will know where to look next and what to add when sngine comes out with a new version. If you do it the old fashioned way, then you can use this file yourself to find the insert points.
Again, these methods are on top of using Git / Github Desktop to help you patch files with 20,000+ lines of code.
In the future, I would like to streamline these methods to be able to automatically patch every sngine release that comes out. I would love to hear comments on this and how we can automate this process.