本文整理汇总了PHP中wp_load_translations_early函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_load_translations_early函数的具体用法?PHP wp_load_translations_early怎么用?PHP wp_load_translations_early使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_load_translations_early函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wp_set_wpdb_vars
/**
* Set the database table prefix and the format specifiers for database
* table columns.
*
* Columns not listed here default to `%s`.
*
* @since 3.0.0
* @access private
*
* @global wpdb $wpdb The WordPress database class.
* @global string $table_prefix The database table prefix.
*/
function wp_set_wpdb_vars()
{
global $wpdb, $table_prefix;
if (!empty($wpdb->error)) {
dead_db();
}
$wpdb->field_types = array('post_author' => '%d', 'post_parent' => '%d', 'menu_order' => '%d', 'term_id' => '%d', 'term_group' => '%d', 'term_taxonomy_id' => '%d', 'parent' => '%d', 'count' => '%d', 'object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'comment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d', 'user_id' => '%d', 'link_id' => '%d', 'link_owner' => '%d', 'link_rating' => '%d', 'option_id' => '%d', 'blog_id' => '%d', 'meta_id' => '%d', 'post_id' => '%d', 'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d', 'active' => '%d', 'cat_id' => '%d', 'deleted' => '%d', 'lang_id' => '%d', 'mature' => '%d', 'public' => '%d', 'site_id' => '%d', 'spam' => '%d');
$prefix = $wpdb->set_prefix($table_prefix);
if (is_wp_error($prefix)) {
wp_load_translations_early();
wp_die(sprintf(__('<strong>ERROR</strong>: %1$s in %2$s can only contain numbers, letters, and underscores.'), '<code>$table_prefix</code>', '<code>wp-config.php</code>'));
}
}
示例2: db_connect
/**
* Connect to and select database.
*
* If $allow_bail is false, the lack of database connection will need
* to be handled manually.
*
* @since 3.0.0
* @since 3.9.0 $allow_bail parameter added.
*
* @param bool $allow_bail Optional. Allows the function to bail. Default true.
* @return bool True with a successful connection, false on failure.
*/
public function db_connect($allow_bail = true)
{
$this->is_mysql = true;
/*
* Deprecated in 3.9+ when using MySQLi. No equivalent
* $new_link parameter exists for mysqli_* functions.
*/
$new_link = defined('MYSQL_NEW_LINK') ? MYSQL_NEW_LINK : true;
$client_flags = defined('MYSQL_CLIENT_FLAGS') ? MYSQL_CLIENT_FLAGS : 0;
if ($this->use_mysqli) {
$this->dbh = mysqli_init();
// mysqli_real_connect doesn't support the host param including a port or socket
// like mysql_connect does. This duplicates how mysql_connect detects a port and/or socket file.
$port = null;
$socket = null;
$host = $this->dbhost;
$port_or_socket = strstr($host, ':');
if (!empty($port_or_socket)) {
$host = substr($host, 0, strpos($host, ':'));
$port_or_socket = substr($port_or_socket, 1);
if (0 !== strpos($port_or_socket, '/')) {
$port = intval($port_or_socket);
$maybe_socket = strstr($port_or_socket, ':');
if (!empty($maybe_socket)) {
$socket = substr($maybe_socket, 1);
}
} else {
$socket = $port_or_socket;
}
}
if (WP_DEBUG) {
mysqli_real_connect($this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags);
} else {
@mysqli_real_connect($this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags);
}
if ($this->dbh->connect_errno) {
$this->dbh = null;
/* It's possible ext/mysqli is misconfigured. Fall back to ext/mysql if:
* - We haven't previously connected, and
* - WP_USE_EXT_MYSQL isn't set to false, and
* - ext/mysql is loaded.
*/
$attempt_fallback = true;
if ($this->has_connected) {
$attempt_fallback = false;
} elseif (defined('WP_USE_EXT_MYSQL') && !WP_USE_EXT_MYSQL) {
$attempt_fallback = false;
} elseif (!function_exists('mysql_connect')) {
$attempt_fallback = false;
}
if ($attempt_fallback) {
$this->use_mysqli = false;
$this->db_connect();
}
}
} else {
if (WP_DEBUG) {
$this->dbh = mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags);
} else {
$this->dbh = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags);
}
}
if (!$this->dbh && $allow_bail) {
wp_load_translations_early();
// Load custom DB error template, if present.
if (file_exists(WP_CONTENT_DIR . '/db-error.php')) {
require_once WP_CONTENT_DIR . '/db-error.php';
die;
}
$this->bail(sprintf(__("\n<h1>Error establishing a database connection</h1>\n<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>%s</code>. This could mean your host's database server is down.</p>\n<ul>\n\t<li>Are you sure you have the correct username and password?</li>\n\t<li>Are you sure that you have typed the correct hostname?</li>\n\t<li>Are you sure that the database server is running?</li>\n</ul>\n<p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='https://wordpress.org/support/'>WordPress Support Forums</a>.</p>\n"), htmlspecialchars($this->dbhost, ENT_QUOTES)), 'db_connect_fail');
return false;
} elseif ($this->dbh) {
if (!$this->has_connected) {
$this->init_charset();
}
$this->has_connected = true;
$this->set_charset($this->dbh);
$this->ready = true;
$this->set_sql_mode();
$this->select($this->dbname, $this->dbh);
return true;
}
return false;
}
示例3: dead_db
/**
* Load custom DB error or display WordPress DB error.
*
* If a file exists in the wp-content directory named db-error.php, then it will
* be loaded instead of displaying the WordPress DB error. If it is not found,
* then the WordPress DB error will be displayed instead.
*
* The WordPress DB error sets the HTTP status header to 500 to try to prevent
* search engines from caching the message. Custom DB messages should do the
* same.
*
* This function was backported to WordPress 2.3.2, but originally was added
* in WordPress 2.5.0.
*
* @since 2.3.2
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
function dead_db()
{
global $wpdb;
wp_load_translations_early();
// Load custom DB error template, if present.
if (file_exists(WP_CONTENT_DIR . '/db-error.php')) {
require_once WP_CONTENT_DIR . '/db-error.php';
die;
}
// If installing or in the admin, provide the verbose message.
if (defined('WP_INSTALLING') || defined('WP_ADMIN')) {
wp_die($wpdb->error);
}
// Otherwise, be terse.
status_header(500);
nocache_headers();
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"<?php
if (is_rtl()) {
echo ' dir="rtl"';
}
?>
>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php
_e('Database Error');
?>
</title>
</head>
<body>
<h1><?php
_e('Error establishing a database connection');
?>
</h1>
</body>
</html>
<?php
die;
}
示例4: db_connect
/**
* Connect to and select database
*
* @since 3.0.0
*/
function db_connect()
{
$this->is_mysql = true;
$new_link = defined('MYSQL_NEW_LINK') ? MYSQL_NEW_LINK : true;
$client_flags = defined('MYSQL_CLIENT_FLAGS') ? MYSQL_CLIENT_FLAGS : 0;
if (WP_DEBUG) {
$this->dbh = mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags);
} else {
$this->dbh = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags);
}
if (!$this->dbh) {
wp_load_translations_early();
$this->bail(sprintf(__("\n<h1>Error establishing a database connection</h1>\n<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>%s</code>. This could mean your host's database server is down.</p>\n<ul>\n\t<li>Are you sure you have the correct username and password?</li>\n\t<li>Are you sure that you have typed the correct hostname?</li>\n\t<li>Are you sure that the database server is running?</li>\n</ul>\n<p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='http://wordpress.org/support/'>WordPress Support Forums</a>.</p>\n"), htmlspecialchars($this->dbhost, ENT_QUOTES)), 'db_connect_fail');
return;
}
$this->set_charset($this->dbh);
$this->ready = true;
$this->select($this->dbname, $this->dbh);
}
示例5: check_connection
/**
* Check that the connection to the database is still up. If not, try to reconnect.
*
* If this function is unable to reconnect, it will forcibly die, or if after the
* the template_redirect hook has been fired, return false instead.
*
* If $allow_bail is false, the lack of database connection will need
* to be handled manually.
*
* @since 3.9.0
*
* @param bool $allow_bail Optional. Allows the function to bail. Default true.
* @return bool|void True if the connection is up.
*/
public function check_connection($allow_bail = true)
{
if ($this->use_mysqli) {
if (@mysqli_ping($this->dbh)) {
return true;
}
} else {
if (@mysql_ping($this->dbh)) {
return true;
}
}
$error_reporting = false;
// Disable warnings, as we don't want to see a multitude of "unable to connect" messages
if (WP_DEBUG) {
$error_reporting = error_reporting();
error_reporting($error_reporting & ~E_WARNING);
}
for ($tries = 1; $tries <= $this->reconnect_retries; $tries++) {
// On the last try, re-enable warnings. We want to see a single instance of the
// "unable to connect" message on the bail() screen, if it appears.
if ($this->reconnect_retries === $tries && WP_DEBUG) {
error_reporting($error_reporting);
}
if ($this->db_connect(false)) {
if ($error_reporting) {
error_reporting($error_reporting);
}
return true;
}
sleep(1);
}
// If template_redirect has already happened, it's too late for wp_die()/dead_db().
// Let's just return and hope for the best.
if (did_action('template_redirect')) {
return false;
}
if (!$allow_bail) {
return false;
}
wp_load_translations_early();
$message = '<h1>' . __('Error reconnecting to the database') . "</h1>\n";
$message .= '<p>' . sprintf(__('This means that we lost contact with the database server at %s. This could mean your host’s database server is down.'), '<code>' . htmlspecialchars($this->dbhost, ENT_QUOTES) . '</code>') . "</p>\n";
$message .= "<ul>\n";
$message .= '<li>' . __('Are you sure that the database server is running?') . "</li>\n";
$message .= '<li>' . __('Are you sure that the database server is not under particularly heavy load?') . "</li>\n";
$message .= "</ul>\n";
$message .= '<p>' . sprintf(__('If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress Support Forums</a>.'), __('https://wordpress.org/support/')) . "</p>\n";
// We weren't able to reconnect, so we better bail.
$this->bail($message, 'db_connect_fail');
// Call dead_db() if bail didn't die, because this database is no more. It has ceased to be (at least temporarily).
dead_db();
}
示例6: ms_not_installed
/**
* Displays a failure message.
*
* Used when a blog's tables do not exist. Checks for a missing $wpdb->site table as well.
*
* @access private
* @since 3.0.0
*/
function ms_not_installed()
{
global $wpdb, $domain, $path;
wp_load_translations_early();
$title = __('Error establishing a database connection');
$msg = '<h1>' . $title . '</h1>';
if (!is_admin()) {
die($msg);
}
$msg .= '<p>' . __('If your site does not display, please contact the owner of this network.') . '';
$msg .= ' ' . __('If you are the owner of this network please check that MySQL is running properly and all tables are error free.') . '</p>';
if (false && !$wpdb->get_var("SHOW TABLES LIKE '{$wpdb->site}'")) {
$msg .= '<p>' . sprintf(__('<strong>Database tables are missing.</strong> This means that MySQL is not running, WordPress was not installed properly, or someone deleted <code>%s</code>. You really should look at your database now.'), $wpdb->site) . '</p>';
} else {
$msg .= '<p>' . sprintf(__('<strong>Could not find site <code>%1$s</code>.</strong> Searched for table <code>%2$s</code> in database <code>%3$s</code>. Is that right?'), rtrim($domain . $path, '/'), $wpdb->blogs, DB_NAME) . '</p>';
}
$msg .= '<p><strong>' . __('What do I do now?') . '</strong> ';
$msg .= __('Read the <a target="_blank" href="http://codex.wordpress.org/Debugging_a_WordPress_Network">bug report</a> page. Some of the guidelines there may help you figure out what went wrong.');
$msg .= ' ' . __('If you’re still stuck with this message, then check that your database contains the following tables:') . '</p><ul>';
foreach ($wpdb->tables('global') as $t => $table) {
if ('sitecategories' == $t) {
continue;
}
$msg .= '<li>' . $table . '</li>';
}
$msg .= '</ul>';
wp_die($msg, $title);
}
示例7: elseif
} elseif (@file_exists(dirname(ABSPATH) . '/wp-config.php') && !@file_exists(dirname(ABSPATH) . '/wp-settings.php')) {
/** The config file resides one level above ABSPATH but is not part of another install */
require_once dirname(ABSPATH) . '/wp-config.php';
} else {
// A config file doesn't exist
define('WPINC', 'wp-includes');
require_once ABSPATH . WPINC . '/load.php';
// Standardize $_SERVER variables across setups.
wp_fix_server_vars();
require_once ABSPATH . WPINC . '/functions.php';
$path = wp_guess_url() . '/wp-admin/setup-config.php';
/*
* We're going to redirect to setup-config.php. While this shouldn't result
* in an infinite loop, that's a silly thing to assume, don't you think? If
* we're traveling in circles, our last-ditch effort is "Need more help?"
*/
if (false === strpos($_SERVER['REQUEST_URI'], 'setup-config')) {
header('Location: ' . $path);
exit;
}
define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
require_once ABSPATH . WPINC . '/version.php';
wp_check_php_mysql_versions();
wp_load_translations_early();
// Die with an error message
$die = sprintf(__("There doesn't seem to be a %s file. I need this before we can get started."), '<code>wp-config.php</code>') . '</p>';
$die .= '<p>' . sprintf(__("Need more help? <a href='%s'>We got it</a>."), __('https://codex.wordpress.org/Editing_wp-config.php')) . '</p>';
$die .= '<p>' . sprintf(__("You can create a %s file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file."), '<code>wp-config.php</code>') . '</p>';
$die .= '<p><a href="' . $path . '" class="button button-large">' . __("Create a Configuration File") . '</a>';
wp_die($die, __('WordPress › Error'));
}
示例8: db_connect
/**
* Connect to and select database.
*
* If $allow_bail is false, the lack of database connection will need
* to be handled manually.
*
* @since 3.0.0
* @since 3.9.0 $allow_bail parameter added.
*
* @param bool $allow_bail Optional. Allows the function to bail. Default true.
* @return bool True with a successful connection, false on failure.
*/
public function db_connect($allow_bail = true)
{
$this->is_mysql = true;
/*
* Deprecated in 3.9+ when using MySQLi. No equivalent
* $new_link parameter exists for mysqli_* functions.
*/
$new_link = defined('MYSQL_NEW_LINK') ? MYSQL_NEW_LINK : true;
$client_flags = defined('MYSQL_CLIENT_FLAGS') ? MYSQL_CLIENT_FLAGS : 0;
$new_link = true;
ini_set('display_errors', 1);
if (WP_DEBUG) {
$this->dbh = sqlsrv_connect($this->dbhost, array("Database" => $this->dbname, "UID" => $this->dbuser, "PWD" => $this->dbpassword, 'ReturnDatesAsStrings' => true, 'MultipleActiveResultSets' => false));
} else {
$this->dbh = sqlsrv_connect($this->dbhost, array("Database" => $this->dbname, "UID" => $this->dbuser, "PWD" => $this->dbpassword, 'ReturnDatesAsStrings' => true, 'MultipleActiveResultSets' => false));
}
if (!$this->dbh && $allow_bail) {
wp_load_translations_early();
// Load custom DB error template, if present.
if (file_exists(WP_CONTENT_DIR . '/db-error.php')) {
require_once WP_CONTENT_DIR . '/db-error.php';
die;
}
$this->bail(sprintf(__("\n<h1>Error establishing a database connection</h1>\n<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>%s</code>. This could mean your host's database server is down.</p>\n<ul>\n\t<li>Are you sure you have the correct username and password?</li>\n\t<li>Are you sure that you have typed the correct hostname?</li>\n\t<li>Are you sure that the database server is running?</li>\n</ul>\n<p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='https://wordpress.org/support/'>WordPress Support Forums</a>.</p>\n"), htmlspecialchars($this->dbhost, ENT_QUOTES)), 'db_connect_fail');
return false;
} elseif ($this->dbh) {
if (!$this->has_connected) {
$this->init_charset();
}
$this->has_connected = true;
$this->set_charset($this->dbh);
$this->ready = true;
$this->set_sql_mode();
//$this->select( $this->dbname, $this->dbh );
return true;
}
return false;
}
示例9: ms_not_installed
/**
* Displays a failure message.
*
* Used when a blog's tables do not exist. Checks for a missing $wpdb->site table as well.
*
* @access private
* @since 3.0.0
* @since 4.4.0 The `$domain` and `$path` parameters were added.
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $domain The requested domain for the error to reference.
* @param string $path The requested path for the error to reference.
*/
function ms_not_installed($domain, $path)
{
global $wpdb;
if (!is_admin()) {
dead_db();
}
wp_load_translations_early();
$title = __('Error establishing a database connection');
$msg = '<h1>' . $title . '</h1>';
$msg .= '<p>' . __('If your site does not display, please contact the owner of this network.') . '';
$msg .= ' ' . __('If you are the owner of this network please check that MySQL is running properly and all tables are error free.') . '</p>';
$query = $wpdb->prepare("SHOW TABLES LIKE %s", $wpdb->esc_like($wpdb->site));
if (!$wpdb->get_var($query)) {
$msg .= '<p>' . sprintf(__('<strong>Database tables are missing.</strong> This means that MySQL is not running, WordPress was not installed properly, or someone deleted %s. You really should look at your database now.'), '<code>' . $wpdb->site . '</code>') . '</p>';
} else {
$msg .= '<p>' . sprintf(__('<strong>Could not find site %1$s.</strong> Searched for table %2$s in database %3$s. Is that right?'), '<code>' . rtrim($domain . $path, '/') . '</code>', '<code>' . $wpdb->blogs . '</code>', '<code>' . DB_NAME . '</code>') . '</p>';
}
$msg .= '<p><strong>' . __('What do I do now?') . '</strong> ';
/* translators: %s: Codex URL */
$msg .= sprintf(__('Read the <a href="%s" target="_blank">bug report</a> page. Some of the guidelines there may help you figure out what went wrong.'), __('https://codex.wordpress.org/Debugging_a_WordPress_Network'));
$msg .= ' ' . __('If you’re still stuck with this message, then check that your database contains the following tables:') . '</p><ul>';
foreach ($wpdb->tables('global') as $t => $table) {
if ('sitecategories' == $t) {
continue;
}
$msg .= '<li>' . $table . '</li>';
}
$msg .= '</ul>';
wp_die($msg, $title, array('response' => 500));
}
示例10: db_connect
/**
* Method to do the database connection.
*
* This overrides wpdb::db_connect() to avoid using MySQL function.
*
* @see wpdb::db_connect()
*/
public function db_connect($allow_bail = true)
{
if (WP_DEBUG) {
$this->dbh = new PDOEngine();
} else {
// WP_DEBUG or not, we don't use @ which causes the slow execution
// PDOEngine class will take the Exception handling.
$this->dbh = new PDOEngine();
}
if (!$this->dbh) {
wp_load_translations_early();
//probably there's no translations
$this->bail(sprintf(__("<h1>Error establlishing a database connection</h1><p>We have been unable to connect to the specified database. <br />The error message received was %s"), $this->dbh->errorInfo()));
return;
}
$this->has_connected = true;
$this->ready = true;
}
示例11: __construct
/**
* Constructor
*/
public function __construct()
{
date_default_timezone_set(AB_Utils::getTimezoneString());
wp_load_translations_early();
$now = new DateTime();
$this->mysql_now = $now->format('Y-m-d H:i:s');
$this->sms = new AB_SMS();
$this->sms_authorized = $this->sms->loadProfile();
$query = AB_Notification::query()->where('active', 1)->whereIn('type', array('staff_agenda', 'client_follow_up', 'client_reminder'));
foreach ($query->find() as $notification) {
$this->processNotification($notification);
}
}
示例12: db_connect
/**
* Connect to and select database
*
* @since 3.0.0
*/
function db_connect()
{
$this->is_mysql = true;
$conn_string = "host=" . $this->dbhost . " dbname=" . $this->dbname . " user=" . $this->dbuser . " password=" . $this->dbpassword . " port=2345";
$this->dbh = pg_connect($conn_string);
if (!$this->dbh) {
wp_load_translations_early();
$this->bail(sprintf(__($conn_string . "\r\n<h1>Error establishing a database connection</h1>\r\n<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>%s</code>. This could mean your host's database server is down.</p>\r\n<ul>\r\n\t<li>Are you sure you have the correct username and password?</li>\r\n\t<li>Are you sure that you have typed the correct hostname?</li>\r\n\t<li>Are you sure that the database server is running?</li>\r\n</ul>\r\n<p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='http://.org/support/'> Support Forums</a>.</p>\r\n"), htmlspecialchars($this->dbhost, ENT_QUOTES)), 'db_connect_fail');
return;
}
$this->set_charset($this->dbh);
$this->ready = true;
$this->select($this->dbname, $this->dbh);
}
示例13: get_weekdays
private function get_weekdays()
{
$out = '<div class="tm-weekdays-picker-wrap">';
// load wp translations
if (function_exists('wp_load_translations_early')) {
wp_load_translations_early();
global $wp_locale;
for ($day_index = 0; $day_index <= 6; $day_index++) {
$out .= '<span class="tm-weekdays-picker"><label><input class="tm-weekday-picker" type="checkbox" value="' . esc_attr($day_index) . '"><span>' . $wp_locale->get_weekday($day_index) . '</span></label></span>';
}
// in case something goes wrong
} else {
$weekday[0] = __('Sunday');
$weekday[1] = __('Monday');
$weekday[2] = __('Tuesday');
$weekday[3] = __('Wednesday');
$weekday[4] = __('Thursday');
$weekday[5] = __('Friday');
$weekday[6] = __('Saturday');
for ($day_index = 0; $day_index <= 6; $day_index++) {
$out .= '<span class="tm-weekdays-picker"><label><input type="checkbox" value="' . esc_attr($day_index) . '"><span>' . $weekday[$day_index] . '</span></label></span>';
}
}
$out .= '</div>';
return $out;
}
示例14: db_connect
/**
* Connect to and select database.
*
* If $allow_bail is false, the lack of database connection will need
* to be handled manually.
*
* @since 3.0.0
* @since 3.9.0 $allow_bail parameter added.
*
* @param bool $allow_bail Optional. Allows the function to bail. Default true.
* @return bool True with a successful connection, false on failure.
*/
public function db_connect($allow_bail = true)
{
$this->is_mysql = true;
/*
* Deprecated in 3.9+ when using MySQLi. No equivalent
* $new_link parameter exists for mysqli_* functions.
*/
$new_link = defined('MYSQL_NEW_LINK') ? MYSQL_NEW_LINK : true;
$client_flags = defined('MYSQL_CLIENT_FLAGS') ? MYSQL_CLIENT_FLAGS : 0;
if ($this->use_mysqli) {
$this->dbh = mysqli_init();
// mysqli_real_connect doesn't support the host param including a port or socket
// like mysql_connect does. This duplicates how mysql_connect detects a port and/or socket file.
$port = null;
$socket = null;
$host = $this->dbhost;
$port_or_socket = strstr($host, ':');
if (!empty($port_or_socket)) {
$host = substr($host, 0, strpos($host, ':'));
$port_or_socket = substr($port_or_socket, 1);
if (0 !== strpos($port_or_socket, '/')) {
$port = intval($port_or_socket);
$maybe_socket = strstr($port_or_socket, ':');
if (!empty($maybe_socket)) {
$socket = substr($maybe_socket, 1);
}
} else {
$socket = $port_or_socket;
}
}
// Set SSL certs if we want to use secure DB connections
if ($client_flags & MYSQLI_CLIENT_SSL) {
$ssl_key = defined('MYSQL_SSL_KEY') && is_file(MYSQL_SSL_KEY) ? MYSQL_SSL_KEY : null;
$ssl_cert = defined('MYSQL_SSL_CERT') && is_file(MYSQL_SSL_CERT) ? MYSQL_SSL_CERT : null;
$ssl_ca = defined('MYSQL_SSL_CA') && is_file(MYSQL_SSL_CA) ? MYSQL_SSL_CA : null;
$ssl_capath = defined('MYSQL_SSL_CA_PATH') && is_dir(MYSQL_SSL_CA_PATH) ? MYSQL_SSL_CA_PATH : null;
$ssl_cipher = defined('MYSQL_SSL_CIPHER') ? MYSQL_SSL_CIPHER : null;
mysqli_ssl_set($this->dbh, $ssl_key, $ssl_cert, $ssl_ca, $ssl_capath, $ssl_cipher);
}
mysqli_real_connect($this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags);
if ($this->dbh->connect_errno) {
$this->dbh = null;
/* It's possible ext/mysqli is misconfigured. Fall back to ext/mysql if:
* - We haven't previously connected, and
* - WP_USE_EXT_MYSQL isn't set to false, and
* - ext/mysql is loaded.
*/
$attempt_fallback = true;
if ($this->has_connected) {
$attempt_fallback = false;
} elseif (defined('WP_USE_EXT_MYSQL') && !WP_USE_EXT_MYSQL) {
$attempt_fallback = false;
} elseif (!function_exists('mysql_connect')) {
$attempt_fallback = false;
}
if ($attempt_fallback) {
$this->use_mysqli = false;
return $this->db_connect($allow_bail);
}
}
} else {
$this->dbh = mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags);
}
if (!$this->dbh && $allow_bail) {
wp_load_translations_early();
// Load custom DB error template, if present.
if (file_exists(WP_CONTENT_DIR . '/db-error.php')) {
require_once WP_CONTENT_DIR . '/db-error.php';
die;
}
$message = '<h1>' . __('Error establishing a database connection') . "</h1>\n";
$message .= '<p>' . sprintf(__('This either means that the username and password information in your %1$s file is incorrect or we can’t contact the database server at %2$s. This could mean your host’s database server is down.'), '<code>wp-config.php</code>', '<code>' . htmlspecialchars($this->dbhost, ENT_QUOTES) . '</code>') . "</p>\n";
$message .= "<ul>\n";
$message .= '<li>' . __('Are you sure you have the correct username and password?') . "</li>\n";
$message .= '<li>' . __('Are you sure that you have typed the correct hostname?') . "</li>\n";
$message .= '<li>' . __('Are you sure that the database server is running?') . "</li>\n";
$message .= "</ul>\n";
$message .= '<p>' . sprintf(__('If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress Support Forums</a>.'), __('https://wordpress.org/support/')) . "</p>\n";
$this->bail($message, 'db_connect_fail');
return false;
} elseif ($this->dbh) {
if (!$this->has_connected) {
$this->init_charset();
}
$this->has_connected = true;
$this->set_charset($this->dbh);
$this->ready = true;
$this->set_sql_mode();
//.........这里部分代码省略.........
示例15: oik_batch_load_wordpress_files
/**
* Batch WordPress without database
*
* Load the required WordPress include files for the task in hand.
* These files are a subset of the full set of WordPress includes.
* We may also need the oik-bwtrace plugin if there are any bw_trace2() calls temporarily inserted into the WordPress files for debugging purposes.
*
* This is not needed in oik-wp.php
*/
function oik_batch_load_wordpress_files()
{
// Load the L10n library.
require_once ABSPATH . WPINC . '/l10n.php';
// for get_translations_for_domain()
require_once ABSPATH . WPINC . "/formatting.php";
require_once ABSPATH . WPINC . "/plugin.php";
//require_once( ABSPATH . WPINC . "/option.php" );
require_once ABSPATH . WPINC . "/functions.php";
require_once ABSPATH . WPINC . '/class-wp-error.php';
require_once ABSPATH . WPINC . "/load.php";
// Not sure if we need to load cache.php ourselves
// require_once( ABSPATH . WPINC . "/cache.php" );
require_once ABSPATH . WPINC . "/version.php";
require_once ABSPATH . WPINC . "/post.php";
// for add_post_type_support()
wp_load_translations_early();
}