Skip to content

Commit

Permalink
QTS: remove obsolete migration functions and styling (#1113)
Browse files Browse the repository at this point in the history
* remove obsolete migration functions
* remove unneeded frontend dedicated styling functions/CSS
  • Loading branch information
spleen1981 authored Feb 22, 2022
1 parent 3a51e19 commit 89f10fb
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 239 deletions.
22 changes: 0 additions & 22 deletions modules/slugs/assets/css/qts-default.css

This file was deleted.

1 change: 0 additions & 1 deletion modules/slugs/assets/css/qts-default.min.css

This file was deleted.

72 changes: 0 additions & 72 deletions modules/slugs/assets/js/qts-settings-upgrade.js

This file was deleted.

89 changes: 1 addition & 88 deletions modules/slugs/includes/class-qtranslate-slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,39 +129,6 @@ public function install() {
$this->activate();
}

/**
* Register front end styles and enqueue.
*/
public function register_plugin_styles() {
wp_register_style( 'qts_front_styles', plugins_url( '/assets/css/qts-default.css', dirname( __FILE__ ) ) );
wp_enqueue_style( 'qts_front_styles' );
}

/**
* Register minified front end styles and enqueue.
* 43LC: easier duplicating the function :|
*/
public function register_plugin_styles_min() {
wp_register_style( 'qts_front_styles', plugins_url( '/assets/css/qts-default.min.css', dirname( __FILE__ ) ) );
wp_enqueue_style( 'qts_front_styles' );
}

/**
* Print front end styles.
*/
public function print_plugin_styles() {
$css_path = dirname( __FILE__ ) . '/assets/css/qts-default.css';

if ( ! file_exists( $css_path ) || ! is_readable( $css_path ) ) {
return;
}
$default_css_file = file_get_contents( $css_path, FILE_USE_INCLUDE_PATH );
$css = "<style media=\"screen\">\n";
$css .= "$default_css_file\n";
$css .= "</style>\n";
echo $css;
}

/**
* Actions when deactivating the plugin.
*/
Expand All @@ -173,42 +140,6 @@ public function deactivate() {
$wp_rewrite->flush_rules();
}

/**
* Admin notice: update your old data.
*/
function notice_update() {
global $current_screen;

if ( $current_screen->id != 'settings_page_qtranslate-slug-settings' ) {
echo "<div class=\"updated\">" . PHP_EOL;
echo "<p><strong>Qtranslate Slug:</strong></p>" . PHP_EOL;
printf( "<p>%s <a href=\"%s\" class=\"button\">%s</a></p>", __( 'Please update your old data to the new system.', 'qts' ), add_query_arg( array( 'page' => 'qtranslate-slug-settings' ), 'options-general.php' ), __( 'upgrade now', 'qts' ) ) . PHP_EOL;
echo "</div>" . PHP_EOL;
}
}

/**
* Checks if old table 'qtranslate_slug' exists and is not empty.
*
* @return object | false
*/
public function check_old_data() {
global $wpdb;

if ( $this->old_data === false ) {
return false;
}
$table_name = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}qtranslate_slug'" );
if ( ! empty( $table_name ) ) {
$this->old_data = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}qtranslate_slug" );
}
if ( empty( $table_name ) || empty( $this->old_data ) ) {
$this->old_data = false;
}

return $this->old_data;
}

