• Hi!

    Installed AO 2.0.2.
    I’m using custom mobile swithing plugin: it detects mobile browsers and switches to mobile WP theme.
    The problem is: AO works fine on desktop version (http://dev2.kuponarama.ru/) but on mobile (http://m.dev2.kuponarama.ru/) it works only for html and inlined CSS and JS – so it cannot optimize external CSS (for example with URL “/wp-content/themes/mobile/css/all.css”).

    Some theme switching code:

    case "m.dev2.kuponarama.ru":
    			define('WP_HOME', 'http://m.dev2.kuponarama.ru');
    			define('WP_SITEURL','http://m.dev2.kuponarama.ru');
    			//define('WP_CONTENT_URL','http://m.dev2.kuponarama.ru/wp-content');
    			break;

    Changing theme:

    /**
     * @return mobile theme name
     */
    function kuponarama_getMobileTheme() {
    	switch($_SERVER["HTTP_HOST"]) {
    		case "m.kuponarama.ru":
    		case "m.dev.kuponarama.ru":
    		case "m.dev2.kuponarama.ru":
    			return "mobile";
    		case "dev.kuponarama.ru":
    		case "kuponarama.ru":
    		case "www.kuponarama.ru":
    			return "clipper-child";
    	}
    }
    
    function ts_get_template($template) {
    	$theme = kuponarama_getMobileTheme();
    	if (empty($theme)) {
    		return $template;
    	}
    	$theme = ts_get_one_theme($theme);
    	if (empty($theme)) {
    		return $template;
    	}
    	// Don't let people peek at unpublished themes.
    	if (isset($theme['Status']) && $theme['Status'] != 'publish')
    	return $template;
    	return $theme['Template'];
    }
    add_filter('template', 'ts_get_template');
    
    function ts_get_stylesheet($stylesheet) {
    	$theme = kuponarama_getMobileTheme();
    	if (empty($theme)) {
    		return $stylesheet;
    	}
    	$theme = ts_get_one_theme($theme);
    	// Don't let people peek at unpublished themes.
    	if (isset($theme['Status']) && $theme['Status'] != 'publish')
    	return $stylesheet;
    	if (empty($theme)) {
    		return $stylesheet;
    	}
    	return $theme['Stylesheet'];
    }
    add_filter('stylesheet', 'ts_get_stylesheet');
    
    // helper function to replace get_theme()
    function ts_get_one_theme($theme) {
    	$themes = wp_get_themes();
    	if (array_key_exists($theme, $themes))
    	return $themes[$theme];
    	return NULL;
    }

    https://ww.wp.xz.cn/plugins/autoptimize/

Viewing 16 replies (of 16 total)
  • Plugin Author Frank Goossens

    (@futtta)

    frustrating we haven’t been able to get this working! do let me know if you ever find out what was going on!

    I might do some tests with switching themes like that in the future.

    frank

Viewing 16 replies (of 16 total)

The topic ‘Cannot optimize mobile theme’ is closed to new replies.