*/ namespace RankMath\Admin; use RankMath\Runner; use RankMath\Traits\Hooker; defined( 'ABSPATH' ) || exit; /** * CMB2_Fields class. * * @codeCoverageIgnore */ class CMB2_Fields implements Runner { use Hooker; /** * Register hooks. */ public function hooks() { // CMB2 Custom Fields. if ( ! has_action( 'cmb2_render_switch' ) ) { $this->action( 'cmb2_render_switch', 'render_switch', 10, 5 ); } if ( ! has_action( 'cmb2_render_notice' ) ) { $this->action( 'cmb2_render_notice', 'render_notice' ); } if ( ! has_action( 'cmb2_render_address' ) ) { $this->action( 'cmb2_render_address', 'render_address', 10, 5 ); } } /** * Render switch field. * * @param array $field The passed in `CMB2_Field` object. * @param mixed $escaped_value The value of this field escaped * It defaults to `sanitize_text_field`. * If you need the unescaped value, you can access it * via `$field->value()`. * @param int $object_id The ID of the current object. * @param string $object_type The type of object you are working with. * Most commonly, `post` (this applies to all post-types), * but could also be `comment`, `user` or `options-page`. * @param object $field_type_object This `CMB2_Types` object. */ public function render_switch( $field, $escaped_value, $object_id, $object_type, $field_type_object ) { if ( empty( $field->args['options'] ) ) { $field->args['options'] = [ 'off' => esc_html( $field->get_string( 'off', __( 'Off', 'rank-math' ) ) ), 'on' => esc_html( $field->get_string( 'on', __( 'On', 'rank-math' ) ) ), ]; } $field->set_options(); echo $field_type_object->radio_inline(); } /** * Render notices * * @param array $field The passed in `CMB2_Field` object. */ public function render_notice( $field ) { $hash = [ 'error' => 'notice notice-alt notice-error error inline', 'info' => 'notice notice-alt notice-info info inline', 'warning' => 'notice notice-alt notice-warning warning inline', ]; echo '
' . $field->args( 'content' ) . '