set_basename( false, __FILE__ ); } else { if ( !function_exists( 'acreports_fs' ) ) { // Create a helper function for easy SDK access. function acreports_fs() { global $acreports_fs; if ( !isset( $acreports_fs ) ) { // Include Freemius SDK. require_once dirname( __FILE__ ) . '/freemius/start.php'; $acreports_fs = fs_dynamic_init( array( 'id' => '14137', 'slug' => 'advanced-customer-reports-woo', 'premium_slug' => 'advanced-customer-reports-woo-pro', 'type' => 'plugin', 'public_key' => 'pk_aec42eab35b95a152a8eb4ae8a911', 'is_premium' => false, 'premium_suffix' => '(PRO)', 'has_addons' => false, 'has_paid_plans' => true, 'trial' => array( 'days' => 7, 'is_require_payment' => true, ), 'menu' => array( 'slug' => 'advanced-customer-reports', 'account' => false, 'contact' => false, 'support' => false, 'pricing' => false, 'parent' => array( 'slug' => 'woocommerce', ), ), 'is_live' => true, 'is_org_compliant' => true, ) ); } return $acreports_fs; } // Init Freemius. acreports_fs(); // Signal that SDK was initiated. do_action( 'acreports_fs_loaded' ); } /** * The capability needed to open the report screens and call their endpoints. * * Defaults to manage_woocommerce so Shop Managers can use the plugin like * they can WooCommerce's own Customers screen. Administrators hold that * capability too. Filter it to restrict the plugin to another capability. */ function acreports_get_required_capability() { $capability = apply_filters( 'acreports_required_capability', 'manage_woocommerce' ); return ( is_string( $capability ) && '' !== $capability ? $capability : 'manage_woocommerce' ); } /** * Whether the current user may view customer reports. * * Every page callback and AJAX handler checks this one function, so the * screens and the endpoints behind them can never disagree about who is * allowed in. */ function acreports_current_user_can_view_reports() { return current_user_can( acreports_get_required_capability() ); } // Add "Report" column to WooCommerce Users page, for users who can open the report. add_filter( 'manage_users_columns', 'acreports_add_report_column', 9999 ); function acreports_add_report_column( $columns ) { if ( !acreports_current_user_can_view_reports() ) { return $columns; } $columns['report'] = __( 'Customer Report', 'advanced-customer-reports-woo' ); return $columns; } // Populate "Report" column with link to report add_filter( 'manage_users_custom_column', 'acreports_populate_report_column', 9999, 3 ); function acreports_populate_report_column( $value, $column_name, $user_id ) { if ( $column_name == 'report' && acreports_current_user_can_view_reports() ) { $user = get_user_by( 'id', $user_id ); if ( !$user ) { return $value; } $report_url = add_query_arg( array( 'page' => 'advanced-customer-reports', 'user_id' => (int) $user->ID, 'username' => $user->user_login, ), admin_url( 'admin.php' ) ); $value = '' . esc_html__( 'View Report', 'advanced-customer-reports-woo' ) . ''; } return $value; } // Add to WooCommerce admin menu after "Customers" add_action( 'admin_menu', 'acreports_add_customer_report_page' ); function acreports_add_customer_report_page() { add_submenu_page( 'woocommerce', __( 'Customer Reports', 'advanced-customer-reports-woo' ), __( 'Customer Reports', 'advanced-customer-reports-woo' ), acreports_get_required_capability(), 'advanced-customer-reports', 'acreports_customer_report_page_callback', 10 ); } // Enqueue admin scripts and styles add_action( 'admin_enqueue_scripts', 'acreports_enqueue_customer_report_scripts' ); function acreports_enqueue_customer_report_scripts() { // only enqueue on our custom page if ( isset( $_GET['page'] ) && $_GET['page'] == 'advanced-customer-reports' ) { wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'jquery-ui-autocomplete' ); // Call local jQuery UI wp_enqueue_script( 'jquery-ui-core' ); // Our scripts and styles $acreports_style_path = plugin_dir_path( __FILE__ ) . 'css/styles.css'; $acreports_script_path = plugin_dir_path( __FILE__ ) . 'js/scripts.js'; wp_enqueue_style( 'customer-report-styles', plugin_dir_url( __FILE__ ) . 'css/styles.css', array(), ( file_exists( $acreports_style_path ) ? filemtime( $acreports_style_path ) : '1.1.5' ) ); // Enqueue JavaScript wp_enqueue_script( 'acreports-scripts', plugin_dir_url( __FILE__ ) . 'js/scripts.js', array('jquery'), ( file_exists( $acreports_script_path ) ? filemtime( $acreports_script_path ) : '1.1.5' ), array( 'strategy' => 'defer', 'in_footer' => true, ) ); wp_localize_script( 'acreports-scripts', 'acreportsScripts', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'acreports_nonce' ), 'deepLink' => acreports_get_report_deep_link(), ) ); } } // Include Functions include_once 'inc/functions.php'; include_once 'inc/functions-report-data.php'; include_once 'inc/functions-customers.php'; include_once 'inc/functions-order-activity.php'; include_once 'inc/admin-options.php'; include_once 'inc/functions-order-summary.php'; // HPOS Compatibility 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 ); } } ); }