WordPress.org

Ready to get started?Download WordPress

Forums

Access main class in other php files (1 post)

  1. vilisseranen
    Member
    Posted 1 year ago #

    Hello everybody,

    I develop my first plugin for wordpress and I have some issues. Please be indulgent, it's the first time I do OOP with php.

    My plugin is called guest_calendar and the main class gec in guest_calendar.php. This class is a singleton.
    In this class, I have many things declared, such as a Captcha object ($securimage) and the $wpdb.

    I manage a calendar (with fullcalendar) wich retrieves events with ajax (it calls fetchEvents.php).

    My problem is : I want to use the $wpdb and $securimage in the file fetchEvents.php. I want to instantiate $gec in fetchEvents.php but I dont know how to do it.

    I wrote

    function loadClass($class)
    {
        if($class == 'gec') {
            require 'guest_calendar.php';
        }
    }
    
    spl_autoload_register('loadClass');

    at the end of guest_calendar.php and $gec = gec::getInstance(); in fetchEvents.php but it is not working.

    This is the plugin structure :

    guest_calendar
    |- guest_calendar.php (containing class gec)
    |- php
    ....|- fetchEvents.php

    I'm using php 5

    Any idea is welcome ! Thank you

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.