# Wrong add\_action on the plugin.php file

**URL:** <https://forum.pinegrow.com/t/wrong-add-action-on-the-plugin-php-file/8622>\
**Category:** Bug Reports\
**Tags:** bug\
**Created:** [January 2, 2024, 9:01pm UTC](https://forum.pinegrow.com/t/wrong-add-action-on-the-plugin-php-file/8622 "2024-01-02T21:01:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wolfgang.Hartl](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/wolfgang.hartl/32/4621_2.png) [@Wolfgang.Hartl](https://forum.pinegrow.com/u/Wolfgang.Hartl)\
**Post date:** [January 2, 2024, 9:01pm UTC](https://forum.pinegrow.com/t/wrong-add-action-on-the-plugin-php-file/8622/1 "2024-01-02T21:01:36Z")

</div>

Hey there,

long time - no see(write). First of all, I wish you all a happy new year - may all your wishes come true in 2024!!

I’m currently creating a new woo project with pinegrow (but, for now, without pg woo extension) and a lot of custom functionality. My goal is to create (aside of the normal blocks) a few blocks which do nothing more then registering a few react scripts to deliver a custom user interface on the my account site and some special Sites for admins.

However, I’m not sure if the bug mentioned below, maybe occurs because of the absence of any CSS file in the project yet. It’s a new project with, at the time of writing, only one block (if that’s somehow neccessary). That block just contains a div with a php action on it executing the following code:

```auto
register_react_app("/beratungen/list");

```

```auto
function register_react_app($sub_path) {
    $HUFSCHUH_PLUGIN_PATH = hufschuh_plugin_base_path();
    $HUFSCHUH_PLUGIN_URL = hufschuh_plugin_base_url();

    // Basispfad hinzufügen
    $base_path = "/blocks/assets/react";
    $full_path = $HUFSCHUH_PLUGIN_PATH . $base_path . $sub_path;

    // CSS-Dateien einbinden
    foreach (glob($full_path . "/*.css") as $css_file) {
        $css_url = $HUFSCHUH_PLUGIN_URL . str_replace($HUFSCHUH_PLUGIN_PATH, '', $css_file);
        wp_enqueue_style(basename($css_file), $css_url);
    }

    // JS-Dateien einbinden
    foreach (glob($full_path . "/*.js") as $js_file) {
        $js_url = $HUFSCHUH_PLUGIN_URL . str_replace($HUFSCHUH_PLUGIN_PATH, '', $js_file);
        wp_enqueue_script(basename($js_file), $js_url, array(), false, true);
    }
}

```

I’m not sure if the mentioned above matters in any way, but in the generated plugin.php file, on the very end of the file there is an action looking for a function called “hufschuh\_add\_blocks\_editor\_styles” which was not generated inside that plugin.php file. That add\_action call causes the site to crash. Based on the name of the function I was wondering if that function get’s maybe added if i have added any CSS or JS file via the block controls?

 ![Bildschirmfoto 2024-01-02 um 21.58.47](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/0/0a4676ccac0d4280eefdb7f82cb2ebbae6762001.png)

I can send you the whole project if you’d like to and if it helps you!? 🙂

Cheers  
Wolfgang

---

<div class="post-metadata">

**Author:** ![Plunky](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/plunky/32/5705_2.png) [@Plunky](https://forum.pinegrow.com/u/Plunky)\
**Post date:** [January 3, 2024, 7:52am UTC](https://forum.pinegrow.com/t/wrong-add-action-on-the-plugin-php-file/8622/2 "2024-01-03T07:52:16Z")

</div>

In Pinegrow, in the WordPress settings (_WordPress \> Theme Settings_) did you initially have the “ **Load only styles of blocks on frontend** ” option enabled and then disabled it?

By unchecking the box and exporting the theme, that section of code is not elminated. It is also not deleted if you regenerate the functions.php file or clean up the exported theme folder.

Tenically, when you uncheck the box “_Load only styles of blocks on frontend_”, in the `pinegrow.json` file the boolean value to the property `blocks_load_if_rendered": "false"` is changed, however Pinegrow continues to export the project without making any changes.

Try it this way:

- Duplicate your current project folder and open it in Pinegrow;
- Define the WordPress settings to suit your needs, use the “Clear the theme folder” option, and close Pinegrow;
- Open the project in vscode, look for that code snippet and delete it anywhere;

```auto
/* Control how block assets are loaded on the front-end */
...
...
...
/* End of controlling how block assets are loaded on the front-end */

```

- Reopen the project in Pinegrow, export the theme;
- Open the exported theme in vscode and check if that feature is still present.

---

<div class="post-metadata">

**Author:** ![Bear](https://avatars.discourse-cdn.com/v4/letter/b/ac8455/32.png) [@Bear](https://forum.pinegrow.com/u/Bear)\
**Post date:** [January 3, 2024, 11:00am UTC](https://forum.pinegrow.com/t/wrong-add-action-on-the-plugin-php-file/8622/3 "2024-01-03T11:00:41Z")

</div>

Hi there!

I’ve resolved the issue by matching action call with function name in plugin itself, then it did not trigger this error anymore.

---

<div class="post-metadata">

**Author:** ![MichelyWeb](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/michelyweb/32/6652_2.png) [@MichelyWeb](https://forum.pinegrow.com/u/MichelyWeb)\
**Post date:** [January 5, 2024, 10:02am UTC](https://forum.pinegrow.com/t/wrong-add-action-on-the-plugin-php-file/8622/4 "2024-01-05T10:02:01Z")

</div>

If once checked the Plugin-Setting “Load only styles and scripts of blocks that are displayed on the front-end” then the exportet plugin breaks:

 ![CleanShot 2024-01-05 at 10.37.13@2x](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/6/6516c29b95a75457a39342b5a72cf10b7c776965.png)

It does not help to uncheck the Box in settings. You need to remove the following code from your plugin PHP file manually:

```auto
/* Control how block assets are loaded on the front-end */
function framesblocks_should_load_separate_core_block_assets() {
    /* Pinegrow generated Load Block Assets Separately Begin */
    //Load only assets of blocks that are used on the page
    add_filter( 'should_load_separate_core_block_assets', '__return_true' );

    /* Pinegrow generated Load Block Assets Separately End */
}
add_action('init', 'framesblocks_add_blocks_editor_styles');
/* End of controlling how block assets are loaded on the front-end */

```

When enabling the “Load only styles and scripts of blocks that are displayed on the front-end” again, this code snippet is added again.

As an alternative you can add this code to the inc/custom.php while replacing MYPREFIX with your plugin slug.

```auto
if(!function_exists('MYPREFIX_add_blocks_editor_styles')) {
    function MYPREFIX_add_blocks_editor_styles() {
        return;
    }
}

```

Interestingly the error stays present if I add css files to my custom blocks.  
I think this is a bug @matjaz ?

---

<div class="post-metadata">

**Author:** ![matjaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/matjaz/32/5_2.png) [@matjaz](https://forum.pinegrow.com/u/matjaz)\
**Post date:** [January 8, 2024, 8:28am UTC](https://forum.pinegrow.com/t/wrong-add-action-on-the-plugin-php-file/8622/5 "2024-01-08T08:28:34Z")

</div>

This is a bug triggered by checking the “Load only styles…” setting. It will be fixed in the next release, coming out this week.

Please note that unchecking the setting does not remove the issue. The solution is to regenerate functions.php / plugin file or to manually remove the code.
