2025-08-13 13:45:25 -07:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Handle plugin shortcodes
|
|
|
|
*/
|
|
|
|
class TWP_Shortcodes {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize shortcodes
|
|
|
|
*/
|
|
|
|
public static function init() {
|
|
|
|
add_action('init', array(__CLASS__, 'register_shortcodes'));
|
|
|
|
add_action('wp_enqueue_scripts', array(__CLASS__, 'enqueue_frontend_assets'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register all shortcodes
|
|
|
|
*/
|
|
|
|
public static function register_shortcodes() {
|
|
|
|
add_shortcode('twp_browser_phone', array(__CLASS__, 'browser_phone_shortcode'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enqueue frontend assets when shortcode is present
|
2025-09-02 11:40:49 -07:00
|
|
|
* Since we now redirect to admin, only basic styling is needed
|
2025-08-13 13:45:25 -07:00
|
|
|
*/
|
|
|
|
public static function enqueue_frontend_assets() {
|
|
|
|
global $post;
|
|
|
|
|
|
|
|
if (is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'twp_browser_phone')) {
|
2025-09-02 11:40:49 -07:00
|
|
|
// Add basic styling for the redirect interface
|
|
|
|
wp_add_inline_style('wp-admin', '
|
|
|
|
.twp-browser-phone-redirect {
|
|
|
|
padding: 20px;
|
|
|
|
border: 1px solid #ddd;
|
|
|
|
border-radius: 5px;
|
|
|
|
background: #f9f9f9;
|
|
|
|
text-align: center;
|
|
|
|
margin: 20px 0;
|
|
|
|
}
|
|
|
|
.twp-browser-phone-redirect h3 {
|
|
|
|
margin-top: 0;
|
|
|
|
color: #333;
|
|
|
|
}
|
|
|
|
.twp-browser-phone-redirect p {
|
|
|
|
margin-bottom: 15px;
|
|
|
|
}
|
|
|
|
.twp-error {
|
|
|
|
padding: 10px;
|
|
|
|
border: 1px solid #dc3232;
|
|
|
|
border-radius: 3px;
|
|
|
|
background: #fbeaea;
|
|
|
|
color: #dc3232;
|
|
|
|
margin: 10px 0;
|
|
|
|
}
|
|
|
|
');
|
2025-08-13 13:45:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Browser phone shortcode handler
|
2025-09-02 11:40:49 -07:00
|
|
|
* Redirects users to the admin browser phone page
|
2025-08-13 13:45:25 -07:00
|
|
|
*/
|
|
|
|
public static function browser_phone_shortcode($atts) {
|
|
|
|
// Check if user is logged in
|
|
|
|
if (!is_user_logged_in()) {
|
|
|
|
return '<div class="twp-error">You must be logged in to access the browser phone.</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if user has permission
|
|
|
|
if (!current_user_can('twp_access_browser_phone') && !current_user_can('manage_options')) {
|
|
|
|
return '<div class="twp-error">You don\'t have permission to access the browser phone.</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse shortcode attributes
|
|
|
|
$atts = shortcode_atts(array(
|
|
|
|
'title' => 'Browser Phone',
|
2025-09-02 11:40:49 -07:00
|
|
|
'button_text' => 'Access Browser Phone',
|
|
|
|
'target' => '_blank'
|
2025-08-13 13:45:25 -07:00
|
|
|
), $atts, 'twp_browser_phone');
|
|
|
|
|
2025-09-02 11:40:49 -07:00
|
|
|
// Generate admin URL for browser phone page
|
|
|
|
$admin_url = admin_url('admin.php?page=twilio-wp-browser-phone');
|
|
|
|
$target = ($atts['target'] === '_blank') ? 'target="_blank"' : '';
|
2025-08-13 13:45:25 -07:00
|
|
|
|
|
|
|
ob_start();
|
|
|
|
?>
|
2025-09-02 11:40:49 -07:00
|
|
|
<div class="twp-browser-phone-redirect">
|
|
|
|
<h3><?php echo esc_html($atts['title']); ?></h3>
|
|
|
|
<p>The browser phone interface has been moved to the WordPress admin area for enhanced security and functionality.</p>
|
|
|
|
<p>
|
|
|
|
<a href="<?php echo esc_url($admin_url); ?>" <?php echo $target; ?> class="button button-primary">
|
|
|
|
<?php echo esc_html($atts['button_text']); ?>
|
|
|
|
</a>
|
|
|
|
</p>
|
2025-08-13 13:45:25 -07:00
|
|
|
</div>
|
|
|
|
<?php
|
|
|
|
return ob_get_clean();
|
|
|
|
}
|
|
|
|
}
|