function qtranslate_updated_settings() {
global $q_config;

Expand Down Expand Up @@ -243,7 +174,6 @@ function init() {
$this->default_language = $q_config['default_language'];

if ( is_admin() ) {
$this->check_old_versions();
// add filters
add_filter( 'qts_validate_post_slug', array( &$this, 'validate_post_slug' ), 0, 3 );
add_filter( 'qts_validate_post_slug', array( &$this, 'unique_post_slug' ), 1, 3 );
Expand All @@ -268,15 +198,7 @@ function init() {
}
} else {
add_filter( 'request', array( &$this, 'filter_request' ) );
// adds external style file
$qts_options = $this->get_options();
if ( ! isset( $qts_options[ QTS_PREFIX . 'styles' ] ) || $qts_options[ QTS_PREFIX . 'styles' ] == "file" ) {
add_action( 'wp_enqueue_scripts', array( &$this, 'register_plugin_styles' ) );
} elseif ( $qts_options[ QTS_PREFIX . 'styles' ] == "minified" ) {
add_action( 'wp_enqueue_scripts', array( &$this, 'register_plugin_styles_min' ) );
} elseif ( $qts_options[ QTS_PREFIX . 'styles' ] == "inline" ) {
add_action( 'wp_print_styles', array( &$this, 'print_plugin_styles' ), 20 );
}
$this->set_options();
}
//FIXME: query vars are broken
add_filter( 'query_vars', array( &$this, 'query_vars' ) );
Expand Down Expand Up @@ -1846,15 +1768,6 @@ private function activate() {
flush_rewrite_rules();
}

/**
* Actions when deactivating the plugin
*/
private function check_old_versions() {
if ( $this->check_old_data() ) {
add_action( 'admin_notices', array( &$this, 'notice_update' ) );
}
}

/**
* Helper: news rules to translate the URL bases.
*
Expand Down
31 changes: 0 additions & 31 deletions modules/slugs/includes/qtranslate-slug-settings-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function qts_options_page_sections() {
$sections = array();
$sections['post_types'] = __( 'Post types', 'qts' );
$sections['taxonomies'] = __( 'Taxonomies', 'qts' );
$sections['styles'] = __( 'Styles', 'qts' );

return $sections;
}
Expand All @@ -33,36 +32,6 @@ function get_multi_txt_choices( $name = false ) {
return $choices;
}

/**
* Define our form fields (settings) for displaying the default styles.
*
* @return array
*/
function qts_options_page_styles() {
$options[] = array(
"section" => "styles",
"id" => QTS_PREFIX . "styles",
"title" => __( 'Change styles type', 'qts' ),
"desc" => array(
__( "adds a file (qts-default.css) to the theme's header.", "qts" ),
__( "adds a minified ( slighlty faster) file (qts-default.min.css) to the theme's header.", "qts" ),
__( "prints the styles directly into the theme's header.", "qts" ),
__( "neither include not print the default style.", "qts" )
),
"type" => "multi-radio",
'class' => 'qts-style',
"choices" => array(
__( "file", "qts" ),
__( "minified", "qts" ),
__( "inline", "qts" ),
__( "none", "qts" )
),
"std" => "file"
);

return $options;
}

/**
* Define our form fields (settings).
*
Expand Down
26 changes: 1 addition & 25 deletions modules/slugs/includes/qtranslate-slug-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function qts_get_settings() {
$output['qts_page_title'] = __( 'Qtranslate Slug options', 'qts' ); // the settings page title
$output['qts_page_sections'] = qts_options_page_sections(); // the settings sections
$output['qts_page_fields'] = qts_options_page_fields(); // the settings fields
$output['qts_page_styles'] = qts_options_page_styles(); // the settings for style
$output['qts_contextual_help'] = qts_options_page_contextual_help(); // the contextual help

return $output;
Expand Down Expand Up @@ -84,12 +83,6 @@ function qts_register_settings() {
qts_create_settings_field( $option );
}
}
if ( ! empty( $settings_output['qts_page_styles'] ) ) {
// call the "add_settings_field" for each
foreach ( $settings_output['qts_page_styles'] as $styleoption ) {
qts_create_settings_field( $styleoption );
}
}
}

add_action( 'admin_init', 'qts_register_settings' );
Expand All @@ -103,12 +96,6 @@ function qts_settings_scripts() {
wp_enqueue_style( 'qts_theme_settings_css', plugins_url( 'assets/css/qts-settings.css', dirname( __FILE__ ) ) );
wp_enqueue_script( 'qts_theme_settings_js', plugins_url( 'assets/js/qts-settings.js', dirname( __FILE__ ) ), array( 'jquery' ) );

/**
* @deprecated
*/
if ( $qtranslate_slug->check_old_data() ) {
wp_enqueue_script( 'qts_theme_settings_upgrade_js', plugins_url( 'assets/js/qts-settings-upgrade.js', dirname( __FILE__ ) ), array( 'jquery' ) );
}
}

add_action( 'admin_head', 'qts_settings_scripts' );
Expand Down Expand Up @@ -150,10 +137,6 @@ function qts_section_fn( $page_section = false ) {

echo "<p>" . __( 'For example, the taxonomy <kbd>category</kbd>, in Spanish would be displayed as <code>https://example.org/es/categoria/taxonomy-name/</code>. If you leave this blank will use the default option when you <a href="https://codex.wordpress.org/Function_Reference/register_taxonomy">registered</a> the taxonomy (if you previously setup a base permastruct for <u>categories</u> or <u>tags</u> in <a href="options-permalink.php">permalinks</a> page, these bases will be overwritten by the translated ones).', 'qts' ) . "</p>";
break;
case 'styles':

echo "<p>" . __( 'The default styles are very minimal, and you can include them or not.', 'qts' ) . "</p>\n";
break;
}
}

Expand Down Expand Up @@ -343,11 +326,6 @@ function qts_show_settings_page() {
// rewrite rules
flush_rewrite_rules();
?>
<?php $css_path = plugin_dir_url( dirname( __FILE__ ) ) . 'assets/css/qts-default.css';
$file_styles = file_get_contents( $css_path );
?>
<p><?php _e( 'If you selected "none", copy and use these styles as you see fit:', 'qts' ); ?> </p>
<textarea name="textarea" rows="10" cols="80"><?php echo $file_styles; ?></textarea>;
<p class="submit">
<input name="Submit" type="submit" class="button-primary"
value="<?php esc_attr_e( 'Save Changes', 'qts' ); ?>"/>
Expand All @@ -370,9 +348,7 @@ function qts_validate_options( $input ) {

// get the settings sections array
$settings_output = qts_get_settings();
$styleoptions = $settings_output['qts_page_styles'];
$slugoptions = $settings_output['qts_page_fields'];
$options = array_merge( $styleoptions, $slugoptions );
$options = $settings_output['qts_page_fields'];

// run a foreach and switch on option type
foreach ( $options as $option ):
Expand Down

0 comments on commit 89f10fb

Please sign in to comment.