/** * Function ProcessShortcode loads HTML from a Google Form URL, * processes it, and inserts it into a WordPress filter to output * as part of a post, page, or widget. * * @param $options array Values passed from the shortcode. * @see RenderGoogleForm * @return boolean - abort processing when false */ static function ProcessWpGFormCPT($options) { // Property short cut $o =& self::$options; // Id? Required - make sure it is reasonable. if ($options['id']) { $o['id'] = $options['id']; // Make sure we didn't get something nonsensical if (is_numeric($o['id']) && $o['id'] > 0 && $o['id'] == round($o['id'])) { $o['id'] = (int) $o['id']; } else { return false; } } else { return false; } if (array_key_exists('uid', $options)) { $o['uid'] = $options['uid']; } // get current form meta data fields $fields = array_merge(wpgform_primary_meta_box_content(true), wpgform_secondary_meta_box_content(true), wpgform_validation_meta_box_content(true), wpgform_placeholder_meta_box_content(true), wpgform_hiddenfields_meta_box_content(true), wpgform_text_overrides_meta_box_content(true)); foreach ($fields as $field) { // Only show the fields which are not hidden if ($field['type'] !== 'hidden') { // get current post meta data $meta = get_post_meta($o['id'], $field['id'], true); // If a meta value is found, strip off the prefix // from the meta key so the id matches the options // used by the form rendering method. if ($meta) { $o[substr($field['id'], strlen(WPGFORM_PREFIX))] = $meta; } } } // Validate columns - make sure it is a reasonable number if (is_numeric($o['columns']) && $o['columns'] > 1 && $o['columns'] == round($o['columns'])) { $o['columns'] = (int) $o['columns']; } else { $o['columns'] = 1; } if (WPGFORM_DEBUG) { wpgform_whereami(__FILE__, __LINE__, 'ProcessWpGFormCPT'); } if (WPGFORM_DEBUG) { wpgform_preprint_r($o); } // Have to have a form URL otherwise the short code is meaningless! return !empty($o['form']); }
/** * Action to save WordPress Google Form meta box data for CPT. * */ function wpgform_save_meta_box_data($post_id) { global $post; // verify nonce - needs to come from either a CPT Edit screen or CPT Quick Edit if (isset($_POST[WPGFORM_PREFIX . 'meta_box_nonce']) && wp_verify_nonce($_POST[WPGFORM_PREFIX . 'meta_box_nonce'], plugin_basename(__FILE__)) || isset($_POST[WPGFORM_PREFIX . 'meta_box_qe_nonce']) && wp_verify_nonce($_POST[WPGFORM_PREFIX . 'meta_box_qe_nonce'], plugin_basename(__FILE__))) { //wpgform_whereami(__FILE__, __LINE__) ; // check for autosave - if autosave, simply return if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // check permissions - make sure action is allowed to be performed if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } elseif (!current_user_can('edit_post', $post_id)) { return $post_id; } // Get the meta box fields for the appropriate CPT and // return if the post isn't a CPT which shouldn't happen if (get_post_type($post_id) == WPGFORM_CPT_FORM) { $fields = array_merge(wpgform_primary_meta_box_content(true), wpgform_secondary_meta_box_content(true), wpgform_validation_meta_box_content(true), wpgform_hiddenfields_meta_box_content(true), wpgform_placeholder_meta_box_content(true), wpgform_text_overrides_meta_box_content(true)); } else { return $post_id; } // Loop through all of the fields and update what has changed // accounting for the fact that Short URL fields are always // updated and CPT fields are ignored in Quick Edit except for // the Short URL field. foreach ($fields as $field) { // Only update other Post Meta fields when on the edit screen - ignore in quick edit mode if (isset($_POST[WPGFORM_PREFIX . 'meta_box_nonce'])) { if (array_key_exists($field['id'], $_POST)) { $new = $_POST[$field['id']]; $old = get_post_meta($post_id, $field['id'], true); if ($new && $new != $old) { update_post_meta($post_id, $field['id'], $new); } elseif ('' == $new && $old) { delete_post_meta($post_id, $field['id'], $old); } else { if ($field['id'] == WPGFORM_PREFIX . 'form' || $field['id'] == WPGFORM_PREFIX . 'transient_reset') { // If form cache reset was selected, or the URL was updated // let's delete the transient and uncheck the "reset" option delete_transient(WPGFORM_FORM_TRANSIENT . $post_id); if ($field['id'] == WPGFORM_PREFIX . 'transient_reset' && $new == 'on') { $new = ''; } } //wpgform_whereami(__FILE__, __LINE__); } } else { delete_post_meta($post_id, $field['id']); } } } // Set the post content to the shortcode for the form for rendering the CPT URL slug if (!wp_is_post_revision($post_id)) { // unhook this function so it doesn't loop infinitely remove_action('save_post_' . WPGFORM_CPT_FORM, 'wpgform_save_meta_box_data'); // update the post, which calls save_post again wp_update_post(array('ID' => $post_id, 'post_content' => sprintf('[wpgform id=\'%d\']', $post_id))); // re-hook this function add_action('save_post_' . WPGFORM_CPT_FORM, 'wpgform_save_meta_box_data'); } } else { return $post_id; } }