wp-reviews-plugin-for-google
Last commit date
include
1 month ago
languages
6 months ago
static
6 days ago
tabs
1 month ago
readme.txt
1 month ago
settings.php
7 months ago
trustindex-google-widget.class.php
6 months ago
trustindex-plugin.class.php
1 month ago
uninstall.php
1 month ago
wordfence-vendor.txt
6 months ago
wp-reviews-plugin-for-google.php
1 month ago
trustindex-google-widget.class.php
133 lines
| 1 | <?php |
| 2 | defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
| 3 | class TrustindexWidget_google extends WP_Widget { |
| 4 | private $widget_fields = [ |
| 5 | 'ti-widget-ID' => [ |
| 6 | 'default' => '', |
| 7 | 'required' => true, |
| 8 | 'placeholder' => 'eg.: 478dcc2136263f2b3a3726ff', |
| 9 | 'name' => 'Trustindex Widget ID', |
| 10 | 'help' => null, |
| 11 | 'help-icon' => '<span class="dashicons dashicons-editor-help btn-insert-tooltip"></span>' |
| 12 | ], |
| 13 | ]; |
| 14 | private $errors = array(); |
| 15 | public function __construct() |
| 16 | { |
| 17 | parent::__construct( |
| 18 | 'trustindex_google_widget', |
| 19 | 'Review Widgets for Google', |
| 20 | [ |
| 21 | 'classname' => 'trustindex-widget', |
| 22 | 'description' => 'Embed Google reviews fast and easily into your WordPress site. Increase SEO, trust and sales using Google reviews.' |
| 23 | ] |
| 24 | ); |
| 25 | } |
| 26 | function widget($args, $instance) |
| 27 | { |
| 28 | global $wpdb; |
| 29 | global $trustindex_pm_google; |
| 30 | $pluginManager = 'TrustindexPlugin_google'; |
| 31 | $pluginManagerInstance = $trustindex_pm_google; |
| 32 | if ($pluginManagerInstance->is_enabled()) { |
| 33 | extract($args); |
| 34 | echo wp_kses_post($before_widget); |
| 35 | $wasError = false; |
| 36 | foreach ($this->widget_fields as $fname => $fparams) { |
| 37 | if ($fparams['required'] && (!isset($instance[ $fname ]) || $instance[ $fname ] == "")) { |
| 38 | $wasError = true; |
| 39 | break; |
| 40 | } |
| 41 | } |
| 42 | if (!$wasError && $instance['ti-widget-ID']) { |
| 43 | echo wp_kses($pluginManagerInstance->renderWidgetFrontend($instance['ti-widget-ID']), $pluginManager::$allowedAttributesForWidget); |
| 44 | } else if ($pluginManagerInstance->is_noreg_linked()) { |
| 45 | $html = preg_replace('/<style\b[^>]*>.*?<\/style>/is', '', $pluginManagerInstance->renderWidgetFrontend()); |
| 46 | echo wp_kses($html, $pluginManager::$allowedAttributesForWidget); |
| 47 | if (!is_file($chosedPlatform->getCssFile()) || get_option($chosedPlatform->get_option_name('load-css-inline'), 0)) { |
| 48 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 49 | echo '<style type="text/css">'.get_option($chosedPlatform->get_option_name('css-content')).'</style>'; |
| 50 | } |
| 51 | } else { |
| 52 | /* translators: %s: URL */ |
| 53 | echo wp_kses_post($pluginManagerInstance->frontEndErrorForAdmins(sprintf(__("Please fill out <strong>all the required fields</strong> in the <a href='%s'>widget settings</a> page", 'wp-reviews-plugin-for-google'), admin_url('admin.php?page='.$pluginManagerInstance->get_plugin_slug().'/settings.php')))); |
| 54 | } |
| 55 | echo wp_kses_post($after_widget); |
| 56 | } else { |
| 57 | } |
| 58 | } |
| 59 | function form($instance) |
| 60 | { |
| 61 | global $wp_version; |
| 62 | global $trustindex_pm_google; |
| 63 | $pluginManager = 'TrustindexPlugin_google'; |
| 64 | $pluginManagerInstance = $trustindex_pm_google; |
| 65 | $tiWidgets = $pluginManagerInstance->get_trustindex_widgets(); |
| 66 | $selectedWidgetId = isset($instance['ti-widget-ID']) ? esc_attr($instance['ti-widget-ID']) : $this->widget_fields['ti-widget-ID']['default']; |
| 67 | ?> |
| 68 | <div class="trustindex-widget-admin"> |
| 69 | <?php if ($pluginManagerInstance->is_trustindex_connected()): ?> |
| 70 | <?php if ($tiWidgets): ?> |
| 71 | <h2><?php echo esc_html(__('Your saved widgets', 'wp-reviews-plugin-for-google')); ?></h2> |
| 72 | <?php foreach ($tiWidgets as $wc): ?> |
| 73 | <p><strong><?php echo esc_html($wc['name']); ?>:</strong></p> |
| 74 | <p> |
| 75 | <?php foreach ($wc['widgets'] as $w): ?> |
| 76 | <a href="#" class="btn-copy-widget-id <?php if ($selectedWidgetId === $w['id']): ?>text-danger<?php endif; ?>" data-ti-id="<?php echo esc_attr($w['id']); ?>"> |
| 77 | <span class="dashicons <?php if ($selectedWidgetId === $w['id']): ?>dashicons-yes<?php else: ?>dashicons-admin-post<?php endif; ?>"></span> |
| 78 | <?php echo esc_html($w['name']); ?> |
| 79 | </a><br /> |
| 80 | <?php endforeach; ?> |
| 81 | </p> |
| 82 | <?php endforeach; ?> |
| 83 | <?php else: ?> |
| 84 | <?php echo wp_kses_post($pluginManager::get_alertbox('warning', |
| 85 | esc_html(__('You have no widget saved!', 'wp-reviews-plugin-for-google')) . ' ' |
| 86 | . "<a target='_blank' href='" . "https://admin.trustindex.io/" . "widget'>". esc_html(__("Let's go, create amazing widgets for free!", 'wp-reviews-plugin-for-google'))."</a>" |
| 87 | )); ?> |
| 88 | <?php endif; ?> |
| 89 | <?php foreach ($this->widget_fields as $fname => $fparams): ?> |
| 90 | <div class="form-group"> |
| 91 | <div class="col-sm-12"> |
| 92 | <label class="<?php if (isset($this->errors[ $fname ])):?>text-danger<?php endif; ?>"> |
| 93 | <?php echo esc_html($fparams['name']); ?> <?php if ($fparams['required']): ?><strong class="text-danger">*</strong><?php endif; ?> |
| 94 | <?php if ($fparams['help-icon']): ?> |
| 95 | <?php echo wp_kses_post($fparams['help-icon']); ?> |
| 96 | <?php endif; ?> |
| 97 | </label> |
| 98 | <input |
| 99 | type="text" |
| 100 | placeholder="<?php echo esc_attr($fparams['placeholder']); ?>" |
| 101 | id="<?php echo esc_attr($this->get_field_id($fname)); ?>" |
| 102 | name="<?php echo esc_attr($this->get_field_name($fname)); ?>" |
| 103 | value="<?php echo esc_attr(isset($instance[ $fname ]) ? $instance[ $fname ] : $fparams['default']); ?>" |
| 104 | class="form-control" |
| 105 | <?php if ($fparams['required']): ?>required="required"<?php endif; ?> |
| 106 | /> |
| 107 | <?php if ($fparams['help']): ?> |
| 108 | <small class="text-muted"><?php echo wp_kses_post($fparams['help']); ?></small> |
| 109 | <?php endif; ?> |
| 110 | </div> |
| 111 | </div> |
| 112 | <?php endforeach; ?> |
| 113 | <div class="help-block block-help-template"> |
| 114 | <span class="dashicons dashicons-dismiss"></span> |
| 115 | <p> |
| 116 | Check our portal, <a href="<?php echo esc_url('https://admin.trustindex.io/'); ?>widget" target="_blank">list your widgets</a> and find IDs in the first colums. |
| 117 | </p> |
| 118 | <img src="<?php echo esc_url($pluginManagerInstance->get_plugin_file_url('static/img/help-where-is-id.jpg')); ?>" alt="ID column here: <?php echo esc_url('https://admin.trustindex.io/'); ?>widget" /> |
| 119 | </div> |
| 120 | <?php else: ?> |
| 121 | <?php echo wp_kses_post($pluginManager::get_alertbox('warning', |
| 122 | esc_html(__('You have not set up your Trustindex account yet!', 'wp-reviews-plugin-for-google')) . ' ' . |
| 123 | esc_html(__('You can only list 10 reviews without it.', 'wp-reviews-plugin-for-google')) . '<br>' |
| 124 | /* translators: %s: URL */ |
| 125 | . wp_kses_post(sprintf(__("Go to <a href='%s'>plugin setup page</a> to complete the one-step setup guide and enjoy the full functionalization!", 'wp-reviews-plugin-for-google'), admin_url('admin.php?page='.$pluginManagerInstance->get_plugin_slug().'/settings.php&tab=setup_trustindex'))) |
| 126 | )); ?> |
| 127 | <?php endif; ?> |
| 128 | </div> |
| 129 | <?php |
| 130 | } |
| 131 | } |
| 132 | ?> |
| 133 |