{"id":995,"date":"2011-09-01T10:48:20","date_gmt":"2011-09-01T15:48:20","guid":{"rendered":"http:\/\/www.uv.mx\/personal\/gvera\/2011\/09\/01\/wp-polls-wordpress-multisite\/"},"modified":"2011-10-25T10:11:25","modified_gmt":"2011-10-25T15:11:25","slug":"wp-polls-wordpress-multisite","status":"publish","type":"post","link":"https:\/\/www.uv.mx\/personal\/gvera\/2011\/09\/01\/wp-polls-wordpress-multisite\/","title":{"rendered":"WP-Polls + WordPress Multisite"},"content":{"rendered":"<p><a href=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2011\/09\/wp-polls.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.uv.mx\/personal\/gvera\/files\/2011\/09\/wp-polls.png\" alt=\"\" width=\"189\" height=\"181\" class=\"aligncenter size-full wp-image-1259\" \/><\/a><\/p>\n<p>We all have seen or even used one of the most common plugins for WordPress: <a href=\"http:\/\/wordpress.org\/extend\/plugins\/wp-polls\/\" target=\"_blank\">WP-Polls<\/a>. This is an AJAX poll system to your WordPress blog. It works pretty nice because is extremely customizable via templates and css styles.<\/p>\n<h3>Problem<\/h3>\n<p>But it has just one big problem\u2026 does not work on a multisite installation.<\/p>\n<p>When you press the \u201cVote\u201d button, a message appears with an error like \u201cpoll ID missing\u201d or something like that.<\/p>\n<p>Why? Because of the AJAX implementation. Because you have a multisite installation, WordPress creates different tables for each site. It adds a prefix for each site tables. For example, the root site might have the default prefix \u201cwp_\u201d, so the next site would have \u201cwp_1\u201d and the next one \u201cwp_2\u201d and so on.<\/p>\n<p>When this plugin makes an AJAX call, always looks for pools inside the default or root site database tables. In this example \u201cwp_\u201d, instead of looking at the tables of the current site.<\/p>\n<h3>Solution<\/h3>\n<p>It it very simple. We have to open the wp-polls.php file at the root of the plugin directory.<!--more--><\/p>\n<p>1. Find this function at the very top of the file.<\/p>\n<p>[php] if (!function_exists(&#8216;add_action&#8217;)) { [\/php]<\/p>\n<p>2. Put this code just right the end of the function.<\/p>\n<p>[php] switch_to_blog($_REQUEST[&#8216;blog_id&#8217;]); [\/php]<\/p>\n<p>Your function, would look like this.<\/p>\n<p>[php]<br \/>\nif (!function_exists(&#8216;add_action&#8217;)) {<br \/>\n\t$wp_root = &#8216;..\/..\/..&#8217;;<br \/>\n\tif (file_exists($wp_root.&#8217;\/wp-load.php&#8217;)) {<br \/>\n\t\trequire_once($wp_root.&#8217;\/wp-load.php&#8217;);<br \/>\n\t} else {<br \/>\n\t\trequire_once($wp_root.&#8217;\/wp-config.php&#8217;);<br \/>\n\t}<br \/>\n\tswitch_to_blog($_REQUEST[&#8216;blog_id&#8217;]);<br \/>\n}<br \/>\n[\/php]<\/p>\n<p>3. Find these lines<\/p>\n<p>[php]<br \/>\n\twp_localize_script(&#8216;wp-polls&#8217;, &#8216;pollsL10n&#8217;, array(<br \/>\n\t\t&#8216;ajax_url&#8217; =&gt; plugins_url(&#8216;wp-polls\/wp-polls.php&#8217;),<br \/>\n[\/php]<\/p>\n<p>4. Change the two lines for the following ones<\/p>\n<p>[php]<br \/>\n\t\/\/Cambio para enviar el ID del blog actual por AJAX<br \/>\n\tglobal $blog_id;<br \/>\n\twp_localize_script(&#8216;wp-polls&#8217;, &#8216;pollsL10n&#8217;, array(<br \/>\n\t\t&#8216;ajax_url&#8217; =&gt; get_bloginfo(&#8216;url&#8217;).&#8217;\/wp-content\/plugins\/wp-polls\/wp-polls.php?blog_id=&#8217;.$blog_id,<br \/>\n[\/php]<\/p>\n<p>5. Save your changes.<\/p>\n<p>Very simple but it works. You have to take on count that every time you update this plugin you have to make these changes again. Well, at least until they fix this.<\/p>\n<p>Hope it works for you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We all have seen or even used one of the most common plugins for WordPress: WP-Polls. This is an AJAX poll system to your WordPress blog. It works pretty nice because is extremely customizable via templates and css styles. Problem But it has just one big problem\u2026 does not work on a multisite installation. When&#8230;<\/p>\n","protected":false},"author":2,"featured_media":1259,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,27],"tags":[11,36,62,12],"class_list":["post-995","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","category-wordpress-2","tag-articulos-2","tag-php","tag-plugins","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/posts\/995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/comments?post=995"}],"version-history":[{"count":0,"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/posts\/995\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/media\/1259"}],"wp:attachment":[{"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/media?parent=995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/categories?post=995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.uv.mx\/personal\/gvera\/wp-json\/wp\/v2\/tags?post=995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}