Exemple #1
0
 /**
  * Sets our object instance and base class instance.
  *
  * @since 1.0.0
  */
 public function set()
 {
     self::$instance = $this;
     $this->base = OMAPI::get_instance();
     $this->view = isset($_GET['optin_monster_api_view']) ? stripslashes($_GET['optin_monster_api_view']) : $this->base->get_view();
     $this->optin = isset($_GET['optin_monster_api_id']) ? $this->base->get_optin(absint($_GET['optin_monster_api_id'])) : false;
 }
Exemple #2
0
 /**
  * Constructor. Sets up and creates the widget with appropriate settings.
  *
  * @since 1.0.0
  */
 public function __construct()
 {
     // Load the base class object.
     $this->base = OMAPI::get_instance();
     $widget_ops = apply_filters('optin_monster_api_widget_ops', array('classname' => 'optin-monster-api', 'description' => __('Place an OptinMonster optin into a widgetized area.', 'optin-monster-api')));
     $control_ops = apply_filters('optin_monster_api_widget_control_ops', array('id_base' => 'optin-monster-api', 'height' => 350, 'width' => 225));
     parent::__construct('optin-monster-api', apply_filters('optin_monster_api_widget_name', __('OptinMonster', 'optin-monster-api')), $widget_ops, $control_ops);
 }
 /**
  * Returns the singleton instance of the class.
  *
  * @since 1.0.0
  *
  * @return OMAPI
  */
 public static function get_instance()
 {
     if (!isset(self::$instance) && !self::$instance instanceof OMAPI) {
         self::$instance = new OMAPI();
     }
     return self::$instance;
 }
Exemple #4
0
 /**
  * Sets our object instance and base class instance.
  *
  * @since 1.0.0
  */
 public function set()
 {
     self::$instance = $this;
     $this->base = OMAPI::get_instance();
     $this->view = 'ajax';
 }
Exemple #5
0
 /**
  * Sets our object instance and base class instance.
  *
  * @since 1.0.0
  */
 public function set()
 {
     self::$instance = $this;
     $this->base = OMAPI::get_instance();
     $this->fields = apply_filters('optin_monster_api_output_fields', $this->fields);
 }
Exemple #6
0
 /**
  * Creates the shortcode for the plugin.
  *
  * @since 1.0.0
  *
  * @global object $post The current post object.
  *
  * @param array $atts Array of shortcode attributes.
  * @return string     The optin output.
  */
 public function shortcode($atts)
 {
     global $post;
     $optin_id = false;
     if (isset($atts['id'])) {
         $optin_id = (int) $atts['id'];
     } else {
         if (isset($atts['slug'])) {
             $optin = get_page_by_path($atts['slug'], OBJECT, 'omapi');
             if ($optin) {
                 $optin_id = $optin->ID;
             }
         } else {
             // A custom attribute must have been passed. Allow it to be filtered to grab the optin ID from a custom source.
             $optin_id = apply_filters('optin_monster_api_custom_optin_id', false, $atts, $post);
         }
     }
     // Allow the optin ID to be filtered before it is stored and used to create the optin output.
     $optin_id = apply_filters('optin_monster_api_pre_optin_id', $optin_id, $atts, $post);
     // If there is no optin, do nothing.
     if (!$optin_id) {
         return false;
     }
     // Try to grab the stored HTML.
     $optin = $this->base->get_optin($optin_id);
     $html = trim(html_entity_decode(stripslashes($optin->post_content), ENT_QUOTES), '\'');
     if (!$html) {
         return false;
     }
     // Make sure to apply shortcode filtering.
     OMAPI::get_instance()->output->set_slug($optin);
     // Possibly add support for Mailpoet.
     $mailpoet = get_post_meta($optin->ID, '_omapi_mailpoet', true);
     if ($mailpoet) {
         OMAPI::get_instance()->output->wp_helper();
     }
     // Return the HTML.
     return $html;
 }
