'); $ajaxrp_options = array( 'ajaxrp_auto_show' => 1, 'ajaxrp_before_html' => '

Random Posts

', 'ajaxrp_after_html' => '
', 'ajaxrp_number_shown' => 10, 'ajaxrp_loading_message' => '

Loading...

', 'ajaxrp_post_format' => '{post} written by {author}', 'ajaxrp_include_sticky' => 0, ); load_plugin_textdomain($ajaxrp_text_domain); function ajaxrp_install() { global $ajaxrp_options; foreach ($ajaxrp_options as $key=>$value) { add_option($key, $value); } } register_activation_hook(__FILE__, 'ajaxrp_install'); /** * @desc Includes the stylesheet and scripts */ function ajaxrp_head() { global $ajaxrp_plugin_dir; $css_file = get_template_directory_uri() . 'ajaxrp-style.css'; if (!file_exists($css_file)) { $css_file = "{$ajaxrp_plugin_dir}css/ajaxrp-style.css"; } printf(' ', $css_file, $ajaxrp_plugin_dir); } add_action('wp_head', 'ajaxrp_head'); function ajaxrp_prepare_post_data($post_content) { global $post; $data = array( 'post_id' => $post->ID, ); $placeholder = ajaxrp_get_placeholder($data); if (get_option('ajaxrp_auto_show')) { // remove the custom tag (if any) and add the place holder to the end of the post $post_content = str_replace(AJAXRP_CUSTOM_TAG, '', $post_content) . $placeholder; return $post_content; } // replace the custom tag with the placeholder return str_replace(AJAXRP_CUSTOM_TAG, $placeholder, $post_content); } add_filter('the_content', 'ajaxrp_prepare_post_data', 5); function ajaxrp_get_placeholder($data) { // if this is not a single post, don't do anything if (!is_single()) { return ''; } $data = base64_encode(serialize($data)); return sprintf(' %s
%s
%s ', stripslashes(get_option('ajaxrp_before_html')), stripslashes(get_option('ajaxrp_loading_message')), $data, stripslashes(get_option('ajaxrp_after_html'))); } function ajaxrp_request_handler() { switch($_POST['ajaxrp_action']) { case 'get_posts': ajaxrp_get_posts(); break; case 'options': ajaxrp_save_options(); break; default: return false; } exit(); } add_action('init', 'ajaxrp_request_handler', 5); function ajaxrp_save_options() { global $ajaxrp_options; foreach ($_POST as $key=>$value) { if ($key == 'ajaxrp_action' || !isset($ajaxrp_options[$key])) continue; if ($key == 'ajaxrp_number_shown') { $value = intval($value); if ($value < 1) $value = 10; // default number of posts is 10 } update_option($key, $value); } header('Location: ' . get_bloginfo('wpurl') . '/wp-admin/options-general.php?page=ajax_random_posts.php&updated=true'); die(); } function ajaxrp_get_posts() { $format = stripslashes(get_option('ajaxrp_post_format')); $data = unserialize(base64_decode($_POST['data'])); $ret = ''; die($ret); } function ajaxrp_options_form() { global $ajaxrp_plugin_dir; printf('

AJAX Random Posts Options



By default, WordPress returns the sticky posts when querying the post. It\'s likely you do not want them to appear in the random list, but just in case you have a good reason to...

Get help with this

Get help with this

', $ajaxrp_plugin_dir, $ajaxrp_plugin_dir, get_option('ajaxrp_number_shown'), get_option('ajaxrp_include_sticky') == 1 ? 'selected="selected"' : '', get_option('ajaxrp_auto_show') == 0 ? 'selected="selected"' : '', stripslashes(get_option('ajaxrp_before_html')), stripslashes(get_option('ajaxrp_after_html')), stripslashes(get_option('ajaxrp_loading_message')), stripslashes(get_option('ajaxrp_post_format'))); } /** * @desc Adds the Options menu item */ function ajaxrp_menu_items() { add_options_page('AJAX Random Posts', 'AJAX Random Posts', 8, basename(__FILE__), 'ajaxrp_options_form'); } # Hook into the settings menu add_action('admin_menu', 'ajaxrp_menu_items'); function ajaxrp() { global $post; $data = array( 'post_id' => $post->ID, ); echo ajaxrp_get_placeholder($data); }