...
|
...
|
@@ -7,87 +7,65 @@
|
7
|
7
|
require_once RC_PLUGIN_DIR . '/inc/class-rucy-component.php';
|
8
|
8
|
|
9
|
9
|
class Class_Rucy_Setting {
|
|
10
|
+ private $options;
|
10
|
11
|
//
|
11
|
12
|
public function set_admin_menu() {
|
12
|
13
|
add_options_page( 'Rucy', 'Rucy', 'manage_options', 'rucy', array( $this, 'add_setting_menu') );
|
13
|
14
|
}
|
14
|
15
|
|
|
16
|
+ public function setting_init() {
|
|
17
|
+ register_setting( 'rucy_setting', RC_SETTING_OPTION_KEY );
|
|
18
|
+ add_settings_section( 'rucy_setting', '', '', 'rucy');
|
|
19
|
+ add_settings_field("rc-post-types", __( 'post type', RC_TXT_DOMAIN ), array($this, 'get_rc_setting_fields'), 'rucy', 'rucy_setting');
|
|
20
|
+ }
|
|
21
|
+
|
15
|
22
|
public function add_setting_menu() {
|
16
|
23
|
$component = new Class_Rucy_Component();
|
17
|
|
- $post_types = $component->get_post_types();
|
18
|
|
- $support_post_type = $component->get_support_post_type();
|
19
|
|
- $is_different = false;
|
20
|
|
- if( ( isset( $_POST['page_options'] ) && $_POST['page_options'] === RC_SETTING_OPTION_KEY )
|
21
|
|
- && ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'update-options' ) )
|
22
|
|
- ) {
|
23
|
|
- // update post
|
24
|
|
- $post_support_posts = ( isset($_POST['rc_support_post_types']) ) ? $_POST['rc_support_post_types'] : array();
|
25
|
|
- if( count( array_diff( $support_post_type, $post_support_posts ) ) ) {
|
26
|
|
- // different data before post
|
27
|
|
- $is_different = true;
|
28
|
|
- }
|
29
|
|
- $is_update = $component->update_support_post_type( $post_support_posts );
|
30
|
|
- if ( $is_different && $is_update ) {
|
31
|
|
- set_transient( RC_SETTING_UPDATE, array( __( 'Success to setting update.', RC_TXT_DOMAIN ) ), 10 );
|
32
|
|
- } else if ( $is_different === false && $is_update === false ) {
|
33
|
|
- set_transient( RC_SETTING_UPDATE, array( __( 'Success to setting update.', RC_TXT_DOMAIN ) ), 10 );
|
34
|
|
- } else if ( $is_different && $is_update === false ) {
|
35
|
|
- // 更新失敗
|
36
|
|
- $e = new WP_Error();
|
37
|
|
- $e->add( 'error', __( 'Failed to setting update.', RC_TXT_DOMAIN ) );
|
38
|
|
- set_transient( RC_SETTING_ERROR, $e->get_error_messages(), 10 );
|
39
|
|
- }
|
40
|
|
- $support_post_type = $component->get_support_post_type();
|
41
|
|
- wp_safe_redirect( menu_page_url( 'rucy', false ) );
|
|
24
|
+ // update post
|
|
25
|
+ $post_support_posts = ( isset($_POST['rc_support_post_types']) ) ? $_POST['rc_support_post_types'] : array();
|
|
26
|
+ $is_update = $component->update_support_post_type( $post_support_posts );
|
|
27
|
+ if ( $is_update ) {
|
|
28
|
+ add_settings_error( 'rucy', 'update', __( 'Success to setting update.', RC_TXT_DOMAIN ), 'updated');
|
|
29
|
+ } else {
|
|
30
|
+ // 更新失敗
|
42
|
31
|
}
|
|
32
|
+ $this->options = $component->get_support_post_type();
|
|
33
|
+ wp_safe_redirect( menu_page_url( 'rucy', false ) );
|
43
|
34
|
?>
|
44
|
35
|
<div class="wrap">
|
45
|
36
|
<h2><?php _e( 'Rucy Settings', RC_TXT_DOMAIN ); ?></h2>
|
|
37
|
+ <?php
|
|
38
|
+ if ( get_settings_errors( 'rucy' ) ) {
|
|
39
|
+ settings_errors( 'rucy' );
|
|
40
|
+ }
|
|
41
|
+ ?>
|
46
|
42
|
<p><?php _e( 'Configure content types reservation update.', RC_TXT_DOMAIN ); ?></p>
|
47
|
43
|
<div class="rc-donation">
|
48
|
44
|
<p><?php _e( 'Your contribution will continue to better this plugin.', RC_TXT_DOMAIN ); ?> <a href="http://www.amazon.co.jp/registry/wishlist/27FDI6LJU0X1O" class="button"><?php _e( 'Donate', RC_TXT_DOMAIN ); ?></a></p>
|
49
|
45
|
</div>
|
50
|
|
- <form method="post" action="#">
|
51
|
|
- <?php wp_nonce_field('update-options'); ?>
|
52
|
|
- <table class="form-table">
|
53
|
|
- <tr class="">
|
54
|
|
- <th><?php _e( 'post type', RC_TXT_DOMAIN ); ?></th>
|
55
|
|
- <td>
|
56
|
|
- <ul>
|
57
|
|
- <?php foreach ( $post_types as $key => $post_type ) {
|
58
|
|
- $checked = ( in_array( $key, $support_post_type ) ) ? 'checked' : '';
|
59
|
|
- ?>
|
60
|
|
- <li><label for="rc_<?php echo $key; ?>"><input type="checkbox" id="rc_<?php echo $key; ?>" name="rc_support_post_types[]" value="<?php echo $key; ?>" <?php echo $checked; ?> /><?php echo $post_type->labels->name; ?></label></li>
|
61
|
|
- <?php } ?>
|
62
|
|
- </ul>
|
63
|
|
- </td>
|
64
|
|
- </tr>
|
65
|
|
- </table>
|
66
|
|
- <input type="hidden" name="action" value="update" />
|
67
|
|
- <input type="hidden" name="page_options" value="<?php echo RC_SETTING_OPTION_KEY ?>"/>
|
68
|
|
- <p class="submit">
|
69
|
|
- <input type="submit" class="button-primary" value="<?php _e( 'Save Changes' ) ?>" />
|
70
|
|
- </p>
|
|
46
|
+ <form method="post" action="options-general.php?page=rucy">
|
|
47
|
+ <?php
|
|
48
|
+ settings_fields('rucy');
|
|
49
|
+ do_settings_sections('rucy');
|
|
50
|
+ submit_button();
|
|
51
|
+ ?>
|
71
|
52
|
</form>
|
72
|
53
|
</div>
|
73
|
54
|
<?php
|
74
|
55
|
}
|
75
|
56
|
|
76
|
|
- public function set_admin_notices() {
|
77
|
|
- $message_class = "";
|
78
|
|
- if ( $messages = get_transient( RC_SETTING_UPDATE ) ) {
|
79
|
|
- $message_class = 'updated';
|
80
|
|
- } else if ( $messages = get_transient( RC_SETTING_ERROR ) ) {
|
81
|
|
- $message_class = 'error';
|
82
|
|
- }
|
|
57
|
+ public function get_rc_setting_fields() {
|
|
58
|
+ $component = new Class_Rucy_Component();
|
|
59
|
+ $post_types = $component->get_post_types();
|
|
60
|
+ $support_post_type = $component->get_support_post_type();
|
83
|
61
|
?>
|
84
|
|
-<div class="<?php echo $message_class; ?>">
|
85
|
|
- <ul>
|
86
|
|
- <?php foreach ( $messages as $message ): ?>
|
87
|
|
- <li><?php echo esc_html( $message ); ?></li>
|
88
|
|
- <?php endforeach; ?>
|
89
|
|
- </ul>
|
90
|
|
-</div>
|
91
|
|
-<?php
|
|
62
|
+<ul id="rc-post-types">
|
|
63
|
+ <?php foreach ( $post_types as $key => $post_type ) {
|
|
64
|
+ $checked = ( in_array( $key, $support_post_type ) ) ? 'checked' : '';
|
|
65
|
+ ?>
|
|
66
|
+ <li><label for="rc_<?php echo $key; ?>"><input type="checkbox" id="rc_<?php echo $key; ?>" name="rc_support_post_types[]" value="<?php echo $key; ?>" <?php echo $checked; ?> /><?php echo $post_type->labels->name; ?></label></li>
|
|
67
|
+ <?php } ?>
|
|
68
|
+</ul>
|
|
69
|
+<?php
|
92
|
70
|
}
|
93
|
71
|
}
|