Your code seems correct, but the problem might lie somewhere else. You need to make sure that the path to your JS file is correct and the function pdocrud_admin_enqueue_scripts()
is being called correctly.
Also, make sure your constructor is being called in the context of a WordPress action that happens after plugins are loaded. Here’s a simple example:
class MyPlugin {
public function __construct() {
add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
}
public function enqueue_scripts() {
wp_enqueue_script('my-plugin-script', plugins_url('/assets/js/frontend-script.js', __FILE__));
}
}
// Hook into the 'plugins_loaded' action to create an instance of your plugin.
add_action('plugins_loaded', function() {
new MyPlugin();
});
In this example, an instance of the MyPlugin class is created on the plugins_loaded
action. This is a good place to initialize your plugin, as all the other plugins have been loaded by the time this action fires.
Also, note that in the enqueue_scripts()
function, the plugins_url()
function is being used to create the URL to the script file. This function generates the correct URL, regardless of where the plugin is installed. The __FILE__
magic constant is being passed as the second argument to plugins_url()
to specify that the path should be relative to the current file.
In your case, you’d replace my-plugin-script
with wp-db-fb-co-frontend-script-js
, and the URL to the script file with your URL.
And remember that wp_enqueue_script()
function needs to be called before wp_head()
function is executed. The admin_enqueue_scripts action is the appropriate hook to use for enqueuing scripts and styles in the admin area.