Plugin Directory

Changeset 1773954


Ignore:
Timestamp:
11/23/2017 11:28:55 AM (8 years ago)
Author:
jasie
Message:

restored styling of widget pagination in frontend (public)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • widget-pagination/trunk/public/class-widget-pagination-public.php

    r1773867 r1773954  
    120120        wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/widget-pagination-public.css', array(), $this->version, 'all' );
    121121
     122        wp_register_style('wgpag-options', plugin_dir_url( __FILE__ ) . '/css/wgpag-options.css', $this->plugin_short );
     123        wp_enqueue_style('wgpag-options');
     124
     125        // https://developer.wordpress.org/reference/hooks/style_loader_tag/
     126        //add_filter('style_loader_tag', array($this, 'replace_option_style'), 10, 2);
     127        add_filter( 'style_loader_tag', array($this, 'replace_option_style'), 10, 4 );
    122128    }
    123129
     
    174180    }
    175181
     182    /**
     183     * Replace wgpag-options css with an inline style which pulls
     184     * the style from the options database.
     185     *
     186     * @param string $html     The link tag for the enqueued style.
     187     * @param string $handle   The style's registered handle.
     188     *
     189     * @return string          HTML
     190     * @author Lars Uebernickel
     191     * @since 0.4
     192     */
     193    function replace_option_style ($html, $handle) {
     194        if ($handle == 'wgpag-options') {
     195            return '<style type="text/css">' . $this->item_css() . '</style>';
     196        }
     197        else {
     198            return $html;
     199        }
     200    }
     201
     202        /**
     203         * TODO descr
     204         *
     205         * @return string   CSS
     206         * @author Lars Uebernickel
     207         * @since 0.4
     208         */
     209        private function item_css () {
     210            $selectors = array(
     211                'item_style'       => 'a',
     212                'hover_item_style' => 'a:hover',
     213                'cur_item_style'   => '.br-current'
     214            );
     215            $css = '';
     216            $options = get_option( $this->plugin_short );
     217            foreach($selectors as $name => $selector) {
     218                $css .= ".br-pagination $selector { ";
     219                foreach ($this->styles as $s => $title) {
     220                    $optval = $options["${name}_$s"];
     221                    if (!empty($optval)) {
     222                        $css .= "$s: $optval; ";
     223                    }
     224                }
     225                $css .= "}";
     226            }
     227
     228            $pagcss = '';
     229            $borders = array ('top', 'bottom', 'left', 'right');
     230            foreach ($borders as $border) {
     231                $borderstyle = $options['pagination_style_border_color_' . $border];
     232                if ($borderstyle) {
     233                    $pagcss .= "border-$border: 1px solid $borderstyle;";
     234                }
     235            }
     236
     237            $pagbg = $options['pagination_style_background_color'];
     238            if ($pagbg) {
     239                $pagcss .= "background-color: $pagbg;";
     240            }
     241
     242            $horalign = $options['pag_option_hor_align'];
     243            $pagcss .= "text-align: $horalign;";
     244
     245            $margintop = $options['pag_option_margin_top'];
     246            $pagcss .= "margin-top: $margintop;";
     247
     248            $marginbottom = $options['pag_option_margin_bottom'];
     249            $pagcss .= "margin-bottom: $marginbottom;";
     250
     251            $css .= ".br-pagination { $pagcss; }";
     252
     253            $liststyle = $options['list_item_style'];
     254            $css .= ".widget-container li { list-style-type: $liststyle; }";
     255
     256            return $css;
     257        }
     258
    176259}
     260?>
Note: See TracChangeset for help on using the changeset viewer.