/** * Generates checksums for defined content types. * * @param type $type * @param type $item_id * @return type */ function generate_checksum($type, $item_id = null) { switch ($type) { case 'group': $checksum = wpcf_admin_fields_get_group($item_id); $checksum['meta'] = $this->get_group_meta($item_id); ksort($checksum['meta']); break; case 'field': $checksum = wpcf_admin_fields_get_field($item_id); break; case 'custom_post_type': $checksum = wpcf_get_custom_post_type_settings($item_id); $checksum['relationship_settings']['has'] = wpcf_pr_get_has($item_id); if (is_array($checksum['relationship_settings']['has'])) { ksort($checksum['relationship_settings']['has']); } $checksum['relationship_settings']['belongs'] = wpcf_pr_get_belongs($item_id); if (is_array($checksum['relationship_settings']['belongs'])) { ksort($checksum['relationship_settings']['belongs']); } break; case 'custom_taxonomy': $checksum = wpcf_get_custom_taxonomy_settings($item_id); break; default: /* * Enable $this->generate_checksum('test'); */ $checksum = $type; break; } // Unset various not wanted data foreach ($this->_remove_data_keys as $key) { if (isset($checksum[$key])) { unset($checksum[$key]); } } if (is_array($checksum)) { ksort($checksum); } // debug( $checksum, false ); return md5(maybe_serialize($checksum)); }
/** * Gets all posts that belong to queried post, grouped by post type. * * @param type $post_id * @param type $post_type * @return type */ function wpcf_pr_post_get_has($post_id, $post_type_q = null) { $post_type = get_post_type($post_id); $has = array_keys(wpcf_pr_get_has($post_type)); $add = is_null($post_type_q) ? '&post_type=any' : '&post_type=' . $post_type_q; $posts = get_posts('numberposts=-1&post_status=null&meta_key=_wpcf_belongs_' . $post_type . '_id&meta_value=' . $post_id . $add); $results = array(); foreach ($posts as $post) { if (!in_array($post->post_type, $has)) { continue; } $results[$post->post_type][] = $post; } return is_null($post_type_q) ? $results : array_shift($results); }