示例#1
0
function et_pb_process_computed_property()
{
    if (!isset($_POST['et_pb_process_computed_property_nonce']) || !wp_verify_nonce($_POST['et_pb_process_computed_property_nonce'], 'et_pb_process_computed_property_nonce')) {
        die(-1);
    }
    if (!current_user_can('edit_posts')) {
        die(-1);
    }
    $depends_on = $_POST['depends_on'];
    $conditional_tags = $_POST['conditional_tags'];
    $current_page = $_POST['current_page'];
    // $_POST['depends_on'] is a single dimensional assoc array created by jQuery.ajax data param, sanatize each key and value, they will both be strings
    foreach ($depends_on as $key => $value) {
        // correctly sanitize the strings with %date variable. sanitize_text_field will strip the '%da' and '%date' will be saved as 'te'.
        $prepared_value = str_replace('%date', '___et-fb-date___', $value);
        $sanitized_value = str_replace('___et-fb-date___', '%date', sanitize_text_field($prepared_value));
        $depends_on[sanitize_text_field($key)] = $sanitized_value;
    }
    $module_slug = sanitize_text_field($_POST['module_type']);
    $post_type = sanitize_text_field($_POST['post_type']);
    $computed_property = sanitize_text_field($_POST['computed_property']);
    // get all fields for module
    $fields = ET_Builder_Element::get_module_fields($post_type, $module_slug);
    // make sure only valid fields are being passed through
    $depends_on = array_intersect_key($depends_on, $fields);
    $conditional_tags = array_intersect_key($conditional_tags, et_fb_conditional_tag_params());
    $current_page = array_intersect_key($current_page, et_fb_current_page_params());
    // computed property field
    $field = $fields[$computed_property];
    $callback = $field['computed_callback'];
    if (is_callable($callback)) {
        die(json_encode($callback($depends_on, $conditional_tags, $current_page)));
    } else {
        die(-1);
    }
}