wp/wp-content/plugins/portfolio/portfolio.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 12 d8a8807227e4
--- a/wp/wp-content/plugins/portfolio/portfolio.php	Tue Jun 09 11:14:17 2015 +0000
+++ b/wp/wp-content/plugins/portfolio/portfolio.php	Mon Oct 14 17:39:30 2019 +0200
@@ -1,16 +1,18 @@
 <?php
 /*
 Plugin Name: Portfolio by BestWebSoft
-Plugin URI: http://bestwebsoft.com/products/
-Description: Plugin for portfolio.
+Plugin URI: https://bestwebsoft.com/products/wordpress/plugins/portfolio/
+Description: Create your personal portfolio WordPress website. Manage and showcase past projects to get more clients.
 Author: BestWebSoft
-Version: 2.33
-Author URI: http://bestwebsoft.com/
+Text Domain: portfolio
+Domain Path: /languages
+Version: 2.46
+Author URI: https://bestwebsoft.com/
 License: GPLv2 or later
 */
 
 /*
-	@ Copyright 2015  BestWebSoft  ( http://support.bestwebsoft.com )
+	@ Copyright 2017  BestWebSoft  ( https://support.bestwebsoft.com )
 
 	This program is free software; you can redistribute it and/or modify
 	it under the terms of the GNU General Public License, version 2, as
@@ -25,494 +27,223 @@
 	along with this program; if not, write to the Free Software
 	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
-global $prtfl_filenames, $prtfl_filepath, $prtfl_themepath;
-$prtfl_filepath = WP_PLUGIN_DIR . '/portfolio/template/';
-$prtfl_themepath = get_stylesheet_directory() . '/';
 
-$prtfl_filenames[]	=	'portfolio.php';
-$prtfl_filenames[]	=	'portfolio-post.php';
-
-$prtfl_boxes = array();
-
-/* Function are using to add on admin-panel Wordpress page 'bws_plugins' and sub-page of this plugin */
+/* Function are using to add on admin-panel Wordpress page 'bws_panel' and sub-page of this plugin */
 if ( ! function_exists( 'add_prtfl_admin_menu' ) ) {
 	function add_prtfl_admin_menu() {
-		bws_add_general_menu( plugin_basename( __FILE__ ) );
-		add_submenu_page( 'bws_plugins', __( 'Portfolio', 'portfolio' ), __( 'Portfolio', 'portfolio' ), 'manage_options', "portfolio.php", 'prtfl_settings_page' );
+		global $submenu, $prtfl_options, $prtfl_plugin_info, $wp_version;
+
+		if ( empty( $prtfl_options ) ) {
+			register_prtfl_settings();
+		}
+
+		$settings = add_submenu_page( 'edit.php?post_type=' . $prtfl_options['post_type_name'], __( 'Portfolio Settings', 'portfolio' ), __( 'Settings', 'portfolio' ), 'manage_options', 'portfolio.php', 'prtfl_settings_page' );
+
+		add_submenu_page( 'edit.php?post_type=' . $prtfl_options['post_type_name'], 'BWS Panel', 'BWS Panel', 'manage_options', 'prtfl-bws-panel', 'bws_add_menu_render' );
+
+		if ( isset( $submenu['edit.php?post_type=' . $prtfl_options['post_type_name']] ) ) {
+			$submenu['edit.php?post_type=' . $prtfl_options['post_type_name']][] = array(
+				'<span style="color:#d86463"> ' . __( 'Upgrade to Pro', 'portfolio' ) . '</span>',
+				'manage_options',
+				'https://bestwebsoft.com/products/wordpress/plugins/portfolio/?k=f047e20c92c972c398187a4f70240285&pn=74&v=' . $prtfl_plugin_info["Version"] . '&wp_v=' . $wp_version );
+		}
+
+		add_action( 'load-' . $settings, 'prtfl_add_tabs' );
+		add_action( 'load-post-new.php', 'prtfl_add_tabs' );
+		add_action( 'load-post.php', 'prtfl_add_tabs' );
+		add_action( 'load-edit.php', 'prtfl_add_tabs' );
+	}
+}
+
+/* Internationalization, first(!)  */
+if ( ! function_exists( 'prtfl_plugins_loaded' ) ) {
+	function prtfl_plugins_loaded() {
+		load_plugin_textdomain( 'portfolio', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
 	}
 }
 
-if ( ! function_exists ( 'prtfl_init' ) ) {
+if ( ! function_exists( 'prtfl_init' ) ) {
 	function prtfl_init() {
 		global $prtfl_boxes, $prtfl_plugin_info;
-		/* Internationalization, first(!) */
-		load_plugin_textdomain( 'portfolio', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
 
-		require_once( dirname( __FILE__ ) . '/bws_menu/bws_functions.php' );
+		require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' );
+		bws_include_init( plugin_basename( __FILE__ ) );
 
 		if ( ! $prtfl_plugin_info ) {
-			if ( ! function_exists( 'get_plugin_data' ) )
+			if ( ! function_exists( 'get_plugin_data' ) ) {
 				require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
+			}
 			$prtfl_plugin_info = get_plugin_data( __FILE__ );
 		}
 		/* Function check if plugin is compatible with current WP version  */
-		bws_wp_version_check( plugin_basename( __FILE__ ), $prtfl_plugin_info, "3.1" );
+		bws_wp_min_version_check( plugin_basename( __FILE__ ), $prtfl_plugin_info, '3.9' );
 
 		$prtfl_boxes['Portfolio-Info'] = array(
-			array( '_prtfl_short_descr', __( 'Short description', 'portfolio' ), __( 'A short description which you\'d like to be displayed on your portfolio page', 'portfolio' ), '', '' ),
-			array( '_prtfl_date_compl', __( 'Date of completion', 'portfolio' ), __( 'The date when the task was completed', 'portfolio' ), '', '' ),
-			array( '_prtfl_link', __( 'Link', 'portfolio' ), __( 'A link to the site', 'portfolio' ), '', '' ),
-			array( '_prtfl_svn', __( 'SVN', 'portfolio' ), __( 'SVN URL', 'portfolio' ), '', '' ),
+			array(
+				'name'	=> '_prtfl_short_descr',
+				'title'	=> __( 'Short description', 'portfolio' ),
+				'type'	=> 'text'
+			),
+			array(
+				'name'	=> '_prtfl_date_compl',
+				'title'	=> __( 'Date of completion', 'portfolio' ),
+				'type'	=> 'text'
+			),
+			array(
+				'name'	=> '_prtfl_link',
+				'title'	=> __( 'Link', 'portfolio' ),
+				'type'	=> 'url'
+			),
+			array(
+				'name'	=> '_prtfl_svn',
+				'title'	=> __( 'SVN URL', 'portfolio' ),
+				'type'	=> 'url'
+			)
 		);
 		/* Call register settings function */
 		register_prtfl_settings();
-		/* Register post type */
+		/* Register post type and taxonomy for portfolio */
 		prtfl_post_type_portfolio();
-		/* Register taxonomy for portfolio */
-		prtfl_taxonomy_portfolio();
+
+		if ( ! is_admin() ) {
+			/* add template for gallery pages */
+			add_action( 'template_include', 'prtfl_template_include' );
+		}
+
+		/* demo data */
+		$demo_options = get_option( 'prtfl_demo_options' );
+		if ( ! empty( $demo_options ) || ( isset( $_GET['page'] ) && 'portfolio.php' == $_GET['page'] ) ) {
+			prtfl_include_demo_data();
+		}
 	}
 }
 
 if ( ! function_exists( 'prtfl_admin_init' ) ) {
 	function prtfl_admin_init() {
-		global $bws_plugin_info, $prtfl_plugin_info;
+		global $bws_plugin_info, $prtfl_plugin_info, $bws_shortcode_list, $wpdb;
+
+		if ( empty( $bws_plugin_info ) ) {
+			$bws_plugin_info = array( 'id' => '74', 'version' => $prtfl_plugin_info["Version"] );
+		}
+
+		/* add Portfolio to global $bws_shortcode_list  */
+		$bws_shortcode_list['prtfl'] = array( 'name' => 'Portfolio', 'js_function' => 'prtfl_shortcode_init' );
 
-		if ( ! isset( $bws_plugin_info ) || empty( $bws_plugin_info ) )
-			$bws_plugin_info = array( 'id' => '74', 'version' => $prtfl_plugin_info["Version"] );
+	}
+}
 
-		prtfl_admin_error();
+/* Function for activation plugin */
+if ( ! function_exists( 'prtfl_plugin_activate' ) ) {
+	function prtfl_plugin_activate() {
+		if ( is_multisite() ) {
+			switch_to_blog( 1 );
+			register_uninstall_hook( __FILE__, 'prtfl_plugin_uninstall' );
+			restore_current_blog();
+		} else {
+			register_uninstall_hook( __FILE__, 'prtfl_plugin_uninstall' );
+		}
 	}
 }
 
 /* Register settings function */
 if ( ! function_exists( 'register_prtfl_settings' ) ) {
 	function register_prtfl_settings() {
-		global $prtfl_options, $prtfl_plugin_info;
-
-		$prtfl_option_defaults = array(
-			'prtfl_custom_size_name'				=>	array( 'portfolio-thumb', 'portfolio-photo-thumb' ),
-			'prtfl_custom_size_px'					=>	array( array( 280, 300 ), array( 240, 260 ) ),
-			'prtfl_order_by' 						=>	'menu_order',
-			'prtfl_order' 							=>	'ASC',
-			'prtfl_custom_image_row_count'			=>	3,
-			'prtfl_date_additional_field' 			=>	1,
-			'prtfl_link_additional_field' 			=>	1,
-			'prtfl_shrdescription_additional_field' =>	1,
-			'prtfl_description_additional_field' 	=>	1,
-			'prtfl_svn_additional_field' 			=>	1,
-			'prtfl_executor_additional_field' 		=>	1,
-			'prtfl_technologies_additional_field'	=>	1,
-			'prtfl_link_additional_field_for_non_registered'	=>	1,
-			'prtfl_date_text_field'					=>	__( 'Date of completion:', 'portfolio' ),
-			'prtfl_link_text_field'					=>	__( 'Link:', 'portfolio' ),
-			'prtfl_shrdescription_text_field'		=>	__( 'Short description:', 'portfolio' ),
-			'prtfl_description_text_field'			=>	__( 'Description:', 'portfolio' ),
-			'prtfl_svn_text_field'					=>	__( 'SVN:', 'portfolio' ),
-			'prtfl_executor_text_field'				=>	__( 'Executor Profile:', 'portfolio' ),
-			'prtfl_screenshot_text_field'			=>	__( 'More screenshots:', 'portfolio' ),
-			'prtfl_technologies_text_field'			=>	__( 'Technologies:', 'portfolio' ),
-			'prtfl_slug' 							=>	'portfolio',
-			'prtfl_rewrite_template' 				=>	1,
-			'prtfl_rename_file' 					=>	0,
-			'plugin_option_version'					=> $prtfl_plugin_info["Version"],
-			'widget_updated' 						=>	1 /* this option is for updating plugin was added in v2.29 */
-		);
+		global $prtfl_options, $prtfl_plugin_info, $wpdb;
 
 		/* Install the option defaults */
-		if ( ! get_option( 'prtfl_options' ) )
-			add_option( 'prtfl_options', $prtfl_option_defaults );
+		if ( ! get_option( 'prtfl_options' ) ) {
+			$option_defaults = prtfl_get_options_default();
+			add_option( 'prtfl_options', $option_defaults );
+		}
 
 		/* Get options from the database */
 		$prtfl_options = get_option( 'prtfl_options' );
 
-		if ( isset( $prtfl_options['prtfl_prettyPhoto_style'] ) )
-			unset( $prtfl_options['prtfl_prettyPhoto_style'] );
-
 		/* Array merge incase this version has added new options */
 		if ( ! isset( $prtfl_options['plugin_option_version'] ) || $prtfl_options['plugin_option_version'] != $prtfl_plugin_info["Version"] ) {
-			if ( ! isset( $prtfl_options['plugin_option_version'] ) || $prtfl_options['plugin_option_version'] < '2.29' )
-				$prtfl_option_defaults['widget_updated'] = 0;
+
+			$wpdb->query( "UPDATE {$wpdb->prefix}posts SET post_type = 'bws-portfolio' WHERE post_type = 'portfolio'" );
+
+			$option_defaults = prtfl_get_options_default();
 
-			$prtfl_options = array_merge( $prtfl_option_defaults, $prtfl_options );
-			$prtfl_options['plugin_option_version'] = $prtfl_plugin_info["Version"];
+			if ( ! isset( $prtfl_options['plugin_option_version'] ) || $prtfl_options['plugin_option_version'] < '2.29' ) {
+				$option_defaults['widget_updated'] = 0;
+			}
+			/* Add options 'post_type_name' */
+			if ( ! isset( $prtfl_options['post_type_name'] ) ) {
+				$option_defaults['post_type_name'] = 'bws-portfolio';
+			}
+
+			$prtfl_options = array_merge( $option_defaults, $prtfl_options );
+			$prtfl_options['plugin_option_version'] = $option_defaults['plugin_option_version'];
+			/* show pro features */
+			$prtfl_options['hide_premium_options'] = array();
+
 			update_option( 'prtfl_options', $prtfl_options );
-			/* update templates when updating plugin */
-			prtfl_plugin_install();
 		}
 
 		if ( function_exists( 'add_image_size' ) ) {
-			add_image_size( 'portfolio-thumb', $prtfl_options['prtfl_custom_size_px'][0][0], $prtfl_options['prtfl_custom_size_px'][0][1], true );
-			add_image_size( 'portfolio-photo-thumb', $prtfl_options['prtfl_custom_size_px'][1][0], $prtfl_options['prtfl_custom_size_px'][1][1], true );
-		}
-	}
-}
-
-
-if ( ! function_exists( 'prtfl_plugin_install' ) ) {
-	function prtfl_plugin_install() {
-		global $prtfl_filenames, $prtfl_filepath, $prtfl_themepath, $prtfl_options;
-
-		if ( empty( $prtfl_options ) )
-			register_prtfl_settings();
-
-		foreach ( $prtfl_filenames as $filename ) {
-			if ( ! file_exists( $prtfl_themepath . $filename ) ) {
-				$handle		=	@fopen( $prtfl_filepath . $filename, "r" );
-				$contents	=	@fread( $handle, filesize( $prtfl_filepath . $filename ) );
-				@fclose( $handle );
-				if ( ! ( $handle = @fopen( $prtfl_themepath . $filename, 'w' ) ) )
-					return false;
-				@fwrite( $handle, $contents );
-				@fclose( $handle );
-				@chmod( $prtfl_themepath . $filename, octdec( 755 ) );
-			} elseif ( ! isset( $prtfl_options['prtfl_rewrite_template'] ) || 1 == $prtfl_options['prtfl_rewrite_template'] ) {
-				$handle		=	@fopen( $prtfl_themepath . $filename, "r" );
-				$contents	=	@fread( $handle, filesize( $prtfl_themepath . $filename ) );
-				@fclose( $handle );
-				if ( ! ( $handle = @fopen( $prtfl_themepath . $filename . '.bak', 'w' ) ) )
-					return false;
-				@fwrite( $handle, $contents );
-				@fclose( $handle );
-				
-				$handle		=	@fopen( $prtfl_filepath . $filename, "r" );
-				$contents	=	@fread( $handle, filesize( $prtfl_filepath . $filename ) );
-				@fclose( $handle );
-				if ( ! ( $handle = @fopen( $prtfl_themepath . $filename, 'w' ) ) )
-					return false;
-				@fwrite( $handle, $contents );
-				@fclose( $handle );
-				@chmod( $prtfl_themepath . $filename, octdec( 755 ) );
+			if ( 'portfolio-thumb' == $prtfl_options['image_size_album'] ) {
+				add_image_size( 'portfolio-thumb', $prtfl_options['custom_size_px']['portfolio-thumb'][0], $prtfl_options['custom_size_px']['portfolio-thumb'][1], true );
+			}
+			if ( 'portfolio-photo-thumb' == $prtfl_options['image_size_photo'] ) {
+				add_image_size( 'portfolio-photo-thumb', $prtfl_options['custom_size_px']['portfolio-photo-thumb'][0], $prtfl_options['custom_size_px']['portfolio-photo-thumb'][1], true );
 			}
 		}
 	}
 }
 
-if ( ! function_exists ( 'prtfl_after_switch_theme' ) ) {
-	function prtfl_after_switch_theme() {
-		global $prtfl_filenames, $prtfl_themepath;
-		$file_exists_flag = true;
-		foreach ( $prtfl_filenames as $filename ) {
-			if ( ! file_exists( $prtfl_themepath . $filename ) )
-				$file_exists_flag = false;
-		}
-		if ( ! $file_exists_flag )
-			prtfl_plugin_install();
-	}
-}
-
-if ( ! function_exists( 'prtfl_admin_error' ) ) {
-	function prtfl_admin_error() {
-		global $prtfl_filenames, $prtfl_filepath, $prtfl_themepath;
-
-		$post = isset( $_REQUEST['post'] ) ? $_REQUEST['post'] : "" ;
-		$post_type = isset( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : "" ;
-		$file_exists_flag = true;
-		if ( ( 'portfolio' == get_post_type( $post ) || 'portfolio' == $post_type ) || ( isset( $_REQUEST['page'] ) && 'portfolio.php' == $_REQUEST['page'] ) ) {
-			foreach ( $prtfl_filenames as $filename ) {
-				if ( ! file_exists( $prtfl_themepath . $filename ) )
-					$file_exists_flag = false;
-			}
-		}
-		if ( ! $file_exists_flag )
-			echo '<div class="error"><p><strong>' . __( 'The files "portfolio.php" and "portfolio-post.php" are not found in your theme directory. Please copy them from the directory `wp-content/plugins/portfolio/template/` to your theme directory for correct work of the Portfolio plugin', 'portfolio' ) . '</strong></p></div>';
-	}
-}
-
-if ( ! function_exists( 'prtfl_settings_page' ) ) {
-	function prtfl_settings_page() {
-		global $prtfl_options, $wpdb, $wp_version, $prtfl_plugin_info;
-		$error = $message = $cstmsrch_options_name = "";
-		$plugin_basename  = plugin_basename( __FILE__ );
-
-		if ( false !== get_option( 'cstmsrchpr_options' ) )
-			$cstmsrch_options_name = "cstmsrchpr_options";
-		elseif ( false !== get_option( 'cstmsrch_options' ) )
-			$cstmsrch_options_name = "cstmsrch_options";
-		elseif ( false !== get_option( 'bws_custom_search' ) )
-			$cstmsrch_options_name = "bws_custom_search";
-
-		$all_plugins = get_plugins();
-		if ( isset( $cstmsrch_options_name ) && "" != $cstmsrch_options_name )
-			$cstmsrch_options = get_option( $cstmsrch_options_name );
-
-		/* Save data for settings page */
-		if ( isset( $_REQUEST['prtfl_form_submit'] ) && check_admin_referer( $plugin_basename, 'prtfl_nonce_name' ) ) {
-			$prtfl_request_options = array();
-			$prtfl_request_options["prtfl_custom_size_name"] = $prtfl_options["prtfl_custom_size_name"];
-
-			$prtfl_request_options["prtfl_custom_size_px"] = array(
-				array( intval( trim( $_REQUEST['prtfl_custom_image_size_w_album'] ) ), intval( trim( $_REQUEST['prtfl_custom_image_size_h_album'] ) ) ),
-				array( intval( trim( $_REQUEST['prtfl_custom_image_size_w_photo'] ) ), intval( trim( $_REQUEST['prtfl_custom_image_size_h_photo'] ) ) )
-			);
-			$prtfl_request_options["prtfl_custom_image_row_count"] =  intval( $_REQUEST['prtfl_custom_image_row_count'] );
-			if ( "" == $prtfl_request_options["prtfl_custom_image_row_count"] || 1 > $prtfl_request_options["prtfl_custom_image_row_count"] )
-				$prtfl_request_options["prtfl_custom_image_row_count"] = 1;
-
-			$prtfl_request_options["prtfl_order_by"]	=	$_REQUEST['prtfl_order_by'];
-			$prtfl_request_options["prtfl_order"]		=	$_REQUEST['prtfl_order'];
-
-			$prtfl_request_options["prtfl_date_additional_field"]			=	isset( $_REQUEST["prtfl_date_additional_field"] ) ? $_REQUEST["prtfl_date_additional_field"] : 0;
-			$prtfl_request_options["prtfl_link_additional_field"]			=	isset( $_REQUEST["prtfl_link_additional_field"] ) ? $_REQUEST["prtfl_link_additional_field"] : 0;
-			$prtfl_request_options["prtfl_shrdescription_additional_field"] =	isset( $_REQUEST["prtfl_shrdescription_additional_field"] ) ? $_REQUEST["prtfl_shrdescription_additional_field"] : 0;
-			$prtfl_request_options["prtfl_description_additional_field"]	=	isset( $_REQUEST["prtfl_description_additional_field"] ) ? $_REQUEST["prtfl_description_additional_field"] : 0;
-			$prtfl_request_options["prtfl_svn_additional_field"]			=	isset( $_REQUEST["prtfl_svn_additional_field"] ) ? $_REQUEST["prtfl_svn_additional_field"] : 0;
-			$prtfl_request_options["prtfl_executor_additional_field"]		=	isset( $_REQUEST["prtfl_executor_additional_field"] ) ? $_REQUEST["prtfl_executor_additional_field"] : 0;
-			$prtfl_request_options["prtfl_technologies_additional_field"]	=	isset( $_REQUEST["prtfl_technologies_additional_field"] ) ? $_REQUEST["prtfl_technologies_additional_field"] : 0;
-
-			$prtfl_request_options["prtfl_link_additional_field_for_non_registered"] = isset( $_REQUEST["prtfl_link_additional_field_for_non_registered"] ) ? $_REQUEST["prtfl_link_additional_field_for_non_registered"] : 0;
-
-			$prtfl_request_options["prtfl_date_text_field"] 			=	stripslashes( esc_html( $_REQUEST["prtfl_date_text_field"] ) );
-			$prtfl_request_options["prtfl_link_text_field"]				=	stripslashes( esc_html( $_REQUEST["prtfl_link_text_field"] ) );
-			$prtfl_request_options["prtfl_shrdescription_text_field"] 	=	stripslashes( esc_html( $_REQUEST["prtfl_shrdescription_text_field"] ) );
-			$prtfl_request_options["prtfl_description_text_field"]		=	stripslashes( esc_html( $_REQUEST["prtfl_description_text_field"] ) );
-			$prtfl_request_options["prtfl_svn_text_field"]				=	stripslashes( esc_html( $_REQUEST["prtfl_svn_text_field"] ) );
-			$prtfl_request_options["prtfl_executor_text_field"]			=	stripslashes( esc_html( $_REQUEST["prtfl_executor_text_field"] ) );
-			$prtfl_request_options["prtfl_screenshot_text_field"]		=	stripslashes( esc_html( $_REQUEST["prtfl_screenshot_text_field"] ) );
-			$prtfl_request_options["prtfl_technologies_text_field"]		=	stripslashes( esc_html( $_REQUEST["prtfl_technologies_text_field"] ) );
-
-			$prtfl_request_options["prtfl_slug"]	=	trim( $_REQUEST['prtfl_slug'] );
-			$prtfl_request_options["prtfl_slug"]	=	strtolower( $prtfl_request_options["prtfl_slug"] );
-			$prtfl_request_options["prtfl_slug"]	=	preg_replace( "/[^a-z0-9\s-]/", "", $prtfl_request_options["prtfl_slug"] );
-			$prtfl_request_options["prtfl_slug"]	=	trim( preg_replace( "/[\s-]+/", " ", $prtfl_request_options["prtfl_slug"] ) );
-			$prtfl_request_options["prtfl_slug"]	=	preg_replace( "/\s/", "-", $prtfl_request_options["prtfl_slug"] );
-
-			$prtfl_request_options["prtfl_rewrite_template"] = isset( $_REQUEST["prtfl_rewrite_template"] ) ? 1 : 0;
-			$prtfl_request_options["prtfl_rename_file"] = isset( $_REQUEST["prtfl_rename_file"] ) ? 1 : 0;
-
-			if ( isset( $_REQUEST['prtfl_add_to_search'] ) && "" != $cstmsrch_options_name ) {
-				if ( false !== get_option( $cstmsrch_options_name ) ) {
-					$cstmsrch_options = get_option( $cstmsrch_options_name );
-					if ( ! in_array( 'portfolio', $cstmsrch_options ) ) {
-						array_push( $cstmsrch_options, 'portfolio' );
-						update_option( $cstmsrch_options_name, $cstmsrch_options );
-					}
-				}
-			} else {
-				if ( false !== get_option( $cstmsrch_options_name ) ) {
-					$cstmsrch_options = get_option( $cstmsrch_options_name );
-					if ( in_array( 'portfolio', $cstmsrch_options ) ) {
-						$key = array_search( 'portfolio', $cstmsrch_options );
-						unset( $cstmsrch_options[ $key ] );
-						update_option( $cstmsrch_options_name, $cstmsrch_options );
-					}
-				}
-			}
-
-			/* For revrite prtfl_slug */
-			global $wp_rewrite;
-			$rules = get_option( 'rewrite_rules' );
-			prtfl_custom_permalinks( $rules );
-			$wp_rewrite->flush_rules();
-
-			/* Array merge incase this version has added new options */
-			$prtfl_options = array_merge( $prtfl_options, $prtfl_request_options );
+/**
+ * Get Plugin default options
+ */
+if ( ! function_exists( 'prtfl_get_options_default' ) ) {
+	function prtfl_get_options_default() {
+		global $prtfl_plugin_info;
 
-			/* Check select one point in the blocks Arithmetic actions and Difficulty on settings page */
-			update_option( 'prtfl_options', $prtfl_options );
-			$message = __( "Settings saved.", 'portfolio' );
-			
-		}
-		/* GO PRO */
-		if ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) {
-			$go_pro_result = bws_go_pro_tab_check( $plugin_basename );
-			if ( ! empty( $go_pro_result['error'] ) )
-				$error = $go_pro_result['error'];
-		}
-		/* Display form on the setting page */ ?>
-		<div class="wrap">
-			<div class="icon32 icon32-bws" id="icon-options-general"></div>
-			<h2><?php _e( 'Portfolio Settings', 'portfolio' ); ?></h2>
-			<h2 class="nav-tab-wrapper">
-				<a class="nav-tab<?php echo ! isset( $_GET['action'] ) ? ' nav-tab-active': ''; ?>" href="admin.php?page=portfolio.php"><?php _e( 'Settings', 'portfolio' ); ?></a>
-				<a class="nav-tab" href="http://bestwebsoft.com/products/portfolio/faq/" target="_blank"><?php _e( 'FAQ', 'portfolio' ); ?></a>
-				<a class="nav-tab bws_go_pro_tab<?php if ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) echo ' nav-tab-active'; ?>" href="admin.php?page=portfolio.php&amp;action=go_pro"><?php _e( 'Go PRO', 'portfolio' ); ?></a>
-			</h2>
-			<div class="updated fade" <?php if ( ! isset( $_REQUEST['prtfl_form_submit'] ) || "" != $error ) echo 'style="display:none"'; ?>><p><strong><?php echo $message; ?></strong></p></div>
-			<div class="error" <?php if ( "" == $error ) echo 'style="display:none"'; ?>><p><strong><?php echo $error; ?></strong></p></div>
-			<div id="prtfl_settings_notice" class="updated fade" style="display:none"><p><strong><?php _e( "Notice:", 'portfolio' ); ?></strong> <?php _e( "The plugin's settings have been changed. In order to save them please don't forget to click the 'Save Changes' button.", 'portfolio' ); ?></p></div>
-			<?php if ( ! ( isset( $_GET['action'] ) && 'go_pro' == $_GET['action'] ) ) { ?>
-				<p><?php _e( "If you would like to add the Latest Portfolio Items to your page or post, just copy and paste this shortcode into your post or page:", 'portfolio' ); ?> [latest_portfolio_items count=3], <?php _e( 'where count=3 is a number of posts to show up in the portfolio.', 'portfolio' ); ?></p>
-				<?php $prefix = ( '1' == get_option( 'prtfl_tag_update' ) ) ? '_prtfl' : '_prtf';
-				if ( NULL != $wpdb->get_var( "SELECT `meta_id` FROM `" . $wpdb->postmeta . "` WHERE `meta_key` = '" . $prefix . "_short_descr' LIMIT 1" ) ) { ?>
-					<table class="form-table">
-						<tr valign="top">
-							<th scope="row"><?php _e( 'Change the way to store your post_meta information for portfolio', 'portfolio' ); ?> </th>
-							<td style="position:relative">
-								<input type="button" value="<?php _e( 'Update All Info', 'portfolio' ); ?>" id="ajax_update_postmeta" name="ajax_update_postmeta" class="button" onclick="javascript:update_postmeta();"> <div id="prtfl_loader"><img src="<?php echo plugins_url( 'images/ajax-loader.gif', __FILE__ ); ?>" alt="loader" /></div>
-							</td>
-						</tr>
-					</table>
-				<?php } ?>
-				<table class="form-table">
-					<tr valign="top">
-						<th scope="row"><?php _e( 'Update images for portfolio', 'portfolio' ); ?> </th>
-						<td style="position:relative">
-							<input type="button" value="<?php _e( 'Update images', 'portfolio' ); ?>" id="ajax_update_images" name="ajax_update_images" class="button" onclick="javascript:update_images();"> <div id="prtfl_img_loader"><img src="<?php echo plugins_url( 'images/ajax-loader.gif', __FILE__ ); ?>" alt="loader" /></div>
-						</td>
-					</tr>
-					<tr valign="top">
-					</tr>
-				</table>
-				<br />
-				<form method="post" action="admin.php?page=portfolio.php" id="prtfl_form_image_size">
-					<table class="form-table">
-						<tr valign="top">
-							<th scope="row"><?php _e( 'Image size for the album cover', 'portfolio' ); ?> </th>
-							<td>
-								<label><?php _e( 'Image size name', 'portfolio' ); ?></label>&nbsp;<?php echo $prtfl_options["prtfl_custom_size_name"][0]; ?><br />
-								<label><?php _e( 'Width (in px)', 'portfolio' ); ?></label> <input type="text" name="prtfl_custom_image_size_w_album" value="<?php echo $prtfl_options["prtfl_custom_size_px"][0][0]; ?>" /><br />
-								<label><?php _e( 'Height (in px)', 'portfolio' ); ?></label> <input type="text" name="prtfl_custom_image_size_h_album" value="<?php echo $prtfl_options["prtfl_custom_size_px"][0][1]; ?>" />
-							</td>
-						</tr>
-						<tr valign="top">
-							<th scope="row"><?php _e( 'Image size for thumbnails', 'portfolio' ); ?> </th>
-							<td>
-								<label><?php _e( 'Image size name', 'portfolio' ); ?></label>&nbsp;<?php echo $prtfl_options["prtfl_custom_size_name"][1]; ?><br />
-								<label><?php _e( 'Width (in px)', 'portfolio' ); ?></label> <input type="text" name="prtfl_custom_image_size_w_photo" value="<?php echo $prtfl_options["prtfl_custom_size_px"][1][0]; ?>" /><br />
-								<label><?php _e( 'Height (in px)', 'portfolio' ); ?></label> <input type="text" name="prtfl_custom_image_size_h_photo" value="<?php echo $prtfl_options["prtfl_custom_size_px"][1][1]; ?>" />
-							</td>
-						</tr>
-						<tr valign="top">
-							<td colspan="2"><span style="color: #888888;font-size: 10px;"><?php _e( 'WordPress will copy thumbnails with the specified dimensions when you upload a new image. It is necessary to click the Update images button at the top of this page in order to generate new images and set new dimensions', 'portfolio' ); ?></span></th>
-						</tr>
-						<tr valign="top">
-							<th scope="row"><?php _e( 'Sort portfolio by', 'portfolio' ); ?> </th>
-							<td>
-								<label class="label_radio"><input type="radio" name="prtfl_order_by" value="ID" <?php if ( 'ID' == $prtfl_options["prtfl_order_by"] ) echo 'checked="checked"'; ?> /> <?php _e( 'portfolio id', 'portfolio' ); ?></label><br />
-								<label class="label_radio"><input type="radio" name="prtfl_order_by" value="title" <?php if ( 'title' == $prtfl_options["prtfl_order_by"] ) echo 'checked="checked"'; ?> /> <?php _e( 'portfolio title', 'portfolio' ); ?></label><br />
-								<label class="label_radio"><input type="radio" name="prtfl_order_by" value="date" <?php if ( 'date' == $prtfl_options["prtfl_order_by"] ) echo 'checked="checked"'; ?> /> <?php _e( 'date', 'portfolio' ); ?></label><br />
-								<label class="label_radio"><input type="radio" name="prtfl_order_by" value="menu_order" <?php if ( 'menu_order' == $prtfl_options["prtfl_order_by"] ) echo 'checked="checked"'; ?> /> <?php _e( 'menu order', 'portfolio' ); ?></label><br />
-								<label class="label_radio"><input type="radio" name="prtfl_order_by" value="rand" <?php if ( 'rand' == $prtfl_options["prtfl_order_by"] ) echo 'checked="checked"'; ?> /> <?php _e( 'random', 'portfolio' ); ?></label>
-							</td>
-						</tr>
-						<tr valign="top">
-							<th scope="row"><?php _e( 'Portfolio sorting', 'portfolio' ); ?> </th>
-							<td>
-								<label class="label_radio" style="width: auto;"><input type="radio" name="prtfl_order" value="ASC" <?php if ( 'ASC' == $prtfl_options["prtfl_order"] ) echo 'checked="checked"'; ?> /> <?php _e( 'ASC (ascending order from lowest to highest values - 1, 2, 3; a, b, c)', 'portfolio' ); ?></label><br />
-								<label class="label_radio" style="width: auto;"><input type="radio" name="prtfl_order" value="DESC" <?php if ( 'DESC' == $prtfl_options["prtfl_order"] ) echo 'checked="checked"'; ?> /> <?php _e( 'DESC (descending order from highest to lowest values - 3, 2, 1; c, b, a)', 'portfolio' ); ?></label>
-							</td>
-						</tr>
-						<tr valign="top">
-							<th scope="row"><?php _e( 'Number of images in the row', 'portfolio' ); ?> </th>
-							<td>
-								<input type="text" name="prtfl_custom_image_row_count" value="<?php echo $prtfl_options["prtfl_custom_image_row_count"]; ?>" />
-							</td>
-						</tr>
-						<tr valign="top">
-							<th scope="row"><?php _e( 'Display additional fields', 'portfolio' ); ?> </th>
-							<td>
-								<input type="checkbox" name="prtfl_date_additional_field" value="1" id="prtfl_date_additional_field" <?php if ( 1 == $prtfl_options['prtfl_date_additional_field'] ) echo 'checked="checked"'; ?> /> <label for="prtfl_date_additional_field" style="float:none;"><?php _e( 'Date', 'portfolio' ); ?></label>
-								<input type="checkbox" name="prtfl_link_additional_field" value="1" id="prtfl_link_additional_field" <?php if ( 1 == $prtfl_options['prtfl_link_additional_field'] ) echo 'checked="checked"'; ?> /> <label for="prtfl_link_additional_field" style="float:none;"><?php _e( 'Link', 'portfolio' ); ?></label>
-								<input type="checkbox" name="prtfl_shrdescription_additional_field" value="1" id="prtfl_shrdescription_additional_field" <?php if ( 1 == $prtfl_options['prtfl_shrdescription_additional_field'] ) echo 'checked="checked"'; ?> /> <label for="prtfl_shrdescription_additional_field" style="float:none;"><?php _e( 'Short Description', 'portfolio' ); ?></label>
-								<input type="checkbox" name="prtfl_description_additional_field" value="1" id="prtfl_description_additional_field" <?php if ( 1 == $prtfl_options['prtfl_description_additional_field'] ) echo 'checked="checked"'; ?> /> <label for="prtfl_description_additional_field" style="float:none;"><?php _e( 'Description', 'portfolio' ); ?></label>
-								<input type="checkbox" name="prtfl_svn_additional_field" value="1" id="prtfl_svn_additional_field" <?php if ( 1 == $prtfl_options['prtfl_svn_additional_field'] ) echo 'checked="checked"'; ?> /> <label for="prtfl_svn_additional_field" style="float:none;"><?php _e( 'SVN', 'portfolio' ); ?></label>
-								<input type="checkbox" name="prtfl_executor_additional_field" value="1" id="prtfl_executor_additional_field" <?php if ( 1 == $prtfl_options['prtfl_executor_additional_field'] ) echo 'checked="checked"'; ?> /> <label for="prtfl_executor_additional_field" style="float:none;"><?php _e( 'Executor', 'portfolio' ); ?></label>
-								<input type="checkbox" name="prtfl_technologies_additional_field" value="1" id="prtfl_technologies_additional_field" <?php if ( 1 == $prtfl_options['prtfl_technologies_additional_field'] ) echo 'checked="checked"'; ?> /> <label for="prtfl_technologies_additional_field" style="float:none;"><?php _e( 'Technologies', 'portfolio' ); ?></label>
-							</td>
-						</tr>
-					</table>
-					<div class="bws_pro_version_bloc">
-						<div class="bws_pro_version_table_bloc">
-							<div class="bws_table_bg"></div>
-							<table class="form-table bws_pro_version">
-								<tr valign="top">
-									<th scope="row"><?php _e( 'Display additional fields', 'portfolio' ); ?> </th>
-									<td width="350">
-										<label><input type="checkbox" name="prtflpr_categories_additional_field" value="1" style="margin-left: -11px;" disabled="disabled" /> <?php _e( 'Categories', 'portfolio' ); ?></label>
-									</td>
-								</tr>
-								<tr valign="top">
-									<th scope="row"><?php _e( 'Hide "More screenshots" block', 'portfolio' ); ?></th>
-									<td width="350">
-										<input type="checkbox" name="prtflpr_disbable_screenshot_block" value="1" style="margin-left: -11px;" disabled="disabled" />
-									</td>
-								</tr>
-								<tr valign="top">
-									<th scope="row" colspan="2">
-										* <?php _e( 'If you upgrade to Pro version all your settings and portfolios will be saved.', 'portfolio' ); ?>
-									</th>
-								</tr>
-							</table>
-						</div>
-						<div class="bws_pro_version_tooltip">
-							<div class="bws_info">
-								<?php _e( 'Unlock premium options by upgrading to a PRO version.', 'portfolio' ); ?>
-								<a href="http://bestwebsoft.com/products/portfolio/?k=f047e20c92c972c398187a4f70240285&pn=74&v=<?php echo $prtfl_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="Portfolio Pro"><?php _e( 'Learn More', 'portfolio' ); ?></a>
-							</div>
-							<a class="bws_button" href="http://bestwebsoft.com/products/portfolio/buy/?k=f047e20c92c972c398187a4f70240285&pn=74&v=<?php echo $prtfl_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="Portfolio Pro">
-								<?php _e( 'Go', 'portfolio' ); ?> <strong>PRO</strong>
-							</a>
-							<div class="clear"></div>
-						</div>
-					</div>
-					<table class="form-table">
-						<tr valign="top">
-							<th scope="row"><?php _e( 'Display the link field as a text for non-registered users', 'portfolio' ); ?></th>
-							<td>
-								<input type="checkbox" name="prtfl_link_additional_field_for_non_registered" value="1" id="prtfl_link_additional_field_for_non_registered" <?php if ( 1 == $prtfl_options['prtfl_link_additional_field_for_non_registered'] ) echo 'checked="checked"'; ?> />
-							</td>
-						</tr>
-						<tr valign="top">
-							<th scope="row"><?php _e( 'Text for additional fields', 'portfolio' ); ?> </th>
-							<td>
-								<label><?php _e( 'Date of completion:', 'portfolio' ); ?></label> <input type="text" name="prtfl_date_text_field" value="<?php echo $prtfl_options["prtfl_date_text_field"]; ?>" /><br />
-								<label><?php _e( 'Link:', 'portfolio' ); ?></label> <input type="text" name="prtfl_link_text_field" value="<?php echo $prtfl_options["prtfl_link_text_field"]; ?>" /><br />
-								<label><?php _e( 'Short description:', 'portfolio' ); ?></label> <input type="text" name="prtfl_shrdescription_text_field" value="<?php echo $prtfl_options["prtfl_shrdescription_text_field"]; ?>" /><br />
-								<label><?php _e( 'Description:', 'portfolio' ); ?></label> <input type="text" name="prtfl_description_text_field" value="<?php echo $prtfl_options["prtfl_description_text_field"]; ?>" /><br />
-								<label><?php _e( 'SVN:', 'portfolio' ); ?></label> <input type="text" name="prtfl_svn_text_field" value="<?php echo $prtfl_options["prtfl_svn_text_field"]; ?>" /><br />
-								<label><?php _e( 'Executor Profile:', 'portfolio' ); ?></label> <input type="text" name="prtfl_executor_text_field" value="<?php echo $prtfl_options["prtfl_executor_text_field"]; ?>" /><br />
-								<label><?php _e( 'More screenshots:', 'portfolio' ); ?></label> <input type="text" name="prtfl_screenshot_text_field" value="<?php echo $prtfl_options["prtfl_screenshot_text_field"]; ?>" /><br />
-								<label><?php _e( 'Technologies:', 'portfolio' ); ?></label> <input type="text" name="prtfl_technologies_text_field" value="<?php echo $prtfl_options["prtfl_technologies_text_field"]; ?>" />
-							</td>
-						</tr>
-						<tr valign="top">
-							<th scope="row"><?php _e( 'Slug for portfolio item', 'portfolio' ); ?></th>
-							<td>
-								<input type="text" name="prtfl_slug" value="<?php echo $prtfl_options["prtfl_slug"]; ?>" /> <span style="color: #888888;font-size: 10px;"><?php _e( 'for any structure of permalinks except the default structure', 'portfolio' ); ?></span>
-							</td>
-						</tr>
-						<tr valign="top">
-							<th scope="row"><?php _e( 'Rewrite templates after update', 'portfolio' ); ?></th>
-							<td>
-								<input type="checkbox" name="prtfl_rewrite_template" value="1" <?php if ( 1 == $prtfl_options['prtfl_rewrite_template'] ) echo 'checked="checked"'; ?> /> <span style="color: #888888;font-size: 10px;"><?php _e( "Turn off the checkbox, if You edited the file 'portfolio.php' or 'portfolio-post.php' file in your theme folder and You don't want to rewrite them", 'portfolio' ); ?></span>
-							</td>
-						</tr>
-						<tr valign="top">
-							<th scope="row"><?php _e( 'Rename uploaded images', 'portfolio' ); ?></th>
-							<td>
-								<input type="checkbox" name="prtfl_rename_file" value="1" <?php if ( 1 == $prtfl_options['prtfl_rename_file'] ) echo 'checked="checked"'; ?> /> <span style="color: #888888;font-size: 10px;"><?php _e( "To avoid conflicts, all the symbols will be excluded, except numbers, the Roman letters,  _ and - symbols.", 'portfolio' ); ?></span>
-							</td>
-						</tr>
-						<tr valign="top">
-							<th scope="row"><?php _e( 'Add portfolio to the search', 'portfolio' ); ?></th>
-							<td>
-								<?php if ( array_key_exists( 'custom-search-plugin/custom-search-plugin.php', $all_plugins ) || array_key_exists( 'custom-search-pro/custom-search-pro.php', $all_plugins ) ) {
-									if ( is_plugin_active( 'custom-search-plugin/custom-search-plugin.php' ) || is_plugin_active( 'custom-search-pro/custom-search-pro.php' ) ) { ?>
-										<input type="checkbox" name="prtfl_add_to_search" value="1" <?php if ( isset( $cstmsrch_options ) && in_array( 'portfolio', $cstmsrch_options ) ) echo 'checked="checked"'; ?> />
-										<span style="color: #888888;font-size: 10px;"> (<?php _e( 'Using Custom Search powered by', 'portfolio' ); ?> <a href="http://bestwebsoft.com/products/">bestwebsoft.com</a>)</span>
-									<?php } else { ?>
-										<input disabled="disabled" type="checkbox" name="prtfl_add_to_search" value="1" <?php if ( isset( $cstmsrch_options ) && in_array( 'portfolio', $cstmsrch_options ) ) echo 'checked="checked"'; ?> />
-										<span style="color: #888888;font-size: 10px;">(<?php _e( 'Using Custom Search powered by', 'portfolio' ); ?> <a href="http://bestwebsoft.com/products/">bestwebsoft.com</a>) <a href="<?php echo bloginfo("url"); ?>/wp-admin/plugins.php"><?php _e( 'Activate Custom Search', 'portfolio' ); ?></a></span>
-									<?php }
-								} else { ?>
-									<input disabled="disabled" type="checkbox" name="prtfl_add_to_search" value="1" />
-									<span style="color: #888888;font-size: 10px;">(<?php _e( 'Using Custom Search powered by', 'portfolio' ); ?> <a href="http://bestwebsoft.com/products/">bestwebsoft.com</a>) <a href="http://bestwebsoft.com/products/custom-search/"><?php _e( 'Download Custom Search', 'portfolio' ); ?></a></span>
-								<?php } ?>
-							</td>
-						</tr>
-					</table>
-					<input type="hidden" name="prtfl_form_submit" value="submit" />
-					<p class="submit">
-						<input type="submit" class="button-primary" value="<?php _e( 'Save Changes' ); ?>" />
-					</p>
-					<?php wp_nonce_field( plugin_basename( __FILE__ ), 'prtfl_nonce_name' ); ?>
-				</form>
-				<?php bws_plugin_reviews_block( $prtfl_plugin_info['Name'], 'portfolio' ); 
-			} elseif ( 'go_pro' == $_GET['action'] ) {
-				bws_go_pro_tab( $prtfl_plugin_info, $plugin_basename, 'portfolio.php', 'portfolio-pro.php', 'portfolio-pro/portfolio-pro.php', 'portfolio', 'f047e20c92c972c398187a4f70240285', '74', isset( $go_pro_result['pro_plugin_is_activated'] ) );
-			} ?>
-		</div>
-	<?php }
+		$option_defaults = array(
+			/* internal general */
+			'plugin_option_version' 					=> $prtfl_plugin_info["Version"],
+			'first_install'								=> strtotime( "now" ),
+			'suggest_feature_banner'					=> 1,
+			'display_settings_notice'					=> 1,
+			/* internal */
+			'display_demo_notice'						=> 1,
+			/* settings */
+			'image_size_album'							=> 'medium',
+			'image_size_photo'							=> 'thumbnail',
+			'custom_size_px'							=> array(
+															'portfolio-thumb' => array( 280, 300 ),
+															'portfolio-photo-thumb' => array( 240, 260 )
+														),
+			'page_id_portfolio_template'				=> '',
+			'order_by' 									=>	'date',
+			'order' 									=>	'DESC',
+			'custom_image_row_count'					=>	3,
+			'date_additional_field' 					=>	1,
+			'link_additional_field' 					=>	1,
+			'shrdescription_additional_field' 			=>	1,
+			'description_additional_field' 				=>	1,
+			'svn_additional_field' 						=>	1,
+			'executor_additional_field' 				=>	1,
+			'technologies_additional_field'				=>	1,
+			'link_additional_field_for_non_registered'	=>	1,
+			'date_text_field'							=>	__( 'Date of completion:', 'portfolio' ),
+			'link_text_field'							=>	__( 'Link:', 'portfolio' ),
+			'shrdescription_text_field'					=>	__( 'Short description:', 'portfolio' ),
+			'description_text_field'					=>	__( 'Description:', 'portfolio' ),
+			'svn_text_field'							=>	__( 'SVN:', 'portfolio' ),
+			'executor_text_field'						=>	__( 'Executor:', 'portfolio' ),
+			'screenshot_text_field'						=>	__( 'More screenshots:', 'portfolio' ),
+			'technologies_text_field'					=>	__( 'Technologies:', 'portfolio' ),
+			/* misc */
+			'slug' 										=>	'portfolio',
+			'post_type_name'							=>	'bws-portfolio',
+			/* other */
+			'widget_updated' 							=>	1, /* this option is for updating plugin was added in v2.29 */
+			'flush_rewrite_rules'						=>	1,
+		);
+		return $option_defaults;
+	}
 }
 
 /* Create post type for portfolio */
@@ -520,35 +251,39 @@
 	function prtfl_post_type_portfolio() {
 		global $wpdb, $prtfl_options;
 
-		$slug		=	isset( $prtfl_options['prtfl_slug'] ) && ! empty( $prtfl_options['prtfl_slug'] ) ? $prtfl_options['prtfl_slug'] : 'portfolio';
 		register_post_type(
-			'portfolio',
+			$prtfl_options['post_type_name'],
 			array(
 				'labels' => array(
-					'name'					=>	__( 'Portfolio', 'portfolio' ),
-					'singular_name'			=>	__( 'Portfolio', 'portfolio' ),
-					'add_new'				=>	__( 'Add New', 'portfolio' ),
-					'add_new_item'			=>	__( 'Add New Portfolio', 'portfolio' ),
-					'edit'					=>	__( 'Edit', 'portfolio' ),
-					'edit_item'				=>	__( 'Edit Portfolio', 'portfolio' ),
-					'new_item'				=>	__( 'New Portfolio', 'portfolio' ),
-					'view'					=>	__( 'View Portfolio', 'portfolio' ),
-					'view_item'				=>	__( 'View Portfolio', 'portfolio' ),
-					'search_items'			=>	__( 'Search Portfolio', 'portfolio' ),
-					'not_found'				=>	__( 'No portfolio found', 'portfolio' ),
-					'not_found_in_trash'	=>	__( 'No portfolio found in Trash', 'portfolio' ),
-					'parent'				=>	__( 'Parent Portfolio', 'portfolio' ),
+					'name'					=> __( 'Portfolio', 'portfolio' ),
+					'all_items'				=> __( 'Projects', 'portfolio' ),
+					'singular_name'			=> __( 'Project', 'portfolio' ),
+					'add_new'				=> __( 'Add New', 'portfolio' ),
+					'add_new_item'			=> __( 'Add New Project', 'portfolio' ),
+					'edit'					=> __( 'Edit', 'portfolio' ),
+					'edit_item'				=> __( 'Edit Project', 'portfolio' ),
+					'new_item'				=> __( 'New Project', 'portfolio' ),
+					'view'					=> __( 'View Project', 'portfolio' ),
+					'view_item'				=> __( 'View Project', 'portfolio' ),
+					'search_items'			=> __( 'Search Projects', 'portfolio' ),
+					'not_found'				=> __( 'No project found', 'portfolio' ),
+					'not_found_in_trash'	=> __( 'No project found in Trash', 'portfolio' ),
+					'parent'				=> __( 'Parent Project', 'portfolio' ),
+					'filter_items_list'		=> __( 'Filter projects list', 'portfolio' ),
+					'items_list_navigation'	=> __( 'Projects list navigation', 'portfolio' ),
+					'items_list'			=> __( 'Projects list', 'portfolio' )
 				),
-				'description'			=>	__( 'Create a portfolio item', 'portfolio' ),
-				'public'				=>	true,
-				'show_ui'				=>	true,
-				'publicly_queryable'	=>	true,
-				'exclude_from_search'	=>	true,
-				'hierarchical'			=>	true,
-				'query_var'				=>	true,
-				'register_meta_box_cb'	=>	'prtfl_init_metaboxes',
-				'rewrite'				=>	array( 'slug' => $slug ),
-				'supports'				=>	array(
+				'description'			=> __( 'Create a project item', 'portfolio' ),
+				'public'				=> true,
+				'show_ui'				=> true,
+				'publicly_queryable'	=> true,
+				'exclude_from_search'	=> true,
+				'hierarchical'			=> true,
+				'query_var'				=> true,
+				'register_meta_box_cb'	=> 'prtfl_init_metaboxes',
+				'rewrite'				=> array( 'slug' => $prtfl_options['slug'] ),
+				'menu_icon'				=> 'dashicons-id-alt',
+				'supports'				=> array(
 					'title', /* Text input field to create a post title. */
 					'editor',
 					'custom-fields',
@@ -559,82 +294,126 @@
 				)
 			)
 		);
-	}
-}
 
-/* Create taxonomy for portfolio - Technologies and Executors Profile */
-if ( ! function_exists( 'prtfl_taxonomy_portfolio' ) ) {
-	function prtfl_taxonomy_portfolio() {
 		register_taxonomy(
 			'portfolio_executor_profile',
-			'portfolio',
+			$prtfl_options['post_type_name'],
 			array(
-				'hierarchical'			=>	false,
-				'update_count_callback' =>	'_update_post_term_count',
-				'labels'				=>	array(
-					'name'							=>	__( 'Executor Profiles', 'portfolio' ),
-					'singular_name'					=>	__( 'Executor Profile', 'portfolio' ),
-					'search_items'					=>	__( 'Search Executor Profiles', 'portfolio' ),
-					'popular_items'					=>	__( 'Popular Executor Profiles', 'portfolio' ),
-					'all_items'						=>	__( 'All Executor Profiles', 'portfolio' ),
-					'parent_item'					=>	__( 'Parent Executor Profile', 'portfolio' ),
-					'parent_item_colon'				=>	__( 'Parent Executor Profile:', 'portfolio' ),
-					'edit_item'						=>	__( 'Edit Executor Profile', 'portfolio' ),
-					'update_item'					=>	__( 'Update Executor Profile', 'portfolio' ),
-					'add_new_item'					=>	__( 'Add New Executor Profile', 'portfolio' ),
-					'new_item_name'					=>	__( 'New Executor Name', 'portfolio' ),
-					'separate_items_with_commas'	=>	__( 'Separate Executor Profiles with commas', 'portfolio' ),
-					'add_or_remove_items'			=>	__( 'Add or remove Executor Profile', 'portfolio' ),
-					'choose_from_most_used'			=>	__( 'Choose from the most used Executor Profiles', 'portfolio' ),
-					'menu_name'						=>	__( 'Executors', 'portfolio' )
+				'hierarchical'			=> false,
+				'update_count_callback' => '_update_post_term_count',
+				'labels'				=> array(
+					'name'							=> __( 'Executors', 'portfolio' ),
+					'singular_name'					=> __( 'Executor', 'portfolio' ),
+					'search_items'					=> __( 'Search Executors', 'portfolio' ),
+					'popular_items'					=> __( 'Popular Executors', 'portfolio' ),
+					'all_items'						=> __( 'All Executors', 'portfolio' ),
+					'parent_item'					=> __( 'Parent Executor', 'portfolio' ),
+					'parent_item_colon'				=> __( 'Parent Executor:', 'portfolio' ),
+					'edit_item'						=> __( 'Edit Executor', 'portfolio' ),
+					'update_item'					=> __( 'Update Executor', 'portfolio' ),
+					'add_new_item'					=> __( 'Add New Executor', 'portfolio' ),
+					'new_item_name'					=> __( 'New Executor Name', 'portfolio' ),
+					'separate_items_with_commas'	=> __( 'Separate executors with commas', 'portfolio' ),
+					'add_or_remove_items'			=> __( 'Add or remove Executor', 'portfolio' ),
+					'choose_from_most_used'			=> __( 'Choose from the most used Executors', 'portfolio' ),
+					'menu_name'						=> __( 'Executors', 'portfolio' ),
+					'items_list_navigation' 		=> __( 'Executors list navigation', 'portfolio' ),
+					'items_list'					=> __( 'Executors list', 'portfolio' )
 				),
-				'sort'					=>	true,
-				'args'					=>	array( 'orderby' => 'term_order' ),
-				'rewrite'				=>	array( 'slug' => 'executor_profile' ),
-				'show_tagcloud'			=>	false
+				'sort'					=> true,
+				'args'					=> array( 'orderby' => 'term_order' ),
+				'rewrite'				=> array( 'slug' => 'executor_profile' ),
+				'show_tagcloud'			=> false
 			)
 		);
 
 		register_taxonomy(
 			'portfolio_technologies',
-			'portfolio',
+			$prtfl_options['post_type_name'],
 			array(
-				'hierarchical'			=>	false,
-				'update_count_callback'	=>	'_update_post_term_count',
-				'labels'				=>	array(
-					'name'							=>	__( 'Technologies', 'portfolio' ),
-					'singular_name'					=>	__( 'Technology', 'portfolio'),
-					'search_items'					=>	__( 'Search Technologies', 'portfolio' ),
-					'popular_items'					=>	__( 'Popular Technologies', 'portfolio' ),
-					'all_items'						=>	__( 'All Technologies', 'portfolio' ),
-					'parent_item'					=>	__( 'Parent Technology', 'portfolio' ),
-					'parent_item_colon'				=>	__( 'Parent Technology:', 'portfolio' ),
-					'edit_item'						=>	__( 'Edit Technology', 'portfolio' ),
-					'update_item'					=>	__( 'Update Technology', 'portfolio' ),
-					'add_new_item'					=>	__( 'Add New Technology', 'portfolio' ),
-					'new_item_name'					=>	__( 'New Technology Name', 'portfolio' ),
-					'separate_items_with_commas'	=>	__( 'Separate Technologies with commas', 'portfolio' ),
-					'add_or_remove_items' 			=>	__( 'Add or remove Technology', 'portfolio' ),
-					'choose_from_most_used' 		=>	__( 'Choose from the most used technologies', 'portfolio' ),
-					'menu_name'						=>	__( 'Technologies', 'portfolio' )
+				'hierarchical'			=> false,
+				'update_count_callback'	=> '_update_post_term_count',
+				'labels'				=> array(
+					'name'							=> __( 'Technologies', 'portfolio' ),
+					'singular_name'					=> __( 'Technology', 'portfolio' ),
+					'search_items'					=> __( 'Search Technologies', 'portfolio' ),
+					'popular_items'					=> __( 'Popular Technologies', 'portfolio' ),
+					'all_items'						=> __( 'All Technologies', 'portfolio' ),
+					'parent_item'					=> __( 'Parent Technology', 'portfolio' ),
+					'parent_item_colon'				=> __( 'Parent Technology:', 'portfolio' ),
+					'edit_item'						=> __( 'Edit Technology', 'portfolio' ),
+					'update_item'					=> __( 'Update Technology', 'portfolio' ),
+					'add_new_item'					=> __( 'Add New Technology', 'portfolio' ),
+					'new_item_name'					=> __( 'New Technology Name', 'portfolio' ),
+					'separate_items_with_commas'	=> __( 'Separate technologies with commas', 'portfolio' ),
+					'add_or_remove_items'			=> __( 'Add or remove Technology', 'portfolio' ),
+					'choose_from_most_used'			=> __( 'Choose from the most used technologies', 'portfolio' ),
+					'menu_name'						=> __( 'Technologies', 'portfolio' ),
+					'items_list_navigation'			=> __( 'Technologies list navigation', 'portfolio' ),
+					'items_list'					=> __( 'Technologies list', 'portfolio' )
 				),
-				'query_var'				=>	'technologies',
-				'rewrite'				=>	array( 'slug' => 'technologies' ),
-				'public'				=>	true,
-				'show_ui'				=>	true,
-				'_builtin'				=>	true,
-				'show_tagcloud' 		=>	false
+				'query_var'				=> 'technologies',
+				'rewrite'				=> array( 'slug' => 'technologies' ),
+				'show_ui'				=> true,
+				'show_tagcloud' 		=> false
 			)
 		);
+
+		if ( isset( $prtfl_options["flush_rewrite_rules"] ) && 1 == $prtfl_options["flush_rewrite_rules"]  ) {
+			flush_rewrite_rules();
+			$prtfl_options["flush_rewrite_rules"] = 0;
+			update_option( 'prtfl_options', $prtfl_options );
+		}
 	}
 }
 
+/**
+ * Plugin include demo
+ * @return void
+ */
+if ( ! function_exists( 'prtfl_include_demo_data' ) ) {
+	function prtfl_include_demo_data() {
+		global $prtfl_BWS_demo_data;
+		require_once( plugin_dir_path( __FILE__ ) . 'inc/demo-data/class-bws-demo-data.php' );
+		$args = array(
+			'plugin_basename' 	=> plugin_basename( __FILE__ ),
+			'plugin_prefix'		=> 'prtfl_',
+			'plugin_name'		=> 'Portfolio',
+			'plugin_page'		=> 'portfolio.php&bws_active_tab=import-export',
+			'demo_folder'		=> plugin_dir_path( __FILE__ ) . 'inc/demo-data/'
+		);
+		$prtfl_BWS_demo_data = new Bws_Demo_Data( $args );
+
+		/* filter for image url from demo data */
+		add_filter( 'wp_get_attachment_url', array( $prtfl_BWS_demo_data, 'bws_wp_get_attachment_url' ), 10, 2 );
+		add_filter( 'wp_get_attachment_image_attributes', array( $prtfl_BWS_demo_data, 'bws_wp_get_attachment_image_attributes' ), 10, 3 );
+		add_filter( 'wp_update_attachment_metadata',array( $prtfl_BWS_demo_data, 'bws_wp_update_attachment_metadata' ), 10, 2 );
+	}
+}
+
+/**
+ * Plugin settings page
+ * @return void
+ */
+if ( ! function_exists( 'prtfl_settings_page' ) ) {
+	function prtfl_settings_page() {
+		require_once( dirname( __FILE__ ) . '/inc/class-prtfl-settings.php' );
+		$page = new Prtfl_Settings_Tabs( plugin_basename( __FILE__ ) ); ?>
+		<div class="wrap">
+			<h1><?php _e( 'Portfolio Settings', 'portfolio' ); ?></h1>
+			<?php $page->display_content(); ?>
+		</div>
+	<?php }
+}
+
 /* add query_var "post_type" in case we have another custom post type with query_var 'portfolio' (example: jetpack portfolio) */
 if ( ! function_exists( 'prtfl_request_filter' ) ) {
 	function prtfl_request_filter( $query_vars ) {
-		if ( isset( $query_vars["post_type"] ) && $query_vars["post_type"] == 'jetpack-portfolio' ) {
-			if ( ! get_posts( $query_vars ) )
-				$query_vars["post_type"] = 'portfolio';
+		global $prtfl_options;
+		if ( isset( $query_vars["post_type"] ) && 'jetpack-portfolio' == $query_vars["post_type"] ) {
+			if ( ! get_posts( $query_vars ) ) {
+				$query_vars["post_type"] = $prtfl_options['post_type_name'];
+			}
 		}
 		return $query_vars;
 	}
@@ -642,8 +421,11 @@
 
 if ( ! function_exists( 'prtfl_technologies_get_posts' ) ) {
 	function prtfl_technologies_get_posts( $query ) {
-		if ( ( isset( $query->query_vars["technologies"] ) || isset( $query->query_vars["portfolio_executor_profile"] ) ) && ( ! is_admin() ) )
-			$query->set( 'post_type', array( 'portfolio' ) );
+		global $prtfl_options;
+
+		if ( ( isset( $query->query_vars["technologies"] ) || isset( $query->query_vars["portfolio_executor_profile"] ) ) && ( ! is_admin() ) ) {
+			$query->set( 'post_type', array( $prtfl_options['post_type_name'] ) );
+		}
 		return $query;
 	}
 }
@@ -658,13 +440,13 @@
 			parent::__construct(
 					'portfolio_technologies_widget',
 					__( 'Technologies', 'portfolio' ),
-					array( 'description' => __( 'Your most used portfolio technologies as a tag cloud', 'portfolio' ) )
+					array( 'description' => __( 'The tag cloud with your most used portfolio technologies.', 'portfolio' ) )
 				);
 		}
 		/* Function to displaying widget in front end */
 		function widget( $args, $instance ) {
 			$widget_title = isset( $instance['widget_title'] ) ? $instance['widget_title'] : null;
-			$widget_title = apply_filters( 'widget_title', $widget_title, '', 'portfolio_technologies_widget' );
+			$widget_title = apply_filters( 'widget_title', $widget_title, $instance, $this->id_base );
 			echo $args['before_widget'];
 			if ( $widget_title )
 				echo $args['before_title'] . $widget_title . $args['after_title'];
@@ -676,7 +458,7 @@
 		/* Function to save widget settings */
 		function update( $new_instance, $old_instance ) {
 			$instance = array();
-			$instance['widget_title'] = ( ! empty( $new_instance['widget_title'] ) ) ? strip_tags( $new_instance['widget_title'] ) : null;		
+			$instance['widget_title'] = ( ! empty( $new_instance['widget_title'] ) ) ? strip_tags( $new_instance['widget_title'] ) : null;
 			return $instance;
 		}
 		/* Function to displaying widget settings in back end */
@@ -698,82 +480,154 @@
 /* Create custom permalinks for portfolio post type */
 if ( ! function_exists( 'prtfl_custom_permalinks' ) ) {
 	function prtfl_custom_permalinks( $rules ) {
+		global $prtfl_options;
 		$newrules = array();
-		$newrules['portfolio/page/([^/]+)/?$']	=	'index.php?pagename=portfolio&paged=$matches[1]';
-		$newrules['portfolio/page/([^/]+)?$']	=	'index.php?pagename=portfolio&paged=$matches[1]';
-		/* return $newrules + $rules; */
+
+		if ( empty( $prtfl_options ) ) {
+			$prtfl_options = get_option( 'prtfl_options' );
+			if ( empty( $prtfl_options ) ) {
+				register_prtfl_settings();
+			}
+		}
+
+		if ( ! empty( $prtfl_options['page_id_portfolio_template'] ) ) {
+			$parent = get_post( $prtfl_options['page_id_portfolio_template'] );
+			if ( ! empty( $parent ) ) {
+				if ( ! isset( $rules['(.+)/' . $parent->post_name . '/([^/]+)/?$'] ) || ! isset( $rules[ $parent->post_name . '/([^/]+)/?$'] ) ) {
+					$newrules['(.+)/' . $parent->post_name .  '/([^/]+)/?$'] = 'index.php?post_type=' . $prtfl_options['post_type_name'] . '&name=$matches[2]&posts_per_page=-1';
+					$newrules[ $parent->post_name . '/([^/]+)/?$'] = 'index.php?post_type=' . $prtfl_options['post_type_name'] . '&name=$matches[1]&posts_per_page=-1';
+					$newrules[ $parent->post_name . '/page/([^/]+)/?$'] = 'index.php?pagename=' . $parent->post_name . '&paged=$matches[1]';
+					$newrules[ $parent->post_name . '/page/([^/]+)?$'] = 'index.php?pagename=' . $parent->post_name . '&paged=$matches[1]';
+				}
+			}
+		}
+
+		/* fix feed permalink (<link rel="alternate" type="application/rss+xml" ... >) on the attachment single page (if the attachment is Attached to the portfolio page) */
+		if ( ! empty( $prtfl_options['slug'] ) ) {
+			$newrules[ $prtfl_options['slug'] . '/.+?/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' ] = 'index.php?attachment=$matches[1]&feed=$matches[2]';
+			$newrules[ $prtfl_options['slug'] . '/.+?/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' ]      = 'index.php?attachment=$matches[1]&feed=$matches[2]';
+		}
 		if ( $rules )
 			return array_merge( $newrules, $rules );
 	}
 }
 
-/* flush_rules() if our rules are not yet included */
-if ( ! function_exists( 'prtfl_flush_rules' ) ) {
-	function prtfl_flush_rules() {
-		$rules = get_option( 'rewrite_rules' );
-		if ( ! isset( $rules['portfolio/page/([^/]+)/?$'] ) ) {
-			global $wp_rewrite;
-			$wp_rewrite->flush_rules();
+/**
+* Load a template. Handles template usage so that plugin can use own templates instead of the themes.
+*
+* Templates are in the 'templates' folder.
+* overrides in /{theme}/bws-templates/ by default.
+* @param mixed $template
+* @return string
+*/
+if ( ! function_exists( 'prtfl_template_include' ) ) {
+	function prtfl_template_include( $template ) {
+		global $prtfl_options, $wp_query;
+
+		if ( function_exists( 'is_embed' ) && is_embed() ) {
+			return $template;
 		}
+
+		$post_type = get_post_type();
+		if ( is_single() && $prtfl_options['post_type_name'] == $post_type ) {
+			$file = 'portfolio-post.php';
+		} elseif ( $prtfl_options['post_type_name'] == $post_type && ( isset( $wp_query->query_vars['technologies'] ) || isset( $wp_query->query_vars['portfolio_executor_profile'] ) ) ) {
+			$file = 'portfolio.php';
+		} elseif ( ! empty( $prtfl_options['page_id_portfolio_template'] ) && is_page( $prtfl_options['page_id_portfolio_template'] ) ) {
+			$file = 'portfolio.php';
+		}
+
+		if ( isset( $file ) ) {
+			if ( ! wp_script_is( 'prtfl_front_script', 'registered' ) ) {
+				wp_register_script( 'prtfl_front_script', plugins_url( 'js/front_script.js', __FILE__ ), array( 'jquery' ) );
+			}
+
+			$find = array( $file, 'bws-templates/' . $file );
+			$template = locate_template( $find );
+
+			if ( ! $template ) {
+				$template = untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/templates/' . $file;
+			}
+		}
+
+		return $template;
 	}
 }
 
 /* Initialization of all metaboxes on the 'Add Portfolio' and Edit Portfolio pages */
 if ( ! function_exists( 'prtfl_init_metaboxes' ) ) {
 	function prtfl_init_metaboxes() {
-		add_meta_box( 'Portfolio-Info', __( 'Portfolio Info', 'portfolio' ), 'prtfl_post_custom_box', 'portfolio', 'normal', 'high' ); /* Description metaboxe */
-		add_meta_box( 'prtfl_categories_meta_box', __( 'Categories', 'portfolio' ), 'prtfl_categories_meta_box', 'portfolio', 'side', 'low' );
-		if ( ! ( function_exists( 'rttchr_metabox_content_in_post' ) || function_exists( 'rttchrpr_metabox_content_in_post' ) ) ) {
-			add_meta_box( 'prtfl_rttchr_metabox_ad', __( 'Already attached', 'portfolio' ), 'prtfl_rttchr_attach_box', 'portfolio', 'side', 'low' );
+		global $prtfl_options;
+		add_meta_box( 'prtfl_metabox_images', __( 'Images', 'portfolio' ), 'prtfl_metabox_images_block', $prtfl_options['post_type_name'], 'normal', 'high' );
+		add_meta_box( 'Portfolio-Info', __( 'General', 'portfolio' ), 'prtfl_post_custom_box', $prtfl_options['post_type_name'], 'normal', 'high' );
+
+		$bws_hide_premium_options_check = bws_hide_premium_options_check( $prtfl_options );
+		if ( ! $bws_hide_premium_options_check ) {
+			add_meta_box( 'prtfl_categories_meta_box', __( 'Categories', 'portfolio' ), 'prtfl_categories_meta_box', $prtfl_options['post_type_name'], 'side', 'low' );
+			add_meta_box( 'prtfl_sectors_meta_box', __( 'Sectors', 'portfolio' ), 'prtfl_sectors_meta_box', $prtfl_options['post_type_name'], 'side', 'low' );
+			add_meta_box( 'prtfl_services_meta_box', __( 'Services', 'portfolio' ), 'prtfl_services_meta_box', $prtfl_options['post_type_name'], 'side', 'low' );
 		}
-		
 	}
 }
 
 /* Create custom meta box for portfolio post type */
 if ( ! function_exists( 'prtfl_post_custom_box' ) ) {
 	function prtfl_post_custom_box( $obj = '', $box = '' ) {
-		global $prtfl_boxes;
+		global $prtfl_boxes, $prtfl_plugin_info, $wp_version, $prtfl_options;
 		/* Generate box contents */
-		foreach ( $prtfl_boxes[ $box[ 'id' ] ] as $prtfl_box ) {
-			echo prtfl_text_field( $prtfl_box );
+		foreach ( $prtfl_boxes[ $box['id'] ] as $box ) {
+			echo prtfl_general_field( $box );
 		}
+
+		$bws_hide_premium_options_check = bws_hide_premium_options_check( $prtfl_options );
+		if ( ! $bws_hide_premium_options_check ) { ?>
+			<div class="bws_pro_version_bloc">
+				<div class="bws_pro_version_table_bloc">
+					<div class="bws_table_bg" style="top: 0px; z-index: 2;"></div>
+
+
+					<div class="portfolio_admin_box">
+						<p><label for="prtfl_client"><strong><?php _e( 'Client', 'portfolio' ); ?></strong></label></p>
+						<?php /* display visual editor */
+						$settings = array(
+							'media_buttons' => 1,
+							'textarea_name' => 'prtfl_client',
+							'textarea_rows' => 5,
+							'tinymce'       => 1
+						);
+						wp_editor( '', 'prtfl_client', $settings ); ?>
+					</div>
+					<div class="portfolio_admin_box">
+						<p><label for="prtfl_featured"><strong><?php _e( 'Featured project', 'portfolio' ); ?></strong></label></p>
+						<p><input id="prtfl_featured" disabled="disabled" type="checkbox" name="prtfl_featured" value="1" />
+							<em><?php _e( 'Add to slider', 'portfolio' ); ?></em>
+						</p>
+					</div>
+					<div class="bws_pro_version_tooltip">
+						<a class="bws_button" href="https://bestwebsoft.com/products/wordpress/plugins/portfolio/?k=f047e20c92c972c398187a4f70240285&pn=74&v=<?php echo $prtfl_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="Portfolio Pro Plugin" style="z-index: 3;" ><?php _e( 'Learn More', 'portfolio' ); ?></a>
+						<div class="clear"></div>
+					</div>
+				</div>
+			</div>
+		<?php }
 	}
 }
 
-/* Create custom meta box for re-attacher ad in portfolio */
-if ( ! function_exists( 'prtfl_rttchr_attach_box' ) ) {
-	function prtfl_rttchr_attach_box() { 
-		global $prtfl_plugin_info, $wp_version;
+/**
+ * This is the field meta box
+ * @param     array      $args   array of data for meta box
+ * @return                       html structure of meta box
+ */
+if ( ! function_exists( 'prtfl_general_field' ) ) {
+	function prtfl_general_field( $args ) {
+		global $post;
 
-		if ( ! function_exists( 'get_plugins' ) )
-			require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
-		$all_plugins = get_plugins();
-		if ( isset( $all_plugins['re-attacher/re-attacher.php'] ) || isset( $all_plugins['re-attacher-pro/re-attacher-pro.php'] ) ) {
-			/* if re-attacher is installed */
-			$link = "plugins.php";
-			$text = __( 'Activate', 'portfolio' );
-		} else {
-			if ( function_exists( 'is_multisite' ) )
-				$link = ( ! is_multisite() ) ? admin_url( '/' ) : network_admin_url( '/' );
-			else
-				$link = admin_url( '/' );
-			$link = $link . 'plugin-install.php?tab=search&type=term&s=Re-attacher+BestWebSoft&plugin-search-input=Search+Plugins';
-			$text = __( 'Install now', 'portfolio' );			
-		} ?>
-		<p>
-			<?php _e( "If you'd like to attach the files, which are already uploaded, please use Re-attacher plugin.", 'portfolio' ) ; 
-			if ( 3.5 > $wp_version ) { ?>
-				<br />
-				<strong>
-					<?php echo '($nbsp;' . __( 'Requires at least', 'portfolio' ) . '&nbsp;WordPress 3.5 )'; ?>
-				</strong>
-			<?php } ?>
-		</p>
-		<p>
-			<a target="_blank" class="button-secondary" href="http://bestwebsoft.com/products/re-attacher/?k=a9c95424ed55d41fd762ce8aad52a519&pn=74&v=<?php echo $prtfl_plugin_info["Version"] . '&wp_v=' . $wp_version ?>" style="margin:0px 5px 2px;"><?php _e( 'Learn more', 'portfolio' ); ?></a>
-			<a class="button-primary" href="<?php echo $link; ?>" target="_blank" style="margin-right: 5px;"><?php echo $text; ?></a>
-		</p>
+		$post_meta = get_post_meta( $post->ID, 'prtfl_information', true );
+		$value = ! empty( $post_meta ) && is_array( $post_meta ) && ! empty( $post_meta[ $args['name'] ] ) ? $post_meta[ $args['name'] ] : ""; ?>
+		<div class="portfolio_admin_box">
+			<p><label for="<?php echo $args['name']; ?>"><strong><?php echo $args['title']; ?></strong></label></p>
+			<p><input id="<?php echo $args['name']; ?>" type="text" style="width:80%;" name="<?php echo $args['name']; ?>" value="<?php echo $value; ?>" /></p>
+		</div>
 	<?php }
 }
 
@@ -794,42 +648,63 @@
 								<li><a href="#"><?php _e( 'Most Used', 'portfolio' ); ?></a></li>
 							</ul>
 							<div class="tabs-panel" style="display: none;">
-								<ul class="categorychecklist form-no-clear">				
+								<ul class="categorychecklist form-no-clear">
 									<li class="popular-category">
 										<label class="selectit"><input checked="checked" disabled="disabled" value="236" type="checkbox" /><?php _e( 'Uncatgorized', 'portfolio' ); ?></label>
 									</li>
 								</ul>
 							</div>
-							<div class="tabs-panel">		
-								<ul class="categorychecklist form-no-clear">				
+							<div class="tabs-panel">
+								<ul class="categorychecklist form-no-clear">
 									<li class="popular-category"><label class="selectit"><input value="236" name="tax_input[portfolio_categories][]" checked="checked" disabled="disabled" type="checkbox" /> <?php _e( 'Uncatgorized', 'portfolio' ); ?></label></li>
 								</ul>
 							</div>
-							<div class="wp-hidden-children">
-								<h4><a href="#">+ <?php _e( 'Add New Category', 'portfolio' ); ?></a></h4>
-								<p class="category-add wp-hidden-child">
-									<label class="screen-reader-text"><?php _e( 'Add New Category', 'portfolio' ); ?></label>
-									<input name="newportfolio_categories" class="form-required form-input-tip" value="<?php _e( 'New Category Name', 'portfolio' ); ?>" type="text" disabled="disabled" /><label class="screen-reader-text"><?php _e( 'Parent Category', 'portfolio' ); ?>:</label>
-									<select name="newportfolio_categories_parent" class="postform">
-										<option value="-1">— <?php _e( 'Parent Category', 'portfolio' ); ?> —</option>
-										<option class="level-0" value="236"><?php _e( 'Uncatgorized', 'portfolio' ); ?></option>
-									</select>
-									<input class="button category-add-submit" value="<?php _e( 'Add New Category', 'portfolio' ); ?>" type="button" disabled="disabled" />
-								</p>
-							</div>
 						</div>
 					</div>
 				</div>
 				<div class="bws_pro_version_tooltip">
-					<div class="bws_info">
-						<?php _e( 'Unlock premium options by upgrading to a PRO version.', 'portfolio' ); ?> 
-						<a href="http://bestwebsoft.com/products/portfolio/?k=f047e20c92c972c398187a4f70240285&pn=74&v=<?php echo $prtfl_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="Portfolio Pro Plugin"><?php _e( 'Learn More', 'portfolio' ); ?></a>
+					<a class="bws_button" href="https://bestwebsoft.com/products/wordpress/plugins/portfolio/?k=f047e20c92c972c398187a4f70240285&pn=74&v=<?php echo $prtfl_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="Portfolio Pro Plugin"><?php _e( 'Learn More', 'portfolio' ); ?></a>
+					<div class="clear"></div>
+				</div>
+			</div>
+		</div>
+	<?php }
+}
+
+/**
+ * Banner on Portfolio Edit Page
+ */
+if ( ! function_exists( 'prtfl_sectors_meta_box' ) ) {
+	function prtfl_sectors_meta_box() {
+		global $prtfl_plugin_info, $wp_version; ?>
+		<div class="bws_pro_version_bloc">
+			<div class="bws_pro_version_table_bloc">
+				<div class="bws_table_bg" style="top: 0px;"></div>
+				<div class="prtfl_portfolio_sectorsdiv">
+					<div class="inside">
+						<div class="">
+							<ul class="category-tabs">
+								<li class="tabs"><a href="#"><?php _e( 'All Sectors', 'portfolio' ); ?></a></li>
+								<li><a href="#"><?php _e( 'Most Used', 'portfolio' ); ?></a></li>
+							</ul>
+							<div class="tabs-panel" style="display: none;">
+								<ul class="categorychecklist form-no-clear">
+									<li class="popular-category">
+										<label class="selectit"><input disabled="disabled" value="236" type="checkbox" /><?php _e( 'Uncatgorized', 'portfolio' ); ?></label>
+									</li>
+								</ul>
+							</div>
+							<div class="tabs-panel">
+								<ul class="categorychecklist form-no-clear">
+									<li class="popular-category"><label class="selectit"><input value="236" name="tax_input[portfolio_sectors][]" disabled="disabled" type="checkbox" /> <?php _e( 'Sector', 'portfolio' ); ?> 1</label></li>
+									<li class="popular-category"><label class="selectit"><input value="237" name="tax_input[portfolio_sectors][]" disabled="disabled" type="checkbox" /> <?php _e( 'Sector', 'portfolio' ); ?> 2</label></li>
+								</ul>
+							</div>
+						</div>
 					</div>
-					<div class="bws_pro_links">
-						<a class="bws_button" href="http://bestwebsoft.com/products/portfolio/buy/?k=f047e20c92c972c398187a4f70240285&pn=74&v=<?php echo $prtfl_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="Portfolio Pro Plugin">
-							<?php _e( 'Go', 'portfolio' ); ?> <strong>PRO</strong>
-						</a>
-					</div>
+				</div>
+				<div class="bws_pro_version_tooltip">
+					<a class="bws_button" href="https://bestwebsoft.com/products/wordpress/plugins/portfolio/?k=f047e20c92c972c398187a4f70240285&pn=74&v=<?php echo $prtfl_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="Portfolio Pro Plugin"><?php _e( 'Learn More', 'portfolio' ); ?></a>
 					<div class="clear"></div>
 				</div>
 			</div>
@@ -837,61 +712,142 @@
 	<?php }
 }
 
-/* This is the default text field meta box */
-if ( ! function_exists( 'prtfl_text_field' ) ) {
-	function prtfl_text_field( $args ) {
-		global $post;
-		$description = $args[2];
-		if ( '1' == get_option( 'prtfl_postmeta_update' ) ) {
-			$post_meta = get_post_meta( $post->ID, 'prtfl_information', true);
-			$args[2] = is_array( $post_meta ) ? esc_html( $post_meta[ $args[0] ] ) : "" ;
-		} else {
-			$args[2] = esc_html( get_post_meta( $post->ID, $args[0], true ) );
-		}
-		$label_format =
-			'<div class="portfolio_admin_box">' .
-			'<p><label for="%1$s"><strong>%2$s</strong></label></p>' .
-			'<p><input style="width: 80%%;" type="text" name="%1$s" id="%1$s" value="%3$s" /></p>' .
-			'<p><em>' . $description .'</em></p>' .
-			'</div>';
-		if ( '_prtfl_date_compl' == $args[0] )
-			echo '<script type="text/javascript">jQuery(document).ready(function(){jQuery("#_prtfl_date_compl").simpleDatepicker({ startdate: new Date().getFullYear()-3, enddate: new Date().getFullYear()+3 });});</script>';
-		return vsprintf( $label_format, $args );
-	}
+/**
+ * Banner on Portfolio Edit Page
+ */
+if ( ! function_exists( 'prtfl_services_meta_box' ) ) {
+	function prtfl_services_meta_box() {
+		global $prtfl_plugin_info, $wp_version; ?>
+		<div class="bws_pro_version_bloc">
+			<div class="bws_pro_version_table_bloc">
+				<div class="bws_table_bg" style="top: 0px;"></div>
+				<div class="prtfl_portfolio_servicesdiv">
+					<div class="inside">
+						<div class="">
+							<ul class="category-tabs">
+								<li class="tabs"><a href="#"><?php _e( 'All Services', 'portfolio' ); ?></a></li>
+								<li><a href="#"><?php _e( 'Most Used', 'portfolio' ); ?></a></li>
+							</ul>
+							<div class="tabs-panel" style="display: none;">
+								<ul class="categorychecklist form-no-clear">
+									<li class="popular-category">
+										<label class="selectit"><input disabled="disabled" value="236" type="checkbox" /><?php _e( 'Uncatgorized', 'portfolio' ); ?></label>
+									</li>
+								</ul>
+							</div>
+							<div class="tabs-panel">
+								<ul class="categorychecklist form-no-clear">
+									<li class="popular-category"><label class="selectit"><input value="236" name="tax_input[portfolio_services][]" disabled="disabled" type="checkbox" /> <?php _e( 'Service', 'portfolio' ); ?> 1</label></li>
+									<li class="popular-category"><label class="selectit"><input value="237" name="tax_input[portfolio_services][]" disabled="disabled" type="checkbox" /> <?php _e( 'Service', 'portfolio' ); ?> 2</label></li>
+								</ul>
+							</div>
+						</div>
+					</div>
+				</div>
+				<div class="bws_pro_version_tooltip">
+					<a class="bws_button" href="https://bestwebsoft.com/products/wordpress/plugins/portfolio/?k=f047e20c92c972c398187a4f70240285&pn=74&v=<?php echo $prtfl_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="Portfolio Pro Plugin"><?php _e( 'Learn More', 'portfolio' ); ?></a>
+					<div class="clear"></div>
+				</div>
+			</div>
+		</div>
+	<?php }
+}
+
+if ( ! function_exists( 'prtfl_metabox_images_block' ) ) {
+	function prtfl_metabox_images_block() {
+		global $post; ?>
+		<div id="prtfl_images_container">
+			<noscript><div class="error"><p><?php _e( 'Please enable JavaScript to add or delete images.', 'portfolio' ); ?></p></div></noscript>
+			<ul>
+				<?php if ( metadata_exists( 'post', $post->ID, '_prtfl_images' ) ) {
+					$prtfl_images = get_post_meta( $post->ID, '_prtfl_images', true );
+				} else {
+					/* Compatibility with old version 1.0.3 */
+					$args = array(
+						'post_parent'		=> $post->ID,
+						'post_type'			=> 'attachment',
+						'post_mime_type'	=> 'image',
+						'numberposts'		=> -1,
+						'orderby'			=> 'menu_order',
+						'order'				=> 'ASC',
+						'exclude'			=> get_post_thumbnail_id(),
+						'fields'			=> 'ids'
+					);
+					$attachments = get_children( $args );
+					$prtfl_images = implode( ',', $attachments );
+				}
+
+				$attachments = array_filter( explode( ',', $prtfl_images ) );
+
+				$update_meta = false;
+
+				if ( ! empty( $attachments ) ) {
+					foreach ( $attachments as $attachment_id ) {
+						$attachment = wp_get_attachment_image( $attachment_id, 'thumbnail' );
+
+						/* skip if attachment is empty */
+						if ( empty( $attachment ) ) {
+							$update_meta = true;
+							continue;
+						}
+
+						echo '<li class="prtfl_single_image" data-attachment_id="' . esc_attr( $attachment_id ) . '">
+							' . $attachment . '
+							<span class="prtfl_delete_image"><a href="#" title="' . __( 'Delete image', 'portfolio' ) . '">' . __( 'Delete', 'portfolio' ) . '</a></span>
+						</li>';
+
+						$updated_images_ids[] = $attachment_id;
+					}
+
+					/* update product meta to set new portfolio ids */
+					if ( $update_meta )
+						update_post_meta( $post->ID, '_prtfl_images', implode( ',', $updated_images_ids ) );
+				} ?>
+			</ul>
+			<input type="hidden" id="prtfl_images" name="prtfl_images" value="<?php echo esc_attr( $prtfl_images ); ?>" />
+		</div>
+		<p class="prtfl_add_portfolio_images hide-if-no-js">
+			<a href="#" data-choose="<?php esc_attr_e( 'Add Images to Portfolio', 'portfolio' ); ?>" data-update="<?php esc_attr_e( 'Add to portfolio', 'portfolio' ); ?>" data-delete="<?php esc_attr_e( 'Delete image', 'portfolio' ); ?>" data-text="<?php esc_attr_e( 'Delete', 'portfolio' ); ?>"><?php _e( 'Add images', 'portfolio' ); ?></a>
+		</p>
+	<?php }
 }
 
 /* When the post is saved, saves our custom data */
-if ( ! function_exists ( 'prtfl_save_postdata' ) ) {
+if ( ! function_exists( 'prtfl_save_postdata' ) ) {
 	function prtfl_save_postdata( $post_id, $post ) {
-		global $prtfl_boxes;
+		global $prtfl_boxes, $prtfl_options;
 
-		register_prtfl_settings();
-
-		if ( "portfolio" == $post->post_type && ! wp_is_post_revision( $post_id ) && ! empty( $_POST ) ) { /* Don't store custom data twice */
+		if ( $prtfl_options['post_type_name'] == $post->post_type && ! wp_is_post_revision( $post_id ) && ! empty( $_POST ) ) { /* Don't store custom data twice */
 			/* Verify this came from the our screen and with proper authorization, because save_post can be triggered at other times */
-			if ( ! current_user_can ( 'edit_page', $post->ID ) ) {
+			if ( ! current_user_can( 'edit_page', $post->ID ) ) {
 				return $post->ID;
 			}
 
 			/* We'll put it into an array to make it easier to loop though. The data is already in $prtfl_boxes, but we need to flatten it out. */
 			foreach ( $prtfl_boxes as $prtfl_boxe ) {
 				foreach ( $prtfl_boxe as $prtfl_fields ) {
-					if ( $prtfl_fields[0] == '_prtfl_link' || $prtfl_fields[0] == '_prtfl_svn' )
-						$my_data[ $prtfl_fields[0] ] = esc_url( $_POST[ $prtfl_fields[0] ] );
-					else
-						$my_data[ $prtfl_fields[0] ] = stripslashes( esc_html( $_POST[ $prtfl_fields[0] ] ) );
+					if ( isset( $_POST[ $prtfl_fields['name'] ] ) ) {
+						if ( 'url' == $prtfl_fields['type'] ) {
+							$my_data[ $prtfl_fields['name'] ] = esc_url( $_POST[ $prtfl_fields['name'] ] );
+						} else {
+							$my_data[ $prtfl_fields['name'] ] = stripslashes( esc_html( $_POST[ $prtfl_fields['name'] ] ) );
+						}
+					}
 				}
 			}
-			/*	Add values of $my_data as custom fields. Let's cycle through the $my_data array! */
-			if ( get_post_meta( $post->ID, 'prtfl_information', FALSE ) ) {
-				/* Custom field has a value and this custom field exists in database */
-				update_post_meta( $post->ID, 'prtfl_information', $my_data );
-			} elseif ( $value ) {
-				/* Custom field has a value, but this custom field does not exist in database */
-				add_post_meta( $post->ID, 'prtfl_information', $my_data );
-			} else {
-				/* Custom field does not have a value, but this custom field exists in database */
-				update_post_meta( $post->ID, 'prtfl_information', $my_data );
+			if ( isset( $my_data ) ) {
+				/*	Add values of $my_data as custom fields. Let's cycle through the $my_data array! */
+				if ( get_post_meta( $post->ID, 'prtfl_information', FALSE ) ) {
+					/* Custom field has a value and this custom field exists in database */
+					update_post_meta( $post->ID, 'prtfl_information', $my_data );
+				} else {
+					/* Custom field does not have a value, but this custom field exists in database */
+					update_post_meta( $post->ID, 'prtfl_information', $my_data );
+				}
+			}
+			if ( isset( $_POST['prtfl_images'] ) ) {
+				$attachment_ids = ! empty( $_POST['prtfl_images'] ) ? array_filter( explode( ',', sanitize_text_field( $_POST['prtfl_images'] ) ) ) : array();
+				update_post_meta( $post_id, '_prtfl_images', implode( ',', $attachment_ids ) );
 			}
 		}
 	}
@@ -900,10 +856,10 @@
 /**
  * Replace shortcode [latest_portfolio_items] from portfolio content before portfolio saving
  */
-if ( ! function_exists ( 'prtfl_content_save_pre' ) ) {
+if ( ! function_exists( 'prtfl_content_save_pre' ) ) {
 	function prtfl_content_save_pre( $content ) {
-		global $post;
-		if ( isset( $post ) && "portfolio" == $post->post_type && ! wp_is_post_revision( $post->ID ) && ! empty( $_POST ) ) {
+		global $post, $prtfl_options;
+		if ( isset( $post ) && $prtfl_options['post_type_name'] == $post->post_type && ! wp_is_post_revision( $post->ID ) && ! empty( $_POST ) ) {
 			/* remove shortcode */
 			$content = preg_replace( '/\[latest_portfolio_items count=[\d]*\]/', '', $content );
 		}
@@ -911,126 +867,283 @@
 	}
 }
 
-if ( ! function_exists ( 'prtfl_register_plugin_links' ) ) {
-	function prtfl_register_plugin_links( $links, $file ) {
-		$base = plugin_basename(__FILE__);
-		if ( $file == $base ) {
-			if ( ! is_network_admin() )
-				$links[]	=	'<a href="admin.php?page=portfolio.php">' . __( 'Settings', 'portfolio' ) . '</a>';
-			$links[]	=	'<a href="http://wordpress.org/plugins/portfolio/faq/" target="_blank">' . __( 'FAQ', 'portfolio' ) . '</a>';
-			$links[]	=	'<a href="http://support.bestwebsoft.com">' . __( 'Support', 'portfolio' ) . '</a>';
-		}
-		return $links;
-	}
-}
+/* this function add custom fields and images for PDF&Print plugin in Portfolio post */
+if ( ! function_exists( 'prtfl_add_pdf_print_content' ) ) {
+	function prtfl_add_pdf_print_content( $content ) {
+		global $post, $prtfl_options;
+		$current_post_type = get_post_type();
+		$custom_content = '';
+
+		if ( $prtfl_options['post_type_name'] == $current_post_type && ! empty( $post ) ) {
+
+			if ( ! $prtfl_options ) {
+				$prtfl_options = get_option( 'prtfl_options' );
+			}
+
+			$post_meta	= get_post_meta( $post->ID, 'prtfl_information', true );
+			$user_id 	= get_current_user_id();
+
+			if ( 1 == $prtfl_options['date_additional_field'] ) {
+				$date_compl		=	isset( $post_meta['_prtfl_date_compl'] ) ? $post_meta['_prtfl_date_compl'] : '';
+				if ( ! empty( $date_compl ) ) {
+					$custom_content .= '<p><span class="lable">' . $prtfl_options['date_text_field'] .' </span> ' . $date_compl . '</p>';
+				}
+			}
+
+			if ( 1 == $prtfl_options['link_additional_field'] && ! empty( $post_meta['_prtfl_link'] ) ) {
+
+				if ( false !== parse_url( $post_meta['_prtfl_link'] ) ) {
+					if ( ( 0 == $user_id && 0 == $prtfl_options['link_additional_field_for_non_registered'] ) || 0 != $user_id ) {
+						$custom_content .= '<p><span class="lable">' . $prtfl_options['link_text_field'] . '</span> <a href="' . $post_meta['_prtfl_link'] . '">' . $post_meta['_prtfl_link'] . '</a></p>';
+					} else {
+						$custom_content .= '<p><span class="lable">' . $prtfl_options['link_text_field'] . '</span> ' . $post_meta['_prtfl_link'] . '</p>';
+					}
+				} else {
+					$custom_content .= '<p><span class="lable">' . $prtfl_options['link_text_field'] . '</span> ' . $post_meta['_prtfl_link'] . '</p>';
+				}
+			}
+			if ( 0 != $user_id ) {
+				if ( 1 == $prtfl_options['svn_additional_field'] && ! empty( $post_meta['_prtfl_svn'] ) ) {
+					$custom_content .= '<p><span class="lable">' . $prtfl_options['svn_text_field'] . '</span> ' . $post_meta['_prtfl_svn'] . '</p>';
+				}
+
+				if ( 1 == $prtfl_options['executor_additional_field'] ) {
+					$executors_profile = wp_get_object_terms( $post->ID, 'portfolio_executor_profile' );
+					if ( ! empty( $executors_profile ) ) {
+						$custom_content .= '<p><span class="lable">' . $prtfl_options['executor_text_field'] . '</span>';
+						$count = 0;
+						foreach ( $executors_profile as $profile ) {
+							if ( $count > 0 ) {
+								$custom_content .= ', ';
+							}
+							$custom_content .= '<a href="' . get_term_link( $profile->slug, 'portfolio_executor_profile' ) . '" title="' . $profile->name . ' profile" target="_blank">' . $profile->name . '</a>';
+							$count++;
+						}
+						$custom_content .= '</p>';
+					}
+				}
+			}
+
+		} elseif ( 'portfolio.php' == basename( get_page_template() ) ) {
+			global $wp_query, $request, $prtfl_options, $pdfprnt_options_array, $pdfprntpr_options;
+
+			if ( ! $prtfl_options ) {
+				$prtfl_options = get_option( 'prtfl_options' );
+			}
 
-if ( ! function_exists ( 'prtfl_plugin_action_links' ) ) {
-	function prtfl_plugin_action_links( $links, $file ) {
-		if ( ! is_network_admin() ) {
-			/* Static so we don't call plugin_basename on every plugin row. */
-			static $this_plugin;
-			if ( ! $this_plugin ) $this_plugin = plugin_basename( __FILE__ );
+			$count = 0;
+			if ( get_query_var( 'paged' ) ) {
+				$paged = get_query_var( 'paged' );
+			} elseif ( get_query_var( 'page' ) ) {
+				$paged = get_query_var( 'page' );
+			} else {
+				$paged = 1;
+			}
+			$per_page = $showitems = get_option( 'posts_per_page' );
+			$technologies = isset( $wp_query->query_vars["technologies"] ) ? $wp_query->query_vars["technologies"] : "";
+			$executor_profile = isset( $wp_query->query_vars["portfolio_executor_profile"] ) ? $wp_query->query_vars["portfolio_executor_profile"] : "";
+			if ( "" != $technologies ) {
+				$args = array(
+					'post_type' 		=> $prtfl_options['post_type_name'],
+					'post_status' 		=> 'publish',
+					'orderby' 			=> $prtfl_options['order_by'],
+					'order'			 	=> $prtfl_options['order'],
+					'posts_per_page'	=> $per_page,
+					'paged' 			=> $paged,
+					'tax_query' 		=> array(
+						array(
+							'taxonomy' 	=> 'portfolio_technologies',
+							'field' 	=> 'slug',
+							'terms' 	=> $technologies
+						)
+					)
+				);
+			} elseif ( "" != $executor_profile ) {
+				$args = array(
+					'post_type' 		=> $prtfl_options['post_type_name'],
+					'post_status' 		=> 'publish',
+					'orderby'			=> $prtfl_options['order_by'],
+					'order' 			=> $prtfl_options['order'],
+					'posts_per_page' 	=> $per_page,
+					'paged' 			=> $paged,
+					'tax_query' 		=> array(
+						array(
+							'taxonomy' 	=> 'portfolio_executor_profile',
+							'field' 	=> 'slug',
+							'terms' 	=> $executor_profile
+						)
+					)
+				);
+			} else {
+				$args = array(
+					'post_type'			=> $prtfl_options['post_type_name'],
+					'post_status'		=> 'publish',
+					'orderby'			=> $prtfl_options['order_by'],
+					'order'				=> $prtfl_options['order'],
+					'posts_per_page'	=> $per_page,
+					'paged'				=> $paged
+				);
+			}
+
+			$second_query = new WP_Query( $args );
+			$request = $second_query->request;
+
+			if ( $second_query->have_posts() ) {
+				while ( $second_query->have_posts() ) {
+					$second_query->the_post();
+					$custom_content .= '<div class="portfolio_content entry-content">
+						<div class="entry">';
+
+					$post_meta = get_post_meta( $post->ID, 'prtfl_information', true );
+					$user_id = get_current_user_id();
 
-			if ( $file == $this_plugin ) {
-				$settings_link = '<a href="admin.php?page=portfolio.php">' . __( 'Settings', 'portfolio' ) . '</a>';
-				array_unshift( $links, $settings_link );
+					$short_descr = isset( $post_meta['_prtfl_short_descr'] ) ? $post_meta['_prtfl_short_descr'] : '';
+					if ( empty( $short_descr ) ) {
+						$short_descr = get_the_excerpt();
+					}
+					$title = get_the_title();
+					if ( empty( $title ) ) {
+						$title = '(' . __( 'No title', 'portfolio' ) . ')';
+					}
+					$post_thumbnail_id	=	get_post_thumbnail_id( $post->ID );
+					if ( empty( $post_thumbnail_id ) ) {
+						$args = array(
+							'post_parent'		=> $post->ID,
+							'post_type'			=> 'attachment',
+							'post_mime_type'	=> 'image',
+							'numberposts'		=> 1
+						);
+						$attachments		= get_children( $args );
+						$post_thumbnail_id	= key( $attachments );
+					}
+
+					if ( ( isset( $pdfprnt_options_array['show_featured_image'] ) && 1 == $pdfprnt_options_array['show_featured_image'] )
+						|| ( isset( $pdfprntpr_options['show_featured_image'] ) && 1 == $pdfprntpr_options['show_featured_image'] ) ) {
+
+						$image = wp_get_attachment_image_src( $post_thumbnail_id, $prtfl_options['image_size_album'] );
+
+						if ( ! empty( $image[0] ) ) {
+							/* get width and height for image_size_album */
+							if ( 'portfolio-thumb' != $prtfl_options['image_size_album'] ) {
+								$width  = absint( get_option( $prtfl_options['image_size_album'] . '_size_w' ) );
+								$height = absint( get_option( $prtfl_options['image_size_album'] . '_size_h' ) );
+							} else {
+								$width  = $prtfl_options['custom_size_px']['portfolio-thumb'][0];
+								$height = $prtfl_options['custom_size_px']['portfolio-thumb'][1];
+							}
+							$image_alt 	= get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true );
+
+							$custom_content .= '<div class="portfolio_thumb"><img src="' . $image[0] . '" width="' . $width . '" height="' . $height . '" style="width:' . $width . 'px; height:' . $height . 'px;" alt="' . $image_alt . '" /></div>';
+						}
+					}
+
+					$custom_content .= '<div class="portfolio_short_content">
+								<div class="item_title">
+									<p><a href="' . get_permalink() . '" rel="bookmark">' . $title . '</a></p>
+								</div>';
+					if ( 1 == $prtfl_options['date_additional_field'] ) {
+						$date_compl	= isset( $post_meta['_prtfl_date_compl'] ) ? $post_meta['_prtfl_date_compl'] : '';
+						if ( ! empty( $date_compl ) ) {
+							$custom_content .= '<p><span class="lable">' . $prtfl_options['date_text_field'] . '</span> ' . $date_compl . '</p>';
+						}
+					}
+
+					if ( 1 == $prtfl_options['link_additional_field'] && ! empty( $post_meta['_prtfl_link'] ) ) {
+						if ( false !== parse_url( $post_meta['_prtfl_link'] ) ) {
+							if ( ( 0 == $user_id && 0 == $prtfl_options['link_additional_field_for_non_registered'] ) || 0 != $user_id ) {
+								$custom_content .= '<p><span class="lable">' . $prtfl_options['link_text_field'] . '</span> <a href="' . $post_meta['_prtfl_link'] . '">' . $post_meta['_prtfl_link'] . '</a></p>';
+							} else {
+								$custom_content .= '<p><span class="lable">' . $prtfl_options['link_text_field'] . '</span> ' . $post_meta['_prtfl_link'] . '</p>';
+							}
+						} else {
+							$custom_content .= '<p><span class="lable">' . $prtfl_options['link_text_field'] . '</span> ' . $post_meta['_prtfl_link'] . '</p>';
+						}
+					}
+					if ( 1 == $prtfl_options['shrdescription_additional_field'] ) {
+						$custom_content .= '<p><span class="lable">' . $prtfl_options['shrdescription_text_field'] . '</span> ' . $short_descr . '</p>';
+					}
+					$custom_content .= '</div>
+						</div>
+					</div>';
+				}
 			}
 		}
-		return $links;
+		return $content . $custom_content;
 	}
 }
-
-
-if ( ! function_exists( 'prtfl_template_redirect' ) ) {
-	function prtfl_template_redirect() {
-		global $wp_query, $post, $posts, $prtfl_filenames, $prtfl_themepath;
-		if ( 'portfolio' == get_post_type() && "" == $wp_query->query_vars["s"] && ! isset( $wp_query->query_vars["technologies"] ) && ! isset( $wp_query->query_vars["portfolio_executor_profile"] ) ) {
-			$file_exists_flag = true;
-			foreach ( $prtfl_filenames as $filename ) {
-				if ( ! file_exists( $prtfl_themepath . $filename ) )
-					$file_exists_flag = false;
-			}
-			if ( $file_exists_flag ) {
-				include( get_stylesheet_directory() . '/portfolio-post.php' );
-				exit();
-			}
-		} elseif ( 'portfolio' == get_post_type() && ( isset( $wp_query->query_vars["technologies"] ) || isset( $wp_query->query_vars["portfolio_executor_profile"] ) ) ) {
-			$file_exists_flag = true;
-			foreach ( $prtfl_filenames as $filename ) {
-				if ( ! file_exists( $prtfl_themepath . $filename ) )
-					$file_exists_flag = false;
-			}
-			if ( $file_exists_flag ) {
-				include( get_stylesheet_directory() . '/portfolio.php' );
-				exit();
-			}
-		}
-	}
-}
-
+/* adding class to manu items  */
 if ( ! function_exists( 'prtfl_add_portfolio_ancestor_to_menu' ) ) {
 	function prtfl_add_portfolio_ancestor_to_menu( $classes, $item ) {
-		if ( is_singular( 'portfolio' ) ) {
+		global $prtfl_options;
+		if ( is_singular( $prtfl_options['post_type_name'] ) ) {
 			global $wpdb, $post;
 			$parent = $wpdb->get_var( "SELECT $wpdb->posts.post_name FROM $wpdb->posts, $wpdb->postmeta WHERE meta_key = '_wp_page_template' AND meta_value = 'portfolio.php' AND (post_status = 'publish' OR post_status = 'private') AND $wpdb->posts.ID = $wpdb->postmeta.post_id" );
 
-			if ( in_array( 'menu-item-' . $item->ID, $classes ) && $parent == strtolower( $item->title ) )
+			if ( in_array( 'menu-item-' . $item->ID, $classes ) && $parent == strtolower( $item->title ) ) {
 				$classes[] = 'current-page-ancestor';
+			}
 		}
 		return $classes;
 	}
 }
 
+/* forming content for portfolio items */
 if ( ! function_exists( 'prtfl_latest_items' ) ) {
 	function prtfl_latest_items( $atts ) {
+		global $prtfl_options, $wp_query;
+		$old_wp_query = $wp_query;
+
 		$content	=	'<div class="prtfl_portfolio_block">';
-		if ( empty( $atts['count'] ) )
+		if ( empty( $atts['count'] ) ) {
 			$atts['count'] = 3;
+		}
 		$args		=	array(
-			'post_type'			=>	'portfolio',
-			'post_status'		=>	'publish',
-			'orderby'			=>	'date',
-			'order'				=>	'DESC',
-			'posts_per_page'	=>	$atts['count'],
+			'post_type'			=> $prtfl_options['post_type_name'],
+			'post_status'		=> 'publish',
+			'orderby'			=> 'date',
+			'order'				=> 'DESC',
+			'posts_per_page'	=> $atts['count'],
 			);
-		query_posts( $args );
+			$second_query = new WP_Query( $args );
+			$request = $second_query->request;
 
-		while ( have_posts() ) : the_post();
+			if ( $second_query->have_posts() ) {
+				while ( $second_query->have_posts() ) {
+					$second_query->the_post();
 			$content .= '
 			<div class="portfolio_content">
 				<div class="entry">';
 					global $post;
-					$meta_values		=	get_post_custom($post->ID);
-					$post_thumbnail_id	=	get_post_thumbnail_id( $post->ID );
-					if( empty ( $post_thumbnail_id ) ) {
+					$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
+					if ( empty ( $post_thumbnail_id ) ) {
 						$args = array(
 							'post_parent'		=>	$post->ID,
 							'post_type'			=>	'attachment',
 							'post_mime_type'	=>	'image',
 							'numberposts'		=>	1
 						);
-						$attachments		=	get_children( $args );
-						$post_thumbnail_id	=	key($attachments);
+						$attachments = get_children( $args );
+						$post_thumbnail_id = key( $attachments );
 					}
-					$image		=	wp_get_attachment_image_src( $post_thumbnail_id, 'portfolio-thumb' );
+					$image = wp_get_attachment_image_src( $post_thumbnail_id, $prtfl_options['image_size_album'] );
+
 					$image_alt	=	get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true );
 					$image_desc	=	get_post( $post_thumbnail_id );
 					$image_desc	=	$image_desc->post_content;
-					$post_meta	=	get_post_meta( $post->ID, 'prtfl_information', true);
-					$date_compl  =	isset( $post_meta['_prtfl_date_compl'] ) ? $post_meta['_prtfl_date_compl'] : '';
-					if ( ! empty( $date_compl ) && 'in progress' != $date_compl ) {
-						$date_compl		=	explode( "/", $date_compl );
-						$date_compl		=	date( get_option( 'date_format' ), strtotime( $date_compl[1]."-".$date_compl[0].'-'.$date_compl[2] ) );
+					$post_meta	=	get_post_meta( $post->ID, 'prtfl_information', true );
+
+					$date_compl = isset( $post_meta['_prtfl_date_compl'] ) ? $post_meta['_prtfl_date_compl'] : '';
+					$link = isset( $post_meta['_prtfl_link'] ) ? $post_meta['_prtfl_link'] : '';
+					$short_descr = isset( $post_meta['_prtfl_short_descr'] ) ? $post_meta['_prtfl_short_descr'] : '';
+					if ( empty( $short_descr ) ) {
+						$short_descr = get_the_excerpt();
 					}
-					$link			=	isset( $post_meta['_prtfl_link'] ) ? $post_meta['_prtfl_link'] : '';
-					$short_descr	=	isset( $post_meta['_prtfl_short_descr'] ) ? $post_meta['_prtfl_short_descr'] : '';
-					if ( empty( $short_descr ) )
-						$short_descr = get_the_excerpt();
 					$title = get_the_title();
-					if ( empty( $title ) )
-						$title = '(' . __( 'No title', 'portfolio-pro' ) . ')';
+					if ( empty( $title ) ) {
+						$title = '(' . __( 'No title', 'portfolio' ) . ')';
+					}
 					$permalink = get_permalink();
-					
+
 					$content .= '<div class="portfolio_thumb" style="width:165px">
 							<img src="' . $image[0] . '" width="' . $image[1] . '" alt="' . $image_alt . '" />
 					</div>
@@ -1040,124 +1153,208 @@
 								<a href="' . $permalink . '" rel="bookmark">' . $title . '</a>
 							</p>
 						</div> <!-- .item_title -->';
-						$content .= '<p>' . $short_descr . '</p>
-					</div> <!-- .portfolio_short_content -->
+						if ( 1 == $prtfl_options['shrdescription_additional_field'] && ( ! empty( $short_descr ) ) ) {
+							$content .= '<p>' . $short_descr . '</p>';
+						}
+					$content .= '</div> <!-- .portfolio_short_content -->
 				</div> <!-- .entry -->
 				<div class="read_more">
 					<a href="' . $permalink . '" rel="bookmark">' . __( 'Read more', 'portfolio' ) . '</a>
 				</div> <!-- .read_more -->
 				<div class="portfolio_terms">';
-				$terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' );
-				if ( is_array( $terms ) && 0 < count( $terms ) ) {
-					$content .= __( 'Technologies', 'portfolio' ) . ':';
-					$count = 0;
-					foreach ( $terms as $term ) {
-						if ( $count > 0 )
-							$content .= ', ';
-						$content .= '<a href="' . get_term_link( $term->slug, 'portfolio_technologies') . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name . '</a>';
-						$count++;
+				if ( 1 == $prtfl_options['technologies_additional_field'] ) {
+					$terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' );
+					if ( is_array( $terms ) && 0 < count( $terms ) ) {
+						$content .= __( 'Technologies', 'portfolio' ) . ':';
+						$count = 0;
+						foreach ( $terms as $term ) {
+							if ( $count > 0 ) {
+								$content .= ', ';
+							}
+							$content .= '<a href="' . get_term_link( $term->slug, 'portfolio_technologies' ) . '" title="' . sprintf( __( "View all projects in %s" ), $term->name ) . '" ' . '>' . $term->name . '</a>';
+							$count++;
+						}
+					} else {
+						$content .= '&nbsp;';
 					}
-				} else {
-					$content .= '&nbsp;';
 				}
 				$content .= '</div><!-- .portfolio_terms -->';
 			$content .= '<div class="prtfl_clear"></div></div> <!-- .portfolio_content -->';
-		endwhile;
+			}
+		}
 		$content .= '</div> <!-- .prtfl_portfolio_block -->';
 		wp_reset_query();
+		$wp_query = $old_wp_query;
 		return $content;
 	}
 }
 
 /* Register style and script files */
-if ( ! function_exists ( 'prtfl_admin_head' ) ) {
+if ( ! function_exists( 'prtfl_admin_head' ) ) {
 	function prtfl_admin_head() {
-		global $wp_version, $prtfl_plugin_info, $post_type;
-		if ( $wp_version < 3.8 )
-			wp_enqueue_style( 'prtfl_stylesheet', plugins_url( 'css/style_wp_before_3.8.css', __FILE__ ) );	
-		else
+		global $prtfl_plugin_info, $hook_suffix, $post_type, $prtfl_options;
+
+		wp_enqueue_style( 'prtfl_icon', plugins_url( 'css/icon.css', __FILE__ ) );
+
+		if ( ( ( 'post.php' == $hook_suffix || 'post-new.php' == $hook_suffix ) && isset( $post_type ) && $prtfl_options['post_type_name'] == $post_type ) ||
+			( isset( $_GET['page'] ) && 'portfolio.php' == $_GET['page'] ) ) {
 			wp_enqueue_style( 'prtfl_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
-		wp_enqueue_style( 'prtfl_datepicker_stylesheet', plugins_url( 'datepicker/datepicker.css', __FILE__ ) );
+			wp_enqueue_style( 'prtfl_jquery-style', plugins_url( 'css/jquery-ui.css', __FILE__ ) );
+			wp_enqueue_script( 'jquery-ui-datepicker' );
 
-		if ( isset( $_GET['page'] ) && "portfolio.php" == $_GET['page'] ) {
 			wp_enqueue_script( 'prtfl_script', plugins_url( 'js/script.js', __FILE__ ) );
-			wp_localize_script( 'prtfl_script', 'prtfl_var', array(
+			wp_localize_script( 'prtfl_script', 'prtfl_vars', array(
 				'prtfl_nonce' 			=> wp_create_nonce( plugin_basename( __FILE__ ), 'prtfl_ajax_nonce_field' ),
-				'update_img_message'	=> __( 'Updating images...', 'portfolio' ),
-				'not_found_img_info'	=> __( 'No image found', 'portfolio'),
-				'img_success'			=> __( 'All images are updated', 'portfolio' ),
-				'img_error'				=> __( 'Error.', 'portfolio' ) ) );
+				'update_img_message'	=> __( 'Updating images...', 'portfolio' ) . '<img class="prtfl_loader" src="' . plugins_url( 'images/ajax-loader.gif', __FILE__ ) . '" alt="" />',
+				'not_found_img_info'	=> __( 'No image found.', 'portfolio' ),
+				'img_success'			=> __( 'All images are updated.', 'portfolio' ),
+				'img_error'				=> __( 'Error:', 'portfolio' ) ) );
+
+			bws_enqueue_settings_scripts();
+			bws_plugins_include_codemirror();
 		}
-		wp_enqueue_script( 'prtfl_datepicker_script', plugins_url( 'datepicker/datepicker.js', __FILE__ ) );
 	}
 }
 
-if ( ! function_exists ( 'prtfl_wp_head' ) ) {
-	function prtfl_wp_head() {
+/* enqueue fancybox script and style css */
+if ( ! function_exists( 'prtfl_wp_enqueue_scripts' ) ) {
+	function prtfl_wp_enqueue_scripts() {
 		wp_enqueue_style( 'prtfl_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
-		
-		if ( ! function_exists( 'is_plugin_active' ) )
-			require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
-		
-		$all_plugins = get_plugins();
-		
-		if ( ! is_plugin_active( 'gallery-plugin-pro/gallery-plugin-pro.php' ) || ( isset( $all_plugins["gallery-plugin-pro/gallery-plugin-pro.php"]["Version"] ) && "1.3.0" >= $all_plugins["gallery-plugin-pro/gallery-plugin-pro.php"]["Version"] ) ) { 
-			wp_enqueue_style( 'prtfl_lightbox_stylesheet', plugins_url( 'fancybox/jquery.fancybox-1.3.4.css', __FILE__ ) );
-			wp_enqueue_script( 'prtfl_fancybox_mousewheelJs', plugins_url( 'fancybox/jquery.mousewheel-3.0.4.pack.js', __FILE__ ), array( 'jquery' ) );
-			wp_enqueue_script( 'prtfl_fancyboxJs', plugins_url( 'fancybox/jquery.fancybox-1.3.4.pack.js', __FILE__ ), array( 'jquery' ) );
+		wp_enqueue_style( 'prtfl_lightbox_stylesheet', plugins_url( 'fancybox/jquery.fancybox.min.css', __FILE__ ) );
+	}
+}
+
+/* styles for IE */
+if ( ! function_exists( 'prtfl_wp_head' ) ) {
+	function prtfl_wp_head() {
+		global $prtfl_options;
+		/* Add style for IE compatibility */
+		if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0' ) !== false || strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
+			$post_type = get_post_type();
+			if ( is_single() && $prtfl_options['post_type_name'] == $post_type ) { ?>
+				<style type="text/css">
+					.portfolio_images_gallery {
+						display: block;
+					}
+					.portfolio_thumb {
+						float: none;
+					}
+				</style>
+			<?php }
 		}
 	}
 }
 
-if ( ! function_exists ( 'prtfl_update_image' ) ) {
+/* initializing script of fancybox */
+if ( ! function_exists( 'prtfl_wp_footer' ) ) {
+	function prtfl_wp_footer() {
+		global $prtfl_options, $post, $wp_query;
+		$post_thumbnail_id = '';
+		if ( ! empty(  $wp_query->post->ID ) ) {
+			$post_thumbnail_id = get_post_thumbnail_id( $wp_query->post->ID );
+		}
+		$image = wp_get_attachment_image_src( $post_thumbnail_id, $prtfl_options['image_size_album'] );
+
+		if ( wp_script_is( 'prtfl_front_script', 'registered' ) ) {
+			wp_enqueue_script( 'prtfl_front_script' );
+			wp_enqueue_script( 'prtfl_fancyboxJs', plugins_url( 'fancybox/jquery.fancybox.min.js', __FILE__ ), array( 'jquery' ) );
+
+			/* Initialization of fancybox script */
+			if ( ! empty( $image[0] ) ) { ?>
+				<script type="text/javascript">
+					( function( $ ){
+						$( document ).ready( function(){
+							$( "a[data-fancybox=portfolio_fancybox]" ).fancybox({
+								loop    : true,
+								arrows  : false,
+								infobar : true,
+								speed : 500,
+								toolbar: false,
+								animationEffect : 'zoom',
+								openEffect : 'elastic',
+								closeEffect : 'elastic'
+							} );
+						} );
+					} )( jQuery );
+				</script>
+			<?php }
+		}
+
+	}
+}
+
+/**
+ * Ajax function for updating images
+ * @return void
+ */
+if ( ! function_exists( 'prtfl_update_image' ) ) {
 	function prtfl_update_image() {
-		global $wpdb;
+		global $wpdb, $prtfl_options;
 		check_ajax_referer( plugin_basename( __FILE__ ), 'prtfl_ajax_nonce_field' );
-		$action	=	isset( $_REQUEST['action1'] ) ? $_REQUEST['action1'] : "";
-		$id		=	isset( $_REQUEST['id'] ) ? $_REQUEST['id'] : "";
+		$action	= isset( $_REQUEST['action1'] ) ? $_REQUEST['action1'] : "";
+		$id		= isset( $_REQUEST['id'] ) ? $_REQUEST['id'] : "";
 		switch ( $action ) {
 			case 'get_all_attachment':
-				$result_parent_id	=	$wpdb->get_results( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = %s", 'portfolio' ) , ARRAY_N );
-				$array_parent_id	=	array();
+				$array_parent_id = $wpdb->get_col( "SELECT `ID` FROM $wpdb->posts WHERE `post_type` = {$prtfl_options['post_type_name']}" );
+				if ( ! empty( $array_parent_id ) ) {
+					$string_parent_id = implode( ",", $array_parent_id );
+
+					$metas = $wpdb->get_results( "SELECT `meta_value` FROM $wpdb->postmeta WHERE `meta_key` = '_prtfl_images' AND `post_id` IN (" . $string_parent_id . ")", ARRAY_A );
 
-				while ( list( $key, $val ) = each( $result_parent_id ) )
-					$array_parent_id[] = $val[0];
+					$result_attachment_id = '';
+					foreach ( $metas as $key => $value ) {
+						if ( ! empty( $value['meta_value'] ) ) {
+							$result_attachment_id .= $value['meta_value'] . ',';
+						}
+					}
+					$result_attachment_id_array = explode( ",", rtrim( $result_attachment_id, ',' ) );
 
-				$string_parent_id = implode( ",", $array_parent_id );
-
-				$result_attachment_id = $wpdb->get_results( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'attachment' AND post_mime_type LIKE 'image%' AND post_parent IN (" . $string_parent_id . ")" );
-				echo json_encode( $result_attachment_id );
+					$attached_id = $wpdb->get_results( "SELECT `ID` FROM $wpdb->posts WHERE `post_type` = 'attachment' AND `post_mime_type` LIKE 'image%' AND `post_parent` IN (" . $string_parent_id . ")", ARRAY_A );
+					foreach ( $attached_id as $key => $value ) {
+						$result_attachment_id_array[] = $value['ID'];
+					}
+					echo json_encode( array_unique( $result_attachment_id_array ) );
+				}
 				break;
 			case 'update_image':
-				$metadata	=	wp_get_attachment_metadata( $id );
-				$uploads	=	wp_upload_dir();
-				$path		=	$uploads['basedir'] . "/" . $metadata['file'];
+				$metadata	= wp_get_attachment_metadata( $id );
+				$uploads	= wp_upload_dir();
+				$path		= $uploads['basedir'] . "/" . $metadata['file'];
 				require_once( ABSPATH . 'wp-admin/includes/image.php' );
 				$metadata_new = prtfl_wp_generate_attachment_metadata( $id, $path, $metadata );
 				wp_update_attachment_metadata( $id, array_merge( $metadata, $metadata_new ) );
 				break;
 			case 'update_options':
-				add_option( 'prtfl_images_update', '1', '', 'no' );
+				unset( $prtfl_options['need_image_update'] );
+				update_option( 'prtfl_options', $prtfl_options );
 				break;
 		}
 		die();
 	}
 }
 
-if ( ! function_exists ( 'prtfl_wp_generate_attachment_metadata' ) ) {
+if ( ! function_exists( 'prtfl_wp_generate_attachment_metadata' ) ) {
 	function prtfl_wp_generate_attachment_metadata( $attachment_id, $file, $metadata ) {
 		global $prtfl_options;
 		$attachment		=	get_post( $attachment_id );
-		add_image_size( 'portfolio-thumb', $prtfl_options['prtfl_custom_size_px'][0][0], $prtfl_options['prtfl_custom_size_px'][0][1], true );
-		add_image_size( 'portfolio-photo-thumb', $prtfl_options['prtfl_custom_size_px'][1][0], $prtfl_options['prtfl_custom_size_px'][1][1], true );
+		$image_size 	= array( 'thumbnail' );
+
+		if ( 'portfolio-thumb' == $prtfl_options['image_size_album'] ) {
+			add_image_size( 'portfolio-thumb', $prtfl_options['custom_size_px']['portfolio-thumb'][0], $prtfl_options['custom_size_px']['portfolio-thumb'][1], true );
+			$image_size[] = 'portfolio-thumb';
+		}
+		if ( 'portfolio-photo-thumb' == $prtfl_options['image_size_photo'] ) {
+			add_image_size( 'portfolio-photo-thumb', $prtfl_options['custom_size_px']['portfolio-photo-thumb'][0], $prtfl_options['custom_size_px']['portfolio-photo-thumb'][1], true );
+			$image_size[] = 'portfolio-photo-thumb';
+		}
 
 		$metadata = array();
-		if ( preg_match('!^image/!', get_post_mime_type( $attachment ) ) && file_is_displayable_image( $file ) ) {
-			$imagesize					=	getimagesize( $file );
-			$metadata['width']			=	$imagesize[0];
-			$metadata['height']			=	$imagesize[1];
-			list($uwidth, $uheight)		=	wp_constrain_dimensions( $metadata['width'], $metadata['height'], 128, 96 );
-			$metadata['hwstring_small']	=	"height='$uheight' width='$uwidth'";
+		if ( preg_match( '!^image/!', get_post_mime_type( $attachment ) ) && file_is_displayable_image( $file ) ) {
+			$imagesize					= getimagesize( $file );
+			$metadata['width']			= $imagesize[0];
+			$metadata['height']			= $imagesize[1];
+			list( $uwidth, $uheight )	= wp_constrain_dimensions( $metadata['width'], $metadata['height'], 128, 96 );
+			$metadata['hwstring_small']	= "height='$uheight' width='$uwidth'";
 
 			/* Make the file path relative to the upload dir */
 			$metadata['file']= _wp_relative_upload_path( $file );
@@ -1165,50 +1362,53 @@
 			/* Make thumbnails and other intermediate sizes */
 			global $_wp_additional_image_sizes;
 
-			$image_size = array( 'portfolio-thumb', 'portfolio-photo-thumb' );/* get_intermediate_image_sizes(); */
-
 			foreach ( $image_size as $s ) {
 				$sizes[ $s ] = array( 'width' => '', 'height' => '', 'crop' => FALSE );
-				if ( isset( $_wp_additional_image_sizes[ $s ]['width'] ) )
-					$sizes[ $s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); /* For theme-added sizes */
-				else
+				if ( isset( $_wp_additional_image_sizes[ $s ]['width'] ) ) {
+					$sizes[ $s]['width'] = intval( $_wp_additional_image_sizes[ $s ]['width'] ); /* For theme-added sizes */
+				} else {
 					$sizes[ $s ]['width'] = get_option( "{$s}_size_w" ); /* For default sizes set in options */
-				if ( isset( $_wp_additional_image_sizes[$s]['height'] ) )
-					$sizes[ $s ]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); /* For theme-added sizes */
-				else
+				}
+				if ( isset( $_wp_additional_image_sizes[ $s ]['height'] ) ) {
+					$sizes[ $s ]['height'] = intval( $_wp_additional_image_sizes[ $s ]['height'] ); /* For theme-added sizes */
+				} else {
 					$sizes[ $s ]['height'] = get_option( "{$s}_size_h" ); /* For default sizes set in options */
-				if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) )
-					$sizes[ $s ]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); /* For theme-added sizes */
-				else
+				}
+				if ( isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ) {
+					$sizes[ $s ]['crop'] = intval( $_wp_additional_image_sizes[ $s ]['crop'] ); /* For theme-added sizes */
+				} else {
 					$sizes[ $s ]['crop'] = get_option( "{$s}_crop" ); /* For default sizes set in options */
+				}
 			}
 
 			$sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
 			foreach ( $sizes as $size => $size_data ) {
 				$resized = prtfl_image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] );
-				if ( $resized )
-					$metadata['sizes'][$size] = $resized;
+				if ( $resized ) {
+					$metadata['sizes'][ $size ] = $resized;
+				}
 			}
 
 			/* Fetch additional metadata from exif/iptc */
 			$image_meta = wp_read_image_metadata( $file );
-			if ( $image_meta )
+			if ( $image_meta ) {
 				$metadata['image_meta'] = $image_meta;
+			}
 		}
 		return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );
 	}
 }
 
-if ( ! function_exists ( 'prtfl_image_make_intermediate_size' ) ) {
+if ( ! function_exists( 'prtfl_image_make_intermediate_size' ) ) {
 	function prtfl_image_make_intermediate_size( $file, $width, $height, $crop=false ) {
 		if ( $width || $height ) {
 			$resized_file = prtfl_image_resize( $file, $width, $height, $crop );
 			if ( ! is_wp_error( $resized_file ) && $resized_file && $info = getimagesize( $resized_file ) ) {
 				$resized_file = apply_filters( 'image_make_intermediate_size', $resized_file );
 				return array(
-					'file'		=>	wp_basename( $resized_file ),
-					'width'		=>	$info[0],
-					'height'	=>	$info[1],
+					'file'		=> wp_basename( $resized_file ),
+					'width'		=> $info[0],
+					'height'	=> $info[1],
 				);
 			}
 		}
@@ -1216,87 +1416,96 @@
 	}
 }
 
-if ( ! function_exists ( 'prtfl_image_resize' ) ) {
+if ( ! function_exists( 'prtfl_image_resize' ) ) {
 	function prtfl_image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
 		$size = @getimagesize( $file );
-		if ( !$size )
+		if ( ! $size ) {
 			return new WP_Error( 'invalid_image', __( 'Image size not defined', 'portfolio' ), $file );
+		}
 		$type = $size[2];
 
-		if ( 3 == $type )
+		if ( 3 == $type ) {
 			$image = imagecreatefrompng( $file );
-		else if ( 2 == $type )
+		} elseif ( 2 == $type ) {
 			$image = imagecreatefromjpeg( $file );
-		else if ( 1 == $type )
+		} elseif ( 1 == $type ) {
 			$image = imagecreatefromgif( $file );
-		else if ( 15 == $type )
+		} elseif ( 15 == $type ) {
 			$image = imagecreatefromwbmp( $file );
-		else if ( 16 == $type )
+		} elseif ( 16 == $type ) {
 			$image = imagecreatefromxbm( $file );
-		else
-			return new WP_Error( 'invalid_image', __( 'We can update only PNG, JPEG, GIF, WPMP or XBM filetype. For other, please, manually reload image.', 'portfolio' ), $file );
-
-		if ( ! is_resource( $image ) )
+		} else {
+			return new WP_Error( 'invalid_image', __( 'We can update only PNG, JPEG, GIF, WPMP or XBM filetype. For other image formats, please manually reload image.', 'portfolio' ), $file );
+		}
+		if ( ! is_resource( $image ) ) {
 			return new WP_Error( 'error_loading_image', $image, $file );
-
+		}
 		/* $size = @getimagesize( $file ); */
 		list( $orig_w, $orig_h, $orig_type ) = $size;
-		$dims = prtfl_image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop);
+		$dims = prtfl_image_resize_dimensions( $orig_w, $orig_h, $max_w, $max_h, $crop );
 
-		if ( ! $dims )
+		if ( ! $dims ) {
 			return new WP_Error( 'error_getting_dimensions', __( 'Image size changes not defined', 'portfolio' ) );
+		}
 		list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims;
 		$newimage = wp_imagecreatetruecolor( $dst_w, $dst_h );
 		imagecopyresampled( $newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
 		/* Convert from full colors to index colors, like original PNG. */
-		if ( IMAGETYPE_PNG == $orig_type && function_exists( 'imageistruecolor' ) && ! imageistruecolor( $image ) )
+		if ( IMAGETYPE_PNG == $orig_type && function_exists( 'imageistruecolor' ) && ! imageistruecolor( $image ) ) {
 			imagetruecolortopalette( $newimage, false, imagecolorstotal( $image ) );
+		}
 		/* We don't need the original in memory anymore */
 		imagedestroy( $image );
 
 		/* $suffix will be appended to the destination filename, just before the extension */
-		if ( ! $suffix )
+		if ( ! $suffix ) {
 			$suffix = "{$dst_w}x{$dst_h}";
+		}
+		$info = pathinfo( $file );
+		$dir = $info['dirname'];
+		$ext = $info['extension'];
+		$name = wp_basename( $file, ".$ext" );
 
-		$info	=	pathinfo( $file );
-		$dir	=	$info['dirname'];
-		$ext	=	$info['extension'];
-		$name	=	wp_basename( $file, ".$ext" );
-
-		if ( ! is_null( $dest_path ) and $_dest_path = realpath( $dest_path ) )
+		if ( ! is_null( $dest_path ) and $_dest_path = realpath( $dest_path ) ) {
 			$dir = $_dest_path;
+		}
 		$destfilename = "{$dir}/{$name}-{$suffix}.{$ext}";
 
 		if ( IMAGETYPE_GIF == $orig_type ) {
-			if ( ! imagegif( $newimage, $destfilename ) )
+			if ( ! imagegif( $newimage, $destfilename ) ) {
 				return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'portfolio' ) );
+			}
 		} elseif ( IMAGETYPE_PNG == $orig_type ) {
-			if ( ! imagepng( $newimage, $destfilename ) )
+			if ( ! imagepng( $newimage, $destfilename ) ) {
 				return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'portfolio' ) );
+			}
 		} else {
 			/* All other formats are converted to jpg */
 			$destfilename = "{$dir}/{$name}-{$suffix}.jpg";
-			if ( ! imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) )
+			if ( ! imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) ) {
 				return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'portfolio' ) );
+			}
 		}
 
 		imagedestroy( $newimage );
 		/* Set correct file permissions */
-		$stat	=	stat( dirname( $destfilename ) );
-		$perms	=	$stat['mode'] & 0000666; /* Same permissions as parent folder, strip off the executable bits */
+		$stat	= stat( dirname( $destfilename ) );
+		$perms	= $stat['mode'] & 0000666; /* Same permissions as parent folder, strip off the executable bits */
 		@chmod( $destfilename, $perms );
 		return $destfilename;
 	}
 }
 
-if ( ! function_exists ( 'prtfl_image_resize_dimensions' ) ) {
+if ( ! function_exists( 'prtfl_image_resize_dimensions' ) ) {
 	function prtfl_image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) {
 
-		if ( 0 >= $orig_w || 0 >= $orig_h )
+		if ( 0 >= $orig_w || 0 >= $orig_h ) {
 			return false;
+		}
 		/* At least one of dest_w or dest_h must be specific */
-		if ( 0 >= $dest_w && 0 >= $dest_h )
+		if ( 0 >= $dest_w && 0 >= $dest_h ) {
 			return false;
+		}
 
 		if ( $crop ) {
 			/* Crop the largest possible portion of the original image that we can size to $dest_w x $dest_h */
@@ -1327,132 +1536,711 @@
 		}
 
 		/* If the resulting image would be the same size or larger we don't want to resize it */
-		if ( $new_w >= $orig_w && $new_h >= $orig_h )
+		if ( $new_w >= $orig_w && $new_h >= $orig_h ) {
 			return false;
+		}
 		/* The return array matches the parameters to imagecopyresampled() */
 		/* Int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h */
-		return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
+		return array( 0, 0, ( int ) $s_x, ( int ) $s_y, ( int ) $new_w, ( int ) $new_h, ( int ) $crop_w, ( int ) $crop_h );
 	}
 }
 
-
-if ( ! function_exists( 'prtfl_sanitize_file_name' ) ) {
-	function prtfl_sanitize_file_name( $file_name ) {
+if ( ! function_exists( 'prtfl_theme_body_classes' ) ) {
+	function prtfl_theme_body_classes( $classes ) {
 		global $prtfl_options;
-		if ( isset( $_REQUEST['post_id'] ) && 'portfolio' == get_post_type( $_REQUEST['post_id'] )
-			&& isset( $prtfl_options['prtfl_rename_file'] ) && $prtfl_options['prtfl_rename_file'] == 1 ) {	
-			$file_name_old = explode( '.', $file_name );
-			$file_name_new = preg_replace( '/--+/', '-', preg_replace( '/[^a-zA-Z0-9_-]/', '', $file_name_old[0] ) );
-
-			if ( $file_name_new == '' || $file_name_new == '-' ) {
-				$slug = isset( $prtfl_options['prtfl_slug'] ) && ! empty( $prtfl_options['prtfl_slug'] ) ? $prtfl_options['prtfl_slug'] : 'portfolio';
-				$file_name_new = $slug . '-' . time();
-			}
-			$file_name = $file_name_new . '.' . $file_name_old[1];
-		}
-		return $file_name;
-	}
-}
-
-if ( ! function_exists( 'prtfl_filter_image_sizes' ) ) {
-	function prtfl_filter_image_sizes( $sizes ) {
-		if ( isset( $_REQUEST['post_id'] ) && 'portfolio' == get_post_type( $_REQUEST['post_id'] ) ) {
-			$prtfl_image_size = array( 'portfolio-thumb', 'portfolio-photo-thumb', 'large' );
-			foreach ( $sizes as $key => $value ) {
-				if ( ! in_array( $key, $prtfl_image_size ) ) {
-					unset( $sizes[ $key ] );
-				}
-			}
-		}
-		return $sizes;
-	}
-}
-
-if ( ! function_exists ( 'prtfl_theme_body_classes' ) ) {
-	function prtfl_theme_body_classes( $classes ) {
 		if ( function_exists( 'wp_get_theme' ) ) {
 			$current_theme = wp_get_theme();
 			$classes[] = 'prtfl_' . basename( $current_theme->get( 'ThemeURI' ) );
 		}
+		if ( in_array( 'page-id-' . $prtfl_options['page_id_portfolio_template'], $classes ) ) {
+			$classes[]     = 'prtfl-page-template';
+			$classes[]     = 'has-sidebar';
+		}
 		return $classes;
 	}
 }
 
-if ( ! function_exists ( 'prtfl_admin_notices' ) ) {
+if ( ! function_exists( 'prtfl_register_plugin_links' ) ) {
+	function prtfl_register_plugin_links( $links, $file ) {
+		global $prtfl_options;
+		$base = plugin_basename( __FILE__ );
+		if ( $file == $base ) {
+			if ( ! is_network_admin() ) {
+				$links[]	=	'<a href="edit.php?post_type=' . $prtfl_options['post_type_name'] . '&page=portfolio.php">' . __( 'Settings', 'portfolio' ) . '</a>';
+			}
+			$links[]	=	'<a href="https://support.bestwebsoft.com/hc/en-us/sections/200538929" target="_blank">' . __( 'FAQ', 'portfolio' ) . '</a>';
+			$links[]	=	'<a href="https://support.bestwebsoft.com">' . __( 'Support', 'portfolio' ) . '</a>';
+		}
+		return $links;
+	}
+}
+
+if ( ! function_exists( 'prtfl_plugin_action_links' ) ) {
+	function prtfl_plugin_action_links( $links, $file ) {
+		if ( ! is_network_admin() ) {
+			/* Static so we don't call plugin_basename on every plugin row. */
+			static $this_plugin;
+			if ( ! $this_plugin ) $this_plugin = plugin_basename( __FILE__ );
+
+			if ( $file == $this_plugin ) {
+				global $prtfl_options;
+				$settings_link = '<a href="edit.php?post_type=' . $prtfl_options['post_type_name'] . '&page=portfolio.php">' . __( 'Settings', 'portfolio' ) . '</a>';
+				array_unshift( $links, $settings_link );
+			}
+		}
+		return $links;
+	}
+}
+
+if ( ! function_exists( 'prtfl_admin_notices' ) ) {
 	function prtfl_admin_notices() {
-		global $hook_suffix, $prtfl_plugin_info, $prtfl_options;
-		
-		if ( 'plugins.php' == $hook_suffix ) {
-			bws_plugin_banner( $prtfl_plugin_info, 'prtfl', 'portfolio', '56e6c97d1bca3199fb16cb817793a8f6', '74', '//ps.w.org/portfolio/assets/icon-128x128.png' );
+		global $hook_suffix, $prtfl_plugin_info, $prtfl_options, $prtfl_BWS_demo_data;
+
+		if ( 'plugins.php' == $hook_suffix || ( isset( $_GET['page'] ) && 'portfolio.php' == $_GET['page'] ) ) {
 
 			/* Get options from the database */
-			if ( ! $prtfl_options )
+			if ( ! $prtfl_options ) {
 				$prtfl_options = get_option( 'prtfl_options' );
+			}
+
+			if ( ! $prtfl_BWS_demo_data ) {
+				prtfl_include_demo_data();
+			}
+			$prtfl_BWS_demo_data->bws_handle_demo_notice( $prtfl_options['display_demo_notice'] );
 
-			if ( $prtfl_options['widget_updated'] == 0 ) {
-				/* Save data for settings page */
-				if ( isset( $_REQUEST['prtfl_form_submit'] ) && check_admin_referer( plugin_basename(__FILE__), 'prtfl_nonce_name' ) ) {
-					$prtfl_options['widget_updated'] = 1;
-					update_option( 'prtfl_options', $prtfl_options );
-				} else { ?>
-					<div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
-						<div class="prtfl_admin_notices bws_banner_on_plugin_page">
-							<form method="post" action="<?php echo $hook_suffix; ?>">
-								<div class="text">
-									<p>
-										<strong><?php _e( "ATTENTION!", 'portfolio' ); ?></strong>
-										<?php _e( "In the current version of Portfolio plugin we updated the Technologies widget. If it was added to the sidebar, it will disappear and you will have to add it again.", 'portfolio' ); ?>
-									</p>
-									<input type="hidden" name="prtfl_form_submit" value="submit" />
-									<p class="submit">
-										<input type="submit" class="button-primary" value="<?php _e( 'Read and Understood' ); ?>" />
-									</p>
-									<?php wp_nonce_field( plugin_basename( __FILE__ ), 'prtfl_nonce_name' ); ?>
-								</div>
-							</form>
+			if ( 'plugins.php' == $hook_suffix ) {
+				if ( isset( $prtfl_options['first_install'] ) && strtotime( '-1 week' ) > $prtfl_options['first_install'] ) {
+					bws_plugin_banner( $prtfl_plugin_info, 'prtfl', 'portfolio', '56e6c97d1bca3199fb16cb817793a8f6', '74', '//ps.w.org/portfolio/assets/icon-128x128.png' );
+				}
+				if ( ! is_network_admin() ) {
+					bws_plugin_banner_to_settings( $prtfl_plugin_info, 'prtfl_options', 'portfolio', 'edit.php?post_type=portfolio&page=portfolio.php', 'Portfolio' );
+				}
+				if ( 0 == $prtfl_options['widget_updated'] ) {
+					/* Save data for settings page */
+					if ( isset( $_REQUEST['prtfl_form_submit'] ) && check_admin_referer( plugin_basename( __FILE__ ), 'prtfl_nonce_name' ) ) {
+						$prtfl_options['widget_updated'] = 1;
+						update_option( 'prtfl_options', $prtfl_options );
+					} else { ?>
+						<div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
+							<div class="prtfl_admin_notices bws_banner_on_plugin_page">
+								<form method="post" action="<?php echo $hook_suffix; ?>">
+									<div class="text">
+										<p>
+											<strong><?php _e( "ATTENTION!", 'portfolio' ); ?></strong>
+											<?php _e( "In the current version of Portfolio plugin we updated the Technologies widget. If it was added to the sidebar, it will disappear and you will have to add it again.", 'portfolio' ); ?>
+										</p>
+										<input type="hidden" name="prtfl_form_submit" value="submit" />
+										<p class="submit">
+											<input type="submit" class="button-primary" value="<?php _e( 'Read and Understood', 'portfolio' ); ?>" />
+										</p>
+										<?php wp_nonce_field( plugin_basename( __FILE__ ), 'prtfl_nonce_name' ); ?>
+									</div>
+								</form>
+							</div>
 						</div>
-					</div>
-				<?php }
+					<?php }
+				}
+			} else {
+				bws_plugin_suggest_feature_banner( $prtfl_plugin_info, 'prtfl_options', 'portfolio' );
 			}
 		}
 	}
 }
 
+/* This function will display title for portfolio type template */
+if ( ! function_exists( 'prtfl_template_title' ) ) {
+	function prtfl_template_title() {
+		global $wp_query, $prtfl_options;
+
+		if ( isset( $wp_query->query_vars["technologies"] ) ) {
+			$term = get_term_by( 'slug', $wp_query->query_vars["technologies"], 'portfolio_technologies' );
+			echo $prtfl_options['technologies_text_field'] . " " . ( $term->name );
+		} elseif ( isset( $wp_query->query_vars["portfolio_executor_profile"] ) ) {
+			$term = get_term_by( 'slug', $wp_query->query_vars["portfolio_executor_profile"], 'portfolio_executor_profile' );
+			echo $prtfl_options['executor_text_field'] . " <h1>" . ( $term->name ) . "</h1>";
+			$_SESSION['prtfl_page_name'] = $prtfl_options['executor_text_field'] . " " . ( $term->name );
+			$_SESSION['prtfl_page_url'] = get_pagenum_link( $wp_query->query_vars['paged'] );
+		} else {
+			the_title( '<h2>', '</h2>' );
+		}
+	}
+}
+
+/* This function will display title for portfolio post type template */
+if ( ! function_exists( 'prtfl_post_template_title' ) ) {
+	function prtfl_post_template_title() {
+		$title = get_the_title();
+		echo empty( $title ) ? '(' . __( 'No title', 'portfolio' ) . ')' : '<h2>'. $title . '</h2>' ;
+	}
+}
+
+/**
+ * Prepare arguments for post query
+ * @return array|false
+ */
+if ( ! function_exists( 'prtfl_get_query_args' ) ) {
+	function prtfl_get_query_args() {
+		global $prtfl_options;
+		$count = 0;
+		if ( get_query_var( 'paged' ) ) {
+			$paged = get_query_var( 'paged' );
+		} elseif ( get_query_var( 'page' ) ) {
+			$paged = get_query_var( 'page' );
+		} else {
+			$paged = 1;
+		}
+		$per_page = $showitems = get_option( 'posts_per_page' );
+
+		if ( ! empty( $wp_query->query_vars["technologies"] ) ) {
+			$args = array(
+				'post_type' 		=> $prtfl_options['post_type_name'],
+				'post_status' 		=> 'publish',
+				'orderby' 			=> $prtfl_options['order_by'],
+				'order'			 	=> $prtfl_options['order'],
+				'posts_per_page'	=> $per_page,
+				'paged' 			=> $paged,
+				'tax_query' 		=> array(
+					array(
+						'taxonomy' 	=> 'portfolio_technologies',
+						'field' 	=> 'slug',
+						'terms' 	=> $wp_query->query_vars["technologies"]
+					)
+				)
+			);
+		} elseif ( ! empty( $wp_query->query_vars["portfolio_executor_profile"] ) ) {
+			$args = array(
+				'post_type' 		=> $prtfl_options['post_type_name'],
+				'post_status' 		=> 'publish',
+				'orderby'			=> $prtfl_options['order_by'],
+				'order' 			=> $prtfl_options['order'],
+				'posts_per_page' 	=> $per_page,
+				'paged' 			=> $paged,
+				'tax_query' 		=> array(
+					array(
+						'taxonomy' 	=> 'portfolio_executor_profile',
+						'field' 	=> 'slug',
+						'terms' 	=> $wp_query->query_vars["portfolio_executor_profile"]
+					)
+				)
+			);
+		} else {
+			$args = array(
+				'post_type'			=> $prtfl_options['post_type_name'],
+				'post_status'		=> 'publish',
+				'orderby'			=> $prtfl_options['order_by'],
+				'order'				=> $prtfl_options['order'],
+				'posts_per_page'	=> $per_page,
+				'paged'				=> $paged
+			);
+		}
+
+		if ( isset( $args ) ) {
+			return $args;
+		} else {
+			return false;
+		}
+	}
+}
+
+/**
+ * Display template content
+ * @return void
+ */
+if ( ! function_exists( 'prtfl_get_content' ) ) {
+	function prtfl_get_content( $second_query ) {
+		global $post, $prtfl_options;
+
+		$request = $second_query->request;
+
+		if ( ! empty( $post ) && ! empty( $post->post_content ) ) {
+			$page_content = $post->post_content;
+			if ( function_exists( 'mltlngg_the_content_filter' ) ) $page_content = mltlngg_the_content_filter( $page_content );
+			/* dublicate filter 'the_content' - as we couldnt use it */
+			if ( function_exists( 'wptexturize' ) ) {
+				$page_content = wptexturize( $page_content );
+			}
+			if ( function_exists( 'convert_smilies' ) ) {
+				$page_content = convert_smilies( $page_content );
+			}
+			if ( function_exists( 'wpautop' ) ) {
+				$page_content = wpautop( $page_content );
+			}
+			if ( function_exists( 'shortcode_unautop' ) ) {
+				$page_content = shortcode_unautop( $page_content );
+			}
+			if ( function_exists( 'prepend_attachment' ) ) {
+				$page_content = prepend_attachment( $page_content );
+			}
+			if ( function_exists( 'wp_make_content_images_responsive' ) ) {
+				$page_content = wp_make_content_images_responsive( $page_content );
+			}
+			if ( function_exists( 'do_shortcode' ) ) {
+				$page_content = do_shortcode( $page_content ); 
+			} ?>
+			<div class="portfolio_content entry-content">
+				<div class="entry"><?php echo $page_content; ?></div>
+			</div>
+		<?php }
+
+
+		if ( $second_query->have_posts() ) {
+			while ( $second_query->have_posts() ) {
+				$second_query->the_post(); ?>
+				<div class="portfolio_content <?php if ( 'twentyfourteen' == get_stylesheet() || 'twentythirteen' == get_stylesheet() || 'twentytwelve' == get_stylesheet() ) echo 'entry-content'; ?>">
+					<div class="entry">
+						<?php $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
+						$image			= wp_get_attachment_image_src( $post_thumbnail_id, $prtfl_options['image_size_album'] );
+						$post_meta		= get_post_meta( $post->ID, 'prtfl_information', true );
+
+						$short_descr = isset( $post_meta['_prtfl_short_descr'] ) ? $post_meta['_prtfl_short_descr'] : '';
+						if ( empty( $short_descr ) ) {
+							$short_descr = get_the_excerpt();
+						}
+						$title = get_the_title();
+						if ( empty( $title ) ) {
+							$title = '(' . __( 'No title', 'portfolio' ) . ')';
+						}
+						$permalink = get_permalink();
+						if ( ! empty( $image[0] ) ) {
+							/* get width and height for image_size_album */
+							if ( 'portfolio-thumb' != $prtfl_options['image_size_album'] ) {
+								$width  = absint( get_option( $prtfl_options['image_size_album'] . '_size_w' ) );
+								$height = absint( get_option( $prtfl_options['image_size_album'] . '_size_h' ) );
+							} else {
+								$width  = $prtfl_options['custom_size_px']['portfolio-thumb'][0];
+								$height = $prtfl_options['custom_size_px']['portfolio-thumb'][1];
+							}
+							$image_alt = get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true ); ?>
+							<div class="portfolio_thumb">
+								<a rel="bookmark" href="<?php echo $permalink; ?>" title="<?php echo $title; ?>">
+									<img src="<?php echo $image[0]; ?>" alt="<?php echo $image_alt; ?>" <?php if ( $width ) echo 'width="' . $width . '"'; if ( $height ) echo 'height="' . $height . '"'; ?> style="<?php if ( $width ) echo 'width:' . $width . 'px;'; if ( $height ) echo 'height:' . $height . 'px;'; ?>" />
+								</a>
+							</div><!-- .portfolio_thumb -->
+						<?php } ?>
+						<div class="portfolio_short_content">
+							<div class="item_title">
+								<p>
+									<a href="<?php echo $permalink; ?>" rel="bookmark"><?php echo $title; ?></a>
+								</p>
+							</div><!-- .item_title -->
+							<?php $date_compl	= isset( $post_meta['_prtfl_date_compl'] ) ? $post_meta['_prtfl_date_compl'] : '';
+							if ( 1 == $prtfl_options['date_additional_field'] && ! empty( $date_compl ) ) { ?>
+								<p>
+									<span class="lable"><?php echo '<b>' . $prtfl_options['date_text_field'] . '</b>'; ?></span> <?php echo $date_compl; ?>
+								</p>
+							<?php }
+							$user_id = get_current_user_id();
+
+							$link =	isset( $post_meta['_prtfl_link'] ) ? $post_meta['_prtfl_link'] : '';
+							if ( 1 == $prtfl_options['link_additional_field'] && ! empty( $link ) ) {
+
+								if ( false !== parse_url( $link ) ) {
+									if ( ( 0 == $user_id && 0 == $prtfl_options['link_additional_field_for_non_registered'] ) || 0 != $user_id ) { ?>
+										<p><span class="lable"><?php echo '<b>' . $prtfl_options['link_text_field'] . '</b>'; ?></span> <a href="<?php echo $link; ?>"><?php echo $link; ?></a></p>
+									<?php } else { ?>
+										<p><span class="lable"><?php echo '<b>' . $prtfl_options['link_text_field'] . '</b>'; ?></span> <?php echo $link; ?></p>
+									<?php }
+								} else { ?>prtfl_options
+									<p><span class="lable"><?php echo '<b>' . $prtfl_options['link_text_field'] . '</b>'; ?></span> <?php echo $link; ?></p>
+								<?php }
+							}
+							if ( 1 == $prtfl_options['shrdescription_additional_field'] ) { ?>
+								<p><span class="lable"><?php echo '<b>' . $prtfl_options['shrdescription_text_field'] . '</b>'; ?></span> <?php echo $short_descr; ?></p>
+							<?php } ?>
+						</div><!-- .portfolio_short_content -->
+					</div><!-- .entry -->
+					<div class="entry_footer">
+						<div class="read_more">
+							<a href="<?php the_permalink(); ?>" rel="bookmark"><?php _e( 'Read more', 'portfolio' ); ?></a>
+						</div><!-- .read_more -->
+						<?php $terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' );
+						if ( 1 == $prtfl_options['technologies_additional_field'] && ! is_wp_error( $terms ) ) {
+							if ( is_array( $terms ) && 0 < count( $terms ) ) { ?>
+								<div class="portfolio_terms">
+									<?php if ( isset( $prtfl_options['technologies_text_field'] ) ) echo '<b>' . $prtfl_options['technologies_text_field'] . '&nbsp;</b>';
+									$links = array();
+									foreach ( $terms as $term ) {
+										$links[] = '<a href="' . get_term_link( $term->slug, 'portfolio_technologies' ) . '" title="' . sprintf( __( "View all projects in %s" ), $term->name ) . '" ' . '>' . $term->name . '</a>';
+									}
+									echo implode( ', ', $links ); ?>
+								</div><!-- .portfolio_terms -->
+							<?php }
+						} ?>
+					</div><!-- .entry_footer -->
+				</div><!-- .portfolio_content -->
+					<?php }
+		}
+	}
+}
+
+/**
+ * Display post template content
+ * @return void
+ */
+if ( ! function_exists( 'prtfl_post_get_content' ) ) {
+	function prtfl_post_get_content() {
+		global $post, $prtfl_options;
+
+		while ( have_posts() ) : the_post(); ?>
+			<article class="portfolio_content entry-content">
+				<div class="entry">
+					<?php global $post;
+					$portfolio_options = get_option( 'prtfl_options' );
+					$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
+					$image			= wp_get_attachment_image_src( $post_thumbnail_id, $prtfl_options['image_size_album'] );
+					$post_meta		= get_post_meta( $post->ID, 'prtfl_information', true );
+
+					if ( ! empty( $image[0] ) ) {
+						$image_large = wp_get_attachment_image_src( $post_thumbnail_id, 'large' );
+						$image_desc = get_post( $post_thumbnail_id );
+						$image_desc = $image_desc->post_content;
+						/* get width and height for image_size_album */
+						if ( 'portfolio-thumb' != $prtfl_options['image_size_album'] ) {
+							$width  = absint( get_option( $prtfl_options['image_size_album'] . '_size_w' ) );
+							$height = absint( get_option( $prtfl_options['image_size_album'] . '_size_h' ) );
+						} else {
+							$width  = $prtfl_options['custom_size_px']['portfolio-thumb'][0];
+							$height = $prtfl_options['custom_size_px']['portfolio-thumb'][1];
+						}
+						$image_alt = get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true ); ?>
+						<div class="portfolio_thumb">
+							<a class="lightbox" data-fancybox="portfolio_fancybox" href="<?php echo $image_large[0]; ?>" title="<?php echo $image_desc; ?>">
+								<img src="<?php echo $image[0]; ?>" alt="<?php echo $image_alt; ?>" <?php if ( $width ) echo 'width="' . $width . '"'; if ( $height ) echo 'height="' . $height . '"'; ?> />
+							</a>
+						</div><!-- .portfolio_thumb -->
+					<?php } ?>
+					<div class="portfolio_short_content">
+						<?php $date_compl	= isset( $post_meta['_prtfl_date_compl'] ) ? $post_meta['_prtfl_date_compl'] : '';
+						if ( 1 == $portfolio_options['date_additional_field'] && ! empty( $date_compl ) ) { ?>
+							<p>
+								<span class="lable"><?php echo '<b>' . $portfolio_options['date_text_field'] . '</b>'; ?></span> <?php echo $date_compl; ?>
+							</p>
+						<?php }
+						$user_id = get_current_user_id();
+
+						$link =	isset( $post_meta['_prtfl_link'] ) ? $post_meta['_prtfl_link'] : '';
+						if ( 1 == $portfolio_options['link_additional_field'] && ! empty( $link ) ) {
+
+							if ( false !== parse_url( $link ) ) { ?>
+								<?php if ( ( 0 == $user_id && 0 == $portfolio_options['link_additional_field_for_non_registered'] ) || 0 != $user_id ) { ?>
+									<p><span class="lable"><?php echo '<b>'.  $portfolio_options['link_text_field'] . '</b>'; ?></span> <a href="<?php echo $link; ?>"><?php echo $link; ?></a></p>
+								<?php } else { ?>
+									<p><span class="lable"><?php echo '<b>' . $portfolio_options['link_text_field'] . '</b>'; ?></span> <?php echo $link; ?></p>
+								<?php }
+							} else { ?>
+								<p><span class="lable"><?php echo '<b>' . $portfolio_options['link_text_field'] . '</b>'; ?></span> <?php echo $link; ?></p>
+							<?php }
+						}
+						if ( 1 == $portfolio_options['description_additional_field'] ) {
+							$full_descr = $post->post_content != "" ? $post->post_content : '';
+							if ( empty( $full_descr ) ){
+								$full_descr = isset( $post_meta['_prtfl_short_descr'] ) ? $post_meta['_prtfl_short_descr'] : '';
+							} else {
+								if ( function_exists( 'mltlngg_the_content_filter' ) ) {
+									$full_descr = mltlngg_the_content_filter( $full_descr );
+								}
+								/* dublicate filter 'the_content' - as we couldnt use it */
+								if ( function_exists( 'wptexturize' ) ) {
+									$full_descr = wptexturize( $full_descr );
+								}
+								if ( function_exists( 'convert_smilies' ) ) {
+									$full_descr = convert_smilies( $full_descr );
+								}
+								if ( function_exists( 'wpautop' ) ) {
+									$full_descr = wpautop( $full_descr );
+								}
+								if ( function_exists( 'shortcode_unautop' ) ) {
+									$full_descr = shortcode_unautop( $full_descr );
+								}
+								if ( function_exists( 'prepend_attachment' ) ) {
+									$full_descr = prepend_attachment( $full_descr );
+								}
+								if ( function_exists( 'wp_make_content_images_responsive' ) ) {
+									$full_descr = wp_make_content_images_responsive( $full_descr );
+								}
+								if ( function_exists( 'do_shortcode' ) ) {
+									$full_descr = do_shortcode( $full_descr );
+								}
+							}
+							if ( ! empty( $full_descr ) ) { ?>
+								<div style = "clear: both;"><span class="lable"><?php echo '<b>' . $prtfl_options['description_text_field'] . '</b>'; ?></span> <?php echo $full_descr; ?></div>
+							<?php }
+						}
+
+						if ( 0 != $user_id && $portfolio_options ) {
+							$svn = isset( $post_meta['_prtfl_svn'] ) ? $post_meta['_prtfl_svn'] : '';
+							if ( 1 == $portfolio_options['svn_additional_field'] && ! empty( $svn ) ) { ?>
+								<p><span class="lable"><?php echo '<b>' . $portfolio_options['svn_text_field'] . '</b>'; ?></span> <?php echo $svn; ?></p>
+							<?php }
+							$executors_profile = wp_get_object_terms( $post->ID, 'portfolio_executor_profile' );
+							if ( 1 == $portfolio_options['executor_additional_field'] && ! empty( $executors_profile ) ) { ?>
+								<p><span class="lable"><?php echo '<b>' . $portfolio_options['executor_text_field'] . '</b>'; ?></span>
+								<?php $count = 0;
+								foreach ( $executors_profile as $profile ) {
+									if ( $count > 0 ) {
+										echo ', ';
+									} ?>
+									<a href="<?php echo get_term_link( $profile->slug, 'portfolio_executor_profile' ); ?>" title="<?php echo $profile->name; ?> profile" target="_blank"><?php echo $profile->name; ?></a>
+									<?php $count++;
+								} ?>
+								</p>
+							<?php }
+						 } ?>
+					</div><!-- .portfolio_short_content -->
+					<div class="portfolio_images_block" data-columns="<?php echo $portfolio_options['custom_image_row_count'] ?>">
+						<?php if ( metadata_exists( 'post', $post->ID, '_prtfl_images' ) ) {
+							$array_post_thumbnail_id = array_filter( explode( ',', get_post_meta( $post->ID, '_prtfl_images', true ) ) );
+						} else {
+							/* Compatibility with old plugin version 2.37 */
+							$args = array(
+								'post_parent'		=> $post->ID,
+								'post_type'			=> 'attachment',
+								'post_mime_type'	=> 'image',
+								'numberposts'		=> -1,
+								'orderby'			=> 'menu_order',
+								'order'				=> 'ASC',
+								'exclude'			=> $post_thumbnail_id,
+								'fields'			=> 'ids'
+							);
+							$array_post_thumbnail_id = get_children( $args );
+						}
+						$count_element = count( $array_post_thumbnail_id );
+
+						foreach ( $array_post_thumbnail_id as $key => $value ) {
+							$image			=	wp_get_attachment_image_src( $value, $prtfl_options['image_size_photo'] );
+							$image_large	=	wp_get_attachment_image_src( $value, 'large' );
+							$image_alt		=	get_post_meta( $value, '_wp_attachment_image_alt', true );
+							$image_title	=	get_post_meta( $value, '_wp_attachment_image_title', true );
+							$image_desc 	=	get_post( $value );
+							$image_desc		=	$image_desc->post_content;
+
+							/* get width and height for image_size_photo */
+							if ( 'portfolio-photo-thumb' != $prtfl_options['image_size_photo'] ) {
+								$width  = absint( get_option( $prtfl_options['image_size_photo'] . '_size_w' ) );
+								$height = absint( get_option( $prtfl_options['image_size_photo'] . '_size_h' ) );
+							} else {
+								$width  = $prtfl_options['custom_size_px']['portfolio-photo-thumb'][0];
+								$height = $prtfl_options['custom_size_px']['portfolio-photo-thumb'][1];
+							}
+
+							if ( 0 == $key ) { ?>
+								<span class="lable"><?php echo '<b>' . $portfolio_options['screenshot_text_field'] . '</b>'; ?></span>
+								<div class="portfolio_images_rows">
+							<?php } ?>
+							<div class="portfolio_images_gallery">
+								<a class="lightbox" data-fancybox="portfolio_fancybox" href="<?php echo $image_large[0]; ?>" title="<?php echo $image_desc; ?>">
+									<img src="<?php echo $image[0]; ?>" alt="<?php echo $image_alt; ?>" <?php if ( $width ) echo 'width="' . $width . '"'; if ( $height ) echo 'height="' . $height . '"'; ?> style="<?php if ( $width ) echo 'width:' . $width . 'px;'; if ( $height ) echo 'height:' . $height . 'px;'; ?>" />
+								</a>
+								<br /><?php echo $image_title;?>
+							</div>
+							<?php if ( 0 == ( $key + 1 ) % $portfolio_options['custom_image_row_count'] && 0 != $key && $key + 1 != $count_element ) { ?>
+								</div><!-- .portfolio_images_rows -->
+								<div class="portfolio_images_rows">
+							<?php }
+						}
+						if ( 0 < $count_element ) { ?>
+							</div><!-- .portfolio_images_rows -->
+						<?php } ?>
+					</div><!-- .portfolio_images_block -->
+				</div><!-- .entry -->
+				<div class="entry_footer entry-footer">
+					<?php $terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' );
+					if ( 1 == $portfolio_options['technologies_additional_field'] && ! ( empty( $terms ) || is_wp_error( $terms ) ) ) {
+						if ( is_array( $terms ) && 0 < count( $terms ) ) { ?>
+							<div class="portfolio_terms">
+								<?php if ( isset( $portfolio_options['technologies_text_field'] ) ) echo '<b>'. $portfolio_options['technologies_text_field'] . '&nbsp;</b>';
+								$links = array();
+								foreach ( $terms as $term ) {
+									$links[] = '<a href="' . get_term_link( $term->slug, 'portfolio_technologies' ) . '" title="' . sprintf( __( "View all projects in %s" ), $term->name ) . '" ' . '>' . $term->name . '</a>';
+								}
+								echo implode( ', ', $links ); ?>
+							</div><!-- .portfolio_terms -->
+						<?php }
+					} ?>
+				</div><!-- .entry_footer .entry-footer -->
+			</article><!-- .portfolio_content -->
+		<?php endwhile;
+	}
+}
+
+/* This function prints pagination for portfolio post type template */
+if ( ! function_exists( 'prtfl_pro_pagination' ) ) {
+	function prtfl_pro_pagination( $second_query, &$args ) {
+		global $wp_query, $prtfl_options;
+		$count_all_albums = $second_query->found_posts;
+
+		$request 	= $wp_query->request;
+		$paged 		= $showitems = $args['paged'];
+		$per_page 	= $args['posts_per_page'];
+		$pages 		= intval( $count_all_albums / $per_page );
+
+		if ( $count_all_albums % $per_page > 0 ) {
+			$pages += 1;
+		}
+		$range = 2;
+
+		if ( ! $pages ) {
+			$pages = 1;
+		}
+		if ( 1 != $pages ) { ?>
+			<div class='clear'></div>
+			<div id="portfolio_pagenation">
+				<div class='pagination'>
+					<?php if ( 2 < $paged && $paged > $range + 1 && $showitems < $pages ) {
+						echo "<a href='" . get_pagenum_link( 1 ) . "'>&laquo;</a>";
+					}
+					if ( 1 < $paged && $showitems < $pages ) {
+						echo "<a href='" . get_pagenum_link( $paged - 1 ) . "'>&lsaquo;</a>";
+					}
+					for ( $i = 1; $i <= $pages; $i++ ) {
+						if ( 1 != $pages && ( ! ( $i >= $paged + $range + 1 || $i <= $paged - $range - 1 ) || $pages <= $showitems ) ) {
+							echo ( $paged == $i ) ? "<span class='current'>" . $i . "</span>":"<a href='" . get_pagenum_link( $i ) . "' class='inactive' >" . $i . "</a>";
+						}
+					}
+					if ( $paged < $pages && $showitems < $pages ) {
+						echo "<a href='" . get_pagenum_link( $paged + 1 ) . "'>&rsaquo;</a>";
+					}
+					if ( $paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages ) {
+						echo "<a href='" . get_pagenum_link( $pages ) . "'>&raquo;</a>";
+					} ?>
+					<div class='clear'></div>
+				</div><!-- .pagination -->
+				<?php if ( function_exists( 'pgntn_display_pagination' ) ) pgntn_display_pagination( 'custom', $second_query ); ?>
+			</div><!-- #portfolio_pagenation -->
+		<?php }
+	}
+}
+
+/* add shortcode content  */
+if ( ! function_exists( 'prtfl_shortcode_button_content' ) ) {
+	function prtfl_shortcode_button_content( $content ) { ?>
+		<div id="prtfl" style="display:none;">
+			<fieldset>
+				<label>
+					<input type="number" value="3" min="0" max="1000" name="prtfl_display_count" id="prtfl_display_count" class="small-text" />
+					<span>
+						<?php _e( 'The number of portfolio projects to display', 'portfolio' ); ?>
+					</span>
+				</label>
+			</fieldset>
+			<input class="bws_default_shortcode" type="hidden" name="default" value="[latest_portfolio_items count=3]" />
+			<script type="text/javascript">
+				function prtfl_shortcode_init() {
+					( function( $ ) {
+						$( '.mce-reset #prtfl_display_count' ).on( 'change', function() {
+							var count = $( '.mce-reset #prtfl_display_count' ).val();
+							var shortcode = '[latest_portfolio_items count=' + count + ']';
+							$( '.mce-reset #bws_shortcode_display' ).text( shortcode );
+						} );
+					} )( jQuery );
+				}
+			</script>
+			<div class="clear"></div>
+		</div>
+	<?php }
+}
+
+/* add help tab  */
+if ( ! function_exists( 'prtfl_add_tabs' ) ) {
+	function prtfl_add_tabs() {
+		global $prtfl_options;
+		$screen = get_current_screen();
+		if ( ( ! empty( $screen->post_type ) && $prtfl_options['post_type_name'] == $screen->post_type ) ||
+			( ! empty( $screen->taxonomy ) && 'portfolio_executor_profile' == $screen->taxonomy ) ||
+			( ! empty( $screen->taxonomy ) && 'portfolio_technologies' == $screen->taxonomy ) ||
+			( isset( $_GET['page'] ) && 'portfolio.php' == $_GET['page'] ) ) {
+			$args = array(
+				'id' 			=> 'prtfl',
+				'section' 		=> '200538929'
+			);
+			bws_help_tab( $screen, $args );
+		}
+	}
+}
+
+if ( ! function_exists( 'prtfl_plugin_deactivation' ) ) {
+	function prtfl_plugin_deactivation() {
+		global $wpdb, $prtfl_BWS_demo_data;
+
+		if ( function_exists( 'is_multisite' ) && is_multisite() ) {
+			$old_blog = $wpdb->blogid;
+			/* Get all blog ids */
+			$blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" );
+			foreach ( $blogids as $blog_id ) {
+				switch_to_blog( $blog_id );
+				prtfl_include_demo_data();
+				$prtfl_BWS_demo_data->bws_remove_demo_data();
+			}
+			switch_to_blog( $old_blog );
+		} else {
+			global $prtfl_BWS_demo_data;
+
+			if ( ! $prtfl_BWS_demo_data ) {
+				prtfl_include_demo_data();
+			}
+			$prtfl_BWS_demo_data->bws_remove_demo_data();
+		}
+	}
+}
 
 if ( ! function_exists( 'prtfl_plugin_uninstall' ) ) {
 	function prtfl_plugin_uninstall() {
+		global $wpdb;
 		require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
 
-		if ( file_exists( get_stylesheet_directory() . '/portfolio.php' ) && ! unlink( get_stylesheet_directory() . '/portfolio.php' ) )
-			add_action( 'admin_notices', create_function( '', ' return "Error delete template file";' ) );
-		if ( file_exists( get_stylesheet_directory() . '/portfolio-post.php' ) && ! unlink( get_stylesheet_directory() . '/portfolio-post.php' ) )
-			add_action( 'admin_notices', create_function( '', ' return "Error delete template file";' ) );
+		$plugins_list = get_plugins();
 
-		delete_option( 'prtfl_options' );
-		delete_option( 'prtfl_tag_update' );
-		$plugins_list = get_plugins();
-		if ( ! array_key_exists( 'portfolio-pro/portfolio-pro.php', $plugins_list ) ) 
-			delete_option( 'widget-portfolio_technologies_widget' );
+		if ( function_exists( 'is_multisite' ) && is_multisite() ) {
+			$old_blog = $wpdb->blogid;
+			/* Get all blog ids */
+			$blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" );
+			foreach ( $blogids as $blog_id ) {
+				switch_to_blog( $blog_id );
+				if ( ! array_key_exists( 'portfolio-pro/portfolio-pro.php', $plugins_list ) ) {
+					delete_option( 'widget_portfolio_technologies_widget' );
+					delete_option( 'prtfl_options' );
+					delete_option( 'prtfl_tag_update' );
+					delete_post_meta_by_key( 'prtfl_information' );
+					delete_post_meta_by_key( '_prtfl_images' );
+					delete_post_meta_by_key( 'prtfl_featured' );
+				}
+			}
+			switch_to_blog( $old_blog );
+		} else {
+			if ( ! array_key_exists( 'portfolio-pro/portfolio-pro.php', $plugins_list ) ) {
+				delete_option( 'widget_portfolio_technologies_widget' );
+				delete_option( 'prtfl_options' );
+				delete_option( 'prtfl_tag_update' );
+				delete_post_meta_by_key( 'prtfl_information' );
+				delete_post_meta_by_key( '_prtfl_images' );
+				delete_post_meta_by_key( 'prtfl_featured' );
+			}
+		}
+
+		require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' );
+		bws_include_init( plugin_basename( __FILE__ ) );
+		bws_delete_plugin( plugin_basename( __FILE__ ) );
 	}
 }
 
-register_activation_hook( __FILE__, 'prtfl_plugin_install' ); /* Activate plugin */
+/* Activate plugin */
+register_activation_hook( __FILE__, 'prtfl_plugin_activate' );
 /* Add portfolio settings page in admin menu */
 add_action( 'admin_menu', 'add_prtfl_admin_menu' );
 add_action( 'admin_init', 'prtfl_admin_init' );
 add_action( 'init', 'prtfl_init' );
-add_action( 'wp_loaded', 'prtfl_flush_rules' );
+add_action( 'plugins_loaded', 'prtfl_plugins_loaded' );
 /* Save custom data from admin  */
 add_action( 'save_post', 'prtfl_save_postdata', 1, 2 );
 add_filter( 'content_save_pre', 'prtfl_content_save_pre', 10, 1 );
 
-/* Add template for single portfolio page */
-add_action( 'template_redirect', 'prtfl_template_redirect' );
-/* Add template in theme after activate new theme */
-add_action( 'after_switch_theme', 'prtfl_after_switch_theme', 10, 2 );
+/* this function add custom fields and images for PDF&Print plugin in Portfolio post */
+add_filter( 'bwsplgns_get_pdf_print_content', 'prtfl_add_pdf_print_content' );
 
 add_action( 'admin_enqueue_scripts', 'prtfl_admin_head' );
-add_action( 'wp_enqueue_scripts', 'prtfl_wp_head' );
+add_action( 'wp_enqueue_scripts', 'prtfl_wp_enqueue_scripts' );
+add_action( 'wp_head', 'prtfl_wp_head' );
+add_action( 'wp_footer', 'prtfl_wp_footer' );
 
 /* add theme name as class to body tag */
 add_filter( 'body_class', 'prtfl_theme_body_classes' );
@@ -1463,6 +2251,8 @@
 add_action( 'wp_ajax_prtfl_update_image', 'prtfl_update_image' );
 
 add_shortcode( 'latest_portfolio_items', 'prtfl_latest_items' );
+/* custom filter for bws button in tinyMCE */
+add_filter( 'bws_shortcode_button_content', 'prtfl_shortcode_button_content' );
 
 add_filter( 'request', 'prtfl_request_filter' );
 /* Display tachnologies taxonomy */
@@ -1474,10 +2264,6 @@
 
 add_filter( 'nav_menu_css_class', 'prtfl_add_portfolio_ancestor_to_menu', 10, 2 );
 
-add_filter( 'sanitize_file_name', 'prtfl_sanitize_file_name' );
-add_filter( 'intermediate_image_sizes_advanced', 'prtfl_filter_image_sizes' );
+add_action( 'admin_notices', 'prtfl_admin_notices' );
 
-add_action( 'admin_notices', 'prtfl_admin_notices');
-
-register_uninstall_hook( __FILE__, 'prtfl_plugin_uninstall' ); /* Deactivate plugin */
-?>
\ No newline at end of file
+register_deactivation_hook( __FILE__, 'prtfl_plugin_deactivation' ); /* Deactivate plugin */
\ No newline at end of file