Support » Fixing WordPress » Class not found after uploading from localhost to website

  • Hello Guys,
    I’ve got a problem with my plugin after uploading to website, everything is ok on my local wamp server but after uploading when I try to activate the plugin these errors appear:

    Fatal error: Uncaught Error:
    Class 'Inc\Base\Activate' not found in /home/vahidsapp/public_html/wp-content/plugins/aa-test/aa-test.php:34 
    Stack trace: #0 /home/vahidsapp/public_html/wp-includes/class-wp-hook.php(286): activate_aa_test('') 
    #1 /home/vahidsapp/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array) 
    #2 /home/vahidsapp/public_html/wp-includes/plugin.php(465): WP_Hook->do_action(Array) 
    #3 /home/vahidsapp/public_html/wp-admin/plugins.php(177): do_action('activate_aa-tes...') 
    #4 {main} thrown in /home/vahidsapp/public_html/wp-content/plugins/aa-test/aa-test.php on line 34

    I reproduce the problem in an empty plugin with only activate/deactivate classes:

    inc/base/Activate.php :

    <?php
    namespace Inc\Base;
    
    class Activate
    {
        public static function activate()
        {
            flush_rewrite_rules();
        }
    }

    similar for deactivate class.

    and this is the main file on the root plugin folder:

    <?php
    
        /**
         * @package AATest
         */
    
        /*
        Plugin Name: AATest
        Plugin URI: https://test.com
        Description: This is a test
        Version: 1.0.0
        Author: Vahid
        Author URI: https://test.com
        License: GPLv2 or later
        Text Domain: aa-test
        */
    
        if( ! defined('ABSPATH'))
            die;
    
        if( file_exists( dirname(__FILE__) . '/vendor/autoload.php'))
            require_once plugin_dir_path(__FILE__) . '/vendor/autoload.php';
    
    function activate_aa_test()
    {
        Inc\Base\Activate::activate();
    }
    
    function deactivate_aa_test()
    {
        Inc\Base\Deactivate::deactivate();
    }
    
    register_activation_hook(__FILE__, 'activate_aa_test');
    register_deactivation_hook(__FILE__, 'deactivate_aa_test');

    and finally the composer.json

    {
        "name": "azadiapp/aa-test",
        "description": "test",
        "type": "project",
        "license": "GPL",
        "authors": [
            {
                "name": "test",
                "email": "test@test.com"
            }
        ],
        "minimum-stability": "dev",
        "require": {},
        "autoload": {
            "psr-4": {"Inc\\": "./inc"}
        }
    }

    on the website I tried to copy vendor folder also I tried to use composer init, composer install, composer dump-autoload but they didn’t fix the problem.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    It may be your hosted server’s PHP is in dire need of being updated. The PHP could be old enough to not support namespaces o.O

    @bcworkz

    I tried in PHP 7.3.7 and also 7.2.20, same problem …

    PHP 7.3.7 (cli)
    Zend Engine v3.3.7 with the ionCube PHP Loaded + ionCube24 v10.3.7

    • This reply was modified 7 months, 1 week ago by vahid671.

    I found the problem I must add the class map in composer.json

    "require": {},
        "config": {
            "optimize-autoloader": true
        },
        "autoload": {
            "psr-4": {"Inc\\": "./inc"},
            "classmap": ["inc/"]
        }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Class not found after uploading from localhost to website’ is closed to new replies.