Last active
November 5, 2020 17:43
-
-
Save plugin-republic/9cf7d3b71d5bd9e194495eab941647c0 to your computer and use it in GitHub Desktop.
Filter the default field value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Enable a default value for checkbox groups. | |
* Your default value must be an array. | |
* You'll need to change the value of the $field_id to match your own Field ID | |
* @param $value The current value of the field | |
* @param $id The field ID in the format pewc_group_888_999 | |
* @param $field The field object | |
* @param $posted The $_POST object | |
*/ | |
function prefix_set_field_value_by_url_param( $value, $id, $field, $posted ) { | |
// Change this to the ID of the field you are setting a default for | |
$field_id = 8018; | |
// Don't overwrite a value that's already there | |
if( isset( $_GET['my_param'] ) && $field_id == $field['field_id'] ) { | |
$value = esc_attr( $_GET['my_param'] ); | |
} | |
return $value; | |
} | |
add_filter( 'pewc_default_field_value', 'prefix_set_field_value_by_url_param', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment