WordPress.org

Ready to get started?Download WordPress

Forums

SpeakUp! Email Petitions
[resolved] New shortcode to show the number of signatures (11 posts)

  1. carlitoscapote
    Member
    Posted 1 year ago #

    Hello Kreg,

    A group of activists asked me to install your plugin in their blog, but I needed to implement a little change. They wanted to be able to place the number of signatures in a variety of places, so I wrote a little function to habilitate a second shortcode.

    It a very simple shortcode. It's usage is:

    [signaturecount id="1"]

    You can use it wherever you want (in posts or pages). To implement it, the only thing I did was to add a function to the includes/signaturelist.php file.

    // register shortcode to display signatures count
    add_shortcode( 'signaturecount', 'dk_speakup_signaturescount_shortcode' );
    function dk_speakup_signaturescount_shortcode( $attr ) {
    
            include_once( 'class.petition.php' );
    
            $id = 1; // default
            if ( isset( $attr['id'] ) && is_numeric( $attr['id'] ) ) {
                    $id = $attr['id'];
            }
    
            $petition = dk_speakup_Petition::retrieve( $id );
    
        return $petition->signatures;
    }

    I'll probably add more changes, so created a project in GitHub with my fork: https://github.com/elcapo/speakup

    It will be nice if you could add this function to the "core" so everybody can use it.

    Thanks for your attention!

    http://wordpress.org/extend/plugins/speakup-email-petitions/

  2. polanve
    Member
    Posted 1 year ago #

    Wow, sounds like you really know your stuff. Your group of activists are lucky. One thing they will probably need is the same thing I need, which is to prevent email typos. This not only causes that you cannot get in touch with the signer, but also the confirmation email will get rejected and too many of those puts you at risk of getting blacklisted as a spammer. The usual solution is to provide a second box for the signer to type the email again, and to give an error message if the two don't match. If you can make this happen, you will have fixed the one big problem with this plug in.

  3. Kreg Wallace
    Member
    Plugin Author

    Posted 1 year ago #

    Nice work, carlitoscapote. I'll look into adding something like that in a future release.

    @polanve - Thanks for the suggestion. I'll look into adding that too.

  4. weslebsack
    Member
    Posted 1 year ago #

    Not sure if this feature is broken, but I can't get it to work in ether version: The latest official version of the plugin or the fork that carlitoscapote posted to github. Every time I include the short code, it breaks the page and won't render anything past the point where the short code is to be displayed.

    Any help would be greatly appreciated--I recommended this plugin to a client based on this information in the discovery phase of the project, and now I'm in a tough position.

    Thanks!

  5. carlitoscapote
    Member
    Posted 1 year ago #

    Hello @weslebsack,

    This feature is still only available in my Github version. But it seems we'll have something like that in a future release.

    Are you having problems with it?
    What WordPress version are you using?

  6. weslebsack
    Member
    Posted 1 year ago #

    Hi @carlitoscapote,
    Thanks for getting back to me! I'm using WordPress 3.5.1 and having issues with the Github version; specifically, when I attempt to show the number of signatures a petition has received.

    When I place the shortcode in the body copy, or attempt to use <?php do_shortcode('[signaturecount id="1"]'); ?>, it causes the page to break; as in, the page won't load any thing past the point of where the signaturecount shortcode is placed.

    I have tried adding your code snippet to both the WordPress.org version of the plugin as well and got the same result.

    Any help you can provide would be very appreciated.

    Thanks!

  7. weslebsack
    Member
    Posted 1 year ago #

    I found a jQuery workaround, but it only works if the short code petition form is also on the same page. In my case, I needed the signature count to show up in a box outside of the form, and to show the remaining signatures in another box. So, I wrote this:

    $(".dk-speakup-signature-count").attr("id","totalsignatures");
    var imgCont = $('.dk-speakup-signature-count span').text();
    document.getElementById('second').innerHTML = imgCont;
    A = imgCont
    B = 500 - A
    document.getElementById('first').innerHTML = B;

    What it's doing is pulling the contents of .dk-speakup-signature-count and placing it in #second. Then, it's taking the total signature count and subtracting it from 500 and placing it in #first

    Hope this helps!

  8. carlitoscapote
    Member
    Posted 1 year ago #

    Can't understand it. I'm using the GitHub version in a WordPress 3.5.1 installation and it seems to work fine. If you take a look at the end of the manifesto, at desobediencia.es, there are two counters:

    • Para apoyar individualmente el manifiesto, firma aquí (ya han firmado 672 personas)
    • Para apoyar como colectivo el manifiesto, firma aquí (ya han firmado 21 colectivos)

    Both numbers are written this code in a page:

    <ul>
    	<li><a href="http://desobediencia.es/manifiesto/firmas-individuales/">Para apoyar individualmente el manifiesto, firma aquí</a> (ya han firmado [signaturecount id="1"] personas)</li>
    	<li><a href="http://desobediencia.es/manifiesto/firmas-de-colectivos/">Para apoyar como colectivo el manifiesto, firma aquí</a> (ya han firmado [signaturecount id="2"] colectivos)</li>
    </ul>

    Don't know why it's not working for you but nice that you found a workaround.

  9. Kreg Wallace
    Member
    Plugin Author

    Posted 1 year ago #

    I believe the problem is that in carlitoscapote's code sample, the petition class was included, but never instantiated.

    I've added the necessary code with slight modification to the top of the emailpetition.php. This update is currently available only in the dev (or master) version of the plugin, which is now available on GitHub: https://github.com/kregwallace/speakup-email-petitions

  10. Kreg Wallace
    Member
    Plugin Author

    Posted 1 year ago #

    This shortcode is now included in the latest release: version 2.3.3

  11. Kate Martin Seattle
    Member
    Posted 1 year ago #

    Hi. I am a WYSIWYG user. I stumble my way through my wordpress sites, but I'm trainable. :-) I loaded your plug in to my site and it's working, but I don't know how to get the count of signatures to be visible. The directions say to paste [signaturecount id="1"] where I want it to display, but I am having no luck. Could you explain to me where to paste the code and why the numbers update isn't just automatic with the plug in? I'm using the widget as well and would like the total number of signatures to show there as well. I'm sure it's some mistake I'm making, but I'd sure love to solve it if you can help...

    Here's what it looks like: http://www.seattlemathcoalition.org The number only shows zero instead of the 6 signatures there already.

    Your help most welcome here.

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic