PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.20
VikAppointments Services Booking Calendar v1.2.20
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / libraries / adapter / form / fields / menuitem.php
vikappointments / libraries / adapter / form / fields Last commit date
groupedlist.php 1 month ago language.php 1 month ago list.php 1 month ago media.php 1 month ago menuitem.php 1 month ago modulelayout.php 1 month ago number.php 1 month ago radio.php 1 month ago spacer.php 1 month ago sql.php 1 month ago text.php 1 month ago textarea.php 1 month ago
menuitem.php
91 lines
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