Skip to content

Commit

Permalink
Merge pull request #31 from codefoxes/trt-fixes5
Browse files Browse the repository at this point in the history
Theme review Fixes 5
  • Loading branch information
karthikax authored May 9, 2020
2 parents b899821 + 52447fb commit f1752d5
Show file tree
Hide file tree
Showing 35 changed files with 311 additions and 291 deletions.
1 change: 1 addition & 0 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

$body_attribute = greenlet_attr( 'body ' . implode( ' ', get_body_class() ) );
printf( '<body %s>', wp_kses( $body_attribute, null ) );
wp_body_open();

do_action( 'greenlet_before_topbar' );
do_action( 'greenlet_topbar' );
Expand Down
26 changes: 13 additions & 13 deletions library/backend/customizer/class-customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ class Customizer {
* @return void
*/
public function __construct() {
require_once LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-multicheck.php';
require_once LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-radio-image.php';
require_once LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-template.php';
require_once LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-template-sequence.php';
require_once LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-divider.php';
require_once LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-color.php';
require_once LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-border.php';
require_once LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-font.php';
require_once LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-length.php';
require_once LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-preset.php';
require_once LIBRARY_DIR . '/backend/customizer/class-sanitizer.php';
require_once LIBRARY_DIR . '/backend/customizer/options.php';
require_once GL_LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-multicheck.php';
require_once GL_LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-radio-image.php';
require_once GL_LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-template.php';
require_once GL_LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-template-sequence.php';
require_once GL_LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-divider.php';
require_once GL_LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-color.php';
require_once GL_LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-border.php';
require_once GL_LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-font.php';
require_once GL_LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-length.php';
require_once GL_LIBRARY_DIR . '/backend/customizer/custom-controls/class-control-preset.php';
require_once GL_LIBRARY_DIR . '/backend/customizer/class-sanitizer.php';
require_once GL_LIBRARY_DIR . '/backend/customizer/options.php';

add_action( 'customize_register', array( $this, 'greenlet_add_custom_controls' ), 0 );
add_action( 'customize_register', array( $this, 'greenlet_customize_register' ) );
Expand All @@ -75,7 +75,7 @@ public function enqueue_scripts() {
* @since 1.1.0
*/
public function enqueue_preview_scripts() {
wp_enqueue_script( 'greenlet-preview', LIBRARY_URL . '/backend/assets/js/greenlet-preview.js', array( 'jquery', 'customize-preview' ), GREENLET_VERSION, true );
wp_enqueue_script( 'greenlet-preview', GL_LIBRARY_URL . '/backend/assets/js/greenlet-preview.js', array( 'jquery', 'customize-preview' ), GREENLET_VERSION, true );
}

/**
Expand Down
13 changes: 0 additions & 13 deletions library/backend/customizer/class-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@
*/
class Sanitizer {

/**
* Sanitizes css string.
*
* @since 1.0.0
* @access public
* @param string $css CSS String.
*
* @return string Sanitized CSS.
*/
public static function sanitize_css( $css ) {
return $css;
}

/**
* Sanitizes multiple checkbox control.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class Control_Border extends \WP_Customize_Control {
* @return void
*/
public function enqueue() {
wp_enqueue_script( 'greenlet-controls', LIBRARY_URL . '/backend/assets/js/greenlet-controls.js', array( 'jquery' ), GREENLET_VERSION, true );
wp_enqueue_style( 'greenlet-controls', LIBRARY_URL . '/backend/assets/css/greenlet-controls.css', array(), GREENLET_VERSION );
wp_enqueue_script( 'greenlet-controls', GL_LIBRARY_URL . '/backend/assets/js/greenlet-controls.js', array( 'jquery' ), GREENLET_VERSION, true );
wp_enqueue_style( 'greenlet-controls', GL_LIBRARY_URL . '/backend/assets/css/greenlet-controls.css', array(), GREENLET_VERSION );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class Control_Color extends \WP_Customize_Control {
* @return void
*/
public function enqueue() {
wp_enqueue_script( 'color-picker-alpha', LIBRARY_URL . '/backend/assets/js/wp-color-picker-alpha.min.js', array( 'jquery', 'wp-color-picker' ), GREENLET_VERSION, true );
wp_enqueue_script( 'greenlet-controls', LIBRARY_URL . '/backend/assets/js/greenlet-controls.js', array( 'jquery' ), GREENLET_VERSION, true );
wp_enqueue_style( 'greenlet-controls', LIBRARY_URL . '/backend/assets/css/greenlet-controls.css', array( 'wp-color-picker' ), GREENLET_VERSION );
wp_enqueue_script( 'color-picker-alpha', GL_LIBRARY_URL . '/backend/assets/js/wp-color-picker-alpha.min.js', array( 'jquery', 'wp-color-picker' ), GREENLET_VERSION, true );
wp_enqueue_script( 'greenlet-controls', GL_LIBRARY_URL . '/backend/assets/js/greenlet-controls.js', array( 'jquery' ), GREENLET_VERSION, true );
wp_enqueue_style( 'greenlet-controls', GL_LIBRARY_URL . '/backend/assets/css/greenlet-controls.css', array( 'wp-color-picker' ), GREENLET_VERSION );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public function __construct( $manager, $id, $args = array() ) {
* @return void
*/
public function enqueue() {
wp_enqueue_script( 'choices', LIBRARY_URL . '/backend/assets/js/choices.min.js', array( 'jquery' ), GREENLET_VERSION, true );
wp_enqueue_style( 'choices', LIBRARY_URL . '/backend/assets/css/choices.css', array(), GREENLET_VERSION );
wp_enqueue_script( 'greenlet-controls', LIBRARY_URL . '/backend/assets/js/greenlet-controls.js', array( 'choices' ), GREENLET_VERSION, true );
wp_enqueue_style( 'greenlet-controls', LIBRARY_URL . '/backend/assets/css/greenlet-controls.css', array(), GREENLET_VERSION );
wp_enqueue_script( 'choices', GL_LIBRARY_URL . '/backend/assets/js/choices.min.js', array( 'jquery' ), GREENLET_VERSION, true );
wp_enqueue_style( 'choices', GL_LIBRARY_URL . '/backend/assets/css/choices.css', array(), GREENLET_VERSION );
wp_enqueue_script( 'greenlet-controls', GL_LIBRARY_URL . '/backend/assets/js/greenlet-controls.js', array( 'choices' ), GREENLET_VERSION, true );
wp_enqueue_style( 'greenlet-controls', GL_LIBRARY_URL . '/backend/assets/css/greenlet-controls.css', array(), GREENLET_VERSION );
wp_localize_script( 'greenlet-controls', 'greenletAllFonts', $this->get_all_fonts() );
}

Expand Down Expand Up @@ -132,7 +132,7 @@ public function get_all_fonts() {
* @return array Google fonts array.
*/
public function get_google_fonts() {
$fonts_file = LIBRARY_DIR . '/backend/assets/fonts/google-fonts.json';
$fonts_file = GL_LIBRARY_DIR . '/backend/assets/fonts/google-fonts.json';
$font_content = greenlet_get_file_contents( $fonts_file );
return json_decode( $font_content, true );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class Control_Length extends \WP_Customize_Control {
* @return void
*/
public function enqueue() {
wp_enqueue_script( 'greenlet-controls', LIBRARY_URL . '/backend/assets/js/greenlet-controls.js', array( 'jquery' ), GREENLET_VERSION, true );
wp_enqueue_style( 'greenlet-controls', LIBRARY_URL . '/backend/assets/css/greenlet-controls.css', array(), GREENLET_VERSION );
wp_enqueue_script( 'greenlet-controls', GL_LIBRARY_URL . '/backend/assets/js/greenlet-controls.js', array( 'jquery' ), GREENLET_VERSION, true );
wp_enqueue_style( 'greenlet-controls', GL_LIBRARY_URL . '/backend/assets/css/greenlet-controls.css', array(), GREENLET_VERSION );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Control_Multicheck extends \WP_Customize_Control {
* @return void
*/
public function enqueue() {
wp_enqueue_script( 'greenlet-controls', LIBRARY_URL . '/backend/assets/js/greenlet-controls.js', array( 'jquery' ), GREENLET_VERSION, true );
wp_enqueue_script( 'greenlet-controls', GL_LIBRARY_URL . '/backend/assets/js/greenlet-controls.js', array( 'jquery' ), GREENLET_VERSION, true );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class Control_Radio_Image extends \WP_Customize_Control {
* @return void
*/
public function enqueue() {
wp_enqueue_script( 'greenlet-controls', LIBRARY_URL . '/backend/assets/js/greenlet-controls.js', array( 'jquery' ), GREENLET_VERSION, true );
wp_enqueue_style( 'greenlet-controls', LIBRARY_URL . '/backend/assets/css/greenlet-controls.css', array(), GREENLET_VERSION );
wp_enqueue_script( 'greenlet-controls', GL_LIBRARY_URL . '/backend/assets/js/greenlet-controls.js', array( 'jquery' ), GREENLET_VERSION, true );
wp_enqueue_style( 'greenlet-controls', GL_LIBRARY_URL . '/backend/assets/css/greenlet-controls.css', array(), GREENLET_VERSION );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class Control_Template_Sequence extends \WP_Customize_Control {
* @return void
*/
public function enqueue() {
wp_enqueue_script( 'greenlet-controls', LIBRARY_URL . '/backend/assets/js/greenlet-controls.js', array( 'jquery' ), GREENLET_VERSION, true );
wp_enqueue_style( 'greenlet-controls', LIBRARY_URL . '/backend/assets/css/greenlet-controls.css', array(), GREENLET_VERSION );
wp_enqueue_script( 'greenlet-controls', GL_LIBRARY_URL . '/backend/assets/js/greenlet-controls.js', array( 'jquery' ), GREENLET_VERSION, true );
wp_enqueue_style( 'greenlet-controls', GL_LIBRARY_URL . '/backend/assets/css/greenlet-controls.css', array(), GREENLET_VERSION );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class Control_Template extends \WP_Customize_Control {
* @return void
*/
public function enqueue() {
wp_enqueue_script( 'greenlet-controls', LIBRARY_URL . '/backend/assets/js/greenlet-controls.js', array( 'jquery' ), GREENLET_VERSION, true );
wp_enqueue_style( 'greenlet-controls', LIBRARY_URL . '/backend/assets/css/greenlet-controls.css', array(), GREENLET_VERSION );
wp_enqueue_script( 'greenlet-controls', GL_LIBRARY_URL . '/backend/assets/js/greenlet-controls.js', array( 'jquery' ), GREENLET_VERSION, true );
wp_enqueue_style( 'greenlet-controls', GL_LIBRARY_URL . '/backend/assets/css/greenlet-controls.css', array(), GREENLET_VERSION );
}

/**
Expand Down
17 changes: 0 additions & 17 deletions library/backend/customizer/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -1728,23 +1728,6 @@ function greenlet_options() {
),
);

$options[] = array(
'type' => 'setting_control',
'id' => 'critical_css',
'sargs' => array(
'sanitize_callback' => array( 'Greenlet\Sanitizer', 'sanitize_css' ),
),
'cargs' => array(
'label' => __( 'Critical CSS', 'greenlet' ),
'description' => __( 'If CSS files are defered enter the critical css here.', 'greenlet' ),
'type' => 'textarea',
'section' => 'performance',
'input_attrs' => array(
'placeholder' => __( 'Leave Blank to not add Critical CSS.', 'greenlet' ),
),
),
);

$options[] = array(
'type' => 'setting_control',
'id' => 'disable_block_editor',
Expand Down
1 change: 0 additions & 1 deletion library/backend/customizer/presets.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
],
"schema": "1",
"defer_css": "1",
"critical_css": "",
"disable_emojis": false
},
"Midnight Dark": {
Expand Down
8 changes: 4 additions & 4 deletions library/backend/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ function greenlet_cover_columns( $positions = array( 'topbar', 'header', 'semifo
* @return array Templates Images Array.
*/
function greenlet_template_images( $section = 'main' ) {
$imagepath = LIBRARY_URL . '/backend/assets/images/main/';
$imagepath = GL_LIBRARY_URL . '/backend/assets/images/main/';

if ( 'cover' === $section ) {
$imagepath = LIBRARY_URL . '/backend/assets/images/cover/';
$imagepath = GL_LIBRARY_URL . '/backend/assets/images/cover/';

$templates = array(
'12' => $imagepath . '12.svg',
Expand Down Expand Up @@ -110,7 +110,7 @@ function greenlet_template_images( $section = 'main' ) {
* @return array Presets array.
*/
function greenlet_get_presets() {
$presets_file = LIBRARY_DIR . '/backend/customizer/presets.json';
$presets_file = GL_LIBRARY_DIR . '/backend/customizer/presets.json';
$presets = greenlet_get_file_contents( $presets_file );
return json_decode( $presets, true );
}
Expand All @@ -125,7 +125,7 @@ function greenlet_get_presets() {
* @return array Preset Images Array.
*/
function greenlet_preset_images() {
$imagepath = LIBRARY_URL . '/backend/assets/images/presets/';
$imagepath = GL_LIBRARY_URL . '/backend/assets/images/presets/';
$presets = greenlet_get_presets();
$images = array();

Expand Down
4 changes: 2 additions & 2 deletions library/backend/options/class-options-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ public function enqueue_admin_scripts( $hook ) {
}

// Styles.
wp_enqueue_style( 'greenlet-options', LIBRARY_URL . '/backend/assets/css/options.css', array(), GREENLET_VERSION );
wp_enqueue_style( 'greenlet-options', GL_LIBRARY_URL . '/backend/assets/css/options.css', array(), GREENLET_VERSION );

// Scripts.
wp_enqueue_script( 'greenlet-options', LIBRARY_URL . '/backend/assets/js/options.js', array(), GREENLET_VERSION, true );
wp_enqueue_script( 'greenlet-options', GL_LIBRARY_URL . '/backend/assets/js/options.js', array(), GREENLET_VERSION, true );
}

/**
Expand Down
29 changes: 27 additions & 2 deletions library/common/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@
exit;
}

/**
* Escape array theme mod.
*
* @since 1.2.5
* @param mixed $item Theme mod item.
* @return array|string
*/
function greenlet_esc_array_mod( $item ) {
if ( 'array' === gettype( $item ) ) {
$escaped = array_map( 'greenlet_esc_array_mod', $item );
} else {
$escaped = esc_html( $item );
}
return $escaped;
}

if ( ! function_exists( 'gl_get_option' ) ) {
/**
* Retrieve Greenlet theme option.
Expand All @@ -20,7 +36,16 @@
* @return mixed Option Value.
*/
function gl_get_option( $option_name, $default = false ) {
return get_theme_mod( $option_name, $default );
$mod = get_theme_mod( $option_name, $default );
$type = gettype( $mod );
if ( 'boolean' === $type ) {
$mod = ( true === $mod || 'true' === $mod || 1 === $mod || '1' === $mod ) ? true : false;
} elseif ( in_array( $type, array( 'string', 'double', 'integer' ), true ) ) {
$mod = esc_html( $mod );
} elseif ( 'array' === $type ) {
$mod = array_map( 'greenlet_esc_array_mod', $mod );
}
return $mod;
}
}

Expand Down Expand Up @@ -309,7 +334,7 @@ function greenlet_get_min_sidebars() {

// Get file names in the template directory, exclude current and parent.
$files = array_filter(
scandir( TEMPLATES_DIR ),
scandir( GL_TEMPLATES_DIR ),
function( $item ) {
return '.' !== $item[0];
}
Expand Down
2 changes: 1 addition & 1 deletion library/common/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
function greenlet_setup() {
// Make the theme available for translation.
load_theme_textdomain( 'greenlet', LANGUAGES_DIR );
load_theme_textdomain( 'greenlet', GL_LANGUAGES_DIR );

// Switch to html5 support.
add_theme_support( 'html5', array( 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption' ) );
Expand Down
6 changes: 3 additions & 3 deletions library/frontend/footer-structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ function greenlet_do_footer() {
$text = sprintf( '<div %s><p>', greenlet_attr( 'copyright' ) );
$text .= sprintf(
'&copy; %1$s &middot; <a href="%2$s">%3$s</a> &middot; %4$s <a href="https://greenletwp.com/" target="_blank" rel="nofollow noopener">%5$s</a></p></div>',
gmdate( 'Y' ),
get_home_url(),
date_i18n( __( 'Y', 'greenlet' ) ),
esc_url( get_home_url() ),
get_bloginfo( 'name' ),
__( 'Powered By', 'greenlet' ),
__( 'Greenlet', 'greenlet' )
);
echo apply_filters( 'greenlet_copyright', $text ); // phpcs:ignore
echo wp_kses_post( apply_filters( 'greenlet_copyright', $text ) );
echo '</div></div>';
greenlet_markup_close();
}
20 changes: 13 additions & 7 deletions library/frontend/header-structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
add_action( 'greenlet_topbar', 'greenlet_do_topbar' );
add_action( 'greenlet_header', 'greenlet_do_header' );

/**
* Add body classes.
*
* @since 1.2.5
* @param array $classes Classes Array.
* @return array Classes Array with added class.
*/
function greenlet_add_body_classes( $classes ) {
$classes[] = 'fixed-topbar';
return $classes;
}

/**
* Print the head.
*
Expand All @@ -30,13 +42,7 @@ function greenlet_do_head() {

$fixed_topbar = gl_get_option( 'fixed_topbar', false );
if ( false !== $fixed_topbar ) {
add_filter(
'body_class',
function ( $classes ) {
$classes[] = 'fixed-topbar';
return $classes;
}
);
add_filter( 'body_class', 'greenlet_add_body_classes' );
}
}

Expand Down
11 changes: 11 additions & 0 deletions library/frontend/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! function_exists( 'wp_body_open' ) ) {
/**
* The shim for wp_body_open.
*
* @since 1.2.5
*/
function wp_body_open() {
do_action( 'wp_body_open' );
}
}
Loading

0 comments on commit f1752d5

Please sign in to comment.