I've inherited a Wordpress project and I am trying to get it set up. I have zero experience in Wordpress and may as well say I have zero PHP experience. So far I've managed to get the environment set up on my local machine but I am stuck on a PHP parse error which I cannot find a solution for by googling. I'd like to at least get the existing project running on my machine.
When I open up my site locally I get redirected to $ROOT/wp-admin/install.php and I get this error in the apache error_log:
[Wed Oct 22 22:32:42 2014] [error] [client ::1] PHP Parse error: parse error in /path/to/project/wp-content/mu-plugins/wpengine-common/plugin.php on line 788
Line 788 is
public function disable_indiv_plugin_update_notices( $value ) {
and the surrounding code is
function wpengine_credits() {
if ( get_option( 'stylesheet' ) != 'twentyeleven' && get_option( 'template' ) != 'twentyeleven' )
return false;
if ( !defined('WPE_FOOTER_HTML') OR !WPE_FOOTER_HTML OR $this->already_emitted_powered_by == true )
return false;
//to prevent repeating
$this->already_emitted_powered_by = true; ?>
<div id="site-host">
WP Engine <?php printf( __( '%s.', 'wpengine' ), 'WordPress Hosting' ); ?>
</div>
<?php
}
public function disable_indiv_plugin_update_notices( $value ) {
$plugins_to_disable_notices_for = array();
$basename = '';
foreach ( $plugins_to_disable_notices_for as $plugin )
$basename = plugin_basename( $plugin );
if ( isset( $value->response[#$basename] ) )
unset( $value->response[$basename] );
return $value;
}
public function get_powered_by_html( $affiliate_code = null ) {
if ( ( ! defined('WPE_FOOTER_HTML') OR !WPE_FOOTER_HTML ) AND !$this->is_widget ) return "";
$this->already_emitted_powered_by = true;
if(WPE_FOOTER_HTML !== "") {
$html = WPE_FOOTER_HTML;
} else {
$html = $this->view('general/powered-by',array('affiliate_code'=>$affiliate_code),false);
}
return "<span class=\"wpengine-promo\">$html</span>";
}
I have a feeling it has to do with my PHP version. I am running PHP 5.4.30. Other solutions to similar problems suggested using
Any suggestions would be appreciated.
Delete the mu-plugins folder in you LOCAL environment... the error you are seeing is a special plugin run by WP Engine on their servers for internal use. It will, as you can see, fail if run outside the WP Engine environment.
Just make sure you don't delete the mu-plugins folder on the WP Engine server when you are putting the local environment back up to production!
Related
Setting:
I have a wordpress site but disabled wp_cron to have the full control of cron.
define('DISABLE_WP_CRON', true);
In crontab -e, I have following cron job:
*/2 * * * * /usr/bin/php /var/www/cron/mycron.php init >> /var/log/error.log 2>&1
The mycron.php has a simple function
if (!empty($argv[1])) {
switch ($argv[1]){
case 'init':
cron_test();
break;
}
}
function cron_test() {
$time = date(DATE_RFC822, time());
write_log("Start:" . $time); //outputs debug to my own log file
};
function write_log($log){
if ( true === WP_DEBUG ) {
if ( is_array( $log ) || is_object( $log ) ) {
write_log( print_r( $log, true ) );
} else {
write_log( $log );
}
}
};
Note that I declared the mycron.php in functions.php for wp:
require_once('parts/mycron.php');
Error log:
In my error.log for the cron, I have the following error:
PHP Warning: Use of undefined constant WP_DEBUG - assumed 'WP_DEBUG'
So, I am guessing there is some sort of disconnection between cron and wp, which is my best guess.
What I am trying to do:
The mycron.php will have many wordpress functions that I would need. How do I make the cron to recognize the wp function such as WP_DEBUG?
Any help will be much appreciated.
Thanks!
You need to load Wordpress functions manually, to use them in a custom script.
require_once("../../../../wp-load.php");
Also answered in depth here,
How to include Wordpress functions in custom .php file?
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
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
I'd like to run a php script from cli which will access a WP plugin's class.
I've seen plenty ways of loading WP environment from cli, most common which I also use is
if( php_sapi_name() !== 'cli' ) {
die("Meant to be run from command line");
}
function find_wordpress_base_path() {
$dir = dirname(__FILE__);
do {
//it is possible to check for other files here
if( file_exists($dir."/wp-config.php") ) {
return $dir;
}
} while( $dir = realpath("$dir/..") );
return null;
}
define( 'BASE_PATH', find_wordpress_base_path()."/" );
define('WP_USE_THEMES', false);
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
require(BASE_PATH . 'wp-load.php');
However the above code will not load the plugins and if I try to access a plugin's class i get the error "Call to undefined method". I've also
tried running it from wp-cli using eval-file command, but again with no luck.
any ideas on how to load wordpress environment with plugins from cli ?
Just upgraded Mediawiki 1.19.6 to the most current, 1.22.2.
Used update.php, which worked just fine. The front page loads, as do SOME of the articles if you enter their exact URL. However, following any of the links produces:
Catchable fatal error: Argument 1 passed to
ContentHandler::getContentText() must implement interface Content,
boolean given, called in <wiki path>/includes/Article.php on line 389
and defined in <wiki path>/includes/content/ContentHandler.php on line
95.
I've looked up the call to getContentText() in Article.php, and it's in a function called fetchContent(), with a comment about it being crufty and a note that the ContentHandler method within is deprecated.
I can't figure out how to fix what's gone wrong, and web searches are only turning up bug reports that are marked fixed... any ideas? Thanks very much.
getContentText() is depreciated.
Use WikiPage::getContent()
https://doc.wikimedia.org/mediawiki-core/master/php/html/classArticle.html#affd3b52d2544cc334d7805ae9e5aba98
We had the same problem. Our ICT guy handled it by adapting the Article.php file placed in the includes directory of your mediawiki. Only 1 function was adapted (line 377 function function fetchContent()). I do not know the exact working principle but the MediaWiki returned to normal.
Also I believe you need to run the mediawiki update routine by visiting:
'HostAdress'/MediaWiki/mw-config/
Original function in Article.php:
function fetchContent() { #BC cruft!
ContentHandler::deprecated( __METHOD__, '1.21' );
if ( $this->mContentLoaded && $this->mContent ) {
return $this->mContent;
}
wfProfileIn( __METHOD__ );
$content = $this->fetchContentObject();
// #todo Get rid of mContent everywhere!
$this->mContent = ContentHandler::getContentText( $content );
ContentHandler::runLegacyHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) );
wfProfileOut( __METHOD__ );
return $this->mContent;
}
New function in Article.php:
function fetchContent() { #BC cruft!
ContentHandler::deprecated( __METHOD__, '1.21' );
if ( $this->mContentLoaded && $this->mContent ) {
return $this->mContent;
}
wfProfileIn( __METHOD__ );
$content = $this->fetchContentObject();
if ( !$content ) {
wfProfileOut( __METHOD__ );
return false;
}
// #todo Get rid of mContent everywhere!
$this->mContent = ContentHandler::getContentText( $content );
ContentHandler::runLegacyHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) );
wfProfileOut( __METHOD__ );
return $this->mContent;
}
is there any way working with Phpfox without memcache service? because i am using hostgator shared server, where as shared server which does not provide any memcache service its only available in dedicated servers only.
I am using Phpfox1.5 is previously hosted in amazon server where mecache service available but its very costly for me so i want to change my site from amazon to hostgator hosting service.
Fatal error: Class 'Memcache' not found in /home/latisse/public_html/spicypeeps.com/include/library/phpfox/cache/storage/memcache.class.php on line 64
Sure, just include a file with this class on top of it:
<?php
// Dummy Memcache for a development environment where Memcache is not installed. Part of mmvc library, https://github.com/kajala/mmvc
// Dependencies: none
//if ( defined('MEMCACHE_COMPRESSED') )
// die( "Memcache seems to be already installed, MemcacheDummy.php should never be included in this case\n" );
define( 'MEMCACHE_COMPRESSED', 1234 ); // dummy value
/**
* Dummy Memcache class for a development environment where Memcache is not installed.
* Note that this class does not do ANYTHING and it is only a convenience for
* the development environment and should never be used in production server.
*/
class Memcache
{
function __construct()
{
}
function connect( $host, $port )
{
assert( is_string($host) );
assert( is_numeric($port) );
return true;
}
function set( $key, $obj, $compressed=false, $expires=0 )
{
assert( is_string($key) );
assert( $compressed === false || $compressed == MEMCACHE_COMPRESSED );
assert( is_numeric($expires) );
return true;
}
function get( $key )
{
assert( is_string($key) || is_array($key) );
return false;
}
}
?>
Note: the code isn't mine, and it is licensed under the BSD license. Original author: link