| Server IP : 43.130.17.34 / Your IP : 216.73.217.6 Web Server : nginx/1.28.0 System : Linux VM-4-12-opencloudos 6.6.92-34.1.oc9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 25 21:32:13 CST 2025 x86_64 User : www ( 1000) PHP Version : 8.0.26 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/yespkg.com/wp-content/plugins/admin-menu-editor-pro/customizables/ |
Upload File : |
<?php
namespace YahnisElsts\AdminMenuEditor\Customizable;
abstract class HtmlHelper {
/**
* Generate a HTML tag.
*
* @param string $tagName
* @param array<string,mixed> $attributes
* @param string|null $content
* @return string
*/
public static function tag($tagName, $attributes = array(), $content = null) {
$html = '<' . $tagName;
$charset = self::getCharset();
//Convert array of CSS classes to a space-separated string.
if ( isset($attributes['class']) && is_array($attributes['class']) ) {
$attributes['class'] = implode(' ', $attributes['class']);
}
//Convert [property => value] to an inline style.
if ( isset($attributes['style']) && is_array($attributes['style']) ) {
if ( !empty($attributes['style']) ) {
$styleAttr = '';
foreach ($attributes['style'] as $name => $value) {
$styleAttr .= $name . ':' . $value . ';';
}
$attributes['style'] = $styleAttr;
} else {
unset($attributes['style']);
}
}
$filteredAttributes = array_filter($attributes, array(self::class, 'isNonEmptyAttributeValue'));
//Special case: The empty string is a valid value for the "value" attribute.
//For example, we want this for <option> tags where $('select').val() would otherwise return the option's text.
if ( isset($attributes['value']) && ($attributes['value'] === '') ) {
$filteredAttributes['value'] = $attributes['value'];
}
$attributes = $filteredAttributes;
if ( !empty($attributes) ) {
foreach ($attributes as $name => $value) {
if ( is_scalar($value) ) {
$stringValue = (string)$value;
} else {
$stringValue = wp_json_encode($value);
}
//esc_attr() doesn't double-encode entities and _wp_specialchars()
//is marked as private, so let's use htmlspecialchars() instead.
$html .= ' ' . $name . '="' . htmlspecialchars($stringValue, ENT_QUOTES, $charset) . '"';
}
}
$html .= '>';
if ( $content !== null ) {
$html .= $content . '</' . $tagName . '>';
}
return $html;
}
private static function isNonEmptyAttributeValue($value) {
return ($value !== null) && ($value !== false) && ($value !== '');
}
private static function getCharset() {
static $charset = null;
if ( $charset === null ) {
$charset = get_option('blog_charset', '');
if ( in_array($charset, array('utf8', 'utf-8', 'UTF8')) ) {
$charset = 'UTF-8';
}
}
return $charset;
}
}