Trait for a submodule that supports meta.
Description
Source
File: src/modules/meta-submodule-trait.php
trait Meta_Submodule_Trait { /** * Retrieves the value of a specific submodule form option. * * @since 1.0.0 * * @param int $form_id Form ID. * @param string $option Name of the form option to retrieve. * @param mixed $default Optional. Value to return if the form option doesn't exist. Default false. * @return mixed Value set for the form option. */ public function get_form_option( $form_id, $option, $default = false ) { return $this->module->get_form_option( $form_id, $this->get_meta_identifier() . '__' . $option, $default ); } /** * Retrieves the values for all submodule form options. * * @since 1.0.0 * * @param int $form_id Form ID. * @return array Associative array of `$key => $value` pairs for every form option that is set. */ public function get_form_options( $form_id ) { $metadata = $this->module->get_form_options( $form_id ); $prefix = $this->get_meta_identifier() . '__'; $options = array(); foreach ( $metadata as $key => $value ) { if ( 0 !== strpos( $key, $prefix ) ) { continue; } $key = substr( $key, strlen( $prefix ) ); $options[ $key ] = $value; } return $options; } /** * Returns the meta identifier for the submodule. * * @since 1.0.0 * * @return string Submodule meta identifier. */ public function get_meta_identifier() { return $this->slug; } /** * Returns the meta subtab title for the submodule. * * @since 1.0.0 * * @return string Submodule meta title. */ public function get_meta_title() { return $this->title; } /** * Returns the meta subtab description for the submodule. * * @since 1.0.0 * * @return string Submodule meta description. */ public function get_meta_description() { return $this->description; } /** * Returns the available meta fields for the submodule. * * @since 1.0.0 * * @return array Associative array of `$field_slug => $field_args` pairs. */ public function get_meta_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.