<?php
/*
    Plugin Name: SysBasics Customize My Account for WooCommerce
    Plugin URI: https://sysbasics.com
    Description: Easily customize the WooCommerce My Account page. Mobile Friendly User avatar, redesign the WooCommerce dashboard, manage menus, and apply premium styles for a better user experience.
    Version: 4.4.14
    Author: SysBasics
    Author URI: https://sysbasics.com
    Domain Path: /languages
    License: GPL v2 or later
    License URI: https://www.gnu.org/licenses/gpl-2.0.html
    Requires at least: 3.3
    Tested up to: 7.0.0
    WC requires at least: 3.0.0
    WC tested up to: 10.9.1
    Requires Plugins: woocommerce
*/

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly


if( !defined( 'wcmamtx_PLUGIN_URL' ) )
    define( 'wcmamtx_PLUGIN_URL', plugin_dir_url( __FILE__ ) );





if ( !defined( 'wcmamtx_update_doc_url' ) )
    define( 'wcmamtx_update_doc_url', 'https://www.sysbasics.com/knowledge-base/category/woocommerce-customize-my-account-pro/' );

if ( !defined( 'wcmamtx_doc_url' ) )
    define( 'wcmamtx_doc_url', 'https://www.sysbasics.com/knowledge-base/category/woocommerce-customize-my-account-pro/' );

if ( !defined( 'pro_url' ) )
    define( 'pro_url', 'https://sysbasics.com/go/customize/' );

if( !defined( 'wcmamtx_redirect_URL' ) )
define( 'wcmamtx_redirect_URL',"admin.php?page=wcmamtx_frontend_customizer" );




$mt_type = 'specific';


if ( !defined( 'wcmamtx_pro_price_html' ) )
    define( 'wcmamtx_pro_price_html', '$49 USD' );

if ( !defined( 'wcmamtx_pro_price_show' ) )
    define( 'wcmamtx_pro_price_show', 'yes' );






add_action( 'before_woocommerce_init', function() {
    if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
        \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
    }
});


add_action( 'init', 'wcmamtx_translate_test_load_plugin_textdomain' );


function wcmamtx_translate_test_load_plugin_textdomain() {
  load_plugin_textdomain( 'customize-my-account-for-woocommerce', false, basename( dirname(__FILE__) ).'/languages' );

}







/**
 * Check if elementor or elementor pro is active
 */


include_once( ABSPATH . 'wp-admin/includes/plugin.php' );




if ( is_plugin_active( 'wpml-sticky-links/plugin.php' )) {
    define( 'wcmamtx_wpmlsticky_mode', 'on' );
} else {
    define( 'wcmamtx_wpmlsticky_mode', 'off' );
}


if ( is_plugin_active( 'sysbasics-account-fields/sysbasics-account-fields.php' ) ) {
    define( 'sysbasics_checkout_mode', 'on' );
} else {
    define( 'sysbasics_checkout_mode', 'off' );
}


    include dirname( __FILE__ ) . '/include/wcmamtx_extra_functions.php';


      //include the classes
    include dirname( __FILE__ ) . '/include/admin/admin_settings.php';
    include dirname( __FILE__ ) . '/include/admin/onboarding.php';
    include dirname( __FILE__ ) . '/include/frontend/frontend_functions.php';
include dirname( __FILE__ ) . '/include/frontend/guest_dashboard_hooks.php';


    include dirname( __FILE__ ) . '/include/sysbasics-avatar-upload.php';

    
    $wcmamtx_layout = wcmamtx_get_layout();

    $nav_style = isset($wcmamtx_layout['nav_style']) ? $wcmamtx_layout['nav_style'] : wcmamtx_get_clean_design_theme_array();
