WP Email Capture: How to edit widgets? (2 posts)

  1. kaswistry
    Posted 5 years ago #

    Hello everybody! I have the WP email capture widget successfully added to my webiste synchbiz.info. In fact, here's the code for the widget:

    function wp_email_capture_widget_init() {
    	// Check to see required Widget API functions are defined...
    	if ( !function_exists('register_sidebar_widget') || !function_exists('register_widget_control') )
    		return; // ...and if not, exit gracefully from the script.
    	// This function prints the sidebar widget--the cool stuff!
    	function wp_email_capture_widget($args) {
    		// $args is an array of strings which help your widget
    		// conform to the active theme: before_widget, before_title,
    		// after_widget, and after_title are the array keys.
    		// Collect our widget's options, or define their defaults.
    		$options = get_option('wp_email_capture_widget');
    		$title = empty($options['title']) ? 'Subscribe!' : $options['title'];
     		// It's important to use the $before_widget, $before_title,
     		// $after_title and $after_widget variables in your output.
    		echo $before_widget;
    		echo $before_title . $title . $after_title;
    		echo $text;
    		echo $after_widget;
    	// This is the function that outputs the form to let users edit
    	// the widget's title and so on. It's an optional feature, but
    	// we'll use it because we can!
    	function wp_email_capture_widget_control() {
    		// Collect our widget's options.
    		$options = get_option('wp_email_capture_widget');
    		$newoptions = get_option('wp_email_capture_widget');
    		// This is for handing the control form submission.
    		if ( $_POST['wp-email-capture-submit'] ) {
    			// Clean up control form submission options
    			$newoptions['title'] = strip_tags(stripslashes($_POST['wp-email-capture-title']));
    			$newoptions['text'] = strip_tags(stripslashes($_POST['wp-email-capture-text']));
    		// If original widget options do not match control form
    		// submission options, update them.
    		if ( $options != $newoptions ) {
    			$options = $newoptions;
    			update_option('wp_email_capture_widget', $options);
    		// Format options as valid HTML. Hey, why not.
    		$title = htmlspecialchars($options['title'], ENT_QUOTES);
    		$text = htmlspecialchars($options['text'], ENT_QUOTES);
    // The HTML below is the control form for editing options.
    		<label for="wp-email-capture-title" style="line-height:35px;display:block;">Widget title: <input type="text" id="wp-email-capture-title" name="wp-email-capture-title" value="<?php echo $title; ?>" /></label>
    <br />
    		<label for="wp-email-capture-text" style="line-height:35px;display:block;">Widget text: <input type="text" id="wp-email-capture-text" name="wp-email-capture-text" value="<?php echo $text; ?>" /></label>
    		<input type="hidden" name="wp-email-capture-submit" id="wp-email-capture-submit" value="1" />
    	// end of widget_mywidget_control()
    	// This registers the widget. About time.
    	register_sidebar_widget('WP Email Capture', 'wp_email_capture_widget');
    	// This registers the (optional!) widget control form.
    	register_widget_control('WP Email Capture', 'wp_email_capture_widget_control');
    // Delays plugin execution until Dynamic Sidebar has loaded first.
    add_action('plugins_loaded', 'wp_email_capture_widget_init');

    And this is the widget I am talking about:

    I just want to know how I can fix the widget to look more neatly. Like this perhaps?


    If you could notice the changes:

    1) space between name and the horizontal bar
    2) space between name and email
    3) space between email and submit


  2. ClaytonJames
    Posted 5 years ago #


    To style your form, you need to add to your CSS file the following ID declarations. wp_email_capture is for sidebar & template widgets, wp_email_capture_2 is for on page forms."


Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.