PluginProbe
Smart Custom Fields / 1.6.5
Smart Custom Fields v1.6.5
1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.7.0 2.0.0 2.0.1 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 All 68 releases
smart-custom-fields / smart-custom-fields.php

smart-custom-fields.php in Smart Custom Fields 1.6.5, at smart-custom-fields.php

265 lines 8.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.6.5
7 * Author: inc2734
8 * Author URI: http://2inc.org
9 * Created: October 9, 2014
10 * Modified: January 5, 2016
11 * Text Domain: smart-custom-fields
12 * Domain Path: /languages
13 * License: GPLv2 or later
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 * Loading translation files
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 add_action( 'after_setup_theme', array( $this, 'after_setup_theme' ) );
38 }
39
40 /**
41 * Loading classes
42 */
43 public function after_setup_theme() {
44 do_action( SCF_Config::PREFIX . 'load' );
45 require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.meta.php';
46 require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.setting.php';
47 require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.group.php';
48 require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.abstract-field-base.php';
49 require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.revisions.php';
50 require_once plugin_dir_path( __FILE__ ) . 'classes/models/class.ajax.php';
51 require_once plugin_dir_path( __FILE__ ) . 'classes/class.scf.php';
52 new Smart_Custom_Fields_Revisions();
53
54 foreach ( glob( plugin_dir_path( __FILE__ ) . 'classes/fields/*.php' ) as $form_item ) {
55 include_once $form_item;
56 $basename = basename( $form_item, '.php' );
57 $classname = preg_replace( '/^class\.field\-(.+)$/', 'Smart_Custom_Fields_Field_$1', $basename );
58 if ( class_exists( $classname ) ) {
59 new $classname();
60 }
61 }
62 do_action( SCF_Config::PREFIX . 'fields-loaded' );
63
64 add_action( 'init' , array( $this, 'register_post_type' ) );
65 add_action( 'init' , array( $this, 'ajax_request' ) );
66 add_action( 'admin_menu' , array( $this, 'admin_menu' ) );
67 add_action( 'current_screen', array( $this, 'current_screen' ) );
68 }
69
70 /**
71 * Uninstall proccesses
72 */
73 public static function uninstall() {
74 $cf_posts = get_posts( array(
75 'post_type' => SCF_Config::NAME,
76 'posts_per_page' => -1,
77 'post_status' => 'any',
78 ) );
79 foreach ( $cf_posts as $post ) {
80 wp_delete_post( $post->ID, true );
81 }
82 delete_post_meta_by_key( SCF_Config::PREFIX . 'repeat-multiple-data' );
83
84 // option の smart-cf-xxx を削除
85 global $wpdb;
86 $wpdb->query(
87 $wpdb->prepare(
88 "
89 DELETE FROM $wpdb->options
90 WHERE option_name LIKE %s
91 ",
92 SCF_Config::PREFIX . '%'
93 )
94 );
95 }
96
97 /**
98 * Run management screens
99 *
100 * @param WP_Screen $screen
101 */
102 public function current_screen( $screen ) {
103 // 一覧画面
104 if ( $screen->id === 'edit-' . SCF_Config::NAME ) {
105 }
106 // 新規作成・編集画面
107 elseif ( $screen->id === SCF_Config::NAME ) {
108 require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.settings.php';
109 new Smart_Custom_Fields_Controller_Settings();
110 }
111 // その他の新規作成・編集画面
112 elseif ( in_array( $screen->id, get_post_types() ) ) {
113 $post_id = $this->get_post_id_in_admin();
114 $Post = new stdClass();
115 $Post->ID = $post_id;
116 $Post->post_type = $screen->id;
117 if ( SCF::get_settings( new WP_Post( $Post ) ) ) {
118 require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.controller-base.php';
119 require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.editor.php';
120 new Smart_Custom_Fields_Revisions();
121 new Smart_Custom_Fields_Controller_Editor();
122 }
123 }
124 // プロフィール編集画面
125 elseif ( in_array( $screen->id, array( 'profile', 'user-edit' ) ) ) {
126 $user_id = $this->get_user_id_in_admin();
127 $user_data = get_userdata( $user_id );
128 $roles[0] = false;
129 if ( $user_data ) {
130 $roles = $user_data->roles;
131 }
132 if ( SCF::get_settings( get_userdata( $user_id ) ) ) {
133 require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.controller-base.php';
134 require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.profile.php';
135 new Smart_Custom_Fields_Controller_Profile();
136 }
137 }
138 // タグ、カテゴリー、タクソノミー
139 elseif ( $screen->taxonomy ) {
140 $term_id = $this->get_term_id_in_admin();
141 if ( $term_id ) {
142 $term = get_term( $term_id, $screen->taxonomy );
143 if ( SCF::get_settings( $term ) ) {
144 require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.controller-base.php';
145 require_once plugin_dir_path( __FILE__ ) . 'classes/controller/class.taxonomy.php';
146 new Smart_Custom_Fields_Controller_Taxonomy();
147 }
148 }
149 }
150 }
151
152 /**
153 * Registering custom post type.
154 * Run the menu display in a different method.
155 */
156 public function register_post_type() {
157 $labels = array(
158 'name' => __( 'Smart Custom Fields', 'smart-custom-fields' ),
159 'menu_name' => __( 'Smart Custom Fields', 'smart-custom-fields' ),
160 'name_admin_bar' => __( 'Smart Custom Fields', 'smart-custom-fields' ),
161 'add_new' => __( 'Add New', 'smart-custom-fields' ),
162 'add_new_item' => __( 'Add New', 'smart-custom-fields' ),
163 'new_item' => __( 'New Field', 'smart-custom-fields' ),
164 'edit_item' => __( 'Edit Field', 'smart-custom-fields' ),
165 'view_item' => __( 'View Field', 'smart-custom-fields' ),
166 'all_items' => __( 'All Fields', 'smart-custom-fields' ),
167 'search_items' => __( 'Search Fields', 'smart-custom-fields' ),
168 'parent_item_colon' => __( 'Parent Fields:', 'smart-custom-fields' ),
169 'not_found' => __( 'No Fields found.', 'smart-custom-fields' ),
170 'not_found_in_trash' => __( 'No Fields found in Trash.', 'smart-custom-fields' )
171 );
172 register_post_type(
173 SCF_Config::NAME,
174 array(
175 'label' => 'Smart Custom Fields',
176 'labels' => $labels,
177 'public' => false,
178 'show_ui' => true,
179 'capability_type' => 'page',
180 'supports' => array( 'title', 'page-attributes' ),
181 'show_in_menu' => false,
182 )
183 );
184 }
185
186 /**
187 * Hooking the process that it want to fire when the ajax request.
188 */
189 public function ajax_request() {
190 $Ajax = new Smart_Custom_Fields_Ajax();
191 }
192
193 /**
194 * Adding menus in management screen.
195 */
196 public function admin_menu() {
197 add_menu_page(
198 'Smart Custom Fields',
199 'Smart Custom Fields',
200 'manage_options',
201 'edit.php?post_type=' . SCF_Config::NAME,
202 false,
203 false,
204 '80.026'
205 );
206 add_submenu_page(
207 'edit.php?post_type=' . SCF_Config::NAME,
208 __( 'Add New', 'smart-custom-fields' ),
209 __( 'Add New', 'smart-custom-fields' ),
210 'manage_options',
211 'post-new.php?post_type=' . SCF_Config::NAME
212 );
213 }
214
215 /**
216 * Getting the post ID in post editing page.
217 *
218 * @return int
219 */
220 protected function get_post_id_in_admin() {
221 $post_id = false;
222 if ( !empty( $_GET['post'] ) ) {
223 $post_id = $_GET['post'];
224 } elseif ( !empty( $_POST['post_ID'] ) ) {
225 $post_id = $_POST['post_ID'];
226 }
227 return $post_id;
228 }
229
230 /**
231 * Getting the user ID in profile and user editing pages.
232 *
233 * @return int
234 */
235 protected function get_user_id_in_admin() {
236 $screen = get_current_screen();
237 $user_id = false;
238 if ( !empty( $_GET['user_id'] ) ) {
239 $user_id = $_GET['user_id'];
240 } elseif ( !empty( $_POST['user_id'] ) ) {
241 $user_id = $_POST['user_id'];
242 } elseif ( $screen->id === 'profile' ) {
243 $current_user = wp_get_current_user();
244 $user_id = $current_user->ID;
245 }
246 return $user_id;
247 }
248
249 /**
250 * Getting the term ID in term editing page.
251 *
252 * @return int
253 */
254 protected function get_term_id_in_admin() {
255 $term_id = false;
256 if ( !empty( $_GET['tag_ID'] ) ) {
257 $term_id = $_GET['tag_ID'];
258 } elseif ( !empty( $_POST['tag_ID'] ) ) {
259 $term_id = $_POST['tag_ID'];
260 }
261 return $term_id;
262 }
263 }
264 new Smart_Custom_Fields();
265