I sometimes need code or data that is cross plugin, so i want to use functions or I want to get data that come from other plugins.
And because I want all code for a plugin in one place, I made the 'custom' function below:
You can make what I call modules and they must be in the modules folder of any plugin.
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function
cf_load_module(
$pluginname
=
''
,
$modulename
=
''
) {
global
$cfg
,
$sed_plugins
;
$ret
=false;
$pluginactive
=false;
if
(
$pluginname
!=
""
) {
if
(
is_array
(
$sed_plugins
))
{
foreach
(
$sed_plugins
as
$i
=>
$k
)
{
if
(
$k
[
'pl_code'
]==
$pluginname
)
{
$pluginactive
=true;
break
;
}
}
}
if
(!
$pluginactive
) {
return
false;
}
if
(
$modulename
!=
''
) {
$filename
=
$cfg
[
'plugins_dir'
].
'/'
.
$pluginname
.
'/modules/'
.
$pluginname
.
'.module.'
.
$modulename
.
'.php'
;
}
else
{
$filename
=
$cfg
[
'plugins_dir'
].
'/'
.
$pluginname
.
'/modules/'
.
$pluginname
.
'.module.php'
;
}
if
(
file_exists
(
$filename
)) {
require_once
(
$filename
);
$ret
=true;
}
}
return
$ret
;
}
How to use it:
PHP
1
2
3
4
if
(cf_load_module(
"myproject"
,
"users"
)) {
$ret
=mod_mpr_users_getProjectRights(
'STRING'
,
$userid
,
$projectid
);
}
In this example it loads the 'users' part from the myproject plugin (i am working on)
Hope somebody can use the idea :D