Permalink
Browse files

added method get_meta_key()

  • Loading branch information...
1 parent d35d57b commit 0241ecf99ea537d44c07c4d659c185b7f986a011 Pär Thernström committed Jan 29, 2013
Showing with 33 additions and 0 deletions.
  1. +3 −0 readme.txt
  2. +22 −0 simple_fields.php
  3. +8 −0 tests/SimpleFieldsTests/SimpleFieldsTest.php
View
@@ -274,6 +274,9 @@ See that "Add"-link above "Article images"? That means that it is repeatable, so
simple_fields_get_extended_return_values_for_field
simple_fields_get_field_group_by_slug
simple_fields_clear_caches
+ simple_fields_get_meta_key_template
+ simple_fields_get_meta_key
+- Added method get_meta_key(). Use it to retrieve the key that simple fields uses for meta/custom fields storage.
- Lotsa code cleanups and stuff
- Fixed so plugin works with jQuery 1.9, because now jQuery(htmlString) requires first char to be < for string to be considered HTML. Was not working due to spaces before first HMTL tag.
View
@@ -3889,6 +3889,28 @@ function get_field_group_by_slug($field_group_slug) {
/**
+ * Get meta key name for a field id + field group id combination
+ *
+ * @param int $field_group_id
+ * @param int field_id
+ * @param int num_in_set
+ * @return string
+ */
+ function get_meta_key($field_group_id = NULL, $field_id = NULL, $num_in_set = 0) {
+
+ if ( ! isset($field_group_id) || ! isset($field_group_id) || ! is_numeric($field_group_id) || ! is_numeric($field_id) || ! is_numeric($num_in_set) ) return FALSE;
+
+ $custom_field_key_template = '_simple_fields_fieldGroupID_%1$d_fieldID_%2$d_numInSet_%3$d';
+ $custom_field_key_template = apply_filters("simple_fields_get_meta_key_template", $custom_field_key_template);
+
+ $custom_field_key = sprintf($custom_field_key_template, $field_group_id, $field_id, $num_in_set);
+ $custom_field_key = apply_filters("simple_fields_get_meta_key", $custom_field_key);
+
+ return $custom_field_key;
+
+ }
+
+ /**
* Returns a field from a fieldgroup using their slugs
*
* @since 1.0.5
@@ -1332,6 +1332,14 @@ function simple_fields_set_value($post_id, $field_slug, $new_numInSet = null, $n
*/
}
+ public function test_misc() {
+
+ // Test meta key
+ $key = $this->sf->get_meta_key(1, 2, 3);
+ $this->assertEquals("_simple_fields_fieldGroupID_1_fieldID_2_numInSet_3", $key);
+
+ }
+
/**
* A contrived example using some WordPress functionality
*/

0 comments on commit 0241ecf

Please sign in to comment.