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-settings.php
151 lines
| 1 | <?php |
| 2 | // Don't load directly. |
| 3 | if ( ! defined( 'ABSPATH' ) || ! pods_is_admin( 'pods_settings' ) ) { |
| 4 | die( '-1' ); |
| 5 | } |
| 6 | |
| 7 | wp_enqueue_script( 'pods' ); |
| 8 | pods_form_enqueue_style( 'pods-form' ); |
| 9 | |
| 10 | /** |
| 11 | * Allow filtering the list of fields for the settings page. |
| 12 | * |
| 13 | * @since 2.8.0 |
| 14 | * |
| 15 | * @param array $fields List of fields for the settings page. |
| 16 | */ |
| 17 | $fields = apply_filters( 'pods_admin_settings_fields', array() ); |
| 18 | |
| 19 | if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'pods-settings' ) ) { |
| 20 | if ( isset( $_POST['pods_cache_flush'] ) ) { |
| 21 | // Handle clearing cache. |
| 22 | $api = pods_api(); |
| 23 | |
| 24 | $api->cache_flush_pods(); |
| 25 | |
| 26 | if ( defined( 'PODS_PRELOAD_CONFIG_AFTER_FLUSH' ) && PODS_PRELOAD_CONFIG_AFTER_FLUSH ) { |
| 27 | $api->load_pods( array( 'bypass_cache' => true ) ); |
| 28 | } |
| 29 | |
| 30 | pods_redirect( pods_query_arg( array( 'pods_cache_flushed' => 1 ), array( 'page', 'tab' ) ) ); |
| 31 | } else { |
| 32 | // Handle saving settings. |
| 33 | $action = __( 'saved', 'pods' ); |
| 34 | |
| 35 | $params = pods_unslash( (array) $_POST ); |
| 36 | |
| 37 | $settings_to_save = []; |
| 38 | |
| 39 | $layout_field_types = PodsForm::layout_field_types(); |
| 40 | |
| 41 | foreach ( $fields as $key => $field ) { |
| 42 | // Auto set the field name. |
| 43 | if ( ! isset( $field['name'] ) ) { |
| 44 | $field['name'] = $key; |
| 45 | } |
| 46 | |
| 47 | // Skip layout field types. |
| 48 | if ( isset( $field['type'] ) && in_array( $field['type'], $layout_field_types, true ) ) { |
| 49 | continue; |
| 50 | } |
| 51 | |
| 52 | $value = ''; |
| 53 | |
| 54 | if ( isset( $params[ 'pods_field_' . $field['name'] ] ) ) { |
| 55 | $value = $params[ 'pods_field_' . $field['name'] ]; |
| 56 | } elseif ( 'boolean' === $field['type'] ) { |
| 57 | $value = '0'; |
| 58 | } |
| 59 | |
| 60 | $sanitize_callback = pods_v( 'sanitize_callback', $field, 'sanitize_text_field', true ); |
| 61 | |
| 62 | // Sanitize value if needed. |
| 63 | if ( is_callable( $sanitize_callback ) ) { |
| 64 | if ( is_array( $value ) ) { |
| 65 | $value = array_map( $sanitize_callback, $value ); |
| 66 | } else { |
| 67 | $value = $sanitize_callback( $value ); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | $settings_to_save[ $field['name'] ] = $value; |
| 72 | } |
| 73 | |
| 74 | if ( $settings_to_save ) { |
| 75 | pods_update_settings( $settings_to_save ); |
| 76 | |
| 77 | $message = sprintf( __( '<strong>Success!</strong> %1$s %2$s successfully.', 'pods' ), __( 'Settings', 'pods' ), $action ); |
| 78 | |
| 79 | pods_message( $message ); |
| 80 | } else { |
| 81 | $error = sprintf( __( '<strong>Error:</strong> %1$s %2$s successfully.', 'pods' ), __( 'Settings', 'pods' ), $action ); |
| 82 | |
| 83 | pods_message( $error, 'error' ); |
| 84 | } |
| 85 | } |
| 86 | } elseif ( 1 === (int) pods_v( 'pods_cache_flushed' ) ) { |
| 87 | pods_message( __( 'Pods transients and cache have been cleared.', 'pods' ) ); |
| 88 | } |
| 89 | |
| 90 | $do = 'save'; |
| 91 | ?> |
| 92 | |
| 93 | <h3><?php _e( 'Clear Pods Cache', 'pods' ); ?></h3> |
| 94 | |
| 95 | <p><?php esc_html_e( 'This will clear all of the transients and object cache that are used by Pods and your site.', 'pods' ); ?></p> |
| 96 | |
| 97 | <p class="submit"> |
| 98 | <input type="submit" class="button button-primary" name="pods_cache_flush" value="<?php esc_attr_e( 'Clear Pods Cache', 'pods' ); ?>" /> |
| 99 | </p> |
| 100 | |
| 101 | <hr /> |
| 102 | |
| 103 | <div class="pods-submittable-fields pods-dependency"> |
| 104 | <?php echo PodsForm::field( 'do', $do, 'hidden' ); ?> |
| 105 | |
| 106 | <?php |
| 107 | foreach ( $fields as $key => $field ) { |
| 108 | // Auto set the field name. |
| 109 | if ( ! isset( $field['name'] ) ) { |
| 110 | $fields[ $key ]['name'] = $key; |
| 111 | } |
| 112 | |
| 113 | // Skip if not hidden. |
| 114 | if ( 'hidden' !== $field['type'] ) { |
| 115 | continue; |
| 116 | } |
| 117 | |
| 118 | // Output hidden field at top. |
| 119 | echo PodsForm::field( 'pods_field_' . $field['name'], pods_get_setting( $field['name'], pods_v( 'default', $field ) ), 'hidden' ); |
| 120 | |
| 121 | // Remove from list of fields to render below. |
| 122 | unset( $fields[ $key ] ); |
| 123 | } |
| 124 | ?> |
| 125 | <table class="form-table pods-manage-field"> |
| 126 | <?php |
| 127 | $field_prefix = 'pods_field_'; |
| 128 | $field_row_classes = ''; |
| 129 | $id = ''; |
| 130 | $value_callback = static function( $field_name, $id, $field, $pod ) { |
| 131 | return pods_get_setting( $field_name, pods_v( 'default', $field ) ); |
| 132 | }; |
| 133 | |
| 134 | pods_view( PODS_DIR . 'ui/forms/table-rows.php', compact( array_keys( get_defined_vars() ) ) ); |
| 135 | ?> |
| 136 | </table> |
| 137 | |
| 138 | <p class="submit"> |
| 139 | <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Save Settings', 'pods' ); ?>"> |
| 140 | <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" /> |
| 141 | </p> |
| 142 | </div> |
| 143 | |
| 144 | <script type="text/javascript"> |
| 145 | jQuery( function ( $ ) { |
| 146 | $( document ).Pods( 'validate' ); |
| 147 | $( document ).Pods( 'dependency', true ); |
| 148 | $( document ).Pods( 'qtip', '.pods-submittable' ); |
| 149 | } ); |
| 150 | </script> |
| 151 |