<?php defined( 'ABSPATH' ) or die( 'No script kiddies please!!' );
if ( !class_exists( 'EGPR_Admin_Menu' ) ) {

    class EGPR_Admin_Menu extends EGPR_Library{
        /**
         * Executes all the tasks for Admin Menu with post type and configuration settings page
         * 
         * @since 1.0.0
         */
        function __construct() {
            add_action('init', array($this, 'egpr_register_post_type')); //register custom post type
            add_action('admin_menu', array($this, 'egpr_register_page')); //add submenu page
            add_action('admin_post_egpr_save_settings', array($this, 'egpr_fn_save_settings'));
            add_action('add_meta_boxes',array($this,'epgpr_add_google_map')); // Display google map metabox
            add_action('save_post', array($this, 'egpr_gmap_meta_save')); // Save google map metabox
            add_action('add_meta_boxes',array($this,'epgpr_add_review_settings')); // Display review settings metabox
            add_action('save_post', array($this, 'egpr_review_setup_meta_save')); // Save review settings metabox
            add_action('add_meta_boxes',array($this,'egpr_add_badge_settings')); //add bagdge settings
            add_action('save_post', array($this, 'egpr_badge_meta_save')); // Save bagdge data metabox
            add_action('add_meta_boxes',array($this,'epgpr_add_display_settings')); // Display review settings metabox
            add_action('save_post', array($this, 'egpr_display_meta_save')); // Save google map metabox
            add_action('add_meta_boxes',array($this,'epgpr_add_rateus_settings')); // Display rate us button metabox
            add_action('save_post', array($this, 'egpr_rateus_meta_save')); // Save rate us button metabox
            add_action('add_meta_boxes',array($this,'epgpr_add_viewall_settings')); // Display view all button metabox
            add_action('save_post', array($this, 'egpr_viewall_meta_save')); // Save view all button metabox
            add_action('add_meta_boxes',array($this,'epgpr_add_custom_settings')); // Display custom settings metabox
            add_action('save_post', array($this, 'egpr_custom_meta_save')); // Save google map metabox
            add_action('add_meta_boxes', array($this, 'egpr_shortcode_usage_metabox')); //added shortcode usages metabox
            add_action('widgets_init', array($this, 'egpr_widget_register')); //create review widgets

            
            /* add meta box for pages and posts */
            add_action( 'add_meta_boxes', array($this, 'egpr_assign_floating_review')); // add floating reviews option in post, page and post type.
            add_action('save_post', array($this, 'egpr_floating_review_save_meta')); // save meta box data.
            
            //add custom row and content
             add_filter('manage_egprreviews_posts_columns', array($this,'egpr_columns_head')); //adding custom row 
             add_action('manage_egprreviews_posts_custom_column', array($this,'egpr_columns_content'), 10, 2); //adding custom row content
             add_action('admin_head-post-new.php', array($this, 'egpr_posttype_admin_css'));
             add_action('admin_head-post.php', array($this, 'egpr_posttype_admin_css'));
             add_filter('post_row_actions', array($this, 'egpr_remove_row_actions'), 10, 1);
             //add_filter('preview_post_link', array($this,  'egpr_change_post_link'), 10, 2);
            // add_filter('post_type_link', array($this,  'egpr_change_link'), 10, 2);
             //add_action( 'template_redirect', array($this, 'egpr_preview_redirect') );

            add_filter('the_content', array($this, 'egpr_preview_etab'));
            //add_action('wp_head', array($this, 'egpr_header_script'));

        }

//   public function egpr_header_script(){
//             echo '    <script type="application/ld+json">        {"aggregateRating": {"reviewCount": 1, "@type": "AggregateRating", "ratingValue": 5.0}, "review": [{"reviewRating": {"ratingValue": 5}, "datePublished": "2017-01-20", "description": "Xtreme Websites designed a website we were looking for that beats all of our competitors\nsites. We are excited for this new step in growing our business. We really enjoyed having expert guidance throughout the entire discovery and design process. Our new website allows \nour customers to have easy access to find and buy what they are looking for, which is exactly what we intended from the beginning. I highly recommend Xtreme for any highly customized web development.", "author": "Michael S."}], "priceRange": null, "name": "Xtreme Websites", "address": {"addressLocality": "Kensington", "addressRegion": "MD", "streetAddress": "10400 Connecticut Ave\nSte 513", "postalCode": "20895", "addressCountry": "US"}, "@context": "http://schema.org/", "image": "https://s3-media2.fl.yelpcdn.com/bphoto/k7UlwNUH8xRXYBo13O11mg/ls.jpg", "@type": "LocalBusiness", "telephone": "+12408959327"}
// </script>';
//         }


          /*
        * Loads the text domain for language translation & Register Everest Google Places Reviews Post Type
        */
        public function egpr_register_post_type() {
            load_plugin_textdomain('everest-google-places-reviews', false, basename(dirname(__FILE__)) . '/languages/');
            include(EGPR_PATH.'inc/admin/egpr-post-type.php');
            register_post_type('egprreviews', $args);
        }

        /*
        * Adding Submenu page
        */
        public function egpr_register_page() {
            add_submenu_page('edit.php?post_type=egprreviews', __('Configuration Settings', EGPR_TD), __('Configuration Settings', EGPR_TD), 'manage_options', 'egpr-configuration-settings', array($this, 'egpr_configuration_settings_callback'));
        }

        public function egpr_configuration_settings_callback() {
            include(EGPR_PATH.'inc/admin/pages/egpr-config-settings.php');
        }
        
        /*
         *  Save Default Setting Values to option table 
        */
        public function egpr_fn_save_settings(){
            if (isset($_POST['egpr_nonce_setup']) && wp_verify_nonce($_POST['egpr_nonce_setup'], 'egpr-nonce')) {
               if(isset($_POST['egpr_settings_submit'])){
                 $_POST = array_map( 'stripslashes_deep', $_POST );
                 $egp_reviews = $this->sanitize_array($_POST['egp_reviews']);
                 update_option('egp_reviews', $egp_reviews);
                 wp_redirect(admin_url('edit.php?post_type=egprreviews&page=egpr-configuration-settings&message=1'));
                 
               }else if(isset($_POST['egpr_restore_settings'])){
                   $act_obj = new EGPR_Activation();
                   $default_settings = $act_obj->egpr_default_settings();
                   update_option('egp_reviews', $default_settings);
                   wp_redirect(admin_url('edit.php?post_type=egprreviews&page=egpr-configuration-settings&restore_message=1'));
                   exit();
               }else if(isset($_POST['egpr_clear_cache'])){
                   $args = array(
                        'post_type' => 'egprreviews',
                        'post_status' => 'publish',
                        'posts_per_page' => -1
                    );
                    $egpr_reviews =get_posts( $args );
                    if(isset($egpr_reviews) && !empty($egpr_reviews)){
                        foreach ($egpr_reviews as $key => $value) {
                           $RID =  $value->ID;
                           $egpr_meta_option = get_post_meta($RID , 'egpr_meta_option', true);
                           $place_id = (isset($egpr_meta_option['place_id']) && $egpr_meta_option['place_id'] != '')?$egpr_meta_option['place_id']:'';
                           $google_transient = 'google_' . md5($place_id); // set transient id
                           delete_transient($google_transient);
                        }
                    }
                      wp_redirect(admin_url('edit.php?post_type=egprreviews&page=egpr-configuration-settings&cache_message=1'));
                       exit();
               }
            } else {
                die('No script kiddies please!');
            }
        }
        
        /*
         * Display Google Map Place ID and Location Metabox
         */
        public function epgpr_add_google_map(){
            add_meta_box('egpr_google_map_section', __('Google Map Location', EGPR_TD), array($this, 'render_gmap_callback'), 'egprreviews', 'normal', 'high');
        }
        
        public function render_gmap_callback( $post ){
             // Add nonce for security and authentication.
            wp_nonce_field(basename(__FILE__), 'egpr_meta_nonce');
            include(EGPR_PATH.'inc/admin/post_type_metabox/egpr-gmap-meta.php');
        }
        
      /*
       * Save Google Map Place ID Data Metabox
       */
       public function egpr_gmap_meta_save($post_id) {

            if (isset($_POST['egpr_meta_option'])) {
                $egpr_meta_option = $this->sanitize_array($_POST['egpr_meta_option']);
                update_post_meta($post_id, 'egpr_meta_option',$egpr_meta_option);
            }
            return;
            // Checks save status
            $is_autosave = wp_is_post_autosave($post_id);
            $is_revision = wp_is_post_revision($post_id);
            $is_valid_nonce = ( isset($_POST['egpr_meta_nonce']) && wp_verify_nonce($_POST['egpr_meta_nonce'], basename(__FILE__)) ) ? 'true' : 'false';
            // Exits script depending on save status
            if ($is_autosave || $is_revision || !$is_valid_nonce) {
                return;
            }
        }
        
        /*
         * Display Review Settings Metabox
         */
        public function epgpr_add_review_settings(){
            add_meta_box('egpr_review_settings_section',  __('General Review Settings', EGPR_TD), array($this,'render_review_setup_callback'),'egprreviews');
        }
        
        public function render_review_setup_callback( $post ){
             // Add nonce for security and authentication.
            wp_nonce_field(basename(__FILE__), 'egpr_review_settings_nonce');
            include(EGPR_PATH.'inc/admin/post_type_metabox/egpr-review-setup-meta.php'); 
        }
        
       /*
       * Save Review General Settings Data Metabox
       */
        public function egpr_review_setup_meta_save( $post_id ){
            if (isset($_POST['egpr_review_settings'])) {
                $egpr_review_settings = (array) $_POST['egpr_review_settings'];
                // sanitize array
                $egpr_settings_options = array_map('sanitize_text_field', $egpr_review_settings);
                // save data
                update_post_meta($post_id, 'egpr_review_settings', $egpr_settings_options);
            }

            return;
            // Checks save status
            $is_autosave = wp_is_post_autosave($post_id);
            $is_revision = wp_is_post_revision($post_id);
            $is_valid_nonce = ( isset($_POST['egpr_review_settings_nonce']) && wp_verify_nonce($_POST['egpr_review_settings_nonce'], basename(__FILE__)) ) ? 'true' : 'false';
            // Exits script depending on save status
            if ($is_autosave || $is_revision || !$is_valid_nonce) {
                return;
            }
        }
        
        /*
         * Add Show Badge Metabox
         */
        public function egpr_add_badge_settings(){
            add_meta_box('egpr_badge_settings_section',  __('Badge Settings', EGPR_TD), array($this,'render_badge_setup_callback'),'egprreviews');
        }
        
        function render_badge_setup_callback( $post ){
              // Add nonce for security and authentication.
            wp_nonce_field(basename(__FILE__), 'egpr_badge_settings_nonce');
            include(EGPR_PATH.'inc/admin/post_type_metabox/egpr-badge-setup-meta.php'); 
        }
        
        /*
       * Save Review General Settings Data Metabox
       */
        function egpr_badge_meta_save( $post_id  ){
             if (isset($_POST['egpr_badge_settings'])) {
                $egpr_badge_settings = $this->sanitize_array($_POST['egpr_badge_settings']);
                update_post_meta($post_id, 'egpr_badge_settings',$egpr_badge_settings);
            }
            return;
            // Checks save status
            $is_autosave = wp_is_post_autosave($post_id);
            $is_revision = wp_is_post_revision($post_id);
            $is_valid_nonce = ( isset($_POST['egpr_badge_settings_nonce']) && wp_verify_nonce($_POST['egpr_badge_settings_nonce'], basename(__FILE__)) ) ? 'true' : 'false';
            // Exits script depending on save status
            if ($is_autosave || $is_revision || !$is_valid_nonce) {
                return;
            }
        }


        /*
         * Display Display Settings Metabox
         */
        public function epgpr_add_display_settings(){
            add_meta_box('egpr_review_display_section',  __('Reviews Settings', EGPR_TD), array($this,'render_display_setup_callback'),'egprreviews');
        }
        
        public function render_display_setup_callback(  $post ){
             // Add nonce for security and authentication.
            wp_nonce_field(basename(__FILE__), 'egpr_display_settings_nonce');
            include(EGPR_PATH.'inc/admin/post_type_metabox/egpr-display-setup-meta.php'); 
        }
        
        public function egpr_display_meta_save( $post_id ){
            if (isset($_POST['egpr_display_settings'])) {
                $egpr_display_settings = (array) $_POST['egpr_display_settings'];
                // sanitize array
                $egpr_display_settings = $this->sanitize_array($egpr_display_settings);
                // save data
                update_post_meta($post_id, 'egpr_display_settings', $egpr_display_settings);
            }

            return;
            // Checks save status
            $is_autosave = wp_is_post_autosave($post_id);
            $is_revision = wp_is_post_revision($post_id);
            $is_valid_nonce = ( isset($_POST['egpr_display_settings_nonce']) && wp_verify_nonce($_POST['egpr_display_settings_nonce'], basename(__FILE__)) ) ? 'true' : 'false';
            // Exits script depending on save status
            if ($is_autosave || $is_revision || !$is_valid_nonce) {
                return;
            }
        }
        
        /*
         * Rate Us Metabox Settings
         */
        public function epgpr_add_rateus_settings(){
            add_meta_box('egpr_rateus_options_section',  __('Rates Us Settings', EGPR_TD), array($this,'render_rateus_setup_callback'),'egprreviews'); 
        }
        
         public function render_rateus_setup_callback(  $post ){
             // Add nonce for security and authentication.
            wp_nonce_field(basename(__FILE__), 'egpr_rateus_options_nonce');
            include(EGPR_PATH.'inc/admin/post_type_metabox/egpr-rateus-options-meta.php'); 
        }

        public function egpr_rateus_meta_save( $post_id ){
            if (isset($_POST['egpr_rateus_settings'])) {
                $egpr_rateus_settings = (array) $_POST['egpr_rateus_settings'];
                // sanitize array
                $egpr_rateus_settings = array_map('sanitize_text_field', $egpr_rateus_settings);
                // save data
                update_post_meta($post_id, 'egpr_rateus_settings', $egpr_rateus_settings);
            }
            return;
            // Checks save status
            $is_autosave = wp_is_post_autosave($post_id);
            $is_revision = wp_is_post_revision($post_id);
            $is_valid_nonce = ( isset($_POST['egpr_rateus_options_nonce']) && wp_verify_nonce($_POST['egpr_rateus_options_nonce'], basename(__FILE__)) ) ? 'true' : 'false';
            // Exits script depending on save status
            if ($is_autosave || $is_revision || !$is_valid_nonce) {
                return;
            }
       }

       /*
       * View all button Metabox
       */
       public function epgpr_add_viewall_settings(){
         add_meta_box('egpr_viewall_options_section',  __('View All Button Settings', EGPR_TD), array($this,'render_viewall_setup_callback'),'egprreviews'); 
       }

      public function render_viewall_setup_callback(  $post ){
             // Add nonce for security and authentication.
            wp_nonce_field(basename(__FILE__), 'egpr_viewall_options_nonce');
            include(EGPR_PATH.'inc/admin/post_type_metabox/egpr-viewall-options-meta.php'); 
        }
        
        /*
        * Save view all button data
        */
        public function egpr_viewall_meta_save( $post_id ){
            if (isset($_POST['egpr_viewall_settings'])) {
                $egpr_viewall_settings = (array) $_POST['egpr_viewall_settings'];
                // sanitize array
                $egpr_viewall_settings = array_map('sanitize_text_field', $egpr_viewall_settings);
                // save data
                update_post_meta($post_id, 'egpr_viewall_settings', $egpr_viewall_settings);
            }
            return;
            // Checks save status
            $is_autosave = wp_is_post_autosave($post_id);
            $is_revision = wp_is_post_revision($post_id);
            $is_valid_nonce = ( isset($_POST['egpr_viewall_options_nonce']) && wp_verify_nonce($_POST['egpr_viewall_options_nonce'], basename(__FILE__)) ) ? 'true' : 'false';
            // Exits script depending on save status
            if ($is_autosave || $is_revision || !$is_valid_nonce) {
                return;
            }


        }
        
        /*
         * Custom Metabox Settings
         */
        public function epgpr_add_custom_settings(){
            add_meta_box('egpr_custom_options_section',  __('Custom Options Settings', EGPR_TD), array($this,'render_custom_setup_callback'),'egprreviews'); 
        }
        
         public function render_custom_setup_callback(  $post ){
             // Add nonce for security and authentication.
            wp_nonce_field(basename(__FILE__), 'egpr_custom_options_nonce');
            include(EGPR_PATH.'inc/admin/post_type_metabox/egpr-custom-options-meta.php'); 
        }
        
         public function egpr_custom_meta_save( $post_id ){
            if (isset($_POST['egpr_custom_settings'])) {
                $egpr_custom_settings = (array) $_POST['egpr_custom_settings'];
                // sanitize array
                $egpr_custom_settings = array_map('sanitize_text_field', $egpr_custom_settings);
                // save data
                update_post_meta($post_id, 'egpr_custom_settings', $egpr_custom_settings);
            }
            return;
            // Checks save status
            $is_autosave = wp_is_post_autosave($post_id);
            $is_revision = wp_is_post_revision($post_id);
            $is_valid_nonce = ( isset($_POST['egpr_custom_options_nonce']) && wp_verify_nonce($_POST['egpr_custom_options_nonce'], basename(__FILE__)) ) ? 'true' : 'false';
            // Exits script depending on save status
            if ($is_autosave || $is_revision || !$is_valid_nonce) {
                return;
            }
        }
        
        /*
         * Add Shortcode Metabox Sidebar
         */
        public function egpr_shortcode_usage_metabox(){
              add_meta_box('egpr_shortcode_usage_section', __('Everest Google Places Reviews Shortcode Usage', EGPR_TD), array($this, 'egpr_shortcode_usage_option_callback'), 'egprreviews', 'side', 'default');
        }
        
        public function egpr_shortcode_usage_option_callback( $post ){
            wp_nonce_field(basename(__FILE__), 'egpr_shortcode_usage_option_nonce');
            include(EGPR_PATH.'inc/admin/post_type_metabox/egpr-usages-meta.php'); 
        }
        
        public function egpr_widget_register(){
             register_widget('Everest_GPR_Widget');
        }
       
        /*
        * Assign Floating Review From specific Review lists
        */
        public function egpr_assign_floating_review(){
             global  $post_type;
             if($post_type != "egprreviews"){
                $screens = array( 'post', 'page', 'post_type' );
                            add_meta_box(
                                    'egpr-floating-review',
                            __( 'Choose Floating Review',EGPR_TD),
                            array($this, 'review_assign_callback'),
                                    '',
                            'side',
                            'default'
                            );
             }
        }
        
        public function review_assign_callback( $post ){
            global $post;
            wp_nonce_field( basename( __FILE__ ), 'egpr_freview_nonce' );
            $freview = get_post_meta( $post->ID, 'egpr-floating-review', true ); 
            $freviewtemplate = get_post_meta( $post->ID, 'egpr-floating-review-templates', true );   
            if( $freviewtemplate != ''){
              $freview_temp = $freviewtemplate;
            }else{
              $freview_temp = 'template1';
            }
            ?>
               <div class="egpr-note-wrap">
                <p class="description"><?php _e('Note: Select default floating review from plugin main tab settings "Floating Review Settings" i.e',EGPR_TD);?>
                 <?php _e('To change the default, click ',EGPR_TD);?><a href="<?php echo admin_url('edit.php?post_type=egprreviews&page=egpr-configuration-settings');?>" target="_blank">Change Default Now.</a></p>
                    <p class="description"><?php _e('Or simply choose specific different review from below dropdown list to assign it on this post/page.',EGPR_TD);?></p>
                </div>
                 <div class="egpr-freview-settings-wrapper">
                         <label><?php _e('Floating Review');?></label>
                         <select name="egpr-floating-review" class="egpr_floating_review" style="width:234px;">
                            <option value="default" <?php if($freview=='default'){echo 'selected="selected"';}?>>Default</option>

                            <?php
                              global $egpr_wpdb;
                              $review_posts = $egpr_wpdb->get_all_reviews('egprreviews');
                                if(isset($review_posts) && !empty($review_posts)):
                                    foreach($review_posts as $key => $value){
                                        ?>
                                   <option value="<?php echo esc_attr($value['ID']); ?>" <?php if( $freview == $value['ID']){echo 'selected="selected"';}?>><?php echo esc_attr($value['post_title']); ?></option>
                                        <?php
                                     }
                              endif;
                            ?>
                            <option value="disable" <?php if( $freview == 'disable'){echo 'selected="selected"';}?>>Disable</option>
                        </select>

                         <label><?php _e('Choose Template');?></label>
                         <select name="egpr-floating-review-templates" id="specific_frlayout" class="egpr_floating_review" style="width:234px;">
                             <option value="default">Default</option>
                             <option value="template1" <?php selected( $freview_temp, 'template1' ); ?>>Template1</option>   <option value="template2" <?php selected( $freview_temp, 'template2' ); ?>>Template2</option>
                             <option value="template3" <?php selected( $freview_temp, 'template3' ); ?>>Template3</option>
                             <option value="template4" <?php selected( $freview_temp, 'template4' ); ?>>Template4</option>
                             <option value="template5" <?php selected( $freview_temp, 'template5' ); ?>>Template5</option>
                        </select>
                           <p class="description"><?php _e('Choose any template layout among 5 for floating review.', 'everest-google-places-reviews'); ?></p>
                                <div id="floating_template1" class="review_preview <?php if ($freview_temp == 'template1') {  echo ''; } else {  echo 'hide_tmp'; } ?>">
                                    <div class="egpr-fleft"> 
                                    <img src="<?php echo EGPR_BACKEND_IMG_DIR . 'floating-off-canvas/offcanvas-1.png' ?>"/ style="width:96%"></div>
                                </div>
                                     <div id="floating_template2" class="review_preview <?php if ($freview_temp == 'template2') {  echo ''; } else {  echo 'hide_tmp'; } ?>">
                                    <img src="<?php echo EGPR_BACKEND_IMG_DIR . 'floating-off-canvas/offcanvas-2.png' ?>" style="width:96%"/>
                                </div> <div id="floating_template3" class="review_preview <?php if ($freview_temp == 'template3') {  echo ''; } else {  echo 'hide_tmp'; } ?>">
                                    <img src="<?php echo EGPR_BACKEND_IMG_DIR . 'floating-off-canvas/offcanvas-3.png' ?>" style="width:96%"/>
                                </div> <div id="floating_template4" class="review_preview <?php if ($freview_temp == 'template4') {  echo ''; } else {  echo 'hide_tmp'; } ?>">
                                     <img src="<?php echo EGPR_BACKEND_IMG_DIR . 'floating-off-canvas/offcanvas-4.png' ?>" style="width:96%"/>
                                </div> 
                                <div id="floating_template5" class="review_preview <?php if ($freview_temp == 'template5') {  echo ''; } else {  echo 'hide_tmp'; } ?>">
                                     <img src="<?php echo EGPR_BACKEND_IMG_DIR . 'floating-off-canvas/offcanvas-5.png' ?>" style="width:96%"/>
                                </div>
                    </div>
                <div class="egpr-note-wrap">                    
                <p class="description"><?php _e('You can even disable review for this post by choosing Disable from above dropdown list.',EGPR_TD);?></p>
                </div>
            <style>
                .hide_tmp {
                    display: none;
                }
                .egpr-note-wrap{
                    background: #e2e2e2;
                    padding: 10px;
                    margin-bottom: 4px;
                    margin-top: 8px;
                }
            </style>
            <script>
              (function ($) {
                  $(document).ready(function () {
                    $('body').on('change', '#specific_frlayout', function () {
                         var review_layout = $(this).val();
                         $('.review_preview').addClass('hide_tmp');
                         $('#floating_'+review_layout).removeClass('hide_tmp');
                     });
                   });//$(function () end
                }(jQuery));
            </script>
    <?php
        }
        
          /**
           * When the post is saved, saves our custom data.
           *
           * @param int $post_id The ID of the post being saved.
           */
        public function egpr_floating_review_save_meta( $post_id ){
             if (isset($_POST['egpr-floating-review'])) {
                $egprreview = sanitize_text_field( $_POST['egpr-floating-review'] );
                update_post_meta($post_id, 'egpr-floating-review', $egprreview);
            }
              if (isset($_POST['egpr-floating-review-templates'])) {
                $egprreview_template = sanitize_text_field( $_POST['egpr-floating-review-templates'] );
                update_post_meta($post_id, 'egpr-floating-review-templates', $egprreview_template);
            }
            return;
            // Checks save status
            $is_autosave = wp_is_post_autosave($post_id);
            $is_revision = wp_is_post_revision($post_id);
            // Verify the nonce before proceeding.
            $is_valid_nonce = ( isset($_POST['egpr_freview_nonce']) && wp_verify_nonce($_POST['egpr_freview_nonce'], basename(__FILE__)) ) ? 'true' : 'false';
            // Exits script depending on save status
            if ($is_autosave || $is_revision || !$is_valid_nonce) {
                return;
            }
        }
        
         /*
         * Add custom column to egpreviews posttype
         */
        public function egpr_columns_head($defaults){
             $defaults['shortcodes'] = __('Shortcodes', EGPR_TD);
             $defaults['template'] = __('Template Include', EGPR_TD);
              unset($defaults['date']);   // remove it from the columns list
              $defaults['date'] = __('Date', EGPR_TD);
              return $defaults;
        }
         /*
         * Added content to custom column to egpreviews posttype
         */
         public function egpr_columns_content($column, $post_ID){
             if ($column == 'shortcodes') {
                $id = $post_ID;
                ?>
                <textarea class="egpr-shortcode-display-value" style="resize: none;" rows="2" cols="40" readonly="readonly">[egpr_reviews id="<?php echo $id; ?>"]</textarea>
                <span class="egpr-copied-info" style="display: none;"><?php _e('Shortcode copied to your clipboard.', EGPR_TD); ?></span>
               <?php
                }
            if ($column == 'template') {
                $id = $post_ID;
                ?>
                <textarea class="egpr-shortcode-display-value2" style="resize: none;" rows="2" cols="45" readonly="readonly">&lt;?php echo do_shortcode("[egpr_reviews id='<?php echo $id; ?>']"); ?&gt;</textarea>
                <span class="egpr-copied-info2" style="display: none;"><?php _e('Shortcode copied to your clipboard.', EGPR_TD); ?></span>
                  <?php
            }
        }
        
        /*
         * Remove view and preview from egpreviews post
         */
        function egpr_posttype_admin_css() {
            global $post_type;
            $post_types = array(
                /* set post types */
                'egprreviews'
            );
            if (in_array($post_type, $post_types))
                echo '<style type="text/css"> #view-post-btn, .updated a,#screen-meta-links .screen-meta-toggle
                {display: none;}</style>';
        }
        
           function egpr_remove_row_actions($actions) {
            if (get_post_type() == 'egprreviews') { // choose the post type where you want to hide the button
              //  unset($actions['view']); // this hides the VIEW button on your edit post screen
                unset($actions['inline hide-if-no-js']);
            }
            return $actions;
        }
        
        /*
         * Change the default “preview” button for egpreviews posttype
         */
      /*  public function egpr_change_post_link($link){
             if ( get_post_type() == 'egprreviews' ) {
               $post_status = get_post_status();
               if ( $post_status != 'auto-draft' ) {
                   $post_id = get_the_ID();
                   $nonce = wp_create_nonce('egpr_nonce');
                   $link = site_url( '?review_preview=true&_wpnonce='.$nonce.'&reviewid=' . $post_id );
                   return $link;
               }
           }else{
               return $link;
           }
        }*/

        /*public function egpr_change_link($post_url,$post) {
          if ( get_post_type() == 'egprreviews' ) {
                $nonce = wp_create_nonce('egpr_nonce');
              return site_url( '?review_preview=true&_wpnonce='.$nonce.'&reviewid=' . $post->ID );
            }else{
                return $post_url;
            }
        }
        */
       /* public function egpr_preview_redirect(){
          if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'egpr_nonce' ) ) {
             if ( isset( $_GET[ 'review_preview' ], $_GET[ 'reviewid' ] ) && $_GET[ 'review_preview' ] && is_user_logged_in() ) {
               include(EGPR_PATH . 'inc/frontend/egpr-preview.php');
               die();
           }
           }
        }*/

        /*
         * Display Backend Preview on single page itself with shortcode load
         */
        public function egpr_preview_etab($content){
            global $post;
            if ( is_singular( 'egprreviews' ) ) {
                if (isset($_GET['preview_id']) && is_user_logged_in()) {
                    $post_id = intval($_GET['preview_id']);
                    return do_shortcode("[egpr_reviews id='$post_id']");
                }if (isset($_GET['p']) && is_user_logged_in()) {
                    $post_id = intval($_GET['p']);
                    return do_shortcode("[egpr_reviews id='$post_id']");
                }else{
                    $post_id = $post->ID;
                    return do_shortcode("[egpr_reviews id='$post_id']");
                }
            }else {
                return $content;
            }
        }
        
    }
    new EGPR_Admin_Menu();
}
