Plugin Directory

Changeset 3325770


Ignore:
Timestamp:
07/10/2025 02:29:02 PM (9 months ago)
Author:
siteimprove
Message:

Version 2.0.8

Location:
siteimprove/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • siteimprove/trunk/admin/class-siteimprove-admin.php

    r3064701 r3325770  
    5050
    5151        $this->plugin_name = $plugin_name;
    52         $this->version     = $version;
     52        $this->version = $version;
    5353
    5454        $this->load_dependencies();
     
    9191        $prepublish_enabled = intval( get_option( 'siteimprove_prepublish_enabled', 0 ) );
    9292
    93         if ( ( $wp_query->is_preview() || $wp_query->is_singular() ) && 1 === $prepublish_allowed && 1 === $prepublish_enabled ) {
     93        if ( ( $wp_query->is_preview() || $wp_query->is_singular() || is_front_page() ) && 1 === $prepublish_allowed && 1 === $prepublish_enabled ) {
    9494            wp_enqueue_style( 'siteimprove_preview_css', plugin_dir_url( __FILE__ ) . 'css/siteimprove-preview.css', array(), $this->version, 'all' );
    9595        }
     
    107107     */
    108108    public function gutenberg_siteimprove_plugin() {
     109        global $post;
     110
     111        if ( $post && $post->ID ) {
     112            $permalink = get_permalink( $post->ID );
     113            if ( $permalink ) {
     114                $this->siteimprove_add_js( $permalink, 'siteimprove_input' );
     115
     116                if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
     117                    error_log( 'Siteimprove Debug: Gutenberg - Post ID: ' . $post->ID );
     118                    error_log( 'Siteimprove Debug: Gutenberg - Permalink: ' . $permalink );
     119                }
     120            }
     121        }
     122
    109123        wp_enqueue_script(
    110124            'gutenberg-siteimprove-plugin',
     
    114128            false
    115129        );
     130
     131        $post_id = $post ? $post->ID : 0;
     132        $url = $post_id ? get_permalink( $post_id ) : '';
     133
    116134        $si_js_args = array(
    117135            'token' => get_option( 'siteimprove_token' ),
    118136            'text' => __( 'Siteimprove Recheck', 'siteimprove' ),
    119             'url' => get_permalink( $post_id ),
     137            'url' => $url,
    120138        );
    121139        wp_localize_script(
     
    132150        global $pagenow;
    133151
     152        if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
     153            error_log( 'Siteimprove Debug: Current page: ' . $pagenow );
     154            error_log( 'Siteimprove Debug: GET params: ' . print_r( $_GET, true ) );
     155        }
     156
    134157        $urls = get_transient( 'siteimprove_url_' . get_current_user_id() );
    135158
    136159        if ( ! wp_doing_ajax() && ! empty( $urls ) ) {
    137160            if ( is_array( $urls ) && count( $urls ) > 1 ) {
    138                 $url    = esc_url( home_url() );
     161                $url = esc_url( home_url() );
    139162                $method = 'siteimprove_recrawl';
    140163            } else {
    141                 $url    = array_pop( $urls );
     164                $url = array_pop( $urls );
    142165                $method = 'siteimprove_recheck';
    143166            }
     
    148171        switch ( $pagenow ) {
    149172            case 'post.php':
    150                 $post_id   = wp_verify_nonce( $this->settings->request_siteimprove_nonce(), 'siteimprove_nonce' ) && ! empty( $_GET['post'] ) ? (int) $_GET['post'] : 0;
    151                 $permalink = get_permalink( $post_id );
    152 
    153                 if ( $permalink ) {
     173                $post_id = ! empty( $_GET['post'] ) ? (int) $_GET['post'] : 0;
     174                $permalink = $post_id ? get_permalink( $post_id ) : false;
     175
     176                if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
     177                    error_log( 'Siteimprove Debug: Post ID: ' . $post_id );
     178                    error_log( 'Siteimprove Debug: Permalink: ' . $permalink );
     179                    error_log( 'Siteimprove Debug: Token: ' . get_option( 'siteimprove_token', 'NOT_SET' ) );
     180                    error_log( 'Siteimprove Debug: User can edit posts: ' . ( current_user_can( 'edit_posts' ) ? 'yes' : 'no' ) );
     181                }
     182
     183                if ( $permalink && current_user_can( 'edit_posts' ) ) {
    154184                    $this->siteimprove_add_js( get_permalink( $post_id ), 'siteimprove_input' );
    155185                    // Only display recheck button in published posts.
     
    162192            case 'term.php':
    163193            case 'edit-tags.php':
    164                 $tag_id   = wp_verify_nonce( $this->settings->request_siteimprove_nonce(), 'siteimprove_nonce' ) && ! empty( $_GET['tag_ID'] ) ? (int) $_GET['tag_ID'] : 0;
    165                 $taxonomy = wp_verify_nonce( $this->settings->request_siteimprove_nonce(), 'siteimprove_nonce' ) && ! empty( $_GET['taxonomy'] ) ? sanitize_key( $_GET['taxonomy'] ) : '';
    166 
    167                 if ( 'term.php' === $pagenow || ( 'edit-tags.php' === $pagenow && wp_verify_nonce( $this->settings->request_siteimprove_nonce(), 'siteimprove_nonce' ) && ! empty( $_GET['action'] ) && 'edit' === $_GET['action'] ) ) {
    168                     $this->siteimprove_add_js( get_term_link( (int) $tag_id, $taxonomy ), 'siteimprove_input' );
    169                     $this->siteimprove_add_js( get_term_link( (int) $tag_id, $taxonomy ), 'siteimprove_recheck_button' );
     194                $tag_id = ! empty( $_GET['tag_ID'] ) ? (int) $_GET['tag_ID'] : 0;
     195                $taxonomy = ! empty( $_GET['taxonomy'] ) ? sanitize_key( $_GET['taxonomy'] ) : '';
     196
     197                if ( ( 'term.php' === $pagenow || ( 'edit-tags.php' === $pagenow && ! empty( $_GET['action'] ) && 'edit' === $_GET['action'] ) ) && current_user_can( 'manage_categories' ) ) {
     198                    $term_link = get_term_link( (int) $tag_id, $taxonomy );
     199                    if ( ! is_wp_error( $term_link ) ) {
     200                        $this->siteimprove_add_js( $term_link, 'siteimprove_input' );
     201                        $this->siteimprove_add_js( $term_link, 'siteimprove_recheck_button' );
     202                    }
    170203                }
    171204                break;
    172205
    173206            default:
    174                 $host    = isset( $_SERVER['HTTP_HOST'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : '';
     207                $host = isset( $_SERVER['HTTP_HOST'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : '';
    175208                $request = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
    176209                $this->siteimprove_add_js( $host . $request, 'siteimprove_domain' );
     
    208241        if ( isset( $_GET['si_preview_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['si_preview_nonce'] ) ), 'siteimprove_nonce' ) ) {
    209242            return;
    210         }
    211         else { 
     243        } else {
    212244            wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/siteimprove.js', array( 'jquery' ), $this->version, false );
     245
     246            /*
     247                                     Pass any server-side vars down to JS.  These will be exposed as
     248                                     php_vars.variablename for example
     249                             */
     250            $jsarray = array(
     251                'prepublish_allowed' => intval( get_option( 'siteimprove_prepublish_allowed', 0 ) ),
     252                'prepublish_enabled' => intval( get_option( 'siteimprove_prepublish_enabled', 0 ) ),
     253                'has_api_key' => intval( strlen( get_option( 'siteimprove_api_key', 0 ) ) > 0 ),
     254            );
     255            wp_localize_script( $this->plugin_name, 'php_vars', $jsarray );
    213256            wp_enqueue_script( 'siteimprove_overlay', $overlay_path, array(), $this->version, true );
    214257        }
     
    217260        if ( ! empty( $public_url ) ) {
    218261            $parsed_url = wp_parse_url( $url );
    219             $url        = "$public_url$parsed_url[path]" . ( isset( $parsed_url['query'] ) ? "?$parsed_url[query]" : '' );
    220         }
    221 
    222         $is_content_page = is_preview() || is_singular();
     262            $url = "$public_url$parsed_url[path]" . ( isset( $parsed_url['query'] ) ? "?$parsed_url[query]" : '' );
     263        }
     264
     265        $is_content_page = is_preview() || is_singular() || is_front_page();
    223266
    224267        $si_js_args = array(
    225268            'token' => get_option( 'siteimprove_token' ),
    226             'txt'   => __( 'Siteimprove Recheck', 'siteimprove' ),
    227             'url'   => $url,
     269            'txt' => __( 'Siteimprove Recheck', 'siteimprove' ),
     270            'url' => $url,
    228271            'version' => $disabled_new_version,
    229272            'is_content_page' => $is_content_page,
     
    242285            'siteimprove_plugin_text',
    243286            array(
    244                 'loading'                     => __( 'Loading... Please wait.', 'siteimprove' ),
     287                'loading' => __( 'Loading... Please wait.', 'siteimprove' ),
    245288                'prepublish_activate_running' => __( 'We are now activating prepublish for your website... Please keep the current page open while the process is running.', 'siteimprove' ),
    246                 'prepublish_feature_ready'    => __( 'Prepublish feature is already enabled for the current website. To use it please go to the preview of any page/post or content that you want to check and click the button <strong>Siteimprove Prepublish Check</strong> located on the top bar of the admin panel.', 'siteimprove' ),
     289                'prepublish_feature_ready' => __( 'Prepublish feature is already enabled for the current website. To use it please go to the preview of any page/post or content that you want to check and click the button <strong>Siteimprove Prepublish Check</strong> located on the top bar of the admin panel.', 'siteimprove' ),
    247290                'prepublish_activation_error' => __( 'Error activating prepublish. Please contact support team.', 'siteimprove' ),
    248291            )
     
    298341    public function siteimprove_save_session_url_post( $post_ID ) {
    299342        if ( ! wp_is_post_revision( $post_ID ) && ! wp_is_post_autosave( $post_ID ) ) {
    300             $urls   = get_transient( 'siteimprove_url_' . get_current_user_id() );
     343            $urls = get_transient( 'siteimprove_url_' . get_current_user_id() );
    301344            $urls[] = get_permalink( $post_ID );
    302345            set_transient( 'siteimprove_url_' . get_current_user_id(), $urls, 900 );
     
    313356     */
    314357    public function siteimprove_save_session_url_term( $term_id, $tt_id, $taxonomy ) {
    315         $urls   = get_transient( 'siteimprove_url_' . get_current_user_id() );
     358        $urls = get_transient( 'siteimprove_url_' . get_current_user_id() );
    316359        $urls[] = get_term_link( (int) $term_id, $taxonomy );
    317360        set_transient( 'siteimprove_url_' . get_current_user_id(), $urls, 900 );
     
    336379            )
    337380        ) {
    338             $urls   = get_transient( 'siteimprove_url_' . get_current_user_id() );
     381            $urls = get_transient( 'siteimprove_url_' . get_current_user_id() );
    339382            $urls[] = get_permalink( $post->ID );
    340383            set_transient( 'siteimprove_url_' . get_current_user_id(), $urls, 900 );
     
    347390    public function siteimprove_wp_head() {
    348391
    349         $user          = wp_get_current_user();
     392        $user = wp_get_current_user();
    350393        $allowed_roles = array(
    351394            'shop_manager',
     
    359402            $type = $this->get_current_page_type();
    360403            switch ( $type ) {
     404                case 'front':
     405                case 'home':
    361406                case 'page':
    362407                case 'single':
     
    368413
    369414                default:
    370                     $host    = isset( $_SERVER['HTTP_HOST'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : '';
     415                    $host = isset( $_SERVER['HTTP_HOST'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : '';
    371416                    $request = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
    372417                    $this->siteimprove_add_js( $host . $request, 'siteimprove_domain' );
     
    426471        $prepublish_allowed = intval( get_option( 'siteimprove_prepublish_allowed', 0 ) );
    427472        $prepublish_enabled = intval( get_option( 'siteimprove_prepublish_enabled', 0 ) );
    428 
    429         if ( ( is_preview() || is_singular() ) && 1 === $prepublish_allowed && 1 === $prepublish_enabled ) {
    430             $prepublish_button = 
    431             '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" height="28px" width="28px" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="28px" height="28px" viewBox="0 0 300 300" style="enable-background:new 0 0 300 300;" xml:space="preserve">
     473        $has_api_key = intval( strlen( get_option( 'siteimprove_api_key', 0 ) ) > 0 );
     474        if ( ( is_preview() || is_singular() || is_front_page() ) && 1 === $prepublish_allowed && 1 === $prepublish_enabled && 1 === $has_api_key ) {
     475            $prepublish_button =
     476                '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" height="28px" width="28px" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="28px" height="28px" viewBox="0 0 300 300" style="enable-background:new 0 0 300 300;" xml:space="preserve">
    432477                <circle fill="#0D4CD3" cx="150" cy="150" r="150"/>
    433478                <g>
     
    437482            $admin_bar->add_menu(
    438483                array(
    439                     'id'    => 'siteimprove-trigger-contentcheck',
     484                    'id' => 'siteimprove-trigger-contentcheck',
    440485                    'title' => $prepublish_button . __( 'Prepublish', 'siteimprove' ),
    441486                    'group' => null,
    442                     'href'  => '#',
    443                     'meta'  => array(
     487                    'href' => '#',
     488                    'meta' => array(
    444489                        'title' => __( 'Siteimprove Prepublish', 'siteimprove' ),
    445490                        'class' => 'siteimprove-trigger-contentcheck',
  • siteimprove/trunk/admin/css/siteimprove-preview.css

    r3064701 r3325770  
    99  padding-left: 30px;
    1010}
    11 @keyframes highlight-blink {
    12   50% {
    13     background-color: rgba(0, 0, 0, 0);
    14     border-color: rgba(0, 0, 0, 0);
    15   }
    16 }
    17 
    18 .si-highlight {
    19     background-color: rgba(221, 10, 27, 0.2);
    20     border: 2px solid #DD0A1B;
    21     animation-name: highlight-blink;
    22     animation-duration: 0.4s;
    23     animation-iteration-count: 4;
    24     animation-timing-function: ease;
    25 }
    26 
    27 body.si-full-highlight {
    28   position: relative;
    29 }
    30 
    31 /* For highlighting of the body, we don't want to wrap an element around the body itself,
    32 as that will cause a re-render of the page of our CMS Plugin, body has to be the first element as well
    33 So instead we add a class to body, and in it we got a pseudo element that is ontop of the body's children */
    34 body.si-full-highlight:before {
    35   content: "";
    36   height: 100%;
    37   width: 100%;
    38   position: absolute;
    39   z-index: 9999;
    40   background-color: rgba(221, 10, 27, 0.2);
    41   border: 2px solid #DD0A1B;
    42   animation-name: highlight-blink;
    43   animation-duration: 0.4s;
    44   animation-iteration-count: 4;
    45   animation-timing-function: ease;
    46 }
    47 
    48 .si-overlay {
    49   position:absolute;
    50   top:0;
    51   left:0;
    52   right:0;
    53   bottom:0;
    54   background-color:rgba(0, 0, 0, 0.55);
    55   background: url(data:;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAABl0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuNUmK/OAAAAATSURBVBhXY2RgYNgHxGAAYuwDAA78AjwwRoQYAAAAAElFTkSuQmCC) repeat scroll transparent\9; /* ie fallback png background image */
    56   z-index:100000;
    57   color:white;
    58 }
  • siteimprove/trunk/admin/js/siteimprove.js

    r3064701 r3325770  
    2323            adminBar.id = 'wpadminbar-disabled';
    2424          }
    25           const cleanDom = iframe.contentWindow.document.cloneNode(true);
     25          const cleanDom = iframe.contentWindow.document;
    2626          document.body.removeChild(iframeContainer);
    2727          resolve(cleanDom);
     
    103103
    104104      _si.push(['onHighlight', function(highlightInfo) {
    105           // Function to wrap a specific text node within an element with a new element
    106           function wrapTextNode(element, from, length, wrapTag) {
    107               $(element).contents().each(function() {
    108                   // 3 = text node
    109                   if (this.nodeType === 3 && this.nodeValue) {
    110                       if (from < this.nodeValue.length) {
    111                           var before = this.nodeValue.substr(0, from);
    112                           var middle = this.nodeValue.substr(from, length);
    113                           var after = this.nodeValue.substr(from + length);
    114                           $(this).before(before).before(wrapTag.clone().text(middle)).before(after).remove();
    115                           // Break out of the each loop
    116                           return false;
    117                       } else {
    118                           from -= this.nodeValue.length;
    119                       }
    120                   }
    121               });
    122           }
    123 
    124           function resetHighlights() {
    125             $(".si-highlight").each(function() {
    126               // This takes the element of the .si-highlight inner HTML and replaces the element with it
    127               $(this).replaceWith($(this).html());
    128             });
    129             // We handle body tag highlight specificially, so we also need to remove it specificially from HTML element
    130             if($("body").hasClass("si-full-highlight")) {
    131               $("body").removeClass("si-full-highlight");
    132             }
    133           }
    134          
    135           function applyHighlights() {
    136             var wrapTag = $("<span class='si-highlight'></span>");
    137             // Apply new highlights based on the information received
    138             $.each(highlightInfo.highlights, function(index, highlight) {
    139                 var $element = $(highlight.selector);
    140                 if (highlight.offset) {
    141                     wrapTextNode($element[0], highlight.offset.start, highlight.offset.length, wrapTag);
    142                 } else {
    143                     if ($element.is('body')) {
    144                       // Add the class to the HTML tag instead, so we can have full height of the highlight
    145                       $element.addClass("si-full-highlight");
    146                     }
    147                     else if ($element.is('img') || $element.children().is("img")) {
    148                       $element.wrap("<div class='si-highlight' style='padding: 5px;'></div>");
    149                     } else {
    150                       $element.wrapInner("<span class='si-highlight'></span>");
    151                     }
    152                 }
    153             });
    154           }
    155 
    156           resetHighlights();
    157           applyHighlights();
    158           // Scroll to the target element
    159           $([document.documentElement, document.body]).stop().animate({
    160               scrollTop: $(".si-highlight").offset().top - $("#wpadminbar").height()
    161           }, 1500);
     105        _si.push(["applyDefaultHighlighting", highlightInfo, document, window]);
    162106      }]);
    163107
     
    171115      // 1 = overlay-latest.js
    172116      if (this.version == 1 && this.is_content_page) {
    173         _si.push(['registerPrepublishCallback', getDomCallback, this.token]);
    174       }
    175 
     117        var { has_api_key, prepublish_allowed, prepublish_enabled } = php_vars;
     118        var cb =
     119          Boolean(+has_api_key) &&
     120          Boolean(+prepublish_allowed) &&
     121          Boolean(+prepublish_enabled)
     122            ? getDomCallback
     123            : null
     124        _si.push(['registerPrepublishCallback', cb, this.token]);
     125      }
    176126
    177127      _si.push([this.method, this.url, this.token]);
  • siteimprove/trunk/admin/partials/class-siteimprove-admin-settings.php

    r3064701 r3325770  
    3939     */
    4040    public function register_section() {
     41        $this->siteimprove_nonce = wp_create_nonce( 'siteimprove-options' );
    4142        // Register settings for siteimprove plugin settings page.
    4243        register_setting( 'siteimprove', 'siteimprove_token' );
     
    108109
    109110        // Register a new section in the siteimprove page.
    110         if ( isset( $_GET['devmode'] ) && wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'siteimprove-options' ) ) {
     111        if ( isset( $_GET['devmode'] ) ) {
    111112            add_settings_section(
    112113                'siteimprove_dev_mode_section',
     
    151152            'siteimprove'
    152153        );
    153 
    154         $this->siteimprove_nonce = wp_create_nonce( 'siteimprove_nonce' );
    155154    }
    156155
     
    179178        if ( 'siteimprove_prepublish' === $args['id'] ) {
    180179            $siteimprove_api_key = get_option( 'siteimprove_api_key', '' );
    181             $prepublish_allowed  = intval( get_option( 'siteimprove_prepublish_allowed', 0 ) );
    182             $prepublish_enabled  = intval( get_option( 'siteimprove_prepublish_enabled', 0 ) );
     180            $prepublish_allowed = intval( get_option( 'siteimprove_prepublish_allowed', 0 ) );
     181            $prepublish_enabled = intval( get_option( 'siteimprove_prepublish_enabled', 0 ) );
    183182            if ( ! empty( $siteimprove_api_key ) ) {
    184183                if ( 1 === $prepublish_allowed ) {
    185184                    ?>
    186                     <p>You can use Prepublish on your account.</p>
    187                     <?php
    188                     if ( 0 === $prepublish_enabled ) :
    189                         ?>
    190                             <p class="siteimprove_prepublish_activation_messages">
    191                         <?php
    192                         echo wp_kses(
    193                             __( 'To enable prepublish for this website click <a href="#" id="siteimprove_enable_prepublish" class="button button-primary">here</a>', 'siteimprove' ),
    194                             array(
    195                                 'a' => array(
    196                                     'href' => array(),
    197                                     'id'    => array(),
    198                                     'class' => array(),
    199                                 ),
    200                             )
    201                         );
    202                         ?>
    203                             </p>
    204                             <?php
    205                         else :
    206                             ?>
    207                         <p>
    208                             <?php
    209                             echo wp_kses(
    210                                 __( 'Prepublish feature is already enabled for the current website. To use it please go to the preview of any page/post or content that you want to check and click the button <strong>Siteimprove Prepublish Check</strong> located on the top bar of the admin panel', 'siteimprove' ),
    211                                 array(
    212                                     'strong' => array(),
    213                                 )
    214                             );
    215                             ?>
    216                         </p>
    217                             <?php
    218                         endif;
     185                                                            <p>You can use Prepublish on your account.</p>
     186                                                            <?php
     187                                                            if ( 0 === $prepublish_enabled ) :
     188                                                                ?>
     189                                                                            <p class="siteimprove_prepublish_activation_messages">
     190                                                                        <?php
     191                                                                        echo wp_kses(
     192                                                                            __( 'To enable prepublish for this website click <a href="#" id="siteimprove_enable_prepublish" class="button button-primary">here</a>', 'siteimprove' ),
     193                                                                            array(
     194                                                                                'a' => array(
     195                                                                                    'href' => array(),
     196                                                                                    'id' => array(),
     197                                                                                    'class' => array(),
     198                                                                                ),
     199                                                                            )
     200                                                                        );
     201                                                                        ?>
     202                                                                            </p>
     203                                                                            <?php
     204                                                            else :
     205                                                                ?>
     206                                                                        <p>
     207                                                                            <?php
     208                                                                            echo wp_kses(
     209                                                                                __( 'Prepublish feature is already enabled for the current website. To use it please go to the preview of any page/post or content that you want to check and click the button <strong>Siteimprove Prepublish Check</strong> located on the top bar of the admin panel', 'siteimprove' ),
     210                                                                                array(
     211                                                                                    'strong' => array(),
     212                                                                                )
     213                                                                            );
     214                                                                            ?>
     215                                                                        </p>
     216                                                                            <?php
     217                                                            endif;
    219218                } else {
    220219                    ?>
    221                     <p>
    222                     <?php
    223                     esc_html_e( 'You can\'t use Prepublish on your account. Please contact sales team to enable this feature for the current website', 'siteimprove' );
    224                     ?>
    225                     </p>
    226                     <?php
     220                                                            <p>
     221                                                            <?php
     222                                                            esc_html_e( 'You can\'t use Prepublish on your account. Please contact sales team to enable this feature for the current website', 'siteimprove' );
     223                                                            ?>
     224                                                            </p>
     225                                                            <?php
    227226                }
    228227            } else {
    229228                ?>
    230                 <p>
    231                 <?php
    232                 esc_html_e( 'Please provide a valid API Username and API Key before using this feature.', 'siteimprove' );
    233                 ?>
    234                 </p>
    235                 <?php
     229                                                <p>
     230                                                <?php
     231                                                esc_html_e( 'Please provide a valid API Username and API Key before using this feature.', 'siteimprove' );
     232                                                ?>
     233                                                </p>
     234                                                <?php
    236235            }
    237236        }
     
    239238        if ( 'siteimprove_public_url' === $args['id'] ) {
    240239            ?>
    241             <p>
    242             <?php
    243                     esc_html_e( 'Please provide the Public URL for the current site if for any reasons it\'s not the same as the Admin Panel URL. Otherwise you can leave this field empty.' );
    244             ?>
    245             </p>
    246             <p>
    247             <?php
    248                     esc_html_e( 'Example: Website Admin Panel is hosted at: http://stg-thewebsite.com but the final Public URL will be http://thewebsite.com', 'siteimprove' );
    249             ?>
    250             </p>
    251             <?php
     240                                    <p>
     241                                    <?php
     242                                    esc_html_e( 'Please provide the Public URL for the current site if for any reasons it\'s not the same as the Admin Panel URL. Otherwise you can leave this field empty.' );
     243                                    ?>
     244                                    </p>
     245                                    <p>
     246                                    <?php
     247                                    esc_html_e( 'Example: Website Admin Panel is hosted at: http://stg-thewebsite.com but the final Public URL will be http://thewebsite.com', 'siteimprove' );
     248                                    ?>
     249                                    </p>
     250                                    <?php
    252251        }
    253252
    254253        if ( 'siteimprove_version_section' === $args['id'] ) {
    255254            ?>
    256             <p>
    257             <?php
    258                     esc_html_e( 'A new version of the plugin is now available. Please note it is a work in progress and may update over time.' );
    259             ?>
    260             </p>
    261             <?php
     255                                    <p>
     256                                    <?php
     257                                    esc_html_e( 'A new version of the plugin is now available. Please note it is a work in progress and may update over time.' );
     258                                    ?>
     259                                    </p>
     260                                    <?php
    262261        }
    263262    }
     
    278277        }
    279278        ?>
    280         <input type="checkbox" id="siteimprove_disable_new_version_field" name="siteimprove_disable_new_version"  value='1' <?php echo esc_attr( $is_checked ); ?> />
    281         <?php
     279                        <input type="checkbox" id="siteimprove_disable_new_version_field" name="siteimprove_disable_new_version"  value='1' <?php echo esc_attr( $is_checked ); ?> />
     280                        <?php
    282281    }
    283282
     
    291290        ?>
    292291
    293         <input type="text" id="siteimprove_token_field" name="siteimprove_token" value="<?php echo esc_attr( get_option( 'siteimprove_token' ) ); ?>" maxlength="50" size="50" />
    294         <input class="button" id="siteimprove_token_request" type="button" value="<?php echo esc_attr( __( 'Request new token', 'siteimprove' ) ); ?>" />
    295         <?php
     292                        <input type="text" id="siteimprove_token_field" name="siteimprove_token" value="<?php echo esc_attr( get_option( 'siteimprove_token' ) ); ?>" maxlength="50" size="50" />
     293                        <input class="button" id="siteimprove_token_request" type="button" value="<?php echo esc_attr( __( 'Request new token', 'siteimprove' ) ); ?>" />
     294                        <?php
    296295    }
    297296
     
    304303    public static function siteimprove_public_url_field( $args ) {
    305304        ?>
    306         <input type="text" id="siteimprove_public_url_field" name="siteimprove_public_url" value="<?php echo esc_attr( get_option( 'siteimprove_public_url' ) ); ?>"  size="50" />
    307         <?php
     305                        <input type="text" id="siteimprove_public_url_field" name="siteimprove_public_url" value="<?php echo esc_attr( get_option( 'siteimprove_public_url' ) ); ?>"  size="50" />
     306                        <?php
    308307    }
    309308
     
    317316        ?>
    318317
    319         <input type="text" id="siteimprove_api_username_field" name="siteimprove_api_username" value="<?php echo esc_attr( get_option( 'siteimprove_api_username' ) ); ?>" maxlength="50" size="50" />
    320         <?php
     318                        <input type="text" id="siteimprove_api_username_field" name="siteimprove_api_username" value="<?php echo esc_attr( get_option( 'siteimprove_api_username' ) ); ?>" maxlength="50" size="50" />
     319                        <?php
    321320    }
    322321
     
    330329        ?>
    331330
    332         <input type="text" id="siteimprove_api_key_field" name="siteimprove_api_key" value="<?php echo esc_attr( get_option( 'siteimprove_api_key' ) ); ?>" maxlength="50" size="50" />
    333         <?php
     331                        <input type="text" id="siteimprove_api_key_field" name="siteimprove_api_key" value="<?php echo esc_attr( get_option( 'siteimprove_api_key' ) ); ?>" maxlength="50" size="50" />
     332                        <?php
    334333    }
    335334
     
    343342        ?>
    344343
    345         <input type="text" id="siteimprove_overlayjs_file_field" name="siteimprove_overlayjs_file" value="<?php echo esc_attr( get_option( 'siteimprove_overlayjs_file' ) ); ?>"  size="50" />
    346         <?php
     344                        <input type="text" id="siteimprove_overlayjs_file_field" name="siteimprove_overlayjs_file" value="<?php echo esc_attr( get_option( 'siteimprove_overlayjs_file' ) ); ?>"  size="50" />
     345                        <?php
    347346    }
    348347
     
    358357        settings_errors( 'siteimprove_messages' );
    359358        ?>
    360         <div class="wrap">
    361             <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
    362             <form action="options.php" method="post">
    363             <?php
    364             // Display settings fields.
    365             settings_fields( 'siteimprove' );
    366             do_settings_sections( 'siteimprove' );
    367             // Submit button.
    368             submit_button( __( 'Save Settings', 'siteimprove' ) );
    369             ?>
    370             </form>
    371         </div>
    372             <?php
     359                        <div class="wrap">
     360                            <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
     361                            <form action="options.php" method="post">
     362                            <?php
     363                            // Display settings fields.
     364                            settings_fields( 'siteimprove' );
     365                            do_settings_sections( 'siteimprove' );
     366                            // Submit button.
     367                            submit_button( __( 'Save Settings', 'siteimprove' ) );
     368                            ?>
     369                            </form>
     370                        </div>
     371                            <?php
    373372    }
    374373
     
    412411                isset( $_POST['siteimprove_api_username'], $_POST['siteimprove_api_key'], $_REQUEST['_wpnonce'] )
    413412                && wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'siteimprove-options' )
    414                 ) {
    415                     $username = sanitize_text_field( wp_unslash( $_POST['siteimprove_api_username'] ) );
    416                     $key      = sanitize_text_field( wp_unslash( $_POST['siteimprove_api_key'] ) );
    417                     $result  = self::check_credentials( $username, $key );
     413            ) {
     414                $username = sanitize_text_field( wp_unslash( $_POST['siteimprove_api_username'] ) );
     415                $key = sanitize_text_field( wp_unslash( $_POST['siteimprove_api_key'] ) );
     416                $result = self::check_credentials( $username, $key );
    418417                if ( 'false' === $result['status'] ) {
    419418                    // return previous username when error is returned from checking both fields.
     
    433432    public static function validate_siteimprove_overlayjs_file( $value ) {
    434433        if ( ! empty( $value ) ) {
    435             $old_value        = get_option( 'siteimprove_overlayjs_file' );
     434            $old_value = get_option( 'siteimprove_overlayjs_file' );
    436435            if ( ! preg_match( '/.+\..{2,}/', $value ) ) {
    437436                add_settings_error( 'siteimprove_messages', 'siteimprove_api_key_error', __( 'Overlay file not saved - Invalid format (please verify if name and extention are correct).', 'siteimprove' ) );
     
    443442                    isset( $_POST['siteimprove_overlayjs_file'], $_REQUEST['_wpnonce'] )
    444443                    && wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'siteimprove-options' )
    445                     ) {
    446                         return $value;
     444                ) {
     445                    return $value;
    447446                }
    448447            }
     
    469468            } else {
    470469                /*
    471                 Now if API username and key are set, it's time to test both
    472                 against the API endpoint to check if it's a valid user/key set
    473                 and also if the keys correspond to the current website
    474                 */
     470                                Now if API username and key are set, it's time to test both
     471                                against the API endpoint to check if it's a valid user/key set
     472                                and also if the keys correspond to the current website
     473                                */
    475474                if (
    476                 isset( $_POST['siteimprove_api_username'], $_POST['siteimprove_api_key'], $_REQUEST['_wpnonce'] )
    477                 && wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'siteimprove-options' )
     475                    isset( $_POST['siteimprove_api_username'], $_POST['siteimprove_api_key'], $_REQUEST['_wpnonce'] )
     476                    && wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'siteimprove-options' )
    478477                ) {
    479478                    $username = sanitize_text_field( wp_unslash( $_POST['siteimprove_api_username'] ) );
    480                     $key      = sanitize_text_field( wp_unslash( $_POST['siteimprove_api_key'] ) );
    481                     $result   = self::check_credentials( $username, $key );
     479                    $key = sanitize_text_field( wp_unslash( $_POST['siteimprove_api_key'] ) );
     480                    $result = self::check_credentials( $username, $key );
    482481                    if ( 'false' === $result['status'] ) {
    483482                        add_settings_error( 'siteimprove_messages', 'siteimprove_api_credentials_error', $result['error'] );
     
    529528        $params = array(
    530529            'httpversion' => '1.1',
    531             'blocking'    => true,
    532             'headers'     => array(
     530            'blocking' => true,
     531            'headers' => array(
    533532                'Authorization' => 'Basic ' . base64_encode( $username . ':' . $key ),
    534                 'sslverify'     => false,
     533                'sslverify' => false,
    535534            ),
    536535        );
     
    562561        $return = array(
    563562            'status' => 'false',
    564             'error'  => __( 'Unable to check API Credentials, please try again', 'siteimprove' ),
     563            'error' => __( 'Unable to check API Credentials, please try again', 'siteimprove' ),
    565564        );
    566565
     
    576575
    577576        if ( isset( $request['response'] ) && 200 === $request['response']['code'] ) {
    578             $results       = json_decode( $request['body'] );
     577            $results = json_decode( $request['body'] );
    579578            $account_sites = $results->items;
    580579
     
    587586            }
    588587
    589             $domain     = wp_parse_url( $site_url, PHP_URL_HOST );
     588            $domain = wp_parse_url( $site_url, PHP_URL_HOST );
    590589            $site_found = false;
    591590
     
    627626        } else {
    628627            /*
    629             TODO: Figure out how to find if the feature is allowed but not enabled yet. For now we
    630             are considering that if there are no errors, then we can keep going and suppose it's
    631             then possibly allowed to be enabled by the user whenever he wishes to do so.
    632             */
     628                        TODO: Figure out how to find if the feature is allowed but not enabled yet. For now we
     629                        are considering that if there are no errors, then we can keep going and suppose it's
     630                        then possibly allowed to be enabled by the user whenever he wishes to do so.
     631                        */
    633632            update_option( 'siteimprove_prepublish_allowed', 1 );
    634633
    635634            /*
    636             Now we'll try to see if the prepublish feature is already enabled.
    637             If not, then we can show the user a button so he can enable it himself.
    638             */
     635                        Now we'll try to see if the prepublish feature is already enabled.
     636                        If not, then we can show the user a button so he can enable it himself.
     637                        */
    639638            $results = json_decode( $request['body'] );
    640639            if ( isset( $results->is_ready ) && true === $results->is_ready ) {
     
    653652    public function prepublish_manual_activation() {
    654653        $siteimprove_api_username = get_option( 'siteimprove_api_username', '' );
    655         $siteimprove_api_key      = get_option( 'siteimprove_api_key', '' );
     654        $siteimprove_api_key = get_option( 'siteimprove_api_key', '' );
    656655
    657656        $return = array(
    658657            'message' => 'activation_triggered',
    659             'result'  => true,
     658            'result' => true,
    660659        );
    661660
     
    678677    public function check_prepublish_activation() {
    679678        $siteimprove_api_username = get_option( 'siteimprove_api_username', '' );
    680         $siteimprove_api_key      = get_option( 'siteimprove_api_key', '' );
     679        $siteimprove_api_key = get_option( 'siteimprove_api_key', '' );
    681680
    682681        $return = array(
    683682            'message' => 'enabled',
    684             'result'  => false,
     683            'result' => false,
    685684        );
    686685
     
    703702            return;
    704703        }
    705    
     704
    706705        // Check if the nonce is set and is valid.
    707706        if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'siteimprove-options' ) ) {
     
    711710            wp_die();
    712711        }
    713    
     712
    714713        wp_die();
    715714    }
  • siteimprove/trunk/includes/class-siteimprove.php

    r3064701 r3325770  
    6161
    6262        $this->plugin_name = 'siteimprove';
    63         $this->version     = '2.0.7';
     63        $this->version     = '2.0.8';
    6464
    6565        $this->load_dependencies();
  • siteimprove/trunk/readme.txt

    r3064701 r3325770  
    33Tags: accessibility, analytics, insights, spelling, seo
    44Requires at least: 4.7.2
    5 Tested up to: 6.4.3
    6 Stable tag: 2.0.7
     5Tested up to: 6.7.1
     6Stable tag: 2.0.8
    77License: GPLv2 or later
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    8686
    8787== Changelog ==
     88= 2.0.8 =
     89* Updated - "Tested up to"
     90* Bugfix - Fixed overlay live view not showing on home page
     91* Bugfix - Fixed overlay not showing in editor pages
     92
    8893= 2.0.7 =
    8994* Change - Changed name of the plugin from "Siteimprove Plugin" to "Siteimprove"
  • siteimprove/trunk/siteimprove.php

    r3064701 r3325770  
    1010 * Plugin URI:          https://www.siteimprove.com/integrations/cms-plugin/wordpress/
    1111 * Description:         Integration with Siteimprove.
    12  * Version:             2.0.7
     12 * Version:             2.0.8
    1313 * Author:              Siteimprove
    1414 * Author URI:          http://www.siteimprove.com/
Note: See TracChangeset for help on using the changeset viewer.