Unable to Add Exceptions through code – array as a string errors
-
Hello,
I have a front-end form that creates posts (using gravity forms). I’m trying to code a function that assigns edit exceptions to a set of user ids using the following code:
// Change 1 in gform_advancedpostcreation_post_after_creation_1 to your form id number. add_filter( 'gform_advancedpostcreation_post_after_creation_28', 'gf_post_pp_edit_multiselect', 10, 4 ); function gf_post_pp_edit_multiselect( $post_id, $feed, $entry, $form ) { // Checkboxes field id. Change this value to your field id number. $field_id = 2; // Get field object. $field = GFAPI::get_field( $form, $field_id ); if ( $field->type == 'multiselect' ) { // Get a comma separated list of multiselect checked $selected = $field->get_value_export( $entry ); $reviewers = []; // Convert list of users to array with user ids. $reviewers = explode( ', ', $selected ); $reviewerVals = array_values($reviewers); } GFCommon::log_debug( __METHOD__ . '(): reviewers => ' . print_r( $reviewers, true ) ); GFCommon::log_debug( __METHOD__ . '(): reviewerVals => ' . print_r( $reviewerVals, true ) ); GFCommon::log_debug( __METHOD__ . '(): selected => ' . print_r( $selected, true ) ); // reviewers => Array // ( // [0] => 7 // [1] => 8 // [2] => 97 // ) // enable all members of this group to read pages which are in the specified term $args = array( 'operation' => 'read', 'mod_type' => 'additional', 'for_item_source' => 'post', 'for_item_type' => 'post', 'via_item_source' => 'post', 'item_id' => $post_id, ); GFCommon::log_debug( __METHOD__ . '(): ppc_arguments => ' . print_r( $args, true ) ); ppc_assign_exceptions ( $reviewerVals, 'user', $args ); //tried with $reviewers, $reviewerVals, $selected - no luck! GFCommon::log_debug( __METHOD__ . '(): ppc_assign_exceptions output => ' . print_r(ppc_assign_exceptions ( $reviewers, 'user', $args )) ); }Could you kindly help me?
The errors I get are:
Warning: array_keys() expects parameter 1 to be array, string given in ".../publishpress-permissions/classes/PublishPress/Permissions/DB/PermissionsUpdate.php " on line 183And so on and so forth.
What am I doing wrong? How am I supposed to call the ppc_assign_exceptions() function for a set of users if I have their ids?
The topic ‘Unable to Add Exceptions through code – array as a string errors’ is closed to new replies.