Okay, we all know how hard on a user's temper it is to install a MOD, then find out it isn't working immediately after, or after an upgrade or other MOD installation. Troubleshooting becomes tedious for the user, any support personnel, and the MOD authors when this happens.
Everyone's time is lost, most especially the user's, if they happened to install the MOD on a live board. Unless the problem is fixed quickly, the user's site loses the desired appearance and reliability that it needs to survive. MOD installations take time, MOD uninstallations more so due to the backwards nature of it.
So how to overcome the problem? It's easy, just use a PHP if() conditional and a constant defined check like so:
- Code: Select all
if(!defined("SOME_CONSTANT"))
{
//Some code here...
}
Coupled with a simple constant declaration in includes/constants.php to override the MOD's edits, and you can simply turn off your MOD's edits if the worst occurs.
From now on, I shall refer to this method as EMED (for Emergency MOD Edit Deactivation).
Code Cleanliness
Yes, cleanliness is an issue here, but for the most part, it's about variable names. It would be best if the constant names and template variable names used had a EMED_ prefix so that other modders and users are not tripping over your variables. Not too hard to understand, right?
Before- and After-Add Edits
For Before- and After-Add edits, all it takes is simply wrapping the chunk of code with a proper if() conditional to check for the constant.
For example:
- Code: Select all
/*
* Some PHP code...
*/
if($user->data['user_id'] == $config['nub'])
{
$user->session_kill($user->data['session_id']);
}
Okay, so for this, the edit is to trigger_error after the session_kill call. Not too hard, is it? Let's assume that the constant that we'll look for will be called EMED_YOU_FAIL_NOTICE.
The resulting code after the edit will look like this:
- Code: Select all
/*
* Some PHP code...
*/
if($user->data['user_id'] == $config['nub'])
{
$user->session_kill($user->data['session_id']);
if(!defined("EMED_YOU_FAIL_NOTICE"))
{
trigger_error($user->lang['YOU_FAIL']);
}
}
Now that wasn't too hard, was it?
Replace-With Edits
Okay, this is a little tougher, but still quite easy. Essentially, at the beginning of the code you replace, you add these lines instead of replacing the code:
- Code: Select all
if(defined("EMED_{MOD_NAME}"))
{
//Original code
And at the end of the snippet, you then add these lines:
- Code: Select all
}
else
{
//New code
To this, you follow with the code that you were going to be using as the replacement code, followed by this simple line:
- Code: Select all
}
Whoo, much better, isn't it?
Inline After-Add, Before-Add, and Replace-With
Now this one is truly harder stuff.
In order to get these edits to work, you'll need to use your own ingenuity. However, I do have one method, which is to simply copy the line and act as if it is a normal Replace-With edit, where the original line is on the top, and the newly edited line on the bottom. It might be awkward to get working within the MODX guidelines, however.
Cookie to whoever finds a more efficient way!

Template Edits
Template edits can't use PHP, so as such, we'll have to use template code, with a template variable assignment statement stuck in the page_header() function in includes/functions.php, like this following snippet:
- Code: Select all
'EMED_{MOD_NAME}' => (!defined("EMED_{MOD_NAME}")) ? false : true,
Then, you just wrap your template edits in this, with your template code going where {TEMPLATE_CODE} is.
- Code: Select all
<!-- IF EMED_{MOD_NAME} -->{TEMPLATE_CODE}<!-- ENDIF -->
This be cake. :3
The Override
Whaa? You don't know how to trigger the override?
Simple.
Open up includes/constants.php and add this line to the end, replacing {MOD_NAME} with the proper text.
- Code: Select all
@define("EMED_{MOD_NAME}", true);
The Cons of using EMED
Yes, there are ways that this coding method can fail. Mainly, it is from MOD conflicts, with the original code from Replace-With edits still existing and being edited without having an effect, where the code simply would not be able to be found if a normal Replace-With edit were used.
It's a chance that must be taken if the method is used, but a vigilant user/MOD installer, if they know of this method's problem, can easily avoid it and warn others of it.
All in all, EMED is a great tool for debugging with multiple MODs interacting on one board. Give it a try sometime, and see if you like it.