Skip to content

Commit 13ef3c4

Browse files
committed
Revert "Bump version to 1.3.0"
This reverts commit bb7bdb2.
1 parent bb7bdb2 commit 13ef3c4

28 files changed

+1632
-1632
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Plugin allows to use post's custom fields values in permalink structure by addin
1212
* Tags: custom fields, permalinks, permalink, url, custom post types, post type, tax, taxonomy, types
1313
* Requires at least: 4.5.0
1414
* Tested up to: 4.9.5
15-
* Stable tag: 1.3.0
15+
* Stable tag: 1.2.0
1616
* Requires PHP: 5.3
1717
* License: MIT
1818
* License URI: http://opensource.org/licenses/MIT

includes/class-plugin-updater.php

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
<?php
2-
/**
3-
* Class Updater
4-
*
5-
* @package WordPress_Custom_Fields_Permalink
6-
*/
7-
8-
namespace CustomFieldsPermalink;
9-
10-
/**
11-
* Class Plugin_Updater handles the upgrade process.
12-
*/
13-
class Plugin_Updater {
14-
15-
/**
16-
* This hook is called once any activated plugins have been loaded.
17-
*
18-
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/plugins_loaded
19-
*/
20-
public function on_init_hook() {
21-
$version_option_name = '_wordpress_custom_fields_permalink_plugin_version';
22-
$version_from = get_option( $version_option_name, null );
23-
$version_to = WORDPRESS_CUSTOM_FIELDS_PERMALINK_PLUGIN_VERSION;
24-
if ( $version_from != $version_to ) {
25-
$this->update_plugin( $version_from, $version_to );
26-
update_option( $version_option_name, $version_to, true );
27-
}
28-
}
29-
30-
/**
31-
* Upgrades the plugin.
32-
*
33-
* @param string $version_from Currently running version.
34-
* @param string $version_to Version upgrade to.
35-
*/
36-
private function update_plugin( $version_from, $version_to ) {
37-
flush_rewrite_rules();
38-
}
39-
}
1+
<?php
2+
/**
3+
* Class Updater
4+
*
5+
* @package WordPress_Custom_Fields_Permalink
6+
*/
7+
8+
namespace CustomFieldsPermalink;
9+
10+
/**
11+
* Class Plugin_Updater handles the upgrade process.
12+
*/
13+
class Plugin_Updater {
14+
15+
/**
16+
* This hook is called once any activated plugins have been loaded.
17+
*
18+
* @link https://codex.wordpress.org/Plugin_API/Action_Reference/plugins_loaded
19+
*/
20+
public function on_init_hook() {
21+
$version_option_name = '_wordpress_custom_fields_permalink_plugin_version';
22+
$version_from = get_option( $version_option_name, null );
23+
$version_to = WORDPRESS_CUSTOM_FIELDS_PERMALINK_PLUGIN_VERSION;
24+
if ( $version_from != $version_to ) {
25+
$this->update_plugin( $version_from, $version_to );
26+
update_option( $version_option_name, $version_to, true );
27+
}
28+
}
29+
30+
/**
31+
* Upgrades the plugin.
32+
*
33+
* @param string $version_from Currently running version.
34+
* @param string $version_to Version upgrade to.
35+
*/
36+
private function update_plugin( $version_from, $version_to ) {
37+
flush_rewrite_rules();
38+
}
39+
}

includes/class-wp-permalink.php

