ap_append_qameta( object $post )

Description #

Append post object with apmeta fields.

Parameters #

  • $post
    object (Required) Post Object.

Source #

File: includes/qameta.php

189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
function ap_append_qameta( $post ) {
    // Convert object as array to prevent using __isset of WP_Post.
    $post_arr = (array) $post;
    if ( ! in_array( $post_arr['post_type'], array( 'question', 'answer' ), true ) || isset( $post_arr['ap_qameta_wrapped'] ) ) {
        return $post;
    }
 
    $exist = true;
    foreach ( ap_qameta_fields() as $fields_name => $val ) {
        if ( ! isset( $post_arr[ $fields_name ] ) ) {
            $exist = false;
            break;
        }
    }
 
    if ( ! $exist ) {
        $defaults = ap_get_qameta( $post->ID );
        if ( ! empty( $defaults ) ) {
            foreach ( $defaults as $pkey => $value ) {
                if ( ! isset( $post_arr[ $pkey ] ) || empty( $post_arr[ $pkey ] ) ) {
                    $post->$pkey = $value;
                }
            }
        }
 
        $post->terms      = maybe_unserialize( $post->terms );
        $post->activities = maybe_unserialize( $post->activities );
 
        $post->votes_net = $post->votes_up - $post->votes_down;
    }
 
    return $post;
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment