key = 'dfrapi_import'; add_action( 'admin_init', array( &$this, 'register_settings' ) ); add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_action( 'admin_notices', array( $this, 'admin_notice' ) ); } function admin_menu() { add_submenu_page( 'dfrapi', __( 'Import — Datafeedr API', DFRAPI_DOMAIN ), __( 'Import', DFRAPI_DOMAIN ), 'manage_options', $this->key, array( $this, 'output' ) ); } function admin_notice() { if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true && isset( $_GET['page'] ) && $this->key == $_GET['page'] ) { echo '

'; _e( 'Settings successfully imported!', DFRAPI_DOMAIN ); echo '

'; } } function output() { echo '
'; echo '

' . dfrapi_setting_pages( $this->page ) . ' — Datafeedr API

'; echo '
'; wp_nonce_field( 'update-options' ); settings_fields( $this->page ); do_settings_sections( $this->page); submit_button( __( 'Import Data', DFRAPI_DOMAIN ) ); echo '
'; echo '
'; } function register_settings() { register_setting( $this->page, $this->key, array( $this, 'validate' ) ); add_settings_section( 'import_data', __( 'Import Data', DFRAPI_DOMAIN ), array( &$this, 'section_import_data_desc' ), $this->page ); add_settings_field( 'import_data_textarea', __( 'Data to Import', DFRAPI_DOMAIN ), array( &$this, 'field_import_data_textarea' ), $this->page, 'import_data' ); } function section_import_data_desc() { echo '

' . __( 'Import data from another website when you want to use the same selection of networks and/or merchants as you have already configured on another website.', DFRAPI_DOMAIN ) . '

'; echo '

' . __( 'You can import network and merchant data at the same time.', DFRAPI_DOMAIN ) . '

'; echo '

'; echo '' . __( 'WARNING: ', DFRAPI_DOMAIN ) . ' '; echo __( 'Importing will overwrite all of your current ', DFRAPI_DOMAIN ); echo ' '. __( 'network settings', DFRAPI_DOMAIN ) . ''; echo __( ' and/or ', DFRAPI_DOMAIN ); echo ' '. __( 'merchant settings', DFRAPI_DOMAIN ) . ''; echo '.

'; } function field_import_data_textarea() { echo '

'; echo '

' . __( 'Paste the exported data into the box, then click [Import Data].' ) . '

'; } function validate( $input ) { if ( isset( $input ) && is_array( $input ) && !empty( $input ) ) { foreach( $input as $key => $value ) { if ( $key == 'data' && ( strlen( $value ) > 16 ) ) { $this->import_data( $value ); } } } } function import_data( $value ) { // Import networks preg_match ("/(\[NETWORKS\]).*(\[\/NETWORKS\])/i", $value, $networks); if ( isset( $networks[0] ) ) { $networks = str_replace( array("[NETWORKS]", "[/NETWORKS]"), "", $networks[0]); $networks = trim( $networks ); if ( strlen( $networks ) > 1 ) { update_option( 'dfrapi_networks', unserialize( $networks ) ); } } // Import merchants preg_match ("/(\[MERCHANTS\]).*(\[\/MERCHANTS\])/i", $value, $merchants); if ( isset( $merchants[0] ) ) { $merchants = str_replace( array("[MERCHANTS]", "[/MERCHANTS]"), "", $merchants[0] ); $merchants = trim( $merchants ); if ( strlen( $merchants ) > 1 ) { update_option( 'dfrapi_merchants', unserialize( $merchants ) ); } } } } // class Dfrapi_Import } // class_exists check