Lines changed: 99 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,99 @@
1-
<?php
2-
/**
3-
* Class RequestProcessor
4-
*
5-
* @package WordPress_Custom_Fields_Permalink
6-
*/
7-
8-
namespace CustomFieldsPermalink;
9-
10-
use WP_Post;
11-
12-
/**
13-
* Class WP_Permalink generates WordPress permalinks.
14-
*/
15-
class WP_Permalink {
16-
17-
/**
18-
* Post meta provider.
19-
*
20-
* @var WP_Post_Meta
21-
*/
22-
private $post_meta;
23-
24-
/**
25-
* WP_Permalink constructor.
26-
*
27-
* @param WP_Post_Meta $post_meta Post meta provider.
28-
*/
29-
public function __construct( WP_Post_Meta $post_meta ) {
30-
$this->post_meta = $post_meta;
31-
}
32-
33-
/**
34-
* Filters the permalink structure for a post before token replacement occurs..
35-
* The pre_post_link filter implementation.
36-
*
37-
* @param string $permalink The site's permalink structure.
38-
* @param WP_Post $post The post in question.
39-
* @param bool $leavename Whether to keep the post name.
40-
*
41-
* @link https://developer.wordpress.org/reference/hooks/pre_post_link/
42-
*
43-
* @return mixed
44-
*/
45-
public function link_post( $permalink, $post, $leavename ) {
46-
return $this->link_rewrite_fields( $permalink, $post );
47-
}
48-
49-
/**
50-
* Filters the permalink for a post of a custom post type.
51-
* The post_type_link filter implementation.
52-
*
53-
* @param string $permalink The post's permalink.
54-
* @param WP_Post $post The post in question.
55-
* @param bool $leavename Whether to keep the post name.
56-
* @param bool $sample Is it a sample permalink.
57-
*
58-
* @link https://developer.wordpress.org/reference/hooks/post_type_link/
59-
*
60-
* @return mixed
61-
*/
62-
public function link_post_type( $permalink, $post, $leavename, $sample ) {
63-
return $this->link_rewrite_fields( $permalink, $post );
64-
}
65-
66-
/**
67-
* Rewrites permalink replacing custom fields.
68-
*
69-
* @param string $permalink The permalink.
70-
* @param WP_Post $post The post.
71-
*
72-
* @return string
73-
*/
74-
private function link_rewrite_fields( $permalink, $post ) {
75-
$that = $this;
76-
$replace_callback = function ( $matches ) use ( &$post, &$that ) {
77-
return $that->link_rewrite_fields_extract( $post, $matches[2] );
78-
};
79-
return preg_replace_callback( '#(%field_(.*?)%)#', $replace_callback, $permalink );
80-
}
81-
82-
/**
83-
* Extract the metadata value from the post.
84-
*
85-
* @param WP_Post $post The post.
86-
* @param string $field_name The metadata key to extract.
87-
*
88-
* @return string
89-
*/
90-
public function link_rewrite_fields_extract( $post, $field_name ) {
91-
$post_meta = $this->post_meta->get_post_meta( $post );
92-
if ( ! isset( $post_meta[ $field_name ] ) ) {
93-
return '';
94-
}
95-
$value = $post_meta[ $field_name ][0];
96-
$value = sanitize_title( $value );
97-
return $value;
98-
}
99-
}
1+
<?php
2+
/**
3+
* Class RequestProcessor
4+
*
5+
* @package WordPress_Custom_Fields_Permalink
6+
*/
7+
8+
namespace CustomFieldsPermalink;
9+
10+
use WP_Post;
11+
12+
/**
13+
* Class WP_Permalink generates WordPress permalinks.
14+
*/
15+
class WP_Permalink {
16+
17+
/**
18+
* Post meta provider.
19+
*
20+
* @var WP_Post_Meta
21+
*/
22+
private $post_meta;
23+
24+
/**
25+
* WP_Permalink constructor.
26+
*
27+
* @param WP_Post_Meta $post_meta Post meta provider.
28+
*/
29+
public function __construct( WP_Post_Meta $post_meta ) {
30+
$this->post_meta = $post_meta;
31+
}
32+
33+
/**
34+
* Filters the permalink structure for a post before token replacement occurs..
35+
* The pre_post_link filter implementation.
36+
*
37+
* @param string $permalink The site's permalink structure.
38+
* @param WP_Post $post The post in question.
39+
* @param bool $leavename Whether to keep the post name.
40+
*
41+
* @link https://developer.wordpress.org/reference/hooks/pre_post_link/
42+
*
43+
* @return mixed
44+
*/
45+
public function link_post( $permalink, $post, $leavename ) {
46+
return $this->link_rewrite_fields( $permalink, $post );
47+
}
48+
49+
/**
50+
* Filters the permalink for a post of a custom post type.
51+
* The post_type_link filter implementation.
52+
*
53+
* @param string $permalink The post's permalink.
54+
* @param WP_Post $post The post in question.
55+
* @param bool $leavename Whether to keep the post name.
56+
* @param bool $sample Is it a sample permalink.
57+
*
58+
* @link https://developer.wordpress.org/reference/hooks/post_type_link/
59+
*
60+
* @return mixed
61+
*/
62+
public function link_post_type( $permalink, $post, $leavename, $sample ) {
63+
return $this->link_rewrite_fields( $permalink, $post );
64+
}
65+
66+
/**
67+
* Rewrites permalink replacing custom fields.
68+
*
69+
* @param string $permalink The permalink.
70+
* @param WP_Post $post The post.
71+
*
72+
* @return string
73+
*/
74+
private function link_rewrite_fields( $permalink, $post ) {
75+
$that = $this;
76+
$replace_callback = function ( $matches ) use ( &$post, &$that ) {
77+
return $that->link_rewrite_fields_extract( $post, $matches[2] );
78+
};
79+
return preg_replace_callback( '#(%field_(.*?)%)#', $replace_callback, $permalink );
80+
}
81+
82+
/**
83+
* Extract the metadata value from the post.
84+
*
85+
* @param WP_Post $post The post.
86+
* @param string $field_name The metadata key to extract.
87+
*
88+
* @return string
89+
*/
90+
public function link_rewrite_fields_extract( $post, $field_name ) {
91+
$post_meta = $this->post_meta->get_post_meta( $post );
92+
if ( ! isset( $post_meta[ $field_name ] ) ) {
93+
return '';
94+
}
95+
$value = $post_meta[ $field_name ][0];
96+
$value = sanitize_title( $value );
97+
return $value;
98+
}
99+
}

