setup_constants(); $this->includes(); do_action( 'wpos_anylc_loaded' ); } /** * Define constant if not already set. * * @param string $name * @param string|bool $value */ public function define( $name, $value ) { if ( ! defined( $name ) ) { define( $name, $value ); } } /** * Setup plugin constants. Basic plugin definitions * * @access private * @since 1.0 */ private function setup_constants() { $this->define( 'WPOS_ANYLC_VERSION', '1.1' ); $this->define( 'WPOS_ANYLC_DIR', plugin_dir_path( __FILE__ ) ); $this->define( 'WPOS_ANYLC_URL', plugin_dir_url( __FILE__ ) ); } /** * Include required files. * * @access private * @since 1.0 */ private function includes() { // Functions file require_once WPOS_ANYLC_DIR .'/includes/wpos-anylc-function.php'; // Script Class require_once WPOS_ANYLC_DIR .'/includes/class-anylc-script.php'; // Admin Class require_once WPOS_ANYLC_DIR .'/includes/class-anylc-admin.php'; } } /** * * The main function responsible for returning the one true Analytics * Instance to functions everywhere. * * Use this function like you would a global variable, except without needing * to declare the global. * * Example: * * @since 1.0 * @return object The one true Analytics Instance. */ function WPOS_ANYLC() { return WPOS_Analytics::instance(); } /** * * Initialize Analytics Module * * @since 1.0 * @return object The one true Analytics Instance. */ function wpos_anylc_init_module( $args = array() ) { global $wpos_analytics_module, $wpos_analytics_product; $defaul_args = array( 'id' => null, 'file' => null, 'name' => null, 'slug' => null, 'type' => 'plugin', 'menu' => false, 'icon' => '', 'text_domain' => 'wpos_analytics', ); $args = wp_parse_args( $args, $defaul_args ); // If required data is not there then simply return if( empty($args['id']) || empty( $args['file'] ) || empty( $args['slug'] ) ) { return false; } // Additional args $promotion = array(); $args['dir'] = pathinfo($args['file'], PATHINFO_DIRNAME); $args['icon'] = empty( $icon ) ? trailingslashit( WP_PLUGIN_URL ).$args['dir'].'/wpos-analytics/assets/images/icon.png' : $args['icon']; $args['brand_icon'] = plugin_dir_url( __FILE__ ).'assets/images/wpos-logo.png'; $args['anylc_optin'] = 'wpos_anylc_pdt_'.$args['id']; if( isset( $args['promotion'] ) ) { foreach ($args['promotion'] as $promotion_key => $promotion_data) { if( empty( $promotion_data['name'] ) || empty( $promotion_data['file'] ) ) { continue; } $promotion[$promotion_key] = $promotion_data; } } $args['promotion'] = $promotion; // Taking some variables $wpos_analytics_module = !empty( $wpos_analytics_module ) ? $wpos_analytics_module : array(); $wpos_analytics_product = !empty( $wpos_analytics_product ) ? $wpos_analytics_product : array(); if( is_array( $wpos_analytics_module ) ) { $wpos_analytics_module[ $args['file'] ] = $args; } if( is_array( $wpos_analytics_product ) ) { $wpos_analytics_product[ $args['slug'] ] = $args; } return $wpos_analytics_module; } /** * * Function on any plugin deactivation * * @since 1.0 * @return object The one true Analytics Instance. */ function wpos_anylc_plugin_activation( $plugin, $network_activation ) { // return if activating from network, or bulk if ( is_network_admin() ) { return; } global $wpos_analytics_module; if( isset( $wpos_analytics_module[ $plugin ] ) ) { $opt_in_data = get_option( $wpos_analytics_module[ $plugin ]['anylc_optin'] ); $optin_status = isset( $opt_in_data['status'] ) ? $opt_in_data['status'] : -1; if( $optin_status == -1 ) { $redirect_link = add_query_arg( array('page' => $wpos_analytics_module[ $plugin ]['slug']), admin_url('admin.php') ); update_option( 'wpos_anylc_redirect', $redirect_link ); } } } add_action( 'activated_plugin', 'wpos_anylc_plugin_activation', 10, 2 ); /** * * Initialize Analytics Class Once all stuff has been loaded * * @since 1.0 * @return object The one true Analytics Instance. */ function wpos_anylc_plugins_loaded() { // Get Analytics Running. WPOS_ANYLC(); } add_action( 'plugins_loaded', 'wpos_anylc_plugins_loaded', 12 ); endif; // End if class_exists check.