Advertisement
Guest User

Untitled

a guest
Sep 12th, 2014
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.28 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Plugin Name: Dotmailer Plugin
  4.  * Description: Dotmailer add to address book
  5.  */
  6.  
  7. // Security
  8. defined('ABSPATH') or die();
  9.  
  10. // Define global variables
  11. $apiemail = "";
  12. $apipassword = "";
  13. $listID = "";
  14.  
  15. // Add menu item to the admin panel
  16. add_action( 'admin_menu', 'dotmailer_menu' );
  17.  
  18. // Add an options page
  19. function dotmailer_menu() {
  20.     add_options_page( 'Dotmailer Options', 'Dotmailer Details', 'manage_options', 'dotmailer', 'dotmailer_options' );
  21. }
  22.  
  23. // Form for the options including three fields
  24. function dotmailer_options() {
  25. ?>
  26.  
  27. <div class="wrap">
  28.     <h2>Dotmailer API information</h2><br />
  29.     <form method="post" action="options.php">
  30.         <?php settings_fields( 'settings-group' );
  31.         do_settings_sections( 'settings-group' );
  32.         ?>
  33.             <label>API key</label><br />
  34.             <input type="email" name="apiemail" value="<?php echo get_option('apiemail'); ?>"><br /><br />
  35.             <label>Password</label><br />
  36.             <input type="password" name="apipassword" value="<?php echo get_option('apipassword'); ?>"><br /><br />
  37.             <label>Address Book List ID</label><br />
  38.             <small>This is the ID for the list you want to save contacts too. Find this by navigating to the list in Dotmailer and taking the 7 digit ID from the end of the URL</small><br /><br />
  39.             <input type="number" name="listID" value="<?php echo get_option('listID'); ?>"/><br /><br />
  40.             <label>Redirect after result</label><br />
  41.             <small>Include the page slug of where you would like to redirect the user after <strong>successful</strong> submission</small><br />
  42.             <input type="text" name="slugSuccess" value="<?php echo get_option('slugSuccess'); ?>"/><br /><br />
  43.             <small>Include the page slug of where you would like to redirect the user after <strong>un</strong>successful submission</small><br />
  44.             <input type="text" name="slugUnsuccess" value="<?php echo get_option('slugUnsuccess'); ?>"/><br />
  45.  
  46.             <p><input type="submit" value="Save" class="button-primary" /></p>
  47.     </form>
  48. </div>
  49. <?php
  50. }
  51.  
  52. // Registers the options
  53. function register_settings() {  
  54.         register_setting('settings-group','apiemail');
  55.         register_setting('settings-group','apipassword');
  56.         register_setting('settings-group','listID');
  57.         register_setting('settings-group','slugUnsuccess');
  58.         register_setting('settings-group','slugSuccess');
  59.     }
  60.  
  61. // Initialises the options registered
  62. add_action( 'admin_init', 'register_settings' );
  63.  
  64.  
  65. // Add a widget for the newsletter form which can be added to the footer/widget areas
  66. class wp_dotmailer extends WP_Widget {
  67.  
  68.     // constructor
  69.     function wp_dotmailer() {
  70.          parent::WP_Widget(false, $name = __('Dotmailer Newsletter Signup', 'wp_widget_dotmailer') );
  71.     }
  72.  
  73.     // widget form creation
  74.     function form($instance) { 
  75.     // Check values
  76.         if( $instance) {
  77.              $title = esc_attr($instance['title']);
  78.         } else {
  79.              $title = '';
  80.              $text = '';
  81.         }
  82.         ?>
  83.             <p>
  84.             <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget Title', 'wp_widget_dotmailer'); ?></label>
  85.             <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
  86.             </p>
  87.         <?php
  88.  
  89.         }
  90.  
  91.         // widget update
  92.         function update($new_instance, $old_instance) {
  93.               $instance = $old_instance;
  94.               // Fields
  95.               $instance['title'] = strip_tags($new_instance['title']);
  96.              return $instance;
  97.         }
  98.  
  99.         // display widget
  100.         function widget($args, $instance) {
  101.            extract( $args );
  102.            // these are the widget options
  103.            $title = apply_filters('widget_title', $instance['title']);
  104.            echo $before_widget;
  105.            // Display the widget
  106.            echo '<div class="widget-text wp_widget_dotmailer_box">';
  107.  
  108.            // Check if title is set
  109.            if ( $title ) {
  110.               echo $before_title . $title . $after_title;
  111.            }
  112.            echo '<form action="wp-content/plugins/dotmailer/dotmailer-add.php" method="POST">';
  113.            echo '<label>Your email:</label>';
  114.            echo '<input type="email" placeholder="your@email.com" name="useremail"/>';
  115.            echo '<input type="submit" class="btn" value="Sign up" />';
  116.            echo '</form>';
  117.            echo '</div>';
  118.            echo $after_widget;
  119.         }
  120. }
  121.  
  122. // register widget
  123. add_action('widgets_init', create_function('', 'return register_widget("wp_dotmailer");'));
  124. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement