LLMS_Post_Model::__construct( string|int|LLMS_Post_Model|WP_Post $model, array $args = array() )

Constructor


Description Description

Setup ID and related post property.


Top ↑

Parameters Parameters

$model

(string|int|LLMS_Post_Model|WP_Post) (Required) 'new', WP post id, instance of an extending class, instance of WP_Post.

$args

(array) (Optional) Args to create the post, only applies when $model is 'new'.

Default value: array()


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/abstracts/abstract.llms.post.model.php

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
public function __construct( $model, $args = array() ) {
 
    if ( 'new' === $model ) {
        $model = $this->create( $args );
        if ( ! is_wp_error( $model ) ) {
            $created = true;
        }
    } else {
        $created = false;
    }
 
    if ( empty( $model ) || is_wp_error( $model ) ) {
        return;
    }
 
    if ( is_numeric( $model ) ) {
 
        $this->id   = absint( $model );
        $this->post = get_post( $this->id );
 
    } elseif ( is_subclass_of( $model, 'LLMS_Post_Model' ) ) {
 
        $this->id   = absint( $model->id );
        $this->post = $model->post;
 
    } elseif ( $model instanceof WP_Post && isset( $model->ID ) ) {
 
        $this->id   = absint( $model->ID );
        $this->post = $model;
 
    }
 
    if ( $created ) {
        $this->after_create();
    }
 
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.13.0 Unknown.
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.