-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixfields.php
141 lines (112 loc) · 3.6 KB
/
pixfields.php
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* Plugin Name: PixFields
* Plugin URI: https://wordpress.org/plugins/pixfields/
* Description: WordPress easy custom fields management plugin.
* Version: 0.7.1
* Author: Pixelgrade
* Author URI: https://pixelgrade.com
* Author Email: [email protected]
* Requires at least: 4.9.9
* Tested up to: 6.2.2
* Text Domain: pixfields_txtd
* License: GPL-2.0 or later.
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Domain Path: /lang
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
// ensure EXT is defined
if ( ! defined( 'EXT' ) ) {
define( 'EXT', '.php' );
}
require 'core/bootstrap' . EXT;
$config = include 'plugin-config' . EXT;
// set textdomain
pixfields::settextdomain( $config['textdomain'] );
// Ensure Test Data
// ----------------
$defaults = include 'plugin-defaults' . EXT;
$current_data = get_option( $config['settings-key'] );
if ( $current_data === false ) {
add_option( $config['settings-key'], $defaults );
} else if ( count( array_diff_key( $defaults, $current_data ) ) != 0 ) {
$plugindata = array_merge( $defaults, $current_data );
update_option( $config['settings-key'], $plugindata );
}
# else: data is available; do nothing
// Load Callbacks
// --------------
$basepath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
$callbackpath = $basepath . 'callbacks' . DIRECTORY_SEPARATOR;
pixfields::require_all( $callbackpath );
require_once( plugin_dir_path( __FILE__ ) . 'class-pixfields.php' );
// Register hooks that are fired when the plugin is activated, deactivated, and uninstalled, respectively.
register_activation_hook( __FILE__, array( 'PixFieldsPlugin', 'activate' ) );
//register_deactivation_hook( __FILE__, array( 'PixTypesPlugin', 'deactivate' ) );
if ( ! function_exists( 'init_pixfields_plugin' ) ) {
function init_pixfields_plugin () {
global $pixfields_plugin;
$pixfields_plugin = PixFieldsPlugin::get_instance();
}
}
add_action('init', 'init_pixfields_plugin');
function display_pixfields() {
echo get_pixfields_template();
}
function get_pixfields_template() {
global $pixfields_plugin;
return $pixfields_plugin->get_template();
}
function get_pixfield( $key , $post_id = null ) {
if ( $post_id == null ) {
global $post;
$post_id = $post->ID;
}
return get_post_meta( $post_id, 'pixfield_' . $key, true );
}
function get_pixfields( $post_id = null ) {
global $pixfields_plugin;
if ( $post_id == null ) {
global $post;
} else {
$post = get_post($post_id);
}
$post_id = $post->ID;
$post_type = $post->post_type;
return $pixfields_plugin->get_post_pixfields($post_type, $post_id);
}
/**
* Get all the filterable keys
* @param $post_type
*
* @return array as $key => $label
*/
function pixfields_get_filterable_metakeys( $post_type ) {
global $pixfields_plugin;
$fields_list = $pixfields_plugin->get_pixfields_list();
$return = array();
if ( isset( $fields_list[$post_type] ) ) {
foreach ( $fields_list[$post_type] as $key => $fields ) {
if ( isset( $fields['filter'] ) ) {
$return[$fields['meta_key']] = $fields['label'];
}
}
}
return $return;
}
/**
* Add the shortcode button only on selected post types
*/
add_filter('filter_shortcodes','filter_pixfields_shortcode_button_by_post_type', 2, 2);
function filter_pixfields_shortcode_button_by_post_type( $shortcodes, $post ) {
global $pixfields_plugin;
$plug_settings = $pixfields_plugin->get_plugin_settings();
$post_types = array_keys( $plug_settings['display_on_post_types'] );
if ( ! empty($post_types) && ! in_array( $post->post_type, $post_types ) ) {
unset( $shortcodes['WpGradeShortcode_PixFields'] );
}
return $shortcodes;
}