wpmetabox / meta-box

The best plugin for WordPress custom fields and custom meta boxes
https://metabox.io
1.19k stars 424 forks source link

Error Meta-Box Activate #810

Closed cacaio closed 8 years ago

cacaio commented 8 years ago

Hello,

When I try to activate the plugin generates this error:

Erro fatal : Class 'RWMB_Core' não foi encontrado na /home/youin756/public_html/wp-content/plugins/meta-box/inc/loader.php na linha 127

How can I solve it ?

Thanks.

westcoastdigital commented 8 years ago

I am having the same error with metabox embedded in my plugin, I have also checked the "3 step fix" and it is all perfectly fine in my functions etc

rilwis commented 8 years ago

Can you check the latest version on Github?

Nicholas-Cardot commented 8 years ago

@rilwis This is a duplicate of issue #800 and I'm using the most current version and still seeing this error on a small number of sites. I've got about 5 - 10 people seeing this error.

I did notice that for some people, this error went away by uninstalling my plugin and reinstalling it. Perhaps there's a hook that runs when it's installed or activated or something. I don't know.

rilwis commented 8 years ago

@Nicholas-Cardot Thanks for letting me know. Can you please send me your plugin (just for testing) via email (in my profile page)? This is annoying bug and I want to fix it completely.

Nicholas-Cardot commented 8 years ago

@rilwis I just sent you a link to our GitHub. You can browse it from there, or download to test if you want. Thanks for be willing to look into this.

Nicholas-Cardot commented 8 years ago

@rilwis Here's the first system status I've gotten back from a customer so far:

Home URL REDACTED Site URL REDACTED WordPress Version 4.5.1 PHP Version 5.5.9-1ubuntu4.16 WP Memory Limit 40M Social Warfare Version 1.4.2 Connection Statuses

fsockopen Enabled cURL Enabled Tweet Counts Enabled Plugin Statuses

Theme Name TMA Theme Version Active Plugins Number of Active Plugins 38 Ad Injection 1.2.0.19 Affiliates 2.15.1 Affiliates WooCommerce Integration Light 1.3.0 Ajax Search Pro 4.8.4 Akismet 3.1.10 Amazon Link 3.2.5 Better WordPress Minify 1.3.3 Broken Link Checker 1.11.2 CloudFlare 1.3.24 Contact Form 7 4.4.1 CoSchedule by Todaymade 2.4.5 Disable Emojis 1.5.1 Easy Slide-In for WordPress 2.0 Featured Images in RSS w/ Size and Position 1.3.7 Get Custom Field Values 3.7 Google Analytics by MonsterInsights 5.4.9 Interactive World Maps 1.6.7 Maintenance 2.7.1 Outbound Link Manager 1.2 Paulund Disable Pingbacks 1.0 Q2W3 Fixed Widget 4.0.6 Quick Adsense 1.9.2 Redirection 2.4.4 Search Meter 2.12 Social Warfare 1.4.2 Symple Shortcodes 2.0.0 TablePress 1.7 TablePress Extension: Responsive Tables 1.2 User Role Editor 4.25.1 W3 Total Cache 0.9.4.1 Widget Logic 0.57 WooCommerce 2.5.5 WooCommerce Conversion Tracking 1.2 Wordfence Security 6.1.4 WP Hide Post 1.2.2 WPML Multilingual CMS 3.3.8 WP Smush 2.2.2 Yoast SEO 3.2.3

Nicholas-Cardot commented 8 years ago

I had another developer look into this issue, and this is what they found. I'll implement this and test this later today:

I have researched the codes of meta-box plugin/extention and I see, we can have a error only when the autoload function (in line 84 of the file meta-box/inc/loader.php) is not triggered (or not worked correctly) before calling the class RWMB_Core, which is calling in the init() function of the same file meta-box/inc/loader.php

So, maybe, that user who see the error, they have a problem with php function spl_autoload_register, which is used for __autoload() implementation, and version of PHP is (PHP 5 >= 5.1.2, PHP 7)

So for that I have added checking code, if our class is not exist, then include the class

here is the solution which we can add in file social-warfare/meta-box/inc/loader.php in function init(), in line 121 before calling the RWMB_Core class

//GX checking/correcting
if ( !class_exists( RWMB_Core ) ) {
   $this->autoload( 'RWMB_Core' ); //by using the class functionality
   //require RWMB_INC_DIR . 'core.php'; //or simple/default php version
}

here is the example 6d7efd74911ac3b90bcb82df6f7c2bb5

rilwis commented 8 years ago

If we include the RWMB_Core class manually, that will fix for it only. But the autoload function won't work for other classes (fields classes). Probably the host disables autoload extension. I will keep digging into that.

Nicholas-Cardot commented 8 years ago

See I was wondering the same thing: That if we include it like this then we're only fixing this one symptom but not actually fixing the whole thing.

rilwis commented 8 years ago

I just found this ticket, and the install manual where they say the autoload functionality can be disabled in PHP 5.2.

My guest is in some rare cases, the autoload is disabled in some hosts where they're running PHP 5.2.

@Nicholas-Cardot Can you check that with your customer?

Nicholas-Cardot commented 8 years ago

The customer I listed above is using 5.5.x, not 5.2. Can it still be disabled on that version or didn't they make it always on after 5.3?

gibrangt commented 8 years ago

Another system status, same problem

