PluginProbe
WPGet API – Connect to any external REST API / trunk
WPGet API – Connect to any external REST API vtrunk
1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.10 2.2.2 2.2.3 All 97 releases
wpgetapi / wpgetapi.php

wpgetapi.php in WPGet API – Connect to any external REST API trunk, at wpgetapi.php

226 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: WPGetAPI
4 * Plugin URI: https://wordpress.org/plugins/wpgetapi/
5 * Description: Connect to external API's and display the API data.
6 * Author: WPGetAPI
7 * Author URI: https://wpgetapi.com/
8 * Version: 2.25.5
9 * Text Domain: wpgetapi
10 * License: GPL2 or later
11 *
12 */
13
14 // Exit if accessed directly.
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 /**
20 * Main Class.
21 *
22 * @since 1.0.0
23 */
24 final class WP_Get_API {
25
26 /**
27 * @var The one true instance
28 * @since 1.0.0
29 */
30 protected static $_instance = null;
31
32 public $version = '2.25.5';
33
34 /**
35 * Main Instance.
36 */
37 public static function instance() {
38 if ( is_null( self::$_instance ) ) {
39 self::$_instance = new self();
40 }
41 return self::$_instance;
42 }
43
44 /**
45 * Throw error on object clone.
46 *
47 * @since 1.0.0
48 * @access protected
49 * @return void
50 */
51 public function __clone() {
52 _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'wpgetapi' ), esc_html( $this->version ) );
53 }
54
55 /**
56 * Disable unserializing of the class.
57 * @since 1.0.0
58 */
59 public function __wakeup() {
60 _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'wpgetapi' ), esc_html( $this->version ) );
61 }
62
63 /**
64 *
65 * @since 1.0.0
66 */
67 public function __construct() {
68 $this->define_constants();
69 $this->hooks();
70 $this->includes();
71
72 do_action( 'wpgetapi_loaded' );
73 }
74
75 /**
76 * Define Constants.
77 * @since 1.0.0
78 */
79 private function define_constants() {
80 $this->define( 'WPGETAPIDIR', plugin_dir_path( __FILE__ ) );
81 $this->define( 'WPGETAPIURL', plugin_dir_url( __FILE__ ) );
82 $this->define( 'WPGETAPIBASENAME', plugin_basename( __FILE__ ) );
83 $this->define( 'WPGETAPIVERSION', $this->version );
84 $this->define( 'WPGETAPILICENSEPAGE', 'wpgetapi_plugin_licenses' );
85 $this->define( 'WPGETAPISTOREURL', 'https://wpgetapi.com' );
86 }
87
88 /**
89 * Define hooks.
90 * @since 1.4.2
91 */
92 private function hooks() {
93 $plugin_file = WPGETAPIBASENAME;
94 add_filter( "plugin_action_links_{$plugin_file}", array( $this, 'plugin_action_links' ), 10, 4 );
95 add_filter( 'plugin_row_meta', array( $this, 'filter_plugin_row_meta' ), 10, 4 );
96
97 // Load translations at the init time
98 add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
99 }
100
101 /**
102 * Define constant if not already set.
103 * @since 1.0.0
104 */
105 private function define( $name, $value ) {
106 if ( ! defined( $name ) ) {
107 define( $name, $value );
108 }
109 }
110
111
112 /**
113 * Include required files.
114 * @since 1.0.0
115 */
116 public function includes() {
117
118 if ( isset( $_GET['page'] ) && strpos( sanitize_text_field( wp_unslash( $_GET['page'] ) ), 'wpgetapi_' ) !== false ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We are not processing form submission.
119 require_once WPGETAPIDIR . '/lib/cmb2/init.php';
120 }
121
122 require_once WPGETAPIDIR . '/includes/block-editor/block-editor.php';
123
124 include_once WPGETAPIDIR . 'includes/class-wpgetapi-encryption.php';
125 include_once WPGETAPIDIR . 'includes/class-wpgetapi-admin-options.php';
126
127 include_once WPGETAPIDIR . 'includes/functions.php';
128 include_once WPGETAPIDIR . 'includes/class-wpgetapi-api-enqueues.php';
129 include_once WPGETAPIDIR . 'includes/class-wpgetapi-api.php';
130
131 include_once WPGETAPIDIR . 'frontend/functions.php';
132 include_once WPGETAPIDIR . 'includes/class-wpgetapi-license-handler.php';
133
134 include_once WPGETAPIDIR . 'includes/class-wpgetapi-notices.php';
135 }
136
137 /**
138 * Filters the array of row meta for each plugin in the Plugins list table.
139 *
140 * @param array<int,string> $plugin_meta An array of the plugin row's meta data.
141 * @param string $plugin_file Path to the plugin file relative to the plugins directory.
142 * @return array<int,string> An array of the plugin row's meta data.
143 */
144 public function filter_plugin_row_meta( array $plugin_meta, $plugin_file ) {
145 if ( 'wpgetapi/wpgetapi.php' !== $plugin_file ) {
146 return $plugin_meta;
147 }
148
149 $plugin_meta[] = sprintf(
150 '<a href="%1$s">%2$s</a>',
151 'https://wpgetapi.com/docs/?utm_campaign=Docs&utm_medium=plugin&utm_source=external',
152 esc_html( 'Docs', 'wpgetapi' )
153 );
154
155 return $plugin_meta;
156 }
157
158 /**
159 * Loading translations.
160 */
161 public function load_textdomain() {
162 load_plugin_textdomain( 'wpgetapi', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
163 }
164
165 /**
166 * Adds items to the plugin's action links on the Plugins listing screen.
167 *
168 * @param array<string,string> $actions Array of action links.
169 * @param string $plugin_file Path to the plugin file relative to the plugins directory.
170 * @param mixed[] $plugin_data An array of plugin data.
171 * @param string $context The plugin context.
172 * @return array<string,string> Array of action links.
173 */
174 public function plugin_action_links( $actions, $plugin_file, $plugin_data, $context ) {
175 $new = array(
176 'setup' => sprintf(
177 '<a href="%s">%s</a>',
178 esc_url( admin_url( 'admin.php?page=wpgetapi_setup' ) ),
179 esc_html__( 'API Setup', 'wpgetapi' )
180 ),
181 );
182
183 return array_merge( $new, $actions );
184 }
185
186 /**
187 * Whether the current user can manage the WPGetAPI plugin admin
188 *
189 * @return Boolean True if the current user can manage the WPGetAPI plugin admin otheriwise false
190 */
191 public function current_user_can_manage() {
192 return current_user_can( 'manage_options' );
193 }
194
195 /**
196 * Whether the current user can manage the WPGetAPI plugin admin
197 *
198 * @return bool
199 */
200 public function is_wpgetapi_admin_page() {
201 $is_wpgetapi_admin_page = false;
202 if ( $this->current_user_can_manage() && ( isset( $_GET['page'] ) && strpos( sanitize_text_field( wp_unslash( $_GET['page'] ) ), 'wpgetapi_' ) !== false ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We are not processing form submission.
203 $is_wpgetapi_admin_page = true;
204 }
205
206 return $is_wpgetapi_admin_page;
207 }
208
209 /**
210 * Check whether any premium addon plugin is active or not.
211 *
212 * @return Boolean True if any premium addon plugin is active otherwise false.
213 */
214 public function is_any_premium_addon_plugin_active() {
215 return is_plugin_active( 'wpgetapi-extras/wpgetapi-extras.php' ) || is_plugin_active( 'wpgetapi-api-to-posts/wpgetapi-api-to-posts.php' ) || is_plugin_active( 'wpgetapi-oauth/wpgetapi-oauth.php' );
216 }
217 }
218
219 /**
220 * Run the plugin.
221 */
222 function wp_get_api() {
223 return WP_Get_API::instance();
224 }
225 wp_get_api();
226