0

Wordpressを中心に構築されたアプリケーションがあります。それはかなりオーダーメイドですが、それでも私はWordpressに付属しているものの多くを活用して感謝しています。今私がやろうとしているのは、Wordpressデータベースで動作するRESTfulAPIを提供することです。私はこれまでのところ非常に満足しているRestlerというオープンソース製品を使用しており、PHPでこのサービスを非常に簡単に提供できますが、このPHPにWordpressマシンをロードして、ビルド済みのコードを活用できるようにしたいと思います。より簡単に、そして便利なWordpress機能。

Restlerを使用すると、インターフェースを定義するPHPクラスファイルができます。WP環境をロードするために、最初にインポートを追加しました。

<?php
include "AddWordpress.php"; // loads wordpress in AJAX mode

/**
 * All actions that the system will process through this service.
 *
 * @package lg-api
 * @return  json    LG_JSON_Activity    
*/
class Actions {
    /**
    * LIST action types
    *
    * List all the action-types available
    *
    * @url GET /
    */
    function list_actions() {
        $actions = new LG_TAX_Action();
        $action_list = $actions->dataset();
        return "\n" . json_encode($action_list) . "\n\n";
    }

}

ここで、AddWordpress.phpは(dev envのデバッグがオンに設定されています):

<?php
error_reporting(E_ALL);
$site_name='yoursite';
$site_domain='www.yoursite.com';

/**
* Construct a fake $_SERVER global to get WordPress to load a specific site.
* This avoids alot of messing about with switch_to_blog() and all its pitfalls.
*/
$_SERVER=array(
'HTTP_HOST'=>$site_domain,
'REQUEST_METHOD'=>'GET',
'REQUEST_URI'=>"/{$site_name}/",
'SERVER_NAME'=>$site_domain,
);

// Remove all our bespoke variables as they'll be in scope as globals and could affect WordPress
unset($site_name,$site_domain);

// Pretend that we're executing an AJAX process. This should help WordPress not load all of the things.
define('DOING_AJAX',true);

// Stop WordPress doing any of its normal output handling.
define('WP_USE_THEMES',false);

// turn on debugging
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);

// Load WordPress - intentionally using an absolute URL due to issues with relative paths on the CLI.
include "/[path-to-root-www]/wp-load.php";

このアプローチは、実際のコードにジャンプしてブラウザーでテストする前にコマンドラインテストファイルを作成するのに最適ですが、何らかの理由でRestlerで実行すると、次のようなエラーが多数発生します。

Notice:  is_404 was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.) in /[path-to-www-root]/wp-includes/functions.php on line 294
Notice:  is_home was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.) in /[path-to-www-root]/wp-includes/functions.php on line 2944
Notice:  is_search was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.) in /[path-to-www-root]/wp-includes/functions.php on line 2944
Notice:  is_archive was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.) in /[path-to-www-root]/wp-includes/functions.php on line 2944
Notice:  is_404 was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.) in /[path-to-www-root]/wp-includes/functions.php on line 2944
Notice:  is_tag was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.) in /[path-to-www-root]/wp-includes/functions.php on line 2944
Notice:  is_search was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.) in /[path-to-www-root]/wp-includes/functions.php on line 2944
Notice:  is_category was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.) in /[path-to-www-root]/wp-includes/functions.php on line 2944

クラスファイルの最後に次のコードを追加し、コマンドラインから実行すると、問題なく機能します。

 $foo = new Actions();
 echo $foo->list_actions();

なぜこれが起こっているのかについて誰かが何か指針を与えることができますか?

アップデート

エラー処理を変更して、スタックトレースを取得し、次のようにしました。

#0 /[path-to-www-root]/wp-includes/query.php(708): _doing_it_wrong('is_404', 'Conditional que...', '3.1')
#1 /[path-to-www-root]/wp-content/themes/pagelines/includes/library.functions.php(68): is_404()
#2 /[path-to-www-root]/wp-content/themes/pagelines/includes/library.options.php(43): is_pagelines_special(Array)
#3 /[path-to-www-root]/wp-content in /[path-to-www-root]/wp-includes/functions.php on line 2944

したがって、最初の呼び出しは、query.phpを呼び出す私のテーマからのようです。詳細情報ですが、これを解決する方法は、コマンドラインから実行する場合とすべての問題を追跡する場合でインポートの初期状態が異なる理由に取り組むことであると確信しているため、実際にどの程度の洞察が得られるかはわかりません。それが始まった悪い状態から発生します。

4

0 に答える 0