Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Eliot Akira on "Object-oriented programming advice: Custom Content Shortcode"

$
0
0

Hello all - I'm pretty familiar with PHP for building templates and plugins, but only recently started studying OOP and using classes.

I'm writing a plugin with two shortcodes, [loop] and [content]. The first does queries, and the second displays fields. For a list of the 3 most recent post titles:

[loop type="post" count="3"]
    <ul>
       <li>[content field="title]</li>
    </ul>
[/loop]

The [content] shortcode can be used stand-alone or inside a loop. The loop passes each post ID found to the content fields, according to the given query.

I would like to update the plugin to use classes for these functions. I have a plan for add-on features, for example: better meta query (relations, compare, range and series of fields, taxonomies, tags); calculate fields and formulae (like a simple spread-sheet); better query of date/time fields for events; etc.

Currently, I'm using a global variable (an array) to store the loop state, the post ID list from the query, if the loop is in attachments or gallery images, etc.

My question is, how would you recommend building these two functions into class objects? I guess I have to think about what data needs to be passed to/from, which should stay private and which public. Would a Singleton pattern be useful in this context? Any suggestions would be welcome.


Viewing all articles
Browse latest Browse all 8245

Trending Articles