$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugins - Fatal error: Uncaught Error: Call to undefined function|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugins - Fatal error: Uncaught Error: Call to undefined function

matteradmin10PV0评论

I tried to create a my own function call Test from a simple plugin php file (list categories Plugin) , but when I called it. It showed error ” Fatal error: Uncaught Error: Call to undefined function… “

<?php
/* 
Plugin Name: List Categories
*/
class ListCategories{
   static function list_categories($atts, $content = null) {
    $atts = shortcode_atts(
      array(
        'show_option_all'    => '',
        'orderby'            => 'name',
        'order'              => 'ASC',
        'style'              => 'list',
        'show_count'         => 0,
        'hide_empty'         => 1,
        'use_desc_for_title' => 1,
        'child_of'           => 0,
        'feed'               => '',
        'feed_type'          => '',
        'feed_image'         => '',
        'exclude'            => '',
        'exclude_tree'       => '',
        'include'            => '',
        'hierarchical'       => 1,
        'title_li'           => __( 'Categories' ),
        'show_option_none'   => __( 'No categories' ),
        'number'             => null,
        'echo'               => 1,
        'depth'              => 0,
        'current_category'   => 0,
        'pad_counts'         => 0,
        'taxonomy'           => 'category',
        'walker'             => null
      ), $atts
    );

    test();
    ob_start();
    wp_list_categories($atts);
    $output = ob_get_contents();       
    ob_end_clean();    
    return $output; 
  }

  function test(){
    //Do something
  }
}

add_shortcode( 'categories', array('ListCategories', 'list_categories') );

Why I couldnt call the function? I tried update Wordpress but it still didnt work. Thanks!

I tried to create a my own function call Test from a simple plugin php file (list categories Plugin) , but when I called it. It showed error ” Fatal error: Uncaught Error: Call to undefined function… “

<?php
/* 
Plugin Name: List Categories
*/
class ListCategories{
   static function list_categories($atts, $content = null) {
    $atts = shortcode_atts(
      array(
        'show_option_all'    => '',
        'orderby'            => 'name',
        'order'              => 'ASC',
        'style'              => 'list',
        'show_count'         => 0,
        'hide_empty'         => 1,
        'use_desc_for_title' => 1,
        'child_of'           => 0,
        'feed'               => '',
        'feed_type'          => '',
        'feed_image'         => '',
        'exclude'            => '',
        'exclude_tree'       => '',
        'include'            => '',
        'hierarchical'       => 1,
        'title_li'           => __( 'Categories' ),
        'show_option_none'   => __( 'No categories' ),
        'number'             => null,
        'echo'               => 1,
        'depth'              => 0,
        'current_category'   => 0,
        'pad_counts'         => 0,
        'taxonomy'           => 'category',
        'walker'             => null
      ), $atts
    );

    test();
    ob_start();
    wp_list_categories($atts);
    $output = ob_get_contents();       
    ob_end_clean();    
    return $output; 
  }

  function test(){
    //Do something
  }
}

add_shortcode( 'categories', array('ListCategories', 'list_categories') );

Why I couldnt call the function? I tried update Wordpress but it still didnt work. Thanks!

Share Improve this question asked Mar 6, 2019 at 8:57 Viet TViet T 33 bronze badges 1
  • Check the syntax. – Max Yudin Commented Mar 6, 2019 at 9:21
Add a comment  | 

1 Answer 1

Reset to default 0

In your code there’s this part:

test();
ob_start();
wp_list_categories($atts);
$output = ob_get_contents();  

But I really doubt that global function called test exists on your page.

There is a function called test in your class, but it’s not static (so you can’t call it from static context unless you change it to static function test(){...}), and you should call it with self::test();

Post a comment

comment list (0)

  1. No comments so far