Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme Update Mechanism Not Working as Expected #587

Open
CrazyVinc opened this issue Jan 9, 2025 · 7 comments
Open

Theme Update Mechanism Not Working as Expected #587

CrazyVinc opened this issue Jan 9, 2025 · 7 comments

Comments

@CrazyVinc
Copy link

CrazyVinc commented Jan 9, 2025

Issue: Update Mechanism Not Working as Expected for Theme

We are using GitHub to host both our WordPress themes and plugins, and we rely on GitHub releases for production and commits for our beta environments. While the update mechanism works perfectly for our plugin, we are encountering issues with the theme's update process.

Current Implementation:

We are using a child theme (lofftrum), and the update mechanism code is implemented in the functions.php file of the child theme. Below is the code that we have placed in the top of our file:

<?php 
// UPDATE MECHANISM
require_once 'inc/plugin-update-checker/plugin-update-checker.php';

use YahnisElsts\PluginUpdateChecker\v5\PucFactory;

$updater = PucFactory::buildUpdateChecker('https://github.com/Isodeco/WPTheme', __FILE__, 'lofftrum', 24);
$updater->setBranch('main');

if (in_array($_SERVER['HTTP_HOST'], ['staging.isodeco.nl', 'beta.isodeco.nl'])) {
    $updater->addFilter('vcs_update_detection_strategies', function ($strategies) {
        unset($strategies['stable_tag']);
        unset($strategies['latest_tag']);
        unset($strategies['latest_release']);
        return $strategies;
    });
}

$updater->setAuthentication('(HIDDEN FOR SECURITY)');

Additional Details:

  • Child Theme: The update mechanism is part of the child theme's functions.php.
  • Shared Authentication: We are using the same GitHub authentication key for both our plugin and theme.
  • Plugin Functionality: The plugin's update mechanism is functioning correctly, so the issue seems isolated to the theme.

Issue Details:

  1. Expected Behavior:

    • Updates should be fetched from GitHub releases for production environments.
    • Updates should be fetched from commits for staging/beta environments.
  2. Observed Behavior:

    • The theme does not fetch updates as expected, even though the plugin works with the same configuration and authentication key.
  3. Environment Details:

    • Staging/Beta: staging.isodeco.nl, beta.isodeco.nl
    • Production: Standard release mechanism through main branch.

Steps Taken:

  • Verified the repository URL and branch settings for the theme.
  • Confirmed the GitHub personal access token (PAT) is valid by testing with the plugin.
  • Temporary updated update_detection_strategies to prioritize commits always.

Questions/Help Needed:

  • Are there any considerations specific to child themes that could be causing the update mechanism to fail?
  • Could the placement of the code in functions.php of the child theme impact its functionality?
  • Are there debugging steps or additional configurations we might have missed?
@YahnisElsts
Copy link
Owner

Are there any considerations specific to child themes that could be causing the update mechanism to fail?

Not as far as I recall.

Could the placement of the code in functions.php of the child theme impact its functionality?

Again, not as far as I recall. As long as the code actually runs, and it runs reasonably early (e.g. before update-related hooks), and the arguments passed to buildUpdateChecker() are correct, it shouldn't matter where that code is placed.

Are there debugging steps or additional configurations we might have missed?

What do you mean by "the theme does not fetch updates as expected"? I'm guessing that it means that updates don't show up at all, but I wanted to clarify in case it's something like "updates are being fetched from the wrong place in the repository".

One debugging step I would recommend is to install the Debug Bar plugin and look at the "PUC (lofftrum)" panel in that plugin. Does all the information there look correct for your theme? If you click the "Check Now" button, what do you get as the result?

@CrazyVinc
Copy link
Author

CrazyVinc commented Jan 9, 2025

When i look at Debug Bar in PUC (lofftrum) i don't get anything, it is just a white screen.

@YahnisElsts
Copy link
Owner

Probably a PHP error then, or - less likely - a JS error. Please check the PHP error log for recent fatal errors. If there's nothing there, check the browser console for JS errors before/after you try to open that panel.

@CrazyVinc
Copy link
Author

There was indeed an error where the debug-bar.js file was forbidden. We have fixed it, and debug bar now indicates that there is an update. However, the next problem is that WordPress does not show that there is an update.

@YahnisElsts
Copy link
Owner

Here are a few more things to check:

  • Is the "Theme directory" correct? This is used to add the update to the update list, and the update might not show up if this value is wrong.
  • Does the "Checked version" field in the "Status" section match the actual installed version of the theme? PUC uses the installed version number when deciding whether to show an update. Unfortunately, the Debug Bar panel doesn't show the installed version as such, but "Checked version" should be the same as the installed version unless you've changed the version number since the last update check.
  • If you're checking the theme list to see if the update is showing up, also check "Dashboard -> Updates". Certain configuration issues can cause an update to show up in one place but not the other.

@CrazyVinc
Copy link
Author

We've checked the following:

  1. Theme Directory
    We noticed that the theme directory was initially set to lofftrum instead of lofttrum. While correcting it to lofttrum was a necessary step, it unfortunately didn’t resolve the issue.

  2. Checked Version
    We confirmed that the Checked Version field in the Debug Bar panel matches the installed version of the theme:

  • Checked Version: 1.1.0
  • Available Update Version: 1.1.1

The update is detected and visible in the Debug Bar under the "An Update Is Available" section. Here’s the relevant Debug Bar output for reference:

Configuration

  • Theme Directory: lofttrum
  • Slug: lofttrum
  • DB Option: puc_external_updates_theme-lofttrum
  • Metadata URL: https://github.com/Isodeco/WPTheme
  • Automatic checks: Every 1 hours
  • Throttling: Disabled
  • Branch: master
  • Authentication Enabled: Yes
  • API Client: YahnisElsts\PluginUpdateChecker\v5p5\Vcs\GitHubApi

Status

  • Checked Version: 1.1.0
  • Cached Update:
    YahnisElsts\PluginUpdateChecker\v5p5\Theme\Update Object
    (
        [slug] => lofttrum
        [version] => 1.1.1
        [download_url] => https://api.github.com/repos/Isodeco/WPTheme/zipball/master
        [details_url] => https://github.com/Isodeco/WPTheme
    )

An Update Is Available

  1. Dashboard and Updates Page
    The update does not appear in any place.

@YahnisElsts
Copy link
Owner

Hmm, all of that looks fine. I don't know why it wouldn't work.

At this point, if I had access to the code, I would probably start adding some debug output or breakpoints to injectUpdate() and related functions to see if it's being called on the "Dashboard -> Updates" page and what exactly is going on in there. Unfortunately, I currently can't think of any useful debugging steps that don't require that sort of thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants