<?php

// WordPress 2.8+
$wp_version = get_bloginfo('version');
if ( version_compare( $wp_version, '2.8', '<' ) ) {
	function esc_attr( $text ) {
		return $text;
	}

	function esc_html( $text ) {
		return $text;
	}

	if ( ! function_exists('get_preferred_from_update_core') ) {
		require_once(ABSPATH . 'wp-admin/includes/update.php');
	}
}

// WordPress 2.9+
if ( version_compare( $wp_version, '2.9', '<' ) ) {
	function get_site_transient( $name ) {
		switch ($name) {
			case 'update_core' :
				$obj = new stdClass();
				$obj->version_checked = $GLOBALS['wp_version'];
				$obj->updates = array( get_preferred_from_update_core() );
				return $obj;
				break;
			case 'update_plugins' :
			case 'update_themes' :
				return false;
				break;
		}
	}
}

// WordPress 3.0+
if ( version_compare( $wp_version, '3.0', '<' ) ) {
	function get_site_url() {
		return get_option('siteurl');
	}
}

// WordPress 3.1+
if ( version_compare( $wp_version, '3.1', '<' ) ) {
	function get_current_screen() {
		$current_screen = new stdClass();
		$current_screen->id = isset($_GET['page']) ? mysql_real_escape_string($_GET['page']) : '';
		if ( $current_screen->id === '') return null;
		return $current_screen;
	}

	function submit_button( $text = null, $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = null ) {
		echo get_submit_button( $text, $type, $name, $wrap, $other_attributes );
	}

	function get_submit_button( $text = null, $type = 'primary large', $name = 'submit', $wrap = true, $other_attributes = null ) {
	        if ( ! is_array( $type ) )
	                $type = explode( ' ', $type );

	        $button_shorthand = array( 'primary', 'small', 'large' );
	        $classes = array( 'button' );
	        foreach ( $type as $t ) {
	                if ( 'secondary' === $t || 'button-secondary' === $t )
	                        continue;
	                $classes[] = in_array( $t, $button_shorthand ) ? 'button-' . $t : $t;
	        }
	        $class = implode( ' ', array_unique( $classes ) );

	        if ( 'delete' === $type )
	                $class = 'button-secondary delete';

	        $text = $text ? $text : __( 'Save Changes' );

	        // Default the id attribute to $name unless an id was specifically provided in $other_attributes
	        $id = $name;
	        if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) {
	                $id = $other_attributes['id'];
	                unset( $other_attributes['id'] );
	        }

	        $attributes = '';
	        if ( is_array( $other_attributes ) ) {
	                foreach ( $other_attributes as $attribute => $value ) {
	                        $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
	                }
	        } else if ( !empty( $other_attributes ) ) { // Attributes provided as a string
	                $attributes = $other_attributes;
	        }

	        $button = '<input type="submit" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" class="' . esc_attr( $class );
	        $button .= '" value="' . esc_attr( $text ) . '" ' . $attributes . ' />';

	        if ( $wrap ) {
	                $button = '<p class="submit">' . $button . '</p>';
	        }

	        return $button;
	}
}

// WordPress 3.4+
if ( version_compare( $wp_version, '3.4', '<' ) ) {
	function wp_get_themes() {
		return get_themes();
	}
}

// WordPress 3.6+
if ( version_compare( $wp_version, '3.6', '<' ) ) {
	function wp_is_writable( $path ) {
		if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) ) {
			return win_is_writable( $path );
		} else {
			return @is_writable( $path );
		}
	}
}

// WordPress 4.5+
if ( version_compare( $wp_version, '4.5', '<' ) ) {
	function wp_get_upload_dir() {
		return wp_upload_dir( null, false );
	}
}

// WordPress 4.7+
if ( version_compare( $wp_version, '4.7', '<' ) ) {
	function get_user_locale( $user_id = 0 ) {
		$user = false;
		if ( 0 === $user_id && function_exists( 'wp_get_current_user' ) ) {
			$user = wp_get_current_user(); // wp 2.0.3
		} elseif ( $user_id instanceof WP_User ) {
			$user = $user_id;
		} elseif ( $user_id && is_numeric( $user_id ) ) {
			$user = get_user_by( 'id', $user_id ); // requires wp 3.3+
		}

		if ( ! $user ) {
			return get_locale();
		}

		$locale = $user->locale;
		return $locale ? $locale : get_locale();
	}
}

// WordPress 5.3+
if ( version_compare( $wp_version, '5.3', '<' ) ) {
	function wp_timezone_string() {
		return get_option( 'timezone_string' );
	}
}