Example #1
0
 private static function getCachedForm($form_id, $post_id, $preview, $force_count = false, $specific_post_id = null)
 {
     global $post;
     StaticClass::$_mail_error = get_option('_' . $form_id . '_last_mail_error', '');
     //put a sanitize someone could add _mail_error text injection?
     StaticClass::$_mail_error = sanitize_text_field(StaticClass::$_mail_error);
     StaticClass::$_cred_container_id = isset($_POST[StaticClass::PREFIX . 'cred_container_id']) ? intval($_POST[StaticClass::PREFIX . 'cred_container_id']) : $post->ID;
     //https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/196173458/comments
     //Security Check
     if (isset(StaticClass::$_cred_container_id) && !empty(StaticClass::$_cred_container_id)) {
         if (!is_numeric(StaticClass::$_cred_container_id)) {
             wp_die('Invalid data');
         }
     }
     $form_count = false !== $force_count ? $force_count : StaticClass::$_staticGlobal['COUNT'];
     if (false !== $force_count || !array_key_exists($form_id . '_' . StaticClass::$_staticGlobal['COUNT'], StaticClass::$_staticGlobal['CACHE'])) {
         // parse and cache form
         $fb = new CRED_Form_Builder();
         $form_post_type = get_post_type($form_id);
         $form = $form_post_type == CRED_USER_FORMS_CUSTOM_POST_NAME ? $fb->user_form($form_id, $post_id, $preview, $form_count, $specific_post_id) : $fb->form($form_id, $post_id, $preview, $form_count, $specific_post_id);
         /* StaticClass::$_staticGlobal['CACHE'][$form_id.'_'.$form_count]=array(
            'form' =>  $output,
            'count' => $form_count,
            'extra' => $this->_formData->getExtra(),
            'css_to_use' => $this->_formData->getCSS(),
            'js' => $this->getJS(),
            'hide_comments' =>  $this->_formData->hasHideComments(),
            'has_recaptcha' =>  $this->hasRecaptcha()
            ); */
         StaticClass::$_staticGlobal['CACHE'][$form_id . '_' . $form_count] = array('form' => $form, 'count' => $form_count, 'extra' => $fb->getExtra(), 'js' => $fb->getJS(), 'hide_comments' => $fb->hasHideComments(), 'has_recaptcha' => $fb->hasRecaptcha());
     }
     if (isset($post_id)) {
         $parent_post = get_post($post_id);
     }
     // add filter to hide comments (new method)
     if (StaticClass::$_staticGlobal['CACHE'][$form_id . '_' . $form_count]['hide_comments'] || isset($parent_post) && $parent_post->comment_status == 'closed') {
         CRED_Form_Builder_Helper::hideComments();
     }
     return StaticClass::$_staticGlobal['CACHE'][$form_id . '_' . $form_count]['form'];
 }