how the output of the drupal hooks - drupal

the drupal is 6.
1, in drupal.everything's output is by a theme function or a template file.is this right. if right,then question 2.
2,in a module there is a hook_link and hook_menu, how they output? i can't find a theme function or a template file effect it. thank you.
eg:in book's module there is a book_link() defined. but i can't find there is a heme_book_link(),and in hook_theme there is no return of the book_link.

3 things that make understanding Drupal hooks:
They are just regular php functions.
Many times they don't return anything.
They are "called" by module_invoke_all() or module_invoke()
For Example: If module foo has a hook_dosomething() there is a function in foo.module that implements module_invoke_all('foo', 'dosomething')
The other way to think about it is that the hook "exteneds" a function someplace else, and anything that happens in the hook happens in the function that calls module_invoke_all() in it.

Not all hooks generate output. hook_menu() and hook_link(), for example, just return arrays with data that will be used by Drupal in some way (e.g. to register new paths in the system).

Related

Wordpress: how to call method and output?

I am using a Wordpress plugin found here https://github.com/hirezstudios/smite-api-wp . Issue I have is the readme says I need to:
// call a method
global $smiteAPI;
$gods = $smiteAPI->getGods(1);
// do whatever with the god data...
I understand I need to implement it on one of my .php files or generate a new one. However, I am unsure what call a method means or how to make the above work. The getGods(1) will return a .json file of all gods in a game called Smite; 1 tells the API english.

what is the real use of __return_empty_array in wordpress and when should we use it?

As I have started learning wordpress plugin developement recently but i can't understand the function __return_empty_array. It returns an array but when should we really use it.
__return_empty_array returns an empty array. It is ued to return empty array to filters. For example consider the case of turning off the link of the authors page. You can add the following code to functions.php to get it done.
add_filter ('author_rewrite_rules', '__return_empty_array');
In this case an empty array is returned and __return_empty_array is used for it. Hope you get me.

Call to undefined function add_options_page()

I developed the plugin for my wordpress project. I successfully tested it on my local xampp server with 5.3 php. Then I uploaded my project to the web hosting with php 5.2. First trouble which with I faced off was unsupporting anonymous functions in php 5.2. No issue, I redeclared all functions with names. But then I got error Call to undefined function add_options_page(), which I counldn't explain. Plz help me guys with your advices
My part of code:
function mainPage(){
///some code
}
function mainPage2(){
add_options_page('Submissions of MAIN page contact form', 'Submissions of MAIN page contact form', 'manage_options','ea_submissions2', mainPage());
}
add_action('admin_menu',mainPage2());
I think something wrong with my funcitons, look through it please.
There is no issue with php 5.2 as I thought, this part of code also doesn't work with php 5.3! Something wrong with my code
I had a similar problem, turns out I was running a function too early:
Use admin_init hook instead of init
Hopefully that helps someone out :D
This doesn't work because you have normal function not wrapped in a class, and because add_options_page does not work yet by that time that is why you get the error.
A fix would be to use an anonymous function in the add action call, but hence that does not work on php 5.2.
So long story short, this is fixable though, but you shouldn't run php 5.2 anymore in the first place. PHP 5.5 is already in development and 5.3 is facto standard these days. A solution is to ask your hosting company to upgrade php to at least 5.3 so that you can use anonymous functions and you can hook it to the add action call.
Or, wrap it all in a class and on the admin init function create the new class.
You have to call your code inside admin_menu like this
add_action( 'admin_menu', array(&$this, 'addWidgetSettingsMenu' ));
Aware that this is an old question, this is your problem:
add_action('admin_menu',mainPage2());
Here you are invoking the mainPage2() function and adding the return value of that function as an argument to the add_action method.
You should do
add_action('admin_menu', 'mainPage2');
This way, the mainPage2 function will be called when admin_menu happens.
Try it without giving space in title :-
SubmissionsOfMainPageContactForm

What's "function_exists" in Wordpress

Im very new to WordPress. I was going through Smooth Slider WP Plugin and saw
if ( function_exists( 'get_smooth_slider_category' ) ) { get_smooth_slider_category('Uncategorized'); }
This pretty much gives what I wanted, but not quite. This pulls all the content in the category and what Im after is just the image URL.
My question is whats "function_exists" in wordpress? and I checked get_smooth_slider_category in functions.php file but couldnt find any. Can someone please explain how function_exists works?
function_exists is a PHP function, not limited to WordPress.
From the manual "Checks the list of defined functions, both built-in (internal) and user-defined, for function_name."
It returns true or false on whether or not the function exists. So you can either create a new function before it that does something slightly different, or prevent an error if it doesn't exist (normally because the required file hasn't been included).
This is a PHP function that checks if the passed in name matches any defined functions (either internal, or user defined).
It is a way to check if a function is "available" before calling it.

How to work with hook_nodeapi after image thumbnail creation with ImageCache

A bit of a followup from a previous question.
As I mentioned in that question, my overall goal is to call a Ruby script after ImageCache does its magic with generating thumbnails and whatnot.
Sebi's suggestion from this question involved using hook_nodeapi.
Sadly, my Drupal knowledge of creating modules and/or hacking into existing modules is pretty limited.
So, for this question:
Should I create my own module or attempt to modify the ImageCache module?
How do I go about getting the generated thumbnail path (from ImageCache) to pass into my Ruby script?
edit
I found this question searching through SO...
Is it possible to do something similar in the _imagecache_cache function that would do what I want?
ie
function _imagecache_cache($presetname, $path) {
...
...
// check if deriv exists... (file was created between apaches request handler and reaching this code)
// otherwise try to create the derivative.
if (file_exists($dst) || imagecache_build_derivative($preset['actions'], $src, $dst)) {
imagecache_transfer($dst);
// call ruby script here
call('MY RUBY SCRIPT');
}
Don't hack into imagecache, remember every time you hack core/contrib modules god kills a kitten ;)
You should create a module that invokes hook_nodeapi, look at the api documentation to find the correct entry point for your script, nodeapi works on various different levels of the node process so you have to pick the correct one for you (it should become clear when you check the link out) http://api.drupal.org/api/function/hook_nodeapi
You won't be able to call the function you've shown because it is private so you'll have to find another route.
You could try and build the path up manually, you should be able to pull out the filename of the uploaded file and then append it to the directory structure, ugly but it should work. e.g.
If the uploaded file is called test123.jpg then it should be in /files/imagecache/thumbnails/test123/jpg (or something similar).
Hope it helps.

Resources