Add title & message shortcodes?
-
Hey Steve,
Endless appreciation for your work on this plugin. It’s a beauty. You’re the hero 2021 needed.
Can I suggest adding shortcodes for petition title & petition message in the next release? Particularly useful for fully populating petition pages with Rick’s fancy /?petition= URL string contribution.
Captain obvious code below!
NB: If anyone wants to add these shortcodes for themselves in the interim – drop the code below into your emailpetition.php file (usual warning: these changes will be lost if an update happens)
// register shortcode to display petition title add_shortcode( 'petitiontitle', 'dk_speakout_petitiontitle_shortcode' ); function dk_speakout_petitiontitle_shortcode( $attr ) { // Check if we have a form preslected if (array_key_exists('petition', $_GET)){ $attr['id'] = $_GET['petition']; } include_once( 'class.petition.php' ); $petition = new dk_speakout_Petition(); $id = 1; // default if ( isset( $attr['id'] ) && is_numeric( $attr['id'] ) ) { $id = $attr['id']; } $petition_exists = $petition->retrieve( $id ); if ( $petition_exists ) { return $petition->title; } else { return ''; } } // register shortcode to display petition message add_shortcode( 'petitionmessage', 'dk_speakout_petitionmessage_shortcode' ); function dk_speakout_petitionmessage_shortcode( $attr ) { // Check if we have a form preslected if (array_key_exists('petition', $_GET)){ $attr['id'] = $_GET['petition']; } include_once( 'class.petition.php' ); $petition = new dk_speakout_Petition(); $id = 1; // default if ( isset( $attr['id'] ) && is_numeric( $attr['id'] ) ) { $id = $attr['id']; } $petition_exists = $petition->retrieve( $id ); if ( $petition_exists ) { return $petition->petition_message; } else { return ''; } }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘Add title & message shortcodes?’ is closed to new replies.