Skip to content

Instantly share code, notes, and snippets.

@seedprod
Created October 23, 2020 14:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save seedprod/b8abe1d0076c4281e6e19a679baacaae to your computer and use it in GitHub Desktop.
Save seedprod/b8abe1d0076c4281e6e19a679baacaae to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: RafflePress Invent Your Own
Plugin URI:
Description: Programmatically Add User and Complete Actions in RafflePress
Version:
Author:
Author URI:
License:
License URI:
*/
function rp_iyo(){
// Set the giveaway and action id
$giveaway_id = '75';
$action_id = '9chrxc';
$action_name = 'Completed Survey';
$email = 'test@example.com';
$fname = 'John';
$lname = 'Test';
$entries_earned = 3;
// Programmatically add Contestant to Giveaway
global $wpdb;
$tablename = $wpdb->prefix . 'rafflepress_contestants';
$sql = "SELECT id FROM $tablename WHERE email = %s AND giveaway_id = %d";
$safe_sql = $wpdb->prepare($sql, $email, $giveaway_id);
$contestant_id = $wpdb->get_var($safe_sql);
if(empty($contestant_id)){
$wpdb->insert(
$tablename,
array(
'giveaway_id' => $giveaway_id,
'email' => $email,
'fname' => $fname,
'lname' => $lname,
),
array(
'%d',
'%s',
'%s',
'%s',
)
);
}
// Programmatically Complete Invent Your Own Action
$entries_tablename = $wpdb->prefix . 'rafflepress_entries';
$insert_arrays = array();
$entry_meta['action'] = $action_name;
for ($i = 1; $i <= $entries_earned; $i++) {
$insert_arrays[] = array(
'giveaway_id' =>$giveaway_id,
'contestant_id' => $contestant_id,
'action_id' => $action_id,
'meta' => wp_json_encode($entry_meta),
);
}
rafflepress_pro_wp_insert_rows($insert_arrays, $entries_tablename);
}
add_action( 'plugins_loaded', 'rp_iyo' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment