min117の日記

初期desireもち。趣味Mac,メインFedora,仕事xp。

WordPressに自作プラグインを追加する(オライリー本)※BGM「四月になれば彼女は」を聞きながら

ハピタス登録で1,000円分になるURL

その買うを、もっとハッピーに。|ハピタス

 

WordPressプラグインの自作

オライリー本はやっぱ良いね。「分かってるやつが分かってる前提で作る想定で書いてる」からムダな解説とか初心者向けの冗長なページが無い。

かなり古いけどソースコードも公開されてる。

www.prime-strategy.co.jp

単なるハウツーじゃなくてWordPressをアプリケーション開発に使おうという内容なのが(応用効いて)素晴らしい。

 

本のとおり作ってみた(ソースは末尾)。

$ vim WordPressインストールフォルダ/wp-content/plugins/wpwa-questions.php

プラグインの有効化

管理画面からプラグインに行ってみると…表示されている!地味に嬉しい。

有効化してみる。

 

コーディングのBGMはサイモン&ガーファンクル「四月になれば彼女は」。

www.youtube.com

検索してたらよくわからん映画がヒットした。何かの縁だし見るか。

4gatsu-movie.toho.co.jp

uncle.xn--eck2cqb1aq2ef0l2gi.com

 

<?php
/*
Plugin Name: WP Questions
Plugin URI: -
Description: Question and Answer interface for developers
Version: 1.0
Author: min117
Author URI: https://dummy.com
License: GPLv2 or later
*/

add_action('init', 'register_wp_questions');


function register_wp_questions() {
    $labels = array(
        'name'                   => __('Questions', 'wp_question'),
        'singular_name'          => __('Questions', 'wp_question'),
        'add_new'                => __('Add New', 'wp_question'),
        'add_new_item'           => __('Add New Question', 'wp_question'),
        'edit_item'              => __('Edit Question', 'wp_question'),
        'new_item'               => __('New Question', 'wp_question'),
        'view_item'              => __('View Question', 'wp_question'),
        'search_item'            => __('Search Question', 'wp_question'),
        'not_found_item'         => __('Not Questions found', 'wp_question'),
        'not_found_item_in_trash'=> __('Not Questions found in Trash', 'wp_question'),
        'parent_item_colon_item' => __('Parent Question:', 'wp_question'),
        'menu_name'              => __('Questions', 'wp_question'),
    );

    $args = array(
        'labels'              => $labels,
        'hierarchical'        => true,
        'description'         => __( 'Questions and Answers', 'wp_question' ),
        'supports'            => array( 'title', 'editor', 'comments' ),
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'publicly_queryable'  => true,
        'exclude_from_search' => true,
        'has_archive'         => true,
        'query_var'           => true,
        'can_export'          => true,
        'rewrite'             => true,
        'capability_type'     => true,
    );

    register_post_type( 'wp_question', $args );
}

?>