callouts
2 weeks ago
upgrade
2 weeks ago
widgets
2 weeks ago
components-admin.php
2 weeks ago
help-addons-row.php
2 weeks ago
help-addons.php
2 weeks ago
help.php
2 weeks ago
postbox-header.php
2 weeks ago
settings-reset.php
2 weeks ago
settings-settings.php
2 weeks ago
settings-tools.php
2 weeks ago
settings.php
2 weeks ago
setup-add.php
2 weeks ago
setup-edit.php
2 weeks ago
shortcode.php
2 weeks ago
view.php
2 weeks ago
settings-tools.php
173 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_recreate_tables'] ) ) { |
| 64 | pods_upgrade()->delta_tables(); |
| 65 | |
| 66 | pods_redirect( pods_query_arg( array( 'pods_recreate_tables_success' => 1 ), array( 'page', 'tab' ) ) ); |
| 67 | } |
| 68 | } elseif ( 1 === (int) pods_v( 'pods_recreate_tables_success' ) ) { |
| 69 | pods_message( 'Pods tables have been recreated.' ); |
| 70 | } |
| 71 | ?> |
| 72 | |
| 73 | <h3><?php esc_html_e( 'Repair Pod, Groups, and Fields', 'pods' ); ?></h3> |
| 74 | |
| 75 | <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> |
| 76 | |
| 77 | <h4><?php esc_html_e( 'What you can expect', 'pods' ); ?></h4> |
| 78 | |
| 79 | <ul class="ul-disc"> |
| 80 | <li><?php esc_html_e( 'If the Pod has Fields but no Groups yet, the first Group will be automatically created', 'pods' ); ?></li> |
| 81 | <li><?php esc_html_e( 'All Groups with conflicting names will be renamed to prevent conflicts with other registered Groups', 'pods' ); ?></li> |
| 82 | <li><?php esc_html_e( 'All Fields with conflicting names will be renamed to prevent conflicts with other registered Fields', 'pods' ); ?></li> |
| 83 | <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> |
| 84 | <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> |
| 85 | <li><?php esc_html_e( 'All Fields that have an invalid Field type set will be changed to Plain Text', 'pods' ); ?></li> |
| 86 | </ul> |
| 87 | |
| 88 | <?php |
| 89 | $repair_pods = []; |
| 90 | |
| 91 | foreach ( $all_pods as $pod ) { |
| 92 | if ( 'post_type' !== $pod->get_object_storage_type() ) { |
| 93 | continue; |
| 94 | } |
| 95 | |
| 96 | $repair_pods[ $pod->get_name() ] = sprintf( |
| 97 | '%1$s (%2$s)', |
| 98 | $pod->get_label(), |
| 99 | $pod->get_name() |
| 100 | ); |
| 101 | } |
| 102 | |
| 103 | asort( $repair_pods ); |
| 104 | |
| 105 | $repair_pods['__all_pods'] = '-- ' . __( 'Run Repair for All Pods', 'pods' ) . ' (' . __( 'Warning: This may be slow on large configurations', 'pods' ) . ') --'; |
| 106 | ?> |
| 107 | |
| 108 | <?php if ( 1 < count( $repair_pods ) ) : ?> |
| 109 | <table class="form-table pods-manage-field"> |
| 110 | <?php |
| 111 | $fields = [ |
| 112 | 'repair_pod' => [ |
| 113 | 'name' => 'repair_pod', |
| 114 | 'label' => __( 'Pod', 'pods' ), |
| 115 | 'type' => 'pick', |
| 116 | 'pick_format_type' => 'single', |
| 117 | 'pick_format_single' => 'autocomplete', |
| 118 | 'data' => $repair_pods, |
| 119 | ], |
| 120 | ]; |
| 121 | |
| 122 | $field_prefix = 'pods_field_'; |
| 123 | $field_row_classes = ''; |
| 124 | $id = ''; |
| 125 | $value_callback = static function( $field_name, $id, $field, $pod ) use ( $field_prefix ) { |
| 126 | return pods_v( $field_prefix . $field_name, 'post', '' ); |
| 127 | }; |
| 128 | |
| 129 | pods_view( PODS_DIR . 'ui/forms/table-rows.php', compact( array_keys( get_defined_vars() ) ) ); |
| 130 | ?> |
| 131 | </table> |
| 132 | |
| 133 | <p class="submit"> |
| 134 | <?php |
| 135 | $confirm = esc_html__( 'Are you sure you want to do this?', 'pods' ) |
| 136 | . "\n\n" . esc_html__( 'This is a good time to make sure you have a backup.', 'pods' ) |
| 137 | . "\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' ); |
| 138 | ?> |
| 139 | <input type="submit" class="button button-primary" name="pods_repair_pod" |
| 140 | value=" <?php esc_attr_e( 'Repair Pod, Groups, and Fields', 'pods' ); ?> " onclick="return confirm( '<?php echo esc_js( $confirm ); ?>' );" /> |
| 141 | <input type="submit" class="button button-secondary" name="pods_repair_pod_preview" |
| 142 | value=" <?php esc_attr_e( 'Preview (no changes will be made)', 'pods' ); ?> " /> |
| 143 | </p> |
| 144 | <?php else : ?> |
| 145 | <p><em><?php esc_html_e( 'No Pods available to repair.', 'pods' ); ?></em></p> |
| 146 | <?php endif; ?> |
| 147 | |
| 148 | <hr /> |
| 149 | |
| 150 | <?php |
| 151 | $relationship_table = $wpdb->prefix . 'podsrel'; |
| 152 | ?> |
| 153 | |
| 154 | <h3><?php esc_html_e( 'Recreate missing tables', 'pods' ); ?></h3> |
| 155 | |
| 156 | <p><?php esc_html_e( 'This will recreate missing tables if there are any that do not exist.', 'pods' ); ?></p> |
| 157 | <h4><?php esc_html_e( 'What you can expect', 'pods' ); ?></h4> |
| 158 | <ul> |
| 159 | <li>🆗 <strong><?php esc_html_e( 'KEEP', 'pods' ); ?>:</strong> <?php |
| 160 | // translators: %s is the name of the wp_podsrel table in the database. |
| 161 | printf( esc_html__( '%s will remain untouched if it already exists', 'pods' ), esc_html( $relationship_table ) ); |
| 162 | ?></li> |
| 163 | <li>🆗 <strong><?php esc_html_e( 'CREATE', 'pods' ); ?>:</strong> <?php |
| 164 | // translators: %s is the name of the wp_podsrel table in the database. |
| 165 | printf( esc_html__( '%s will be created if it does not exist', 'pods' ), esc_html( $relationship_table ) ); |
| 166 | ?></li> |
| 167 | </ul> |
| 168 | |
| 169 | <p class="submit"> |
| 170 | <?php $confirm = __( 'Are you sure you want to do this?', 'pods' ); ?> |
| 171 | <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 ); ?>' );" /> |
| 172 | </p> |
| 173 |