コード例 #1
0
ファイル: functions.php プロジェクト: INN/pmp-distribution
/**
 * Save/push updated distribution options (for distributors)
 *
 * @since 0.0.1
 */
function pmp_save_dist_options($post_id)
{
    if (!isset($_POST['pmp_save_dist_options'])) {
        return;
    }
    $sdk = new SDKWrapper();
    $pmp_guid = get_post_meta($post_id, 'pmp_guid', true);
    $pmp_doc = $sdk->fetchDoc($pmp_guid);
    $types = array('series', 'property');
    foreach ($types as $type) {
        $meta_key = 'pmp_' . $type . '_override';
        // Indicate that the $type was explicitly net to false
        if (!isset($_POST[$meta_key]) || empty($_POST[$meta_key])) {
            $collection_guid = false;
        } else {
            $collection_guid = $_POST[$meta_key];
        }
        if (!empty($collection_guid)) {
            $existing_guids = array();
            if (!isset($pmp_doc->links->collection)) {
                $pmp_doc->links->collection = array();
            } else {
                $existing_guids = array_map(function ($item) {
                    return SDKWrapper::guid4href($item->href);
                }, $pmp_doc->links->collection);
            }
            foreach ((array) $collection_guid as $guid) {
                // Preserve existing $profile links, only add ours
                if (!in_array($guid, $existing_guids)) {
                    $pmp_doc->links->collection[] = (object) array('href' => $sdk->href4guid($guid), 'rels' => array("urn:collectiondoc:collection:{$type}"));
                }
            }
        } else {
            // Unset the values that belong to us
            $our_collection_guids = (array) get_post_meta($post_id, $meta_key . '_distribution', true);
            $new_collections = array();
            foreach ($pmp_doc->links->collection as $collection) {
                if (!in_array(SDKWrapper::guid4href($collection->href), $our_collection_guids)) {
                    array_push($new_collections, $collection);
                }
            }
            $pmp_doc->links->collection = $new_collections;
        }
        update_post_meta($post_id, $meta_key . '_distribution', $collection_guid);
    }
    $pmp_doc->save();
}
コード例 #2
0
ファイル: ajax.php プロジェクト: jackbrighton/pmp-wordpress
/**
 * Ajax function to save a group's users
 *
 * @since 0.2
 */
function pmp_save_users()
{
    check_ajax_referer('pmp_ajax_nonce', 'security');
    $group_data = json_decode(stripslashes($_POST['data']));
    $sdk = new SDKWrapper();
    $group = $sdk->fetchDoc($group_data->group_guid);
    if (!empty($group_data->user_guids)) {
        $group->links->item = array();
        foreach ($group_data->user_guids as $user_guid) {
            $link_item = new \stdClass();
            $link_item->href = $sdk->href4guid($user_guid);
            $group->links->item[] = $link_item;
        }
    } else {
        unset($group->links->item);
    }
    $group->save();
    print json_encode(array("success" => true, "data" => SDKWrapper::prepFetchData($group)));
    wp_die();
}