/**
 * Build and return the Restricted Content component.
 *
 * @since   1.0.0
 *
 * @param   array  $args  The args.
 *
 * @return  string        The HTML.
 */
function mm_restricted_content($args)
{
    $component = 'mm-restricted-content';
    // Set our defaults and use them as needed.
    $defaults = array('specific_roles' => '', 'roles' => '', 'restricted_content' => '', 'other_content' => '');
    $args = wp_parse_args((array) $args, $defaults);
    // Get clean param values.
    $specific_roles = $args['specific_roles'];
    $roles = strpos($args['roles'], ',') ? explode(',', $args['roles']) : (array) $args['roles'];
    $restricted_content = $args['restricted_content'];
    $other_content = $args['other_content'];
    $valid_user = false;
    // Get Mm classes.
    $mm_classes = apply_filters('mm_components_custom_classes', '', $component, $args);
    if (is_user_logged_in()) {
        if ('' !== $roles[0]) {
            foreach ($roles as $role) {
                if (mm_check_user_role($role)) {
                    $valid_user = true;
                    break;
                }
            }
        } else {
            $valid_user = true;
        }
    }
    $content = $valid_user ? $restricted_content : $other_content;
    $mm_classes .= $valid_user ? ' valid-user' : ' invalid-user';
    if (strpos($content, '<')) {
        /* We have HTML */
        $inner_output = function_exists('wpb_js_remove_wpautop') ? wpb_js_remove_wpautop($content, true) : $content;
    } elseif (mm_is_base64($content)) {
        /* We have a base64 encoded string */
        $inner_output = rawurldecode(base64_decode($content));
    } else {
        /* We have a non-HTML string */
        $inner_output = $content;
    }
    // Return an empty string if we have an invalid user but no invalid user message.
    if (!$valid_user && '' === $other_content) {
        return '';
    }
    ob_start();
    ?>

	<div class="<?php 
    echo esc_attr($mm_classes);
    ?>
">
		<div class="mm-restricted-content-inner">
			<?php 
    echo do_shortcode($inner_output);
    ?>
		</div>
	</div>

	<?php 
    return ob_get_clean();
}
Exemplo n.º 2
0
/**
 * MIGHTYminnow Components
 *
 * Component: Hero Banner
 *
 * @package mm-components
 * @since   1.0.0
 */
