本文整理汇总了PHP中addslashes_gpc函数的典型用法代码示例。如果您正苦于以下问题:PHP addslashes_gpc函数的具体用法?PHP addslashes_gpc怎么用?PHP addslashes_gpc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了addslashes_gpc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bsearch_clean_terms
/**
* Clean search string from XSS exploits.
*
* @since 1.0
*
* @param string $val Potentially unclean string
* @return string Cleaned string
*/
function bsearch_clean_terms($val)
{
global $bsearch_settings;
$val = stripslashes(urldecode($val));
$badwords = array_map('trim', explode(',', $bsearch_settings['badwords']));
$censorChar = ' ';
/**
* Allow the censored character to be replaced.
*
* @since 2.1.0
*
* @param string $censorChar Censored character
* @param string $val Raw search string
*/
$censorChar = apply_filters('bsearch_censor_char', $censorChar, $val);
$val_censored = bsearch_censor_string($val, $badwords, $censorChar);
// No more bad words
$val = $val_censored['clean'];
$val = addslashes_gpc($val);
$val = wp_kses_post($val);
/**
* Clean search string from XSS exploits.
*
* @since 2.0.0
*
* @param string $val Cleaned string
*/
return apply_filters('bsearch_clean_terms', $val);
}
示例2: make_duplicate
function make_duplicate($master_post_id, $lang)
{
global $wpml_post_translations;
do_action('icl_before_make_duplicate', $master_post_id, $lang);
$master_post = get_post($master_post_id);
$is_duplicated = false;
$translations = $wpml_post_translations->get_element_translations($master_post_id, false, false);
if (isset($translations[$lang])) {
$post_array['ID'] = $translations[$lang];
if (WPML_WordPress_Actions::is_bulk_trash($post_array['ID']) || WPML_WordPress_Actions::is_bulk_untrash($post_array['ID'])) {
return true;
}
$is_duplicated = get_post_meta($translations[$lang], '_icl_lang_duplicate_of', true);
}
$post_array['post_author'] = $master_post->post_author;
$post_array['post_date'] = $master_post->post_date;
$post_array['post_date_gmt'] = $master_post->post_date_gmt;
$duplicated_post_content = $this->duplicate_post_content($lang, $master_post);
$post_array['post_content'] = addslashes_gpc($duplicated_post_content);
$duplicated_post_title = $this->duplicate_post_title($lang, $master_post);
$post_array['post_title'] = addslashes_gpc($duplicated_post_title);
$duplicated_post_excerpt = $this->duplicate_post_excerpt($lang, $master_post);
$post_array['post_excerpt'] = addslashes_gpc($duplicated_post_excerpt);
if ($this->sitepress->get_setting('sync_post_status')) {
$sync_post_status = true;
} else {
$sync_post_status = !isset($post_array['ID']) || $this->sitepress->get_setting('sync_delete') && $master_post->post_status === 'trash' || $is_duplicated;
}
if ($sync_post_status || isset($post_array['ID']) && get_post_status($post_array['ID']) === 'auto-draft') {
$post_array['post_status'] = $master_post->post_status;
}
$post_array['comment_status'] = $master_post->comment_status;
$post_array['ping_status'] = $master_post->ping_status;
$post_array['post_name'] = $master_post->post_name;
if ($master_post->post_parent) {
$parent = $this->sitepress->get_object_id($master_post->post_parent, $master_post->post_type, false, $lang);
$post_array['post_parent'] = $parent;
}
$post_array['menu_order'] = $master_post->menu_order;
$post_array['post_type'] = $master_post->post_type;
$post_array['post_mime_type'] = $master_post->post_mime_type;
$trid = $this->sitepress->get_element_trid($master_post->ID, 'post_' . $master_post->post_type);
$id = $this->save_duplicate($post_array, $lang);
require_once ICL_PLUGIN_PATH . '/inc/cache.php';
icl_cache_clear();
global $ICL_Pro_Translation;
/** @var WPML_Pro_Translation $ICL_Pro_Translation */
if ($ICL_Pro_Translation) {
$ICL_Pro_Translation->_content_fix_links_to_translated_content($id, $lang);
}
if (!is_wp_error($id)) {
$ret = $this->run_wpml_actions($master_post, $trid, $lang, $id, $post_array);
} else {
$ret = false;
}
return $ret;
}
示例3: array
//.........这里部分代码省略.........
$q['attachment'] = str_replace('%2F', '/', urlencode(urldecode($q['attachment'])));
$attach_paths = '/' . trim($q['attachment'], '/');
$q['attachment'] = sanitize_title(basename($attach_paths));
$q['name'] = $q['attachment'];
$where .= " AND post_name = '" . $q['attachment'] . "'";
}
if ( (int) $q['w'] ) {
$q['w'] = ''.intval($q['w']);
$where .= " AND WEEK(post_date, 1)='" . $q['w'] . "'";
}
if ( intval($q['comments_popup']) )
$q['p'] = intval($q['comments_popup']);
// If a attachment is requested by number, let it supercede any post number.
if ( ($q['attachment_id'] != '') && (intval($q['attachment_id']) != 0) )
$q['p'] = (int) $q['attachment_id'];
// If a post number is specified, load that post
if (($q['p'] != '') && intval($q['p']) != 0) {
$q['p'] = (int) $q['p'];
$where = ' AND ID = ' . $q['p'];
}
if (($q['page_id'] != '') && (intval($q['page_id']) != 0)) {
$q['page_id'] = intval($q['page_id']);
$q['p'] = $q['page_id'];
$where = ' AND ID = '.$q['page_id'];
}
// If a search pattern is specified, load the posts that match
if (!empty($q['s'])) {
$q['s'] = addslashes_gpc($q['s']);
$search = ' AND (';
$q['s'] = preg_replace('/, +/', ' ', $q['s']);
$q['s'] = str_replace(',', ' ', $q['s']);
$q['s'] = str_replace('"', ' ', $q['s']);
$q['s'] = trim($q['s']);
if ($q['exact']) {
$n = '';
} else {
$n = '%';
}
if (!$q['sentence']) {
$s_array = explode(' ',$q['s']);
$q['search_terms'] = $s_array;
$search .= '((post_title LIKE \''.$n.$s_array[0].$n.'\') OR (post_content LIKE \''.$n.$s_array[0].$n.'\'))';
for ( $i = 1; $i < count($s_array); $i = $i + 1) {
$search .= ' AND ((post_title LIKE \''.$n.$s_array[$i].$n.'\') OR (post_content LIKE \''.$n.$s_array[$i].$n.'\'))';
}
$search .= ' OR (post_title LIKE \''.$n.$q['s'].$n.'\') OR (post_content LIKE \''.$n.$q['s'].$n.'\')';
$search .= ')';
} else {
$search = ' AND ((post_title LIKE \''.$n.$q['s'].$n.'\') OR (post_content LIKE \''.$n.$q['s'].$n.'\'))';
}
}
// Category stuff
if ((empty($q['cat'])) || ($q['cat'] == '0') ||
// Bypass cat checks if fetching specific posts
( $this->is_single || $this->is_page )) {
$whichcat='';
} else {
$q['cat'] = ''.urldecode($q['cat']).'';
示例4: do_action_ref_array
//.........这里部分代码省略.........
if ($q['attachment_id'] != '' && intval($q['attachment_id']) != 0) {
$q['p'] = (int) $q['attachment_id'];
}
// If a post number is specified, load that post
if ($q['p'] != '' && intval($q['p']) != 0) {
$q['p'] = (int) $q['p'];
$where = ' AND ID = ' . $q['p'];
}
if ($q['page_id'] != '' && intval($q['page_id']) != 0) {
$q['page_id'] = intval($q['page_id']);
if ('page' == get_option('show_on_front') && $q['page_id'] == get_option('page_for_posts')) {
$this->is_singular = false;
$this->is_page = false;
$this->is_home = true;
$this->is_posts_page = true;
} else {
$q['p'] = $q['page_id'];
$where = ' AND ID = ' . $q['page_id'];
}
}
// If a search pattern is specified, load the posts that match
if (!empty($q['s'])) {
// added slashes screw with quote grouping when done early, so done later
$q['s'] = stripslashes($q['s']);
if ($q['sentence']) {
$q['search_terms'] = array($q['s']);
} else {
preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $q[s], $matches);
$q['search_terms'] = array_map(create_function('$a', 'return trim($a, "\\"\'\\n\\r ");'), $matches[0]);
}
$n = $q['exact'] ? '' : '%';
$searchand = '';
foreach ((array) $q['search_terms'] as $term) {
$term = addslashes_gpc($term);
$search .= "{$searchand}((post_title LIKE '{$n}{$term}{$n}') OR (post_content LIKE '{$n}{$term}{$n}'))";
$searchand = ' AND ';
}
$term = addslashes_gpc($q['s']);
if (!$q['sentence'] && count($q['search_terms']) > 1 && $q['search_terms'][0] != $q['s']) {
$search .= " OR (post_title LIKE '{$n}{$term}{$n}') OR (post_content LIKE '{$n}{$term}{$n}')";
}
if (!empty($search)) {
$search = " AND ({$search}) ";
}
}
// Category stuff
if (empty($q['cat']) || $q['cat'] == '0' || ($this->is_single || $this->is_page)) {
$whichcat = '';
} else {
$q['cat'] = '' . urldecode($q['cat']) . '';
$q['cat'] = addslashes_gpc($q['cat']);
$join = " LEFT JOIN {$wpdb->post2cat} ON ({$wpdb->posts}.ID = {$wpdb->post2cat}.post_id) ";
$cat_array = preg_split('/[,\\s]+/', $q['cat']);
$in_cats = $out_cats = $out_posts = '';
foreach ($cat_array as $cat) {
$cat = intval($cat);
$in = strstr($cat, '-') ? false : true;
$cat = trim($cat, '-');
if ($in) {
$in_cats .= "{$cat}, " . get_category_children($cat, '', ', ');
} else {
$out_cats .= "{$cat}, " . get_category_children($cat, '', ', ');
}
}
$in_cats = substr($in_cats, 0, -2);
$out_cats = substr($out_cats, 0, -2);
示例5: preg_replace
$author_name = preg_replace('|[^a-z0-9-_]|', '', strtolower($author_name));
$author = $wpdb->get_var("SELECT ID FROM {$wpdb->users[$wp_id]} WHERE user_login='" . $author_name . "'");
$whichauthor .= ' AND (post_author = ' . intval($author) . ')';
}
$where .= $search . $whichcat . $whichauthor;
if (empty($order) || strtoupper($order) != 'ASC' && strtoupper($order) != 'DESC') {
$order = 'DESC';
}
// order by stuff
if (empty($orderby)) {
$orderby = 'date ' . $order;
} else {
// used to filter values
$allowed_keys = array('author', 'date', 'category', 'title');
$orderby = urldecode($orderby);
$orderby = addslashes_gpc($orderby);
$orderby_array = explode(' ', $orderby);
if (!in_array($orderby_array[0], $allowed_keys)) {
$orderby_array[0] = 'date';
}
$orderby = $orderby_array[0] . ' ' . $order;
if (count($orderby_array) > 1) {
for ($i = 1; $i < count($orderby_array); $i = $i + 1) {
// Only allow certain values for safety
if (in_array($orderby_array[$i], $allowed_keys)) {
$orderby .= ',post_' . $orderby_array[$i] . ' ' . $order;
}
}
}
}
if (!$whichcat && !$m && !$p && !$w && !$s && empty($poststart) && empty($postend)) {
示例6: getTerms
//.........这里部分代码省略.........
if ( !empty($exclude) ) {
$exterms = preg_split('/[\s,]+/',$exclude);
foreach ( (array) $exterms as $exterm ) {
if (empty($exclusions)) {
$exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' ';
} else {
$exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' ';
}
}
}
if ( !empty($exclusions) ) {
$exclusions .= ')';
}
$exclusions = apply_filters('list_terms_exclusions', $exclusions, $args );
$where .= $exclusions;
if ( !empty($slug) ) {
$slug = sanitize_title($slug);
$where .= " AND t.slug = '$slug'";
}
if ( !empty($name__like) ) {
$where .= " AND t.name LIKE '{$name__like}%'";
}
if ( strpos($st_name_like, ' ') != false || strpos($st_name_like, ' ') != null ) {
$tmp = '';
$sts = explode(' ', $st_name_like);
foreach ( (array) $sts as $st ) {
if ( empty($st) )
continue;
$st = addslashes_gpc($st);
$tmp .= " t.name LIKE '%{$st}%' OR ";
}
// Remove latest OR
$tmp = substr( $tmp, 0, strlen($tmp) - 4);
$where .= " AND ( $tmp ) ";
unset($tmp) ;
} elseif ( !empty($st_name_like) ) {
$where .= " AND t.name LIKE '%{$st_name_like}%'";
}
if ( '' != $parent ) {
$parent = (int) $parent;
$where .= " AND tt.parent = '$parent'";
}
if ( $hide_empty && !$hierarchical ) {
$where .= ' AND tt.count > 0';
}
$number_sql = '';
if ( strpos($number, ',') != false || strpos($number, ',') != null ) {
$number_sql = $number;
} else {
$number = (int) $number;
if ( $number != 0 ) {
$number_sql = 'LIMIT ' . $number;
}
}
if ( !empty($search) ) {
$search = like_escape($search);
示例7: header
<?php
$doing_rss = 1;
require 'wp-blog-header.php';
header('Content-type: text/xml; charset=' . get_settings('blog_charset'), true);
$link_cat = $_GET['link_cat'];
if (empty($link_cat) || $link_cat == 'all' || $link_cat == '0') {
$sql_cat = '';
} else {
// be safe
$link_cat = '' . urldecode($link_cat) . '';
$link_cat = addslashes_gpc($link_cat);
$link_cat = intval($link_cat);
if ($link_cat != 0) {
$sql_cat = "AND {$wpdb->links}.link_category = {$link_cat}";
$cat_name = $wpdb->get_var("SELECT {$wpdb->linkcategories}.cat_name FROM {$wpdb->linkcategories} WHERE {$wpdb->linkcategories}.cat_id = {$link_cat}");
if (!empty($cat_name)) {
$cat_name = ": category {$cat_name}";
}
}
}
echo '<?xml version="1.0"?' . ">\n";
?>
<!-- generator="wordpress/<?php
echo $wp_version;
?>
" -->
<opml version="1.0">
<head>
<title>Links for <?php
echo get_bloginfo('name') . $cat_name;
示例8: get_bsearch_matches
/**
* Get the matches for the search term.
*
* @since 1.2
*
* @param string $search_info Search terms array
* @param bool $bydate Sort by date?
* @return array Search results
*/
function get_bsearch_matches($search_query, $bydate)
{
global $wpdb, $bsearch_settings;
// if there are two items in $search_info, the string has been broken into separate terms that
// are listed at $search_info[1]. The cleaned-up version of $search_query is still at the zero index.
// This is when fulltext is disabled, and we search using LIKE
$search_info = get_bsearch_terms($search_query);
// Get search transient
$search_query_transient = 'bs_' . preg_replace('/[^A-Za-z0-9\\-]/', '', str_replace(' ', '', $search_query));
/**
* Filter name of the search transient
*
* @since 2.1.0
*
* @param string $search_query_transient Transient name
* @param array $search_query Search query
*/
$search_query_transient = apply_filters('bsearch_transient_name', $search_query_transient, $search_query);
$search_query_transient = substr($search_query_transient, 0, 40);
// Name of the transient limited to 40 chars
$matches = get_transient($search_query_transient);
if ($matches) {
if (isset($matches['search_query'])) {
if ($matches['search_query'] == $search_query) {
$results = $matches[0];
/**
* Filter array holding the search results
*
* @since 1.2
*
* @param object $matches Search results object
* @param array $search_info Search query
*/
return apply_filters('get_bsearch_matches', $matches, $search_info);
}
}
}
// If no transient is set
if (!isset($results)) {
$sql = bsearch_sql_prepare($search_info, $bsearch_settings['boolean_mode'], $bydate);
$results = $wpdb->get_results($sql);
}
// If no results are found then force BOOLEAN mode
if (!$results) {
$sql = bsearch_sql_prepare($search_info, 1, $bydate);
$results = $wpdb->get_results($sql);
}
// If no results are found then force LIKE mode
if (!$results) {
// strip out all the fancy characters that fulltext would use
$search_query = addslashes_gpc($search_query);
$search_query = preg_replace('/, +/', ' ', $search_query);
$search_query = str_replace(',', ' ', $search_query);
$search_query = str_replace('"', ' ', $search_query);
$search_query = trim($search_query);
$search_words = explode(' ', $search_query);
$s_array[0] = $search_query;
// Save original query at [0]
$s_array[1] = $search_words;
// Save array of terms at [1]
$search_info = $s_array;
$sql = bsearch_sql_prepare($search_info, 0, $bydate);
$results = $wpdb->get_results($sql);
}
$matches[0] = $results;
$matches['search_query'] = $search_query;
if ($bsearch_settings['cache']) {
// Set search transient
set_transient($search_query_transient, $matches, 7200);
}
/**
* Described in better-search.php
*/
return apply_filters('get_bsearch_matches', $matches, $search_info);
}
示例9: search_for_albums
/**
* search for albums and return the result
*
* @since 1.7.0
* @param string $request
* @param int $limit number of results, 0 shows all results
* @return Array Result of the request
*/
function search_for_albums($request, $limit = 0)
{
global $wpdb;
// If a search pattern is specified, load the posts that match
if (!empty($request)) {
// added slashes screw with quote grouping when done early, so done later
$request = stripslashes($request);
// split the words it a array if separated by a space or comma
preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $request, $matches);
$search_terms = array_map(create_function('$a', 'return trim($a, "\\"\'\\n\\r ");'), $matches[0]);
$n = '%';
$searchand = '';
$search = '';
foreach ((array) $search_terms as $term) {
$term = addslashes_gpc($term);
$search .= "{$searchand}(name LIKE '{$n}{$term}{$n}')";
$searchand = ' AND ';
}
$term = esc_sql($request);
if (count($search_terms) > 1 && $search_terms[0] != $request) {
$search .= " OR (name LIKE '{$n}{$term}{$n}')";
}
if (!empty($search)) {
$search = " AND ({$search}) ";
}
$limit = $limit > 0 ? 'LIMIT ' . intval($limit) : '';
} else {
return false;
}
// build the final query
$query = "SELECT * FROM {$wpdb->nggalbum} WHERE 1=1 {$search} ORDER BY name ASC {$limit}";
$result = $wpdb->get_results($query);
return $result;
}
示例10: ame_ajax_save_categories
/**
* SACK response function for saving post categories
*
* @since 1.2.0
* @author scripts@schloebe.de
*/
function ame_ajax_save_categories()
{
global $wpdb, $post;
$postid = intval($_POST['postid']);
$ame_cats = $_POST['ame_cats'];
$ame_categories = substr($ame_cats, 0, -1);
$catarray = explode(",", $ame_categories);
wp_set_post_categories($postid, $catarray);
unset($GLOBALS['category_cache']);
$categories = get_the_category($postid);
$ame_post_cats = "";
if (!empty($categories)) {
$out = array();
foreach ($categories as $c) {
$out[] = '<a href="edit.php?category_name=' . $c->slug . '"> ' . esc_html(sanitize_term_field('name', $c->name, $c->term_id, 'category', 'display')) . '</a>';
}
$ame_post_cats = join(', ', $out);
} else {
$ame_post_cats = __('Uncategorized');
}
do_action('edit_post', $postid, get_post($postid));
do_action('save_post', $postid, get_post($postid));
die("re_init();jQuery('span#ame_category" . $postid . "').fadeOut('fast', function() {\r\n\t\tjQuery('a#thickboxlink" . $postid . "').show();\r\n\t\tjQuery('span#ame_category" . $postid . "').html('" . addslashes_gpc($ame_post_cats) . "').fadeIn('fast');\r\n\t});");
}
示例11: mysql_real_escape_string
$value = mysql_real_escape_string($value);
}
return $value;
}
if (isset($_GET["s"])) {
$search_term = quote_smart($_GET["s"]);
}
if (isset($_GET["from"])) {
$from = (int) $_GET["from"];
$pagenow = (int) ($from / $onepage + 1);
}
if (isset($_GET["page"])) {
$pagenow = (int) $_GET["page"];
$from = $pagenow * $onepage - $onepage;
}
$search_term = addslashes_gpc($search_term);
$search_term = preg_replace('/, +/', ' ', $search_term);
$search_term = str_replace(',', ' ', $search_term);
$search_term = str_replace('"', ' ', $search_term);
$search_term = trim($search_term);
$s_array = explode(' ', $search_term);
echo "<ul>";
if ($search_term != "") {
$search = "SELECT ID, post_title FROM {$wpdb->posts} WHERE (post_title LIKE '{$wildcard}" . $s_array[0] . "{$wildcard}' OR post_content LIKE '{$wildcard}" . $s_array[0] . "{$wildcard}')";
for ($i = 1; $i < count($s_array); $i = $i + 1) {
$search .= " AND (post_title LIKE '{$wildcard}" . $s_array[$i] . "{$wildcard}' OR post_content LIKE '{$wildcard}" . $s_array[$i] . "{$wildcard}')";
}
$search .= " ORDER BY post_date DESC";
$posts = $wpdb->get_results($search);
if ($posts) {
$results = true;
示例12: sp_cron_check_news
function sp_cron_check_news()
{
$url = 'http://simple-press.com/downloads/simple-press/simple-press-news.xml';
$response = wp_remote_get($url, array('timeout' => 5));
if (is_wp_error($response) || wp_remote_retrieve_response_code($response) != 200) {
return;
}
$body = wp_remote_retrieve_body($response);
if (!$body) {
return;
}
$newNews = new SimpleXMLElement($body);
if ($newNews) {
$data = sp_get_sfmeta('news', 'news');
$cur_id = !empty($data[0]['meta_value']) ? $data[0]['meta_value']['id'] : -999;
if ($newNews->news->id != $cur_id) {
$curNews = array();
$curNews['id'] = (string) $newNews->news->id;
$curNews['show'] = 1;
$curNews['news'] = addslashes_gpc((string) $newNews->news[0]->message);
sp_add_sfmeta('news', 'news', $curNews, 0);
}
}
}
示例13: get_param
if (test_param('order')) {
$_order = get_param('order');
if (strtoupper($_order) != 'ASC' && strtoupper($_order) != 'DESC') {
$_criteria_order = 'DESC';
} else {
$_criteria_order = $_order;
}
}
// order by stuff
if (!test_param('orderby')) {
$_criteria_sort = 'post_date';
} else {
// used to filter values
$_allowed_keys = array('author', 'date', 'category', 'title');
$_order_keys = array('post_author', 'post_date', 'cat_name', 'post_title');
$_orderby_list = explode(' ', addslashes_gpc(urldecode(get_param('orderby'))));
if (!in_array($_orderby_list[0], $_allowed_keys)) {
$_orderby_array[] = 'post_date';
}
for ($_i = 0; $_i < count($_orderby_list); $_i++) {
// Only allow certain values for safety
$_key = array_search($_orderby_list[$_i], $_allowed_keys);
if ($_key !== false) {
$_orderby_array[] = $_order_keys[$_key];
}
}
$_criteria_sort = $_orderby_array;
if (in_array('category', $_orderby_list) && !test_param('category_name')) {
$_joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'ID', 'post_id');
$_joinCriteria->cascade(new XoopsJoinCriteria(wp_table('categories'), 'category_id', 'cat_ID'));
}
示例14: duplicate_custom_fields
function duplicate_custom_fields($master_post_id, $lang)
{
global $wpdb, $sitepress;
$duplicate_post_id = false;
$post_type = get_post_field('post_type', $master_post_id);
$trid = $sitepress->get_element_trid($master_post_id, 'post_' . $post_type);
if ($trid) {
$translations = $sitepress->get_element_translations($trid, 'post_' . $post_type);
if (isset($translations[$lang])) {
$duplicate_post_id = $translations[$lang]->element_id;
} else {
return false;
// translation not found!
}
}
$default_exceptions = array('_wp_old_slug', '_edit_last', '_edit_lock', '_icl_translator_note', '_icl_lang_duplicate_of', '_wpml_media_duplicate', '_wpml_media_featured');
$exceptions = $default_exceptions;
//Todo: make sure the following filter won't remove the default exceptions
$exceptions = apply_filters('wpml_duplicate_custom_fields_exceptions', $exceptions);
// low level copy
$custom_fields_master = $wpdb->get_col($wpdb->prepare("SELECT meta_key FROM {$wpdb->postmeta} WHERE post_id=%d group by meta_key", $master_post_id));
$custom_fields_duplicate = $wpdb->get_col($wpdb->prepare("SELECT meta_key FROM {$wpdb->postmeta} WHERE post_id=%d group by meta_key", $duplicate_post_id));
$custom_fields_master = array_diff($custom_fields_master, $exceptions);
$custom_fields_duplicate = array_diff($custom_fields_duplicate, $exceptions);
$remove = array_diff($custom_fields_duplicate, $custom_fields_master);
foreach ($remove as $key) {
delete_post_meta($duplicate_post_id, $key);
}
foreach ($custom_fields_master as $key) {
$master_custom_field_values_array = get_post_meta($master_post_id, $key);
$master_custom_field_values_single = get_post_meta($master_post_id, $key, true);
$is_repeated = false;
if ($master_custom_field_values_array != $master_custom_field_values_single) {
//Repeated fields
$master_custom_field_values = $master_custom_field_values_array;
$is_repeated = true;
} else {
//Field stored as serialized array
$master_custom_field_values[] = $master_custom_field_values_single;
}
if ($is_repeated) {
$duplicate_custom_field_values = get_post_meta($duplicate_post_id, $key);
} else {
$duplicate_custom_field_values[] = get_post_meta($duplicate_post_id, $key, true);
}
if (!$duplicate_custom_field_values || $master_custom_field_values != $duplicate_custom_field_values) {
if ($is_repeated) {
//Delete the old one
delete_post_meta($duplicate_post_id, $key);
//And add new ones from the original
foreach ($master_custom_field_values as $master_custom_field_value) {
add_post_meta($duplicate_post_id, $key, addslashes_gpc(apply_filters('icl_duplicate_generic_string', $master_custom_field_value, $lang, array('context' => 'custom_field', 'attribute' => 'value', 'key' => $key))));
}
} else {
update_post_meta($duplicate_post_id, $key, addslashes_gpc(apply_filters('icl_duplicate_generic_string', $master_custom_field_value, $lang, array('context' => 'custom_field', 'attribute' => 'value', 'key' => $key))));
}
}
}
return true;
}
示例15: search_propertylist
function search_propertylist($query = '', $startat = 0, $show = STAYPRESS_PROPERTY_PER_PAGE, $type = 'all', $includethumbimages = false)
{
if ($type == 'all') {
$type = 'publish,draft,pending,private';
}
// Need to redo this search
if (!empty($query)) {
// Check for a "smart" query lookup of id
if (strpos(strtolower($query), 'id:') !== false) {
$post__in = array((int) str_replace('id:', '', strtolower($query)));
} else {
$n = '%';
$query = addslashes_gpc($query);
$sql = "SELECT post_id FROM {$this->property} WHERE (reference LIKE '{$n}{$query}{$n}' OR title LIKE '{$n}{$query}{$n}' OR description LIKE '{$n}{$query}{$n}' OR country LIKE '{$n}{$query}{$n}' OR region LIKE '{$n}{$query}{$n}' OR town LIKE '{$n}{$query}{$n}')";
$sql .= $this->db->prepare(" AND blog_id = %d", $this->blog_id);
$results = $this->db->get_col($sql);
if (empty($results)) {
return false;
} else {
$post__in = $results;
}
}
}
$args = array('posts_per_page' => $show, 'offset' => $startat, 'orderby' => 'post_modified', 'order' => 'DESC', 'post_type' => STAYPRESS_PROPERTY_POST_TYPE, 'post_status' => $type, 'post__in' => $post__in);
if (!$this->user->has_cap('edit_others_properties')) {
$args['author'] = $this->user->ID;
}
$get_properties = new WP_Query();
$propertylist = $get_properties->query($args);
$this->max_num_pages = $get_properties->max_num_pages;
$this->found_posts = $get_properties->found_posts;
return $propertylist;
}