1 | <?php |
||
6 | class GravityView_Admin_Metaboxes { |
||
7 | |||
8 | static $metaboxes_dir; |
||
9 | |||
10 | /** |
||
11 | * @var int The post ID of the current View |
||
12 | */ |
||
13 | var $post_id = 0; |
||
14 | |||
15 | /** |
||
16 | * |
||
17 | */ |
||
18 | function __construct() { |
||
31 | |||
32 | /** |
||
33 | * Add WordPress hooks |
||
34 | * @since 1.7.2 |
||
35 | */ |
||
36 | function initialize() { |
||
46 | |||
47 | /** |
||
48 | * GravityView wants to have the top (`normal`) metaboxes all to itself, so we move all plugin/theme metaboxes down to `advanced` |
||
49 | * @since 1.15.2 |
||
50 | */ |
||
51 | function update_priority() { |
||
67 | |||
68 | function register_metaboxes() { |
||
91 | |||
92 | /** |
||
93 | * Render the View Settings metabox |
||
94 | * @since 1.8 |
||
95 | * @param WP_Post $post |
||
96 | */ |
||
97 | function settings_metabox_render( $post ) { |
||
118 | |||
119 | /** |
||
120 | * Add default tabs to the Settings metabox |
||
121 | * @since 1.8 |
||
122 | */ |
||
123 | private function add_settings_metabox_tabs() { |
||
124 | |||
125 | $metaboxes = array( |
||
126 | array( |
||
127 | 'id' => 'template_settings', |
||
128 | 'title' => __( 'View Settings', 'gravityview' ), |
||
129 | 'file' => 'view-settings.php', |
||
130 | 'icon-class' => 'dashicons-admin-generic', |
||
131 | 'callback' => '', |
||
132 | 'callback_args' => '', |
||
133 | ), |
||
134 | array( |
||
135 | 'id' => 'multiple_entries', |
||
136 | 'title' => __( 'Multiple Entries', 'gravityview' ), |
||
137 | 'file' => 'multiple-entries.php', |
||
138 | 'icon-class' => 'dashicons-admin-page', |
||
139 | 'callback' => '', |
||
140 | 'callback_args' => '', |
||
141 | ), |
||
142 | array( |
||
143 | 'id' => 'single_entry', // Use the same ID as View Settings for backward compatibility |
||
144 | 'title' => __( 'Single Entry', 'gravityview' ), |
||
145 | 'file' => 'single-entry.php', |
||
146 | 'icon-class' => 'dashicons-media-default', |
||
147 | 'callback' => '', |
||
148 | 'callback_args' => '', |
||
149 | ), |
||
150 | array( |
||
151 | 'id' => 'edit_entry', // Use the same ID as View Settings for backward compatibility |
||
152 | 'title' => __( 'Edit Entry', 'gravityview' ), |
||
153 | 'file' => 'edit-entry.php', |
||
154 | 'icon-class' => 'dashicons-welcome-write-blog', |
||
155 | 'callback' => '', |
||
156 | 'callback_args' => '', |
||
157 | ), |
||
158 | array( |
||
159 | 'id' => 'sort_filter', |
||
160 | 'title' => __( 'Filter & Sort', 'gravityview' ), |
||
161 | 'file' => 'sort-filter.php', |
||
162 | 'icon-class' => 'dashicons-sort', |
||
163 | 'callback' => '', |
||
164 | 'callback_args' => '', |
||
165 | ), |
||
166 | array( |
||
167 | 'id' => 'permissions', // Use the same ID as View Settings for backward compatibility |
||
168 | 'title' => __( 'Permissions', 'gravityview' ), |
||
169 | 'file' => 'permissions.php', |
||
170 | 'icon-class' => 'dashicons-lock', |
||
171 | 'callback' => '', |
||
172 | 'callback_args' => '', |
||
173 | ), |
||
174 | ); |
||
175 | |||
176 | /** |
||
177 | * @filter `gravityview/metaboxes/default` Modify the default settings metabox tabs |
||
178 | * @param array $metaboxes |
||
179 | * @since 1.8 |
||
180 | */ |
||
181 | $metaboxes = apply_filters( 'gravityview/metaboxes/default', $metaboxes ); |
||
182 | |||
183 | foreach( $metaboxes as $m ) { |
||
184 | |||
185 | $tab = new GravityView_Metabox_Tab( $m['id'], $m['title'], $m['file'], $m['icon-class'], $m['callback'], $m['callback_args'] ); |
||
186 | |||
187 | GravityView_Metabox_Tabs::add( $tab ); |
||
188 | |||
189 | } |
||
190 | |||
191 | unset( $tab ); |
||
192 | |||
193 | } |
||
194 | |||
195 | /** |
||
196 | * Generate the title for Data Source, which includes the Action Links once configured. |
||
197 | * |
||
198 | * @since 1.8 |
||
199 | * |
||
200 | * @param int $post_id ID of the current post |
||
201 | * |
||
202 | * @return string "Data Source", plus links if any |
||
203 | */ |
||
204 | private function get_data_source_header( $post_id ) { |
||
205 | |||
206 | //current value |
||
207 | $current_form = gravityview_get_form_id( $post_id ); |
||
208 | |||
209 | $links = GravityView_Admin_Views::get_connected_form_links( $current_form, false ); |
||
210 | |||
211 | if( !empty( $links ) ) { |
||
212 | $links = '<span class="alignright gv-form-links">'. $links .'</span>'; |
||
213 | } |
||
214 | |||
215 | return __( 'Data Source', 'gravityview' ) . $links; |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * Render html for 'select form' metabox |
||
220 | * |
||
221 | * @param object $post |
||
222 | * @return void |
||
223 | */ |
||
224 | public function render_data_source_metabox( $post ) { |
||
225 | |||
226 | include self::$metaboxes_dir . 'views/data-source.php'; |
||
227 | |||
228 | } |
||
229 | |||
230 | /** |
||
231 | * Render html for 'select template' metabox |
||
232 | * |
||
233 | * @param object $post |
||
234 | * @return void |
||
235 | */ |
||
236 | public function render_select_template_metabox( $post ) { |
||
240 | |||
241 | /** |
||
242 | * Generate the script tags necessary for the Gravity Forms Merge Tag picker to work. |
||
243 | * |
||
244 | * @param int $curr_form Form ID |
||
245 | * @return null|string Merge tags html; NULL if $curr_form isn't defined. |
||
246 | */ |
||
247 | public static function render_merge_tags_scripts( $curr_form ) { |
||
248 | |||
249 | if( empty( $curr_form )) { |
||
250 | return NULL; |
||
251 | } |
||
252 | |||
253 | $form = gravityview_get_form( $curr_form ); |
||
254 | |||
255 | $get_id_backup = isset($_GET['id']) ? $_GET['id'] : NULL; |
||
256 | |||
257 | if( isset( $form['id'] ) ) { |
||
258 | $form_script = 'var form = ' . GFCommon::json_encode($form) . ';'; |
||
259 | |||
260 | // The `gf_vars()` method needs a $_GET[id] variable set with the form ID. |
||
261 | $_GET['id'] = $form['id']; |
||
262 | |||
263 | } else { |
||
264 | $form_script = 'var form = new Form();'; |
||
265 | } |
||
266 | |||
267 | $output = '<script type="text/javascript" data-gv-merge-tags="1">' . $form_script . "\n" . GFCommon::gf_vars(false) . '</script>'; |
||
268 | |||
269 | // Restore previous $_GET setting |
||
270 | $_GET['id'] = $get_id_backup; |
||
271 | |||
272 | return $output; |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * Render html for 'View Configuration' metabox |
||
277 | * |
||
278 | * @access public |
||
279 | * @param mixed $post |
||
280 | * @return void |
||
281 | */ |
||
282 | function render_view_configuration_metabox( $post ) { |
||
283 | |||
284 | // Use nonce for verification |
||
285 | wp_nonce_field( 'gravityview_view_configuration', 'gravityview_view_configuration_nonce' ); |
||
286 | |||
287 | // Selected Form |
||
288 | $curr_form = gravityview_get_form_id( $post->ID ); |
||
289 | |||
290 | $view = \GV\View::from_post( $post ); |
||
291 | |||
292 | // Selected template |
||
293 | $curr_template = gravityview_get_template_id( $post->ID ); |
||
294 | |||
295 | echo self::render_merge_tags_scripts( $curr_form ); |
||
296 | |||
297 | include self::$metaboxes_dir . 'views/view-configuration.php'; |
||
298 | } |
||
299 | |||
300 | /** |
||
301 | * Render html View General Settings |
||
302 | * |
||
303 | * @access public |
||
304 | * @param object $post |
||
305 | * @return void |
||
306 | */ |
||
307 | function render_view_settings_metabox( $post ) { |
||
315 | |||
316 | |||
317 | |||
318 | /** |
||
319 | * Render shortcode hint in the Publish metabox |
||
320 | * |
||
321 | * @access public |
||
322 | * @return void |
||
323 | */ |
||
324 | function render_shortcode_hint() { |
||
339 | |||
340 | } |
||
341 | |||
343 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.