admin管理员组

文章数量:1287934

edit : I unlocked using the rest api and not ajax (so no js) thanks to the response of Tom J Nowell

I'm pretty new in wordpress plugin dev

I want to load some js for a plugin with ajax request.

To do so I have created the following code (I have removed the non necessary code) :

all the file is in the same folder into plugins

script.js

console.log('loaded');
var ajax_url = wcdouchette_ajax_object.ajax_url;
console.log('ajax_url');

wc-douchette.php

class Wcdouchette {
    protected function __construct() {
        $this->init();
    }

    public function wcdouchette_includes() {
      // JavaScript
      wp_enqueue_script('wcdouchette-script-js', plugins_url( 'script.js', __FILE__ ));
      // Pass ajax_url to script.js
      wp_localize_script(
        'wcdouchette-script-js',
        'wcdouchette_ajax_object',
        array( 'ajax_url' => admin_url( 'admin-ajax.php' ) )
      );
    }

    private function init() {
      if (get_site_url() === '') $this->_isdev = true;
      add_action('wp_enqueue_scripts', array(&$this, 'wcdouchette_includes'));
      add_action('wp_ajax_wcdouchette_send_to_pmp', array(&$this, 'wcdouchette_send_to_pmp'));
      add_action('woocommerce_admin_order_actions_end', array(&$this, 'wcdouchette_btn_in_wcactions_column'));
      add_action('admin_menu', array(&$this, 'wcdouchette_options_page'));
      add_action('admin_init', array(&$this, 'wcdouchette_register_settings'));
    }
}

But i doesn't see any console.log. Any idea ?

本文标签: plugin developmentscript seem not load with use wpenqueuescript