Posts tagged ‘wordpress’

CodeIgniterからWordprssを呼び出した際に苦労したから、FuelPHPからはどうだろうと思いやってみた。
とりあえずということでまずは投稿された記事が呼び出せるか?(ってか、まだこれしかしてない)
まずは、フォルダの構成。あまり深く考えず、ドキュメントルートにwordpressを置いてみた。

ドキュメントルートの名前はwpplus(適当)

wp_1

 

この状態でwordpressのインストールを実行。

 

次に、 /fuel/app/bootstrap.php の編集を行う。
ポイントは3行目の「 require ‘../wordpress/wp-load.php’; 」の部分。
10行目の「require COREPATH.’classes’.DIRECTORY_SEPARATOR.’autoloader.php’; 」の部分より、
前に呼び出す必要がある。

<?php

require '../wordpress/wp-load.php';

// Load in the Autoloader
require COREPATH.'classes'.DIRECTORY_SEPARATOR.'autoloader.php';
class_alias('Fuel\\Core\\Autoloader', 'Autoloader');

// Bootstrap the framework DO NOT edit this
require COREPATH.'bootstrap.php';
Autoloader::add_classes(array(
// Add classes you want to override here
// Example: 'View' => APPPATH.'classes/view.php',
));

// Register the autoloader
Autoloader::register();

/**
* Your environment. Can be set to any of the following:
*
* Fuel::DEVELOPMENT
* Fuel::TEST
* Fuel::STAGING
* Fuel::PRODUCTION
*/
Fuel::$env = (isset($_SERVER['FUEL_ENV']) ? $_SERVER['FUEL_ENV'] : Fuel::DEVELOPMENT);

// Initialize the framework with the config file.
Fuel::init('config.php');

次に、Controllerの作成。
ポイントは9行目の「 require_once ‘../wordpress/wp-blog-header.php’; 」の部分。
後はWordpressの関数を呼び出すことで記事の一覧を取得出来る。


というわけで、非常に簡単でした。

wordpressのコメント欄は名前とEメールアドレスが必須となっていますが、
これを名前のみ必須にする方法です。

 

1.Eメールの入力チェックを変更する。

Eメールの入力チェックを実施しないように変更します。
「wp-comments-post.php」 を編集します。

77行目あたりの以下のコードをコメントアウトします。

if ( get_option('require_name_email') && !$user->exists() ) {
if ( 6 > strlen($comment_author_email) || '' == $comment_author )
wp_die( __('ERROR: please fill the required fields (name, email).') );
elseif ( !is_email($comment_author_email))
wp_die( __('ERROR: please enter a valid email address.') );
}

更に以下のコードを入力します。

if(!$user->ID){
if ('' == $comment_author)
wp_die('名前を入力して下さい。');
}

2.Eメールアドレス入力欄を削除する

Eメールアドレス入力欄を削除するには、wp-includes配下の「comment-template.php」を編集します。

1523行目あたりのコードを以下のように編集します。

■編集前

$fields = array(
'author' => '

' . ' ' . '

', 'email' => '', 'url' => '

' . '

', );

■編集後

$fields = array(
'author' => '

' . ' ' . '

', 'url' => '

' . '

' );

3.不要なメッセージを非表示にする

上記の編集を実施しても、「メールアドレスが公開されることはありません」という表記が残っていますので、

以下のように編集することで非表示になります。 wp-includes配下の「comment-template.php」を編集します。

1530行目あたり

$defaults = array(
'fields' => apply_filters( 'comment_form_default_fields', $fields ),
'comment_field' => '

', 'must_log_in' => '', 'logged_in_as' => '

' . sprintf( __( 'Logged in as %2$s. Log out?' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '

', //コメントアウト 'comment_notes_before' => '

' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '

', 'comment_notes_after' => '

' . sprintf( __( 'You may use these HTML tags and attributes: %s' ), ' ' . allowed_tags() . '' ) . '

', 'id_form' => 'commentform', 'id_submit' => 'submit', 'title_reply' => __( 'Leave a Reply' ), 'title_reply_to' => __( 'Leave a Reply to %s' ), 'cancel_reply_link' => __( 'Cancel reply' ), 'label_submit' => __( 'Post Comment' ), );

上記の3つの作業で実現することができます。

編集結果は以下の通りです。

20130221