wordpress/wp-content/plugins/widget-css-classes/includes/widget-css-classes-settings.class.php
/**
	 * @todo Move to separate class or split in different methods.
	 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
	 * @SuppressWarnings(PHPMD.NPathComplexity)
	 */
@todo Move to separate class or split in different methods.
@todo Move to separate class or split in different methods .
public function register_importexport_settings() {
		if ( ! current_user_can( 'manage_options' ) ) {
			return;
		}
		$get = $_GET; $post = $_POST;
		$this->plugin_tabs['importexport'] = esc_attr__( 'Import/Export', WCSSC_Lib::DOMAIN );
		$wcssc_message_class = '';
		$wcssc_message       = '';
		if ( isset( $get['wcssc_message'] ) ) {
			switch ( $get['wcssc_message'] ) {
				case 1:
					$wcssc_message_class = 'updated';
					$wcssc_message       = esc_attr__( 'Settings Imported', WCSSC_Lib::DOMAIN );
					break;
				case 2:
					$wcssc_message_class = 'error';
					$wcssc_message       = esc_attr__( 'Invalid Settings File', WCSSC_Lib::DOMAIN );
					break;
				case 3:
					$wcssc_message_class = 'error';
					$wcssc_message       = esc_attr__( 'No Settings File Selected', WCSSC_Lib::DOMAIN );
					break;
			}
		}
		if ( ! empty( $wcssc_message ) ) {
			echo '<div class=" ' . esc_attr( $wcssc_message_class ) . ' "><p>' . esc_html( $wcssc_message ) . '</p></div>';
		}
		if ( isset( $get['widget-css-classes-settings-export'] ) ) {
			header( 'Content-Disposition: attachment; filename=widget-css-classes-settings.txt' );
			header( 'Content-Type: text/plain; charset=utf-8' );
			$general = get_option( 'WCSSC_options' );
			echo "[START=WCSSC SETTINGS]\n";
			foreach ( $general as $id => $text ) {
				 >> wp_json_encode is WP 4.1+
				echo "$id\t" . json_encode( $text ) . "\n";
			}
			echo '[STOP=WCSSC SETTINGS]';
			exit;
		}
		if ( isset( $post['widget-css-classes-settings-import'] ) ) {
			$wcssc_message = 3;
			if ( $_FILES['widget-css-classes-settings-import-file']['tmp_name'] ) {
				$wcssc_message = 2;
				$import        = explode(
					"\n",
					 >> yeah yeah, I know...
					file_get_contents( $_FILES['widget-css-classes-settings-import-file']['tmp_name'] )
				);
				if ( array_shift( $import ) === '[START=WCSSC SETTINGS]' && array_pop( $import ) === '[STOP=WCSSC SETTINGS]' ) {
					$options = WCSSC_Lib::get_settings();
					foreach ( $import as $import_option ) {
						list( $key, $value ) = explode( "\t", $import_option );
						$options[ $key ] = json_decode( sanitize_text_field( $value ) );
						if ( $options['dropdown'] ) { 
							$options['defined_classes'] = $options['dropdown'];
							unset( $options['dropdown'] );
						}
					}
					WCSSC_Lib::update_settings( $options );
					$wcssc_message = 1;
				}
			}
			wp_safe_redirect( admin_url( '/options-general.php?page=widget-css-classes-settings&tab=importexport&wcssc_message=' . esc_attr( $wcssc_message ) ) );
			exit;
		}
	}
public function register_importexport_settings ( ) { if ( ! current_user_can ( 'manage_options' ) ) { return ; } $ get = $ _GET ; $ post = $ _POST ; $ this -> plugin_tabs [ 'importexport' ] = esc_attr__ ( 'Import/Export' , WCSSC_Lib :: DOMAIN ) ; $ wcssc_message_class = '' ; $ wcssc_message = '' ; if ( isset ( $ get [ 'wcssc_message' ] ) ) { switch ( $ get [ 'wcssc_message' ] ) { case 1 : $ wcssc_message_class = 'updated' ; $ wcssc_message = esc_attr__ ( 'Settings Imported' , WCSSC_Lib :: DOMAIN ) ; break ; case 2 : $ wcssc_message_class = 'error' ; $ wcssc_message = esc_attr__ ( 'Invalid Settings File' , WCSSC_Lib :: DOMAIN ) ; break ; case 3 : $ wcssc_message_class = 'error' ; $ wcssc_message = esc_attr__ ( 'No Settings File Selected' , WCSSC_Lib :: DOMAIN ) ; break ; } } if ( ! empty ( $ wcssc_message ) ) { echo '<div class=" ' . esc_attr ( $ wcssc_message_class ) . ' "><p>' . esc_html ( $ wcssc_message ) . '</p></div>' ; } if ( isset ( $ get [ 'widget-css-classes-settings-export' ] ) ) { header ( 'Content-Disposition: attachment; filename=widget-css-classes-settings.txt' ) ; header ( 'Content-Type: text/plain; charset=utf-8' ) ; $ general = get_option ( 'WCSSC_options' ) ; echo " [START=WCSSC SETTINGS] \n " ; foreach ( $ general as $ id => $ text ) { echo " $ id \t " . json_encode ( $ text ) . " \n " ; } echo '[STOP=WCSSC SETTINGS]' ; exit ; } if ( isset ( $ post [ 'widget-css-classes-settings-import' ] ) ) { $ wcssc_message = 3 ; if ( $ _FILES [ 'widget-css-classes-settings-import-file' ] [ 'tmp_name' ] ) { $ wcssc_message = 2 ; $ import = explode ( " \n " , file_get_contents ( $ _FILES [ 'widget-css-classes-settings-import-file' ] [ 'tmp_name' ] ) ) ; if ( array_shift ( $ import ) === '[START=WCSSC SETTINGS]' && array_pop ( $ import ) === '[STOP=WCSSC SETTINGS]' ) { $ options = WCSSC_Lib :: get_settings ( ) ; foreach ( $ import as $ import_option ) { list ( $ key , $ value ) = explode ( " \t " , $ import_option ) ; $ options [ $ key ] = json_decode ( sanitize_text_field ( $ value ) ) ; if ( $ options [ 'dropdown' ] ) { $ options [ 'defined_classes' ] = $ options [ 'dropdown' ] ; unset ( $ options [ 'dropdown' ] ) ; } } WCSSC_Lib :: update_settings ( $ options ) ; $ wcssc_message = 1 ; } } wp_safe_redirect ( admin_url ( '/options-general.php?page=widget-css-classes-settings&tab=importexport&wcssc_message=' . esc_attr ( $ wcssc_message ) ) ) ; exit ; } }
@todo Move to separate class or split in different methods.
@todo Move to separate class or split in different methods .
// @codingStandardsIgnoreLine // export settings // @codingStandardsIgnoreLine >> wp_json_encode is WP 4.1+ // import settings // @codingStandardsIgnoreLine >> yeah yeah, I know... // Update for 1.3.0