-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstant-custom-fields.php
More file actions
68 lines (47 loc) · 1.97 KB
/
instant-custom-fields.php
File metadata and controls
68 lines (47 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/*
Plugin Name: Instant Custom Fields
Description: Allows instant embedding of custom fields in Post & Page Content. Useful for javascript tags (Video Embeds) that get stripped from Post Content.
Plugin URI: http://complex.com
Author: Anthony L. Rivera
Author URI: http://complexmediainc.com
Version: 1.0
License: GPL2
*/
/*
Copyright (C) 2015 Anthony L. Rivera anthonylrivera@gmail.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if ( ! array_key_exists( 'instant-custom-fields', $GLOBALS ) ) {
if ( !class_exists( 'Instant_Custom_Fields' ) ) {
class Instant_Custom_Fields {
public function __construct(){
add_filter( 'the_content', array( $this, 'filter_instant_shortcodes'), 1, 1 );
}
public function filter_instant_shortcodes( $content ) {
global $post;
preg_match_all('/{{*?[a-zA-Z0-9-_]*}}/', $content, $cfs );
if ( isset($cfs) && is_array($cfs) ) {
foreach ( $cfs[0] as $icf_tag ) {
$icf_name = substr($icf_tag, 2, -2);
$custom_field_value = get_post_meta( $post->ID, $icf_name, true );
if( ! empty( $custom_field_value ) ) {
$content = str_replace( $icf_tag, $custom_field_value, $content );
}
}
}
return $content;
}
}
$GLOBALS['instant-custom-fields'] = new Instant_Custom_Fields();
}
}