Example #1
0
 /**
  * Converts a WPRA level to a Monolog one.
  *
  * @since 4.8.1
  * @param int"string $level A numeric or string representation of a WPRA level.
  *  If is WPRA-prefixed, i.e. a full constant name, the prefix will be removed.
  * @return int The numeric representation of the corresponding Monolog level.
  * @throws \InvalidArgumentException If no such Monolog level defined.
  */
 public static function wpraToMonologLevel($level)
 {
     $wpraPrefix = static::WPRA_LEVEL_PREFIX;
     if (!is_numeric($level) && stripos($level, $wpraPrefix)) {
         $level = substr($level, strlen($wpraPrefix));
     }
     if (is_string($level) || $level > 50) {
         return static::toMonologLevel($level);
     }
     $levels = wprss_log_get_levels();
     if (!isset($levels[$level])) {
         throw new \InvalidArgumentException(sprintf('Monolog Level "%1$s" is not defined', $level));
     }
     $level = $levels[$level];
     return static::toMonologLevel($level);
 }
Example #2
0
/**
 * Renders the 'log_level' setting field.
 * 
 * @param array $field Info about the field
 */
function wprss_setting_log_level_callback($field)
{
    $log_level = wprss_get_general_setting($field['field_id']);
    foreach (wprss_log_get_levels(false) as $_level => $_label) {
        $options[$_level] = $_label;
        if (is_numeric($_level) && $_level / 2 >= 1) {
            $options[(int) $_level * -1] = $_label . ' and below';
        }
    }
    krsort($options, defined('SORT_NATURAL' ? SORT_NATURAL : SORT_STRING));
    ?>
		<select id="<?php 
    echo $field['field_id'];
    ?>
" name="wprss_settings_general[<?php 
    echo $field['field_id'];
    ?>
]">
		<?php 
    foreach ($options as $value => $text) {
        $selected = (string) $value === (string) $log_level ? 'selected="selected"' : '';
        ?>
<option value="<?php 
        echo $value;
        ?>
" <?php 
        echo $selected;
        ?>
><?php 
        echo __($text, WPRSS_TEXT_DOMAIN);
        ?>
</option><?php 
    }
    ?>
		</select>
		<?php 
    echo wprss_settings_inline_help($field['field_id'], $field['tooltip']);
}