<?php

/**
 * Registers 'twitter' post type 
 *
 * This function registers the 'twitter' posts
 * type which is used for the twitter feed.
 *
 * @function team_post_type()
 *
 * @uses register_post_type()
 *
 * @param N/A
 *
 * @return N/A
 *
 * @since 1.3.9 
 *
 */




/**
 * Registers 'departments' taxonomy for 'team' post type 
 *
 * This function registers the 'departments' taxonomy
 * for the 'team' posts type which is used for the
 * meet the team posts.
 *
 * @function team_taxonomy()
 *
 * @uses register_taxonomy()
 *
 * @param N/A
 *
 * @return N/A
 *
 * @since 1.0.0 
 *
 */

function custom_post_twitter() {

    $labels = array(
        'name'                  => _x( 'Twitter', 'Post Type General Name', 'text_domain' ),
        '_name'         => _x( 'Twitter', 'Post Type Singular Name', 'text_domain' ),
        'menu_name'             => __( 'Twitter', 'text_domain' ),
        'name_admin_bar'        => __( 'Twitter', 'text_domain' ),
        'archives'              => __( 'Item Archives', 'text_domain' ),
        'attributes'            => __( 'Item Attributes', 'text' ),
        'parent_item_colon'     => __( 'Parent Item:', 'text_domain' ),
        'all_items'             => __( 'All Items', 'text_domain' ),
        'add_new_item'          => __( 'Add New Item', 'text_domain' ),
        'add_new'               => __( 'Add New', 'text_domain' ),
        'new_item'              => __( 'New Item', 'text_domain' ),
        'edit_item'             => __( 'Edit', 'text_domain' ),
        'update_item'           => __( 'Update Item', 'text_domain' ),
        'view_item'             => __( 'View Item', 'text_domain' ),
        'view_items'            => __( 'View Items', 'text_domain' ),
        'search_items'          => __( 'Search Item', 'text_domain' ),
        'not_found'             => __( 'Not found', 'text_domain' ),
        'not_found_in_trash'    => __( 'Not found in Trash', 'text_domain' ),
        'featured_image'        => __( 'Featured Image', 'text_domain' ),
        'set_featured_image'    => __( 'Set featured image', 'text_domain' ),
        'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
        'use_featured_image'    => __( 'Use as featured image', 'text_domain' ),
        'insert_into_item'      => __( 'Insert into item', 'text_domain' ),
        'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
        'items_list'            => __( 'Items list', 'text_domain' ),
        'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
        'filter_items_list'     => __( 'Filter items list', 'text_domain' ),
    );

    $args = array(
        'label'                 => __( 'Twitter', 'text_domain' ),
        'description'           => __( 'Twitter Custom Post Type', 'text_domain' ),
        'labels'                => $labels,
        'supports'              => array( 'title', 'editor' ),
        'taxonomies'            => array( 'category', 'post_tag' ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        'menu_icon'             => 'dashicons-twitter',
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => true,
        'exclude_from_search'   => false,
        'public_queryable'      => true,
        'capability_type'       => 'post',
        'show_in_rest'          => true,
    );

    register_post_type( 'twitter', $args );

}
add_action( 'init', 'custom_post_twitter', 0 );


/**
 * Returns 'twitter' post type 
 *
 * This function returns the twitter posts
 *
 * @function add_twitter()
 *
 * @uses WP_Query::the_post(), get_template_part()
 *
 * @param N/A
 *
 * @return (string) The 'twitter' posts
 *
 * @since 1.0.0 
 *
 */

/**
 * Returns 'team' post type 
 *
 * This function returns the 'twitter' posts type which
 * is used for the twitter feed. The posts are
 * returned using the twitter template located in the
 * WordPress Theme.
 *
 * @function add_meet_the_team()
 *
 * @uses WP_Query::the_post(), get_template_part()
 *
 * @param N/A
 *
 * @return (string) The 'team' posts
 *
 * @since 1.0.0 
 *
 */
function add_twitter( $var ) {
	
    if (ow_global_var('opt_twitter') == 1) {
		ob_start();
        // Show design related to Twitter shortcode here
        ?>
        <link rel="stylesheet" type="text/css" href="<?php echo WP_PLUGIN_URL ;?>/ow-plugin/css/custom-twitter.css">
        <div class="col-md-6">
            <div class="eapps-twitter-feed-header-inner">
                <?php $twitter_color = get_option('twitter_color');?>
                <div class="eapps-twitter-feed-header-banner-container eapps-twitter-feed-header-banner-container-hide-image" style="background-color: <?php echo $twitter_color; ?>;border-radius: 10px 10px 0 0;"></div>
                <div class="eapps-twitter-feed-header-user">
                    <?php
                        $twitter_linkk = get_option('twitter_linkk');
                    ?>
					        <a rel="nofollow" href="<?php echo $twitter_linkk; ?>" target="_blank" class="eapps-twitter-feed-header-user-image-container">
		<?php $twitter_image = get_option('twitter_image');
if ($twitter_image) {
	echo '<img src="' . esc_attr($twitter_image) . '" class="twitterindividuallogo" />';

}?>
        </a>

                    <div class="eapps-twitter-feed-user-info">
                        <div class="eapps-twitter-feed-header-user-info-name-wrapper">
                            <div class="apps-twitter-feed-header-user-info-name">
                                <a href="<?php echo $twitter_linkk; ?>" target="_blank">
                                    <?php
                                        $twitter_name = get_option('twitter_name');
                                    ?>
                                    <?php echo $twitter_name; ?>
                                </a>
                            </div>
                            <div class="eapps-twitter-feed-header-user-info-screen-name">
                                <a rel="nofollow" href="<?php echo $twitter_linkk; ?>" target="_blank">
                                    <?php
                                        $twitter_subname = get_option('twitter_subname');
                                    ?>
                                    <?php echo $twitter_subname; ?>
                                </a>
                            </div>
                        </div>
                        <a rel="nofollow" href="<?php echo $twitter_linkk; ?>" target="_blank" eapps-link="follow" class="eapps-twitter-feed-header-user-info-follow" style="background-color: <?php echo $twitter_color; ?>">
                <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18">
                    <path
                        d="M16.07 5.388c.219 4.83-3.395 10.216-9.79 10.216A9.765 9.765 0 0 1 1 14.06a6.94 6.94 0 0 0 5.1-1.421 3.446 3.446 0 0 1-3.218-2.385c.54.103 1.07.073 1.555-.06-1.656-.33-2.8-1.82-2.763-3.41.465.258.996.412 1.56.43A3.432 3.432 0 0 1 2.17 2.628a9.788 9.788 0 0 0 7.1 3.589C8.766 4.068 10.4 2 12.624 2c.99 0 1.885.417 2.513 1.084a6.925 6.925 0 0 0 2.188-.833 3.452 3.452 0 0 1-1.515 1.9 6.9 6.9 0 0 0 1.978-.54 6.96 6.96 0 0 1-1.718 1.777z"
                    ></path>
                </svg>
                            <span class="eapps-twitter-feed-header-user-info-follow-label">Follow</span>
                        </a>
                    </div>
                </div>
            </div>


            <div style="overflow-y:auto; overflow-x: hidden; height: 350px;background-color: #eaeaea; padding: 5px; border-radius: 0 0 10px 10px;" >

                <?php
                // Loop codes
                $args = array(
                    'post_type' => 'twitter',
                    'posts_per_page' => 3,
                    'orderby' => 'date',
                    'order' => ''
                );

                $my_query = new WP_Query($args);

                ?>
                <div style="overflow-y:scroll; height:300px;">
                    <?php
                    if($my_query->have_posts()) :
                        while($my_query->have_posts()) : $my_query->the_post(); ?>
                            <h2><?php the_content(); ?></h2>

                        <?php endwhile; 
                    endif;
                    wp_reset_postdata();
                    ?>
                </div>
            </div>
        </div>
    <?php
		return ob_get_clean();
    } else {
        // Show message indicating the feed is not accessible
        echo "Twitter Feed is disabled";
    }
}
add_shortcode('iris_twitter', 'add_twitter');





