/**
	 * Called, when Plugin activated.
	 * 
	 * Creates or updates the options to latest version
	 * 
	 * Creates folder for upload files and initialises options, if not present
	 */
	public function on_activate() 
	{	
		//	We need WC -> if WC is not active, do not allow to activate the plugin, because we cannot load the correct version (backward compatibility)
		if ( ! function_exists('is_plugin_active') ) 
		{
			require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
		}
		if( ! is_plugin_active( 'woocommerce/woocommerce.php' ) )
		{
			deactivate_plugins( WC_Email_Att::$plugin_base_name );
			wp_die( __('<p>The plugin <strong>WooCommerce Email Attachments</strong> needs the plugin WooCommerce to be able to be activated. Please activate this plugin first. Plugin could not be activated.</p>', WC_Email_Att::TEXT_DOMAIN ), __( 'Plugin Activation Error', WC_Email_Att::TEXT_DOMAIN ),  array( 'response'=> 200, 'back_link' => TRUE ) );
		}
		
		//	See Documentation WP register_post_type
		WC_Email_Att::instance()->handler_wp_register_cpt_email_att();
		flush_rewrite_rules();
		
		$this->options = WC_Email_Att::get_options_default();
		
			//	test for previous versions, that need update - Optionname changed with 3.0.0
		$need_update = $this->check_for_update();
		
		//	Checks and creates new Upload Folder with fallback
		if( ! WC_Email_Att_Func::create_folder( $this->options['upload_folder'] ) )
		{
			$this->options['upload_folder'] = '/wc_email_attachment_uploads';
			update_option( WC_Email_Att::OPTIONNAME, $this->options );
			if( ! WC_Email_Att_Func::create_folder( $this->options['upload_folder'] ) )
			{
				deactivate_plugins( WC_Email_Att::$plugin_base_name );
				wp_die( __( '<p>The plugin <strong>WooCommerce Email Attachments</strong> encountered an error on creating the new upload folder. Try again or check your permissons or the permissons of Wordpress with your administrator. Plugin could not be activated.</p>', WC_Email_Att::TEXT_DOMAIN ), __( 'Plugin Activation Error', WC_Email_Att::TEXT_DOMAIN ),  array( 'response'=> 200, 'back_link' => TRUE ) );
			}
		}
				
		if( ! empty( $need_update ) )
		{
			update_option( WC_Email_Att::OPTIONNAME_UPDATE, $need_update );
		}
	}
Пример #2
0
	/**
	 * 
	 */
	protected function init_data_210()
	{
		$this->options_new = WC_Email_Att::get_options_default();
		$this->options_old = $this->get_options_default_210 ();
	}