public static function replaceContentWithForm($content) { global $post, $wp_query; //resolve problem when view templates are added in sidebar widgets remove_filter('the_content', array(__CLASS__, 'replaceContentWithForm'), 1000); // if it is front page and form preview is required if (array_key_exists('cred_form_preview', $_GET)) { CRED_Loader::load('CLASS/Form_Builder'); return CRED_Form_Builder::getForm(intval($_GET['cred_form_preview']), null, true); } if (array_key_exists('cred_user_form_preview', $_GET)) { CRED_Loader::load('CLASS/Form_Builder'); return CRED_Form_Builder::getUserForm(intval($_GET['cred_user_form_preview']), null, true); } global $_creds_created; if (!isset($_creds_created)) { $_creds_created = array(); } if (!empty($_creds_created) && in_array($_GET['cred-edit-form'], $_creds_created)) { return apply_filters('the_content', $content); } if (strpos($content, 'cred-edit-form=' . $_GET['cred-edit-form']) !== false || array_key_exists('cred-edit-form', $_GET) && !is_admin()) { array_push($_creds_created, $_GET['cred-edit-form']); CRED_Loader::load('CLASS/Form_Builder'); // get a localised form if exists return CRED_Form_Builder::getForm(self::getLocalisedID(intval($_GET['cred-edit-form'])), $post->ID, false); } if (array_key_exists('cred-edit-form', $_GET) && !is_admin()) { if (strpos($content, 'cred-edit-form=' . $_GET['cred-edit-form']) !== false) { array_push($_creds_created, $_GET['cred-edit-form']); // Show if the content has a cred-edit-form link. CRED_Loader::load('CLASS/Form_Builder'); // get a localised form if exists return CRED_Form_Builder::getForm(self::getLocalisedID(intval($_GET['cred-edit-form'])), $post->ID, false); } else { // Check if it's called from the_content function or wpv-post-body function. $db = debug_backtrace(); //StaticClass::_pre($db); foreach ($db as $n => $dbf) { if (isset($dbf['function']) && ($dbf['function'] == 'the_content' || $dbf['function'] == 'wpv_shortcode_wpv_post_body') || $dbf['function'] == 'apply_filters' && in_array('the_content', $dbf['args'])) { array_push($_creds_created, $_GET['cred-edit-form']); CRED_Loader::load('CLASS/Form_Builder'); return CRED_Form_Builder::getForm(self::getLocalisedID(intval($_GET['cred-edit-form'])), $post->ID, false); } } // if (isset($db[3]['function']) && ($db[3]['function'] == 'the_content' || $db[3]['function'] == 'wpv_shortcode_wpv_post_body')) { // CRED_Loader::load('CLASS/Form_Builder'); // return CRED_Form_Builder::getForm(self::getLocalisedID(intval($_GET['cred-edit-form'])), $post->ID, false); // } } } // else do nothing return $content; }