Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
480 views
in Plugins by
edited by

I'm making a few changes to the infamous badges plugin. I need to add images and read them from the list of badges page.

This is a sample of what I'm looking for:

It is actually currently working but I have hardcoded the path to the check image and I need some way to get it decently and relatively.

Is there any function that would allow this?

EG: I would like to store the images (and any other resource) in a folder such as "qa-plugin/q2a-badges/images/*" and then retrieve them using something like "qa_get_plugin_resource('images/check.png')" (not sure if the plugin should be included there or could be inferred)

After a second thought: Maybe a plugin that uses images not fetched by JavaScript would also help to replicate the procedure. The ones that come by default don't seem to contain any. Do you know know any plugin that requires images?

Thanks.

Q2A version: 1.6.2

1 Answer

+2 votes
by
selected by
 
Best answer

Ok, it was simpler than I thought. The key was in the load_module function:

load_module($directory, $urltoroot, $type, $name). If a module defines this function, it is called by Q2A before the module is used. The $directory parameter contains the full local path of the module's plugin directory, which can be used as a prefix for includestatements within the module. The $urltoroot parameter contains the URL of the plugin directory, relative to the current page request.

In my case it would be better to use the $urltoroot variable and store it into a class member so that it can be then used this way:

echo '<img src="' . $this->urltoroot . 'check.png" />'

by
An example, would have helped us php noobs to understand/follow this so much better?
by
@Funrunna: You find an example here: https://github.com/q2apro/q2apro-best-users-per-month-free/blob/master/qa-best-users-per-month-page.php

var $directory;
var $urltoroot;
function load_module($directory, $urltoroot)
{
$this->directory=$directory;
$this->urltoroot=$urltoroot;
}

Then you can use $this->urltoroot everywhere you need it.


PS: Don't forget to register the module in qa-plugin.php with e.g.:
qa_register_plugin_module('page', 'qa-best-users-per-month-page.php', 'qa_best_users_per_month_page', 'Best Users Page');
...