Beispiel #1
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);
 }