*/ namespace RankMath_Monitor; use MyThemeShop\Helpers\Str; use RankMath_Monitor\Admin\Admin_Helper; defined( 'ABSPATH' ) || exit; /** * CMB2 class. */ class CMB2 { /** * Set field arguments based on type. * * @param CMB2 $cmb CMB2 metabox object. */ public static function pre_init( $cmb ) { foreach ( $cmb->prop( 'fields' ) as $id => $field_args ) { $type = $field_args['type']; $field = $cmb->get_field( $id ); if ( in_array( $type, array( 'meta_tab_container_open', 'tab_container_open', 'tab_container_close', 'tab_open', 'tab_close', 'raw' ) ) ) { $field->args['save_field'] = false; $field->args['render_row_cb'] = array( '\RankMath_Monitor\CMB2', "render_{$type}" ); } if ( 'notice' === $type ) { $field->args['save_field'] = false; } if ( ! empty( $field_args['dep'] ) ) { self::set_dependencies( $field, $field_args ); } } } /** * Generate the dependency html for JavaScript. * * @param CMB2_Field $field CMB2 field object. * @param array $args Dependency array. */ private static function set_dependencies( $field, $args ) { if ( ! isset( $args['dep'] ) || empty( $args['dep'] ) ) { return; } $dependency = ''; $relation = 'OR'; if ( 'relation' === key( $args['dep'] ) ) { $relation = current( $args['dep'] ); unset( $args['dep']['relation'] ); } foreach ( $args['dep'] as $dependence ) { $compasrison = isset( $dependence[2] ) ? $dependence[2] : '='; $dependency .= ''; } $where = 'group' === $args['type'] ? 'after_group' : 'after_field'; $field->args[ $where ] = ''; } /** * Get the object type for the current page, based on the $pagenow global. * * @see CMB2->current_object_type() * * @return string Page object type name. */ public static function current_object_type() { global $pagenow; $type = 'post'; if ( in_array( $pagenow, array( 'user-edit.php', 'profile.php', 'user-new.php' ), true ) ) { $type = 'user'; } if ( in_array( $pagenow, array( 'edit-comments.php', 'comment.php' ), true ) ) { $type = 'comment'; } if ( in_array( $pagenow, array( 'edit-tags.php', 'term.php' ), true ) ) { $type = 'term'; } if ( defined( 'DOING_AJAX' ) && isset( $_POST['action'] ) && 'add-tag' === $_POST['action'] ) { $type = 'term'; } return $type; } /** * Render raw field. * * @param array $field_args Array of field arguments. * @param CMB2_Field $field The field object. * @return CMB2_Field */ public static function render_raw( $field_args, $field ) { if ( $field->args( 'file' ) ) { include $field->args( 'file' ); } elseif ( $field->args( 'content' ) ) { echo $field->args( 'content' ); } return $field; } /** * Render tab container opening
for option panel. * * @param array $field_args Array of field arguments. * @param CMB2_Field $field The field object. * @return CMB2_Field */ public static function render_tab_container_open( $field_args, $field ) { $active = ! empty( $_GET['rank-math-tab'] ) ? $_GET['rank-math-tab'] : 'general'; echo '
'; ?>
args( 'tabs' ) as $id => $tab ) : if ( empty( $tab ) ) { continue; } if ( isset( $tab['type'] ) && 'seprator' === $tab['type'] ) { printf( '%s', $tab['title'] ); continue; } ?> >
for metabox. * * @param array $field_args Array of field arguments. * @param CMB2_Field $field The field object. * @return CMB2_Field */ public static function render_meta_tab_container_open( $field_args, $field ) { echo '
'; if ( Admin_Helper::is_term_profile_page() ) : ?>

args( 'tabs' ) as $id => $tab ) : if ( empty( $tab ) ) { continue; } ?>
. * * @param array $field_args Array of field arguments. * @param CMB2_Field $field The field object. * @return CMB2_Field */ public static function render_tab_container_close( $field_args, $field ) { echo '
'; echo '
'; return $field; } /** * Render tab content opening
. * * @param array $field_args Array of field arguments. * @param CMB2_Field $field The field object. * @return CMB2_Field */ public static function render_tab_open( $field_args, $field ) { echo '
'; return $field; } /** * Render tab content closing
. * * @param array $field_args Array of field arguments. * @param CMB2_Field $field The field object. * @return CMB2_Field */ public static function render_tab_close( $field_args, $field ) { echo '
'; return $field; } /** * Handles sanitization for HTML entities. * * @param mixed $value The unsanitized value from the form. * @return mixed Sanitized value to be stored. */ public static function sanitize_htmlentities( $value ) { return htmlentities( $value ); } /** * Handles sanitization for webmaster tag and remove tag. * * @param mixed $value The unsanitized value from the form. * @return mixed Sanitized value to be stored. */ public static function sanitize_webmaster_tags( $value ) { $value = trim( $value ); if ( ! empty( $value ) && Str::starts_with( '