[wp-hackers] Creating objects within a plug-in

Jacob Santos wordpress at santosj.name
Sat Jan 12 02:50:47 GMT 2008


Dude, I totally forgot about the functions.php for a series on Plugins 
that I'm doing. I'll have to do some research and write an article on it 
also.

 From what I understand from your problem. It appears that you will want 
to use options API instead. Your class can still build your "opt" array 
based off of it. The options API will serialize your array and allow you 
to plug it into your class property as it is. This will allow you to 
build a plugin in your functions.php that will also setup an admin page 
for managing the options.

It appears that any existing functions.php file is included during the 
WordPress bootstrap, so you can include anything in it that you can in a 
plugin.

Just kind of have to make sure that you clean up your options when the 
user removes you. If you name your options well enough, 
'yourthemename_{Whatever}' then it will allow for manually cleanup later.

Hope that helps. The Options API, I think, is pretty intuitive, so you 
should have any problem with it if you have classes and objects down.

Good luck.

Jacob Santos

Williams Phillip wrote:
> I am still new enough to PHP so I am not familiar with how it 
> serializes objects, but that might be it. However, let me see if I can 
> walk through the use case a little better in case there is another 
> solution.
>
> The user will go to an admin page to setup a specific filter for 
> archives. They will specify the options such as the type of archive 
> links to display, the categories to include/exclude, etc. She then 
> wants to use the filter in a sidebar to display archive links. She 
> would then need to edit the sidebar template and include something like:
>
> global $all_filter;
> $all_filter->get_filtered_archives();
>
> on the page at the desired location.
>
> Presently she would add the following at the beginning of my 
> functions.php, say:
>
> $all_filter = new arch_filter;
> $all_filter->opt['type'] ='monthly';
> $all_filter->opt['exclude'] = get_cat_ID('News').",".implode(",", 
> get_career_categories());
> $all_filter->opt['show_post_count'] = true;
>
> I am trying avoid the user having to instantiate the filters in this 
> manner and would rather the filters be managed through admin screens. 
> So the question is where does the $all_filter object first get 
> instantiated once the admin screens have been implemented.
>
> Phil
> phil.m.williams at gmail.com
>
>
>
>
> On Jan 11, 2008, at 10:54 AM, Burobjorn wrote:
>
>> Not sure if I understand the question correctly, but perhaps you're 
>> looking at serializing objects?
>>
>> grtz
>> BjornW
>>
>>
>> Williams Phillip wrote:
>>> I am developing a plug-in that will allow archive links and pages to 
>>> be easily filtered to exclude or include specific categories. It 
>>> consists of a filter class that encapsulates the functionality of 
>>> wp_get_archives() with the additional subqueries to limit the 
>>> returned posts to the specified categories.
>>> Currently, I instantiate various archive filter objects at the 
>>> beginning of the functions.php file. I can then use them on any page 
>>> by declaring the objects as global. I would like to be able to go 
>>> the next step and build an admin screen that will allow a user to 
>>> configure any number of archive filters for use on within templates. 
>>> I am planning on either using the options route or creating my own 
>>> table structure to manage the filter settings.
>>> My question is this. How would a filter object be instantiated that 
>>> could then be used within another PHP file?
>>> Phil
>>> phil.m.williams at gmail.com
>>> _______________________________________________
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>>
>> -- 
>>
>> met vriendelijke groet,
>> Bjorn Wijers
>>
>> * b u r o b j o r n .nl *
>> digitaal vakmanschap | digital craftsmanship
>>
>> Concordiastraat 68-126
>> 3551 EM Utrecht
>> The Netherlands
>>
>> phone: +31 30 2444 101
>> http://www.burobjorn.nl
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers


-- 

Jacob Santos

http://www.santosj.name - blog

Also known as darkdragon and santosj on WP trac.



More information about the wp-hackers mailing list