if ( ! is_string( $nav_style ) ) { $nav_style = '02'; }
$nav_style = preg_replace( '/[^0-9a-zA-Z_-]/', '', basename( $nav_style ) );
if ( $nav_style === '' ) { $nav_style = '02'; }

    if ($nav_style == "04") {
        include dirname( __FILE__ ) . '/react-myaccount/react-myaccount.php';
        include dirname( __FILE__ ) . '/include/wcmamtx-shipment-tracking/rma-address-fix.php';
        include dirname( __FILE__ ) . '/include/wcmamtx-shipment-tracking/rma-endpoint-url-fix.php';
        include dirname( __FILE__ ) . '/include/wcmamtx-shipment-tracking/rma-billing-address.php';
        include dirname( __FILE__ ) . '/include/wcmamtx-shipment-tracking/rma-save-address.php';
        include dirname( __FILE__ ) . '/include/wcmamtx-shipment-tracking/rma-icon-fix.php';
    }


    include dirname( __FILE__ ) . '/include/wcmamtx-shipment-tracking/wcmamtx-shipment-tracking.php';

    include dirname( __FILE__ ) . '/include/wcmamtx-whitelabel.php';

    include dirname( __FILE__ ) . '/include/wcmamtx-customizer.php';
        include dirname( __FILE__ ) . '/include/wcmamtx-view-order-customizer.php';

    include dirname( __FILE__ ) . '/include/wcmamtx-orders-customizer.php';
    include dirname( __FILE__ ) . '/include/wcmamtx-downloads-customizer.php';
include dirname( __FILE__ ) . '/include/wcmamtx-guest-dashboard-customizer.php';

    

   if (!function_exists('wcmamtx_placeholder_img_src')) {
     function wcmamtx_placeholder_img_src() {
        return ''.wcmamtx_PLUGIN_URL.'assets/images/placeholder.png';
    }

}





/**
 * Get woocommerce version 
 */

if (!function_exists('wcmamtx_get_woo_version_number_free')) {

    function wcmamtx_get_woo_version_number_free() {
       
       if ( ! function_exists( 'get_plugins' ) )
         require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    
       
       $plugin_folder = get_plugins( '/' . 'customize-my-account-for-woocommerce' );
       $plugin_file = 'customize-my-account-for-woocommerce.php';
    
    
       if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) {
          return $plugin_folder[$plugin_file]['Version'];

       } else {
    
        return NULL;
       }
    }
}






$wcmamtx_endpoint_allowed_to_add = get_option('wcmamtx_endpoint_allowed_to_add');
$wcmamtx_groups_allowed_to_add = get_option('wcmamtx_groups_allowed_to_add');


if (!isset($wcmamtx_endpoint_allowed_to_add) || ($wcmamtx_endpoint_allowed_to_add == "")) {
    update_option('wcmamtx_endpoint_allowed_to_add',02);
}

if (!isset($wcmamtx_groups_allowed_to_add) || ($wcmamtx_groups_allowed_to_add == "")) {
    update_option('wcmamtx_groups_allowed_to_add',02);
}

/**
 * Get woocommerce version 
 */

if (!function_exists('wcmamtx_get_woo_version_number')) {

    function wcmamtx_get_woo_version_number() {
       
       if ( ! function_exists( 'get_plugins' ) )
         require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    
       
       $plugin_folder = get_plugins( '/' . 'woocommerce' );
       $plugin_file = 'woocommerce.php';
    
    
       if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) {
          return $plugin_folder[$plugin_file]['Version'];

       } else {
    
        return NULL;
       }
    }
}


if (!function_exists('wcmamtx_plugin_add_settings_link')) {

    function wcmamtx_plugin_add_settings_link( $links ) {

        $mt_type = wcmamtx_get_version_type();

        $settings_link1 = '<a href="' . admin_url( '/admin.php?page=wcmamtx_advanced_settings' ) . '">' . esc_html__( 'Settings','customize-my-account-for-woocommerce' ) . '</a>';

        array_push( $links, $settings_link1 );

        $wizard_link = '<a href="' . admin_url( 'admin.php?page=wcmamtx_onboarding' ) . '">' . esc_html__( 'Setup Wizard', 'customize-my-account-for-woocommerce' ) . '</a>';
        array_push( $links, $wizard_link );

            $settings_link2 = '<a href="'.pro_url.'" style="color:green; font-weight:bold;">' . esc_html__( 'Upgrade to premium version','customize-my-account-for-woocommerce' ) . '</a>';
            array_push( $links, $settings_link2 );



        return $links;
    }
}

$plugin = plugin_basename( __FILE__ );

add_filter( "plugin_action_links_$plugin", 'wcmamtx_plugin_add_settings_link' );



