public function add_db_table() { global $wpdb; $table_name = $wpdb->prefix . "prelaunchr"; $sql = "CREATE TABLE {$table_name} (\n\t\t\tid INT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\ttime INT NOT NULL,\n\t\t\temail VARCHAR(254) NOT NULL,\n\t\t\tpid VARCHAR(36) NOT NULL,\n\t\t\trid INT(20) UNSIGNED,\n\t\t\tKEY pid (pid),\n\t\t\tKEY time (time),\n\t\t\tPRIMARY KEY id (id),\n\t\t\tUNIQUE (email,pid)\n\t\t);"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; if (function_exists('dbDelta')) { dbDelta($sql); } add_option('prelaunchr_db_version', Prelaunchr()->get_version()); }
function prelaunchr_referral_progress() { Prelaunchr()->prelaunchr_get_template_part('thankyou/referral-progress'); }
/** * Output the reward meta box HTML * * @param WP_Post $object Current post object * @param array $box Metabox information */ public function do_reward_meta_box($object, $box) { wp_nonce_field(basename(__FILE__), 'prelaunchr-reward'); ?> <p> <label for='prelaunchr-referrals-needed'> <?php _e('Referrals Needed:', Prelaunchr()->get_plugin_name()); ?> <input type='number' id='prelaunchr-referrals-needed' name='prelaunchr-referrals-needed' value='<?php echo esc_attr(get_post_meta($object->ID, '_prelaunchr-referrals-needed', true)); ?> ' /> </label> </p> <?php }
public function record_submission() { global $wpdb; check_ajax_referer(__FILE__, 'nonce'); $data = array(); $format = array(); $email = $wpdb->_real_escape(stripslashes($_POST['email'])); /** * Allow devs to hook in */ do_action('prelaunchr_record_submission', $email, $data, $format); /** * Check if email is valid */ $email = $this->is_valid_email($email); if (!$email) { wp_send_json_error(__('Invalid Email', Prelaunchr()->get_plugin_name())); } /** * If akismet is installed check the email against akismet */ if ($this->akismet_available()) { $request = 'blog=' . urlencode(wp_unslash((string) site_url())) . '&user_ip=' . urlencode(wp_unslash((string) $this->get_ip_address())) . '&user_agent=' . urlencode(wp_unslash((string) $this->get_user_agent())) . '&referrer=' . urlencode(wp_unslash((string) $this->get_referer())) . '&comment_type=' . urlencode('email') . '&comment_author_email=' . urlencode(wp_unslash((string) $email)); if ($this->akismet_check($request)) { wp_send_json_error(__('Spam detected - If this is an error please contact us directly', Prelaunchr()->get_plugin_name())); } } /** * Check if the email already exists in our list */ if ($this->email_exists($email)) { $url = get_permalink($this->get_post_with_shortcode()) . (parse_url(untrailingslashit(get_permalink($this->get_post_with_shortcode())), PHP_URL_QUERY) ? '&' : '?'); wp_send_json_error(sprintf(__('Thanks we have already recorded your interest. Check your referrals <a href="%s">here</a>.', Prelaunchr()->get_plugin_name()), esc_url($url . 'pid=' . $this->get_pid_from_email($email)))); } $data['email'] = $email; $format[] = '%s'; /** * Get the time of the submission */ $data['time'] = time(); $format[] = '%d'; /** * PID - Inidividual Prelaunchr ID (PID) for each email */ if (isset($_POST['pid'])) { $data['pid'] = $this->valid_uuid($_POST['pid']); } else { $data['pid'] = 0; } $format[] = '%s'; /** * RID - Referrer ID (RID) */ if (isset($_POST['rid'])) { $data['rid'] = $this->get_referrer_id($this->valid_uuid($_POST['rid'])); } else { $data['rid'] = 0; } $format[] = '%s'; /** * Allow devs to filter the data before storing */ apply_filters('prelaunchr_record_submission', $data, $format); /** * Insert submission into database. */ global $wpdb; $result = $wpdb->insert($wpdb->prefix . "prelaunchr", $data, $format); /** * Allow devs to hook in */ do_action('prelaunchr_after_record_submission', $result, $data, $format); if ($result === false) { wp_send_json_error(__('Oops there was an error updating our records, please contact us directly (1)', Prelaunchr()->get_plugin_name())); } else { if ($result === 0) { wp_send_json_error(__('Oops there was an error updating our records, please contact us directly (2)', Prelaunchr()->get_plugin_name())); } else { if ($result > 0) { wp_send_json_success($data); } } } }
<h2><?php _e("Here's how it works", Prelaunchr()->get_plugin_name()); ?> </h2> <p><?php printf(__('You currently have %d Referrals!', Prelaunchr()->get_plugin_name()), $referrals); ?> </p> <div class="referrals"> <ul class="labels"> <li class="referrals"><?php _e("Referrals", Prelaunchr()->get_plugin_name()); ?> </li> <li class="rewards"><?php _e("Rewards", Prelaunchr()->get_plugin_name()); ?> </li> </ul> <ul class="referral-progress"> <li class="reward"> <div class="referrals">0</div> </li> <?php foreach ($rewards as $post) { setup_postdata($post); ?> <?php $reward_friends = get_post_meta($post->ID, '_prelaunchr-referrals-needed', true); $reward_percentage = $reward_friends / $max * 100; ?>
<?php /** * File Security Check */ if (!empty($_SERVER['SCRIPT_FILENAME']) && basename(__FILE__) == basename($_SERVER['SCRIPT_FILENAME'])) { die('You do not have sufficient permissions to access this page!'); } $pid = Prelaunchr()->valid_uuid($_GET['pid']); if ($pid) { $url = get_permalink() . (parse_url(untrailingslashit(get_permalink()), PHP_URL_QUERY) ? '&' : '?') . 'ref=' . $pid; ?> <div id="referral-link" ><?php echo $url; ?> </div> <?php }
/** ************************************************************************ * REQUIRED! This method dictates the table's columns and titles. This should * return an array where the key is the column slug (and class) and the value * is the column's title text. If you need a checkbox for bulk actions, refer * to the $columns array below. * * The 'cb' column is treated differently than the rest. If including a checkbox * column in your table you must create a column_cb() method. If you don't need * bulk actions or checkboxes, simply leave the 'cb' entry out of your array. * * @see WP_List_Table::::single_row_columns() * @return array An associative array containing column information: 'slugs'=>'Visible Titles' **************************************************************************/ function get_columns() { $columns = array('cb' => '<input type="checkbox" />', 'email' => __('Email', Prelaunchr()->get_plugin_name()), 'referrals' => __('Referrals', Prelaunchr()->get_plugin_name()), 'referrer' => __('Referred By', Prelaunchr()->get_plugin_name()), 'time' => __('Time', Prelaunchr()->get_plugin_name()), 'pid' => __('ID', Prelaunchr()->get_plugin_name())); return $columns; }