WP Version: 4.5.1 WP_DEBUG: Disabled WP Language: enUS Multisite: No WP Memory Limit: 40MB WP Memory Limit Status: Not OK - Recommended Memory Limit is 64MB WP Table Prefix: wp WP Table Prefix Length: 3 WP Table Prefix Status: Acceptable WP Timezone: , GMT: -6 WP Remote Post: wp_remote_post() works Permalink Structure: /%postname%/ Registered Post Stati: publish, future, draft, pending, private, trash, auto-draft, inherit Show On Front: page Page On Front: Page For Posts:

Theme Information

Theme Name: realhomes Theme Version:
Theme Author:
Theme Author URI:
Is Child Theme: No

Plugins Information

-- Must-Use Plugins

-- WordPress Active Plugins

Meta Box: 4.7.3 Rilwis https://metabox.io Meta Box Columns: 0.1 Rilwis http://www.deluxeblogtips.com/meta-box Meta Box Tabs: 0.1.3 Rilwis http://metabox.io/plugins/meta-box-tabs/ Simple System Status: 1.0.0 Leo Gopal http://leogopal.com/

-- WordPress Inactive Plugins

Akismet: 3.1.7 Automattic http://akismet.com/ Hello Dolly: 1.6 Matt Mullenweg http://wordpress.org/plugins/hello-dolly/

Server Environment

Server Info: Apache Host: DBH: localhost, SRV: casasycasasinmobiliaria.com Default Timezone: UTC MySQL Version: 5.5.42-37.1

-- PHP Configuration

PHP Version: 5.6.14 PHP Post Max Size: 64M PHP Time Limit: 30 PHP Max Input Vars: 1000 PHP Safe Mode: No PHP Memory Limit: 256M PHP Upload Max Size: 64M PHP Upload Max Filesize: 64M PHP Arg Separator: & PHP Allow URL File Open: Yes

-- PHP Extentions

DISPLAY ERRORS: On (1) FSOCKOPEN: Your server supports fsockopen. cURL: Your server supports cURL. SOAP Client: Your server has the SOAP Client enabled. SUHOSIN: Your server does not have SUHOSIN installed.

-- Session Configuration

Session: Disabled Session Name: PHPSESSID Cookie Path: / Save Path: /tmp Use Cookies: On Use Only Cookies: On

-- Client Details:

Platform: Windows Browser Name: Chrome
Browser Version: 49.0.2623.112 User Agent String: Mozilla/5.0 (Windows NT 6.3; WOW 64) AppleWebKit/537.36 (KHTML, l ike Gecko) Chrome/49.0.2623.112 Safari/537.36

Nicholas-Cardot commented 8 years ago

Here's a note that I got back from another developer:


as you know It's solving the problem for RWMB_Core, but we can have also problem for other classes in current plugin as I see, all problem can be from only autoload function so, If we are sure we have a suuport for spl_autoload_register next step which I can suggest, It's adding the 3rd parammeter

spl_autoload_register( array( $this, 'autoload' ), true ); //If true, spl_autoload_register() will prepend the autoloader on the autoload queue instead of appending it. //maybe we can have also conflict for spl_autoloads from other plugins (multiple autoloads) http://www.phpro.org/tutorials/SPL-Autoload.html also, we can try to set the extensions (to be sure) spl_autoload_extensions(".php");

however, we need to be sure we have a spl_autoload support in php, if no, so we need to check and change the way for autoload (or include manually)


So is there a way that we can just include everything manually?

Nicholas-Cardot commented 8 years ago

@rilwis I think I may have a solution.

It appears that on a very, very small number of sites (I'm estimating about <0.1%) they have autoload functionality disabled by the hosting provider. Usually this is done in php.ini. In order to cater to these hosting scenarios, we need to include the files manually.

So I wrote a function that recursively searches through the plugin folder and includes every php file. However, this failed, because many of the classes extend other classes, it's necessary to include these files in the correct order. If using a generic, recursive search, it will throw errors when trying to extend a class that has not yet been defined.

Here's what I'm thinking:

First, we check to see if the spl_autoload_register() actually fired off. The very first class called after the autoload registration is RWMB_Core, so simply checking if it exists will let us know if the autoloader worked or not. For example:

$this->constants();
spl_autoload_register( array( $this, 'autoload' ) );
if( !class_exists( 'RWMB_Core' ) {
    $this->autoload_fallback();
}
$this->init();

So there we've simply checked if it's worked and called a function that will populate manual requires/includes in the rare case that the autoloader didn't work. Now we need to create that fallback function:

public function autoload_fallback() 
{
    require_once RWMB_DIR . 'fields/filea.php
    require_once RWMB_DIR . 'fields/fileb.php
    require_once RWMB_DIR . 'fields/filec.php
}

So what I need to finish this is simply a list of the files in the proper order to avoid 'Class BlahBlah not found in..." errors. Can you provide that list?

rilwis commented 8 years ago

Hi @Nicholas-Cardot ,

That was exactly what I was thinking about. I will do that now.

rilwis commented 8 years ago

Done. Can you please test it on real hosting? @Nicholas-Cardot @cacaio @CarassiusPro ? I tested it on my localhost by disabling autoload and it works.

d2roth commented 8 years ago

Hey @rilwis and @Nicholas-Cardot, instead of going through and making a list of the order couldn't you just add a require, or require_once, statement at the top of each field file that would require the needed class file if the class doesn't exist?

So inside fields/file.php you would have if (!class_exists('fielda')){require_once('fielda.php');}. If fielda extends another class it would have the a require at the top as well.

Would that work or is it over-complicating the solution?

rilwis commented 8 years ago

@d2roth it would work, of course. That was how I did in previous versions. However, loading all files is still a must-do job (remember the autoload doesn't work in that case).