group, label, position, render. * @return array */ public static function sections( $sections ) { $sections = (array) $sections; $sections['periods'] = array( 'tab' => 'timing', 'label' => __( 'When the periods start', 'careback' ), 'position' => 5, 'render' => array( __CLASS__, 'render_periods' ), ); $sections['deleting'] = array( 'tab' => 'safeguards', 'label' => __( 'Deleting the plugin', 'careback' ), 'position' => 90, 'render' => array( __CLASS__, 'render_deleting' ), ); return $sections; } /** * The fields of the last save that were refused (their stored value kept). * * @return string[] */ public static function invalid_fields() { return self::$invalid; } /** * The values of the two sections, from the returns form. A status that is * not one to choose and a buffer outside 0–30 are refused: the stored value * stays and the field says why. * * @param array $values Values the form stores. * @param string $screen Id of the screen saving (Admin::SCREEN). * @param Settings|null $settings The screen's settings. * @param array $posted The posted form (Admin::save(), after its capability and nonce checks). * @return array */ public static function save( $values, $screen = '', $settings = null, $posted = array() ) { $values = (array) $values; $posted = (array) $posted; if ( Admin::SCREEN !== $screen ) { return $values; } unset( $settings ); self::$invalid = array(); $values['delete_data_on_uninstall'] = empty( $posted['delete_data_on_uninstall'] ) ? 0 : 1; if ( isset( $posted['delivered_status'] ) && is_scalar( $posted['delivered_status'] ) ) { $status = sanitize_key( $posted['delivered_status'] ); if ( isset( Periods::choices()[ $status ] ) ) { $values['delivered_status'] = $status; } } if ( isset( $posted['delivery_buffer_days'] ) && is_scalar( $posted['delivery_buffer_days'] ) ) { $buffer = trim( sanitize_text_field( $posted['delivery_buffer_days'] ) ); if ( '' !== $buffer && ctype_digit( $buffer ) && (int) $buffer <= Periods::BUFFER_MAX ) { $values['delivery_buffer_days'] = (int) $buffer; } else { self::$invalid[] = 'delivery_buffer_days'; } } return $values; } /** * True when the save before this screen refused the field. * * @param string $field Field name. * @return bool */ private static function refused( $field ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display only: the result of the redirect after a save; nothing is changed. $raw = isset( $_GET[ self::INVALID_ARG ] ) && is_scalar( $_GET[ self::INVALID_ARG ] ) ? sanitize_text_field( wp_unslash( $_GET[ self::INVALID_ARG ] ) ) : ''; return in_array( $field, explode( ',', $raw ), true ); } /** * When the periods start: the explanation, the status, the buffer, the * example. * * @param array $s Stored settings. * @param string $screen Id of the screen printing it. * @param Settings|null $settings The settings that screen prints. */ public static function render_periods( array $s, $screen = '', $settings = null ) { unset( $screen ); $settings = $settings instanceof Settings ? $settings : new Settings(); $status = Periods::delivered_status( $settings ); $buffer = Periods::buffer_days( $settings ); $choices = Periods::choices(); $refused = self::refused( 'delivery_buffer_days' ); $example = self::example( $settings, $choices ); ?>
| class="small-text" /> |
|
|