{"id":7517194,"date":"2016-06-26T04:23:34","date_gmt":"2016-06-26T04:23:34","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/shortcodes-patch\/"},"modified":"2016-09-01T15:59:35","modified_gmt":"2016-09-01T15:59:35","slug":"shortcodes-patch","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/shortcodes-patch\/","title":{"rendered":"Shortcodes patch"},"content":{"rendered":"<p>Hi,<\/p>\n<p>I saw some additional shortcodes were started by the original author(s), but not finished. I finished and added some more. I believe this should allow users to correctly display confirmed users, unconfirmed users, a tally of each, and a total number of signatories all with shortcodes. I think the functions I called are fast and scoped to the minimum data, but let me know if you see any other optimizations. Below is an <code>svn diff<\/code> to be applied as a patch:<\/p>\n<pre><code>Index: lh-signing.php\n===================================================================\n--- lh-signing.php\t(revision 1443169)\n+++ lh-signing.php\t(working copy)\n@@ -656,8 +656,9 @@\n public function list_attached_users($id, $list, $fields)  {\n\n $users = get_users( array(\n-  &#039;connected_type&#039; =&gt; array($list,&#039;foobar&#039;),\n-  &#039;connected_items&#039; =&gt; $id\n+  &#039;connected_type&#039; =&gt; array($list),\n+  &#039;connected_items&#039; =&gt; get_queried_object_id(),\n+  &#039;fields&#039; =&gt; array($fields)\n ) );\n\n $return_string = &quot;&lt;ul&gt;&quot;;\n@@ -664,7 +665,7 @@\n\n foreach ( $users as $user ) {\n\n-$return_string .= &#039;&lt;li&gt;&#039;.get_the_author_meta( &#039;display_name&#039;, $user-&gt;ID ).&#039;&lt;\/li&gt;&#039;;\n+$return_string .= &#039;&lt;li&gt;&#039;. $user-&gt;{&#039;display_name&#039;} .&#039;&lt;\/li&gt;&#039;;\n\n }\n\n@@ -674,7 +675,30 @@\n\n }\n\n+public function count_attached_users($id, $list, $fields) {\n\n+$users = get_users( array(\n+  &#039;connected_type&#039; =&gt; array($list),\n+  &#039;connected_items&#039; =&gt; get_queried_object_id(),\n+  &#039;fields&#039; =&gt; array($fields)\n+) );\n+\n+\n+$user_count = 0;\n+\n+foreach ( $users as $user ) {\n+\n+$user_count++;\n+\n+}\n+\n+$return_string = $user_count;\n+\n+return $return_string;\n+\n+}\n+\n+\n public function the_content_filter( $content ) {\n\n global $post;\n@@ -910,6 +934,7 @@\n add_shortcode($this-&gt;namespace.&#039;_form&#039;, array($this,&quot;form_shortcode_output&quot;));\n add_shortcode($this-&gt;namespace.&#039;_unconfirmed_count&#039;, array($this,&quot;unconfirmed_count_shortcode_output&quot;));\n add_shortcode($this-&gt;namespace.&#039;_confirmed_count&#039;, array($this,&quot;confirmed_count_shortcode_output&quot;));\n+add_shortcode($this-&gt;namespace.&#039;_total_count&#039;, array($this,&quot;total_count_shortcode_output&quot;));\n add_shortcode($this-&gt;namespace.&#039;_unconfirmed_list&#039;, array($this,&quot;unconfirmed_list_shortcode_output&quot;));\n add_shortcode($this-&gt;namespace.&#039;_confirmed_list&#039;, array($this,&quot;confirmed_list_shortcode_output&quot;));\n\n@@ -961,10 +986,10 @@\n\n extract( shortcode_atts( array (\n &#039;id&#039; =&gt; false,\n-&#039;fields&#039; =&gt; &#039;display_name&#039; ), $atts )\n+&#039;fields&#039; =&gt; &#039;display_name&#039; ), $atts )\n );\n\n-$return_string = $this_&gt;list_attached_users($id, &#039;signing_sign_unconfirmed&#039;, $fields);\n+$return_string = $this-&gt;list_attached_users($id, &#039;signing_sign_unconfirmed&#039;, $fields);\n\n@@ -972,6 +997,66 @@\n\n }\n\n+public function confirmed_list_shortcode_output($atts,$content = null)  {\n+\n+extract( shortcode_atts( array (\n+&#039;id&#039; =&gt; false,\n+&#039;fields&#039; =&gt; &#039;display_name&#039; ), $atts )\n+);\n+\n+$return_string = $this-&gt;list_attached_users($id, &#039;signing_sign_confirmed&#039;, $fields);\n+\n+\n+\n+return $return_string;\n+\n+}\n+\n+\n+public function confirmed_count_shortcode_output($atts,$content = null) {\n+\n+extract( shortcode_atts( array (\n+&#039;id&#039; =&gt; false,\n+&#039;fields&#039; =&gt; &#039;display_name&#039; ), $atts )\n+);\n+\n+$return_string = &#039;&lt;span class=&quot;confirmed_count&quot;&gt;&#039; . $this-&gt;count_attached_users($id, &#039;signing_sign_confirmed&#039;, $fields) . &#039;&lt;\/span&gt;&#039;;\n+\n+\n+return $return_string;\n+\n+}\n+\n+public function unconfirmed_count_shortcode_output($atts,$content = null) {\n+\n+extract( shortcode_atts( array (\n+&#039;id&#039; =&gt; false,\n+&#039;fields&#039; =&gt; &#039;display_name&#039; ), $atts )\n+);\n+\n+$return_string = &#039;&lt;span class=&quot;confirmed_count&quot;&gt;&#039; . $this-&gt;count_attached_users($id, &#039;signing_sign_unconfirmed&#039;, $fields) . &#039;&lt;\/span&gt;&#039;;\n+\n+\n+return $return_string;\n+\n+}\n+\n+public function total_count_shortcode_output($atts,$content = null) {\n+\n+extract( shortcode_atts( array (\n+&#039;id&#039; =&gt; false,\n+&#039;fields&#039; =&gt; &#039;display_name&#039; ), $atts )\n+);\n+\n+$return_string = &#039;&lt;span class=&quot;confirmed_count&quot;&gt;&#039;;\n+$return_string .= $this-&gt;count_attached_users($id, &#039;signing_sign_unconfirmed&#039;, $fields) + $this-&gt;count_attached_users($id, &#039;signing_sign_confirmed&#039;, $fields);\n+$return_string .= &#039;&lt;\/span&gt;&#039;;\n+\n+\n+return $return_string;\n+\n+}\n+\n public function add_meta_boxes($post_type, $post) {\n\n if (has_shortcode( $post-&gt;post_content, &#039;lh_signing_form&#039; )){\n@@ -1576,4 +1661,4 @@\n\n-?&gt;\n\\ No newline at end of file\n+?&gt;\nIndex: readme.txt\n===================================================================\n--- readme.txt\t(revision 1443169)\n+++ readme.txt\t(working copy)\n@@ -16,6 +16,20 @@\n\n Creating a petition\/list\/signup is as easy as adding a shortcode to a post or page (or CPT). From there additional editors are available to configure easch aspect of the sign up. Everything is completely self hosted and all list members become users of your site (not a third parties).\n\n+Available shortcodes:\n+\n+[lh_signing_form] (enable signatories on any post, page, or custom post type)\n+\n+Unconfirmed signatories: [lh_signing_unconfirmed_count]\n+\n+Confirmed signatories: [lh_signing_confirmed_count]\n+\n+Total signatories: [lh_signing_total_count]\n+\n+[lh_signing_unconfirmed_list] (unformated list)\n+\n+[lh_signing_confirmed_list] (unformated list)\n+\n == Installation ==\n\n 1. Upload the &lt;code&gt;lh-signing&lt;\/code&gt; folder to the &lt;code&gt;\/wp-content\/plugins\/&lt;\/code&gt; directory\n@@ -97,4 +111,4 @@\n * Conditionally show admin boxes\n\n **2.61 June 22, 2016**\n-* Update links\n\\ No newline at end of file\n+* Update links<\/code><\/pre>\n<p>https:\/\/wordpress.org\/plugins\/lh-signing\/<\/p>\n","protected":false},"template":"","class_list":["post-7517194","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/7517194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/7517194\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=7517194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}