key = 'dfrapi_import'; add_action( 'admin_init', array( $this, 'register_settings' ) ); add_action( 'admin_menu', array( $this, 'admin_menu' ), 60 ); 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 '
' . __( '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