/** * Add new project * * @param string $project_name Default is sitename. * @param string $project_url Default is wordpress blog url. * @param string $project_webhook not implemented yet. * @access public * @since 1.0.0.0 * @return array $project_information */ public static function add_project($project_name = "", $project_url = "", $project_webhook = "") { if (Bugherd_Client::$_is_authenticated) { if (empty($project_name)) { $project_name = get_bloginfo("sitename"); } if (empty($project_url)) { $project_url = get_bloginfo("wpurl"); } $xml = sprintf('<?xml version="1.0" encoding="UTF-8"?> <project> <name>%s</name> <devurl>%s</devurl> <webhook>%s</webhook> </project>', $project_name, $project_url, $project_webhook); $project_detail = Bugherd_Client::api('projects', 'POST', $xml); return $project_detail; } }
/** * Ajax functionality * * @access public * @since 1.0.0.0 */ public static function ajax() { global $wp_version; if (!defined("DOING_AJAX")) { return false; } check_ajax_referer('save-bugherd', '_wpnonce_bugherd'); $json_result = array(); $task = $_REQUEST['task']; if ($task == "check_login") { $login = Bugherd_Client::login($_POST['username'], $_POST['password']); //if user is successfully logged in attach project information to the response if (!is_wp_error($login)) { $json_result['success'] = true; $json_result['data'] = Bugherd_Client::get_projects(); } else { $json_result['success'] = false; $json_result['data'] = $login; } } elseif ($task == "add_new_project") { //if(false === ($json_result = get_transient('project_add'))) //set_transient('project_add', $json_result); $login = Bugherd_Client::login($_POST['username'], $_POST['password']); if (!is_wp_error($login)) { $project_information = Bugherd_Client::add_project(stripslashes($_POST['bugherd_new_project'])); $json_result['success'] = true; $json_result['data'] = $project_information; } else { $json_result['success'] = false; $json_result['data'] = $login; } } elseif ($task == "save_settings") { $existing_settings = get_option('bugherd_options', array()); if (version_compare($wp_version, '3.0', '>=')) { if (empty($existing_settings) && is_multisite()) { $existing_settings = get_site_option('bugherd_options', array()); } } $data = stripslashes_deep($_POST['options']); //In case of multisite if user has not selected any site, then checkbox do not appear in form, which cause trouble with wp_parse_args below, so make sure to provide some value if (!array_key_exists("sites", $data)) { $data['sites'] = array(); } //Preserve existing settings (if posted information missing some (like integration code) $data = wp_parse_args($data, $existing_settings); update_option('bugherd_options', $data); //copy across multisites if (version_compare($wp_version, '3.0', '>=')) { if (is_multisite() && is_main_site() && current_user_can('manage_sites')) { update_site_option('bugherd_options', $data); } } //$bugherd_options = get_option('bugherd_options',array()); $json_result['success'] = true; $json_result['data'] = __(sprintf('Successfully updated BugHerd settings. <a href="%1$s" target="_blank">click here to preview</a>', get_bloginfo('wpurl')), 'wp-bugherd'); } //Response header('Content-type: application/json'); echo json_encode($json_result); exit; }