<?php

/**
 * Plugin Name: Big Boom Alert Bar
 * Description: Displays an alert message anywhere on your site
 * Version: 1.0.0
 * Author: Big Boom Design
 * Author URI: http://bigboomdesign.com
 */
require_once albar_dir("lib/class-alert-bar.php");
# Admin routines
if (is_admin()) {
    # define sections and fields for options page
    add_action('admin_init', array('Alert_Bar_Options', 'register_settings'));
    # styles and scripts
    add_action('admin_enqueue_scripts', array('Alert_Bar', 'admin_enqueue'));
    # plugin options page
    add_action('admin_menu', 'albar_settings_page');
    function albar_settings_page()
    {
        add_options_page('Alert Bar', 'Alert Bar', 'manage_options', 'albar_settings', array('Alert_Bar_Options', 'settings_page'));
    }
    # Action links on main Plugins screen
    $plugin = plugin_basename(__FILE__);
    add_filter("plugin_action_links_{$plugin}", 'albar_plugin_actions');
    function albar_plugin_actions($links)
    {
        $settings_link = '<a href="options-general.php?page=albar_settings">Settings</a>';
        array_unshift($links, $settings_link);
        return $links;
    }
        extract($setting);
        if (!isset($choices)) {
            return;
        }
        $out = array();
        if (!is_array($choices)) {
            $out[] = array('id' => $name . '_' . self::clean_str_for_field($choices), 'label' => $choices, 'value' => self::clean_str_for_field($choices));
        } else {
            foreach ($choices as $choice) {
                if (!is_array($choice)) {
                    $out[] = array('label' => $choice, 'id' => $name . '_' . self::clean_str_for_field($choice), 'value' => self::clean_str_for_field($choice));
                } else {
                    # if choice is already an array, we need to check for missing data
                    if (!array_key_exists('id', $choice)) {
                        $choice['id'] = $name . '_' . self::clean_str_for_field($choice['label']);
                    }
                    if (!array_key_exists('value', $choice)) {
                        $choice['value'] = $name . '_' . self::clean_str_for_field($choice['label']);
                    }
                    $out[] = $choice;
                }
            }
        }
        return $out;
    }
}
# end class Alert_Bar
# require files for plugin
foreach (Alert_Bar::$classes as $class) {
    Alert_Bar::req_file(albar_dir("lib/class-{$class}.php"));
}