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

Text Domain vs Slug #125

Open
stingray82 opened this issue Sep 20, 2024 · 6 comments
Open

Text Domain vs Slug #125

stingray82 opened this issue Sep 20, 2024 · 6 comments

Comments

@stingray82
Copy link

Is it possible to make the update checker check both slug and text domain? I've tried a htaccess redirect from one to the other but that works for a browser but not for the server is it possible to modify it to do both? so as an example

Example:
Bones-plugin.zip is checked and returned even if it is looking for bones.zip?

any suggestions would be appreciated

@stingray82
Copy link
Author

I think I've done this, I still need to test thoroughly. I've added a custom-plugin-handler.php in the root directory, and modified the includes/Wpup/UpdateServer.php I have forked and uploaded here if someone else wants this https://github.com/stingray82/wp-update-server

@YahnisElsts
Copy link
Owner

FWIW, I did look at the fork but couldn't figure out what it has to do with the text domain (the code doesn't mention "domain" or "language"), so I don't have any useful suggestions for this issue. I guess if it works 🤷

@stingray82
Copy link
Author

Maybe I did a poor job of explaining it, I have some plugins which when looking on the server look for Pluginname.zip and actually there folder and basic structure is actually pluginname-plugin.zip, this wasn't an issue when I was pushing and uploading them all manually but has been an issue when I added some automation, so new versions are pushed downloaded, zipped and uploaded to my custom repo it was causing me issues with updates

$custom_plugins = array( 'my-custom' => array( 'zip_path' => __DIR__ . '/packages/my-custom-plugin.zip', 'main_file' => 'my-custom-plugin/my-custom-plugin.php', ), );

@YahnisElsts
Copy link
Owner

Hmm, if the slug => filename conversion is predictable, you might also be able to implement this by changing the findPackage method. The current implementation looks for slug.zip, but technically you could pass any valid ZIP filename to the package loader callback. This way you might not need to manually list every custom plugin. However, that's just an alternative idea.

@stingray82
Copy link
Author

I will look into that anything that makes it super easy to maintain I am up for so will definitely take a look at that

@stingray82
Copy link
Author

stingray82 commented Sep 22, 2024

Thanks for that its much more efficient and allows me to just add any new ones there, code is below in case its of use to anyone else, still testing it but it appears to be working;
` //Stingray82 Modification
protected function findPackage($slug) {
// Sanitize the slug to ensure it's safe for file handling
$safeSlug = preg_replace('@[^a-z0-9\-_\.,+!]@i', '', $slug);

// Define an array of possible modifiers for the filename
$modifiers = array(
    '',            // Standard slug.zip
    '-plugin',     // slug-plugin.zip
	'-tweaks-and-updates', // Tweak files
    // Add more modifiers here as needed
);

// Loop through each modifier and attempt to find the corresponding ZIP file
foreach ($modifiers as $modifier) {
    $filename = $this->packageDirectory . '/' . $safeSlug . $modifier . '.zip';

    // Log the attempt to find the file
    //error_log("Looking for package file: " . $filename); // Only needed for error handling

    // If the file is found and readable, return it
    if (is_file($filename) && is_readable($filename)) {
        return call_user_func($this->packageFileLoader, $filename, $slug, $this->cache);
    }
}

// If no files are found, return null
return null;

}
//End Stingray82 Modification`

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