Skip to content

Commit 1de1771

Browse files
committed
Formatting code.
1 parent d23b2a8 commit 1de1771

File tree

1 file changed

+71
-71
lines changed

1 file changed

+71
-71
lines changed

wordpress-custom-fields-permalink-plugin.php

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -10,88 +10,88 @@
1010

1111
class CustomFieldsPermalink {
1212

13-
const PARAM_CUSTOMFIELD_KEY = 'custom_field_key';
14-
const PARAM_CUSTOMFIELD_VALUE = 'custom_field_value';
13+
const PARAM_CUSTOMFIELD_KEY = 'custom_field_key';
14+
const PARAM_CUSTOMFIELD_VALUE = 'custom_field_value';
1515

1616
public static $checkCustomFieldValue = false;
17-
18-
public static function linkPost($permalink, $post, $leavename) {
19-
return self::linkRewriteFields($permalink, $post);
20-
}
21-
22-
public static function linkPostType($permalink, $post, $leavename, $sample) {
23-
return self::linkRewriteFields($permalink, $post);
24-
}
25-
26-
protected static function linkRewriteFields($permalink, $post) {
27-
return preg_replace('#(%field_(.*?)%)#e', 'CustomFieldsPermalink::linkRewriteFieldsExtract($post, "\\2")', $permalink);
28-
}
29-
30-
public static function linkRewriteFieldsExtract($post, $fieldName) {
31-
$postMeta = get_post_meta($post->ID);
32-
33-
if(!isset($postMeta[$fieldName]))
34-
return '';
35-
36-
$value = implode('', $postMeta[$fieldName]);
17+
18+
public static function linkPost($permalink, $post, $leavename) {
19+
return self::linkRewriteFields($permalink, $post);
20+
}
21+
22+
public static function linkPostType($permalink, $post, $leavename, $sample) {
23+
return self::linkRewriteFields($permalink, $post);
24+
}
25+
26+
protected static function linkRewriteFields($permalink, $post) {
27+
return preg_replace('#(%field_(.*?)%)#e', 'CustomFieldsPermalink::linkRewriteFieldsExtract($post, "\\2")', $permalink);
28+
}
29+
30+
public static function linkRewriteFieldsExtract($post, $fieldName) {
31+
$postMeta = get_post_meta($post->ID);
32+
33+
if(!isset($postMeta[$fieldName]))
34+
return '';
35+
36+
$value = implode('', $postMeta[$fieldName]);
3737

3838
$value = sanitize_title($value);
3939

4040
return $value;
41-
}
42-
43-
public static function registerExtraQueryVars($value) {
44-
array_push($value, self::PARAM_CUSTOMFIELD_KEY, self::PARAM_CUSTOMFIELD_VALUE);
45-
return $value;
46-
}
47-
48-
public static function processRequest($value) {
49-
// additional parameters added to Wordpress
50-
// Main Loop query
51-
$value['meta_key'] = $value[self::PARAM_CUSTOMFIELD_KEY];
41+
}
42+
43+
public static function registerExtraQueryVars($value) {
44+
array_push($value, self::PARAM_CUSTOMFIELD_KEY, self::PARAM_CUSTOMFIELD_VALUE);
45+
return $value;
46+
}
47+
48+
public static function processRequest($value) {
49+
// additional parameters added to Wordpress
50+
// Main Loop query
51+
$value['meta_key'] = $value[self::PARAM_CUSTOMFIELD_KEY];
5252

5353
// do not check field's value for this moment
5454
if(true === self::$checkCustomFieldValue) {
5555
$value['meta_value'] = $value[self::PARAM_CUSTOMFIELD_VALUE];
56-
}
56+
}
57+
58+
// remove temporary injected parameters
59+
unset($value[self::PARAM_CUSTOMFIELD_KEY], $value[self::PARAM_CUSTOMFIELD_VALUE]);
60+
61+
return $value;
62+
}
63+
64+
public static function rewriteRulesArrayFilter($rules) {
65+
$keys = array_keys($rules);
66+
$tmp = $rules;
67+
$rules = array();
68+
69+
for($i = 0, $j = sizeof($keys); $i < $j; ++$i) {
70+
$key = $keys[$i];
71+
72+
if (preg_match('/%field_([^%]*?)%/', $key)) {
73+
$keyNew = preg_replace(
74+
'/%field_([^%]*?)%/',
75+
'([^/]+)',
76+
// you can simply add next group to the url, because WordPress
77+
// detect them automatically and add next $matches indiceis
78+
$key
79+
);
80+
$rules[$keyNew] = preg_replace(
81+
'/%field_([^%]*?)%/',
82+
sprintf('%s=$1&%s=', self::PARAM_CUSTOMFIELD_KEY, self::PARAM_CUSTOMFIELD_VALUE),
83+
// here on the end will be pasted $matches[$i] from $keyNew, so we can
84+
// grab it it the future in self::PARAM_CUSTOMFIELD_VALUE parameter
85+
$tmp[$key]
86+
);
87+
}
88+
else {
89+
$rules[$key] = $tmp[$key];
90+
}
91+
}
5792

58-
// remove temporary injected parameters
59-
unset($value[self::PARAM_CUSTOMFIELD_KEY], $value[self::PARAM_CUSTOMFIELD_VALUE]);
60-
61-
return $value;
62-
}
63-
64-
public static function rewriteRulesArrayFilter($rules) {
65-
$keys = array_keys($rules);
66-
$tmp = $rules;
67-
$rules = array();
68-
69-
for($i = 0, $j = sizeof($keys); $i < $j; ++$i) {
70-
$key = $keys[$i];
71-
72-
if (preg_match('/%field_([^%]*?)%/', $key)) {
73-
$keyNew = preg_replace(
74-
'/%field_([^%]*?)%/',
75-
'([^/]+)',
76-
// you can simply add next group to the url, because WordPress
77-
// detect them automatically and add next $matches indiceis
78-
$key
79-
);
80-
$rules[$keyNew] = preg_replace(
81-
'/%field_([^%]*?)%/',
82-
sprintf('%s=$1&%s=', self::PARAM_CUSTOMFIELD_KEY, self::PARAM_CUSTOMFIELD_VALUE),
83-
// here on the end will be pasted $matches[$i] from $keyNew, so we can
84-
// grab it it the future in self::PARAM_CUSTOMFIELD_VALUE parameter
85-
$tmp[$key]
86-
);
87-
}
88-
else {
89-
$rules[$key] = $tmp[$key];
90-
}
91-
}
92-
93-
return $rules;
94-
}
93+
return $rules;
94+
}
9595
}
9696

9797
add_filter('pre_post_link', array('CustomFieldsPermalink', 'linkPost'), 100, 3);

0 commit comments

Comments
 (0)