Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // http://www.gravityhelp.com/forums/topic/password-protect-a-post-published-by-a-gf-form
- // this code goes in your current theme's functions.php file
- // change the 349 here to your form ID
- add_action('gform_after_submission_349', 'set_post_password', 10, 2);
- function set_post_password($entry, $form) {
- // see if the field containing the password has a value
- // change the 6 here to the field in your form where you accepted the post password
- if(check_not_empty($entry[6],1)) {
- $post = get_post($entry['post_id']);
- $post->post_password = $entry[6];
- wp_update_post($post);
- }
- }
- // props for this function: http://www.php.net/manual/en/function.empty.php#77617
- function check_not_empty($s, $include_whitespace = false){
- if ($include_whitespace) {
- // make it so strings containing white space are treated as empty too
- $s = trim($s);
- }
- return (isset($s) && strlen($s)); // var is set and not an empty string ''
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement