• Hello,

    I have added a plugin which adds category images to the normal post category. I would like to output the category image URL to the API as a value. I modified the category.php controller by adding:

    var $image;

    and by adding the following

    function import_wp_object($wp_category) {
        $this->id = (int) $wp_category->term_id;
        $this->slug = $wp_category->slug;
        $this->title = $wp_category->name;
        $this->description = $wp_category->description;
        $this->parent = (int) $wp_category->parent;
        $this->post_count = (int) $wp_category->count;
        // image:
        $this->image = z_taxonomy_image_url($this->id);
      }
Viewing 2 replies - 1 through 2 (of 2 total)
  • I’m having a very similar issue.

    I am running WordPress 3.9.2 with a custom theme, and I’ve created a custom API controller. I’m using JSON API 1.1.1 and Categories Images 2.4.2.

    At the top of the custom controller I have
    include_once(ABSPATH.'wp-admin/includes/plugin.php');

    Then I use the following code for the category image:

    $image = '';
    if (function_exists('z_taxonomy_image_url')) $image = z_taxonomy_image_url($category->term_id);

    I have set this up on a development server and a production one. It works fine in development, but in production the function_exists command is failing.

    Re gielcobben’s issue, what error are you encountering? Are you getting a php error such as “call to undefined function” or are you getting a false value returned from the z_taxonomy_image_url function?

    Further to my last post, if I use is_plugin_active() to detect the categories-images plugin, it returns false, yet in other parts of my code it returns true.

    All I can think is that it is something to do with the JSON API plugin.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Add function from a plugin to the json model’ is closed to new replies.