LLMS_Meta_Box_Membership::save( int $post_id )

Save field data.


Description Description

See also See also


Top ↑

Parameters Parameters

$post_id

(int) (Required) WP_Post ID of the post being saved.


Top ↑

Return Return

(int) -1 When no user or user is missing required capabilities or when there's no or invalid nonce. 0 during inline saves or ajax requests or when no fields are found for the metabox. 1 if fields were found. This doesn't mean there weren't errors during saving.


Top ↑

Source Source

File: includes/admin/post-types/meta-boxes/class.llms.meta.box.membership.php

287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
public function save( $post_id ) {
 
    if ( ! llms_verify_nonce( 'lifterlms_meta_nonce', 'lifterlms_save_data' ) ) {
        return -1;
    }
 
    // Return early during quick saves and ajax requests.
    if ( isset( $_POST['action'] ) && 'inline-save' === $_POST['action'] ) {
        return 0;
    } elseif ( llms_is_ajax() ) {
        return 0;
    }
 
    $membership = new LLMS_Membership( $post_id );
 
    if ( ! isset( $_POST[ $this->prefix . 'restriction_add_notice' ] ) ) {
        $_POST[ $this->prefix . 'restriction_add_notice' ] = 'no';
    }
 
    // Get all defined fields.
    $fields = $this->get_fields();
 
    // save all the fields.
    $save_fields = array(
        $this->prefix . 'restriction_redirect_type',
        $this->prefix . 'redirect_page_id',
        $this->prefix . 'redirect_custom_url',
        $this->prefix . 'restriction_add_notice',
        $this->prefix . 'restriction_notice',
        $this->prefix . 'sales_page_content_page_id',
        $this->prefix . 'sales_page_content_type',
        $this->prefix . 'sales_page_content_url',
    );
 
    if ( ! is_array( $fields ) ) {
        return 0;
    }
 
    $to_return = 0;
 
    // Loop through the fields.
    foreach ( $fields as $group => $data ) {
 
        // Find the fields in each tab.
        if ( isset( $data['fields'] ) && is_array( $data['fields'] ) ) {
 
            // loop through the fields.
            foreach ( $data['fields'] as $field ) {
 
                // don't save things that don't have an ID or that are not listed in $save_fields.
                if ( isset( $field['id'] ) && in_array( $field['id'], $save_fields, true ) ) {
 
                    if ( isset( $field['sanitize'] ) && 'shortcode' === $field['sanitize'] ) {
                        $val = llms_filter_input_sanitize_string( INPUT_POST, $field['id'], array( FILTER_FLAG_NO_ENCODE_QUOTES ) );
                    } elseif ( isset( $field['multi'] ) && $field['multi'] ) {
                        $val = llms_filter_input_sanitize_string( INPUT_POST, $field['id'], array( FILTER_REQUIRE_ARRAY ) );
                    } else {
                        $val = llms_filter_input_sanitize_string( INPUT_POST, $field['id'] );
                    }
 
                    $membership->set( substr( $field['id'], strlen( $this->prefix ) ), $val );
                    $to_return = 1;
                }
            }
        }
    }
 
    return $to_return;
 
}


Top ↑

Changelog Changelog

Changelog
Version Description
5.9.0 Stop using deprecated FILTER_SANITIZE_STRING.
3.36.3 Added logic to correctly sanitize fields of type 'multi' (array) and 'shortcode' (preventing quotes encode). Also align the return type to the parent save() method.
3.35.0 Verify nonces and sanitize $_POST data.
3.30.0 Autoenroll courses saved via AJAX and removed from this method.
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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