WordPress.org

Ready to get started?Download WordPress

Forums

TIP: Plugin development using PHP classes or the "Cannot redeclare class". (1 post)

  1. dzenkovich
    Member
    Posted 5 years ago #

    Hi guys, thought this might be worth of sharing:

    There is a weird problem in WP - the "Cannot redeclare class" plugin activation fatall error, and as in the past, looks like this is related to WP's hooks into /admin side for missing files at the process of initializiation of the plugin or something.

    Whatever, point is - I've been struggling with this for couple of hours and the only solution (that is simple and powerfull enough) I've found - is to avoid the classes in the main plugin file!

    So this stands for:
    1. Use a stupid simple initiation file (the first file WP will load from you plugin directory)
    2. Move all of you classes into other files (aka oldschool /includes)
    3. Place a retarded check as: if(class_exists('MyMainClass'))
    4. Code include of the class file and it's initialization only if check fails (yep, class is not here yet - we go).

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 5 years ago by dzenkovich
  • This topic is not a support question
  • WordPress version: 2.6