<?php
   /*
   Plugin Name: Link Directory
   Plugin URI: https://imtejs.com/
   description: This plugin is used to create link directory lilke pligg and plikli. It's alternative to pligg and plikli.
   Version: 0.1
   Author: Tejas Gokani
   Author URI: https://imtejs.com/
   License: GPL2
   */






/********************************** Adding Bootstrap CSS**********************
***********************************************************************************/
function weblinks_enqueue_styles() {
wp_enqueue_style( 'bootstrap', '//stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css' );

}
add_action('wp_enqueue_scripts', 'weblinks_enqueue_styles');

/**************************Creating New  custom post type************************
***************************************************************************************/
include( plugin_dir_path( __FILE__ ) . 'web-links.php');

/****************************Done****************************************************
**************************************************************************************/
/*
add_action('init', 'my_weblink_rewrite'); 
function my_weblink_rewrite() {

    add_permastruct('weblink', '/%customname%/', false);
}

add_filter( 'post_type_link', 'my_weblink_permalinks', 10, 2 );
function my_weblink_permalinks( $permalink, $post ) {
      return str_replace( '%customname%/', $post->post_name, $permalink );
}

register_activation_hook(__FILE__,'my_weblink_plugin_activate');
function my_weblink_plugin_activate() {
    flush_rewrite_rules();
}
*/

/* Filter the single_template with our custom function*/
add_filter('single_template', 'my_weblink_template');


/********************************** Adding Template Function**********************
***********************************************************************************/

function my_weblink_template($template) {
    global $post;
    /* Checks for single template by post type 
    if ( $post->post_type == 'weblink' ) {
        if ( file_exists( PLUGIN_PATH . '/weblink-single.php' ) ) {
            return PLUGIN_PATH . '/weblink-single.php';
        }
		*/
		if ('weblink' == get_post_type(get_queried_object_id()) ) {
        // if you're here, you're on a singlar page for your costum post 
        // type and WP did NOT locate a template, use your own.
        $template = dirname(__FILE__) . '/weblink-single.php';
    }
    return $template;
    }

    //return $single;

/********************************** Weblink Shortcode**********************
***********************************************************************************/

include( plugin_dir_path( __FILE__ ) . 'show_allweblink_shortcode.php');


/********************************** Form Shortcode**********************
***********************************************************************************/

include( plugin_dir_path( __FILE__ ) . 'show_weblinkform_shortcode.php');

/********************************** Show and edit Shortcode**********************
***********************************************************************************/

include( plugin_dir_path( __FILE__ ) . 'showandeditweblink.php');



?>