0

im working in a plugin in localhost, it works fine in my localhost website im using composer in it but then when i upload it to my website then it trows a fatal error because composer autoload is not working, in the php file with the same name as my plugin i require the vendor autoload, the errors says that the files that i call wiht autoload do not exists i dont know to much about php or composer, i cant understand why in localhost works but not in my online website dont, the vendor file exists, as i saw in the cpanel directory and then i try to upload the same plugin to other local website an it worked fine, the problem is when i upload it to the website this is the error

Fatal error: Uncaught Error: Class 'Inc\Base\CreateOrDropTables' not found in /home/hoteljupiterve/test.hoteljupiterve.com/wp-content/plugins/booking-jupiter/booking-jupiter.php:35 Stack trace: #0 /home/hoteljupiterve/test.hoteljupiterve.com/wp-includes/class-wp-hook.php(286): activate_booking_plugin('') #1 /home/hoteljupiterve/test.hoteljupiterve.com/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array) #2 /home/hoteljupiterve/test.hoteljupiterve.com/wp-includes/plugin.php(465): WP_Hook->do_action(Array) #3 /home/hoteljupiterve/test.hoteljupiterve.com/wp-admin/plugins.php(177): do_action('activate_bookin...') #4 {main} thrown in /home/hoteljupiterve/test.hoteljupiterve.com/wp-content/plugins/booking-jupiter/booking-jupiter.php on line 35

and this is my booking-jupiter.php

<?php

/**
 * @package booking-jupiter
 */
/*
Plugin name: booking-jupiter
Plugin URI: http://localhost/PluginPrueba
Description: plugin de reserva de habitaciones 
Version: 1.0.0
Author: Guillermo Marin
Author URI: https://www.hoteljupiterve.com
License: GPLv2 or later
Text Domain: booking-jupiter
*/

// define el absolute path, lo primero que hay que hacer siempre

if ( ! defined('ABSPATH')) {
    echo 'error bro, el die mato todo ';
    die;
}

// busca a vendor en composer para usar el use y namespase

if ( file_exists( dirname( __FILE__ ) . '/vendor/autoload.php' ) ) {
    require_once dirname( __FILE__ ) . '/vendor/autoload.php';
}

// activo y desactivo el plugin de manera procedural, es la forma en la que pide wordpress

function activate_booking_plugin()
{
    Inc\Base\CreateOrDropTables::create_all_tables();
    Inc\Base\CreateClient::create_client_role();
    // (new Inc\Base\CreateOrDropTables())->create_all_tables();
}

function deactivate_bookin_plugins()
{
    Inc\Base\DeactivateBooking::deactivate();
}

// ya cree las funciones y bueno estos metodos de wordpress hacen el trabajo
register_activation_hook( __FILE__, 'activate_booking_plugin' );
register_deactivation_hook( __FILE__, 'deactivate_bookin_plugins' );


// busca si exite la clase Init para darle con el registerservices y asi que todos los demas se inicialicen perro
if ( class_exists( 'Inc\\Init' ) ) {
    Inc\Init::register_services();
}

thats all my booking-jupiter.php, i cant activate the plugin because of that error and if use require once to the CreateOrDropTables when i try the same with the Inc/init.php. it says that the class do no exists

i just try to eliminate the vendor folder and composer.json file from the cpanel an then i did install composer from the cpanel to my plugin folder, i didnt work i got the same error

  • Did you try to contact Composer Community for help? I think they are more details in this area. – simongcc Apr 16 at 2:17
  • no, but now im gonna do it, thanks! – Guillermo Marin Apr 16 at 2:20
  • Are you uploading all the contents of the vendor/ directory? In composer it's common to exclude that directory from version control, but the folder will need to be inside the plugin files to work in WordPress. – Jacob Peattie Apr 16 at 2:43
  • yes, im uploading all the contents of the vendor/ directory, any other suggestion? im new so i can make some mistakes – Guillermo Marin Apr 16 at 3:13
  • What error messages? Please edit your question and provide all steps to reproduce. – leymannx Apr 16 at 8:46
0

sorry i got the solution but never posted here, i got errors because of case sensitive with my folders, i dont know why in localhost i got no error but in my website i got the folder inc and then i got the "Inc\Base" inc !== "Inc" my bad a stupid error, thanks for all who answered

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.