PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.2.2
Pods – Custom Content Types and Fields v3.2.2
trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / ui / admin / settings-tools.php
pods / ui / admin Last commit date
callouts 2 years ago upgrade 2 years ago widgets 2 years ago components-admin.php 2 years ago help-addons-row.php 2 years ago help-addons.php 2 years ago help.php 2 years ago postbox-header.php 2 years ago settings-reset.php 2 years ago settings-settings.php 2 years ago settings-tools.php 2 years ago settings.php 2 years ago setup-add.php 2 years ago setup-edit.php 2 years ago shortcode.php 2 years ago view.php 2 years ago
settings-tools.php
209 lines
1 <?php
2
3 use Pods\Tools\Repair;
4
5 // Don't load directly.
6 if ( ! defined( 'ABSPATH' ) || ! pods_is_admin( 'pods_settings' ) ) {
7 die( '-1' );
8 }
9
10 global $wpdb;
11
12 $pods_api = pods_api();
13
14 $all_pods = $pods_api->load_pods();
15
16 if ( isset( $_POST['_wpnonce'] ) && false !== wp_verify_nonce( $_POST['_wpnonce'], 'pods-settings' ) ) {
17 if ( isset( $_POST['pods_repair_pod'] ) || isset( $_POST['pods_repair_pod_preview'] ) ) {
18 $pod_name = pods_v( 'pods_field_repair_pod', 'post' );
19
20 if ( is_array( $pod_name ) ) {
21 $pod_name = $pod_name[0];
22 }
23
24 $pod_name = sanitize_text_field( $pod_name );
25
26 if ( empty( $pod_name ) ) {
27 pods_message( __( 'No Pod selected.', 'pods' ), 'error' );
28 } else {
29 if ( '__all_pods' === $pod_name ) {
30 $pods_to_repair = [];
31
32 foreach ( $all_pods as $pod ) {
33 if ( 'post_type' !== $pod->get_object_storage_type() ) {
34 continue;
35 }
36
37 $pods_to_repair[] = $pod->get_name();
38 }
39 } else {
40 $pods_to_repair = [ $pod_name ];
41 }
42
43 foreach ( $pods_to_repair as $pod_to_repair ) {
44 $pod = $pods_api->load_pod( [ 'name' => $pod_to_repair ], false );
45
46 if ( empty( $pod ) ) {
47 pods_message( __( 'Pod not found.', 'pods' ) . ' (' . $pod_to_repair . ')', 'error' );
48 } else {
49 $tool = pods_container( Repair::class );
50
51 $mode = 'full';
52
53 if ( ! empty( $_POST['pods_repair_pod_preview'] ) ) {
54 $mode = 'preview';
55 }
56
57 $results = $tool->repair_groups_and_fields_for_pod( $pod, $mode );
58
59 pods_message( $results['message_html'] );
60 }
61 }
62 }
63 } elseif ( isset( $_POST['pods_repair_pods'] ) || isset( $_POST['pods_repair_pods_preview'] ) ) {
64 $tool = pods_container( Repair::class );
65
66 $mode = 'full';
67
68 if ( ! empty( $_POST['pods_repair_pods_preview'] ) ) {
69 $mode = 'preview';
70 }
71
72 $results = $tool->repair_pods( $mode );
73
74 pods_message( $results['message_html'] );
75 } elseif ( isset( $_POST['pods_recreate_tables'] ) ) {
76 pods_upgrade()->delta_tables();
77
78 pods_redirect( pods_query_arg( array( 'pods_recreate_tables_success' => 1 ), array( 'page', 'tab' ) ) );
79 }
80 } elseif ( 1 === (int) pods_v( 'pods_recreate_tables_success' ) ) {
81 pods_message( 'Pods tables have been recreated.' );
82 }
83 ?>
84
85 <h3><?php esc_html_e( 'Repair Pod, Groups, and Fields', 'pods' ); ?></h3>
86
87 <p><?php esc_html_e( 'This tool will attempt to repair a Pod, Groups, and Fields. When the tool runs you will be provided with a complete list of repairs made.', 'pods' ); ?></p>
88
89 <h4><?php esc_html_e( 'What you can expect', 'pods' ); ?></h4>
90
91 <ul class="ul-disc">
92 <li><?php esc_html_e( 'If the Pod has Fields but no Groups yet, the first Group will be automatically created', 'pods' ); ?></li>
93 <li><?php esc_html_e( 'All Groups with conflicting names will be renamed to prevent conflicts with other registered Groups', 'pods' ); ?></li>
94 <li><?php esc_html_e( 'All Fields with conflicting names will be renamed to prevent conflicts with other registered Fields', 'pods' ); ?></li>
95 <li><?php esc_html_e( 'All orphaned Fields that belong to a Group that no longer exists will be auto-assigned to the first available Group', 'pods' ); ?></li>
96 <li><?php esc_html_e( 'All orphaned Fields that do not belong to a Group will be auto-assigned to the first available Group', 'pods' ); ?></li>
97 <li><?php esc_html_e( 'All Fields that have an invalid Field type set will be changed to Plain Text', 'pods' ); ?></li>
98 <li><?php esc_html_e( 'All Fields that have invalid arguments set will have those arguments removed (conditional logic saved with serialized data and other arguments not intended for the DB used by early Pods 2.x releases)', 'pods' ); ?></li>
99 </ul>
100
101 <?php
102 $repair_pods = [];
103
104 foreach ( $all_pods as $pod ) {
105 if ( 'post_type' !== $pod->get_object_storage_type() ) {
106 continue;
107 }
108
109 $repair_pods[ $pod->get_name() ] = sprintf(
110 '%1$s (%2$s)',
111 $pod->get_label(),
112 $pod->get_name()
113 );
114 }
115
116 asort( $repair_pods );
117
118 $repair_pods['__all_pods'] = '-- ' . __( 'Run Repair for All Pods', 'pods' ) . ' (' . __( 'Warning: This may be slow on large configurations', 'pods' ) . ') --';
119 ?>
120
121 <?php if ( 1 < count( $repair_pods ) ) : ?>
122 <table class="form-table pods-manage-field">
123 <?php
124 $fields = [
125 'repair_pod' => [
126 'name' => 'repair_pod',
127 'label' => __( 'Pod', 'pods' ),
128 'type' => 'pick',
129 'pick_format_type' => 'single',
130 'pick_format_single' => 'autocomplete',
131 'data' => $repair_pods,
132 ],
133 ];
134
135 $field_prefix = 'pods_field_';
136 $field_row_classes = '';
137 $id = '';
138 $value_callback = static function( $field_name, $id, $field, $pod ) use ( $field_prefix ) {
139 return pods_v( $field_prefix . $field_name, 'post', '' );
140 };
141
142 pods_view( PODS_DIR . 'ui/forms/table-rows.php', compact( array_keys( get_defined_vars() ) ) );
143 ?>
144 </table>
145
146 <p class="submit">
147 <?php
148 $confirm = esc_html__( 'Are you sure you want to do this?', 'pods' )
149 . "\n\n" . esc_html__( 'This is a good time to make sure you have a backup.', 'pods' )
150 . "\n\n" . esc_html__( 'We will be making a few repairs to your configuration that should not be destructive to your data but you should be always have a backup just in case.', 'pods' );
151 ?>
152 <input type="submit" class="button button-primary" name="pods_repair_pod"
153 value=" <?php esc_attr_e( 'Repair Pod, Groups, and Fields', 'pods' ); ?> " onclick="return confirm( '<?php echo esc_js( $confirm ); ?>' );" />
154 <input type="submit" class="button button-secondary" name="pods_repair_pod_preview"
155 value=" <?php esc_attr_e( 'Preview (no changes will be made)', 'pods' ); ?> " />
156 </p>
157 <?php else : ?>
158 <p><em><?php esc_html_e( 'No Pods available to repair.', 'pods' ); ?></em></p>
159 <?php endif; ?>
160
161 <hr />
162
163 <h3><?php esc_html_e( 'Repair Pod configurations', 'pods' ); ?></h3>
164
165 <p><?php esc_html_e( 'This will repair pod configurations themselves.', 'pods' ); ?></p>
166 <h4><?php esc_html_e( 'What you can expect', 'pods' ); ?></h4>
167 <ul class='ul-disc'>
168 <li><?php esc_html_e( 'All Pods with conflicting names will be renamed to prevent conflicts with other registered Pods', 'pods' ); ?></li>
169 </ul>
170
171 <p class='submit'>
172 <?php
173 $confirm = esc_html__( 'Are you sure you want to do this?', 'pods' )
174 . "\n\n" . esc_html__( 'This is a good time to make sure you have a backup.', 'pods' )
175 . "\n\n" . esc_html__( 'We will be making a few repairs to your configuration that should not be destructive to your data but you should be always have a backup just in case.', 'pods' );
176 ?>
177 <input type="submit" class="button button-primary" name="pods_repair_pods"
178 value=" <?php esc_attr_e( 'Repair Pod configurations', 'pods' ); ?> "
179 onclick="return confirm( '<?php echo esc_js( $confirm ); ?>' );"/>
180 <input type="submit" class="button button-secondary" name="pods_repair_pods_preview"
181 value=" <?php esc_attr_e( 'Preview (no changes will be made)', 'pods' ); ?> "/>
182 </p>
183
184 <hr />
185
186 <?php
187 $relationship_table = $wpdb->prefix . 'podsrel';
188 ?>
189
190 <h3><?php esc_html_e( 'Recreate missing tables', 'pods' ); ?></h3>
191
192 <p><?php esc_html_e( 'This will recreate missing tables if there are any that do not exist.', 'pods' ); ?></p>
193 <h4><?php esc_html_e( 'What you can expect', 'pods' ); ?></h4>
194 <ul>
195 <li>🆗 &nbsp;&nbsp;<strong><?php esc_html_e( 'KEEP', 'pods' ); ?>:</strong> <?php
196 // translators: %s is the name of the wp_podsrel table in the database.
197 printf( esc_html__( '%s will remain untouched if it already exists', 'pods' ), esc_html( $relationship_table ) );
198 ?></li>
199 <li>🆗 &nbsp;&nbsp;<strong><?php esc_html_e( 'CREATE', 'pods' ); ?>:</strong> <?php
200 // translators: %s is the name of the wp_podsrel table in the database.
201 printf( esc_html__( '%s will be created if it does not exist', 'pods' ), esc_html( $relationship_table ) );
202 ?></li>
203 </ul>
204
205 <p class="submit">
206 <?php $confirm = __( 'Are you sure you want to do this?', 'pods' ); ?>
207 <input type="submit" class="button button-primary" name="pods_recreate_tables" value=" <?php esc_attr_e( 'Recreate missing tables', 'pods' ); ?> " onclick="return confirm( '<?php echo esc_js( $confirm ); ?>' );" />
208 </p>
209