Elliott de Launay
Elliott de Launay

Reputation: 1168

Wordpress PHP Fatal Error with Openshift

When I try to access the plugins or themes section of my wordpress site from the admin panel I am presented with a blank screen. When I run the logs I get the following error:

Navigating to wp-admin/plugins.php:

PHP Fatal error:  Call to undefined function wp_json_encode() in /var/lib/openshift/{userID}/app-root/data/current/wp-includes/update.php on line 277

Navigating to wp-admin/themes.php:

PHP Fatal error:  Call to undefined function wp_json_encode() in /var/lib/openshift/{userID}/app-root/data/current/wp-includes/update.php on line 440

Solutions online indicated that I should re-add the function, or re-install Wordpress. Without access to the core files, I downloaded a local repository of the application (but noticed it did not contain any of the plugins or themes I had uploaded via the admin interface).

I extracted a plugin and theme (placing them in the respective directories) then pushed the changes to production in the hopes that it would extract and re-install an updated version of wordpress. I then restarted the app.

The error still persists and I can not validate if the plugin or theme I uploaded were installed. Is there a way to refresh or reinstall a wordpress instance on Openshift?

I'm wondering how I can fix this issue without creating a new gear and migrating my data via the database. Note: Front end is working fine.

Version of Wordpress: 4.1.1

Upvotes: 0

Views: 198

Answers (1)

Elliott de Launay
Elliott de Launay

Reputation: 1168

I ended up connecting to the app via SFTP and modified the file the following directly

/var/lib/openshift/{userID}/app-root/data/current/wp-includes/functions.php 

and added the following function:

function wp_json_encode( $data, $options = 0, $depth = 512 ) {
/*
 * json_encode() has had extra params added over the years.
 * $options was added in 5.3, and $depth in 5.5.
 * We need to make sure we call it with the correct arguments.
 */
if ( version_compare( PHP_VERSION, '5.5', '>=' ) ) {
    $args = array( $data, $options, $depth );
} elseif ( version_compare( PHP_VERSION, '5.3', '>=' ) ) {
    $args = array( $data, $options );
} else {
    $args = array( $data );
}

$json = call_user_func_array( 'json_encode', $args );

// If json_encode() was successful, no need to do more sanity checking.
// ... unless we're in an old version of PHP, and json_encode() returned
// a string containing 'null'. Then we need to do more sanity checking.
if ( false !== $json && ( version_compare( PHP_VERSION, '5.5', '>=' ) || false === strpos( $json, 'null' ) ) )  {
    return $json;
}

try {
    $args[0] = _wp_json_sanity_check( $data, $depth );
} catch ( Exception $e ) {
    return false;
}

return call_user_func_array( 'json_encode', $args );

}

Ref: https://wordpress.org/support/topic/fatal-error-call-to-undefined-function-wp_json_encode-in

Upvotes: 0

Related Questions