-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlimit-locations.php
More file actions
145 lines (129 loc) · 3.85 KB
/
limit-locations.php
File metadata and controls
145 lines (129 loc) · 3.85 KB
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
142
143
144
145
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link #
* @since 1.0.0
* @package Location_Limits
*
* @wordpress-plugin
* Plugin Name: Listing Pro Location Limits
* Plugin URI: https://github.com/peterson-umoke/listing-pro-limits
* Description: This is a plugin that adds limits to the locations for pricing plans and used to control what the number of locations a user can select
* Version: 1.0.0
* Author: P.N.U.M.A
* Author URI: #
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: location-limits
* Domain Path: /languages
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
/**
* Currently plugin version.
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define('LOCATION_LIMITS_VERSION', '1.0.0');
/**
* require t5he autoloader from composer
*/
require_once dirname(__FILE__) . "/vendor/autoload.php";
class umk_limit_locations
{
/**
* the post type to apply to
*
* @var string
*/
private $postType;
/**
* the plugin id
*
* @var string
*/
private $id;
/**
* @var string
*/
private $field_key;
/**
* the construct method
*
* @param string $id
*/
public function __construct($id)
{
$this->id = $id;
$this->postType = "price_plan";
$this->field_key = 'location_limit_number';
}
/**
* add the required actions and hooks
*/
public function init()
{
add_action('cmb2_admin_init', array($this, 'metabox'));
add_action('wp_ajax_get_locations_limits', array($this, 'get_location_limits'));
add_action('wp_enqueue_scripts', array($this, 'enqueue_assets'));
}
/**
* the list of metabox to add to the application
*
* @return object|void|string
*/
public function metabox()
{
$cmb = new_cmb2_box(array(
'id' => $this->id,
'title' => __('Location Limit', 'location-limits'),
'object_types' => array('price_plan'), // Post type
'context' => 'side',
'priority' => 'high',
'show_names' => true, // Show field names on the left
));
$cmb->add_field(array(
'name' => __('Location Limits', 'location-limits'),
'desc' => __('Enter the limit of locations for this pricing plan', 'location-limits'),
'id' => 'location_limit_number',
'type' => 'text',
"default" => 1,
"attributes" => [
"type" => "number",
"min" => 1,
],
));
}
/**
* ajax used to register the required enpoints for getting the location limits
* @noinspection PhpParamsInspection
*/
public function get_location_limits()
{
$id = $_REQUEST['plan_id'];
$location = cmb2_get_field_value($this->id, $this->field_key, $id);
$location = array("limit" => $location);
// kill the script
die(json_encode($location));
}
/**
* enqueue the javascript for the plugin
*/
public function enqueue_assets()
{
wp_register_script('limit-locations-script', plugins_url('limit-locations.js', __FILE__));
wp_enqueue_script('limit-locations-script');
}
}
// instantiate the plugin
$umkLimitLocations = new umk_limit_locations("limit-locations");
// init the plugin
$umkLimitLocations->init();