PluginProbe
Search and Replace / 1.36
Search and Replace v1.36
trunk 1.36
search-replace / search-replace.php

search-replace.php in Search and Replace 1.36, at search-replace.php

183 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4
5 Plugin Name: Search and Replace
6
7 Plugin URI: http://www.info-d-74.com
8
9 Description: Search and replace into any pages and posts
10
11 Version: 1.36
12
13 Author: InfoD74
14
15 Author URI: http://www.info-d-74.com/en/shop
16
17 Text Domain: search-replace
18
19 Domain Path: /languages
20
21 */
22
23
24
25 add_action( 'admin_menu', 'register_search_and_replace_menu' );
26
27 function register_search_and_replace_menu() {
28
29
30
31 if(is_admin())
32
33 add_menu_page('Search and Replace', 'Search and Replace', 'edit_pages', 'search-and-replace', 'search_and_replace', esc_url(plugins_url( 'search-replace/images/icon.png' )), 30);
34
35
36
37 }
38
39
40
41 add_action('admin_print_styles', 'search_and_replace_css' );
42
43
44
45 function search_and_replace_css() {
46
47 //die( print plugins_url('css/style.css', __FILE__));
48
49 wp_enqueue_style( 'SearchAndReplaceFreeStylesheet', esc_url(plugins_url('css/style.css', __FILE__)) );
50
51 //wp_enqueue_style( 'SearchAndReplaceStylesheet' );
52
53 }
54
55
56
57 function search_and_replace() {
58
59
60
61 echo '<h1>'.esc_html(__('Search and replace', 'search-replace')).'</h1>';
62
63
64
65 if(is_admin() && current_user_can('manage_options'))
66
67 {
68
69
70
71 //on traite les données sousmises
72
73
74
75 if(sizeof($_POST) > 0)
76
77 {
78
79 check_admin_referer( 'search_replace' );
80
81
82
83 global $wpdb;
84
85
86
87 if(!empty($_POST['post']))
88
89 $where[] = "post_type = 'post'";
90
91 if(!empty($_POST['page']))
92
93 $where[] = "post_type = 'page'";
94
95
96
97 if(sizeof($where) == 0)
98
99 {
100
101 echo '<h2>'.esc_html(__('You must select at least one type of content!', 'search-replace')).'</h2>';
102
103 }
104
105 else
106
107 {
108
109
110
111 $where_query = implode(' OR ', $where);
112
113
114
115 $search = stripslashes_deep($_POST['s']);
116
117 $replace = stripslashes_deep($_POST['r']);
118
119
120
121 $query = $wpdb->prepare(
122
123 "UPDATE ".$wpdb->posts."
124
125 SET post_excerpt = REPLACE(post_excerpt, %s, %s),
126
127 post_content = REPLACE(post_content, %s, %s),
128
129 post_title = REPLACE(post_title, %s, %s)
130
131 WHERE ".$where_query,
132
133 $search, $replace, $search, $replace, $search, $replace
134
135 );
136
137
138
139 $res = $wpdb->query(
140
141 $query
142
143 );
144
145
146
147 echo '<h2>'.esc_html(__('Done!', 'search-replace')).' '.sprintf( esc_html(__('%d rows were changed', 'search-replace')), (int)$res).'</h2>';
148
149
150
151 }
152
153
154
155 }
156
157
158
159 include(plugin_dir_path( __FILE__ ) . 'templates/form.php');
160
161 }
162
163 else
164
165 esc_html_e('Denied ! You must be admin.', 'search-replace');
166
167
168
169 }
170
171
172
173 function search_and_replace_textdomain() {
174
175 load_plugin_textdomain( 'search-replace', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
176
177 }
178
179 add_action( 'plugins_loaded', 'search_and_replace_textdomain' );
180
181
182
183 ?>