Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

100
Visualizações
Why JS alert message is not fired when in class

I am learning wordpress plugin development. I have dummy question - Why, the alert message is not fired, when located in js class or in index.js?

I created new file "test.php" in my plugin folder

<?php
/*
Plugin Name: Test
Description: test plugin
Version: 1.0
Author: Jarda

*/


class Test{

    function __construct(){
add_action('wp_enqueue_scripts', array($this, 'startMyScripts'));
    }

    function startMyScripts(){
        wp_enqueue_script( 'testScript', plugin_dir_url( __FILE__ ) . '/src/index.js' );
    }
    
    $test = new Test();
}

Than I created js file "index.js" in /src/

import Search from "./modules/Search"
const search = new Search()

And a class "Search" in /src/modules

    class Search{
    constructor(){
    alert("helo")
    console.log("fired")
    }
}

export default Search

I have node installed, package.json file looks like this

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "wp-scripts build",
    "start": "wp-scripts start",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@wordpress/scripts": "^23.5.0"
  }
}
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Ok, so the path must be wp_enqueue_script( 'testScript', plugin_dir_url( FILE ) . '/build/index.js' );

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda