class-admin.php
3 months ago
class-columns-modal.php
1 month ago
class-columns.php
2 weeks ago
class-counter.php
2 months ago
class-crawler-detect.php
7 months ago
class-cron.php
1 month ago
class-dashboard.php
1 month ago
class-emails-mailer.php
1 month ago
class-emails-period.php
1 month ago
class-emails-query.php
1 month ago
class-emails-scheduler.php
1 month ago
class-emails-template.php
1 month ago
class-emails.php
1 month ago
class-frontend.php
2 weeks ago
class-functions.php
1 year ago
class-import.php
2 months ago
class-integration-gutenberg.php
6 months ago
class-integrations.php
2 months ago
class-query.php
2 months ago
class-settings-api.php
1 month ago
class-settings-display.php
4 months ago
class-settings-emails.php
1 month ago
class-settings-general.php
1 month ago
class-settings-integrations.php
5 months ago
class-settings-other.php
1 month ago
class-settings-reports.php
1 month ago
class-settings.php
1 month ago
class-toolbar.php
3 months ago
class-traffic-signals.php
2 months ago
class-update.php
1 month ago
class-widgets.php
1 month ago
functions.php
1 month ago
class-settings-integrations.php
116 lines
| 1 | <?php |
| 2 | // exit if accessed directly |
| 3 | if ( ! defined( 'ABSPATH' ) ) |
| 4 | exit; |
| 5 | |
| 6 | /** |
| 7 | * Post_Views_Counter_Settings_Integrations class. |
| 8 | * |
| 9 | * @class Post_Views_Counter_Settings_Integrations |
| 10 | */ |
| 11 | class Post_Views_Counter_Settings_Integrations { |
| 12 | |
| 13 | /** |
| 14 | * Get sections. |
| 15 | * |
| 16 | * @return array |
| 17 | */ |
| 18 | public function get_sections() { |
| 19 | return [ |
| 20 | 'post_views_counter_integrations' => [ |
| 21 | 'tab' => 'integrations', |
| 22 | 'title' => __( 'Integrations', 'post-views-counter' ), |
| 23 | 'callback' => [ $this, 'section_integrations' ] |
| 24 | ] |
| 25 | ]; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Get fields. |
| 30 | * |
| 31 | * @return array |
| 32 | */ |
| 33 | public function get_fields() { |
| 34 | $fields = []; |
| 35 | $integrations = Post_Views_Counter_Integrations::get_integrations(); |
| 36 | |
| 37 | foreach ( $integrations as $slug => $integration ) { |
| 38 | $field = [ |
| 39 | 'tab' => 'integrations', |
| 40 | 'section' => 'post_views_counter_integrations', |
| 41 | 'id' => 'pvc-integration_' . $slug, |
| 42 | 'type' => 'custom', |
| 43 | 'title' => $integration['name'], |
| 44 | 'callback' => [ $this, 'integration_field' ], |
| 45 | 'skip_saving' => true, |
| 46 | 'slug' => $slug |
| 47 | ]; |
| 48 | |
| 49 | if ( isset( $integration['pro'] ) && $integration['pro'] && ! class_exists( 'Post_Views_Counter_Pro' ) ) { |
| 50 | $field['class'] = 'pvc-pro'; |
| 51 | } |
| 52 | |
| 53 | $fields[ $slug ] = $field; |
| 54 | } |
| 55 | |
| 56 | return $fields; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Section description: integrations. |
| 61 | * |
| 62 | * @return void |
| 63 | */ |
| 64 | public function section_integrations() { |
| 65 | echo '<p class="description">' . esc_html__( 'Manage available Post Views Counter integrations.', 'post-views-counter' ) . '</p>'; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Custom integration field. |
| 70 | * |
| 71 | * @param array $field |
| 72 | * @return string |
| 73 | */ |
| 74 | public function integration_field( $field ) { |
| 75 | $slug = $field['slug']; |
| 76 | $integrations = Post_Views_Counter_Integrations::get_integrations(); |
| 77 | $integration = $integrations[$slug]; |
| 78 | $pro_missing = ! empty( $integration['pro'] ) && empty( $integration['pro_active'] ); |
| 79 | |
| 80 | $checked = $integration['status'] ? 'checked' : ''; |
| 81 | $disabled = ! $integration['availability'] || $pro_missing ? 'disabled' : ''; |
| 82 | |
| 83 | $classes = [ 'pvc-integration-content' ]; |
| 84 | if ( ! $integration['availability'] ) |
| 85 | $classes[] = 'unavailable'; |
| 86 | |
| 87 | $label_classes = []; |
| 88 | if ( ! $integration['availability'] ) |
| 89 | $label_classes[] = 'pvc-disabled'; |
| 90 | |
| 91 | $html = '<div class="' . esc_attr( implode( ' ', $classes ) ) . '">'; |
| 92 | $html .= '<label' . ( ! empty( $label_classes ) ? ' class="' . esc_attr( implode( ' ', $label_classes ) ) . '"' : '' ) . '>'; |
| 93 | $html .= '<input type="checkbox" role="switch" name="post_views_counter_settings_integrations[integrations][' . esc_attr( $slug ) . ']" value="1" ' . $checked . ' ' . $disabled . ' />'; |
| 94 | |
| 95 | // add availability indicator |
| 96 | if ( $integration['availability'] && $pro_missing ) { |
| 97 | $html .= ' <span class="pvc-availability-status available">' . esc_html__( '(available)', 'post-views-counter' ) . '</span>'; |
| 98 | } |
| 99 | |
| 100 | $html .= ' ' . esc_html( $integration['description'] ); |
| 101 | $html .= '</label>'; |
| 102 | |
| 103 | if ( ! empty( $integration['items'] ) ) { |
| 104 | $html .= '<ul class="pvc-integration-items">'; |
| 105 | foreach ( $integration['items'] as $item ) { |
| 106 | $html .= '<li><strong>' . esc_html( $item['name'] ) . ':</strong> ' . esc_html( $item['description'] ) . '</li>'; |
| 107 | } |
| 108 | $html .= '</ul>'; |
| 109 | } |
| 110 | |
| 111 | $html .= '</div>'; |
| 112 | |
| 113 | return $html; |
| 114 | } |
| 115 | } |
| 116 |