Ajaxize will allow you to ajaxize almost any php function on your site.

It can be a plugin, a function you wrote, or even a core wordpress function.


There are some (obvious or less obvious) limitations currently:


Enter a function name below.

Function Name:

The generated div can be inserted to any page/post on the site and will ajaxize the call to the function automatically.

Please make sure you enter a valid function name, that the function does not require any parameters, and that it returns valid HTML.

Copy & paste this div below

"; $output_div = "
"; $content .= "
" . htmlentities($output_div) . "
"; $content .= "

Function output (via ajaxize):

"; $content .= '
'; $content .= str_replace('><', '> If you see this message. Something is not working <', $output_div); $content .= '
'; return $content; } function plugin_admin_add_page() { global $ajaxize_this_hook; $ajaxize_this_hook = add_options_page('Ajaxize settings', 'Ajaxize', 'manage_options', 'ajaxize_this', 'plugin_options_page'); } // display the admin options page function plugin_options_page() { ?>

Ajaxize

A random Secret Key was automatically generated when the plugin was first installed.
You can change your secret key, but please be aware that any previously-generated divs will stop working.
Do not post or share this key.

"; } // validate our options function plugin_options_validate_secret_key($input) { $options = get_option('ajaxize_this_options'); // doing per-field regex validation. // You can add / change validation rules here foreach ($input as $k => $v) { if (preg_match('/^[a-z0-9]{12,}$/i', $v)) { $options[$k] = $v; } else { add_settings_error('secret_key','ajaxize_this_err','Secret Key must be alphanumeric and at least 12 characters long','error'); } } return $options; } function ajaxize_this_validate_function($fn_name) { if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $fn_name)) { if (! function_exists($fn_name)) { add_action('admin_notices', create_function('', 'echo \'

Fuction not found.

\';')); } else return $fn_name; } else { add_action('admin_notices', create_function('', 'echo \'

Invalid function name. Make sure to remove () and any extra spaces.

\';')); } } add_filter('contextual_help', 'ajaxize_this_help', 10, 3); // help page for ajaxize plugin (taken from FAQ) function ajaxize_this_help($contextual_help, $screen_id, $screen) { global $ajaxize_this_hook; if ($screen_id == $ajaxize_this_hook) { $contextual_help = <<Ajaxize

Ajaxize will allow you to ajaxize almost any php function on your site. It can be a plugin, a function you wrote, or even a core wordpress function.


Frequently Asked Questions

How does ajaxize work?

To ajaxize your plugin or function, the only thing you need is the function name. Go to Settings->ajaxize and enter your function name. Then click 'Generate DIV'.

If all is working fine you should get a div that you can add to any page, post or template. You should also see the output of the generated div below.

How do I find the correct function name?

Many plugins come with shortcodes or function names that can be entered directly into the template. It is usually within the plugin documentation. Search the documentation for information how to use the plugin in your templates. Otherwise, you can try the plugin editor (Plugins->Editor), select your plugin and then search for the function name inside the php code.

Are there any limitations to which functions I can use?

Yes.

How can I test if ajaxize is working?

Try 'ajaxize_this_test' (without the quotes) and click Generate DIV to test it.

What is the Secret Key? Do I need to change it?

The secret key is there to allow you to ajaxize any function you want, but only the functions you want and not others. The secret key is used to create a 'signature' on the div you generate. This signature is generated using HMAC, and the Secret Key is the key used by HMAC.

A few notes about the secret key:

Can I add stuff or modify the div?

This is a normal div. The only part that you cannot change is the id section. Even the smallest change to the id will invalidate the signature, and it will stop working. Therefore, if you have a new function you also want to ajaxize - you'd have to use the ajaxize generator. Don't just replace the function name, because the signature will not be valid for any other function.

What is this good for?

ajaxize is most suitable when you are using a caching solution (W3 Total Cache, WP Super Cache etc). With ajaxize you can keep the page cached, but still pull content dynamically. Best used for quotes, feedbacks, statistics etc, but can work on almost any type of output.

It might also be useful to speed up page loads with plugins like Facebook and Twitter buttons (which often take some time to load if embedded directly).

It won't make you rich in 21 days nor will it make your pencil longer.

Can I automatically refresh the div every X seconds?

Yes, but currently you'd have to write your own javascript for it. Here is a small example using jQuery (replace with your own div id):

<script>
var refreshId = setInterval(function() {
 
    var $data = $('div[id^="ajaxize_this:REPLACE_THIS"]');
    $data.each( function() {
        $data.fadeOut(2000, function() {
            $data.load("/index.php?ajaxize_this=" + $data.attr('id'), function() {
                $data.fadeIn(2000);
            });
        });
    });
 
    return false;
}, 10000); 
</script>

I'm getting an error after generating a DIV "ajaxize: Error executing . Is this function correct?" What's wrong?

Check that the function name is correct, do not include brackets. Use: some_function instead of some_function(). Make sure the function does not require any parameters either.

I generate a DIV but the Function output is empty. Why?

Some plugins/functions produce iframes and other content that might only get displayed in the right context. In general, if there's an error, you would get an error message on the settings page. Try to copy the div into a post instead. It might still work.


EOD; } return $contextual_help; } /* END PLUGIN SETTINGS */ ?>