set_help_sidebar( '
' . __('For more information:') . '
' . sprintf('', static::HELP_LINK_DOCS, __('Documentation', 'wp-fail2ban')). sprintf('', static::HELP_LINK_REFERENCE, __('Reference', 'wp-fail2ban')). sprintf('', static::HELP_LINK_SUPPORT, __('Support', 'wp-fail2ban')) ); } /** * Helper: Create dt/dd pair * * @since 4.4.0 Add return type * @since 4.3.3.0 * * @param string $id * @param array $paras * @param string|null $title * * @return string */ protected function help_entry($id, array $paras, $title = null): string { if (is_null($title)) { $title = $this->__[$id]; } $paras = apply_filters("help-entry::{$id}.paras", $paras); $entry = apply_filters("help-entry::{$id}.pre", ''); $entry .= "'.join('
', array_map([$this, 'process_para'], $paras)).'
'; } elseif (is_string($paras)) { return $paras; } else { throw new \InvalidArgumentException(); } } /** * Helper: Create paragraph content * * @since 4.4.0 Add return type * @since 4.3.3.0 * * @param array|string $para * * @return string */ protected function process_para($para): string { if (is_array($para)) { $para = join('%s: %s
%s
wp-config.php;
these tabs reflect those values.', 'wp-fail2ban'),
__('Upgrade to the Premium version to enable this interface.', 'wp-fail2ban')
);
}
/**
* Helper: is this the active tab?
*
* @since 4.4.0 Add return type
* @since 4.3.0
*
* @return bool
*/
protected function isActiveTab(): bool
{
return ($this->tab_name == self::getActiveTab()->getName());
}
/**
* Helper - tab
*
* @since 4.4.0 Add return type
* @since 4.0.0
*
* @param string $slug Tab slug
*
* @return TabBase Tab
*/
public static function getTab($slug): TabBase
{
return self::$tabs[$slug];
}
/**
* Helper - set the default tab.
*
* @since 4.4.0 Add type hint, return type
* @since 4.3.0
*
* @param string $default Default tab slug
*
* @return void
*/
public static function setDefaultTab(string $default): void
{
self::$default_tab = $default;
}
/**
* Helper - current tab
*
* @since 4.4.0 Add return type
* @since 4.0.0
*
* @return TabBase Tab
*/
public static function getActiveTab(): TabBase
{
if (!empty(self::$active_tab)) {
return self::$active_tab;
}
return (self::$active_tab = (array_key_exists($_GET['tab'] ?? '--', self::$tabs))
? self::$tabs[$_GET['tab']]
: self::$tabs[self::$default_tab]
);
}
/**
* Helper - tab name
*
* @since 4.4.0 Add type hint, return type
* @since 4.0.0
*
* @param string $slug Tab slug
*
* @return string Tab name
*/
public static function getTabName(string $slug): string
{
return self::getTab($slug)->getName();
}
/**
* Helper - tab exists?
*
* @since 4.4.0 Add type hint, return type
* @since 4.3.0
*
* @param string $slug Tab slug
*
* @return bool
*/
public static function tabExists(string $slug): bool
{
return array_key_exists($slug, self::$tabs);
}
/**
* Link to documentation
*
* @since 5.0.0 Simplify
* @since 4.4.0 Add type hint, return type
* @since 4.3.0 Protected
* @since 4.2.0
*
* @param string $define
*
* @return string
*/
protected function doc_link(string $define): string
{
$link = <<< HTML
%s
HTML;
return sprintf($link, self::HELP_LINK_REFERENCE, $define, __('Reference', 'wp-fail2ban'), $define);
}
/**
* Standard list of links to docs
*
* @since 4.4.0 Add return type
* @since 4.3.0
*
* @param array $defines List of defines
* @param bool $para Wrap in
*
* @return string HTML
*/
protected function see_also(array $defines, $para = true): string
{
$html = sprintf('%s', __('See also:', 'wp-fail2ban'));
if (1 == count($defines)) {
$html .= ' '.$this->doc_link($defines[0]);
} else {
$html .= sprintf(
'
— %s',
implode('
— ', array_map(function ($i) {
return $this->doc_link($i);
}, $defines))
);
}
if ($para) {
$html = '
'.$html.'
'; } return $html; } /** * id="%s" Helper * * @since 4.4.0 Add type hint, return type * @since 4.3.0 Moved here. * @since 4.0.0 * * @param string $define * * @return string */ protected function field_name(string $define): string { global $wp_fail2ban; return 'wp-fail2ban['.join('][', $wp_fail2ban['config'][$define]['field']).']'; } /** * name="%s" Helper * * @since 4.4.0 Add $suffix, type hint, return type * @since 4.3.0 Moved here. * @since 4.0.0 * * @param string $define * @param string|null $suffix * * @return string */ protected function field_id(string $define, string $suffix = null): string { global $wp_fail2ban; $rv = join('-', $wp_fail2ban['config'][$define]['field']); if (!empty($suffix)) { $rv .= '-'.$suffix; } return $rv; } /** * Helper: checked() * * @since 4.4.0 Add type hints, return type * @since 4.3.0 * * @param string $define * @param mixed $current * @param bool $echo * * @return string */ protected function def_checked(string $define, $current = true, bool $echo = true): string { return checked(Config::get($define), $current, $echo); } /** * NDEF disabled helper * * @since 4.4.0 Add filter, type hints, return type * @since 4.3.0 Add $override; moved here. * @since 4.0.0 * * @param string $define * @param bool $override * * @return string */ protected function ndef_disabled(string $define, bool $override = false): string { return disabled(Config::def($define) || apply_filters("{$define}.ndef_disabled", $override), true, false); } /** * Display standard checkbox * * @since 4.4.0 Add type hints, return type * @since 4.3.0 * * @param string $define Constant * @param bool $show_desc Show description? * @param string $plan Freemius plan * @param bool $echo Echo? * * @return string HTML * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function checkbox(string $define, bool $show_desc = true, string $plan = 'bronze', bool $echo = true): string { $html = sprintf( '', checked(Config::get($define), true, false) ); if ($show_desc) { $html = ''; } if ($echo) { echo $html; } return $html; } /** * Display standard radio buttons * * @since 4.4.0 Add type hints, return type * @since 4.3.3 * * @param array|string $define * @param bool $show_desc * @param string $plan * @param bool $echo * @param string $cssClass * * @return string * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function radio($define, bool $show_desc = true, string $plan = 'bronze', bool $echo = true): string { global $wp_fail2ban; if (is_array($define)) { extract($define); } $html = ''; foreach ($wp_fail2ban['config'][$define]['values'] as $value) { $checked = $this->def_checked($define, $value, false); if ($show_desc) { $html .= "'; } else { $html .= "
"; } $html .= '
'; } if ($echo) { echo $html; } return $html; } /** * Display standard text input * * @since 4.4.0 Add type hints, return type * @since 4.3.0 * * @param string $define Constant * @param bool $show_desc Show description? * @param string $plan Freemius plan * @param bool $echo Echo? * @param string $value Text value * @param string $cssClass CSS class * * @return string HTML * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function inputText(string $define, bool $show_desc = true, string $plan = 'bronze', bool $echo = true, string $value = null, string $cssClass = 'regular-text', string $type = 'text'): string { if (is_null($value)) { $value = Config::get($define); } $html = sprintf( '', $this->field_id($define), $cssClass, $type, esc_attr($value) ); if ($show_desc) { $html .= sprintf('%s
', Config::desc($define)); } if ($echo) { echo $html; } return $html; } /** * Helper: input type=email * * @since 4.4.0 Add type hints, return type * @since 4.3.2.2 * * @param string $define Constant * @param bool $show_desc Show description? * @param string $plan Freemius plan * @param bool $echo Echo? * @param string $value Text value * @param string $cssClass CSS class * * @return string HTML */ protected function inputEmail( string $define, bool $show_desc = true, string $plan = 'bronze', bool $echo = true, string $value = null, string $cssClass = 'regular-text' ) : string { return $this->inputText($define, $show_desc, $plan, $echo, $value, $cssClass, 'email'); } /** * Helper: input type=password * * @since 4.4.0 Add return type * @since 4.3.2.2 * * @param string $define Constant * @param bool $show_desc Show description? * @param string $plan Freemius plan * @param bool $echo Echo? * @param string $value Text value * @param string $cssClass CSS class * * @return string HTML */ protected function inputPassword( string $define, bool $show_desc = true, string $plan = 'bronze', bool $echo = true, string $value = null, string $cssClass = 'regular-text' ) : string { return $this->inputText($define, $show_desc, $plan, $echo, $value, $cssClass, 'password'); } /** * Helper: setting description * * @since 4.4.0 Add type hints, return type * @since 4.3.0 * * @param string $define * @param bool $echo * * @return string */ protected function description(string $define, bool $echo = true): string { if (!is_null($desc = Config::desc($define))) { if ($echo) { echo ''.$desc.'
'; } return $desc; } else { return ''; } } /** * Helper: setting description extended * * @since 5.1.0 * * @param string $define * @param bool $echo * * @return string */ protected function description_ex(string $define, bool $echo = true): string { if (!is_null($desc = Config::desc_ex($define))) { if ($echo) { echo ''.$desc.'
'; } return $desc; } else { return ''; } } }