function mm_hero_banner($args)
{
    $component = 'mm-hero-banner';
    // Set our defaults and use them as needed.
    $defaults = array('background_image' => '', 'background_position' => 'center center', 'full_height' => 0, 'min_height' => 360, 'overlay_color' => '', 'overlay_opacity' => '0.1', 'text_color' => 'default', 'heading_level' => 'h2', 'heading_text' => '', 'content' => '', 'secondary_content' => '', 'content_align' => 'left', 'button_link' => '', 'button_link_target' => '_self', 'button_text' => '', 'button_style' => '', 'button_border_weight' => 'default', 'button_corner_style' => '', 'button_color' => '');
    $args = wp_parse_args((array) $args, $defaults);
    // Get clean param values.
    $background_image = $args['background_image'];
    $background_position = $args['background_position'];
    $full_height = $args['full_height'];
    $min_height = $args['min_height'];
    $overlay_color = $args['overlay_color'];
    $overlay_opacity = $args['overlay_opacity'];
    $text_color = $args['text_color'];
    $heading_level = $args['heading_level'];
    $heading_text = $args['heading_text'];
    $content = $args['content'];
    $secondary_content = $args['secondary_content'];
    $content_align = $args['content_align'];
    $button_link = $args['button_link'];
    $button_link_target = $args['button_link_target'];
    $button_text = $args['button_text'];
    $button_style = $args['button_style'];
    $button_border_weight = $args['button_border_weight'];
    $button_corner_style = $args['button_corner_style'];
    $button_color = $args['button_color'];
    $heading_output = '';
    $content_output = '';
    $overlay_output = '';
    $button_output = '';
    $secondary_content_output = '';
    // Get Mm classes.
    $mm_classes = apply_filters('mm_components_custom_classes', '', $component, $args);
    $mm_classes .= ' mm-text-align-' . $content_align;
    if (mm_true_or_false($full_height)) {
        $mm_classes .= ' mm-full-window-height';
    }
    // Support the background image being an ID or a URL.
    if (is_numeric($background_image)) {
        $image_size = apply_filters('mm_hero_banner_image_size', 'full');
        $image_array = wp_get_attachment_image_src($background_image, $image_size);
        $image_url = $image_array[0];
    } else {
        $image_url = esc_url($background_image);
    }
    // Build wrapper styles.
    $wrap_styles = array();
    if ($image_url) {
        $wrap_styles[] = "background-image: url({$image_url});";
    }
    if ($background_position) {
        $wrap_styles[] = "background-position: {$background_position};";
    }
    if (1 < (int) $min_height) {
        $wrap_styles[] = 'min-height: ' . (int) $min_height . 'px;';
    }
    $wrap_styles = implode(' ', $wrap_styles);
    // Build background overlay.
    if ($overlay_color) {
        $overlay_styles = array();
        $overlay_styles[] = 'background-color: ' . $overlay_color . ';';
        $overlay_styles[] = 'opacity: ' . (double) $overlay_opacity . ';';
        $overlay_styles[] = 'filter: alpha(opacity=' . (double) $overlay_opacity * 100 . ');';
        $overlay_styles = implode(' ', $overlay_styles);
        $overlay_output = '<div class="hero-overlay" style="' . esc_attr($overlay_styles) . '"></div>';
    }
    // Build the heading.
    if ($heading_text) {
        $heading_output = sprintf('<%s class="hero-heading %s">%s</%s>', esc_html($heading_level), esc_attr('mm-text-color-' . $text_color), esc_html($heading_text), esc_html($heading_level));
    }
    // Build the content.
    if (strpos($content, '<')) {
        /* We have HTML */
        $content_output = function_exists('wpb_js_remove_wpautop') ? wpb_js_remove_wpautop($content, true) : $content;
    } elseif (mm_is_base64($content)) {
        /* We have a base64 encoded string */
        $content_output = rawurldecode(base64_decode($content));
    } else {
        /* We have a non-HTML string */
        $content_output = $content;
    }
    if ($content) {
        $content_output = sprintf('<div class="hero-content %s">%s</div>', esc_attr('mm-text-color-' . $text_color), do_shortcode($content_output));
    }
    // Build the button output.
    if ($button_text) {
        $button_args = array('link' => $button_link, 'link_title' => $button_text, 'link_target' => $button_link_target, 'button_text' => $button_text, 'style' => $button_style, 'corner_style' => $button_corner_style, 'border_weight' => $button_border_weight, 'color' => $button_color, 'alignment' => $content_align);
        $button_output = mm_button($button_args);
    }
    // Handle $secondary_content being HTML, plain text, or a base64 encoded string.
    if (strpos($secondary_content, '<')) {
        /* We have HTML */
        $secondary_content_output = function_exists('wpb_js_remove_wpautop') ? wpb_js_remove_wpautop($secondary_content, true) : $secondary_content;
    } elseif (mm_is_base64($secondary_content)) {
        /* We have a base64 encoded string */
        $secondary_content_output = rawurldecode(base64_decode($secondary_content));
    } else {
        /* We have a non-HTML string */
        $secondary_content_output = $secondary_content;
    }
    if ($secondary_content) {
        $secondary_content_output = sprintf('<div class="hero-secondary-content %s">%s</div>', esc_attr('mm-text-color-' . $text_color), do_shortcode($secondary_content_output));
    }
    ob_start();
    ?>

	<div class="<?php 
    echo esc_attr($mm_classes);
    ?>
" style="<?php 
    echo esc_attr($wrap_styles);
    ?>
">

		<?php 
    echo $overlay_output;
    ?>

		<div class="hero-content-wrap">

			<?php 
    echo wp_kses_post($heading_output);
    ?>

			<?php 
    echo wp_kses_post($content_output);
    ?>

			<?php 
    echo wp_kses_post($button_output);
    ?>

			<?php 
    echo wp_kses_post($secondary_content_output);
    ?>

		</div>
	</div>

	<?php 
    return ob_get_clean();
}