-
Notifications
You must be signed in to change notification settings - Fork 31
/
qtranslate-slug.php
183 lines (135 loc) · 4.53 KB
/
qtranslate-slug.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
/*
Plugin Name: qTranslate slug
Plugin URI: http://not-only-code.github.com/qtranslate-slug/
Description: Allows to define a slug for each language and some qTranslate bug fixes
Version: 1.1.18
Author: Carlos Sanz Garcia, Pedro Carvalho
Author URI: http://github.com/not-only-code
*/
////////////////////////////////////////////////////////////////////////////////////////
if ( !function_exists('_debug') ):
function _debug( $message ) {
if ( WP_DEBUG === true ):
if ( is_array( $message ) || is_object( $message ) ) {
error_log( print_r( $message, true ) );
} else {
error_log( $message );
}
endif;
}
endif;
////////////////////////////////////////////////////////////////////////////////////////
/**
* Includes
*
* @since 1.1.8
*/
include_once(dirname(__FILE__).'/includes/class-qtranslate-slug-widget.php');
include_once(dirname(__FILE__).'/includes/class-qtranslate-slug.php');
include_once(dirname(__FILE__).'/includes/termmeta-core.php');
////////////////////////////////////////////////////////////////////////////////////////
/**
* Define Constants
*
* @since 1.0
*/
if (!defined("QTS_VERSION")) define("QTS_VERSION", '1.1.18');
if (!defined("QTS_PREFIX")) define("QTS_PREFIX", '_qts_');
if (!defined("QTS_PAGE_BASENAME")) define('QTS_PAGE_BASENAME', 'qtranslate-slug-settings');
if (!defined("QTS_OPTIONS_NAME")) define("QTS_OPTIONS_NAME", 'qts_options');
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
////////////////////////////////////////////////////////////////////////////////////////
/**
* Init the plugin
*
* @since 1.0
*/
global $qtranslate_slug;
$qtranslate_slug = new QtranslateSlug();
// plugin activation
register_activation_hook( __FILE__, array($qtranslate_slug, 'install') );
// plugin deactivation
register_deactivation_hook( __FILE__, array($qtranslate_slug, 'deactivate') );
// plugin uninstall
register_uninstall_hook( __FILE__, 'qts_uninstall' );
// plugin init
add_action('plugins_loaded', array($qtranslate_slug, 'init') );
////////////////////////////////////////////////////////////////////////////////////////
/**
* Language Selector Code for templating
*
* @package Qtranslate Slug
* @subpackage Core
* @since 1.0
*/
function qts_language_menu ($type = "text", $args = array()) {
global $qtranslate_slug;
$qtranslate_slug->language_menu($type, $args);
}
/**
* Finds the translated slug of the given post by calling get_slug
* @param int $id the post id
* @param string $lang which language to look for
* @since 1.1.13
*/
function qts_get_slug( $id, $lang ) {
global $qtranslate_slug;
return $qtranslate_slug->get_slug($id, $lang);
}
/**
* Adds support for old plugin function
*
* @package Qtranslate Slug
* @subpackage Core
* @since 1.1.5
*/
function qTranslateSlug_getSelfUrl ($lang = false) { // bad naming, I'll keep just in case
return qts_get_url($lang);
}
function qts_get_url($lang = false) {
global $qtranslate_slug;
return $qtranslate_slug->get_current_url($lang);
}
/**
* Add a "Settings" link to the plugins.php page for Qtranslate Slug
*
* @package Qtranslate Slug
* @subpackage Settings
* @version 1.0
*
* @return calls qts_show_msg()
*/
function qts_add_settings_link( $links, $file ) {
if (QtranslateSlug::block_activate()) return $links;
$this_plugin = plugin_basename( __FILE__ );
if( $file == $this_plugin ) {
$settings_link = "<a href=\"options-general.php?page=" . QTS_PAGE_BASENAME . "\">" . __( 'Settings', 'qts' ) . '</a>';
array_unshift($links, $settings_link);
}
return $links;
}
add_filter( 'plugin_action_links', 'qts_add_settings_link', 10, 2 );
/**
* Delete plugin stored data ( options, termmeta table and postmeta data )
*
* @package Qtranslate Slug
* @subpackage Settings
* @version 1.0
*
*/
function qts_uninstall() {
global $q_config, $wpdb, $wp_version;
// options
delete_option(QTS_OPTIONS_NAME);
delete_option('qts_version');
// don't delete termmeta table as it will be used by wp beginning 4.4
if( version_compare($wp_version, "4.4", "<" ) ) {
$wpdb->query("DROP TABLE IF EXISTS $wpdb->termmeta");
}
// delete postmeta data
$meta_keys = array();
foreach ($q_config['enabled_languages'] as $lang) $meta_keys[] = sprintf("_qts_slug_%s", $lang);
$meta_keys = "'". implode( "','", $meta_keys ) . "'";
$wpdb->query("DELETE from $wpdb->postmeta WHERE meta_key IN ($meta_keys)");
}