| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | -defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); | |
| 2 | +defined( 'ABSPATH' ) || exit; | |
| 3 | 3 | |
| 4 | 4 | if ( ! imagify_can_optimize_custom_folders() ) { |
| 5 | 5 | return; |
| 6 | 6 | } |
| @@ -6,19 +6,19 @@ | ||
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | // Get folders, remove excluded ones, sort them, add labels. |
| 9 | 9 | $custom_folders = Imagify_Folders_DB::get_instance()->get_active_folders_column( 'path' ); |
| 10 | -$themes = array(); | |
| 10 | +$themes = []; | |
| 11 | 11 | |
| 12 | 12 | if ( $custom_folders ) { |
| 13 | 13 | $custom_folders = array_combine( $custom_folders, $custom_folders ); |
| 14 | - $custom_folders = array_map( array( 'Imagify_Files_Scan', 'remove_placeholder' ), $custom_folders ); | |
| 14 | + $custom_folders = array_map( [ 'Imagify_Files_Scan', 'remove_placeholder' ], $custom_folders ); | |
| 15 | 15 | $custom_folders = array_map( 'trailingslashit', $custom_folders ); |
| 16 | - $custom_folders = array_filter( $custom_folders, array( 'Imagify_Files_Scan', 'is_path_autorized' ) ); | |
| 16 | + $custom_folders = array_filter( $custom_folders, [ 'Imagify_Files_Scan', 'is_path_autorized' ] ); | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | if ( $custom_folders ) { |
| 20 | - $custom_folders = array_map( array( $this->filesystem, 'make_path_relative' ), $custom_folders ); | |
| 20 | + $custom_folders = array_map( [ $this->filesystem, 'make_path_relative' ], $custom_folders ); | |
| 21 | 21 | $custom_folders = array_map( 'untrailingslashit', $custom_folders ); |
| 22 | 22 | natcasesort( $custom_folders ); |
| 23 | 23 | $custom_folders = array_map( 'trailingslashit', $custom_folders ); |
| 24 | 24 | |
| @@ -29,11 +29,11 @@ | ||
| 29 | 29 | |
| 30 | 30 | // Current used theme(s). |
| 31 | 31 | if ( ! is_network_admin() ) { |
| 32 | 32 | $current_theme = wp_get_theme(); |
| 33 | - $themes_not_added = array(); | |
| 33 | + $themes_not_added = []; | |
| 34 | 34 | |
| 35 | - foreach ( array( $current_theme, $current_theme->parent() ) as $theme ) { | |
| 35 | + foreach ( [ $current_theme, $current_theme->parent() ] as $theme ) { | |
| 36 | 36 | if ( ! $theme || ! $theme->exists() ) { |
| 37 | 37 | continue; |
| 38 | 38 | } |
| 39 | 39 | |
| @@ -39,19 +39,19 @@ | ||
| 39 | 39 | |
| 40 | 40 | $theme_path = trailingslashit( $theme->get_stylesheet_directory() ); |
| 41 | 41 | |
| 42 | 42 | if ( ! Imagify_Files_Scan::is_path_forbidden( $theme_path ) ) { |
| 43 | - $theme = array( | |
| 43 | + $theme = [ | |
| 44 | 44 | 'name' => $theme->display( 'Name' ), |
| 45 | 45 | 'path' => Imagify_Files_Scan::add_placeholder( $theme_path ), |
| 46 | 46 | 'label' => $this->filesystem->make_path_relative( $theme_path ), |
| 47 | - ); | |
| 47 | + ]; | |
| 48 | 48 | |
| 49 | 49 | $themes[ $theme['path'] ] = $theme; |
| 50 | 50 | $added = false; |
| 51 | 51 | $rel_path = strtolower( $theme['label'] ); |
| 52 | 52 | |
| 53 | - foreach ( $custom_folders as $path => $label ) { | |
| 53 | + foreach ( $custom_folders as $path_name => $label ) { | |
| 54 | 54 | if ( strpos( $rel_path, strtolower( $label ) ) === 0 ) { |
| 55 | 55 | $added = true; |
| 56 | 56 | break; |
| 57 | 57 | } |
| @@ -67,9 +67,9 @@ | ||
| 67 | 67 | } |
| 68 | 68 | ?> |
| 69 | 69 | <div class="imagify-custom-folders-section"> |
| 70 | 70 | <div class="imagify-col" id="custom-folders"> |
| 71 | - <h3 class="imagify-options-subtitle"><?php _e( 'Custom Folders', 'imagify' ); ?></h3> | |
| 71 | + <h3 class="imagify-options-subtitle"><?php esc_html_e( 'Custom Folders', 'imagify' ); ?></h3> | |
| 72 | 72 | |
| 73 | 73 | <div id="imagify-custom-folders" class="hide-if-no-js imagify-mt2"> |
| 74 | 74 | |
| 75 | 75 | <?php if ( $themes ) { ?> |
| @@ -80,15 +80,15 @@ | ||
| 80 | 80 | <?php |
| 81 | 81 | $theme = reset( $themes ); |
| 82 | 82 | |
| 83 | 83 | /* translators: %s is a theme name. */ |
| 84 | - printf( __( 'You’re using %s', 'imagify' ), '<strong>' . $theme['name'] . '</strong>' ); | |
| 84 | + printf( esc_html__( 'You’re using %s', 'imagify' ), '<strong>' . esc_html( $theme['name'] ) . '</strong>' ); | |
| 85 | 85 | |
| 86 | 86 | if ( $themes_count > 1 ) { |
| 87 | 87 | $theme = end( $themes ); |
| 88 | 88 | echo '<br>'; |
| 89 | 89 | /* translators: %s is a theme name. */ |
| 90 | - printf( __( 'child theme of %s', 'imagify' ), '<strong>' . $theme['name'] . '</strong>' ); | |
| 90 | + printf( esc_html__( 'child theme of %s', 'imagify' ), '<strong>' . esc_html( $theme['name'] ) . '</strong>' ); | |
| 91 | 91 | } |
| 92 | 92 | ?> |
| 93 | 93 | </p> |
| 94 | 94 | </div> |
| @@ -96,39 +96,41 @@ | ||
| 96 | 96 | <div class="imagify-fts-content"> |
| 97 | 97 | <?php |
| 98 | 98 | if ( ! $themes_not_added ) { |
| 99 | 99 | ?> |
| 100 | - <p class="imagify-mb0"><?php echo _n( 'Your theme is already in the optimization process. All Good!', 'Your themes are already in the optimization process. All Good!', $themes_count, 'imagify' ); ?></p> | |
| 100 | + <p class="imagify-mb0"><?php echo esc_html( _n( 'Your theme is already in the optimization process. All Good!', 'Your themes are already in the optimization process. All Good!', $themes_count, 'imagify' ) ); ?></p> | |
| 101 | 101 | <?php |
| 102 | 102 | } elseif ( count( $themes_not_added ) !== $themes_count ) { |
| 103 | 103 | $theme = reset( $themes_not_added ); |
| 104 | 104 | $theme = $themes[ $theme ]; |
| 105 | 105 | ?> |
| 106 | - <p><?php _e( 'Only one of your current themes is in the optimization process, would you like to also optimize the other one?', 'imagify' ); ?></p> | |
| 106 | + <p><?php esc_html_e( 'Only one of your current themes is in the optimization process, would you like to also optimize the other one?', 'imagify' ); ?></p> | |
| 107 | 107 | |
| 108 | 108 | <button id="imagify-add-themes-to-custom-folder" |
| 109 | 109 | class="button imagify-button-clean imagify-add-themes" type="button" |
| 110 | 110 | data-theme="<?php echo esc_attr( $theme['path'] ) . '#///#' . esc_attr( $theme['label'] ); ?>"> |
| 111 | 111 | <span class="dashicons dashicons-plus"></span> |
| 112 | - <span class="button-text"><?php | |
| 112 | + <span class="button-text"> | |
| 113 | + <?php | |
| 113 | 114 | /* translators: %s is a theme name. */ |
| 114 | - printf( __( 'Add %s to optimization', 'imagify' ), '<strong>' . $theme['name'] . '</strong>' ); | |
| 115 | - ?></span> | |
| 115 | + printf( esc_html__( 'Add %s to optimization', 'imagify' ), '<strong>' . esc_html( $theme['name'] ) . '</strong>' ); | |
| 116 | + ?> | |
| 117 | + </span> | |
| 116 | 118 | </button> |
| 117 | 119 | <?php |
| 118 | 120 | } else { |
| 119 | - foreach ( $themes as $path => $theme ) { | |
| 120 | - $themes[ $path ] = esc_attr( $theme['path'] ) . '#///#' . esc_attr( $theme['label'] ); | |
| 121 | + foreach ( $themes as $path_name => $theme ) { | |
| 122 | + $themes[ $path_name ] = esc_attr( $theme['path'] ) . '#///#' . esc_attr( $theme['label'] ); | |
| 121 | 123 | } |
| 122 | 124 | ?> |
| 123 | - <p><?php echo _n( 'Would you like to optimize your theme?', 'Would you like to optimize your themes?', $themes_count, 'imagify' ); ?></p> | |
| 125 | + <p><?php echo esc_html( _n( 'Would you like to optimize your theme?', 'Would you like to optimize your themes?', $themes_count, 'imagify' ) ); ?></p> | |
| 124 | 126 | |
| 125 | 127 | <button id="imagify-add-themes-to-custom-folder" |
| 126 | 128 | class="button imagify-button-clean imagify-add-themes" type="button" |
| 127 | - data-theme="<?php echo implode( '" data-theme-parent="', $themes ); ?>"> | |
| 129 | + data-theme="<?php echo implode( '" data-theme-parent="', $themes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>"> | |
| 128 | 130 | <span class="dashicons dashicons-plus"></span> |
| 129 | 131 | <span |
| 130 | - class="button-text"><?php echo _n( 'Add the theme to optimization', 'Add the themes to optimization', $themes_count, 'imagify' ); ?></span> | |
| 132 | + class="button-text"><?php echo esc_html( _n( 'Add the theme to optimization', 'Add the themes to optimization', $themes_count, 'imagify' ) ); ?></span> | |
| 131 | 133 | </button> |
| 132 | 134 | <?php |
| 133 | 135 | } |
| 134 | 136 | ?> |
| @@ -136,15 +138,15 @@ | ||
| 136 | 138 | </div> |
| 137 | 139 | <?php } ?> |
| 138 | 140 | |
| 139 | 141 | <p class="imagify-kindof-title imagify-flex imagify-vcenter"> |
| 140 | - <span><?php _e( 'Select folders for optimization.', 'imagify' ); ?></span> | |
| 142 | + <span><?php esc_html_e( 'Select folders for optimization.', 'imagify' ); ?></span> | |
| 141 | 143 | <span> |
| 142 | 144 | <button id="imagify-add-custom-folder" |
| 143 | 145 | class="button imagify-button-mini imagify-button-primary imagify-add-custom-folder" |
| 144 | 146 | type="button"> |
| 145 | 147 | <span class="dashicons dashicons-plus"></span> |
| 146 | - <span class="button-text"><?php _e( 'Add folders', 'imagify' ); ?></span> | |
| 148 | + <span class="button-text"><?php esc_html_e( 'Add folders', 'imagify' ); ?></span> | |
| 147 | 149 | </button> |
| 148 | 150 | <img class="imagify-loader" aria-hidden="true" alt="<?php esc_attr_e( 'Loading...', 'imagify' ); ?>" src="<?php echo esc_url( IMAGIFY_ASSETS_IMG_URL . 'loader-balls.svg' ); ?>" width="38" height="24"/> |
| 149 | 151 | </span> |
| 150 | 152 | </p> |
| @@ -152,12 +154,15 @@ | ||
| 152 | 154 | <fieldset id="imagify-custom-folders-selected"> |
| 153 | 155 | <?php |
| 154 | 156 | if ( $custom_folders ) { |
| 155 | 157 | foreach ( $custom_folders as $placeholder => $label ) { |
| 156 | - $this->print_template( 'part-settings-row-custom-folder', array( | |
| 157 | - 'value' => $placeholder, | |
| 158 | - 'label' => $label, | |
| 159 | - ) ); | |
| 158 | + $this->print_template( | |
| 159 | + 'part-settings-row-custom-folder', | |
| 160 | + [ | |
| 161 | + 'value' => $placeholder, | |
| 162 | + 'label' => $label, | |
| 163 | + ] | |
| 164 | + ); | |
| 160 | 165 | } |
| 161 | 166 | } |
| 162 | 167 | ?> |
| 163 | 168 | </fieldset> |
| @@ -165,27 +170,30 @@ | ||
| 165 | 170 | <p> |
| 166 | 171 | <?php |
| 167 | 172 | printf( |
| 168 | 173 | /* translators: 1 and 2 are <strong> opening and closing tags. */ |
| 169 | - __( '%1$sSelecting a folder will also optimize images in sub-folders.%2$s The only exception is "Site’s root": when selected, only images that are directly at the site’s root will be optimized (sub-folders can be selected separately).', 'imagify' ), | |
| 174 | + esc_html__( '%1$sSelecting a folder will also optimize images in sub-folders.%2$s The only exception is "Site’s root": when selected, only images that are directly at the site’s root will be optimized (sub-folders can be selected separately).', 'imagify' ), | |
| 170 | 175 | '<strong>', |
| 171 | 176 | '</strong>' |
| 172 | 177 | ); |
| 173 | 178 | ?> |
| 174 | 179 | <br/> |
| 175 | - <?php _e( 'Folders that are hidden in the folder selector window are excluded and will not be optimized even if a parent folder is selected.', 'imagify' ); ?> | |
| 180 | + <?php esc_html_e( 'Folders that are hidden in the folder selector window are excluded and will not be optimized even if a parent folder is selected.', 'imagify' ); ?> | |
| 176 | 181 | </p> |
| 177 | 182 | |
| 178 | - <p class="imagify-success hidden"><?php _e( 'You changed your custom folder settings, don\'t forget to save your changes!', 'imagify' ); ?></p> | |
| 183 | + <p class="imagify-success hidden"><?php esc_html_e( 'You changed your custom folder settings, don\'t forget to save your changes!', 'imagify' ); ?></p> | |
| 179 | 184 | |
| 180 | 185 | <script type="text/html" id="tmpl-imagify-custom-folder"> |
| 181 | 186 | <?php |
| 182 | - $this->print_template( 'part-settings-row-custom-folder', array( | |
| 183 | - 'value' => '{{ data.value }}', | |
| 184 | - 'label' => '{{ data.label }}', | |
| 185 | - ) ); | |
| 187 | + $this->print_template( | |
| 188 | + 'part-settings-row-custom-folder', | |
| 189 | + [ | |
| 190 | + 'value' => '{{ data.value }}', | |
| 191 | + 'label' => '{{ data.label }}', | |
| 192 | + ] | |
| 193 | + ); | |
| 186 | 194 | ?> |
| 187 | 195 | </script> |
| 188 | 196 | </div> |
| 189 | 197 | </div> |
| 190 | 198 | </div> |
| 191 | -<?php | |
| 199 | + | |