PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
vikbooking / libraries / adapter / form / fields / menuitem.php

menuitem.php in VikBooking Hotel Booking Engine & PMS 1.8.16, at libraries/adapter/form/fields/menuitem.php

91 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikWP - Libraries
4 * @subpackage adapter.form
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2023 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 JLoader::import('adapter.form.fields.list');
15
16 /**
17 * Form field class to handle dropdown fields containing
18 * the pages assigned to a specific shortcode of the plugin.
19 *
20 * @since 10.0
21 */
22 class JFormFieldMenuItem extends JFormFieldList
23 {
24 /**
25 * Cache the available shortcodes to prevent duplicate queries.
26 *
27 * @var array
28 * @since 10.1.51
29 */
30 protected static $shortcodes = [];
31
32 /**
33 * @override
34 * Method to get the options to populate list.
35 *
36 * @return array The field option objects.
37 *
38 * @since 10.1.51
39 */
40 public function getOptions()
41 {
42 // obtain the default options defined by the parent
43 $options = parent::getOptions();
44
45 if (!$options)
46 {
47 // placeholder not specified, use the default one
48 $options[''] = '--';
49 }
50
51 if (!empty($this->prefix))
52 {
53 // set modowner with custom prefix
54 $this->modowner = $this->prefix;
55 }
56
57 // check whether the same results have been already cached
58 if (!isset(static::$shortcodes[$this->modowner]))
59 {
60 // init the cache
61 static::$shortcodes[$this->modowner] = [];
62
63 /**
64 * Force the client path because we need to load the shortcodes model
65 * always from the back-end folder.
66 *
67 * An issue occurred since WP 5.8, after the refactoring of the widgets
68 * management page, where the client now results to be "site" in place
69 * of "admin".
70 *
71 * @since 10.1.34
72 */
73 $model = JModel::getInstance($this->modowner, 'shortcodes', 'admin');
74
75 if ($model)
76 {
77 foreach ($model->all() as $item)
78 {
79 if ($item->post_id)
80 {
81 static::$shortcodes[$this->modowner][$item->post_id] = get_the_title($item->post_id) . " - {$item->type}";
82 }
83 }
84 }
85 }
86
87 // join the default options with the cached values
88 return $options + static::$shortcodes[$this->modowner];
89 }
90 }
91