• Paul

    (@paulacato)


    Hi,

    We’ve noticed a bug where “Uncaught ReferenceError: Main is not defined at …” which is defined in:

    wp_add_inline_script(
    ASSET_PREFIX . "-ssba",
    sprintf(
    'Main.boot( %s );',
    wp_json_encode( array() )
    )
    );

    We noticed in the client the following:

    <script data-no-instant type="text/javascript" src="https://example.com/wp/wp-content/plugins/simple-share-buttons-adder/js/ssba.js?ver=1719322229" id="simple-share-buttons-adder-ssba-js"></script>
    <script data-no-instant type="text/javascript" id="simple-share-buttons-adder-ssba-js-after">
    /* <![CDATA[ */
    Main.boot( [] );
    /* ]]> */
    </script>

    The script-source had /wp/ behind it, when the plugin is not installed in the /wp/ directory but in another directory.

    So I was wondering if there is a way where I can provide a pull-request with changes ?

    How did i fix it on my part?

    1. in instance.php on line 16 I added:
    define( 'SSBA_PLUGIN_URL', plugin_dir_url( __FILE__ ) );

    2. In php/class-plugin.php I changed the following:

    All /wp-content/plugins/simple-share-buttons-adder/ to SSBA_PLUGIN_URL

    So you get registers like:

    // Line 57:
    wp_register_script(
    ASSET_PREFIX . "-ssba",
    SSBA_PLUGIN_URL . "js/ssba.js",
    array( 'jquery' ),
    filemtime( DIR_PATH . "js/ssba.js" ),
    true
    );

    // Line 77:
    wp_register_style(
    ASSET_PREFIX . "-ssba",
    SSBA_PLUGIN_URL . "css/ssba.css",
    array(),
    filemtime( DIR_PATH . "css/ssba.css" )
    );


    Looking forward for your reply,
    regards,

    Paul – Senior Frontend developer at Acato.nl

Viewing 2 replies - 1 through 2 (of 2 total)
  • I found a github repo, but the plugin there — although the same name is used (not the slug, though), and even links to the official website — is fundamentally different from the code we get from www.ads-software.com

    Independently of Paul, I experienced this error and fixed it by replacing one line;

    file: php/class-plugin.php

    function: register_assets()

    in the first wp_register_scripts call, replace

    "/wp-content/plugins/simple-share-buttons-adder/js/ssba.js",

    with

    plugin_dir_url( __DIR__ ) .'/js/ssba.js',

    Plugin Contributor ShareThis

    (@sharethis)

    Hi Paul,

    Thank you for reaching out and reporting this issue with the “Simple Share Buttons Adder” plugin. We appreciate your detailed explanation and the temporary fix you’ve implemented.

    The error you’re encountering, “Uncaught ReferenceError: Main is not defined,” seems to be due to the incorrect script source path. Your solution to define SSBA_PLUGIN_URL and replace hardcoded paths in the plugin’s PHP files is a good approach to resolving this issue.

    To address your question about providing a pull request, here are the steps you can follow:

    1. Fork the Repository: Go to the plugin’s GitHub repository and fork it to your own GitHub account.
    2. Clone the Repository: Clone the forked repository to your local development environment.
    3. Implement the Fix: Apply the changes you’ve described:
    • Define SSBA_PLUGIN_URL in instance.php.
    • Update the paths in php/class-plugin.php to use SSBA_PLUGIN_URL.
    1. Commit Your Changes: Commit the changes to your local repository with a clear commit message describing the fix.
    2. Push to Your Fork: Push the changes to your forked repository on GitHub.
    3. Create a Pull Request: Go to the original repository and create a pull request from your fork. Provide a detailed description of the changes and how they resolve the issue.

    Here’s a brief outline of the changes for reference:

    instance.php

    // Line 16
    define('SSBA_PLUGIN_URL', plugin_dir_url(__FILE__));

    php/class-plugin.php

    // Line 57
    wp_register_script(
      ASSET_PREFIX . "-ssba",
      SSBA_PLUGIN_URL . "js/ssba.js",
      array('jquery'),
      filemtime(DIR_PATH . "js/ssba.js"),
      true
    );
    
    // Line 77
    wp_register_style(
      ASSET_PREFIX . "-ssba",
      SSBA_PLUGIN_URL . "css/ssba.css",
      array(),
      filemtime(DIR_PATH . "css/ssba.css")
    );

    We look forward to reviewing your pull request and incorporating your improvements into the plugin. If you have any further questions or need assistance during the process, please feel free to ask.

    Best regards,
    ShareThis Team

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.