-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreal-time-find-and-replace.php
143 lines (87 loc) · 2.54 KB
/
real-time-find-and-replace.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
<?php
/*
Plugin Name: Real-Time Find and Replace
Version: 3.9
*/
//Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/*
* Add a submenu under Tools
*/
function far_add_pages() {
add_submenu_page( 'tools.php', 'Real-Time Find and Replace', 'Real-Time Find and Replace', 'activate_plugins', 'real-time-find-and-replace', 'far_options_page' );
}
function far_options_page() {
include( plugin_dir_path( __FILE__ ) . 'js/dynmicjs.php');
?>
<form method="post" action="<?php echo esc_url( $_SERVER["REQUEST_URI"] );?>">
<div class="container">
<table id="myTable" class=" table order-list">
<thead>
<tr>
<td>Search</td>
<td>Replace</td>
<td>Select Page</td>
</tr>
</thead>
<tbody>
<br><br>
<?php
$i = 0;
$far_settings = get_option( 'far_plugin_settings' );
print_r($far_settings);
foreach ( $far_settings["search"] as $key => $find ){
$args = array(
'sort_column' => 'post_title',
'post_type' => 'page',
'post_status' => 'publish'
);
$pages = get_pages($args);
$searchfield = $far_settings["search"][$i];
$replacefield = $far_settings["replace"][$i];
$selectpage = $far_settings["page"][$i];
$cols = '<tr ><td><textarea class="form-control" name="search['.$i.']" />'.$searchfield.'</textarea></td>';
$cols.= '<td><textarea class="form-control" name="replace['.$i.']"/>'.$replacefield.'</textarea></td>';
$cols.= '<td>';
$cols.='<select name="page['.$i.']"> ';
foreach ($pages as $page)
{
$title = $page->post_title;
$id = $page->ID;
echo "<option value='.$id.'>.$title.</option>";
}
$cols.='</select>';
$cols .= '<td><input type="button" class="ibtnDel btn btn-md btn-danger " value="Delete"></td>';
echo $cols ;
$i = $i + 1;
echo "</tr>";
}
echo "<div class='findif' id='id' style='display:none'>".$i."</div>";
?>
<br><br><br>
</tbody>
<tfoot>
<tr>
<td colspan="5" style="text-align: left;">
<input type="hidden" name="row">
<input type="button" class="btn btn-lg btn-block " id="addrow" value="Add Row" />
<input type="submit"/>
</td>
</tr>
<tr>
</tr>
</tfoot>
</table>
</div>
</form>
<?php
if ( isset( $_POST['row'] ) ) {
update_option( 'far_plugin_settings', $_POST );
}
//var_dump(get_option( 'far_plugin_settings' ));
} ?>
<?php
//Add left menu item in admin
add_action( 'admin_menu', 'far_add_pages' );