Plugin Directory

Changeset 2881771


Ignore:
Timestamp:
03/17/2023 08:05:32 AM (3 years ago)
Author:
ryviu
Message:

Check connect store with Ryviu

Location:
ryviu/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • ryviu/trunk/assets/css/ryviu-admin.css

    r2764966 r2881771  
    338338.settings_page_ryviu-setting-admin #wpbody-content h2{
    339339    font-size: 25px;
    340     color: #2d89c2;
    341340}
    342341.settings_page_ryviu-setting-admin.wp-core-ui .button-primary{
     
    349348    border-radius: 6px;
    350349    border: 1px solid #dedede;
    351     height: 40px;
    352     line-height: 38px;
     350    height: 38px;
     351    line-height: 36px;
    353352    padding:0 25px 0 15px;
    354353}
     
    358357}
    359358.settings_page_ryviu-setting-admin input{
    360     height: 40px;
    361     line-height: 40px;
     359    height: 38px;
     360    line-height: 38px;
    362361    border-color: #d9d9d9;
    363362    color: #333;
     
    366365.settings_page_ryviu-setting-admin .form-table td p{
    367366    font-style: italic;
    368     opacity: 0.8;
     367    font-size: 13px;
    369368}
    370369.settings_page_ryviu-setting-admin .wrap form{
     
    382381.r--notices{
    383382    position: relative;
    384     padding-left: 40px!important;
     383    height: 40px;
     384    margin: 10px 0;
     385    padding-left: 60px!important;
     386    display: flex;
     387    align-items: center;
     388}
     389.r-cl-connect .notice-dismiss{
     390    top: 50%;
     391    transform: translateY(-50%);
    385392}
    386393.r--notices img{
    387    height: 30px;
     394   height: 40px;
    388395   position: absolute;
    389396   left: 0;
    390    top: -4px;
     397   top: 50%;
     398   transform: translateY(-50%);
    391399   vertical-align: middle;
     400}
     401.r--notices p{
     402    font-size: 14px;
     403    color: #000;
    392404}
    393405.notice-success.r-cl-connect{
     
    397409    display: block!important;
    398410}
     411.ryviu-page--image{
     412    width: 130px;
     413    margin-right:20px;
     414}
     415.r-des{
     416    font-size: 14px;
     417}
     418.ryviu-page--header{
     419    padding: 30px 0 30px;
     420    display: flex;
     421    align-items: center;
     422    border-bottom: 1px solid #d5d5d5;
     423    max-width: 860px;
     424}
     425.ryviu-page--intro{
     426    font-size: 14px;
     427    padding-right: 10px;
     428}
     429.ryviu-page--title{
     430    margin-top: 5px;
     431}
     432.ryviu-page--btn{
     433    border: solid 1px #549ecb;
     434    color: #fff;
     435    font-weight: 500;
     436    padding: 8px 20px;
     437    border-radius: 5px;
     438    display: inline-block;
     439    background: #549ecb;
     440    text-decoration: none;
     441    margin-right: 8px;
     442    margin-bottom: 10px;
     443}
     444.ryviu-page--btn:hover,
     445.ryviu-page--btn:active,
     446.ryviu-page--btn:focus{
     447    background: #187ebd;
     448    border-color: #187ebd;
     449    color: #fff;
     450}
     451.ryviu-page--btnnd{
     452    border: solid 1px #dedede;
     453    background: #fff;
     454    color: #413434;
     455}
     456.ryviu-page--btnnd:hover,
     457.ryviu-page--btnnd:active,
     458.ryviu-page--btnnd:focus{
     459    background: #F7F7F7;
     460    border-color: #D6D6D6;
     461    color: #413434;
     462}
     463.r-rate--us{
     464    color: #fdbe11;
     465    border-color: #fdbe11;
     466}
     467@media only screen and (max-width: 600px) {
     468    .ryviu-page--header {
     469      display: none;
     470    }
     471}
  • ryviu/trunk/assets/js/local-ryviu.js

    r2764966 r2881771  
    88        //Nothing to do
    99        let element_trigger_click = '.ryviu_reviews_tab_tab > a';
     10
    1011        if(ryviu_app.element_trigger_click && ryviu_app.element_trigger_click != ''){
    1112            element_trigger_click = ryviu_app.element_trigger_click;
    1213        }
     14       
    1315        if (ryviu_app.active_reviews_tab == 1) {
    1416            $(element_trigger_click).trigger('click');
    1517        }
    1618       
    17         if (ryviu_app.position_display == 1) {
     19        if (ryviu_app.position_display == 1 || element_trigger_click != '.ryviu_reviews_tab_tab > a') {
    1820            $(document).on('click','.product-widget__ryviu',function(){
    1921                $(element_trigger_click).trigger('click');
  • ryviu/trunk/includes/class-ryviu.php

    r2764966 r2881771  
    7575     */
    7676    public function query_vars( $vars ){
    77         array_push( $vars, 'ryviu' );
    78         array_push( $vars, 'type' );
    79         array_push( $vars, 'handle' );
    80         array_push( $vars, 'endpoint' );
    81         return $vars;
     77        $new_vars = ['ryviu', 'type', 'handle', 'endpoint'];
     78        return array_merge($vars, $new_vars);
    8279    }
    8380
     
    172169        // Add js to check Ryviu connect
    173170
    174         wp_enqueue_script( 'ryviu_check_connect', RYVIU_URL_ASSETS.'js/check-ryviu.js' );
     171        wp_enqueue_script( 'ryviu_check_connect', RYVIU_URL_ASSETS.'js/check-ryviu.js?version=3' );
    175172
    176173        if ( 'settings_page_ryviu-setting-admin' == $hook ) {
  • ryviu/trunk/includes/functions.php

    r2872853 r2881771  
    3030    }
    3131}
     32
     33// Check connect Ryviu
     34$check_settings = get_option( 'ryviu_client_settings' );
     35$check_ryviu_connect = $check_settings && $check_settings != new \stdClass() ? true : false;
     36
     37// Remove default reviews
     38$check_reviews_woo_active = get_option( 'woocommerce_enable_reviews' );
     39
     40if(isset($check_reviews_woo_active) && $check_reviews_woo_active == 'yes' && $check_ryviu_connect){
     41    function iconic_disable_reviews() {
     42        remove_post_type_support( 'product', 'comments' );
     43    }
     44   
     45    add_action( 'init', 'iconic_disable_reviews' );
     46   
     47    function remove_reviews_tab($tabs) {
     48        unset($tabs['reviews']);
     49        return $tabs;
     50    }
     51
     52    add_filter( 'woocommerce_product_tabs', 'remove_reviews_tab', 98 );
     53
     54    remove_action ('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
     55}
     56
     57       
     58// End remove default reviews
    3259
    3360/**
     
    110137
    111138
    112 if($position_display){
    113     switch($position_display){
    114         case 1: {
    115                 $priority = 65;
    116                 if(null !== RyviuSettings::get_option('position_display')){
    117                     $priority = RyviuSettings::get_option('priority_position_display');
     139
     140// Check if
     141if($check_ryviu_connect){
     142
     143    if($position_display){
     144        switch($position_display){
     145            case 1: {
     146                    $priority = 65;
     147                    if(null !== RyviuSettings::get_option('position_display')){
     148                        $priority = RyviuSettings::get_option('priority_position_display');
     149                    }
     150                   
     151                    add_filter( 'woocommerce_product_tabs', 'woo_ryviu_review_product_tab', $priority );
    118152                }
    119                 add_filter( 'woocommerce_product_tabs', 'woo_ryviu_review_product_tab', $priority );
    120             }
    121             break;
    122 
    123         case 11:
    124         case 4: {
    125                 $config_hook = ryviu_display_position_hook();
    126                 $config = $config_hook[$position_display];
    127                 $priority = 10;
    128                 if(null !== RyviuSettings::get_option('position_display')){
    129                     $priority = RyviuSettings::get_option('priority_position_display');
     153                break;
     154
     155            case 11:
     156            case 4: {
     157                    $config_hook = ryviu_display_position_hook();
     158                    $config = $config_hook[$position_display];
     159                    $priority = 10;
     160                    if(null !== RyviuSettings::get_option('position_display')){
     161                        $priority = RyviuSettings::get_option('priority_position_display');
     162                    }
     163                    add_action( $config['hook_name'], 'ryviu_product_display_review', $config['priority'] );
    130164                }
    131                 add_action( $config['hook_name'], 'ryviu_product_display_review', $config['priority'] );
    132             }
    133             break;
    134 
    135         case 10: {
    136                 $priority = 20;
    137                 if(null !== RyviuSettings::get_option('position_display')){
    138                     $priority = RyviuSettings::get_option('priority_position_display');
     165                break;
     166
     167            case 10: {
     168                    $priority = 20;
     169                    if(null !== RyviuSettings::get_option('position_display')){
     170                        $priority = RyviuSettings::get_option('priority_position_display');
     171                    }
     172                    add_action('ryviu_display_review', 'ryviu_product_display_review', 20 );
    139173                }
    140                 add_action('ryviu_display_review', 'ryviu_product_display_review', 20 );
    141             }
    142             break;
    143     }
    144 }
    145 
    146 if($position_display_widget){
    147     switch($position_display_widget){
    148         case 2:
    149         case 3: {
    150                 $config_hook = ryviu_display_position_hook();
    151                 $config = $config_hook[$position_display_widget];
    152                 add_action( $config['hook_name'], 'ryviu_widget_rating_total', $config['priority'] );
    153             }
    154             break;
    155 
    156         case 10: {
    157                 add_action('ryviu_display_total_review', 'ryviu_widget_rating_total', 20 );
    158             }
    159             break;
    160     }
    161 }
    162 
    163 
    164 if($position_display_widget_in_loop){
    165     switch($position_display_widget_in_loop){
    166         case 5:
    167         case 6: {
    168                 $config_hook = ryviu_display_position_hook();
    169                 $config = $config_hook[$position_display_widget_in_loop];
    170                 add_action( $config['hook_name'], 'ryviu_widget_rating_total_in_product_category', $config['priority'] );
    171             }
    172             break;
    173 
    174         case 10: {
    175                 add_action('ryviu_display_review_total_in_loop', 'ryviu_widget_rating_total_in_product_category', 20 );
    176             }
    177             break;
    178     }
    179 }
    180 
     174                break;
     175        }
     176    }
     177
     178    if($position_display_widget){
     179        switch($position_display_widget){
     180            case 2:
     181            case 3: {
     182                    $config_hook = ryviu_display_position_hook();
     183                    $config = $config_hook[$position_display_widget];
     184                    add_action( $config['hook_name'], 'ryviu_widget_rating_total', $config['priority'] );
     185                }
     186                break;
     187
     188            case 10: {
     189                    add_action('ryviu_display_total_review', 'ryviu_widget_rating_total', 20 );
     190                }
     191                break;
     192        }
     193    }
     194
     195
     196    if($position_display_widget_in_loop){
     197        switch($position_display_widget_in_loop){
     198            case 5:
     199            case 6: {
     200                    $config_hook = ryviu_display_position_hook();
     201                    $config = $config_hook[$position_display_widget_in_loop];
     202                    add_action( $config['hook_name'], 'ryviu_widget_rating_total_in_product_category', $config['priority'] );
     203                }
     204                break;
     205
     206            case 10: {
     207                    add_action('ryviu_display_review_total_in_loop', 'ryviu_widget_rating_total_in_product_category', 20 );
     208                }
     209                break;
     210        }
     211    }
     212}
    181213
    182214/**
     
    409441function woo_ryviu_review_product_tab( $tabs ) {
    410442    global $product;
     443   
    411444    if(!$product){
    412445        $product_id = ryviu_get_page_id();
     
    418451        $custom_title = isset($custom_title)? $custom_title: 'Reviews (%total_number%)';
    419452        if ($custom_title == '') {
    420             $custom_title = 'Reviews (%total_number%)';
     453            $custom_title = 'Reviews (%total_number%)';
    421454        }
    422455
     
    439472        }
    440473
    441         $tabs['ryviu_reviews_tab'] = array(
    442             'title'     => __( $custom_title, 'woocommerce' ),
    443             'priority'  => 50,
    444             'callback'  => 'ryviu_product_display_review'
    445         );
    446 
    447         unset($tabs['reviews']);
    448 
    449         return $tabs;
     474        $tabs['ryviu_reviews_tab'] = array(
     475            'title'     => __( $custom_title, 'woocommerce' ),
     476            'priority'  => 50,
     477            'callback'  => 'ryviu_product_display_review'
     478        );
     479
     480        unset($tabs['reviews']);
     481
     482        return $tabs;
    450483    }
    451484}
  • ryviu/trunk/includes/main-class.php

    r2872856 r2881771  
    88
    99    public static function check_connect_ryviu($check = false) {
     10        $mes = 'Connection failed, please contact Ryviu support for help.';
    1011        delete_option( 'ryviu_client_settings' );
    1112        $settings = get_option( 'ryviu_client_settings' );
     
    3435                    }
    3536                }
     37                $mes = 'Your store has not been linked to Ryviu, or the connected WordPress address is incorrect. Please login your Ryviu account and check in the settings page.';
    3638            }catch(Exception $e){
    3739                //handle exception
     
    4143            wp_send_json([
    4244                'status' => 'error',
    43                 'mes' => 'Connection failed, please contact Ryviu support for help.'
     45                'mes' => $mes
    4446            ]);
    4547        }
  • ryviu/trunk/includes/settings.php

    r2872853 r2881771  
    5959        $this->options = get_option( 'ryviu_settings_reviews' );
    6060        ?>
     61        <div class="ryviu-page--header">
     62            <img class="ryviu-page--image" src="https://app.ryviu.io/images/logo-ryviu-v8.svg"/>
     63            <div class="ryviu-page--intro">
     64                <h1 class="ryviu-page--title">Welcome to Ryviu!</h1>
     65                <p class="ryviu-page--intro">Ryviu is a product review app that helps you generate eCommerce social proof, increase trust & sales. You can easy to customize reviews with Ryviu and show them in your store.</p>
     66                <a class="ryviu-page--btn" href="https://app.ryviu.io" target="_blank">Ryviu Dashboard</a>
     67                <a class="ryviu-page--btn ryviu-page--btnnd" href="https://docs.ryviu.com/en/collections/1861213-woocommerce" target="_blank">Document</a>
     68                <a class="ryviu-page--btn ryviu-page--btnnd r-rate--us" href="https://wordpress.org/support/plugin/ryviu/reviews/#new-post" target="_blank">&#9733; Rate Us</a>
     69            </div>
     70        </div>
    6171        <div class="wrap">
    62 
     72           
    6373            <form method="post" action="options.php">
    64             <?php
    65                 // This prints out all hidden setting fields
    66                 settings_fields( 'ryviu_option_group' );
    67                 do_settings_sections( 'ryviu-setting-admin' );
    68 
    69                 echo '<div class="info">
    70                 <p><strong>Priority</strong>: Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.</p>
    71             </div>';
    72 
    73                 submit_button();
    74             ?>
     74                <?php
     75                    // This prints out all hidden setting fields
     76                    settings_fields( 'ryviu_option_group' );
     77                    do_settings_sections( 'ryviu-setting-admin' );
     78
     79                    echo '<div class="info">
     80                    <p><strong>Priority</strong>: Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.</p>
     81                </div>';
     82
     83                    submit_button();
     84                ?>
    7585            </form>
    7686        </div>
     
    108118
    109119    public function fields_settings(){
    110         return array(
    111             array(
    112                 'name' => 'custom_tab_title',
    113                 'title' => 'Title reviews tab'
    114             ),
    115             array(
    116                 'name' => 'position_display_widget',
    117                 'title' => 'Star rating on product page'
    118             ),
    119             array(
    120                 'name' => 'position_display',
    121                 'title' => 'Review box on product page'
    122             ),
    123             array(
    124                 'name' => 'active_reviews_tab',
    125                 'title' => 'Default active review tab'
    126             ),
    127             array(
    128                 'name' => 'position_display_widget_in_loop',
    129                 'title' => 'Star rating on collection page'
    130             ),
    131             array(
    132                 'name' => 'question_and_answer',
    133                 'title' => 'Question and Answer'
    134             ),
    135             array(
    136                 'name' => 'custom_question_tab_title',
    137                 'title' => 'Title Question & Answer tab'
    138             ),
    139             array(
    140                 'name' => 'wordpress_theme',
    141                 'title' => 'Wordpress Theme'
    142             ),
    143             array(
    144                 'name' => 'data_rocket_status',
    145                 'title' => 'Cloudfare CDN & Data Rocket'
    146             ),
    147             array(
    148                 'name' => 'element_trigger_click',
    149                 'title' => 'Title reviews tab HTML'
    150             )
    151         );
     120        $fields = [
     121            'custom_tab_title' => 'Title reviews tab',
     122            'position_display_widget' => 'Star rating on product page',
     123            'position_display' => 'Review box on product page',
     124            'active_reviews_tab' => 'Default active review tab',
     125            'position_display_widget_in_loop' => 'Star rating on collection page',
     126            'question_and_answer' => 'Question and Answer',
     127            'custom_question_tab_title' => 'Title Question & Answer tab',
     128            'wordpress_theme' => 'Wordpress Theme',
     129            'data_rocket_status' => 'Cloudfare CDN & Data Rocket',
     130            'element_trigger_click' => 'Title reviews tab HTML',
     131        ];
     132   
     133        return array_map(function($name, $title) {
     134            return ['name' => $name, 'title' => $title];
     135        }, array_keys($fields), array_values($fields));
     136    }
     137
     138    public function check_selected($val1 = '1', $val2 = '2'){
     139        if($val1 == $val2){
     140            return 'selected="selected"';
     141        }
     142        return '';
    152143    }
    153144
     
    197188     */
    198189    public function print_section_info(){
    199         print 'Enter your settings below:';
     190        print '<p class="r-des">Enter your settings below:</p>';
    200191    }
    201192
     
    265256        $select = isset($this->options[$name])? $this->options[$name] : 1;
    266257        $priority_select = isset($this->options['priority_'.$name])?$this->options['priority_'.$name] : 10;
    267 
    268258        echo '<select id="position_display" class="ryviu_settings_reviews" name="ryviu_settings_reviews['.$name.']">';
    269259        foreach (ryviu_display_position_hook($name) as $key => $data) {
    270             echo '<option value="'. $key .'" '. selected($select, $key) .'>'. $data['title'] .'</option>';
     260            echo '<option value="'. $key .'" '. $this->check_selected($select, $key) .'>'. $data['title'] .'</option>';
    271261        }
    272262        echo '</select>';
     
    274264            echo '<span class="priority-label">Priority</span><select name="ryviu_settings_reviews[priority_'.$name.']">';
    275265            foreach([6, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80] as $priority){
    276                 echo '<option value="'. $priority .'" '. selected($priority_select, $priority) .'>'. $priority .'</option>';
     266                echo '<option value="'. $priority .'" '. $this->check_selected($priority_select, $priority) .'>'. $priority .'</option>';
    277267            }
    278268            echo '</select>';
     
    314304
    315305        foreach ($themes as $key => $data) {
    316             echo '<option value="'. $key .'" '. selected($select, $key) .'>'. $data .'</option>';
     306            echo '<option value="'. $key .'" '. $this->check_selected($select, $key) .'>'. $data .'</option>';
    317307        }
    318308        echo '</select>';
     
    328318        echo '<select id="active_reviews_tab" class="ryviu_settings_reviews" name="ryviu_settings_reviews[active_reviews_tab]">';
    329319        foreach (array('1' => 'Yes', '0' => 'No') as $key => $data) {
    330             echo '<option value="'. $key .'" '. selected($select, $key) .'>'. $data .'</option>';
     320            echo '<option value="'. $key .'" '. $this->check_selected($select, $key) .'>'. $data .'</option>';
    331321        }
    332322        echo '</select>';
     
    340330        echo '<select id="question_and_answer" class="ryviu_settings_reviews" name="ryviu_settings_reviews[question_and_answer]">';
    341331        foreach (array('0' => 'Disable', '1' => 'After single product summary','2' => 'Question and Answer tab' ) as $key => $data) {
    342             echo '<option value="'. $key .'" '. selected($select, $key) .'>'. $data .'</option>';
     332            echo '<option value="'. $key .'" '. $this->check_selected($select, $key) .'>'. $data .'</option>';
    343333        }
    344334        echo '</select>';
     
    356346            $select = $this->options['enable_ajax_add_to_cart'];
    357347        }
    358 
     348       
    359349        echo '<select id="position_display" class="ryviu_settings_reviews" name="ryviu_settings_reviews[enable_ajax_add_to_cart]">';
    360350        foreach (array('1' => 'Yes', '0' => 'No') as $key => $data) {
    361             echo '<option value="'. $key .'" '. selected($select, $key) .'>'. $data .'</option>';
     351            echo '<option value="'. $key .'" '. $this->check_selected($select, $key) .'>'. $data .'</option>';
    362352        }
    363353        echo '</select>';
  • ryviu/trunk/ryviu.php

    r2872853 r2881771  
    4343define('RYVIU_APP_HOOK_URL', 'https://app.ryviu.io/webhook/woocommerce/');
    4444
    45 require plugin_dir_path( __FILE__ ) . 'includes/main-class.php';
     45require_once plugin_dir_path( __FILE__ ) . 'includes/main-class.php';
    4646
    4747/**
     
    7373
    7474    if(!$settings || $settings == new \stdClass()){
    75         echo '<div class="notice notice-error is-dismissible r-cl-connect"><p class="r--notices"><img src="https://app.ryviu.io/images/logo-ryviu-v8.svg" alt="" /><b>Ryviu:</b> It looks like there is a problem connecting your store to Ryviu. Please <a class="ryviu-check-connect" href="javascript:void(0)">click here</a> to check the issue, or please <a target="_blank" href="https://www.ryviu.com">contact us</a> for help.</p></div>';
     75        echo '<div class="notice notice-error is-dismissible r-cl-connect"><div class="r--notices"><img src="https://app.ryviu.io/images/logo-ryviu-v8.svg" alt="" /><p><b>Ryviu:</b> It looks like there is a problem connecting your store to Ryviu. Please <a class="ryviu-check-connect" href="javascript:void(0)">click here</a> to check the issue, or please <a target="_blank" href="https://www.ryviu.com/contact-us">contact us</a> for help.</p></div></div>';
    7676        echo '<div class="notice notice-success is-dismissible r-cl-connect"><p class="r--notices"><img src="https://app.ryviu.io/images/logo-ryviu-v8.svg" alt="" /><b>Ryviu: Successful connection</b></p></div>';
    7777    }
    7878}
     79
    7980
    8081register_activation_hook( __FILE__, 'activate_ryviu' );
     
    8485
    8586// Include main ryviu class
    86 require plugin_dir_path( __FILE__ ) . 'includes/class-ryviu.php';
     87require_once plugin_dir_path( __FILE__ ) . 'includes/class-ryviu.php';
    8788
    8889// Main Class Called
Note: See TracChangeset for help on using the changeset viewer.