Closed mehdi-najaran closed 10 months ago
Of course. You just need to adjust your initialization code to pass the correct file path (i.e. the full path to the main plugin file) to the update checker since using __FILE__
will no longer work.
Can you provide me with a sample code?
Not in a useful way. The actual code will depend on how your plugin is set up and what you're using to pass in the plugin file path. You could define a custom constant in your main plugin file and replace __FILE__
with that, or have the initialization code in a class and pass the path via dependency injection, or something else.
Yes, you are right, but I will do anything. I face an error
Please provide me with a simple code sample for this issue, or send me another communication method such as Telegram so that I can communicate with you there.
Please post your current code and the error.
This was the code that I had previously put in the main file of the plugin:
function auto_update_setup()
{
require(plugin_dir_path(__FILE__) . '/include/update-checker/plugin-update-checker.php');
$checkerClass = 'YahnisElsts\\PluginUpdateChecker\\v5\\PucFactory';
if (class_exists($checkerClass)) {
$UpdateChecker = $checkerClass::buildUpdateChecker(
'https://my-site.com/main.json',
__FILE__,
'my-slug'
);
}
}
add_action('plugins_loaded', 'auto_update_setup');
Now I want to put the code in the include folder and include_once in the main file Please give me the new code
function auto_update_setup()
{
require(plugin_dir_path(__FILE__) . '/update-checker/plugin-update-checker.php');
$checkerClass = 'YahnisElsts\\PluginUpdateChecker\\v5\\PucFactory';
if (class_exists($checkerClass)) {
$UpdateChecker = $checkerClass::buildUpdateChecker(
'https://my-site.com/main.json',
__FILE__,
'my-slug'
);
}
}
add_action('plugins_loaded', 'auto_update_setup');
I changed it myself, but it didn't work
As I mentioned, perhaps you might consider using a constant to pass the plugin file name to the code. In your main plugin file:
define('MY_MAIN_PLUGIN_FILE', __FILE__);
Then in your auto_update_setup()
function, replace __FILE__
with MY_MAIN_PLUGIN_FILE
. (Of course, it's recommended to replace MY_MAIN_PLUGIN_FILE
with a unique name to avoid plugin conflicts.)
thank you . The problem was solved ❤️
Is there a way to call this project in a file other than the plugin core?
For example, create a file in the include folder. And that file will be include_once