/**
  * Collect metadata from all boxes.
  */
 function save_post($post_id, $post)
 {
     if ('revision' == $post->post_type || defined('DOING_AJAX')) {
         return;
     }
     if (isset($_POST['p2p_connections'])) {
         // Loop through the hidden fields instead of through $_POST['p2p_meta'] because empty checkboxes send no data.
         foreach ($_POST['p2p_connections'] as $p2p_id) {
             $data = scbForms::get_value(array('p2p_meta', $p2p_id), $_POST, array());
             $connection = p2p_get_connection($p2p_id);
             if (!$connection) {
                 continue;
             }
             $fields = p2p_type($connection->p2p_type)->fields;
             foreach ($fields as $key => &$field) {
                 $field['name'] = $key;
             }
             $data = scbForms::validate_post_data($fields, $data);
             scbForms::update_meta($fields, $data, $p2p_id, 'p2p');
         }
     }
     // Ordering
     if (isset($_POST['p2p_order'])) {
         foreach ($_POST['p2p_order'] as $key => $list) {
             foreach ($list as $i => $p2p_id) {
                 p2p_update_meta($p2p_id, $key, $i);
             }
         }
     }
 }
 function __set($key, $val)
 {
     p2p_update_meta($this->p2p_id, $key, $val);
 }
 /**
  * Collect metadata from all boxes.
  */
 static function save_post($post_id, $post)
 {
     if ('revision' == $post->post_type || defined('DOING_AJAX')) {
         return;
     }
     // Custom fields
     if (isset($_POST['p2p_types'])) {
         foreach ($_POST['p2p_types'] as $p2p_type) {
             $ctype = p2p_type($p2p_type);
             if (!$ctype) {
                 continue;
             }
             foreach ($ctype->get_connections($post_id) as $p2p_id => $item_id) {
                 $data = scbForms::get_value(array('p2p_meta', $p2p_id), $_POST, array());
                 foreach (self::$box_args[$p2p_type]->fields as $key => $field_args) {
                     if ('checkbox' == $field_args['type']) {
                         $new_values = scbForms::get_value($key, $data, array());
                         $old_values = p2p_get_meta($p2p_id, $key);
                         foreach (array_diff($new_values, $old_values) as $value) {
                             p2p_add_meta($p2p_id, $key, $value);
                         }
                         foreach (array_diff($old_values, $new_values) as $value) {
                             p2p_delete_meta($p2p_id, $key, $value);
                         }
                     } else {
                         p2p_update_meta($p2p_id, $key, $data[$key]);
                     }
                 }
             }
         }
     }
     // Ordering
     if (isset($_POST['p2p_order'])) {
         foreach ($_POST['p2p_order'] as $key => $list) {
             foreach ($list as $i => $p2p_id) {
                 p2p_update_meta($p2p_id, $key, $i);
             }
         }
     }
 }
Exemple #4
0
/**
 * AJAX Handler for saving all steps
 *
 * @since 1.0.0
 * @return void
 */
