about
7 years ago
css
7 years ago
img
7 years ago
js
7 years ago
menu
7 years ago
partials
7 years ago
scss
7 years ago
settings
7 years ago
admin-notices.php
7 years ago
admin.php
7 years ago
class-strong-testimonials-addons.php
7 years ago
class-strong-testimonials-admin-category-list.php
7 years ago
class-strong-testimonials-admin-list.php
7 years ago
class-strong-testimonials-admin-scripts.php
7 years ago
class-strong-testimonials-defaults.php
7 years ago
class-strong-testimonials-exporter.php
7 years ago
class-strong-testimonials-help.php
7 years ago
class-strong-testimonials-list-table.php
7 years ago
class-strong-testimonials-page-shortcodes.php
7 years ago
class-strong-testimonials-post-editor.php
7 years ago
class-strong-testimonials-updater.php
7 years ago
class-strong-testimonials-upsell.php
7 years ago
class-strong-views-list-table.php
7 years ago
class-walker-strong-category-checklist.php
7 years ago
class-walker-strong-form-category-checklist.php
7 years ago
compat.php
7 years ago
custom-fields-ajax.php
7 years ago
custom-fields.php
7 years ago
form-preview.php
7 years ago
view-list-order.php
7 years ago
views-ajax.php
7 years ago
views-validate.php
7 years ago
views.php
7 years ago
class-strong-testimonials-addons.php
133 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class Strong_Testimonials_Addons |
| 4 | * |
| 5 | * @since 2.38 |
| 6 | */ |
| 7 | class Strong_Testimonials_Addons { |
| 8 | |
| 9 | private $addons = array(); |
| 10 | |
| 11 | public function __construct() { |
| 12 | add_filter( 'wpmtst_submenu_pages', array( $this, 'add_submenu' ) ); |
| 13 | |
| 14 | // Add ajax action to reload extensions |
| 15 | add_action( 'wp_ajax_wpmtst_reload_extensions', array( $this, 'reload_extensions' ), 20 ); |
| 16 | } |
| 17 | |
| 18 | private function check_for_addons() { |
| 19 | |
| 20 | if ( false !== ( $data = get_transient( 'strong_testimonials_all_extensions' ) ) ) { |
| 21 | return $data; |
| 22 | } |
| 23 | |
| 24 | $addons = array(); |
| 25 | |
| 26 | $url = apply_filters( 'strong_testimonials_addon_server_url', WPMTST_STORE_URL . '/wp-json/mt/v1/get-all-extensions' ); |
| 27 | |
| 28 | // Get data from the remote URL. |
| 29 | $response = wp_remote_get( $url ); |
| 30 | |
| 31 | if ( ! is_wp_error( $response ) ) { |
| 32 | |
| 33 | // Decode the data that we got. |
| 34 | $data = json_decode( wp_remote_retrieve_body( $response ), true ); |
| 35 | |
| 36 | if ( ! empty( $data ) && is_array( $data ) ) { |
| 37 | $addons = $data; |
| 38 | // Store the data for a week. |
| 39 | set_transient( 'strong_testimonials_all_extensions', $data, 7 * DAY_IN_SECONDS ); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | return apply_filters( 'wpmtst_addons', $addons ); |
| 44 | } |
| 45 | |
| 46 | public function render_addons() { |
| 47 | |
| 48 | wp_enqueue_style( 'wpmtst-admin-style' ); |
| 49 | wp_enqueue_script( 'wpmtst-admin-script' ); |
| 50 | |
| 51 | if ( ! empty( $this->addons ) ) { |
| 52 | foreach ( $this->addons as $addon ) { |
| 53 | $image = ( '' != $addon['image'] ) ? $addon['image'] : WPMTST_ASSETS_IMG . '/logo.png'; |
| 54 | echo '<div class="wpmtst-addon">'; |
| 55 | echo '<div class="wpmtst-addon-box">'; |
| 56 | echo '<img src="' . esc_attr( $image ) . '">'; |
| 57 | echo '<div class="wpmtst-addon-content">'; |
| 58 | echo '<h3>' . esc_html( $addon['name'] ) . '</h3>'; |
| 59 | echo '<div class="wpmtst-addon-description">' . wp_kses_post( $addon['description'] ) . '</div>'; |
| 60 | echo '</div>'; |
| 61 | echo '</div>'; |
| 62 | echo '<div class="wpmtst-addon-actions">'; |
| 63 | echo apply_filters( 'wpmtst_addon_button_action', '<a href="' . esc_url( WPMTST_STORE_UPGRADE_URL . '?utm_source=st-lite&utm_campaign=upsell&utm_medium=' . esc_attr( $addon['slug'] ) ) . '" target="_blank" class="button primary-button">' . esc_html__( 'Upgrade to PRO', 'strong-testimonials' ) . '</a>', $addon ); |
| 64 | echo '</div>'; |
| 65 | echo '</div>'; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Add submenu page. |
| 73 | * |
| 74 | * @param $pages |
| 75 | * |
| 76 | * @return mixed |
| 77 | */ |
| 78 | public function add_submenu( $pages ) { |
| 79 | $pages[91] = $this->get_submenu(); |
| 80 | return $pages; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Return submenu page parameters. |
| 85 | * |
| 86 | * @return array |
| 87 | */ |
| 88 | public function get_submenu() { |
| 89 | return array( |
| 90 | 'page_title' => __( 'Extensions', 'strong-testimonials' ), |
| 91 | 'menu_title' => __( 'Extensions', 'strong-testimonials' ), |
| 92 | 'capability' => 'strong_testimonials_options', |
| 93 | 'menu_slug' => 'strong-testimonials-addons', |
| 94 | 'function' => array( $this, 'addons_page' ), |
| 95 | ); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | /** |
| 100 | * Print the Addons page. |
| 101 | */ |
| 102 | public function addons_page() { |
| 103 | |
| 104 | $this->addons = $this->check_for_addons(); |
| 105 | ?> |
| 106 | |
| 107 | <div class="wrap"> |
| 108 | <h1 style="margin-bottom: 20px; display: inline-block;"><?php esc_html_e( 'Extensions', 'strong-testimonials' ); ?></h1> |
| 109 | |
| 110 | <a id="wpmtst-reload-extensions" class="button button-primary" style="margin: 10px 0 0 30px;" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wpmtst-reload-extensions' ) ); ?>"><?php esc_html_e( 'Reload Extensions', 'strong-testimonials' ); ?></a> |
| 111 | |
| 112 | <div class="wpmtst-addons-container"> |
| 113 | <?php $this->render_addons(); ?> |
| 114 | </div> |
| 115 | </div> |
| 116 | <?php |
| 117 | } |
| 118 | |
| 119 | public function reload_extensions() { |
| 120 | // Run a security check first. |
| 121 | check_admin_referer( 'wpmtst-reload-extensions', 'nonce' ); |
| 122 | |
| 123 | delete_transient( 'strong_testimonials_all_extensions' ); |
| 124 | |
| 125 | die; |
| 126 | } |
| 127 | |
| 128 | |
| 129 | |
| 130 | } |
| 131 | |
| 132 | new Strong_Testimonials_Addons(); |
| 133 |