public function setUp() { parent::setUp(); global $wp_rewrite, $wp_query; $GLOBALS['wp_rewrite']->init(); flush_rewrite_rules(false); $this->_api = new Give_API(); $roles = new Give_Roles(); $roles->add_roles(); $roles->add_caps(); $this->_api->add_endpoint($wp_rewrite); $this->_rewrite = $wp_rewrite; $this->_query = $wp_query; //Create a Donation Form $post_id = $this->factory->post->create(array('post_title' => 'Test Form', 'post_type' => 'give_forms', 'post_status' => 'publish')); $this->_user_id = $this->factory->user->create(array('role' => 'administrator')); wp_set_current_user($this->_user_id); $_multi_level_donations = array(array('_give_id' => array('level_id' => '1'), '_give_amount' => '10.00', '_give_text' => 'Basic Level'), array('_give_id' => array('level_id' => '2'), '_give_amount' => '20.00', '_give_text' => 'Intermediate Level'), array('_give_id' => array('level_id' => '3'), '_give_amount' => '40.00', '_give_text' => 'Advanced Level')); $meta = array('give_price' => '0.00', '_give_price_option' => 'multi', '_give_price_options_mode' => 'on', '_give_donation_levels' => array_values($_multi_level_donations), 'give_product_notes' => 'Donation Notes', '_give_product_type' => 'default'); foreach ($meta as $key => $value) { update_post_meta($post_id, $key, $value); } $this->_post = get_post($post_id); //Generate Donations $user = get_userdata(1); $user_info = array('id' => $user->ID, 'email' => '*****@*****.**', 'first_name' => $user->first_name, 'last_name' => $user->last_name); $donation_details = array(array('id' => $post_id, 'options' => array('price_id' => 1))); $total = 0; $prices = get_post_meta($donation_details[0]['id'], '_give_donation_levels', true); $item_price = $prices[1]['_give_amount']; $total += $item_price; $purchase_data = array('price' => number_format((double) $total, 2), 'give_form_title' => get_the_title($post_id), 'give_form_id' => $post_id, 'date' => date('Y-m-d H:i:s', strtotime('-1 day')), 'purchase_key' => strtolower(md5(uniqid())), 'user_email' => $user_info['email'], 'user_info' => $user_info, 'currency' => 'USD', 'status' => 'pending', 'gateway' => 'manual'); $_SERVER['REMOTE_ADDR'] = '10.0.0.0'; $_SERVER['SERVER_NAME'] = 'give_virtual'; $payment_id = give_insert_payment($purchase_data); give_update_payment_status($payment_id, 'complete'); $this->_api_output = $this->_api->get_forms(); $this->_api_output_sales = $this->_api->get_recent_donations(); global $wp_query; $wp_query->query_vars['format'] = 'override'; }
/** * Install user roles on sub-sites of a network * * Roles do not get created when Give is network activation so we need to create them during admin_init * * @since 1.0 * @return void */ function give_install_roles_on_network() { global $wp_roles; if (!is_object($wp_roles)) { return; } if (!array_key_exists('give_manager', $wp_roles->roles)) { // Create Give shop roles $roles = new Give_Roles(); $roles->add_roles(); $roles->add_caps(); } }
/** * Cleanup User Roles * * This upgrade routine removes unused roles and roles with typos * * @since 1.5.2 */ function give_v152_cleanup_users() { $give_version = get_option('give_version'); if (!$give_version) { // 1.0 is the first version to use this option so we must add it $give_version = '1.0'; } $give_version = preg_replace('/[^0-9.].*/', '', $give_version); //v1.5.2 Upgrades if (version_compare($give_version, '1.5.2', '<') || !give_has_upgrade_completed('upgrade_give_user_caps_cleanup')) { //Delete all caps with "ss" //Also delete all unused "campaign" roles $delete_caps = array('delete_give_formss', 'delete_others_give_formss', 'delete_private_give_formss', 'delete_published_give_formss', 'read_private_forms', 'edit_give_formss', 'edit_others_give_formss', 'edit_private_give_formss', 'edit_published_give_formss', 'publish_give_formss', 'read_private_give_formss', 'assign_give_campaigns_terms', 'delete_give_campaigns', 'delete_give_campaigns_terms', 'delete_give_campaignss', 'delete_others_give_campaignss', 'delete_private_give_campaignss', 'delete_published_give_campaignss', 'edit_give_campaigns', 'edit_give_campaigns_terms', 'edit_give_campaignss', 'edit_others_give_campaignss', 'edit_private_give_campaignss', 'edit_published_give_campaignss', 'manage_give_campaigns_terms', 'publish_give_campaignss', 'read_give_campaigns', 'read_private_give_campaignss', 'view_give_campaigns_stats', 'delete_give_paymentss', 'delete_others_give_paymentss', 'delete_private_give_paymentss', 'delete_published_give_paymentss', 'edit_give_paymentss', 'edit_others_give_paymentss', 'edit_private_give_paymentss', 'edit_published_give_paymentss', 'publish_give_paymentss', 'read_private_give_paymentss'); global $wp_roles; foreach ($delete_caps as $cap) { foreach (array_keys($wp_roles->roles) as $role) { $wp_roles->remove_cap($role, $cap); } } // Create Give plugin roles $roles = new Give_Roles(); $roles->add_roles(); $roles->add_caps(); //The Update Ran update_option('give_version', preg_replace('/[^0-9.].*/', '', GIVE_VERSION)); give_set_upgrade_complete('upgrade_give_user_caps_cleanup'); delete_option('give_doing_upgrade'); } }