Exemplo n.º 1
0
/**
 * Register Widgets
 *
 * Include and register widgets that theme supports.
 *
 * @since 0.9
 */
function ctfw_register_widgets()
{
    // Available widgets
    $widgets = ctfw_widgets();
    // Church Theme Content plugin is installed and activated?
    $ctc_active = ctfw_ctc_plugin_active();
    // Loop widgets
    foreach ($widgets as $widget_id => $widget_data) {
        // Theme supports widget and required features?
        $supported = true;
        $theme_support = array_merge((array) $widget_data['theme_support'], (array) $widget_data['theme_support_required']);
        foreach ($theme_support as $feature) {
            if (!empty($feature) && !current_theme_supports($feature)) {
                // support can be empt / not required (filtering in a non-framework widget)
                $supported = false;
                // one strike and you're out
                break;
            }
        }
        // Theme support is okay
        if ($supported) {
            // Church Theme Content is active or not required for widget
            if (empty($widget_data['ctc_required']) || $ctc_active) {
                // Include class if exists
                $widget_class_paths = array(trailingslashit(CTFW_THEME_CLASS_DIR) . $widget_data['class_file'], trailingslashit(CTFW_CLASS_DIR) . $widget_data['class_file']);
                if (locate_template($widget_class_paths, true)) {
                    // includes and returns true if exists
                    // Register the widget
                    register_widget($widget_data['class']);
                    // Unregister widgets it replaces
                    if (isset($widget_data['unregister'])) {
                        foreach ($widget_data['unregister'] as $unregister_widget) {
                            unregister_widget($unregister_widget);
                        }
                    }
                }
            }
        }
    }
}
/**
 * Admin notice
 *
 * Show notice at top of admin until plugin is both installed and activated.
 *
 * @since 0.9
 */
function ctfw_ctc_plugin_notice()
{
    // Show only on relevant pages as not to overwhelm the admin
    $screen = get_current_screen();
    if (!in_array($screen->base, array('dashboard', 'themes', 'plugins'))) {
        return;
    }
    // Prevent plugins (CTC add-ons) from showing similar notice
    // Make sure this is always after last return above, meaning a notice is being shown
    if (!empty($GLOBALS['ctc_install_notice_sent'])) {
        return;
    } else {
        $GLOBALS['ctc_install_notice_sent'] = true;
    }
    // Plugin not installed
    if (!ctfw_ctc_plugin_installed() && current_user_can('install_plugins')) {
        $notice = sprintf(__('<b>Plugin Required:</b> Please install and activate the <a href="%s" class="thickbox">Church Theme Content</a> plugin to use with the current theme.', 'church-theme-framework'), network_admin_url('plugin-install.php?tab=plugin-information&plugin=' . ctfw_ctc_plugin_slug() . '&TB_iframe=true&width=700&height=450'));
    } elseif (!ctfw_ctc_plugin_active() && current_user_can('activate_plugins')) {
        $notice = sprintf(__('Please <a href="%s">activate</a> the <b>Church Theme Content</b> plugin required by the current theme.', 'church-theme-framework'), wp_nonce_url(self_admin_url('plugins.php?action=activate&plugin=' . ctfw_ctc_plugin_file()), 'activate-plugin_' . ctfw_ctc_plugin_file()));
    }
    // Show notice
    if (isset($notice)) {
        ?>
		<div class="error">
			<p>
				<?php 
        echo $notice;
        ?>
			</p>
		</div>
		<?php 
    }
}