Make Better WordPress Minify Work On OpenShift


Read {count} times since 2020

If you run a WordPress blog on OpenShift, you might not be able to run the Minify plugins. These plugins won’t work if your OpenShift app is directly installed from the WordPress catridge they provide. This happens because the plugins, themes and other directories of wp-content are linked directories which means they’re fake. The folders are just shortcuts of the original folder situated in app-root/data. This makes the minify plugin hard to find the source of the file. Hence it won’t work.

This happened to my blog and I looked in to the source files of plugin and found a solution. You can solve this problem with only **5 lines **of code !

Editing bwp-minify/min/index.php

The changes we are going to make to fix the problem are on the bwp-minify/min/index.php file of the plugin. You can use SFTP to edit the file or you can use the Plugin Editor of WordPress.

SFTP

See the tutorial to know how to use File Transfer Protocol (FTP) to access the source code of you app running on OpenShift.

Connect to your site’s **FTP **server and go to the following location :

/var/lib/openshift/your-app-id/app-root/runtime/repo/php/wp-content/plugins/bwp-minify/min

Open the file index.php from the directory using your text editor.

WordPress Plugin Editor

Go to wp-admin/plugin-editor.php page. Choose Better Wordpress Minify from “plugin to edit” field. Then choose

bwp-minify/min/index.php

from the files section shown on right side of window.

Solution

Search the file for the following line :

$min_serveOptions['minifierOptions']['text/css']['symlinks']

Add the following code just above the line you just searched :

if(preg_match("/wp-content/",$_GET['f'])){
 $_SERVER['DOCUMENT_ROOT'] = "/var/lib/openshift/app-id/app-root";
 $_GET['f']=str_replace("wp-content/","data/",$_GET['f']);
 $_GET['f']=str_replace("wp-includes/","runtime/repo/php/wp-includes/",$_GET['f']);
}

Make sure that you have replaced the app-id with your application’s id. You can get your app id from the Web URL of your app on Openshift Console. An example URL :

https://openshift.redhat.com/app/console/application/527de613e0b8cdef8d000212-blog

From the above URL, the id of the app is 527de613e0b8cdef8d000212 found just after the “application/” and end at the “-” sign.

And the whole code of that area would be :

if(preg_match("/wp-content/",$_GET['f'])){
 $_SERVER['DOCUMENT_ROOT'] = "/var/lib/openshift/app-id/app-root";
 $_GET['f']=str_replace("wp-content/","data/",$_GET['f']);
 $_GET['f']=str_replace("wp-includes/","runtime/repo/php/wp-includes/",$_GET['f']);
}
$min_serveOptions['minifierOptions']['text/css']['symlinks'] = $min_symlinks;

Save the file. Now, Enable the plugin if it’s deactivated. Open your blog and you will see the magic. If there are any problems, then please comment it on the comments section below. I will be here to help you out.