$this->add_localized_data();
}
/**
* Add classes to of WordPress admin.
*
* @codeCoverageIgnore
*
* @param string $classes Space-separated list of CSS classes.
*
* @return string
*/
public function body_class( $classes = '' ) {
return $classes . ' ' . join( ' ', $this->classes );
}
/**
* Save anything you want using onsave function.
*
* @codeCoverageIgnore
*/
public function save() {
call_user_func( $this->onsave, $this );
}
/**
* Contextual Help.
*
* @codeCoverageIgnore
*/
public function contextual_help() {
$screen = get_current_screen();
foreach ( $this->help as $tab_id => $tab ) {
$tab['id'] = $tab_id;
$tab['content'] = $this->get_help_content( $tab );
$screen->add_help_tab( $tab );
}
}
/**
* Render admin page content using render function you passed in config.
*
* @codeCoverageIgnore
*/
public function display() {
if ( is_null( $this->render ) ) {
return;
}
if ( 'settings' === $this->render ) {
return $this->display_settings();
}
if ( is_callable( $this->render ) ) {
call_user_func( $this->render, $this );
return;
}
if ( is_string( $this->render ) ) {
include_once $this->render;
}
}
/**
* Is the page is currrent page.
*
* @return bool
*/
public function is_current_page() {
return Param::get( 'page' ) === $this->id;
}
/**
* Enqueue styles
*
* @codeCoverageIgnore
*/
private function enqueue_styles() {
if ( ! isset( $this->assets['styles'] ) || empty( $this->assets['styles'] ) ) {
return;
}
foreach ( $this->assets['styles'] as $handle => $src ) {
wp_enqueue_style( $handle, $src, null, rank_math()->version );
}
}
/**
* Enqueue scripts.
*
* @codeCoverageIgnore
*/
private function enqueue_scripts() {
if ( ! isset( $this->assets['scripts'] ) || empty( $this->assets['scripts'] ) ) {
return;
}
foreach ( $this->assets['scripts'] as $handle => $src ) {
wp_enqueue_script( $handle, $src, null, rank_math()->version, true );
}
}
/**
* Get tab content
*
* @codeCoverageIgnore
*
* @param array $tab Tab to get content for.
*
* @return string
*/
private function get_help_content( $tab ) {
ob_start();
// If it is a function.
if ( isset( $tab['content'] ) && is_callable( $tab['content'] ) ) {
call_user_func( $tab['content'] );
}
// If it is a file.
if ( isset( $tab['view'] ) && $tab['view'] ) {
require $tab['view'];
}
return ob_get_clean();
}
/**
* Localized data.
*/
private function add_localized_data() {
if ( empty( $this->assets['json'] ) ) {
return;
}
foreach ( $this->assets['json'] as $key => $value ) {
Helper::add_json( $key, $value );
}
Helper::add_json(
'settings',
[
'general' => Helper::get_settings( 'general' ),
'titles' => Helper::get_settings( 'titles' ),
'sitemap' => Helper::get_settings( 'sitemap' ),
]
);
}
/**
* Display settings.
*/
private function display_settings() {
rank_math()->admin->display_admin_header();
echo '';
}
}