| 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: 1.8.4 |
| 9 |
* Text Domain: wpgetapi |
| 10 |
* License: GPL2 or later |
| 11 |
* |
| 12 |
*/ |
| 13 |
|
| 14 |
// Exit if accessed directly. |
| 15 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 16 |
|
| 17 |
/** |
| 18 |
* Main Class. |
| 19 |
* |
| 20 |
* @since 1.0.0 |
| 21 |
*/ |
| 22 |
final class WpGetApi { |
| 23 |
|
| 24 |
/** |
| 25 |
* @var The one true instance |
| 26 |
* @since 1.0.0 |
| 27 |
*/ |
| 28 |
protected static $_instance = null; |
| 29 |
|
| 30 |
public $version = '1.8.4'; |
| 31 |
|
| 32 |
/** |
| 33 |
* Main Instance. |
| 34 |
*/ |
| 35 |
public static function instance() { |
| 36 |
if ( is_null( self::$_instance ) ) { |
| 37 |
self::$_instance = new self(); |
| 38 |
} |
| 39 |
return self::$_instance; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Throw error on object clone. |
| 44 |
* |
| 45 |
* @since 1.0.0 |
| 46 |
* @access protected |
| 47 |
* @return void |
| 48 |
*/ |
| 49 |
public function __clone() { |
| 50 |
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'wpgetapi' ), '1.0.0' ); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Disable unserializing of the class. |
| 55 |
* @since 1.0.0 |
| 56 |
*/ |
| 57 |
public function __wakeup() { |
| 58 |
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'wpgetapi' ), '1.0.0' ); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* |
| 63 |
* @since 1.0.0 |
| 64 |
*/ |
| 65 |
public function __construct() { |
| 66 |
$this->define_constants(); |
| 67 |
$this->hooks(); |
| 68 |
$this->includes(); |
| 69 |
|
| 70 |
do_action( 'wpgetapi_loaded' ); |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Define Constants. |
| 75 |
* @since 1.0.0 |
| 76 |
*/ |
| 77 |
private function define_constants() { |
| 78 |
$this->define( 'WPGETAPIDIR',plugin_dir_path( __FILE__ ) ); |
| 79 |
$this->define( 'WPGETAPIURL',plugin_dir_url( __FILE__ ) ); |
| 80 |
$this->define( 'WPGETAPIBASENAME', plugin_basename( __FILE__ ) ); |
| 81 |
$this->define( 'WPGETAPIVERSION', $this->version ); |
| 82 |
$this->define( 'WPGETAPILICENSEPAGE', 'wpgetapi_plugin_licenses' ); |
| 83 |
$this->define( 'WPGETAPISTOREURL', 'https://wpgetapi.com' ); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Define hooks. |
| 88 |
* @since 1.4.2 |
| 89 |
*/ |
| 90 |
private function hooks() { |
| 91 |
$plugin_file = WPGETAPIBASENAME; |
| 92 |
add_filter( "plugin_action_links_{$plugin_file}", array( $this, 'plugin_action_links' ), 10, 4 ); |
| 93 |
add_filter( 'plugin_row_meta', array( $this, 'filter_plugin_row_meta' ), 10, 4 ); |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Define constant if not already set. |
| 98 |
* @since 1.0.0 |
| 99 |
*/ |
| 100 |
private function define( $name, $value ) { |
| 101 |
if ( ! defined( $name ) ) { |
| 102 |
define( $name, $value ); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
/** |
| 108 |
* Include required files. |
| 109 |
* @since 1.0.0 |
| 110 |
*/ |
| 111 |
public function includes() { |
| 112 |
|
| 113 |
require_once ( WPGETAPIDIR . '/lib/cmb2/init.php' ); |
| 114 |
require_once ( WPGETAPIDIR . '/includes/block-editor/block-editor.php' ); |
| 115 |
|
| 116 |
include_once ( WPGETAPIDIR . 'includes/class-encryption.php' ); |
| 117 |
include_once ( WPGETAPIDIR . 'includes/class-admin-options.php' ); |
| 118 |
|
| 119 |
include_once ( WPGETAPIDIR . 'includes/functions.php' ); |
| 120 |
include_once ( WPGETAPIDIR . 'includes/class-enqueues.php' ); |
| 121 |
include_once ( WPGETAPIDIR . 'includes/class-api.php' ); |
| 122 |
|
| 123 |
include_once ( WPGETAPIDIR . 'frontend/functions.php' ); |
| 124 |
include_once ( WPGETAPIDIR . 'includes/class-licenses.php' ); |
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* Filters the array of row meta for each plugin in the Plugins list table. |
| 130 |
* |
| 131 |
* @param array<int,string> $plugin_meta An array of the plugin row's meta data. |
| 132 |
* @param string $plugin_file Path to the plugin file relative to the plugins directory. |
| 133 |
* @return array<int,string> An array of the plugin row's meta data. |
| 134 |
*/ |
| 135 |
function filter_plugin_row_meta( array $plugin_meta, $plugin_file ) { |
| 136 |
if ( 'wpgetapi/wpgetapi.php' !== $plugin_file ) { |
| 137 |
return $plugin_meta; |
| 138 |
} |
| 139 |
|
| 140 |
$plugin_meta[] = sprintf( |
| 141 |
'<a href="%1$s">%2$s</a>', |
| 142 |
'https://wpgetapi.com/docs/?utm_campaign=Docs&utm_medium=plugin&utm_source=external', |
| 143 |
esc_html( 'Docs', 'wpgetapi' ) |
| 144 |
); |
| 145 |
|
| 146 |
return $plugin_meta; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
/** |
| 151 |
* Adds items to the plugin's action links on the Plugins listing screen. |
| 152 |
* |
| 153 |
* @param array<string,string> $actions Array of action links. |
| 154 |
* @param string $plugin_file Path to the plugin file relative to the plugins directory. |
| 155 |
* @param mixed[] $plugin_data An array of plugin data. |
| 156 |
* @param string $context The plugin context. |
| 157 |
* @return array<string,string> Array of action links. |
| 158 |
*/ |
| 159 |
function plugin_action_links( $actions, $plugin_file, $plugin_data, $context ) { |
| 160 |
$new = array( |
| 161 |
'setup' => sprintf( |
| 162 |
'<a href="%s">%s</a>', |
| 163 |
esc_url( admin_url( 'admin.php?page=wpgetapi_setup' ) ), |
| 164 |
esc_html__( 'API Setup', 'wpgetapi' ) |
| 165 |
), |
| 166 |
); |
| 167 |
|
| 168 |
return array_merge( $new, $actions ); |
| 169 |
} |
| 170 |
|
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
/** |
| 175 |
* Run the plugin. |
| 176 |
*/ |
| 177 |
function WpGetApi() { |
| 178 |
return WpGetApi::instance(); |
| 179 |
} |
| 180 |
WpGetApi(); |