MP_Addon_CalculatorsGoogleSpreadSheetsAddon

Class MP_Addon_CalculatorsGoogleSpreadSheetsAddon.


Source Source

File: calculator-google-spreadsheets-add-on/calculator-google-spreadsheets-add-on.php

	class MP_Addon_CalculatorsGoogleSpreadSheetsAddon {


		/**
		 * Register functions.
		 * @since  1.0.0
		 * @access public
		 */
		public function register() {

			load_plugin_textdomain( 'CalculatorsGoogleSpreadSheetsAddon', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );

			add_action( 'mortgage_platform_addons', array( $this, 'init' ), 10 );

		}


		/**
		 * Init function.
		 * @since  1.0.0
		 * @access public
		 */
		public function init() {

			if ( isset(get_option( MortgagePlatform::$prefix . 'export' )['allow_google_sheet']) && get_option( MortgagePlatform::$prefix . 'export' )['allow_google_sheet'] ) {
				add_action( 'export_lead_data', array( new MP_Addon_Google_Spreadsheets, 'set_lead_data_to_spreadsheet' ) );
			}

			add_filter( MortgagePlatform::$prefix . 'export', array( new MP_Addon_Google_Spreadsheets_Settings, 'filter_export_data_settings' ), 40 );

			add_action( 'admin_init', array( new MP_Addon_Google_Spreadsheets_Settings, 'register' ) , 40);

			add_action( 'admin_menu', array( $this, 'add_google_spreadsheets_addon' ), 50 );

			add_action( 'init', array(new MP_Addon_Google_Spreadsheets, 'decode_state'), 9 );

			if (!empty(get_option(MortgagePlatform::$prefix . 'google_sheet_access_token'))){
				add_action( 'add_meta_boxes', array( new MP_Addon_Google_Spreadsheets_Settings, 'google_spreadsheet_metabox' ), 20 );
				add_filter(MortgagePlatform::$prefix . 'add_connectors', array(new MP_Addon_Google_Spreadsheets_Settings, 'export_to_google_spreadsheets'));
				add_action(MortgagePlatform::$prefix . 'connector', array( new MP_Addon_Google_Spreadsheets, 'send_google_spreadsheets_manually' ));

			}

			add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );

			add_action( 'wp_ajax_google_revoke_token', array( new MP_Addon_Google_Spreadsheets, 'revoke_token' ) );
			add_action( 'wp_ajax_google_spreadsheet_send', array( new MP_Addon_Google_Spreadsheets, 'google_send_from_lead_page' ) );


		}

		/**
		 * Activate plugin.
		 * @since  1.0.0
		 * @access public
		 */
		public function activate() {

			flush_rewrite_rules();

			MP_Addon_Google_Spreadsheets_Settings::default_settings();

		}


		/**
		 * Deactivate plugin.
		 * @since  1.0.0
		 * @access public
		 */
		public function deactivate() {

			flush_rewrite_rules();

		}


		/**
		 * Add Google Spreadsheets add-on on the add-ons page.
		 * @access public
		 * @since  1.0.0
		 */
		public function add_google_spreadsheets_addon() {

			add_filter( 'mortgage_platform_addon_page', array( $this, 'addon_template' ) );

		}


		/**
		 * Google Spreadsheets add-on template.
		 * @access public
		 * @since  1.0.0
		 */
		public function addon_template() {
			?>
            <div class="mortgage-calculator-addon">
                <h3><?php echo esc_html__( 'Google Spreadsheets add-on', 'CalculatorsGoogleSpreadSheetsAddon' ); ?></h3>
                <p><?php echo esc_html__( 'Description', 'CalculatorsGoogleSpreadSheetsAddon' ); ?></p>
                <a href="#"
                   class="addon"><?php echo esc_html__( 'install add-on', 'CalculatorsGoogleSpreadSheetsAddon' ); ?></a>
            </div>
			<?php
		}


		/**
		 * Enqueue admin scripts.
		 * @access public
		 * @since  1.0.0
		 */
		public function enqueue_admin_scripts( $hook ) {
			if ( ('toplevel_page_mortgage_platform' === $hook && 'mortgage_platform' === $_GET['page'] && isset($_GET['tab']) && 'google_sheet' === $_GET['tab'] ) || 'post.php' === $hook) {
				wp_enqueue_script( 'addon_google_sheeets_admin', plugins_url( 'assets/js/google-sheets-admin.js', __FILE__ ), array( 'jquery' ), '1.0.0', true );
			}
		}

	}

Top ↑

Methods Methods


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.