PluginProbe
Related Posts By PickPlugins / trunk
Related Posts By PickPlugins vtrunk
trunk 1.0 1.1 1.2 2.0.0 2.0.1 2.0.10 2.0.11 2.0.14 2.0.16 2.0.17 2.0.18 2.0.19 2.0.2 2.0.20 2.0.21 2.0.22 2.0.23 2.0.24 2.0.25 2.0.26 2.0.27 2.0.28 2.0.29 2.0.30 All 60 releases
related-post / includes / class-post-meta.php

class-post-meta.php in Related Posts By PickPlugins trunk, at includes/class-post-meta.php

233 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * @Author pickplugins
5 * Copyright: 2015 pickplugins
6 */
7
8 if (!defined('ABSPATH')) exit; // if direct access
9
10 class class_related_post_post_meta
11 {
12
13 public function __construct()
14 {
15
16 add_action('add_meta_boxes', array($this, 'meta_boxes_related_post'));
17 add_action('save_post', array($this, 'meta_boxes_related_post_save'));
18 }
19
20 public function meta_boxes_related_post($post_type)
21 {
22 $related_post_settings = get_option('related_post_settings');
23
24
25 $post_types_display = isset($related_post_settings['post_types_display']) ? $related_post_settings['post_types_display'] : array();
26
27 $manual_post_types = [];
28
29 if (!empty($post_types_display)) {
30
31 foreach ($post_types_display as $index => $types) {
32 $manual_post = isset($types['manual_post']) ? $types['manual_post'] : '';
33
34 if ($manual_post == 'yes') {
35 $manual_post_types[] = $index;
36 }
37 }
38 }
39
40
41 $post_types = !empty($manual_post_types) ? $manual_post_types : array('post');
42
43
44 //$post_types = array('post');
45 if (in_array($post_type, $post_types)) {
46
47 add_meta_box(
48 'related_post_metabox',
49 __('Related Post', 'related-post'),
50 array($this, 'related_post_meta_box_function'),
51 $post_type,
52 'side',
53 'default'
54 );
55 }
56 }
57
58 public function related_post_meta_box_function($post)
59 {
60
61 wp_nonce_field('related_post_nonce_check', 'related_post_nonce_check_value');
62 global $post;
63
64 //$pm_related_post_meta = get_post_meta( $post->ID, 'pm_related_post_meta', true );
65 $related_post_ids = get_post_meta($post->ID, 'related_post_ids', true);
66 $related_post_enable = get_post_meta($post->ID, 'related_post_enable', true);
67
68 //echo '<pre>' . var_export($related_post_enable, true) . '</pre>';
69
70 wp_enqueue_style('font-awesome-5');
71
72
73 ?>
74
75 <div class="related-post-meta">
76
77
78 <label><input type="checkbox" <?php checked($related_post_enable, 1) ?> id="related_post_enable" name="related_post_enable" value="1">Display related post by force</label>
79
80
81 <div class="post-list">
82
83
84 <?php
85 if (!empty($related_post_ids))
86 foreach ($related_post_ids as $post_id) {
87
88 $post_title = get_the_title($post_id);
89
90 ?>
91 <div class="item">
92 <span class="remove"><i class="fas fa-times"></i></span>
93 <span class="move"><i class="fas fa-sort"></i></span>
94 <span class="title"><?php esc_html($post_title); ?></span>
95 <input type="hidden" name="related_post_ids[]" value="<?php echo esc_attr($post_id); ?>" />
96
97 </div>
98 <?php
99
100 }
101
102 ?>
103
104
105 </div>
106
107
108
109
110 <script>
111 jQuery(document).ready(function($) {
112
113 $(function() {
114 $(".post-list").sortable({
115 handle: '.move'
116 });
117
118 });
119
120 });
121 </script>
122
123 <br>
124 <input placeholder="Start typing..." type="text" class="related_post_get_ids" post_id="<?php echo esc_attr($post->ID); ?>" name="related_post_get_ids" value="" />
125 <br><br>
126 <label><input type="checkbox" id="any_posttypes" name="any_posttypes" value="any"><?php esc_html_e("Any post types", 'related-post') ?></label>
127
128 <div class="suggest-post-list">
129
130 </div>
131
132
133 </div>
134
135 <style>
136 .related-post-meta {}
137
138 .related-post-meta .item {
139 display: block;
140 margin: 5px 0;
141 }
142
143 .related-post-meta .remove {
144 background: #fd5a0d;
145 padding: 3px 7px;
146 color: #fff;
147 display: inline-block;
148 cursor: pointer;
149 }
150
151 .related-post-meta .move {
152 background: #cacaca;
153 padding: 3px 8px;
154 color: #fff;
155 display: inline-block;
156 cursor: move;
157 }
158
159 .related-post-meta .title {}
160
161 .related-post-meta .suggest-post-list {
162 margin-top: 12px;
163 }
164
165 .related-post-meta .suggest-post-list .item {
166 cursor: pointer;
167 margin: 4px 0;
168 background: #ddd;
169 padding: 5px 7px;
170 }
171
172 .related-post-meta .related_post_get_ids {
173 width: 100%;
174 }
175
176 .suggest-post-list .title-text {
177 display: inline-block;
178 word-break: break-word;
179 }
180
181 .suggest-post-list .icon-plus {
182 display: inline-block;
183 }
184
185 .suggest-post-list .icon-add {
186 display: none;
187 }
188
189 .suggest-post-list .item:hover .icon-plus {
190 display: none;
191 }
192
193 .suggest-post-list .item:hover .icon-add {
194 display: inline-block;
195 }
196 </style>
197
198 <?php
199 }
200
201 public function meta_boxes_related_post_save($post_id)
202 {
203
204 if (!isset($_POST['related_post_nonce_check_value'])) return $post_id;
205 $nonce = isset($_POST['related_post_nonce_check_value']) ? sanitize_text_field($_POST['related_post_nonce_check_value']) : '';
206 if (!wp_verify_nonce($nonce, 'related_post_nonce_check')) return $post_id;
207
208 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
209
210 if ('page' == $_POST['post_type']) {
211 if (!current_user_can('edit_page', $post_id)) return $post_id;
212 } else {
213 if (!current_user_can('edit_post', $post_id)) return $post_id;
214 }
215
216 //$pm_related_post_meta = related_post_recursive_sanitize_arr( $_POST['pm_related_post_meta'] );
217
218
219 $related_post_ids = isset($_POST['related_post_ids']) ? related_post_recursive_sanitize_arr($_POST['related_post_ids']) : [];
220 update_post_meta($post_id, 'related_post_ids', $related_post_ids);
221
222 $related_post_enable = isset($_POST['related_post_enable']) ? sanitize_text_field($_POST['related_post_enable']) : '';
223 update_post_meta($post_id, 'related_post_enable', $related_post_enable);
224
225
226
227 // Saving the Meta Data from ARRAY
228
229 }
230 }
231
232 new class_related_post_post_meta();
233