Tips and Tricks HQ Support Portal › Forums › WP Photo Seller › Photo Seller – Can I upgrade proof an edited file?
- This topic has 6 replies, 2 voices, and was last updated 9 years, 10 months ago by dwest100.
-
AuthorPosts
-
January 13, 2015 at 4:16 am #12056dwest100Member
Hi, I’ve edited the WPSSearchImages.php file to make the image search more flexible with multiple keywords.
My question is:
Can I save the edited version of the file in my theme folder so it will be safe from upgrades, and still have the plugin use my version?
If so, is there a best practice for placing the file in a folder within the theme folder?
Thanks!
January 13, 2015 at 5:11 am #67998adminKeymasterThe best way to do that is to use a hook or a filter. We can add filters to our plugin so you can apply your customization. Can you please explain what changes you have made so we can see the best way of handling it?
January 13, 2015 at 5:34 am #67999dwest100MemberSure! Here’s the code
It only searches the descriptions of the images. Those are not used by Google so you can fill them up with various keywords users might search without triggering Google’s stuffing flags. Alt tags can then be kept to the ideal minimums for google.
Finds singular forms of plural words (bird is found in birds) and partials of words (finds burr in cockleburr) and does so with multiple keywords.
<?php
class WPSSearchImages
{
function __construct() {
//NOP
}
//Searches all gallery photos using multiple keywords and returns an array of results containing post IDs (ie, image IDs)
static function perform_gallery_keyword_search($keyword)
{ //Handles the keyword search of galleries and photos
global $wpdb;
//Clear the previous search result array if it exists
WPSSession::drop("last_search_results");
WPSSession::drop("last_search_term");
//Perform query
// always escape search string
//$queried = mysql_real_escape_string($keyword);
// explode the search string
$keywords = explode(" ",$keyword);
foreach($keywords as $k){
$sql .= "AND $wpdb->posts.post_content LIKE '%$k%' ";
}
$querystr = "
SELECT DISTINCT $wpdb->postmeta.post_id
FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
AND $wpdb->postmeta.meta_key = '_wpps_gallery_id'
AND $wpdb->posts.post_type = 'attachment'
$sql
ORDER BY $wpdb->postmeta.post_id ASC
";
$results = $wpdb->get_results($querystr,ARRAY_A);
//Extract only the post id and put into array
$s_data = array();
foreach($results as $res)
{
$s_data[] = $res;
}
$unique_results = array_unique($s_data); //Remove duplicates
//Store result array in session variable
if(empty($unique_results)){
return null;
}else{
$searched_photos_array = WPSGalleryItem::getSearchedPhotoItemsArray($unique_results);
WPSSession::set("last_search_results", $searched_photos_array);
WPSSession::set("last_search_term", $keyword);
return $searched_photos_array;
}
}
}
?>
January 14, 2015 at 1:50 am #68000adminKeymasterWhich particular line of code is your change?
January 14, 2015 at 5:47 am #68001dwest100MemberBeginning with //explode the search string…down to…$querystr =
And I deleted all the code that searched the other fields and merged the results.
If you take a look at the original file in the plugin you can easily see what was omitted/replaced with the new code.
January 15, 2015 at 12:39 am #68002adminKeymasterWe have added a filter in the plugin that should help you do this (without having to modify the core plugin file). When this new version is ready for testing, we will give you a copy and tell you how to use it.
January 16, 2015 at 7:23 pm #68003dwest100MemberCool! Thanks much!
-
AuthorPosts
- You must be logged in to reply to this topic.