RadoslavGeorgiev / rila-framework

A front-end WordPress framework with a set of many extendable class wrappers, inpired by the MVC ideology
GNU General Public License v2.0
18 stars 3 forks source link

Create a rila() function #5

Closed RadoslavGeorgiev closed 8 years ago

RadoslavGeorgiev commented 8 years ago

The function should be able to convert as many object/data types to a Rila object as possible. It should receive a single argument, which works similarly to the second argument for ACF's get_field function.

Possible types

Type Example value Target
int 3 Rila\Post
WP_Post get_post( 3 ) Rila\Post
WP_Term get_term_by( 'id', 5, 'category' ) Rila\Term
WP_User get_user_by( 'email', 'user@example.com' ) Rila\User
WP_Comment get_comment( 5 ) Rila\Comment
string 'post_3' Rila\Post
string 'term_3' Rila\Term

Examples

<?php
# Just get a post by ID
$post = rila( 3 );

# Get a post by using a WP object
$post = get_post( 3 );
$post = rila( $post );

# Get a post by a (post type) string
$post = rila( 'event_10' );

# Get a term by a (custom taxonomy) string
$term = rila( 'category_3' );

Extension

It would be cool if the function allowed custom "data" types to be used. If the framework has a "Tweet" class, which handles a tweet, it would be cool to be able to get the tweet by ID:

<?php
$tweet = new rila( 'tweet_234364323' );

Arrays

Eventually, the function would also support arrays of values and create the respective collection.

No parameter

If there is no parameter, the function could simply create a collection of posts and allow further augumentation, in order to imitate jQuery:

<?php
$posts = rila()->type( 'event' )->meta( 'type', 'physical' );
RadoslavGeorgiev commented 8 years ago

Done in f99597521249d233445ba25c98975bafb15e2292 , no array support, rest is as said above.