Skip to content

Commit ef3d259

Browse files
committed
Initial commit
1 parent 7f01723 commit ef3d259

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
extension-loader
1+
Redux extension-loader
22
================
33

4-
The loader code needed to instantiate any Redux extension.
4+
The loader code needed to instantiate any Redux extension. To load any Redux extension, you need but do two things:
5+
6+
* Inside loader.php change `{$redux_opt_name}` to match your opt_name or set `$redux_opt_name` to your `opt_name` and make sure it's accessible by loader.php.
7+
* Change the function name and hook reference of `redux_register_custom_extension_loader` as not to conflict with another developer's code.
8+
9+
Then place any extension folder within ~/extensions.
10+
11+
Depending on the extension you may also need to load a config file of some type to declare the options for that extension.

loader.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
// Replace {$redux_opt_name} with your opt_name.
4+
// Also be sure to change this function name!
5+
6+
if(!function_exists('redux_register_custom_extension_loader')) :
7+
function redux_register_custom_extension_loader($ReduxFramework) {
8+
$path = dirname( __FILE__ ) . '/extensions/';
9+
$folders = scandir( $path, 1 );
10+
foreach($folders as $folder) {
11+
if ($folder === '.' or $folder === '..' or !is_dir($path . $folder) ) {
12+
continue;
13+
}
14+
$extension_class = 'ReduxFramework_Extension_' . $folder;
15+
if( !class_exists( $extension_class ) ) {
16+
// In case you wanted override your override, hah.
17+
$class_file = $path . $folder . '/extension_' . $folder . '.php';
18+
$class_file = apply_filters( 'redux/extension/'.$ReduxFramework->args['opt_name'].'/'.$folder, $class_file );
19+
if( $class_file ) {
20+
require_once( $class_file );
21+
$extension = new $extension_class( $ReduxFramework );
22+
}
23+
}
24+
}
25+
}
26+
// Modify {$redux_opt_name} to match your opt_name
27+
add_action("redux/extensions/{$redux_opt_name}/before", 'redux_register_custom_extension_loader', 0);
28+
endif;

0 commit comments

Comments
 (0)