LLMS_AJAX_Handler::llms_update_access_plans( array $request )

AJAX handler for creating and updating access plans via the metabox on courses & memberships


Parameters Parameters

$request

(array) (Required) $_POST data.


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/class.llms.ajax.handler.php

1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
    $metabox       = new LLMS_Meta_Box_Product();
    $post_id       = absint( $request['post_id'] );
    $metabox->post = get_post( $post_id );
 
    $errors = array();
 
    foreach ( $request['plans'] as $raw_plan_data ) {
 
        if ( empty( $raw_plan_data ) ) {
            continue;
        }
 
        $raw_plan_data = wp_unslash( $raw_plan_data );
 
        // Ensure we can switch plans that used to be paid to free.
        if ( isset( $raw_plan_data['is_free'] ) && llms_parse_bool( $raw_plan_data['is_free'] ) && ! isset( $raw_plan_data['price'] ) ) {
            $raw_plan_data['price'] = 0;
        }
 
        $raw_plan_data['product_id'] = $post_id;
 
        // retained filter for backwards compat.
        $raw_plan_data = apply_filters( 'llms_access_before_save_plan', $raw_plan_data, $metabox );
 
        $plan = llms_insert_access_plan( $raw_plan_data );
        if ( is_wp_error( $plan ) ) {
            $errors[ $raw_plan_data['menu_order'] ] = $plan;
        } else {
            // retained hook for backwards compat.
            do_action( 'llms_access_plan_saved', $plan, $raw_plan_data, $metabox );
        }
    }
 
    return array(
        'errors' => $errors,
        'html'   => $metabox->get_html(),
    );
 
}
 
/**
 * AJAX handler for persisting tracking events.
 *
 * @since 3.37.14


Top ↑

Changelog Changelog

Changelog
Version Description
3.33.1 Use wp_unslash() before inserting access plan data.
3.29.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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