YahnisElsts / plugin-update-checker

A custom update checker for WordPress plugins. Useful if you don't want to host your project in the official WP repository, but would still like it to support automatic updates. Despite the name, it also works with themes.
MIT License
2.26k stars 410 forks source link

not working for themes #387

Closed masoudarvishi closed 4 years ago

masoudarvishi commented 4 years ago

Hello.

i use this code:

if (!class_exists('Puc_v4_Factory')) { require_once(get_template_directory(). 'plugin-update-checker/plugin-update-checker.php' ); } $UpdateChecker = Puc_v4_Factory::buildUpdateChecker( 'http://myserver.co/?action=get_metadata&slug=tia20', FILE, 'tia20' );

but when refresh mywebsite (in localhost) showing this error:

RuntimeException: The update checker cannot determine if "C:/wamp64/www/myweb/wp-content/themes/tia20/plugin-update-checker/plugin-update-checker.php" is a plugin or a theme. This is a bug. Please contact the PUC developer. in C:\wamp64\www\myweb\wp-content\themes\tia20\plugin-update-checker\Puc\v4p10\Factory.php on line 80

I easily provided this feature for plugins. But I have this problem in themes!

YahnisElsts commented 4 years ago

Judging by the file name in the error message, your code might be inside the plugin-update-checker.php file. Is that true? If yes, then you will need to either move the code to a different file that's in the theme's root directory (e.g. functions.php) or replace __FILE__ with the full path to the theme directory.

For themes, the second argument passed to buildUpdateChecker() must be the full path to the theme directory (or a file that's immediately inside that directory), so the __FILE__ constant will only work if the code that calls buildUpdateChecker() is in functions.php or another top-level file.

masoudarvishi commented 4 years ago

Thanks. Yes the file path is correct. Can you provide me with a sample code? I did not catch

masoudarvishi commented 4 years ago

I replaced this code __FILE__ use get_template_directory() but not work.

YahnisElsts commented 4 years ago

What happens when you use get_template_directory()? Do you still get the exact same error message or something different?

Can you provide me with a sample code?

Any sample code that I could provide would look pretty much the same as your current code except for the function arguments. Unfortunately, I can't provide the correct arguments because they will be different for every theme.

masoudarvishi commented 4 years ago

No no error is given. You fixed the error and I put the codes in a separate file.

I put the code in the theme function file, it worked fine. But I put the code in another file, it does not work and does not give any errors. I think the problem is from __FILE__ I do not know what to put in place of this __FILE__

masoudarvishi commented 4 years ago

i use code in funtctions.php theme:

if (!class_exists('Puc_v4_Factory')) {
require_once(get_template_directory(). 'plugin-update-checker/plugin-update-checker.php' );
}
$UpdateChecker = Puc_v4_Factory::buildUpdateChecker(
'http://myserver.co/?action=get_metadata&slug=tia20',
FILE,
'tia20'
);

is worked!

But I want to put this code in another file.

masoudarvishi commented 4 years ago

I put the above code in this file. I created this file myself. I put this file in the theme function

if (!class_exists('Puc_v4_Factory')) {
    require_once(get_template_directory(). 'plugin-update-checker/plugin-update-checker-url.php' );
}

have put this code in the file (plugin-update-checker-url.php) as well:

if (!class_exists('Puc_v4_Factory')) {
require_once(get_template_directory(). 'plugin-update-checker/plugin-update-checker.php' );
}
$UpdateChecker = Puc_v4_Factory::buildUpdateChecker(
'http://myserver.co/?action=get_metadata&slug=tia20',
FILE,
'tia20'
);
YahnisElsts commented 4 years ago

This may sound like a silly question, but if there is no error when you use get_template_directory() instead of __FILE__, how do you know that the code isn't working?

One way to work around the problem might be to define a new file name constant in functions.php and then use that in your other file. For example, do this in functions.php:

define('MY_THEME_FUNCTIONS_PHP', __FILE__);

Then use the new constant in plugin-update-checker-url.php:

$UpdateChecker = Puc_v4_Factory::buildUpdateChecker(
    'http://myserver.co/?action=get_metadata&slug=tia20',
    MY_THEME_FUNCTIONS_PHP,
    'tia20'
);

Of course, MY_THEME_FUNCTIONS_PHP is just an example name and I would recommend replacing it with something more unique.

masoudarvishi commented 4 years ago

thank you very much. The problem was solved. thank you.

masoudarvishi commented 4 years ago

How can I hide the download link? After the update operation, by clicking on the update details, the download link will be displayed. This is very bad!

masoudarvishi commented 4 years ago

i use md5, but not work.

link http://myserver.co/?action=get_metadata&slug=tia20 convert to bcb00107d4d5c64e2364cb8dcb1fa9a9.

https://www.md5hashgenerator.com/

After this, the update will no longer be displayed

YahnisElsts commented 4 years ago

Do you want the user to be able to install the update? Then their server must have the update link (or at least have a way to generate the link, which is effectively the same as having the link). And if the user's server has the link then the user can get the link, too.

If you want to prevent people from reusing download links, you could modify the update server to require a license key and/or provide time-limited links. However, all of that is beyond the scope of this discussion.

masoudarvishi commented 4 years ago

https://ibb.co/16rXf60

masoudarvishi commented 4 years ago

I do not want the user to be able to see the link during the update! I want the link to be hidden

YahnisElsts commented 4 years ago

I don't know how to do that, at least not off the top of my head. Also, I wouldn't recommend spending too much time on that because it would be pretty useless from a security perspective - a skilled user would be able to get the link anyway.

masoudarvishi commented 4 years ago

tnx.

YahnisElsts commented 4 years ago

All right then, I'll close this now.