/** * Attempts to detect a WordPress installation and bootstraps the environment with it * * @return bool Whether it is a WP install and we have database credentials */ public function is_wordpress() { $path_mod = ''; $depth = 0; $max_depth = 4; $bootstrap_file = 'wp-blog-header.php'; while (!file_exists(dirname(__FILE__) . "{$path_mod}/{$bootstrap_file}")) { $path_mod .= '/..'; if ($depth++ >= $max_depth) { break; } } if (file_exists(dirname(__FILE__) . "{$path_mod}/{$bootstrap_file}")) { // store WP path $this->path = dirname(__FILE__) . $path_mod; // just in case we're white screening try { // need to make as many of the globals available as possible or things can break // (globals suck) global $wp, $wpdb, $wp_query, $wp_the_query, $wp_version, $wp_db_version, $tinymce_version, $manifest_version, $required_php_version, $required_mysql_version, $post, $posts, $wp_locale, $authordata, $more, $numpages, $currentday, $currentmonth, $page, $pages, $multipage, $wp_rewrite, $wp_filesystem, $blog_id, $request, $wp_styles, $wp_taxonomies, $wp_post_types, $wp_filter, $wp_object_cache, $query_string, $single, $post_type, $is_iphone, $is_chrome, $is_safari, $is_NS4, $is_opera, $is_macIE, $is_winIE, $is_gecko, $is_lynx, $is_IE, $is_apache, $is_iis7, $is_IIS; // prevent multisite redirect define('WP_INSTALLING', true); // prevent super/total cache define('DONOTCACHEDB', true); define('DONOTCACHEPAGE', true); define('DONOTCACHEOBJECT', true); define('DONOTCDN', true); define('DONOTMINIFY', true); // cancel batcache if (function_exists('batcache_cancel')) { batcache_cancel(); } // bootstrap WordPress require dirname(__FILE__) . "{$path_mod}/{$bootstrap_file}"; $this->set('path', ABSPATH); $this->set('is_wordpress', true); return true; } catch (Exception $error) { // try and get database values using regex approach $db_details = $this->define_find($this->path . '/wp-config.php'); if ($db_details) { define('DB_NAME', $db_details['name']); define('DB_USER', $db_details['user']); define('DB_PASSWORD', $db_details['pass']); define('DB_HOST', $db_details['host']); define('DB_CHARSET', $db_details['char']); define('DB_COLLATE', $db_details['coll']); // additional error message $this->add_error('WordPress detected but could not bootstrap environment. There might be a PHP error, possibly caused by changes to the database', 'db'); } if ($db_details) { return true; } } } return false; }
/** * Load the JSON API */ function rest_oauth1_loaded() { if (empty($GLOBALS['wp']->query_vars['rest_oauth1'])) { return; } // Do not cache Authentication endpoints // TODO: This needs a better approach if (function_exists('batcache_cancel')) { batcache_cancel(); } $authenticator = new WP_REST_OAuth1(); $response = $authenticator->dispatch($GLOBALS['wp']->query_vars['rest_oauth1']); if (is_wp_error($response)) { $error_data = $response->get_error_data(); if (is_array($error_data) && isset($error_data['status'])) { $status = $error_data['status']; } else { $status = 500; } status_header($status); echo $response->get_error_message(); die; } header('Content-Type: application/x-www-form-urlencoded; charset=utf-8'); $response = http_build_query($response, '', '&'); echo $response; // Finish off our request die; }