Exemple #7
0
 /**
  * Retrieves the setting UI for the setting specified.
  *
  * @since 1.0.0
  *
  * @param string $id 	  The optin ID to target.
  * @param string $setting The possible subkey setting for the option.
  * @return string		  HTML setting string.
  */
 public function get_setting_ui($id, $setting = '')
 {
     // Prepare variables.
     $ret = '';
     $optin_id = isset($_GET['optin_monster_api_id']) ? absint($_GET['optin_monster_api_id']) : 0;
     $value = 'optins' == $id ? get_post_meta($optin_id, '_omapi_' . $setting, true) : $this->base->get_option($id, $setting);
     // Load the type of setting UI based on the option.
     switch ($id) {
         case 'api':
             switch ($setting) {
                 case 'user':
                     $ret = $this->get_password_field($setting, $value, $id, __('API Username', 'optin-monster-api'), __('The API Username found in your OptinMonster Settings area.', 'optin-monster-api'), __('Enter your API Username here...', 'optin-monster-api'));
                     break 2;
                 case 'key':
                     $ret = $this->get_password_field($setting, $value, $id, __('API Key', 'optin-monster-api'), __('The API Key found in your OptinMonster Settings area.', 'optin-monster-api'), __('Enter your API Key here...', 'optin-monster-api'));
                     break 2;
             }
             break;
         case 'settings':
             switch ($setting) {
                 case 'cookies':
                     $ret = $this->get_checkbox_field($setting, $value, $id, __('Clear local cookies on optin update?', 'optin-monster-api'), __('If checked, local cookies will be cleared for all optins after optin settings are adjusted and saved.', 'optin-monster-api'));
                     break 2;
             }
             break;
         case 'optins':
             switch ($setting) {
                 case 'enabled':
                     $ret = $this->get_checkbox_field($setting, $value, $id, __('Enable optin on site?', 'optin-monster-api'), __('The optin will not be displayed on this site unless this setting is checked.', 'optin-monster-api'));
                     break 2;
                 case 'global':
                     $ret = $this->get_checkbox_field($setting, $value, $id, __('Load optin globally?', 'optin-monster-api'), __('If checked, the optin code will be loaded on all pages of your site.', 'optin-monster-api'));
                     break 2;
                 case 'automatic':
                     $ret = $this->get_checkbox_field($setting, $value, $id, __('Automatically add after post?', 'optin-monster-api'), sprintf(__('Automatically adds the optin after each post. You can turn this off and add it manually to your posts by <a href="%s" target="_blank">clicking here and viewing the tutorial.</a>', 'optin-monster-api'), 'http://optinmonster.com/docs/manually-add-after-post-optin/'));
                     break 2;
                 case 'users':
                     $ret = $this->get_dropdown_field($setting, $value, $id, $this->get_user_output(), __('Who should see this optin?', 'optin-monster-api'), sprintf(__('Determines who should be able to view this optin. Want to hide for newsletter subscribers? <a href="%s" target="_blank">Click here to learn how.</a>', 'optin-monster-api'), 'http://optinmonster.com/docs/how-to-hide-optinmonster-from-existing-newsletter-subscribers/'));
                     break 2;
                 case 'never':
                     $val = is_array($value) ? implode(',', $value) : $value;
                     $ret = $this->get_custom_field($setting, '<input type="hidden" value="' . $val . '" id="omapi-field-' . $setting . '" class="omapi-select-ajax" name="omapi[' . $id . '][' . $setting . ']" data-placeholder="' . esc_attr__('Type to search and select post(s)...', 'optin-monster-api') . '">', __('Never load optin on:', 'optin-monster-api'), __('Never loads the optin on the selected posts and/or pages.', 'optin-monster-api'));
                     break 2;
                 case 'only':
                     $val = is_array($value) ? implode(',', $value) : $value;
                     $ret = $this->get_custom_field($setting, '<input type="hidden" value="' . $val . '" id="omapi-field-' . $setting . '" class="omapi-select-ajax" name="omapi[' . $id . '][' . $setting . ']" data-placeholder="' . esc_attr__('Type to search and select post(s)...', 'optin-monster-api') . '">', __('Load optin exclusively on:', 'optin-monster-api'), __('Loads the optin only on the selected posts and/or pages.', 'optin-monster-api'));
                     break 2;
                 case 'categories':
                     $categories = get_categories();
                     if ($categories) {
                         ob_start();
                         wp_category_checklist(0, 0, (array) $value, false, null, true);
                         $cats = ob_get_clean();
                         $ret = $this->get_custom_field('categories', $cats, __('Load optin on post categories:', 'optin-monster-api'));
                     }
                     break;
                 case 'taxonomies':
                     // Attempt to load post tags.
                     $html = '';
                     $tags = get_taxonomy('post_tag');
                     if ($tags) {
                         $tag_terms = get_tags();
                         if ($tag_terms) {
                             $display = (array) $value;
                             $display = isset($display['post_tag']) ? implode(',', $display['post_tag']) : '';
                             $html = $this->get_custom_field($setting, '<input type="hidden" value="' . $display . '" id="omapi-field-' . $setting . '" class="omapi-select-ajax" name="tax_input[post_tag][]" data-placeholder="' . esc_attr__('Type to search and select post tag(s)...', 'optin-monster-api') . '">', __('Load optin on post tags:', 'optin-monster-api'), __('Loads the optin only on the selected post tags.', 'optin-monster-api'));
                         }
                     }
                     // Possibly load taxonomies setting if they exist.
                     $taxonomies = get_taxonomies(array('public' => true, '_builtin' => false));
                     $taxonomies['post_format'] = 'post_format';
                     $data = array();
                     if ($taxonomies) {
                         foreach ($taxonomies as $taxonomy) {
                             $terms = get_terms($taxonomy);
                             if ($terms) {
                                 ob_start();
                                 $display = (array) $value;
                                 $display = isset($display[$taxonomy]) ? $display[$taxonomy] : array();
                                 $tax = get_taxonomy($taxonomy);
                                 $args = array('descendants_and_self' => 0, 'selected_cats' => (array) $display, 'popular_cats' => false, 'walker' => null, 'taxonomy' => $taxonomy, 'checked_ontop' => true);
                                 wp_terms_checklist(0, $args);
                                 $output = ob_get_clean();
                                 if (!empty($output)) {
                                     $data[$taxonomy] = $this->get_custom_field('taxonomies', $output, __('Load optin on ' . strtolower($tax->labels->name) . ':', 'optin-monster-api'));
                                 }
                             }
                         }
                     }
                     // If we have taxonomies, add them to the taxonomies key.
                     if (!empty($data)) {
                         foreach ($data as $setting) {
                             $html .= $setting;
                         }
                     }
                     // Return the data.
                     $ret = $html;
                     break;
                 case 'show':
                     $ret = $this->get_custom_field('show', $this->get_show_fields($value), __('Load optin on post types and archives:', 'optin-monster-api'));
                     break;
                 case 'shortcode':
                     $ret = $this->get_checkbox_field($setting, $value, $id, __('Parse content for shortcodes?', 'optin-monster-api'), __('Optins support shortcodes. If you have added shortcodes to this optin campaign, check this option so they can be executed.', 'optin-monster-api'));
                     break 2;
                 case 'mailpoet':
                     $ret = $this->get_checkbox_field($setting, $value, $id, __('Save lead to MailPoet?', 'optin-monster-api'), __('If checked, successful optin leads will be saved to MailPoet.', 'optin-monster-api'));
                     break 2;
                 case 'mailpoet_list':
                     $ret = $this->get_dropdown_field($setting, $value, $id, $this->get_mailpoet_lists(), __('Add lead to this MailPoet list:', 'optin-monster-api'), __('All successful leads for the optin will be added to this particular MailPoet list.', 'optin-monster-api'));
                     break 2;
             }
             break;
     }
     // Return the setting output.
     return apply_filters('optin_monster_api_setting_ui', $ret, $setting, $id);
 }
