Trait for a submodule that supports settings.
Description
Source
File: src/modules/settings-submodule-trait.php
trait Settings_Submodule_Trait { /** * Retrieves the value of a specific submodule option. * * @since 1.0.0 * * @param string $option Name of the option to retrieve. * @param mixed $default Optional. Value to return if the option doesn't exist. Default false. * @return mixed Value set for the option. */ public function get_option( $option, $default = false ) { return $this->module->get_option( $this->get_settings_identifier() . '__' . $option, $default ); } /** * Retrieves the values for all submodule options. * * @since 1.0.0 * * @return array Associative array of `$key => $value` pairs for every option that is set. */ public function get_options() { $settings = $this->module->get_options(); $prefix = $this->get_settings_identifier() . '__'; $options = array(); foreach ( $settings as $key => $value ) { if ( 0 !== strpos( $key, $prefix ) ) { continue; } $key = substr( $key, strlen( $prefix ) ); $options[ $key ] = $value; } return $options; } /** * Returns the settings identifier for the submodule. * * @since 1.0.0 * * @return string Submodule settings identifier. */ public function get_settings_identifier() { return $this->slug; } /** * Returns the settings subtab title for the submodule. * * @since 1.0.0 * * @return string Submodule settings title. */ public function get_settings_title() { return $this->title; } /** * Returns the available settings sections for the submodule. * * @since 1.0.0 * * @return array Associative array of `$section_slug => $section_args` pairs. */ public function get_settings_sections() { return array(); } /** * Returns the available settings fields for the submodule. * * @since 1.0.0 * * @return array Associative array of `$field_slug => $field_args` pairs. */ public function get_settings_fields() { return array(); } }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |
Methods
- enabled — Checks whether the protector is enabled for a specific form.
- get_meta_fields — Returns the available meta fields for the submodule.
- render_output — Renders the output for the protector before the Submit button.
- verify_request — Verifies a request by ensuring that it is not spammy.
- wrap_form_name — Wraps a non-prefixed form input name attribute so that it will be properly included the submission POST data.