By bula
WordPress themes are typically submitted to the review team to be hosted and published on the WordPress Theme Directory. We are working on an internal theme that will not work outside of our use case. It is also developed and managed using git and hosted on our Digital Ocean droplet.
How can we use our self-hosted, git-managed WordPress theme and have it behave like a normal theme would? For example, WordPress detects when the theme needs to be updated and the theme is auto-updated. If auto-updating is disabled, then it should wait till the update link is clicked manually.
I have begun with creating a --bare repo on our droplet with ssh authentication. I have also attempted to create a php class in the theme that cross checks the active theme’s version with the git repo but have unsuccessful in doing so. I did find some articles that have some good info but always ends up using a service or plugin to handle the pushing. If at all possible, we would like to accomplish this without 3rd party services or plugins.
I have broken out what I think needs to happen in the following steps:
I was able to get the current theme version by using wp_get_theme() and then retrieving the version property. I am hoping to use the same function to check the theme on in the git repo but I hit a wall trying to retrieve the git repo. I am not sure how to retrieve the git repo, and once it is retrieved, how would I decode it from the bare git data. Also to clarify, we are not using Github or any other service to manage our git repo. Our WordPress install is currently setup on my local environment (wp-env) as I have not yet deployed it to a server. We are planning on deploying it on a FreeBSD distribution with Nginx.
<?php
class Dnk_Webos_Version_Check {
protected $file;
protected $theme;
protected $version;
public function __construct( $file ) {
$this->file = $file;
$this->theme = wp_get_theme();
$this->version = $this->theme->version;
// Debug test
add_action( 'admin_notices', array( $this, 'debug_notice' ) );
}
public function debug_notice() {
$debug = esc_html( $this->theme );
?>
<div class="notice notice-success is-dismissible">
<p><?php echo $this->version; ?></p>
</div>
<?php
}
}
?>
Local Environment WordPress 5.8 PHP 7.4.21 Apache/2.4.38 (Debian) Linux 5.10.25-linuxkit x86_64
Git Server FreeBSD 12.2 zfs x64
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there,
I believe that the most straightforward way to do this is by using this GitHub updater here:
https://github.com/afragen/git-updater
This plugin is designed to update any GitHub hosted WordPress plugin or theme. Your plugin or theme must contain a header in the style.css header or in the plugin’s header denoting the location on GitHub.
Regards, Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.