| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin name: Smart Custom Fields |
| 4 |
* Plugin URI: https://github.com/inc2734/smart-custom-fields/ |
| 5 |
* Description: Smart Custom Fields is a simple plugin that management custom fields. |
| 6 |
* Version: 1.2.1 |
| 7 |
* Author: Takashi Kitajima |
| 8 |
* Author URI: http://2inc.org |
| 9 |
* Created: October 9, 2014 |
| 10 |
* Modified: March 12, 2015 |
| 11 |
* Text Domain: smart-custom-fields |
| 12 |
* Domain Path: /languages |
| 13 |
* License: GPLv2 |
| 14 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html |
| 15 |
*/ |
| 16 |
class Smart_Custom_Fields { |
| 17 |
|
| 18 |
/** |
| 19 |
* __construct |
| 20 |
*/ |
| 21 |
public function __construct() { |
| 22 |
require_once plugin_dir_path( __FILE__ ) . 'classes/class.config.php'; |
| 23 |
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) ); |
| 24 |
register_uninstall_hook( __FILE__, array( __CLASS__, 'uninstall' ) ); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* 各クラス・翻訳ファイルの読み込み |
| 29 |
*/ |
| 30 |
public function plugins_loaded() { |
| 31 |
load_plugin_textdomain ( |
| 32 |
'smart-custom-fields', |
| 33 |
false, |
| 34 |
dirname( plugin_basename( __FILE__ ) ) . '/languages' |
| 35 |
); |
| 36 |
|
| 37 |
do_action( SCF_Config::PREFIX . 'load' ); |
| 38 |
require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.setting.php'; |
| 39 |
require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.group.php'; |
| 40 |
require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.abstract-field-base.php'; |
| 41 |
require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.revisions.php'; |
| 42 |
require_once plugin_dir_path( __FILE__ ) . 'classes/class.scf.php'; |
| 43 |
new Smart_Custom_Fields_Revisions(); |
| 44 |
|
| 45 |
foreach ( glob( plugin_dir_path( __FILE__ ) . 'classes/fields/*.php' ) as $form_item ) { |
| 46 |
include_once $form_item; |
| 47 |
$basename = basename( $form_item, '.php' ); |
| 48 |
$classname = preg_replace( '/^class\.field\-(.+)$/', 'Smart_Custom_Fields_Field_$1', $basename ); |
| 49 |
if ( class_exists( $classname ) ) { |
| 50 |
new $classname(); |
| 51 |
} |
| 52 |
} |
| 53 |
do_action( SCF_Config::PREFIX . 'fields-loaded' ); |
| 54 |
|
| 55 |
add_action( 'init' , array( $this, 'register_post_type' ) ); |
| 56 |
add_action( 'admin_menu' , array( $this, 'admin_menu' ) ); |
| 57 |
add_action( 'current_screen', array( $this, 'current_screen' ) ); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* アンインストール時の処理 |
| 62 |
*/ |
| 63 |
public static function uninstall() { |
| 64 |
$cf_posts = get_posts( array( |
| 65 |
'post_type' => SCF_Config::NAME, |
| 66 |
'posts_per_page' => -1, |
| 67 |
'post_status' => 'any', |
| 68 |
) ); |
| 69 |
foreach ( $cf_posts as $post ) { |
| 70 |
wp_delete_post( $post->ID, true ); |
| 71 |
} |
| 72 |
delete_post_meta_by_key( SCF_Config::PREFIX . 'repeat-multiple-data' ); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* 各管理画面の実行 |
| 77 |
* |
| 78 |
* @param WP_Screen $screen |
| 79 |
*/ |
| 80 |
public function current_screen( $screen ) { |
| 81 |
// 一覧画面 |
| 82 |
if ( $screen->id === 'edit-' . SCF_Config::NAME ) { |
| 83 |
} |
| 84 |
// 新規作成・編集画面 |
| 85 |
elseif ( $screen->id === SCF_Config::NAME ) { |
| 86 |
require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.settings.php'; |
| 87 |
new Smart_Custom_Fields_Controller_Settings(); |
| 88 |
} |
| 89 |
// その他の新規作成・編集画面 |
| 90 |
elseif ( SCF::get_settings( $screen->id, false ) ) { |
| 91 |
require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.editor.php'; |
| 92 |
new Smart_Custom_Fields_Controller_Editor(); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* カスタム投稿タイプの登録。メニュー表示は別メソッドで実行 |
| 98 |
*/ |
| 99 |
public function register_post_type() { |
| 100 |
$labels = array( |
| 101 |
'name' => __( 'Smart Custom Fields', 'smart-custom-fields' ), |
| 102 |
'menu_name' => __( 'Smart Custom Fields', 'smart-custom-fields' ), |
| 103 |
'name_admin_bar' => __( 'Smart Custom Fields', 'smart-custom-fields' ), |
| 104 |
'add_new' => __( 'Add New', 'smart-custom-fields' ), |
| 105 |
'add_new_item' => __( 'Add New', 'smart-custom-fields' ), |
| 106 |
'new_item' => __( 'New Field', 'smart-custom-fields' ), |
| 107 |
'edit_item' => __( 'Edit Field', 'smart-custom-fields' ), |
| 108 |
'view_item' => __( 'View Field', 'smart-custom-fields' ), |
| 109 |
'all_items' => __( 'All Fields', 'smart-custom-fields' ), |
| 110 |
'search_items' => __( 'Search Fields', 'smart-custom-fields' ), |
| 111 |
'parent_item_colon' => __( 'Parent Fields:', 'smart-custom-fields' ), |
| 112 |
'not_found' => __( 'No Fields found.', 'smart-custom-fields' ), |
| 113 |
'not_found_in_trash' => __( 'No Fields found in Trash.', 'smart-custom-fields' ) |
| 114 |
); |
| 115 |
register_post_type( |
| 116 |
SCF_Config::NAME, |
| 117 |
array( |
| 118 |
'label' => 'Smart Custom Fields', |
| 119 |
'labels' => $labels, |
| 120 |
'public' => false, |
| 121 |
'show_ui' => true, |
| 122 |
'capability_type' => 'page', |
| 123 |
'supports' => array( 'title', 'page-attributes' ), |
| 124 |
'show_in_menu' => false, |
| 125 |
) |
| 126 |
); |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* 管理画面にメニューを追加 |
| 131 |
*/ |
| 132 |
public function admin_menu() { |
| 133 |
add_menu_page( |
| 134 |
'Smart Custom Fields', |
| 135 |
'Smart Custom Fields', |
| 136 |
'manage_options', |
| 137 |
'edit.php?post_type=' . SCF_Config::NAME, |
| 138 |
false, |
| 139 |
false, |
| 140 |
'80.026' |
| 141 |
); |
| 142 |
add_submenu_page( |
| 143 |
'edit.php?post_type=' . SCF_Config::NAME, |
| 144 |
__( 'Add New', 'smart-custom-fields' ), |
| 145 |
__( 'Add New', 'smart-custom-fields' ), |
| 146 |
'manage_options', |
| 147 |
'post-new.php?post_type=' . SCF_Config::NAME |
| 148 |
); |
| 149 |
} |
| 150 |
} |
| 151 |
new Smart_Custom_Fields(); |
| 152 |
|