WordPress.org

Plugin Directory

Changeset 515528


Ignore:
Timestamp:
03/06/12 20:22:50 (2 years ago)
Author:
ramon fincken
Message:

Bugfix

Location:
find-replace
Files:
8 added
3 edited

Legend:

Unmodified
Added
Removed
  • find-replace/trunk/form.php

    r514237 r515528  
    11<?php 
    22/** 
    3  * Admin renamer extended operations. 
    4  * 
    5  * Managing the worpress additonal admin renamer extended operations. 
    63 * 
    74 * @category      WordPress Plugins 
    85 * @package       Plugins 
    9  * @author        Bas Bosman, MijnPress DE 
     6 * @author        Bas Bosman, MijnPress DE, Ramon Fincken 
    107 * @copyright     Yes, Open source, MijnPress.nl 
    118 */ 
    129if (!defined('ABSPATH')) die("Aren't you supposed to come here via WP-Admin?"); 
    13 global $wpdb, $current_user; 
     10global $wpdb; 
    1411 
    1512$message = null; 
     
    2623        echo '<div id="message" class="error">No replace string</div>'; 
    2724    } 
    28     elseif (!isset($_POST['posttype']) || !count($_POST['posttype'])){ 
     25    elseif (!isset($_POST['post_type']) || !count($_POST['post_type'])){ 
    2926        echo '<div id="message" class="error">No post type selected</div>'; 
    3027    } else { 
    31  
    3228        //Is magic quotes on? 
    33         if (get_magic_quotes_gpc()) { 
    34             $posttype_org = $_POST['posttype']; 
    35             // Yes? Strip the added slashes 
    36             $_POST = array_map('stripslashes', $_POST); 
    37             $_POST['posttype'] = $posttype_org; 
     29        // http://codex.wordpress.org/Function_Reference/stripslashes_deep 
     30        if ( get_magic_quotes_gpc() ) { 
     31            $_POST = array_map( 'stripslashes_deep', $_POST ); 
    3832        } 
    3933 
    4034        //logic 
    41         $query          = ""; 
    42          
     35        $query  = ""; 
     36        $subquery = ""; 
     37 
     38        // at least 1 post_type is there, so the opening ( will match the ) below this foreach 
    4339        foreach ($_POST['post_type'] as $type) { 
    44          $query         = $query == '' ? 'WHERE p.post_type IN(' : $query . ', '; 
    45          $query         .= "'" . $type . "'"; 
    46       } 
    47       $query         .= ")"; 
    48        
     40            $subquery         = $subquery == '' ? 'WHERE p.post_type IN(' : $subquery . ', '; 
     41            $subquery         .= "'" . $type . "'"; 
     42        } 
     43        $query         = $subquery.")"; 
     44 
    4945        $field          = 'post_content'; 
    5046        $search         = $_POST['search']; 
    5147        $replace        = $_POST['replace']; 
    52         $prio           = ($_POST['low_priority'] == 'yes') ? ' LOW_PRIORITY ' : ''; 
     48        $prio           = ($_POST['low_priority'] == 'yes') ? ' LOW_PRIORITY ' : ''; 
    5349 
     50        $updatequery = $wpdb->prepare( "UPDATE ".$prio." $wpdb->posts AS p SET p.".$field." = REPLACE(p.".$field.", '%s', '%s') $query", $search, $replace ); 
    5451 
    55       $updatequery = $wpdb->prepare( "UPDATE ".$prio." $wpdb->posts AS p SET p.".$field." = REPLACE(p.".$field.", '%s', '%s') $query", $search, $replace ); 
    56  
    57       $wpdb->query($updatequery); 
     52        $wpdb->query($updatequery); 
    5853 
    5954        if(isset($_POST['postmeta']) && $_POST['postmeta'] == 'yes') 
    6055        { 
    6156            $field = 'meta_value'; 
    62          
     57 
    6358            $updatequery = $wpdb->prepare( "UPDATE ".$prio." $wpdb->postmeta AS pm, $wpdb->posts AS p SET pm.".$field." = REPLACE(pm.".$field.", '%s', '%s') $query AND pm.post_id = p.ID", $search, $replace ); 
    64  
    6559            $wpdb->query($updatequery); 
    6660        } 
    6761 
    6862        if(empty($prio)) 
    69         {        
     63        { 
    7064            echo '<div id="message" class="updated fade">All instances of \'' . $search . '\' are replaced with \''. $replace .'\'.</div>'; 
    7165        } 
     
    7771} 
    7872?> 
     73<h1>Find &amp; Replace plugin</h1> 
     74<p>A simple tool.</p> 
     75 
    7976<form id="form1" name="form1" method="post" action="" 
    80     onsubmit="return confirm('Are you sure?')"> 
     77    onsubmit="return confirm('Are you sure? There is NO undo.')"> 
    8178<table> 
    8279    <tr> 
    8380        <td>Include postmeta values:</td> 
    84         <td><input type="radio" name="postmeta" value="yes" checked="checked" /> Yes (Recommended)<br/> 
    85 <input type="radio" name="postmeta" value="no" /> No 
    86 </td> 
     81        <td><input type="radio" name="postmeta" value="yes" checked="checked" /> 
     82        Yes (Recommended)<br /> 
     83        <input type="radio" name="postmeta" value="no" /> No</td> 
    8784    </tr> 
    8885    <tr> 
    89         <td>Use <a href="http://dev.mysql.com/doc/refman/5.0/en/update.html" target="_blank">LOW_PRIORITY</a> to do the update:</td> 
    90         <td><input type="radio" name="low_priority" value="no" checked="checked" /> No (Instant updates to your database)<br/> 
    91 <input type="radio" name="low_priority" value="yes" /> Yes (Delayed updates, when the server has resources. Could take a long time!) 
    92 </td> 
     86        <td>Use <a href="http://dev.mysql.com/doc/refman/5.0/en/update.html" 
     87            target="_blank">LOW_PRIORITY</a> to do the update:</td> 
     88        <td><input type="radio" name="low_priority" value="no" 
     89            checked="checked" /> No (Instant updates to your database)<br /> 
     90        <input type="radio" name="low_priority" value="yes" /> Yes (Delayed 
     91        updates, when the server has resources. Could take a long time or even forever!)</td> 
    9392    </tr> 
    9493    <tr> 
     
    102101    <tr> 
    103102        <td valign="top">Post types:</td> 
    104         <td> 
    105          <?php 
    106          //get all 
    107            $post_types           = get_post_types(array('public' => true), 'object'); 
    108            unset($post_types['attachment']); 
    109            foreach ($post_types as $type => $info) { 
    110             echo '<label><input type="checkbox" name="post_type[]" value="' . $type . '"> ' . $info->labels->singular_name . '</label><br>'; 
    111            } 
    112          ?> 
    113          <label><input type="checkbox" name="post_type[]" value="trash"> Trash</label> 
    114       </td> 
    115     <tr> 
     103        <td><?php 
     104        //get all 
     105        $post_types  = get_post_types(array('public' => true), 'object'); 
     106        unset($post_types['attachment']); 
     107        foreach ($post_types as $type => $info) { 
     108            echo '<label><input type="checkbox" name="post_type[]" value="' . $type . '"> ' . $info->labels->singular_name . '</label><br>'; 
     109        } 
     110        ?> <label><input type="checkbox" name="post_type[]" value="trash"> 
     111        Trash</label></td> 
     112    </tr> 
    116113</table> 
    117114<input type="submit" name="submitbutton" value="Search and replace" 
     
    122119&nbsp;&nbsp;&nbsp;A search for "MySearch" will not find content with 
    123120"mysearch".<br /> 
    124 * Warning, Search &amp; replace postmeta will replace all postmeta, regardless of post type!<br /> 
    125121* Only the current version of your page or post will be updated.<br /> 
    126122* Example when you moved domains and you want to replace all links in 
  • find-replace/trunk/readme.txt

    r514295 r515528  
    55Requires at least: 2.0.2 
    66Tested up to: 3.3.1 
    7 Stable tag: 1.7 
     7Stable tag: 1.8 
    88 
    99Lets you find and replace text in pages, posts, Custom Post types and trashed items with a GUI. 
     
    3333 
    3434== Changelog == 
     35= 1.8 = 
     36Bugfix: No post type selected error even though i am selecting pages<br> 
     37pluginsupport.mijnpress.nl/2012/03/06/keep-getting-the-no-post-type-selected-error-even-though-i-am-selecting-pages/<br> 
     38Bugfix: html table close tr 
     39 
     40 
    3541= 1.7 = 
    3642Bugfix: Stripslashes (deep bypass) 
Note: See TracChangeset for help on using the changeset viewer.