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 / Admin / Plugin_Promo.php

Plugin_Promo.php in Posts Table with Search & Sort 1.3.4, at lib/Admin/Plugin_Promo.php

64 lines 1.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\Admin;
3
4 use Barn2\PTS_Lib\Registerable,
5 Barn2\PTS_Lib\Plugin\Plugin;
6
7 /**
8 * Provides functions to add the plugin promo to the plugin settings page in the WordPress admin.
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.0
15 */
16 class Plugin_Promo implements Registerable {
17
18 private $plugin;
19 private $plugin_id;
20
21 public function __construct( Plugin $plugin ) {
22 $this->plugin = $plugin;
23 $this->plugin_id = $plugin->get_id();
24 }
25
26 public function register() {
27 add_action( 'barn2_after_plugin_settings', [ $this, 'render_promo' ] );
28 add_action( 'admin_enqueue_scripts', [ $this, 'load_styles' ] );
29 }
30
31 public function load_styles() {
32 wp_enqueue_style( 'barn2-promo', plugins_url( 'lib/assets/css/admin/plugin-promo.min.css', $this->plugin->get_file() ) );
33 }
34
35 public function render_promo() {
36 $promo_content = $this->get_promo_content();
37
38 if ( ! empty( $promo_content ) ) {
39 echo '<div id="barn2_plugin_promo" class="barn2-plugin-promo">' . $promo_content . '</div>';
40 }
41 }
42
43 private function get_promo_content() {
44 if ( ( $promo_content = get_transient( 'barn2_plugin_promo_' . $this->plugin_id ) ) === false ) {
45 $promo_response = wp_remote_get( 'https://barn2.co.uk/wp-json/barn2/v2/pluginpromo/' . $this->plugin_id . '?_=' . date( 'mdY' ) );
46
47 if ( wp_remote_retrieve_response_code( $promo_response ) != 200 ) {
48 return;
49 }
50
51 $promo_content = json_decode( wp_remote_retrieve_body( $promo_response ), true );
52
53 set_transient( 'barn2_plugin_promo_' . $this->plugin_id, $promo_content, DAY_IN_SECONDS );
54 }
55
56 if ( empty( $promo_content ) || is_array( $promo_content ) ) {
57 return;
58 }
59
60 return $promo_content;
61 }
62
63 }
64