PluginProbe
BetterLinks – Link Shortener, Link Cloaking, Redirects, Affiliate Link Manager & MCP / trunk
BetterLinks – Link Shortener, Link Cloaking, Redirects, Affiliate Link Manager & MCP vtrunk
3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 3.0.0 2.4.13 2.4.12 2.4.11 2.4.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 All 110 releases
betterlinks / includes / Admin / Metabox.php

Metabox.php in BetterLinks – Link Shortener, Link Cloaking, Redirects, Affiliate Link Manager & MCP trunk, at includes/Admin/Metabox.php

294 lines 12.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BetterLinks\Admin;
4 if ( ! defined( 'ABSPATH' ) ) { exit; }
5
6 class Metabox {
7
8 private $is_pro_enabled;
9 public static function init() {
10 $self = new self();
11 $self->is_pro_enabled = apply_filters('betterlinks/pro_enabled', false);
12 add_action('add_meta_boxes', [$self, 'add_auto_create_shortlink_teaser'], 10, 2);
13 add_action('add_meta_boxes', [$self, 'add_affiliate_disclosure_teaser'], 10, 2);
14 add_action('add_meta_boxes', [$self, 'add_ai_link_assistant_teaser'], 10, 2);
15 }
16
17 /**
18 * The AI Link Assistant ships in BetterLinks Pro 2.8.0+. Free users and older
19 * Pro builds get the locked teaser metabox instead of the real feature.
20 */
21 private function is_link_genius_available() {
22 return $this->is_pro_enabled
23 && defined('BETTERLINKS_PRO_VERSION')
24 && version_compare(BETTERLINKS_PRO_VERSION, '2.8.0', '>=');
25 }
26
27 public function add_ai_link_assistant_teaser( $post_type, $post ) {
28 if ( ! $this->is_link_genius_available() && ! $this->is_using_gutenberg_block() && in_array( $post_type, ['post', 'page'] ) ) {
29 // Existing Pro users (on an older build) own Pro — no "Pro" badge for them.
30 $title = $this->is_pro_enabled
31 ? esc_html__( 'AI Link Assistant', 'betterlinks' )
32 : esc_html__( 'AI Link Assistant', 'betterlinks' ) . '<span class="pro-badge">' . esc_html__( 'Pro', 'betterlinks' ) . '</span>';
33 add_meta_box('betterlinks-ai-link-assistant-teaser', $title, [$this, 'ai_link_assistant_teaser'], $post_type, 'side', 'core');
34 }
35 }
36
37 public function ai_link_assistant_teaser() {
38 // Existing Pro user on an older build → prompt to update; free user → upsell.
39 $is_old_pro = $this->is_pro_enabled;
40 $badge = $is_old_pro ? '' : '<span class="pro-badge">' . esc_html__( 'Pro', 'betterlinks' ) . '</span>';
41 $cta_url = $is_old_pro ? self_admin_url( 'update-core.php' ) : 'https://wpdeveloper.com/in/upgrade-betterlinks';
42 $cta_label = $is_old_pro ? __( 'Update BetterLinks Pro', 'betterlinks' ) : __( 'Upgrade to PRO', 'betterlinks' );
43 $cta_target = $is_old_pro ? '_self' : '_blank';
44 ?>
45 <div class="betterlinks-ai-link-assistant">
46 <p><?php esc_html_e( 'Get smart, AI-powered link suggestions ranked by your own click data while you write.', 'betterlinks' ); ?></p>
47 <?php if ( $is_old_pro ) : ?>
48 <p class="betterlinks-ai-link-assistant__note">
49 <?php
50 printf(
51 /* translators: %s: minimum required BetterLinks Pro version. */
52 esc_html__( 'Requires BetterLinks Pro v%s or greater. Please update to use it.', 'betterlinks' ),
53 '2.8.0'
54 );
55 ?>
56 </p>
57 <?php endif; ?>
58 <div class="betterlinks-form-group betterlinks-form-flex">
59 <label>
60 <?php esc_html_e( 'Smart link suggestions', 'betterlinks' ); ?>
61 <?php echo wp_kses_post( $badge ); ?>
62 </label>
63 <input type="text" placeholder="<?php esc_attr_e( 'e.g. “link management” → /go/link-management', 'betterlinks' ); ?>" disabled />
64 </div>
65 <div class="betterlinks-form-group betterlinks-form-flex">
66 <label>
67 <?php esc_html_e( 'Auto-detect &amp; cloak raw URLs', 'betterlinks' ); ?>
68 <?php echo wp_kses_post( $badge ); ?>
69 </label>
70 <input type="text" placeholder="www.example.com → /go/example" disabled />
71 </div>
72 <a class="betterlinks-ai-link-assistant__cta" href="<?php echo esc_url( $cta_url ); ?>" target="<?php echo esc_attr( $cta_target ); ?>" rel="noopener noreferrer">
73 <?php echo esc_html( $cta_label ); ?>
74 </a>
75 </div>
76 <style>
77 .betterlinks-ai-link-assistant .betterlinks-form-group {
78 margin-bottom: 1rem;
79 }
80 .betterlinks-ai-link-assistant .betterlinks-form-flex {
81 display: flex;
82 flex-direction: column;
83 }
84 .betterlinks-ai-link-assistant input {
85 width: 100%;
86 cursor: not-allowed;
87 box-sizing: border-box;
88 }
89 .betterlinks-ai-link-assistant__note {
90 margin: 0 0 1rem;
91 padding: 8px 10px;
92 border-radius: 4px;
93 background: #FFF8F1;
94 border: 1px solid #FFE7CC;
95 color: #92400e;
96 font-size: 12px;
97 line-height: 1.5;
98 }
99 .betterlinks-ai-link-assistant__cta {
100 display: inline-flex;
101 align-items: center;
102 justify-content: center;
103 width: 100%;
104 box-sizing: border-box;
105 padding: 9px 18px;
106 margin-top: 4px;
107 border-radius: 6px;
108 background: linear-gradient(202deg, #2961ff 0%, #003be2 100%);
109 color: #fff;
110 font-size: 13px;
111 font-weight: 600;
112 text-decoration: none;
113 }
114 .betterlinks-ai-link-assistant__cta:hover {
115 color: #fff;
116 opacity: 0.92;
117 }
118 .betterlinks-ai-link-assistant span.pro-badge {
119 background: linear-gradient(202deg, #2961ff 0%, #003be2 100%);
120 color: #fff;
121 border-radius: 2px;
122 padding: 3px 6px;
123 font-size: 10px;
124 margin-left: 3px;
125 line-height: 1;
126 text-transform: uppercase;
127 display: inline-flex;
128 align-items: center;
129 transform: translateY(-10px);
130 }
131 </style>
132 <?php
133 }
134
135 public function add_affiliate_disclosure_teaser( $post_type, $post ) {
136 if( !$this->is_pro_enabled && !$this->is_using_gutenberg_block() && in_array( $post_type, ['post', 'page'])) {
137 add_meta_box('betterlinks-affiliate-disclosure-teaser', __('BetterLinks Affiliate Disclosure<span class="pro-badge">Pro</span>', 'betterlinks'), [$this, 'affiliate_disclosure_teaser'], $post_type, 'side', 'core');
138 }
139 }
140
141 public function affiliate_disclosure_teaser($post) {
142 ?>
143 <div>
144 <p>
145 <?php
146 /* translators: %s: post type slug (post, page, etc.) */
147 printf( esc_html__( 'This will allow you to add an Affiliate Link Disclosure in this %s', 'betterlinks' ), esc_html( $post->post_type ) );
148 ?>
149 </p>
150 <div class="betterlinks-affiliate-link-disclosure">
151 <div class="betterlinks-form-group betterlinks-form-flex">
152 <label>
153 <?php esc_html_e('Affiliate Disclosure Position', 'betterlinks') ?>
154 <span class="pro-badge">
155 <?php esc_html_e('Pro', 'betterlinks') ?>
156 </span>
157 </label>
158 <select name="betterlinks_affiliate_disclosure_position" style="width: 100%;cursor: not-allowed;" disabled>
159 <option value="">Select Position</option>
160 </select>
161 </div>
162 <div class="betterlinks-form-group betterlinks-form-flex">
163 <label>
164 <?php esc_html_e('Affiliate Disclosure Text', 'betterlinks') ?>
165 <span class="pro-badge">
166 <?php esc_html_e('Pro', 'betterlinks') ?>
167 </span>
168 </label>
169 <textarea name="affiliate_disclosure_text" style="width: 100%;" disabled></textarea>
170 </div>
171 </div>
172 <div>
173 </div>
174 </div>
175 <style>
176 .betterlinks-form-group {
177 margin-bottom:1rem;
178 }
179 .betterlinks-form-group input,
180 .betterlinks-form-group textarea {
181 cursor: not-allowed;
182 }
183 .betterlinks-form-flex {
184 display: flex;
185 flex-direction: column;
186 }
187 span.pro-badge {
188 background: linear-gradient(202deg,#2961ff 0%,#003be2 100%);
189 color: #fff;
190 border-radius: 2px;
191 padding: 3px 6px;
192 font-size: 10px;
193 margin-left: 3px;
194 line-height: 1;
195 text-transform: uppercase;
196 display: inline-flex;
197 align-items: center;
198 border-radius: 2px;
199 transform: translateY(-10px);
200 }
201 </style>
202 <?php
203 }
204
205 public function add_auto_create_shortlink_teaser( $post_type, $post ) {
206 if( !$this->is_pro_enabled && !$this->is_using_gutenberg_block() && in_array( $post_type, ['post', 'page', 'product'])) {
207 add_meta_box('betterlinks-auto-create-shortlink-teaser', __('BetterLinks Auto-Create Links<span class="pro-badge">Pro</span>', 'betterlinks'), [$this, 'auto_create_shortlink_teaser'], $post_type, 'side', 'core');
208 }
209 }
210
211 public function auto_create_shortlink_teaser() {
212 ?>
213 <div>
214 <p><?php esc_html_e( 'A BetterLink for this post will be generated on publish', 'betterlinks' ) ?></p>
215 <div class="betterlinks_auto_create_link_form">
216 <div class="betterlinks-form-group">
217 <label>
218 <?php echo esc_html( site_url() . '/' ); ?>
219 <span class="pro-badge">
220 <?php esc_html_e('Pro', 'betterlinks') ?>
221 </span>
222 </label>
223 <div style="display: flex; align-items: center;justify-content: space-between;">
224 <input
225 type="text"
226 name="betterlinks_auto_create_shortlinks"
227 id="betterlinks_auto_create_shortlinks"
228 disabled
229 />
230 </div>
231 </div>
232 <div class="betterlinks-form-group betterlinks-form-flex">
233 <label>
234 <?php esc_html_e('BetterLinks Category', 'betterlinks') ?>
235 <span class="pro-badge">
236 <?php esc_html_e('Pro', 'betterlinks') ?>
237 </span>
238 </label>
239 <select name="betterlinks_auto_link_category" disabled style="cursor: not-allowed;">
240 <option value="">Select Category</option>
241 </select>
242 </div>
243 <div class="betterlinks-form-group betterlinks-form-flex">
244 <label>
245 <?php esc_html_e('Redirect Type', 'betterlinks') ?>
246 <span class="pro-badge">
247 <?php esc_html_e('Pro', 'betterlinks') ?>
248 </span>
249 </label>
250 <select name="betterlinks_auto_link_redirect_type" disabled style="cursor: not-allowed;">
251 <option value="">Select Type</option>
252 </select>
253 </div>
254 </div>
255 </div>
256 <style>
257 .betterlinks-form-group {
258 margin-bottom:1rem;
259 }
260 .betterlinks-form-group input {
261 cursor: not-allowed;
262 }
263 .betterlinks-form-flex {
264 display: flex;
265 flex-direction: column;
266 }
267 #betterlinks_auto_create_shortlinks{
268 flex-grow: 1;
269 }
270 span.pro-badge {
271 background: linear-gradient(202deg,#2961ff 0%,#003be2 100%);
272 color: #fff;
273 border-radius: 2px;
274 padding: 3px 6px;
275 font-size: 10px;
276 margin-left: 3px;
277 line-height: 1;
278 text-transform: uppercase;
279 display: inline-flex;
280 align-items: center;
281 border-radius: 2px;
282 transform: translateY(-10px);
283 }
284 </style>
285 <?php
286 }
287
288 public function is_using_gutenberg_block() {
289 $current_screen = get_current_screen();
290 $is_using_block_editor = $current_screen->is_block_editor || (function_exists( 'is_gutenberg_page' ) && is_gutenberg_page());
291 return $is_using_block_editor;
292 }
293 }
294