I have a php site and i need connection to my wordpress site (they are on the same server)
So i just include the config file to open a new connection like:
require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-config.php');
But i'm getting an error (seems like its running some other wp commands as well for some reason:
#0 /home/public_html/wp-includes/class-wp-hook.php(298): call_user_func_array()
#1 /home/public_html/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters()
#2 /home/public_html/wp-includes/plugin.php(453): WP_Hook->do_action()
#3 /home/public_html/wp-settings.php(448): do_action()
#4 /home/public_html/wp-config.php(87): require_once()
#5 /home/public_html/myphpsite/protected/modules/contacts/controllers/ContactsController.php(695): require_once()
What is happening here?
Any tips? Thanks!
EDIT: WP Config below
<?php
/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the
* installation. You don't have to use the web site, you can
* copy this file to "wp-config.php" and fill in the values.
*
* This file contains the following configurations:
*
* * MySQL settings
* * Secret keys
* * Database table prefix
* * ABSPATH
*
* @link https://codex.wordpress.org/Editing_wp-config.php
*
* @package WordPress
*/
// ** MySQL settings ** //
/** The name of the database for WordPress */
define('DB_NAME', 'db');
/** MySQL database username */
define('DB_USER','dba');
/** MySQL database password */
define('DB_PASSWORD','asd');
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );
/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
define('WP_DEBUG', false);
define('WP_DEBUG_LOG', false);
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors', 0);
/**
* Authentication Unique Keys and Salts.
*
* Change these to different unique phrases!
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
*
* @since 2.6.0
*/
define('AUTH_KEY', '4= 6|5taXSAxeaP/Zdd1(jkuLX(^X;E+L<^Jt^I!5t/]+ulnl?aF,7K*X9[/f_}w');
define('SECURE_AUTH_KEY', '*4vFa=[Lgf6Sva|w^9+3iFVx-0ATu>`>7*9PnT27Os{% 4G,*P(f<xHp|+I5A5u&');
define('LOGGED_IN_KEY', 'B+nC*4!Dn0`CNfXv`8 Y#T<c6%Rpc> 1lI62)4/%st~++_KmCiP]S=HY}nz{{]m|');
define('NONCE_KEY', '8~6fxOX5aF_O?aiv-[(uLwd_^zXvZIKy9q@ygA<VQ9yOcTkk6j*~:{?%wmf&8zT2');
define('AUTH_SALT', '3>YiOmi!-_vZM#3${^5x@hcrvKPD/u?Qu`tw>u)ty^)X}YzQ?%w!C4vV.=;+Ro[q');
define('SECURE_AUTH_SALT', 'Otaj|C=4$.%9jomO|`Z)[K/i:cK*vc^InQ|h]_c+e5%dSdrnnzz2+$|55[(AbmAS');
define('LOGGED_IN_SALT', '!FEtJ~4@dq|*`fXIrIF(zWLKbjI~5<E{h4mIyOm*(C&Q|J#/LVEXgnn|01Fy#=nW');
define('NONCE_SALT', 'D]b9]_|pK!,,,*L*E)4pJCi^E2<8o?2tJ-b~=,Cywqiss$Dg0oZU/[bn2dkx1 m-');
/**
* WordPress Database Table prefix.
*
* You can have multiple installations in one database if you give each
* a unique prefix. Only numbers, letters, and underscores please!
*/
$table_prefix = 'bbcrmFE_';
define('API_HOST','/api');
define('API_USER','api');
define('API_PASS','api');
/* That's all, stop editing! Happy blogging. */
/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) )
define( 'ABSPATH', dirname( __FILE__ ) . '/' );
/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';
答案 0 :(得分:1)
Try load the /wp-load.php
file, here the Wordpress load all thing that it needs to access the WP Features.
require_once($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php');
EDIT:
The your problema it's happen because on the end of the wp-config.php
file it's called a other file wp-settings.php
, and inside them, a lot of thing is loaded.
Maybe, you can create another file, something like this wp-constants.php
and put all your constants inside them. And in your wp-config.php
, you just include this file.
This way, you can share the constants bettenw your WP site and you another site.