admin管理员组文章数量:1426188
I'm using wp_remove_get
to get the WordPress theme style content (style.css) and then get the theme version number. However I don't know exactly what regex I should use to get the version code:
<?php
$response = wp_remote_get( '.css' );
if( is_array($response) ) {
$content = $response['body']; // Remote get the file content. Now get the version number in $content.
}
?>
Also I'm going to get the version of about 20 themes (sites) on the same page, what I need to do to decrease the page load?
Thanks.
I'm using wp_remove_get
to get the WordPress theme style content (style.css) and then get the theme version number. However I don't know exactly what regex I should use to get the version code:
<?php
$response = wp_remote_get( 'http://example/wp-content/themes/theme-name/style.css' );
if( is_array($response) ) {
$content = $response['body']; // Remote get the file content. Now get the version number in $content.
}
?>
Also I'm going to get the version of about 20 themes (sites) on the same page, what I need to do to decrease the page load?
Thanks.
Share Improve this question edited Nov 1, 2015 at 16:41 jas 1,52511 silver badges23 bronze badges asked Nov 1, 2015 at 15:42 Thomas W.Thomas W. 1 3- What you're doing is inherently expensive/slow, but you should focus on how to do it in this question, and ask follow up questions in new questions once you've got an answer. Of note, regex should be unnecessary, WP already has code to do this in Core – Tom J Nowell ♦ Commented Nov 1, 2015 at 19:16
- What does "20 themes (sites) on the same page" mean? Is this multisite? – s_ha_dum Commented Nov 1, 2015 at 20:07
- It's a theme listing page, no multisite – Thomas W. Commented Nov 3, 2015 at 1:52
3 Answers
Reset to default 0Please check out this answer to a similar question about regex for getting info from the theme's style.css
.
When it comes to the second part of your question - if you are concerned about page load times, you could always use AJAX to get the information about each theme separately. You would display the page with all themes listed but without their version numbers at first. Once the page is loaded, you could send an AJAX request to wp-admin for each theme, process the information on the backend (get the theme's CSS, run regex to find version number) and formulate a response with the theme's version number. Display the version number on your page and you are done! Repeat for every theme on your list.
You can grab the version number like this:
preg_match('/[\n\r].*Version:\s*([^\n\r]*)/', $content, $matches);
$ver = $matches[1];
Do you have control over the theme?
If you do, you can create a file inside your theme, called version.php
for example, and add the following code -
<?php
header("Access-Control-Allow-Origin: https://www.example");
$parse_uri = explode('wp-content', $_SERVER['SCRIPT_FILENAME']);
require $parse_uri[0] . 'wp-load.php';
$currentTheme = wp_get_theme();
echo json_encode($currentTheme->get('Version'));
You can also get the theme name -
echo json_encode($currentTheme->get('Version'));
You can then use PHP or (better) JavaScript to access the version.php
on each site and get the theme version. Use promises or async()
/await()
to get hundreds of themes on the same page.
本文标签: wp remote getRemotely get WordPress theme version
版权声明:本文标题:wp remote get - Remotely get WordPress theme version 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745393784a2656721.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论