Exemplo n.º 1
0
/**
 * Visual Composer component.
 *
 * We're firing a bit late because we want to come after all
 * custom post types and taxonomies have been registered.
 *
 * @since  1.0.0
 */
function mm_vc_posts()
{
    // Only proceed if we're in the admin and Visual Composer is active.
    if (!is_admin()) {
        return;
    }
    if (!function_exists('vc_map')) {
        return;
    }
    $query_types = mm_get_query_types_for_vc('mm-posts');
    $titles = mm_get_post_titles_for_vc('mm-posts');
    $post_types = mm_get_post_types_for_vc('mm-posts');
    $taxonomies = mm_get_taxonomies_for_vc('mm-posts');
    $heading_levels = mm_get_heading_levels_for_vc('mm-posts');
    $image_sizes = mm_get_image_sizes_for_vc('mm-posts');
    $templates = mm_get_mm_posts_templates_for_vc('mm-posts');
    // Grab post type values with capital letters for description and title fields.
    $post_types_formatted = mm_get_post_types('mm-posts ');
    // Modify the array of post titles for better formatting.
    $last = array_slice($post_types_formatted, -1);
    $first = join(', ', array_slice($post_types_formatted, 0, -1));
    $both = array_filter(array_merge(array($first), $last), 'strlen');
    $formatted_titles = join(' or ', $both);
    $fomatted_plural_titles = str_replace(array(',', ' or'), array('s,', 's or'), trim($formatted_titles)) . 's';
    $title_heading = sprintf(__('Enter the Title(s) of Specific %s to Display', 'mm-components'), esc_html($fomatted_plural_titles));
    $title_description = sprintf(__('Enter a specific %s to display', 'mm-components'), esc_html($formatted_titles));
    vc_map(array('name' => __('Posts', 'mm-components'), 'base' => 'mm_posts', 'class' => '', 'icon' => MM_COMPONENTS_ASSETS_URL . 'component-icon.png', 'category' => __('Content', 'mm-components'), 'admin_enqueue_css' => MM_COMPONENTS_URL . '/css/post-titles-autocomplete.css', 'params' => array(array('type' => 'dropdown', 'heading' => __('Selection Type', 'mm-components'), 'param_name' => 'query_type', 'description' => __('Select posts by title or select posts of a specific type, taxonomy or term', 'mm-components'), 'value' => $query_types), array('type' => 'autocomplete', 'heading' => $title_heading, 'param_name' => 'post_ids', 'description' => $title_description, 'settings' => array('values' => $titles), 'dependency' => array('element' => 'query_type', 'value' => array('specific'))), array('type' => 'dropdown', 'heading' => __('Post Type', 'mm-components'), 'param_name' => 'post_type', 'description' => __('Select a post type to display multiple posts', 'mm-components'), 'value' => $post_types, 'dependency' => array('element' => 'query_type', 'value' => array('collection'))), array('type' => 'dropdown', 'heading' => __('Taxonomy', 'mm-components'), 'param_name' => 'taxonomy', 'description' => __('Select a taxonomy and term to only include posts that have the term', 'mm-components'), 'value' => $taxonomies, 'dependency' => array('element' => 'query_type', 'value' => array('collection'))), array('type' => 'textfield', 'heading' => __('Term', 'mm-components'), 'param_name' => 'term', 'description' => __('Specify a term in the selected taxonomy to only include posts that have the term', 'mm-components'), 'value' => '', 'dependency' => array('element' => 'query_type', 'value' => array('collection'))), array('type' => 'dropdown', 'heading' => __('Heading Level', 'mm-components'), 'param_name' => 'heading_level', 'description' => __('Select the post title heading level', 'mm-components'), 'value' => $heading_levels), array('type' => 'textfield', 'heading' => __('Posts Per Page', 'mm-components'), 'param_name' => 'per_page', 'description' => __('Specify the maximum number of posts to show at once', 'mm-components'), 'value' => '10'), array('type' => 'dropdown', 'heading' => __('Pagination', 'mm-components'), 'param_name' => 'pagination', 'value' => array(__('None', 'mm-components') => '', __('Next/Prev', 'mm-components') => 'next-prev', __('Page Numbers', 'mm-components') => 'page-numbers')), array('type' => 'checkbox', 'heading' => __('Show the Featured Image?', 'mm-components'), 'param_name' => 'show_featured_image', 'value' => array(__('Yes', 'mm-components') => 1)), array('type' => 'dropdown', 'heading' => __('Featured Image Size', 'mm-components'), 'param_name' => 'featured_image_size', 'value' => $image_sizes, 'dependency' => array('element' => 'show_featured_image', 'not_empty' => true)), array('type' => 'dropdown', 'heading' => __('Template', 'mm-components'), 'param_name' => 'template', 'description' => __('Select a custom template for custom output', 'mm-components'), 'value' => $templates), array('type' => 'checkbox', 'heading' => __('Use Masonry?', 'mm-components'), 'param_name' => 'masonry', 'value' => array(__('Yes', 'mm-components') => 1)), array('type' => 'checkbox', 'heading' => __('Link Title?', 'mm-components'), 'param_name' => 'link_title', 'std' => 1, 'value' => array(__('Yes', 'mm-components') => 1)), array('type' => 'checkbox', 'heading' => __('Show post info?', 'mm-components'), 'param_name' => 'show_post_info', 'description' => __('Default post info output includes post date and author.', 'mm-components'), 'value' => array(__('Yes', 'mm-components') => 1)), array('type' => 'checkbox', 'heading' => __('Show post meta?', 'mm-components'), 'param_name' => 'show_post_meta', 'description' => __('Default post meta output includes category and tag links.', 'mm-components'), 'value' => array(__('Yes', 'mm-components') => 1)), array('type' => 'checkbox', 'heading' => __('Use full post content?', 'mm-components'), 'param_name' => 'use_post_content', 'description' => __('By default the excerpt will be used. Check this to output the full post content.', 'mm-components'), 'value' => array(__('Yes', 'mm-components') => 1)))));
    // Because this component is registered on init we will call a custom action here
    // so that any templates adding extra params have a better hook to add them on.
    do_action('mm_posts_register_extra_vc_params');
}
Exemplo n.º 2
0
/**
 * Register UI for Shortcake.
 *
 * @since  1.0.0
*/
function mm_components_mm_posts_shortcode_ui()
{
    if (!function_exists('shortcode_ui_register_for_shortcode')) {
        return;
    }
    $post_types = mm_get_post_types('mm-posts');
    $image_sizes = mm_get_image_sizes('mm-posts');
    $taxonomies = mm_get_taxonomies('mm-posts');
    $templates = mm_get_mm_posts_templates('mm-posts');
    shortcode_ui_register_for_shortcode('mm_posts', array('label' => esc_html__('Mm Posts', 'mm-components'), 'listItemImage' => MM_COMPONENTS_ASSETS_URL . 'component-icon.png', 'attrs' => array(array('label' => esc_html('Post ID', 'mm-components'), 'description' => esc_html__('Enter a post ID to display a single post', 'mm-components'), 'attr' => 'post_id', 'type' => 'text'), array('label' => esc_html__('Post Type', 'mm-components'), 'description' => esc_html__('Select a post type to display multiple posts', 'mm-components'), 'attr' => 'post_type', 'type' => 'select', 'options' => $post_types), array('label' => esc_html__('Taxonomy', 'mm-components'), 'description' => esc_html__('Select a taxonomy and term to only include posts that have the term', 'mm-components'), 'attr' => 'taxonomy', 'type' => 'select', 'options' => $taxonomies), array('label' => esc_html__('Term', 'mm-components'), 'description' => esc_html__('Specify a term in the selected taxonomy to only include posts that have the term', 'mm-components'), 'attr' => 'term', 'type' => 'text'), array('label' => esc_html__('Posts Per Page', 'mm-components'), 'description' => esc_html__('Specify the maximum number of posts to show at once', 'mm-components'), 'value' => '10', 'attr' => 'per_page', 'type' => 'text'), array('label' => esc_html__('Pagination', 'mm-components'), 'attr' => 'pagination', 'type' => 'select', 'options' => array('' => esc_html__('None', 'mm-components'), 'next-prev' => esc_html__('Next/Prev', 'mm-components'), 'page-numbers' => esc_html__('Page Numbers', 'mm-components'))), array('label' => esc_html__('Template', 'mm-components'), 'description' => esc_html__('Select a custom template for custom output', 'mm-components'), 'attr' => 'template', 'type' => 'select', 'options' => $templates), array('label' => esc_html__('Use Masonry?', 'mm-button'), 'attr' => 'masonry', 'type' => 'checkbox'), array('label' => esc_html__('Show the Featured Image?', 'mm-button'), 'attr' => 'show_featured_image', 'type' => 'checkbox'), array('label' => esc_html__('Featured Image Size', 'mm-components'), 'attr' => 'featured_image_size', 'type' => 'select', 'options' => $image_sizes), array('label' => esc_html__('Show post info?', 'mm-button'), 'description' => esc_html__('Default post info output includes post date and author.', 'mm-components'), 'attr' => 'show_post_info', 'type' => 'checkbox'), array('label' => esc_html__('Show post meta?', 'mm-button'), 'description' => esc_html__('Default post meta output includes category and tag links.', 'mm-components'), 'attr' => 'show_post_meta', 'type' => 'checkbox'), array('label' => esc_html__('Use full post content?', 'mm-button'), 'description' => esc_html__('By default the excerpt will be used. Check this to output the full post content.', 'mm-components'), 'attr' => 'use_post_content', 'type' => 'checkbox'))));
}
Exemplo n.º 3
0
/**
 * Return an array of post/page titles for use in a Visual Composer autocomplete param.
 *
 * @since   1.0.0
 *
 * @param   string  $context  The context to pass to our filter.
 *
 * @return  array             The array of formatted titles.
 */
function mm_get_post_titles_for_vc($context = '')
{
    // Grab the posts.
    $posts = get_posts(array('posts_per_page' => -1, 'post_type' => mm_get_post_types('mm-components')));
    $post_titles = array();
    foreach ($posts as $post) {
        $post_label = sprintf('<strong>%s</strong> %s', ucwords($post->post_type), $post->post_title);
        $post_titles[] = array('value' => $post->ID, 'label' => $post_label);
    }
    return apply_filters('mm_post_titles', $post_titles, $context);
}
Exemplo n.º 4
0
/**
 * Return an array of post types for use in a Visual Composer dropdown param.
 *
 * @since   1.0.0
 *
 * @param   string  $context  The context to pass to our filter.
 *
 * @return  array             The array of formatted post types.
 */
function mm_get_post_types_for_vc($context = '')
{
    return array_flip(mm_get_post_types($context));
}