I have a set of plugins that do different things. I’m wanting to write a plugin with a class I can extend in each of my custom plugins to meet a common goal. In my “socket” plugin I have something like this

class socketPlugin {
        function __construct($extendedClass){
    global $wpdb;
    $tablename = $wpdb->prefix."tableName";

    $classCount = $wpdb->get_var(
        "SELECT COUNT(id) FROM $tablename WHERE extendedClass="$extendedClass""
    );

    if($classCount && $classCount > 0){
        $wpdb->insert(
            $tablename,
            array(
            'extendedClass' => $extendedClass
            )
        );
    }

}

I then want to do something like this:

class myCustomClass extends socketPlugin {

}

And pass a variable into the constructor. Right now, if I do the above I get the PHP “white screen of death”.

Any ideas why I’m getting a white screen? How can I propperly extend the class of the socket plugin?

1 Answer
1

If the classes are not in the same file, you’ll need to require it into the child class ( myCustomClass ). Are you doing that?

Example :

//get the base class
if(!class_exists('MyParentClass')) {
    require_once plugin_dir_path( __FILE__ ) . '/_inc/MyParentClass.php';
}

/**
 * Class Definition
 */
class MyChildClass extends MyParentClass{

    // class definition

}

Leave a Reply

Your email address will not be published. Required fields are marked *