/** * Validates options being saved for Vanilla Forums. WordPress is a bit hinky * here, so we use hidden inputs to identify the forum being saved and validate * the inputs accordingly. This is a catch-all validation for all forms. */ function vf_validate_options($options) { $formname = vf_get_value('form-name', $options); $alloptions = get_option(VF_OPTIONS_NAME); if (!is_array($alloptions)) { $alloptions = array(); } switch ($formname) { case 'url-form': $url = vf_get_value('url', $options, ''); $options = $alloptions; $options['url'] = $url; if (vf_get_value('embed-code', $options, '') == '') { // Set the embed_code if it is not already defined. $embedurl = vf_combine_paths(array($url, 'js/embed.js'), '/'); $options['embed-code'] = '<script type="text/javascript" src="' . $embedurl . '"></script>'; } vf_configure_embed_container(); break; case 'embed-form': $embed_code = vf_get_value('embed-code', $options, ''); $embed_widgets = vf_get_value('embed-widgets', $options, '0'); $options = $alloptions; $url = vf_get_value('url', $options, ''); if ($embed_code == '') { // Set the embed_code if it is not already defined. $embedurl = vf_combine_paths(array($url, 'js/embed.js'), '/'); $options['embed-code'] = '<script type="text/javascript" src="' . $embedurl . '"></script>'; } else { $options['embed-code'] = $embed_code; } $options['embed-widgets'] = $embed_widgets; break; case 'embed-comments-form': $embed_comments = vf_get_value('embed-comments', $options, '0'); $embed_categoryid = vf_get_value('embed-categoryid', $options, '0'); $matchCategories = vf_get_value('embed-matchcategories', $options, '0'); $options = $alloptions; $options['embed-comments'] = $embed_comments; $options['embed-categoryid'] = $embed_categoryid; $options['embed-matchcategories'] = $matchCategories; break; default: $options = array_merge($alloptions, $options); break; } return $options; }
/** * Handle saving the permalink via ajax. */ function vf_embed_edit_slug() { $post_id = vf_configure_embed_container(); check_ajax_referer('samplepermalink', 'samplepermalinknonce'); $slug = isset($_POST['new_slug']) ? $_POST['new_slug'] : null; wp_update_post(array('ID' => $post_id, 'post_name' => $slug)); die(get_sample_permalink_html($post_id, 'Discussion Forum', $slug)); }
/** * Validates options being saved for Vanilla Forums. WordPress is a bit hinky * here, so we use hidden inputs to identify the forum being saved and validate * the inputs accordingly. This is a catch-all validation for all forms. */ function vf_validate_options($options) { $formname = vf_get_value('form-name', $options); $alloptions = get_option(VF_OPTIONS_NAME); if (!is_array($alloptions)) { $alloptions = array(); } switch ($formname) { case 'url-form': $url = vf_get_value('url', $options, ''); $options = $alloptions; // Make a rest request to Vanilla's API to validate that the forum is at the given location. $resturl = vf_combine_paths(array($url, '?p=discussions.json'), '/'); $data = json_decode(vf_rest($resturl)); if (!is_object($data)) { $options['url'] = ''; add_settings_error('url', 'url', 'Forum url could not be validated. Are you sure you entered the correct web address of your forum?'); } else { $options['url'] = $url; if (vf_get_value('embed-code', $options, '') == '') { // Set the embed_code if it is not already defined. $embedurl = vf_combine_paths(array($url, 'plugins/embedvanilla/remote.js'), '/'); $options['embed-code'] = '<script type="text/javascript" src="' . $embedurl . '"></script>'; } vf_configure_embed_container(); } break; case 'embed-form': $embed_code = vf_get_value('embed-code', $options, ''); $options = $alloptions; $url = vf_get_value('url', $options, ''); if ($embed_code == '') { // Set the embed_code if it is not already defined. $embedurl = vf_combine_paths(array($url, 'plugins/embedvanilla/remote.js'), '/'); $options['embed-code'] = '<script type="text/javascript" src="' . $embedurl . '"></script>'; } else { $options['embed-code'] = $embed_code; } break; default: $options = array_merge($alloptions, $options); break; } return $options; }