function badgeos_update_steps_ajax_handler()
{
    // Only continue if we have any steps
    if (isset($_POST['steps'])) {
        // Grab our $wpdb global
        global $wpdb;
        // Setup an array for storing all our step titles
        // This lets us dynamically update the Label field when steps are saved
        $new_titles = array();
        // Loop through each of the created steps
        foreach ($_POST['steps'] as $key => $step) {
            // Grab all of the relevant values of that step
            $step_id = $step['step_id'];
            $required_count = !empty($step['required_count']) ? $step['required_count'] : 1;
            $trigger_type = $step['trigger_type'];
            $achievement_type = $step['achievement_type'];
            // Clear all relation data
            $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->p2p} WHERE p2p_to=%d", $step_id));
            delete_post_meta($step_id, '_badgeos_achievement_post');
            // Flip between our requirement types and make an appropriate connection
            switch ($trigger_type) {
                // Connect the step to ANY of the given achievement type
                case 'any-achievement':
                    $title = sprintf(__('any %s', 'badgeos'), $achievement_type);
                    break;
                case 'all-achievements':
                    $title = sprintf(__('all %s', 'badgeos'), $achievement_type);
                    break;
                case 'specific-achievement':
                    p2p_create_connection($step['achievement_type'] . '-to-step', array('from' => absint($step['achievement_post']), 'to' => $step_id, 'meta' => array('date' => current_time('mysql'))));
                    $title = '"' . get_the_title($step['achievement_post']) . '"';
                    break;
                case 'badgeos_specific_new_comment':
                    update_post_meta($step_id, '_badgeos_achievement_post', absint($step['achievement_post']));
                    $title = sprintf(__('comment on post %d', 'badgeos'), $step['achievement_post']);
                    break;
                default:
                    $triggers = badgeos_get_activity_triggers();
                    $title = $triggers[$trigger_type];
                    break;
            }
            // Update the step order
            p2p_update_meta(badgeos_get_p2p_id_from_child_id($step_id), 'order', $key);
            // Update our relevant meta
            update_post_meta($step_id, '_badgeos_count', $required_count);
            update_post_meta($step_id, '_badgeos_trigger_type', $trigger_type);
            update_post_meta($step_id, '_badgeos_achievement_type', $achievement_type);
            // Available hook for custom Activity Triggers
            $custom_title = sprintf(__('Earn %1$s %2$s.', 'badgeos'), $title, sprintf(_n('%d time', '%d times', $required_count), $required_count));
            $custom_title = apply_filters('badgeos_save_step', $custom_title, $step_id, $step);
            // Update our original post with the new title
            $post_title = !empty($step['title']) ? $step['title'] : $custom_title;
            wp_update_post(array('ID' => $step_id, 'post_title' => $post_title));
            // Add the title to our AJAX return
            $new_titles[$step_id] = stripslashes($post_title);
        }
        // Send back all our step titles
        echo json_encode($new_titles);
    }
    // Cave Johnson. We're done here.
    die;
}
Exemple #5
0
/** Refuse candidate as task doer */
function ajax_refuse_candidate()
{
    $_POST['nonce'] = empty($_POST['nonce']) ? '' : trim($_POST['nonce']);
    if (empty($_POST['link-id']) || empty($_POST['doer-id']) || empty($_POST['task-id']) || empty($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], $_POST['link-id'] . '-candidate-refuse-' . $_POST['doer-id'])) {
        die(json_encode(array('status' => 'fail', 'message' => __('<strong>Error:</strong> wrong data given.', 'tst'))));
    }
    p2p_update_meta($_POST['link-id'], 'is_approved', false);
    // Send email to the task doer:
    $task = get_post($_POST['task-id']);
    $doer = get_user_by('id', $_POST['doer-id']);
    tst_actualize_member_role($_POST['doer-id']);
    global $email_templates;
    //    add_filter('wp_mail_content_type', function(){
    //        return 'text/html';
    //    });
    wp_mail(get_user_by('id', $_POST['doer-id'])->user_email, $email_templates['refuse_candidate_doer_notice']['title'], nl2br(sprintf($email_templates['refuse_candidate_doer_notice']['text'], $doer->first_name, $task->post_title)));
    // Task is automatically switched "publish":
    wp_update_post(array('ID' => $_POST['task-id'], 'post_status' => 'publish'));
    die(json_encode(array('status' => 'ok')));
}
 function attach_domain($domain_id)
 {
     $domains = $this->get_domains();
     if ($domains) {
         foreach ($domains as $domain) {
             if (intval($domain_id) === $domain->ID && !$this->is_domain_attached($domain->post_title)) {
                 $p2p_id = p2p_type(foolic_post_relationships::LICENSEKEY_TO_DOMAINS)->get_p2p_id($this->ID, $domain->ID);
                 if ($p2p_id) {
                     //we found the detached domain. Only attach if already detached
                     p2p_update_meta($p2p_id, 'attached', '1');
                     //update all our domains
                     $this->process_domains();
                     return true;
                 }
             }
         }
     }
     return false;
 }
function sfhiv_group_members_save_connection_info($post_ID)
{
    if (get_post_type($post_ID) != 'sfhiv_group') {
        return;
    }
    if (!isset($_POST['sfhiv-group-member'])) {
        return;
    }
    $connections = $_POST['sfhiv-group-member'];
    foreach ($connections as $id => $connection) {
        foreach ($connection as $key => $value) {
            p2p_update_meta($id, $key, $value);
        }
    }
}