includes/class-wp-post-meta.php

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
<?php
2-
/**
3-
* Class RequestProcessor
4-
*
5-
* @package WordPress_Custom_Fields_Permalink
6-
*/
7-
8-
namespace CustomFieldsPermalink;
9-
10-
use WP_Post;
11-
12-
/**
13-
* Class WP_Post_Meta gets post metadata.
14-
*/
15-
class WP_Post_Meta {
16-
17-
/**
18-
* Get post meta applying <code>wpcfp_get_post_metadata</code> filter.
19-
*
20-
* @param WP_Post $post The post.
21-
*
22-
* @return array
23-
*/
24-
public function get_post_meta( $post ) {
25-
$post_meta = get_post_meta( $post->ID );
26-
/**
27-
* Filters of retrieved metadata of a post to link rewrite.
28-
*
29-
* @since 1.2.0
30-
*
31-
* @param array $post_meta The metadata returned from get_post_meta.
32-
* @param WP_Post $post The post object.
33-
*/
34-
$filtered_post_meta = apply_filters( 'wpcfp_get_post_metadata', $post_meta, $post );
35-
// Do some fixes after user generated values.
36-
// If it's single value, wrap this in array, as WordPress internally does.
37-
// @see get_post_meta() with $single = false.
38-
foreach ( $filtered_post_meta as $key => &$value ) {
39-
if ( ! is_array( $value ) ) {
40-
$value = array( $value );
41-
}
42-
}
43-
return $filtered_post_meta;
44-
}
45-
}
1+
<?php
2+
/**
3+
* Class RequestProcessor
4+
*
5+
* @package WordPress_Custom_Fields_Permalink
6+
*/
7+
8+
namespace CustomFieldsPermalink;
9+
10+
use WP_Post;
11+
12+
/**
13+
* Class WP_Post_Meta gets post metadata.
14+
*/
15+
class WP_Post_Meta {
16+
17+
/**
18+
* Get post meta applying <code>wpcfp_get_post_metadata</code> filter.
19+
*
20+
* @param WP_Post $post The post.
21+
*
22+
* @return array
23+
*/
24+
public function get_post_meta( $post ) {
25+
$post_meta = get_post_meta( $post->ID );
26+
/**
27+
* Filters of retrieved metadata of a post to link rewrite.
28+
*
29+
* @since 1.2.0
30+
*
31+
* @param array $post_meta The metadata returned from get_post_meta.
32+
* @param WP_Post $post The post object.
33+
*/
34+
$filtered_post_meta = apply_filters( 'wpcfp_get_post_metadata', $post_meta, $post );
35+
// Do some fixes after user generated values.
36+
// If it's single value, wrap this in array, as WordPress internally does.
37+
// @see get_post_meta() with $single = false.
38+
foreach ( $filtered_post_meta as $key => &$value ) {
39+
if ( ! is_array( $value ) ) {
40+
$value = array( $value );
41+
}
42+
}
43+
return $filtered_post_meta;
44+
}
45+
}

0 commit comments

Comments
 (0)