1
votes

I started to create my first plugin for wordpress with admin pages and user page using OOP. At the "plugins" folder I created a new for my plugin. I have "index.php", an "includes" folder with some object php and "admin" folder. At the "themes" folder I created a new page-* php for the users. My problem, that I can't use my objects at user side. In the admin pages everything is fine, I can call and get datas, but in the page-*.php the /* @var $datas Object[] */ is don't do the same, $datas is NULL. How to link my admin and theme pages? Thank for the help!

1
So you are trying to access the properties of an object in the frontend of wordpress that has been instantiated in admin ? - Jamie_D
Yes. In the plugin folder have an includes folder (with classes and admin). The object created/edited in the admin main file. Maybe I put the classes into the themes folder? I don't know yet wordpress structure what what can see. - Galtomasz
Generally, a plugin is simply an extension of your theme's functions.php file, so any object that resides (and is included) in your plugin will be accessible in your frontend theme, provided you instantiate it. See Initiate a class in a WP plugin - Jamie_D
The problem with this class call, that I don't need the functions in the class now. I have only a construct and some getter functions. I need the final object which content is the sql table all data. This created in the admin file with $images = new Photos(id, param1, param2, param3,... ); uploadPhotos($images);. For list data $images = getPhotos(); get the data with sql query. After this I would like to use a foreach $images as $image and get values by $image->getParam(). - Galtomasz
Please post your class code. - Jamie_D

1 Answers

0
votes

Thanks for Jamie-D, I can solve my problem. I can't reach the original object in admin side, but I created a same structure as in admin and call the same functions. With this I created a new variable for the object, which contain the same data as the original, because both use the same database.