Plugin Directory

Changeset 3149972


Ignore:
Timestamp:
09/11/2024 11:01:59 AM (18 months ago)
Author:
ybug
Message:

feat: Add "visibility" option field

Location:
ybug-feedback-widget/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ybug-feedback-widget/trunk/admin/class-ybug-admin.php

    r2821784 r3149972  
    116116    }
    117117
     118    /**
     119     * Render Visibility field
     120     *
     121     * @since    1.2.0
     122     */
     123    public function render_visibility_field(  ) {
     124
     125        $options = get_option( 'ybug' );
     126        $options['visibility'] = @$options['visibility'] ?: 'frontend';
     127        ?>
     128        <p>
     129            <label>
     130                <input name="ybug[visibility]" type="radio" value="frontend" class="tog" <?php checked( 'frontend' === $options['visibility'] ); ?> />
     131                <?php echo __( 'Show on the Website', 'ybug' ); ?>
     132            </label>
     133        </p>
     134        <p>
     135            <label>
     136                <input name="ybug[visibility]" type="radio" value="admin" class="tog" <?php checked( 'admin' === $options['visibility'] ); ?> />
     137                <?php echo __( 'Show in the Admin Area', 'ybug' ); ?>
     138            </label>
     139        </p>
     140        <p>
     141            <label>
     142                <input name="ybug[visibility]" type="radio" value="both" class="tog" <?php checked( 'both' === $options['visibility'] ); ?> />
     143                <?php echo __( 'Show on both (Website &amp; Admin Area)', 'ybug' ); ?>
     144            </label>
     145        </p>
     146        <?php
     147
     148    }
     149
    118150
    119151    public function render_section_callback(  ) {
     
    222254        );
    223255
     256        add_settings_field(
     257            'visibility',
     258            __( 'Where to show:', 'ybug' ),
     259            array( $this, 'render_visibility_field' ),
     260            'ybugSettings',
     261            'Ybug_settings_section'
     262        );
     263
    224264
    225265        wp_enqueue_style('admin_css', plugin_dir_url( __FILE__ ) . 'css/ybug-admin.css', array(), $this->version);
     
    240280     * @since    1.0.0
    241281     */
    242     public function enqueue_scripts() {
     282    public function enqueue_scripts()
     283    {
     284        $this->enqueue_ybug_snippet();
    243285    }
    244286
     287    /**
     288     * Render JS snippet for the admin area
     289     *
     290     * @since    1.2.0
     291     */
     292    public function enqueue_ybug_snippet()
     293    {
     294        $options = get_option( 'ybug' );
     295
     296        // Show to all logged in users
     297        if (@$options['restrict_access'] === 'all' && !is_user_logged_in()) {
     298            return;
     299        }
     300
     301        // Show only to some users by role
     302        if (@$options['restrict_access'] === 'roles') {
     303            if (!array_filter($options['roles'], 'current_user_can')) {
     304                return;
     305            }
     306        }
     307
     308        // Show only if admin visibility is enabled
     309        if (!@$options['visibility'] || $options['visibility'] === 'frontend') {
     310            return;
     311        }
     312
     313        if (!@$options['project']) {
     314            return;
     315        }
     316
     317        $settings = [
     318            'id' => $options['project'],
     319        ];
     320
     321        // TODO ADD MORE SETTINGS
     322
     323        $snippet = "
     324<!-- Ybug code start (https://ybug.io) -->
     325<script type='text/javascript'>
     326(function() {
     327window.ybug_settings = " . json_encode($settings) . ";
     328var ybug = document.createElement('script'); ybug.type = 'text/javascript'; ybug.async = true;
     329ybug.src = 'https://widget.ybug.io/button/'+window.ybug_settings.id+'.js';
     330var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ybug, s);
     331})();
     332</script>
     333<!-- Ybug code end -->";
     334
     335        wp_register_script('ybug-admin-snippet', '');
     336        wp_enqueue_script('ybug-admin-snippet');
     337        wp_add_inline_script('ybug-admin-snippet', $snippet);
     338    }
     339
    245340}
  • ybug-feedback-widget/trunk/includes/class-ybug.php

    r2821784 r3149972  
    137137        add_action( 'admin_init', array( $plugin_admin, 'admin_init' ) );
    138138
    139         //      $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
    140         //      $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
    141 
     139        $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
     140        $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
    142141    }
    143142
  • ybug-feedback-widget/trunk/public/class-ybug-public.php

    r2821784 r3149972  
    5252        }
    5353
     54        // Show only if frontend visibility is enabled (default)
     55        if (@$options['visibility'] && ($options['visibility'] === 'admin')) {
     56            return;
     57        }
     58
    5459        if (@$options['project']) {
    5560
  • ybug-feedback-widget/trunk/readme.txt

    r2821786 r3149972  
    33Tags: feedback, bug-tracking, user feedback, visual feedback, feedback widget, feedback button, screenshot
    44Requires at least: 3.0.1
    5 Tested up to: 6.1
    6 Stable tag: 1.1.1
     5Tested up to: 6.6
     6Stable tag: 1.2.0
    77Requires PHP: 5.3
    88License: GPLv2 or later
     
    6262* Added new setting - access restriction
    6363
     64= 1.2.0 =
     65* Added new setting - widget visibility (website vs admin area)
     66
    6467== Upgrade Notice ==
Note: See TracChangeset for help on using the changeset viewer.