Skip to content

Node.js based forum software built for the modern web

fixed #1143 -- also removed near-meaningless info messages saying that a Hook had been registered.

Julian Lam1c19ae48bd8e
diff --git a/src/plugins.js b/src/plugins.js
index 9462785054..f334d8b0da 100644
--- a/src/plugins.js
+++ b/src/plugins.js
@@ -246,24 +246,31 @@ var fs = require('fs'),
`data.priority`, the relative priority of the method when it is eventually called (default: 10)
*/
+ var method;
+
if (data.hook && data.method && typeof data.method === 'string' && data.method.length > 0) {
data.id = id;
if (!data.priority) data.priority = 10;
- data.method = data.method.split('.').reduce(function(memo, prop) {
- if (memo[prop]) {
+ method = data.method.split('.').reduce(function(memo, prop) {
+ if (memo !== null && memo[prop]) {
return memo[prop];
} else {
- // Couldn't find method by path, assuming property with periods in it (evil!)
- Plugins.libraries[data.id][data.method];
+ // Couldn't find method by path, aborting
+ return null;
}
}, Plugins.libraries[data.id]);
+ if (method === null) {
+ winston.warn('[plugins/' + id + '] Hook method mismatch: ' + data.hook + ' => ' + data.method);
+ return callback();
+ }
+
+ // Write the actual method reference to the hookObj
+ data.method = method;
+
Plugins.loadedHooks[data.hook] = Plugins.loadedHooks[data.hook] || [];
Plugins.loadedHooks[data.hook].push(data);
- if (global.env === 'development') {
- winston.info('[plugins] Hook registered: ' + data.hook + ' will call ' + id);
- }
callback();
} else return;
};