Make WordPress Core

Changeset 948 in tests


Ignore:
Timestamp:
08/05/2012 10:11:25 PM (13 years ago)
Author:
nbachiyski
Message:

Introduce create_and_get()

Sometimes we need to get the object after creating it and this is a
convenient shortcut.

As a consequence, it introduces get(), so that we have a common way
to retrieve object by its id

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/factory.php

    r922 r948  
    3333        return wp_update_post( $fields );
    3434    }
     35
     36    function get( $post_id ) {
     37        return get_post( $post_id );
     38    }
    3539}
    3640
     
    5458        return wp_update_user( $fields );
    5559    }
     60
     61    function get( $user_id ) {
     62        return get_user( $user_id );
     63    }
    5664}
    5765
     
    7987        $args['comment_post_ID'] = $post_id;
    8088        return $this->create_many( $count, $args, $generation_definitions );
     89    }
     90
     91    function get( $comment_id ) {
     92        return get_comment( $comment_id );
    8193    }
    8294}
     
    102114
    103115    function update_object( $blog_id, $fields ) {}
     116
     117    function get( $blog_id ) {
     118        return get_blog_details( $blog_id, false );
     119    }
    104120}
    105121
     
    136152    function add_post_terms( $post_id, $terms, $taxonomy, $append = true ) {
    137153        return wp_set_post_terms( $post_id, $terms, $taxonomy, $append );
     154    }
     155
     156    function get( $term_id ) {
     157        return get_term( $term_id );
    138158    }
    139159}
     
    177197        return $created;
    178198    }
     199
     200    function create_and_get( $args = array(), $generation_definitions = null ) {
     201        $object_id = $this->create( $args, $generation_definitions );
     202        return $this->get( $object_id );
     203    }
     204
     205    abstract function get( $object_id );
    179206
    180207    function create_many( $count, $args = array(), $generation_definitions = null ) {
Note: See TracChangeset for help on using the changeset viewer.