/** * Activate the power-up and add the defaults */ function add_defaults() { global $wpdb; $options = $this->options; if ($options['li_susbscibe_installed'] != 1 || !is_array($options)) { // conditionals below are a hack for not overwriting the users settings with defaults in 0.8.4 $opt = array('li_susbscibe_installed' => '1', 'li_subscribe_vex_class' => isset($options['li_subscribe_vex_class']) ? $options['li_subscribe_vex_class'] : 'vex-theme-bottom-right-corner', 'li_subscribe_heading' => isset($options['li_subscribe_heading']) ? $options['li_subscribe_heading'] : 'Sign up for email updates', 'li_subscribe_text' => isset($options['li_subscribe_text']) ? $options['li_subscribe_text'] : '', 'li_subscribe_btn_label' => isset($options['li_subscribe_btn_label']) ? $options['li_subscribe_btn_label'] : 'SUBSCRIBE', 'li_subscribe_btn_color' => isset($options['li_subscribe_btn_color']) ? $options['li_subscribe_btn_color'] : 'leadout-popup-color-blue', 'li_subscribe_name_fields' => isset($options['li_subscribe_name_fields']) ? $options['li_subscribe_name_fields'] : '0', 'li_subscribe_phone_field' => isset($options['li_subscribe_phone_field']) ? $options['li_subscribe_phone_field'] : '0', 'li_subscribe_template_posts' => '1', 'li_subscribe_template_pages' => '1', 'li_subscribe_template_archives' => '1', 'li_subscribe_template_home' => '1', 'li_subscribe_mobile_popup' => isset($options['li_subscribe_mobile_popup']) ? $options['li_subscribe_mobile_popup'] : '1'); update_option('leadin_subscribe_options', $opt); // Create smart list for subscribe pop-up $q = $wpdb->prepare("SELECT tag_id FROM {$wpdb->li_tags} WHERE tag_synced_lists LIKE '%%%s%'", ".vex-dialog-form"); $subscriber_list_exists = $wpdb->get_var($q); if (!$subscriber_list_exists) { $tagger = new LI_Tag_Editor(); $tagger->add_tag('Subscribers', '.vex-dialog-form', ''); } } }
/** * Creates list table for Contacts page * */ function leadout_render_tag_list_page() { global $wp_version; if ($this->action == 'delete_tag') { $tag_id = isset($_GET['tag']) ? $_GET['tag'] : FALSE; $tagger = new LI_Tag_Editor($tag_id); $tagger->delete_tag($tag_id); } //Create an instance of our package class... $leadoutTagsTable = new LI_Tags_Table(); // Process any bulk actions before the contacts are grabbed from the database $leadoutTagsTable->process_bulk_action(); //Fetch, prepare, sort, and filter our data... $leadoutTagsTable->data = $leadoutTagsTable->get_tags(); $leadoutTagsTable->prepare_items(); ?> <div class="leadout-contacts"> <?php $this->leadout_header('Manage LeadOut Tags <a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=leadout_tags&action=add_tag" class="add-new-h2">Add New</a>', 'leadout-contacts__header', 'Loaded Tag List'); ?> <div class=""> <!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions --> <form id="" method="GET"> <input type="hidden" name="page" value="<?php echo $_REQUEST['page']; ?> " /> <div class="leadout-contacts__table"> <?php $leadoutTagsTable->display(); ?> </div> <input type="hidden" name="contact_type" value="<?php echo isset($_GET['contact_type']) ? $_GET['contact_type'] : ''; ?> "/> <?php if (isset($_GET['filter_content'])) { ?> <input type="hidden" name="filter_content" value="<?php echo isset($_GET['filter_content']) ? stripslashes($_GET['filter_content']) : ''; ?> "/> <?php } ?> <?php if (isset($_GET['filter_action'])) { ?> <input type="hidden" name="filter_action" value="<?php echo isset($_GET['filter_action']) ? $_GET['filter_action'] : ''; ?> "/> <?php } ?> </form> </div> </div> <?php }
/** * Process bulk actions for deleting */ function process_bulk_action() { global $wpdb; $ids_for_action = ''; $hashes_for_action = ''; if (strstr($this->current_action(), 'delete')) { if ('delete_selected' === $this->current_action()) { for ($i = 0; $i < count($_GET['contact']); $i++) { $ids_for_action .= $_GET['contact'][$i]; if ($i != count($_GET['contact']) - 1) { $ids_for_action .= ','; } } } else { if ('delete_all' === $this->current_action()) { $contacts = $this->get_contacts(); foreach ($contacts as $contact) { $ids_for_action .= $contact['ID'] . ','; } $ids_for_action = rtrim($ids_for_action, ','); } else { // default case for when it's not actually processing a bulk action return FALSE; } } $q = $wpdb->prepare("SELECT hashkey FROM {$wpdb->li_leads} WHERE lead_id IN ( " . $ids_for_action . " ) ", ""); $hashes = $wpdb->get_results($q); if (count($hashes)) { foreach ($hashes as $hash) { $hashes_for_action .= "'" . $hash->hashkey . "',"; } $hashes_for_action = rtrim($hashes_for_action, ','); $q = $wpdb->prepare("UPDATE {$wpdb->li_pageviews} SET pageview_deleted = 1 WHERE lead_hashkey IN (" . $hashes_for_action . ") ", ""); $delete_pageviews = $wpdb->query($q); $q = $wpdb->prepare("UPDATE {$wpdb->li_submissions} SET form_deleted = 1 WHERE lead_hashkey IN (" . $hashes_for_action . ") ", ""); $delete_submissions = $wpdb->query($q); $q = $wpdb->prepare("UPDATE {$wpdb->li_leads} SET lead_deleted = 1 WHERE lead_id IN (" . $ids_for_action . ") ", ""); $delete_leads = $wpdb->query($q); $q = $wpdb->prepare("UPDATE {$wpdb->li_tag_relationships} SET tag_relationship_deleted = 1 WHERE contact_hashkey IN (" . $hashes_for_action . ") ", ""); $delete_tags = $wpdb->query($q); } } if (isset($_POST['bulk_edit_tags'])) { $q = $wpdb->prepare("SELECT tag_id FROM {$wpdb->li_tags} WHERE tag_slug = %s ", $_POST['bulk_selected_tag']); $tag_id = $wpdb->get_var($q); if (empty($_POST['leadout_selected_contacts'])) { $contacts = $this->get_contacts(); foreach ($contacts as $contact) { $ids_for_action .= $contact['ID'] . ','; } $ids_for_action = rtrim($ids_for_action, ','); } else { $ids_for_action = $_POST['leadout_selected_contacts']; } $q = $wpdb->prepare("\n SELECT \n l.hashkey, l.lead_email,\n ( SELECT ltr.tag_id FROM {$wpdb->li_tag_relationships} ltr WHERE ltr.tag_id = %d AND ltr.contact_hashkey = l.hashkey GROUP BY ltr.contact_hashkey ) AS tag_set \n FROM \n {$wpdb->li_leads} l\n WHERE \n l.lead_id IN ( " . $ids_for_action . " ) AND l.lead_deleted = 0 GROUP BY l.lead_id", $tag_id); $contacts = $wpdb->get_results($q); $insert_values = ''; $contacts_to_update = ''; if (count($contacts)) { foreach ($contacts as $contact) { if ($contact->tag_set === NULL) { $insert_values .= '(' . $tag_id . ', "' . $contact->hashkey . '"),'; } else { $contacts_to_update .= "'" . $contact->hashkey . "',"; } } } if ($_POST['bulk_edit_tag_action'] == 'add_tag') { if ($insert_values) { $q = "INSERT INTO {$wpdb->li_tag_relationships} ( tag_id, contact_hashkey ) VALUES " . rtrim($insert_values, ','); $wpdb->query($q); } if ($contacts_to_update) { // update the relationships for the contacts that exist already making sure to set all the tag_relationship_deleted = 0 $q = $wpdb->prepare("UPDATE {$wpdb->li_tag_relationships} SET tag_relationship_deleted = 0 WHERE tag_id = %d AND contact_hashkey IN ( " . rtrim($contacts_to_update, ',') . ") ", $tag_id); $wpdb->query($q); } // Bulk push all the email addresses for the tag to the MailChimp API $tagger = new LI_Tag_Editor($tag_id); $tagger->push_contacts_to_tagged_list($tag_id); } else { if ($contacts_to_update) { // "Delete" the existing tags only $q = $wpdb->prepare("UPDATE {$wpdb->li_tag_relationships} SET tag_relationship_deleted = 1 WHERE tag_id = %d AND contact_hashkey IN ( " . rtrim($contacts_to_update, ',') . ") ", $tag_id); $wpdb->query($q); } } } }