So you have this really cool Theme or Plugin. And of course you love Redux because – let’s face it – who doesn’t? You understand how the Redux plug-in works, but the concept of a theme or plugin installing another plugin escapes you, or perhaps you don’t really care for TGM or any of its variations. What are you to do?

You’ve come to the right place. Embedding Redux into your theme or plugin is as easy as 1, 2, 3. You might be wondering, what if your client also installs the Redux plugin? Will it conflict? The answer is no. Even better, the Redux plug-in will always supersede your theme’s require of Redux. This means your clients could – hypothetically – receive updates to Redux without any theme update from you. Pretty cool, eh?

Let’s begin, shall we?

Step 1: Get the Source

There are a variety of methods in which to acquire the Redux Framework source code. Please refer to the [Getting Started] guide. Here we’ll go over a few more advanced git methods. It’s important to choose a name for the folder in which Redux will be contained, as it could be difficult to change the name later. Redux may be placed into any directory or in any path (such as ~/admin or ~/framework).

Cloning the Repository Using Git

Installation through Git allows ensures you’ll always have the latest version of Redux. Our master branch is designed to be the most stable, up-to-date code. Grabbing it will result in the best possible experience for your clients. If you’re not familiar with Git, using this method can be a bit daunting. If this is the case, it’s recommended beginners read Git Immersion. For a more thorough understanding of Git, another excellent resource is Pro Git. Assuming you now have a working understanding of Git, here is how to clone the master branch of Redux. Using the Linux command line, type the following:

cd my-project
git clone https://github.com/ReduxFramework/ReduxFramework.git ReduxFramework

This will clone the Redux master repository into a folder called ReduxFramework. Feel free to move this anywhere, but please make note of where it’s stored. Once this is done, move on to step 2.

Cloning the Repository as a Git Submodule

Git submodules are a powerful tool, which allows you to easily include a third-party project of your own while still treating them as two separate projects. Rather than provide an in-depth explanation of the benefits and use of submodules, it’s recommended you take a moment and read through the submodules page in the official Git documentation. When you’re ready to dive in, the following command generates a clone of Redux as a submodule:

cd my-project
git submodule add https://github.com/ReduxFramework/ReduxFramework.git ReduxFramework

This clones the repo into a directory titled ReduxFramework. Unless you have any desire to embark upon the arduous task of renaming a submodule, it’s strongly suggested choosing a folder name before running this command. Change the last string (in this case, ReduxFramework) to the relative path you desire. Once this is accomplished, move on to step 2.

Step 2: Include the framework and/or sample config file

Simple, elegant, and easy:

PLEASE NOTE: This example assumes you have installed Redux into a folder titled ReduxFramework. If you have installed Redux into a folder with a different name (these are case sensitive), you must update the following code so the folder name matches with your folder name. Cutting and pasting this code if your folder name differs will fail.

Before we get started, it worth recommending that you never modify the sample-config.php file itself!! Editing this file directly will result in a loss of your configuration data when updating the Redux code base. Rather, the sample-config.php file should be copied to another location, where modifications may then be made. You have been warned!

if ( !class_exists( 'ReduxFramework' ) && file_exists( dirname( __FILE__ ) . '/ReduxFramework/ReduxCore/framework.php' ) ) {
    require_once( dirname( __FILE__ ) . '/ReduxFramework/ReduxCore/framework.php' );
}
if ( !isset( $redux_demo ) && file_exists( dirname( __FILE__ ) . '/ReduxFramework/sample/sample-config.php' ) ) {
    require_once( dirname( __FILE__ ) . '/ReduxFramework/sample/sample-config.php' );
}

Be sure to update the relative path in relation to the file in which the code is executed. It’s suggested to place this code at the top of your functions.php file.

Here is where the true magic of Redux comes into play. Suppose a user has Redux installed by itself via a plugin. Your theme is now using the plugin class and not the embedded version you included with your theme or plug-in! Put another way, your project will just work out of the box, no questions asked! Redux, when installed as a plug-in takes priority. Any references that include Redux in your own framework.php will be ignored. Redux – installed as a plug-in – can be forever updated by the user and your theme receives the benefit without you ever needing to push any code update! What other options framework can claim the same?

The answer: None!

Tagged:

Comments are closed.