PluginProbe
Posts Table with Search & Sort / 1.3.4
Posts Table with Search & Sort v1.3.4
1.4.13 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2 1.3 1.3.1 1.3.1-v2 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 40 releases
posts-data-table / lib / Plugin / Simple_Plugin.php

Simple_Plugin.php in Posts Table with Search & Sort 1.3.4, at lib/Plugin/Simple_Plugin.php

182 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Barn2\PTS_Lib\Plugin;
3
4 use Barn2\PTS_Lib\Util;
5
6 /**
7 * Basic implementation of the Plugin interface which stores core data about a
8 * WordPress plugin (ID, version number, etc). Data is passed as an array on construction.
9 *
10 * @package Barn2\barn2-lib
11 * @author Barn2 Plugins <support@barn2.co.uk>
12 * @license GPL-3.0
13 * @copyright Barn2 Media Ltd
14 * @version 1.2
15 */
16 class Simple_Plugin implements Plugin {
17
18 protected $file;
19 protected $data;
20 private $basename = null;
21 private $dir_path = null;
22 private $dir_url = null;
23
24 public function __construct( array $data ) {
25 $this->data = array_merge( [
26 'id' => 0,
27 'name' => '',
28 'version' => '',
29 'file' => null,
30 'is_woocommerce' => false,
31 'is_edd' => false,
32 'documentation_path' => '',
33 'settings_path' => '',
34 ], $data
35 );
36
37 $this->data['id'] = (int) $this->data['id'];
38 $this->data['documentation_path'] = ltrim( $this->data['documentation_path'], '/' );
39 $this->data['settings_path'] = ltrim( $this->data['settings_path'], '/' );
40
41 // Check for 'item_id' in case 'id' not set.
42 if ( ! $this->get_id() && ! empty( $this->data['item_id'] ) ) {
43 $this->data['id'] = (int) $this->data['item_id'];
44 }
45
46 // WooCommerce plugins cannot be EDD plugins (and vice-versa).
47 if ( $this->is_edd() ) {
48 $this->data['is_woocommerce'] = false;
49 } elseif ( $this->is_woocommerce() ) {
50 $this->data['is_edd'] = false;
51 }
52 }
53
54 /**
55 * Get the plugin ID, usually the EDD Download ID.
56 *
57 * $return int The plugin ID.
58 */
59 public function get_id() {
60 return $this->data['id'];
61 }
62
63 /**
64 * Get the name of this plugin.
65 *
66 * @return string The plugin name.
67 */
68 public function get_name() {
69 return $this->data['name'];
70 }
71
72 /**
73 * Get the plugin version number (e.g. 1.3.2).
74 *
75 * @return string The version number.
76 */
77 public function get_version() {
78 return $this->data['version'];
79 }
80
81 /**
82 * Get the full path to the main plugin file.
83 *
84 * @return string The plugin file.
85 */
86 public function get_file() {
87 return $this->data['file'];
88 }
89
90 /**
91 * Get the slug for this plugin (e.g. my-plugin).
92 *
93 * @return string The plugin slug.
94 */
95 public function get_slug() {
96 $dir_path = $this->get_dir_path();
97 return ! empty( $dir_path ) ? basename( $dir_path ) : '';
98 }
99
100 /**
101 * Get the 'basename' for the plugin (e.g. my-plugin/my-plugin.php).
102 *
103 * @return string The plugin basename.
104 */
105 public function get_basename() {
106 if ( null === $this->basename ) {
107 $this->basename = ! empty( $this->data['file'] ) ? plugin_basename( $this->data['file'] ) : '';
108 }
109 return $this->basename;
110 }
111
112 /**
113 * Get the full directory path to the plugin folder, with trailing slash (e.g. /wp-content/plugins/my-plugin/).
114 *
115 * @return string The plugin directory path.
116 */
117 public function get_dir_path() {
118 if ( null === $this->dir_path ) {
119 $this->dir_path = ! empty( $this->data['file'] ) ? plugin_dir_path( $this->data['file'] ) : '';
120 }
121 return $this->dir_path;
122 }
123
124 /**
125 * Get the URL to the plugin folder.
126 *
127 * @return string (URL)
128 */
129 public function get_dir_url() {
130 if ( null === $this->dir_url ) {
131 $this->dir_url = ! empty( $this->data['file'] ) ? plugin_dir_url( $this->data['file'] ) : '';
132 }
133 return $this->dir_url;
134 }
135
136 /**
137 * Is this plugin a WooCommerce extension?
138 *
139 * @return boolean true if it's a WooCommerce extension.
140 */
141 public function is_woocommerce() {
142 return (bool) $this->data['is_woocommerce'];
143 }
144
145 /**
146 * Is this plugin an Easy Digital Downloads extension?
147 *
148 * @return boolean true if it's an EDD extension.
149 */
150 public function is_edd() {
151 return (bool) $this->data['is_edd'];
152 }
153
154 /**
155 * Get the documentation URL for this plugin.
156 *
157 * @return string (URL)
158 */
159 public function get_documentation_url() {
160 return esc_url( Util::KNOWLEDGE_BASE_URL . '/' . $this->data['documentation_path'] );
161 }
162
163 /**
164 * Get the support URL for this plugin.
165 *
166 * @return string (URL)
167 */
168 public function get_support_url() {
169 return Util::barn2_url( 'support-center/' );
170 }
171
172 /**
173 * Get the settings page URL in the WordPress admin.
174 *
175 * @return string (URL)
176 */
177 public function get_settings_page_url() {
178 return ! empty( $this->data['settings_path'] ) ? admin_url( $this->data['settings_path'] ) : '';
179 }
180
181 }
182