PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 3.0.5
Admin Columns v3.0.5
7.1.4 7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Admin / Page / Settings.php
codepress-admin-columns / classes / Admin / Page Last commit date
Addons.php 8 years ago Columns.php 8 years ago Help.php 8 years ago Settings.php 8 years ago Upgrade.php 8 years ago Welcome.php 8 years ago
Settings.php
241 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 class AC_Admin_Page_Settings extends AC_Admin_Page {
8
9 const SETTINGS_NAME = 'cpac_general_options';
10
11 const SETTINGS_GROUP = 'cpac-general-settings';
12
13 private $options;
14
15 public function __construct() {
16 $this
17 ->set_slug( 'settings' )
18 ->set_label( __( 'Settings', 'codepress-admin-columns' ) );
19
20 $this->options = get_option( self::SETTINGS_NAME );
21
22 register_setting( self::SETTINGS_GROUP, self::SETTINGS_NAME );
23
24 add_filter( 'option_page_capability_' . self::SETTINGS_GROUP, array( $this, 'set_capability' ) );
25 add_action( 'admin_init', array( $this, 'handle_column_request' ) );
26 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
27 }
28
29 public function admin_scripts() {
30 if ( $this->is_current_screen() ) {
31 wp_enqueue_style( 'ac-admin-page-settings', AC()->get_plugin_url() . 'assets/css/admin-page-settings' . AC()->minified() . '.css', array(), AC()->get_version() );
32 }
33 }
34
35 public function set_capability() {
36 return 'manage_admin_columns';
37 }
38
39 /**
40 * @param string $key
41 */
42 public function attr_name( $key ) {
43 echo esc_attr( self::SETTINGS_NAME . '[' . sanitize_key( $key ) . ']' );
44 }
45
46 /**
47 * @param $key
48 *
49 * @return false|string When '0' there are no options stored.
50 */
51 public function get_option( $key ) {
52 return isset( $this->options[ $key ] ) ? $this->options[ $key ] : false;
53 }
54
55 private function is_empty_options() {
56 return false === $this->options;
57 }
58
59 public function delete_options() {
60 delete_option( self::SETTINGS_NAME );
61 }
62
63 /**
64 * @return bool
65 */
66 public function show_edit_button() {
67 return $this->is_empty_options() || $this->get_option( 'show_edit_button' );
68 }
69
70 /**
71 * Deletes all stored column settings. Does not delete general settings.
72 */
73 private function delete_all_column_settings() {
74 global $wpdb;
75
76 $sql = "
77 DELETE
78 FROM $wpdb->options
79 WHERE option_name LIKE %s";
80
81 $wpdb->query( $wpdb->prepare( $sql, AC_ListScreen::OPTIONS_KEY . '%' ) );
82
83 // @since 3.0
84 do_action( 'ac/restore_all_columns' );
85 }
86
87 /**
88 * @since 1.0
89 */
90 public function handle_column_request() {
91 if ( ! AC()->user_can_manage_admin_columns() || ! $this->is_current_screen() ) {
92 return;
93 }
94
95 switch ( filter_input( INPUT_POST, 'ac_action' ) ) :
96
97 case 'restore_all' :
98 if ( $this->verify_nonce( 'restore-all' ) ) {
99 $this->delete_all_column_settings();
100
101 AC()->notice( __( 'Default settings succesfully restored.', 'codepress-admin-columns' ), 'updated' );
102 }
103 break;
104
105 endswitch;
106 }
107
108 public function single_checkbox( $args = array() ) {
109 $defaults = array(
110 'name' => '',
111 'label' => '',
112 'instructions' => '',
113 'default_value' => false,
114 );
115
116 $args = (object) wp_parse_args( $args, $defaults );
117
118 $current_value = $this->is_empty_options() ? $args->default_value : $this->get_option( $args->name );
119 ?>
120 <p>
121 <label for="<?php echo $args->name; ?>">
122 <input name="<?php $this->attr_name( $args->name ); ?>" id="<?php echo $args->name; ?>" type="checkbox" value="1" <?php checked( $current_value, '1' ); ?>>
123 <?php echo $args->label; ?>
124 </label>
125 <?php if ( $args->instructions ) : ?>
126 <a class="ac-pointer instructions" rel="pointer-<?php echo $args->name; ?>" data-pos="right">
127 <?php _e( 'Instructions', 'codepress-admin-columns' ); ?>
128 </a>
129 <?php endif; ?>
130 </p>
131 <?php if ( $args->instructions ) : ?>
132 <div id="pointer-<?php echo $args->name; ?>" style="display:none;">
133 <h3><?php _e( 'Notice', 'codepress-admin-columns' ); ?></h3>
134 <?php echo $args->instructions; ?>
135 </div>
136 <?php
137 endif;
138 }
139
140 /**
141 * @param bool $type
142 *
143 * @return string
144 */
145 public function get_default_text( $type = 'on' ) {
146 $string = __( 'off', 'codepress-admin-columns' );
147
148 if ( 'on' === $type ) {
149 $string = __( 'on', 'codepress-admin-columns' );
150 }
151
152 return sprintf( __( "Default is %s.", 'codepress-admin-columns' ), '<code>' . $string . '</code>' );
153 }
154
155 public function display() { ?>
156 <table class="form-table ac-form-table settings">
157 <tbody>
158 <tr class="general">
159 <th scope="row">
160 <h2><?php _e( 'General Settings', 'codepress-admin-columns' ); ?></h2>
161 <p><?php _e( 'Customize your Admin Columns settings.', 'codepress-admin-columns' ); ?></p>
162 </th>
163 <td>
164 <form method="post" action="options.php">
165
166 <?php settings_fields( self::SETTINGS_GROUP ); ?>
167
168 <?php
169 $this->single_checkbox( array(
170 'name' => 'show_edit_button',
171 'label' => sprintf( __( "Show %s button on table screen.", 'codepress-admin-columns' ), '"' . __( 'Edit columns', 'codepress-admin-columns' ) . '"' ) . ' ' . $this->get_default_text( 'on' ),
172 'default_value' => '1',
173 ) );
174 ?>
175
176 <?php do_action( 'ac/settings/general', $this ); ?>
177
178 <p>
179 <input type="submit" class="button" value="<?php _e( 'Save' ); ?>"/>
180 </p>
181 </form>
182 </td>
183 </tr>
184
185 <?php
186
187 /** Allow plugins to add their own custom settings to the settings page. */
188 if ( $groups = apply_filters( 'ac/settings/groups', array() ) ) {
189
190 foreach ( $groups as $id => $group ) {
191
192 $title = isset( $group['title'] ) ? $group['title'] : '';
193 $description = isset( $group['description'] ) ? $group['description'] : '';
194
195 ?>
196
197 <tr>
198 <th scope="row">
199 <h2><?php echo esc_html( $title ); ?></h2>
200
201 <p><?php echo $description; ?></p>
202 </th>
203 <td>
204 <?php
205
206 /** Use this Hook to add additional fields to the group */
207 do_action( "ac/settings/group/" . $id );
208
209 ?>
210 </td>
211 </tr>
212
213 <?php
214 }
215 }
216 ?>
217
218 <tr class="restore">
219 <th scope="row">
220 <h2><?php _e( 'Restore Settings', 'codepress-admin-columns' ); ?></h2>
221 <p><?php _e( 'This will delete all column settings and restore the default settings.', 'codepress-admin-columns' ); ?></p>
222 </th>
223 <td>
224 <form method="post">
225
226 <?php $this->nonce_field( 'restore-all' ); ?>
227
228 <input type="hidden" name="ac_action" value="restore_all">
229 <input type="submit" class="button" name="ac-restore-defaults" value="<?php echo esc_attr( __( 'Restore default settings', 'codepress-admin-columns' ) ); ?>" onclick="return confirm('<?php echo esc_js( __( "Warning! ALL saved admin columns data will be deleted. This cannot be undone. 'OK' to delete, 'Cancel' to stop", 'codepress-admin-columns' ) ); ?>');">
230 </form>
231 </td>
232 </tr>
233
234 </tbody>
235 </table>
236
237 <?php
238 }
239
240 }
241