PluginProbe
Autoptimize / 3.1.16
Autoptimize v3.1.16
3.1.16 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 All 108 releases
autoptimize / classes / autoptimizeProTab.php

autoptimizeProTab.php in Autoptimize 3.1.16, at classes/autoptimizeProTab.php

134 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles adding "more tools" tab in AO admin settings page which promotes (future) AO
4 * addons and/or affiliate services.
5 */
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 class autoptimizeProTab
12 {
13 /**
14 * Random title string.
15 *
16 * @var string
17 */
18 protected $rnd_title = null;
19
20 public function __construct()
21 {
22 $this->run();
23 }
24
25 public function run()
26 {
27 if ( $this->enabled() ) {
28 add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_pro_tabs' ), 10, 1 );
29 }
30 if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
31 add_action( 'network_admin_menu', array( $this, 'add_admin_menu' ) );
32 } else {
33 add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
34 }
35 }
36
37 protected function enabled()
38 {
39 return apply_filters( 'autoptimize_filter_show_partner_tabs', true );
40 }
41
42 public function add_pro_tabs( $in )
43 {
44 $in = array_merge(
45 $in,
46 array(
47 'ao_protab' => '&#x1F680; ' . $this->get_rnd_title()
48 )
49 );
50
51 return $in;
52 }
53
54 public function add_admin_menu()
55 {
56 if ( $this->enabled() ) {
57 add_submenu_page( '', 'AO pro', 'AO pro', 'manage_options', 'ao_protab', array( $this, 'ao_pro_page' ) );
58 }
59 }
60
61 public function ao_pro_page()
62 {
63 ?>
64 <style>
65 .ao_settings_div {background: white;border: 1px solid #ccc;padding: 1px 15px;margin: 15px 10px 10px 0;font-size: 120% !important; padding-bottom:20px;}
66 .ao_settings_div p {font-size:110%;}
67
68 #aoprocontainer{width:100%;overflow:hidden;}
69 #aoprotxt{width:68%;float:left;}
70 #aoprobuy { background:#ba4102;text-align:center;border-radius:25px; }
71 #aoprobuy p {margin:.25em 1em}
72 #aoprobuy p#cta {font-size:150%;}
73 #aoproimg {width:28%;float:right;}
74
75 @media (max-width:699px) {
76 #aoproimg{display:none;}
77 #aoprotxt{width:100% !important;}
78 #aoprobuy{font-size:70%;}
79 }
80 </style>
81 <script>document.title = "Autoptimize: <?php echo $this->get_rnd_title() ?> " + document.title;</script>
82 <div class="wrap">
83 <h1><?php apply_filters( 'autoptimize_filter_settings_is_pro', false ) ? esc_html_e( 'Autoptimize Pro Settings', 'autoptimize' ) : esc_html_e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
84 <?php
85 echo autoptimizeConfig::ao_admin_tabs();
86 $aopro_explanation = '';
87
88 $_transient = 'aopro_explain';
89 $_explain_html = 'https://misc.optimizingmatters.com/aopro_explain.html?ao_ver=';
90
91 // get the HTML with the explanation of what AOPro is.
92 if ( apply_filters( 'autoptimize_settingsscreen_remotehttp', true ) ) {
93 $aopro_explanation = get_transient( $_transient );
94 if ( empty( $aopro_explanation ) ) {
95 $ccss_expl_resp = wp_remote_get( $_explain_html . AUTOPTIMIZE_PLUGIN_VERSION );
96 if ( ! is_wp_error( $ccss_expl_resp ) ) {
97 if ( '200' == wp_remote_retrieve_response_code( $ccss_expl_resp ) ) {
98 $aopro_explanation = wp_kses_post( wp_remote_retrieve_body( $ccss_expl_resp ) );
99 set_transient( $_transient, $aopro_explanation, WEEK_IN_SECONDS );
100 }
101 }
102 }
103 }
104
105 // placeholder text in case HTML is empty.
106 if ( empty( $aopro_explanation ) ) {
107 // translators: h2, strong but also 2 links.
108 $aopro_explanation = sprintf( esc_html__( '%1$sAdd more power to Autoptimize with Pro!%2$s%3$sAs a user of Autoptimize you understand %5$sthe importance of having a fast site%6$s. Autoptimize Pro is a premium Power-Up extending AO by adding %5$simage optimization, CDN, automatic critical CSS rules generation and page caching but also providing extra “booster” options%6$s, all in one handy subscription to make your site even faster!%4$s%3$sHave a look at %7$shttps://autoptimize.com/pro/%8$s for more info or %9$sclick here to buy now%10$s!%4$s', 'autoptimize' ), '<h2>', '</h2>', '<p>', '</p>', '<strong>', '</strong>', '<a href="https://autoptimize.com/pro/" target="_blank">', '</a>', '<a href="https://checkout.freemius.com/mode/dialog/plugin/10906/plan/18508/?currency=auto" target="_blank">', '</a>' );
109 } else {
110 // we were able to fetch the explenation, so add the JS to show correct language.
111 $aopro_explanation .= "<script>jQuery('.ao_i18n').hide();d=document;lang=d.getElementsByTagName('html')[0].getAttribute('lang').substring(0,2);if(d.getElementById(lang)!= null){jQuery('#'+lang).show();}else{jQuery('#default').show();}</script>";
112 }
113 ?>
114 <div class="ao_settings_div">
115 <?php
116 // and echo it.
117 echo $aopro_explanation;
118 ?>
119 </div>
120 </div>
121 <?php
122 }
123
124 public function get_rnd_title() {
125 // alternate between tab title every 5 minutes.
126 if ( floor( date( "i", time() ) / 5 ) %2 === 0 ) {
127 $this->rnd_title = esc_html__( 'Page Cache', 'autoptimize' );
128 } else {
129 $this->rnd_title = esc_html__( 'Pro Boosters', 'autoptimize' );
130 }
131 return $this->rnd_title;
132 }
133 }
134