Exemple #8
0
 /**
  * Runs the migration through OMAPI_Api
  *
  * @since 1.0.0
  *
  * @return bool
  */
 public function run()
 {
     $this->api->set_additional_data($this->data);
     $response = $this->api->request();
     if (is_wp_error($response)) {
         return false;
     }
     $migration_data = get_option('_om_migration_data', array('migrated_optins' => array()));
     $migration_data['errors'] = false;
     if (property_exists($response, 'imported_optins')) {
         $migration_data['migrated_optins'] = array_merge($migration_data['migrated_optins'], $response->imported_optins);
     }
     if (property_exists($response, 'integrations')) {
         $migration_data['integrations'] = $response->integrations;
     }
     if (property_exists($response, 'site')) {
         $migration_data['site'] = $response->site;
     }
     if (property_exists($response, 'errors')) {
         foreach ($response->errors as $error) {
             $migration_data['errors'][] = $error;
         }
     }
     if (property_exists($response, 'new_optins') && $response->new_optins) {
         foreach ($response->new_optins as $slug => $optin) {
             // Maybe update an optin rather than add a new one.
             $local = $this->base->get_optin_by_slug($slug);
             $data = array();
             if ($local) {
                 $data['ID'] = $local->ID;
                 $data['post_title'] = $optin->title;
                 $data['post_content'] = $optin->output;
                 $data['post_status'] = 'publish';
                 wp_update_post($data);
                 update_post_meta($local->ID, '_omapi_type', $optin->type);
                 update_post_meta($local->ID, '_omapi_ids', $optin->ids);
                 $post_id = $local->ID;
             } else {
                 $data['post_name'] = $slug;
                 $data['post_title'] = $optin->title;
                 $data['post_excerpt'] = $optin->id;
                 $data['post_content'] = $optin->output;
                 $data['post_status'] = 'publish';
                 $data['post_type'] = 'omapi';
                 $post_id = wp_insert_post($data);
                 update_post_meta($post_id, '_omapi_type', $optin->type);
                 update_post_meta($post_id, '_omapi_ids', $optin->ids);
             }
             // Now that the data has been saved, let's now try to grab meta from the previous optin for output settings.
             $prev_optin = get_posts(array('post_type' => 'optin', 'posts_per_page' => 1, 'no_found_rows' => true, 'cache_results' => false, 'name' => $slug));
             if (empty($prev_optin)) {
                 continue;
             }
             // Now grab all the meta for the optin.
             $prev_optin = $prev_optin[0];
             $meta = get_post_meta($prev_optin->ID, '_om_meta', true);
             $test = get_post_meta($prev_optin->ID, '_om_test_mode', true);
             $fields = $this->base->output->fields;
             // Get all the new fields available and store the data.
             foreach ($fields as $field) {
                 $value = false;
                 switch ($field) {
                     case 'enabled':
                         $value = false;
                         // Make sure the optins are disabled by default when being added back.
                         break;
                     case 'global':
                         $value = isset($meta['display']['global']) && $meta['display']['global'] ? true : false;
                         break;
                     case 'automatic':
                         $value = isset($meta['display']['automatic']) && $meta['display']['automatic'] ? true : false;
                         break;
                     case 'users':
                         $value = isset($meta['logged_in']) && $meta['logged_in'] ? 'out' : 'all';
                         break;
                     case 'never':
                         $value = !empty($meta['display']['never']) ? $meta['display']['never'] : array();
                         break;
                     case 'only':
                         $value = !empty($meta['display']['exclusive']) ? $meta['display']['exclusive'] : array();
                         break;
                     case 'categories':
                         $value = !empty($meta['display']['categories']) ? $meta['display']['categories'] : array();
                         break;
                     case 'show':
                         $value = !empty($meta['display']['show']) ? $meta['display']['show'] : array();
                         break;
                     case 'test':
                         $value = $test ? true : false;
                         break;
                     case 'shortcode':
                         $value = false;
                         break;
                     case 'mailpoet':
                         $provider = isset($meta['email']['provider']) ? $meta['email']['provider'] : 'none';
                         $value = 'mailpoet' == $provider ? true : false;
                         // If true, we need to set the MailPoet list as well.
                         if ($value) {
                             $list = isset($meta['email']['list_id']) ? $meta['email']['list_id'] : false;
                             if ($list) {
                                 update_post_meta($post_id, '_omapi_mailpoet_list', $list);
                             }
                         }
                         break;
                     case 'type':
                     case 'ids':
                         $value = get_post_meta($post_id, '_omapi_' . $field, true);
                         break;
                 }
                 update_post_meta($post_id, '_omapi_' . $field, $value);
             }
         }
     }
     update_option('_om_migration_data', $migration_data);
     return true;
 }
Exemple #9
0
 /**
  * Primary class constructor.
  *
  * @since 1.0.0
  *
  * @param string $route  The API route to target.
  * @param array $creds   Array of API credentials.
  * @param string $method The API method.
  */
 public function __construct($route, $creds, $method = 'POST')
 {
     // Set class properties.
     $this->route = $route;
     $this->protocol = $this->is_ssl() ? 'https://' : 'http://';
     $this->url = $this->protocol . $this->base . $this->route . '/';
     $this->method = $method;
     $this->user = $creds['user'];
     $this->key = $creds['key'];
     $this->plugin = OMAPI::get_instance()->plugin_slug;
 }