if (!function_exists('wcmamtx_plugin_row_meta')) {
    function wcmamtx_plugin_row_meta( $links, $file ) {    
        if ( plugin_basename( __FILE__ ) == $file ) {
            $row_meta = array(
                'docs'    => '<a href="' . esc_url( wcmamtx_doc_url ) . '" target="_blank" aria-label="' . esc_attr__( 'Docs', 'customize-my-account-for-woocommerce' ) . '" style="color:green;">' . esc_html__( 'Docs', 'customize-my-account-for-woocommerce' ) . '</a>',
                'support'    => '<a href="' . esc_url( 'https://www.sysbasics.com/customize-my-account-free-plugin-support/' ) . '" target="_blank" aria-label="' . esc_attr__( 'Support', 'customize-my-account-for-woocommerce' ) . '" style="color:green;">' . esc_html__( 'Support', 'customize-my-account-for-woocommerce' ) . '</a>'
            );
            return array_merge( $links, $row_meta );
        }
        return (array) $links;
    }
}

require __DIR__ . '/Appsero/src/Client.php';

/**
 * Initialize the plugin tracker
 *
 * @return void
 */
function Appsero_init_tracker_customize_my_account_for_woocommerce() {

    if ( ! class_exists( 'wcmamtx_Appsero\Client' ) ) {
      require_once __DIR__ . '/Appsero/src/Client.php';
    }

    $client = new wcmamtx_Appsero\Client( '5a4e946c-7285-41e2-a115-d7b48482092c', 'Customize My Account for WooCommerce', __FILE__ );



    $client->insights()
       ->add_plugin_data()
       ->init();

}

Appsero_init_tracker_customize_my_account_for_woocommerce();

add_filter( 'plugin_row_meta', 'wcmamtx_plugin_row_meta', 10, 2 );


if( !defined( 'wcmamtx_version_type' ) )
    define( 'wcmamtx_version_type', $mt_type );


if (!function_exists('wcmamtx_plugin_path')) {

    function wcmamtx_plugin_path() {
  
       return untrailingslashit( plugin_dir_path( __FILE__ ) );
    }

}


if (!function_exists('wcmamtx_get_version_type')) {

    function wcmamtx_get_version_type() {
        $plugin_path = plugin_dir_path( __FILE__ );

        if ((strpos($plugin_path, 'pro') !== false) && ( wcmamtx_version_type == "specific")) { 
            $dt_type = 'specific';
        } else {
            $dt_type = 'all';
        }
    
        return $dt_type;
    }
}

$mt_type = wcmamtx_get_version_type();


/**
 * Get woocommerce version 
 */

if (!function_exists('wcmamtx_get_plugin_version_number')) {

    function wcmamtx_get_plugin_version_number() {
       
       if ( ! function_exists( 'get_plugins' ) )
         require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    
       
       $plugin_folder = get_plugins( '/customize-my-account-for-woocommerce' );
       $plugin_file = 'customize-my-account-for-woocommerce.php';
    
    
       if ( isset( $plugin_folder[$plugin_file]['Version'] ) ) {
          return $plugin_folder[$plugin_file]['Version'];

       } else {
    
        return NULL;
       }
    }
}

register_activation_hook(__FILE__, 'wcmamtx_plugin_activation_hook');

add_action('admin_init', 'wcmamtx_admin_plugin_redirect');

/**
 * Get account menu item classes.
 *
 * @since 1.0.0
 */

if (!function_exists('wcmamtx_plugin_activation_hook')) {

    function wcmamtx_plugin_activation_hook() {

        // Don't forget to exit() because wp_redirect doesn't exit automatically
        add_option('wcmamtx_do_activation_redirect', true);
        add_option('wcmamtx_install_time', time());


    }

}


/**
 * Get account menu item classes.
 *
 * @since 1.0.0
 */

if (!function_exists('wcmamtx_admin_plugin_redirect')) {

    function wcmamtx_admin_plugin_redirect() {

        $wcmamtx_act_date_free = get_option('wcmamtx_act_date_free');

        $date_today = date("Ymd");

        if (!isset($wcmamtx_act_date_free) || ($wcmamtx_act_date_free == "")) {
            update_option('wcmamtx_act_date_free',$date_today);
        }

        if (get_option('wcmamtx_do_activation_redirect', false)) {
            delete_option('wcmamtx_do_activation_redirect');

            /* Send new installs to the onboarding wizard; returning installs
               (where onboarding was already completed) go straight to settings. */
            if ( ! get_option( 'wcmamtx_onboarding_completed' ) ) {
                wp_safe_redirect( admin_url( 'admin.php?page=wcmamtx_onboarding' ) );
            } else {
                wp_safe_redirect( admin_url( wcmamtx_redirect_URL ) );
            }

            exit;
        }

    }

}

?>