' . wp_kses( $description, self::get_allowed_html_for_wp_kses_from_content( $description ) ) . '
' : '';
$extra_link_tabs = '';
foreach ( $extra_links as $extra_link_text => $extra_link ) {
$extra_link_tabs .= '
';
}
/**
* Retrieves a specific tab's content based on the provided key and tab type.
*
* @since 2.8.3
*
* This function dynamically loads content for a specified tab type (e.g., tutorials, premium services)
* based on a given configuration key. It uses a mapping to fetch the correct tab content, which is then
* wrapped in a `
` element with a `data-tab-type` attribute for identification.
*
* @param string $key The configuration key used to retrieve tab settings.
* @param string $tab_type The type of tab to retrieve (e.g., 'tutorials', 'premium-services').
*
* @return string|null The HTML content for the specified tab, or null if the tab or key is not found.
*
* Usage:
* ```
* echo wp_kses_post( Util_Ui::get_tab('example_key', 'tutorials'); // Retrieves the tutorials tab for 'example_key'
* ```
*/
public static function get_tab( string $key, string $tab_type ): ?string {
// If for any reason the key or tab type is empty, return an empty string.
if ( empty( $key ) || empty( $tab_type ) ) {
return '';
}
require_once 'ConfigSettingsTabs.php';
$configs = Config_Tab_Settings::get_config( $key );
// Define a mapping of tab types to the corresponding config keys.
$tab_mapping = array(
'help' => 'help',
'premium-services' => 'premium_support',
);
// Check if the provided tab type exists in the mapping and in the configs.
if ( isset( $tab_mapping[ $tab_type ] ) && isset( $configs['tabs'][ $tab_mapping[ $tab_type ] ] ) ) {
return '
' . $configs['tabs'][ $tab_mapping[ $tab_type ] ] . '
';
}
return null;
}
/**
* Config save button.
*
* @param string $id ID.
* @param string $extra Extra.
*
* @return void
*/
public static function button_config_save( $id = '', $extra = '' ) {
$b1_id = 'w3tc_save_options_' . $id;
$b2_id = 'w3tc_default_save_and_flush_' . $id;
$nonce_field = self::nonce_field( 'w3tc' );
$nonce_html = wp_kses( $nonce_field, self::get_allowed_html_for_wp_kses_from_content( $nonce_field ) );
$extra_html = wp_kses( $extra, self::get_allowed_html_for_wp_kses_from_content( $extra ) );
?>
';
}
?>
is_sealed( $key ) ) {
echo 'disabled="disabled" ';
}
}
/**
* Returns nonce field HTML
*
* @param string|int $action Action.
* @param string $name Name.
* @param bool $referer Referrer.
*
* @return string
*/
public static function nonce_field( $action = -1, $name = '_wpnonce', $referer = true ) {
$return = '
';
if ( $referer ) {
$return .= wp_referer_field( false );
}
return $return;
}
/**
* Returns an notification box
*
* @param string $message Message.
* @param string $id Adds an id to the notification box.
*
* @return string
*/
public static function get_notification_box( $message, $id = '' ) {
$page_val = Util_Request::get_string( 'page' );
if ( empty( $page_val ) || ( ! empty( $page_val ) && 'w3tc_' !== substr( $page_val, 0, 5 ) ) ) {
$logo = sprintf(
'

"',
esc_url( plugins_url( '/pub/img/W3TC_dashboard_logo_title.png', W3TC_FILE ) ) . ''
);
} else {
$logo = '';
}
return sprintf(
'
%s
',
$id ? 'id="' . esc_attr( $id ) . '"' : '',
$logo . wp_kses( $message, self::get_allowed_html_for_wp_kses_from_content( $message ) )
);
}
/**
* Echos an notification box
*
* @param string $message Message.
* @param string $id adds an id to the notification box.
*
* @return void
*/
public static function e_notification_box( $message, $id = '' ) {
$notification_box = self::get_notification_box( $message, $id );
echo wp_kses(
$notification_box,
self::get_allowed_html_for_wp_kses_from_content( $notification_box )
);
}
/**
* Echos an error box.
*
* @param string $message Message.
* @param string $id Id.
*
* @return void
*/
public static function error_box( $message, $id = '' ) {
$page_val = Util_Request::get_string( 'page' );
if ( empty( $page_val ) || ( ! empty( $page_val ) && 'w3tc_' !== substr( $page_val, 0, 5 ) ) ) {
$logo = sprintf(
'

',
esc_url( plugins_url( '/pub/img/W3TC_dashboard_logo_title.png', W3TC_FILE ) . '' )
);
} else {
$logo = '';
}
$v = sprintf(
'
%s
',
$id ? 'id="' . esc_attr( $id ) . '"' : '',
$logo . wp_kses( $message, self::get_allowed_html_for_wp_kses_from_content( $message ) )
);
echo wp_kses(
$v,
self::get_allowed_html_for_wp_kses_from_content( $v )
);
}
/**
* Format bytes into B, KB, MB, GB and TB
*
* phpcs:disable Squiz.PHP.CommentedOutCode.Found
*
* @param int $bytes Bytes.
* @param int $precision Precision.
*
* @return string
*/
public static function format_bytes( $bytes, $precision = 2 ) {
$units = array( 'B', 'KB', 'MB', 'GB', 'TB' );
$bytes = max( $bytes, 0 );
$pow = floor( ( $bytes ? log( $bytes ) : 0 ) / log( 1024 ) );
$pow = min( $pow, count( $units ) - 1 );
// Uncomment one of the following alternatives.
$bytes /= pow( 1024, $pow );
// $bytes /= ( 1 << ( 10 * $pow ) );
return round( $bytes, $precision ) . ' ' . $units[ $pow ];
}
/**
* Format mbytes into B, KB, MB, GB and TB
*
* phpcs:disable Squiz.PHP.CommentedOutCode.Found
*
* @param int $bytes Bytes.
* @param int $precision Precision.
*
* @return string
*/
public static function format_mbytes( $bytes, $precision = 2 ) {
$units = array( 'B', 'KB', 'MB', 'GB', 'TB' );
$bytes = max( $bytes, 0 );
$pow = floor( ( $bytes ? log( $bytes ) : 0 ) / log( 1024 ) );
$pow = min( $pow, count( $units ) - 1 );
// Uncomment one of the following alternatives.
$bytes /= pow( 1024, $pow );
// $bytes /= ( 1 << ( 10 * $pow ) );
return round( $bytes, $precision ) . ' ' . $units[ $pow + 2 ];
}
/**
* Returns an hidden input text element
*
* @param string $id ID.
* @param string $name Name.
* @param string $value Value.
*
* @return string
*/
public static function r_hidden( $id, $name, $value ) {
return '
';
}
/**
* Echos a hidden input text element
*
* @param string $id ID.
* @param string $name Name.
* @param string $value Value.
*
* @return void
*/
public static function hidden( $id, $name, $value ) {
$hidden = self::r_hidden( $id, $name, $value );
echo wp_kses(
$hidden,
self::get_allowed_html_for_wp_kses_from_content( $hidden )
);
}
/**
* Echos an label element
*
* @param string $id ID.
* @param string $text Text.
*
* @return void
*/
public static function label( $id, $text ) {
$label = '
';
echo wp_kses(
$label,
self::get_allowed_html_for_wp_kses_from_content( $label )
);
}
/**
* Echos an input text element
*
* @param string $id ID.
* @param string $name Name.
* @param string $value Value.
* @param bool $disabled Disabled.
* @param int $size Size.
* @param string $type Type.
* @param string $placeholder Placeholder.
*
* @return void
*/
public static function textbox( $id, $name, $value, $disabled = false, $size = 40, $type = 'text', $placeholder = '' ) {
$placeholder = ! empty( $placeholder ) ? ' placeholder="' . esc_attr( $placeholder ) . '"' : '';
echo '
';
}
/**
* Echos an input password element
*
* @param string $id ID.
* @param string $name Name.
* @param string $value Value.
* @param bool $disabled Diabled.
* @param int $size Size.
*
* @return void
*/
public static function passwordbox( $id, $name, $value, $disabled = false, $size = 40 ) {
echo '
';
}
/**
* Echoes a select element.
*
* @param string $id The ID attribute for the select element.
* @param string $name The name attribute for the select element.
* @param string $value The selected value.
* @param array $values An array of options, where the key is the option value and the value is the label.
* @param bool $disabled Whether the select element should be disabled. Default false.
* @param array $optgroups {
* Optional. An associative array of optgroup labels.
*
* @type int|string $key The optgroup identifier.
* @type string $label The label for the optgroup.
* }
*
* @return void
*/
public static function selectbox( $id, $name, $value, $values, $disabled = false, $optgroups = null ) {
echo '
';
}
/**
* Echos a select option
*
* @param string $key Key.
* @param string $selected_value Name.
* @param string $descriptor Descriptor.
*
* @return void
*/
private static function option( $key, $selected_value, $descriptor ) {
if ( ! is_array( $descriptor ) ) {
$label = $descriptor;
$disabled = false;
} else {
$label = $descriptor['label'];
$disabled = ! empty( $descriptor['disabled'] );
}
echo '
' . "\n";
}
/**
* Echos a group of radio elements values: value => label pair or value => array(label, disabled, postfix).
*
* @param string $name Name.
* @param string $value Value.
* @param array $values {
* Values.
*
* @type string $label Label for the radio button.
* @type bool $disabled Whether the radio button is disabled.
* @type string $postfix Postfix to be appended to the label.
* @type bool $pro_feature Whether the radio button is a pro feature.
* @type string $pro_excerpt Excerpt for pro feature description.
* @type string $pro_description Full description for the pro feature.
* @type string $intro_label Intro label for pro feature.
* @type string $score Score associated with the pro feature.
* @type string $score_label Label for the score.
* @type string $score_description Description for the score.
* @type string $score_link Link related to the score.
* @type bool $show_learn_more Whether to show the "learn more" option for the pro feature.
* }
* @param bool $disabled Disabled flag for all radio buttons.
* @param string $separator Separator to be used between radio buttons.
*
* @return void
*/
public static function radiogroup( $name, $value, $values, $disabled = false, $separator = '' ) {
$c = Dispatcher::config();
$is_pro = Util_Environment::is_w3tc_pro( $c );
$first = true;
foreach ( $values as $key => $label_or_array ) {
if ( $first ) {
$first = false;
} else {
echo wp_kses(
$separator,
self::get_allowed_html_for_wp_kses_from_content( $separator )
);
}
$label = '';
$item_disabled = false;
$postfix = '';
$pro_feature = false;
if ( ! is_array( $label_or_array ) ) {
$label = $label_or_array;
} else {
$label = $label_or_array['label'];
$item_disabled = $label_or_array['disabled'];
$postfix = isset( $label_or_array['postfix'] ) ? $label_or_array['postfix'] : '';
$pro_feature = isset( $label_or_array['pro_feature'] ) ? $label_or_array['pro_feature'] : false;
}
if ( $pro_feature ) {
self::pro_wrap_maybe_start();
}
echo '
' .
wp_kses( $postfix, self::get_allowed_html_for_wp_kses_from_content( $postfix ) ) . "\n";
if ( $pro_feature ) {
self::pro_wrap_description(
$label_or_array['pro_excerpt'],
$label_or_array['pro_description'],
$name . '__' . $key
);
if ( ! $is_pro && isset( $label_or_array['intro_label'] ) && isset( $label_or_array['score'] ) && isset( $label_or_array['score_label'] ) && isset( $label_or_array['score_description'] ) && isset( $label_or_array['score_link'] ) ) {
$score_block = self::get_score_block( $label_or_array['intro_label'], $label_or_array['score'], $label_or_array['score_label'], $label_or_array['score_description'], $label_or_array['score_link'] );
echo wp_kses( $score_block, self::get_allowed_html_for_wp_kses_from_content( $score_block ) );
}
$show_learn_more = isset( $label_or_array['show_learn_more'] ) && is_bool( $label_or_array['show_learn_more'] ) ? $label_or_array['show_learn_more'] : true;
self::pro_wrap_maybe_end( $name . '__' . $key, $show_learn_more );
}
}
}
/**
* Echos an input text element
*
* @param string $id ID.
* @param string $name Name.
* @param string $value Value.
* @param bool $disabled Disabled.
*
* @return void
*/
public static function textarea( $id, $name, $value, $disabled = false ) {
// The "textarea" element must not have padding around the value.
?>
';
return $score_block;
}
/**
* Prints the Google PageSpeed score block that is built into the config_item_xxx methods.
* This allows for manual printing in places that may need it.
*
* @param string $intro_label Intro Label.
* @param string $score Score Value.
* @param string $score_label Score Label.
* @param string $score_description Score Description.
* @param string $score_link Score Link.
*
* @return void
*/
public static function print_score_block( $intro_label, $score, $score_label, $score_description, $score_link ) {
$score_block = self::get_score_block( $intro_label, $score, $score_label, $score_description, $score_link );
echo wp_kses( $score_block, self::get_allowed_html_for_wp_kses_from_content( $score_block ) );
}
}