theme development – How to fix : Uncaught ArgumentCountError: Too few arguments to function?

Question

I am getting this error:

 Fatal error: Uncaught ArgumentCountError: Too few arguments to function _themenameLibClassesEnqueue::css(), 1 passed in C:xampphtdocswordpresswp-includesclass-wp-hook.php on line 292 and at least 2 expected in C:xampphtdocswordpresswp-contentthemesnewthemelibclassesEnqueue.php:11 Stack trace: #0 C:xampphtdocswordpresswp-includesclass-wp-hook.php(292): _themenameLibClassesEnqueue->css('') #1 C:xampphtdocswordpresswp-includesclass-wp-hook.php(316): WP_Hook->apply_filters(NULL, Array) #2 C:xampphtdocswordpresswp-includesplugin.php(484): WP_Hook->do_action(Array) #3 C:xampphtdocswordpresswp-includesscript-loader.php(2027): do_action('wp_enqueue_scri...') #4 C:xampphtdocswordpresswp-includesclass-wp-hook.php(292): wp_enqueue_scripts('') #5 C:xampphtdocswordpresswp-includesclass-wp-hook.php(316): WP_Hook->apply_filters(NULL, Array) #6 C:xampphtdocswordpresswp-includesplugin.php(484): WP_Hook->do_action(Array) #7 C:xampphtdocswordpresswp-includesgeneral-template.php(3009): do_action('wp_head') #8 C:xampphtdocswordpresswp-contentthemesnewthemeheader.php(8): wp_head() #9 C:xampphtdocswordpresswp-includestemplate.php(730): require_once('C:\xampp\htdocs...') #10 C:xampphtdocswordpresswp-includestemplate.php(676): load_template('C:\xampp\htdocs...', true, Array) #11 C:xampphtdocswordpresswp-includesgeneral-template.php(48): locate_template(Array, true, true, Array) #12 C:xampphtdocswordpresswp-contentthemesnewthemeindex.php(19): get_header() #13 C:xampphtdocswordpresswp-includestemplate-loader.php(106): include('C:\xampp\htdocs...') #14 C:xampphtdocswordpresswp-blog-header.php(19): require_once('C:\xampp\htdocs...') #15 C:xampphtdocswordpressindex.php(17): require('C:\xampp\htdocs...') #16 {main} thrown in C:xampphtdocswordpresswp-contentthemesnewthemelibclassesEnqueue.php on line 11

There has been a critical error on this website.

there’s a class file in my mytheme/lib/classes/Enqueue.php:

namespace _themenameLibClasses;

class Enqueue {
    public function __construct() {
        add_action('wp_enqueue_scripts', [$this, 'css']);
        add_action('wp_enqueue_scripts', [$this, 'js']);
        add_action('admin_enqueue_scripts', [$this, 'admin_css']);
        add_action('admin_enqueue_scripts', [$this, 'admin_js']);
    }
    public function css($handle, $path, $deps=[], $ver=false, $media="all") {
        wp_enqueue_style($handle, get_template_directory_uri() . $path, $deps, $ver, $media);
    }
    public function js($handle, $path, $deps=[], $ver=false, $media="all") {
        wp_enqueue_script($handle, get_template_directory_uri() . $path, $deps, $ver, $media);
    }
    public function admin_css($handle, $path, $deps=[], $var=false, $media="all") {
        wp_enqueue_style($handle, get_template_directory_uri() . $path, $deps, $ver, $media);
    }
    public function admin_js($handle, $path, $deps=[], $var=false, $media="all") {
        wp_enqueue_script($handle, get_template_directory_uri() . $path, $deps, $ver, $media);
    }
}

and another file mytheme/Lib/enqueue_assets.php:

<?php

namespace _themenameLib;
require_once get_template_directory() . '/lib/classes/Enqueue.php';
use _themenameLibClassesEnqueue;;
$enqueue = new Enqueue;


$enqueue->css('_themename-stylesheet', '/dist/assets/css/bundle.css', [], 1.0, 'all');

both of the files are included in function.php by require_once.
I am trying to learn object oriented php by creating a starter theme for myself.
Thanks in advance.

0
sabbir ahmed 1 month 2021-06-29T22:38:22-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse