本文整理汇总了PHP中normalize_whitespace函数的典型用法代码示例。如果您正苦于以下问题:PHP normalize_whitespace函数的具体用法?PHP normalize_whitespace怎么用?PHP normalize_whitespace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了normalize_whitespace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: storeForumNames
function storeForumNames($db, $username, $password, $email, $sig, $occ, $from, $website, $icq, $aim, $yim, $msnm, $interests, $viewemail, $gametype)
{
$username = strip_tags($username);
$username = trim($username);
$username = normalize_whitespace($username);
$username = mysql_escape_string($username);
$sig = chop($sig);
// Strip all trailing whitespace.
$sig = str_replace("\n", "<BR>", $sig);
$sig = mysql_escape_string($sig);
$occ = mysql_escape_string($occ);
$intrest = mysql_escape_string($intrest);
$from = mysql_escape_string($from);
$password = str_replace("\\", "", $password);
$passwd = md5($password);
$email = mysql_escape_string($email);
$regdate = time();
// Ensure the website URL starts with "http://".
$website = trim($website);
if (substr(strtolower($website), 0, 7) != "http://") {
$website = "http://" . $website;
}
if ($website == "http://") {
$website = "";
}
$website = mysql_escape_string($website);
// Check if the ICQ number only contains digits
$icq = ereg("^[0-9]+\$", $icq) ? $icq : '';
$aim = mysql_escape_string($aim);
$yim = mysql_escape_string($yim);
$msnm = mysql_escape_string($msnm);
if ($viewemail == "1") {
$sqlviewemail = "1";
} else {
$sqlviewemail = "0";
}
$sql = "SELECT max(user_id) AS total FROM users";
if (!($r = mysql($db, $sql))) {
return -1;
}
list($total) = mysql_fetch_array($r);
$total += 1;
$userDateFormat = $board_config['default_dateformat'];
$userTimeZone = $board_config['board_timezone'];
$sql = "INSERT INTO users (user_id, username, user_dateformat, user_timezone, user_regdate, user_email, user_icq, user_password, user_occ, user_interests, user_from, user_website, user_sig, user_aim, user_viewemail, user_yim, user_msnm, user_game_type) VALUES ('{$total}', '{$username}', '{$userDateFormat}', '{$userTimeZone}', '{$regdate}', '{$email}', '{$icq}', '{$passwd}', '{$occ}', '{$intrest}', '{$from}', '{$website}', '{$sig}', '{$aim}', '{$sqlviewemail}', '{$yim}', '{$msnm}', '{$gametype}')";
if (!($result = mysql($db, $sql))) {
return -1;
}
return $total;
}
示例2: bp_email
public function bp_email(BP_Email $email)
{
$recipients = $email->get_to();
$to = array();
foreach ($recipients as $recipient) {
$to[] = $recipient->get_address();
}
$subject = $email->get_subject('replace-tokens');
$message = normalize_whitespace($email->get_content_plaintext('replace-tokens'));
$filter_set = false;
if ('plaintext' != Sendgrid_Tools::get_content_type()) {
add_filter('wp_mail_content_type', array($this, 'set_html_content_type'), 100);
$filter_set = true;
$message = $email->get_template('add-content');
}
$result = wp_mail($to, $subject, $message);
if ($filter_set) {
remove_filter('wp_mail_content_type', array($this, 'set_html_content_type'));
}
return $result;
}
示例3: by_ids
/**
* Save the data for a new commit to the database
*
* @param Array $commit Zip model of the parent to save
* @return array|\WP_Error revision meta saved, WP_Error if failed
* @since 0.5.0
*/
public function by_ids($ids)
{
// reset object defaults
$this->changed = false;
$this->commit_meta = array('state_ids' => array());
$this->commit_id = 0;
$this->ids = $ids;
if (!array_key_exists('zip', $this->ids) || !is_integer($this->ids['zip'])) {
// @todo add message
return new \WP_Error();
}
if (array_key_exists('files', $this->ids) && is_array($this->ids['files'])) {
$this->states_by_file_ids($this->ids['files']);
}
if (array_key_exists('deleted', $this->ids) && is_array($this->ids['deleted'])) {
$this->deleted_states_by_file_ids($this->ids['deleted']);
}
// If files haven't changed...
if (!$this->changed) {
// ...and if no states are connected...
if (empty($this->commit_meta['state_ids'])) {
// ...then we're done.
return $this->ids;
}
$revisions = wp_get_post_revisions($this->ids['zip']);
// ...and there are no commits...
if (empty($revisions)) {
// ...save a commit...
$this->commit_id = wp_save_post_revision($this->ids['zip']);
}
// ...but if files have changed and no commit was saved...
} elseif (0 === $this->commit_id) {
// ...save a commit...
$this->commit_id = wp_save_post_revision($this->ids['zip']);
}
// ...and if no commit has been saved...
if (0 === $this->commit_id) {
$prev_revision = array_shift($revisions);
$current_post = get_post($this->ids['zip']);
// ...and if the description has changed...
if (normalize_whitespace($current_post->post_title) !== normalize_whitespace($prev_revision->post_title)) {
// ...save a commit...
$this->commit_id = wp_save_post_revision($this->ids['zip']);
}
}
// ...and if a commit has been saved...
if (0 !== $this->commit_id) {
// ...save the commit meta.
update_metadata('post', $this->commit_id, '_wpgp_commit_meta', $this->commit_meta);
}
return $this->ids;
}
示例4: wp_text_diff
/**
* Displays a human readable HTML representation of the difference between two strings.
*
* The Diff is available for getting the changes between versions. The output is
* HTML, so the primary use is for displaying the changes. If the two strings
* are equivalent, then an empty string will be returned.
*
* The arguments supported and can be changed are listed below.
*
* 'title' : Default is an empty string. Titles the diff in a manner compatible
* with the output.
* 'title_left' : Default is an empty string. Change the HTML to the left of the
* title.
* 'title_right' : Default is an empty string. Change the HTML to the right of
* the title.
*
* @since 2.6.0
*
* @see wp_parse_args() Used to change defaults to user defined settings.
* @uses Text_Diff
* @uses WP_Text_Diff_Renderer_Table
*
* @param string $left_string "old" (left) version of string
* @param string $right_string "new" (right) version of string
* @param string|array $args Optional. Change 'title', 'title_left', and 'title_right' defaults.
* @return string Empty string if strings are equivalent or HTML with differences.
*/
function wp_text_diff($left_string, $right_string, $args = null)
{
$defaults = array('title' => '', 'title_left' => '', 'title_right' => '');
$args = wp_parse_args($args, $defaults);
if (!class_exists('WP_Text_Diff_Renderer_Table')) {
require ABSPATH . WPINC . '/wp-diff.php';
}
$left_string = normalize_whitespace($left_string);
$right_string = normalize_whitespace($right_string);
$left_lines = explode("\n", $left_string);
$right_lines = explode("\n", $right_string);
$text_diff = new Text_Diff($left_lines, $right_lines);
$renderer = new WP_Text_Diff_Renderer_Table($args);
$diff = $renderer->render($text_diff);
if (!$diff) {
return '';
}
$r = "<table class='diff'>\n";
if (!empty($args['show_split_view'])) {
$r .= "<col class='content diffsplit left' /><col class='content diffsplit middle' /><col class='content diffsplit right' />";
} else {
$r .= "<col class='content' />";
}
if ($args['title'] || $args['title_left'] || $args['title_right']) {
$r .= "<thead>";
}
if ($args['title']) {
$r .= "<tr class='diff-title'><th colspan='4'>{$args['title']}</th></tr>\n";
}
if ($args['title_left'] || $args['title_right']) {
$r .= "<tr class='diff-sub-title'>\n";
$r .= "\t<td></td><th>{$args['title_left']}</th>\n";
$r .= "\t<td></td><th>{$args['title_right']}</th>\n";
$r .= "</tr>\n";
}
if ($args['title'] || $args['title_left'] || $args['title_right']) {
$r .= "</thead>\n";
}
$r .= "<tbody>\n{$diff}\n</tbody>\n";
$r .= "</table>";
return $r;
}
示例5: wp_create_post_autosave
/**
* Creates autosave data for the specified post from $_POST data.
*
* @package WordPress
* @subpackage Post_Revisions
* @since 2.6.0
*
* @param mixed $post_data Associative array containing the post data or int post ID.
* @return mixed The autosave revision ID. WP_Error or 0 on error.
*/
function wp_create_post_autosave($post_data)
{
if (is_numeric($post_data)) {
$post_id = $post_data;
$post_data = $_POST;
} else {
$post_id = (int) $post_data['post_ID'];
}
$post_data = _wp_translate_postdata(true, $post_data);
if (is_wp_error($post_data)) {
return $post_data;
}
$post_author = get_current_user_id();
// Store one autosave per author. If there is already an autosave, overwrite it.
if ($old_autosave = wp_get_post_autosave($post_id, $post_author)) {
$new_autosave = _wp_post_revision_data($post_data, true);
$new_autosave['ID'] = $old_autosave->ID;
$new_autosave['post_author'] = $post_author;
// If the new autosave has the same content as the post, delete the autosave.
$post = get_post($post_id);
$autosave_is_different = false;
foreach (array_intersect(array_keys($new_autosave), array_keys(_wp_post_revision_fields($post))) as $field) {
if (normalize_whitespace($new_autosave[$field]) != normalize_whitespace($post->{$field})) {
$autosave_is_different = true;
break;
}
}
if (!$autosave_is_different) {
wp_delete_post_revision($old_autosave->ID);
return 0;
}
/**
* Fires before an autosave is stored.
*
* @since 4.1.0
*
* @param array $new_autosave Post array - the autosave that is about to be saved.
*/
do_action('wp_creating_autosave', $new_autosave);
return wp_update_post($new_autosave);
}
// _wp_put_post_revision() expects unescaped.
$post_data = wp_unslash($post_data);
// Otherwise create the new autosave as a special post revision
return _wp_put_post_revision($post_data, true);
}
示例6: nxt_get_post_autosave
if ('auto-draft' == $post->post_status) {
if ('edit' == $action) {
$post->post_title = '';
}
$autosave = false;
$form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />";
} else {
$autosave = nxt_get_post_autosave($post_ID);
}
$form_action = 'editpost';
$nonce_action = 'update-' . $post_type . '_' . $post_ID;
$form_extra .= "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr($post_ID) . "' />";
// Detect if there exists an autosave newer than the post and if that autosave is different than the post
if ($autosave && mysql2date('U', $autosave->post_modified_gmt, false) > mysql2date('U', $post->post_modified_gmt, false)) {
foreach (_nxt_post_revision_fields() as $autosave_field => $_autosave_field) {
if (normalize_whitespace($autosave->{$autosave_field}) != normalize_whitespace($post->{$autosave_field})) {
$notice = sprintf(__('There is an autosave of this post that is more recent than the version below. <a href="%s">View the autosave</a>'), get_edit_post_link($autosave->ID));
break;
}
}
unset($autosave_field, $_autosave_field);
}
$post_type_object = get_post_type_object($post_type);
// All meta boxes should be defined and added before the first do_meta_boxes() call (or potentially during the do_meta_boxes action).
require_once './includes/meta-boxes.php';
add_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', null, 'side', 'core');
if (current_theme_supports('post-formats') && post_type_supports($post_type, 'post-formats')) {
add_meta_box('formatdiv', _x('Format', 'post format'), 'post_format_meta_box', null, 'side', 'core');
}
// all taxonomies
foreach (get_object_taxonomies($post_type) as $tax_name) {
示例7: edit_my_calendar_styles
//.........这里部分代码省略.........
esc_attr_e($mc_show_css);
?>
"/>
</p>
<p>
<input type="checkbox" id="reset_styles"
name="reset_styles" <?php
if (mc_is_custom_style(get_option('mc_css_file'))) {
echo "disabled='disabled'";
}
?>
/> <label
for="reset_styles"><?php
_e('Restore My Calendar stylesheet', 'my-calendar');
?>
</label>
<input type="checkbox" id="use_styles"
name="use_styles" <?php
mc_is_checked('mc_use_styles', 'true');
?>
/>
<label
for="use_styles"><?php
_e('Disable My Calendar Stylesheet', 'my-calendar');
?>
</label>
</p>
<p>
<?php
if (mc_is_custom_style(get_option('mc_css_file'))) {
_e('The editor is not available for custom CSS files. You should edit your custom CSS locally, then upload your changes.', 'my-calendar');
} else {
?>
<label
for="style"><?php
_e('Edit the stylesheet for My Calendar', 'my-calendar');
?>
</label><br/><textarea
class="style-editor" id="style" name="style" rows="30"
cols="80"<?php
if (get_option('mc_use_styles') == 'true') {
echo "disabled='disabled'";
}
?>
><?php
echo $my_calendar_style;
?>
</textarea>
<?php
}
?>
</p>
<p>
<input type="submit" name="save" class="button-primary button-adjust"
value="<?php
_e('Save Changes', 'my-calendar');
?>
"/>
</p>
</fieldset>
</form>
<?php
$left_string = normalize_whitespace($my_calendar_style);
$right_string = normalize_whitespace($mc_current_style);
if ($right_string) {
// if right string is blank, there is no default
if (isset($_GET['diff'])) {
echo '<div class="wrap jd-my-calendar" id="diff">';
echo wp_text_diff($left_string, $right_string, array('title' => __('Comparing Your Style with latest installed version of My Calendar', 'my-calendar'), 'title_right' => __('Latest (from plugin)', 'my-calendar'), 'title_left' => __('Current (in use)', 'my-calendar')));
echo '</div>';
} else {
if (trim($left_string) != trim($right_string)) {
echo '<div class="wrap jd-my-calendar">';
echo '<div class="updated"><p>' . __('There have been updates to the stylesheet.', 'my-calendar') . ' <a href="' . admin_url("admin.php?page=my-calendar-styles&diff#diff") . '">' . __('Compare Your Stylesheet with latest installed version of My Calendar.', 'my-calendar') . '</a></p></div>';
echo '</div>';
} else {
echo '
<div class="wrap jd-my-calendar">
<p>' . __('Your stylesheet matches that included with My Calendar.', 'my-calendar') . '</p>
</div>';
}
}
}
?>
</div>
</div>
<p><?php
_e('Resetting your stylesheet will set your stylesheet to the version currently distributed with the plug-in.', 'my-calendar');
?>
</p>
</div>
</div>
</div>
<?php
mc_show_sidebar();
?>
</div><?php
}
示例8: get_autosave_notice
function get_autosave_notice()
{
global $post;
if ('auto-draft' == $post->post_status) {
$autosave = false;
} else {
$autosave = wp_get_post_autosave($post->ID);
}
// Detect if there exists an autosave newer than the post and if that autosave is different than the post
if ($autosave && mysql2date('U', $autosave->post_modified_gmt, false) > mysql2date('U', $post->post_modified_gmt, false)) {
foreach (_wp_post_revision_fields() as $autosave_field => $_autosave_field) {
if (normalize_whitespace($autosave->{$autosave_field}) !== normalize_whitespace($post->{$autosave_field})) {
return sprintf(__('There is an autosave of this post that is more recent than the version below. <a href="%s">View the autosave</a>'), get_edit_post_link($autosave->ID));
}
}
// If this autosave isn't different from the current post, begone.
wp_delete_post_revision($autosave->ID);
}
return false;
}
示例9: eshop_form_admin_style
//.........这里部分代码省略.........
if ($eshopoptions['style'] == 'yes') {
$yes = ' checked="checked"';
$no = '';
} else {
$no = ' checked="checked"';
$yes = '';
}
?>
<input type="radio" id="usestyle" name="usestyle" value="yes"<?php
echo $yes;
?>
/><label for="usestyle"><?php
_e('Yes', 'eshop');
?>
</label>
<input type="radio" id="nostyle" name="usestyle" value="no"<?php
echo $no;
?>
/><label for="nostyle"><?php
_e('No', 'eshop');
?>
</label>
<p class="submit eshop"><input type="submit" value="<?php
_e('Amend', 'eshop');
?>
" name="submit" /></p>
</fieldset>
</form>
<?php
}
//check for new css
$plugin_dir = WP_PLUGIN_DIR;
$dirs = wp_upload_dir();
$upload_dir = $dirs['basedir'];
$eshop_goto = $upload_dir . '/eshop_files/eshop.css';
$eshop_from = $plugin_dir . '/eshop/files/eshop.css';
$eshopver = split('\\.', ESHOP_VERSION);
$left_string = file_get_contents($eshop_from, true);
$right_string = file_get_contents($eshop_goto, true);
?>
</div>
<div class="wrap">
<h2><?php
_e('Style Editor', 'eshop');
?>
</h2>
<p><?php
_e('Use this simple <abbr><span class="abbr" title="Cascading Style Sheet">CSS</span></abbr> file editor to modify the default style sheet file.', 'eshop');
?>
</p>
<form method="post" action="themes.php?page=eshop-style.php" id="edit_box">
<fieldset>
<legend><?php
_e('Style File Editor.', 'eshop');
?>
</legend>
<label for="stylebox"><?php
_e('Edit Style', 'eshop');
?>
</label><br />
<textarea rows="20" cols="80" id="stylebox" name="cssFile"><?php
if (!is_file($styleFile)) {
$error = 1;
}
if (!isset($error) && filesize($styleFile) > 0) {
$f = "";
$f = fopen($styleFile, 'r');
$file = fread($f, filesize($styleFile));
echo $file;
fclose($f);
} else {
_e('Sorry. The file you are looking for could not be found', 'eshop');
}
?>
</textarea>
<p class="submit eshop"><input type="submit" class="button-primary" value="<?php
_e('Update Style', 'eshop');
?>
" name="submit" /></p>
</fieldset>
</form>
</div>
<?php
$left_string = normalize_whitespace($left_string);
$right_string = normalize_whitespace($right_string);
if (isset($_GET['diff'])) {
echo '<div class="wrap" id="diff">';
echo wp_text_diff($right_string, $left_string, array('title' => __('Comparing Current Style with latest installed version of eShop', 'eshop'), 'title_right' => __('Latest(from plugin)', 'eshop'), 'title_left' => __('Current (in use)', 'eshop')));
echo '</div>';
} elseif (trim($left_string) != trim($right_string)) {
echo '<div class="wrap">';
echo '<p>' . __('There may have been updates to the style.', 'eshop') . ' <a href="themes.php?page=eshop-style.php&diff#diff">' . __('Compare Current Style with latest installed version of eShop.', 'eshop') . '</a></p>';
echo '</div>';
} else {
echo '<div class="wrap">';
echo '<p>' . __('Your CSS matches that included with eShop.', 'eshop') . '</p>';
echo '</div>';
}
}
示例10: wp_save_post_revision
/**
* Saves an already existing post as a post revision.
*
* Typically used immediately after post updates.
* Adds a copy of the current post as a revision, so latest revision always matches current post
*
* @since 2.6.0
*
* @uses _wp_put_post_revision()
*
* @param int $post_id The ID of the post to save as a revision.
* @return mixed Null or 0 if error, new revision ID, if success.
*/
function wp_save_post_revision($post_id)
{
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if (!($post = get_post($post_id))) {
return;
}
if (!post_type_supports($post->post_type, 'revisions')) {
return;
}
if ('auto-draft' == $post->post_status) {
return;
}
if (!wp_revisions_enabled($post)) {
return;
}
// Compare the proposed update with the last stored revision verifying that
// they are different, unless a plugin tells us to always save regardless.
// If no previous revisions, save one
if ($revisions = wp_get_post_revisions($post_id)) {
// grab the last revision, but not an autosave
foreach ($revisions as $revision) {
if (false !== strpos($revision->post_name, "{$revision->post_parent}-revision")) {
$last_revision = $revision;
break;
}
}
if (isset($last_revision) && apply_filters('wp_save_post_revision_check_for_changes', true, $last_revision, $post)) {
$post_has_changed = false;
foreach (array_keys(_wp_post_revision_fields()) as $field) {
if (normalize_whitespace($post->{$field}) != normalize_whitespace($last_revision->{$field})) {
$post_has_changed = true;
break;
}
}
//don't save revision if post unchanged
if (!$post_has_changed) {
return;
}
}
}
$return = _wp_put_post_revision($post);
$revisions_to_keep = wp_revisions_to_keep($post);
if ($revisions_to_keep < 0) {
return $return;
}
// all revisions and autosaves
$revisions = wp_get_post_revisions($post_id, array('order' => 'ASC'));
$delete = count($revisions) - $revisions_to_keep;
if ($delete < 1) {
return $return;
}
$revisions = array_slice($revisions, 0, $delete);
for ($i = 0; isset($revisions[$i]); $i++) {
if (false !== strpos($revisions[$i]->post_name, 'autosave')) {
continue;
}
wp_delete_post_revision($revisions[$i]->ID);
}
return $return;
}
示例11: wp_text_diff
function wp_text_diff($left_string, $right_string, $args = null)
{
$defaults = array('title' => '', 'title_left' => '', 'title_right' => '');
$args = wp_parse_args($args, $defaults);
$left_string = normalize_whitespace($left_string);
$right_string = normalize_whitespace($right_string);
$left_lines = explode("\n", $left_string);
$right_lines = explode("\n", $right_string);
$text_diff = new Text_Diff($left_lines, $right_lines);
$renderer = new Email_Post_Changes_Diff();
$diff = $renderer->render($text_diff);
if (!$diff) {
return '';
}
$r = "<table class='diff'>\n";
$r .= "<col class='ltype' /><col class='content' /><col class='ltype' /><col class='content' />";
if ($args['title'] || $args['title_left'] || $args['title_right']) {
$r .= "<thead>";
}
if ($args['title']) {
$r .= "<tr class='diff-title'><th colspan='4'>{$args['title']}</th></tr>\n";
}
if ($args['title_left'] || $args['title_right']) {
$r .= "<tr class='diff-sub-title'>\n";
$r .= "\t<td></td><th>{$args['title_left']}</th>\n";
$r .= "\t<td></td><th>{$args['title_right']}</th>\n";
$r .= "</tr>\n";
}
if ($args['title'] || $args['title_left'] || $args['title_right']) {
$r .= "</thead>\n";
}
$r .= "<tbody>\n{$diff}\n</tbody>\n";
$r .= "</table>";
return $r;
}
示例12: geodir_cp_from_submit_handler
function geodir_cp_from_submit_handler()
{
global $plugin_prefix, $wpdb;
if (isset($_REQUEST['geodir_save_post_type'])) {
$custom_post_type = trim($_REQUEST['geodir_custom_post_type']);
$listing_slug = trim($_REQUEST['geodir_listing_slug']);
$listing_order = trim($_REQUEST['geodir_listing_order']);
$categories = $_REQUEST['geodir_categories'];
$tags = isset($_REQUEST['geodir_tags']) ? $_REQUEST['geodir_tags'] : '';
$name = $_REQUEST['geodir_name'];
//htmlentities(trim($_REQUEST['geodir_name']));
$singular_name = trim($_REQUEST['geodir_singular_name']);
$add_new = trim($_REQUEST['geodir_add_new']);
$add_new_item = trim($_REQUEST['geodir_add_new_item']);
$edit_item = trim($_REQUEST['geodir_edit_item']);
$new_item = trim($_REQUEST['geodir_new_item']);
$view_item = trim($_REQUEST['geodir_view_item']);
$search_item = trim($_REQUEST['geodir_search_item']);
$not_found = trim($_REQUEST['geodir_not_found']);
$not_found_trash = trim($_REQUEST['geodir_not_found_trash']);
$support = $_REQUEST['geodir_support'];
$description = trim($_REQUEST['geodir_description']);
$menu_icon = trim($_REQUEST['geodir_menu_icon']);
$can_export = $_REQUEST['geodir_can_export'];
$geodir_cp_meta_keyword = $_REQUEST['geodir_cp_meta_keyword'];
$geodir_cp_meta_description = $_REQUEST['geodir_cp_meta_description'];
$label_post_profile = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_post_profile']));
$label_post_info = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_post_info']));
$label_post_images = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_post_images']));
$label_post_map = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_post_map']));
$label_reviews = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_reviews']));
$label_related_listing = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_related_listing']));
$cpt_image = isset($_FILES['geodir_cpt_img']) && !empty($_FILES['geodir_cpt_img']) ? $_FILES['geodir_cpt_img'] : NULL;
$cpt_image_remove = isset($_POST['geodir_cpt_img_remove']) ? $_POST['geodir_cpt_img_remove'] : false;
if ($can_export == 'true') {
$can_export = true;
} else {
$can_export = false;
}
$custom_post_type = geodir_clean($custom_post_type);
// erase special characters from string
$listing_slug = geodir_clean($listing_slug);
// erase special characters from string
if (isset($_REQUEST['posttype']) && $_REQUEST['posttype'] != '') {
$geodir_post_types = get_option('geodir_post_types');
$post_type_array = $geodir_post_types[$_REQUEST['posttype']];
}
if ($custom_post_type != '' && $listing_slug != '') {
if (empty($post_type_array)) {
$is_custom = 1;
//check post type create by custom or any other add-once
$posttypes_array = get_option('geodir_post_types');
$post_type = $custom_post_type;
$custom_post_type = 'gd_' . $custom_post_type;
if (array_key_exists($custom_post_type, $posttypes_array)) {
$error[] = __('Post Type already exists.', GEODIR_CP_TEXTDOMAIN);
}
foreach ($posttypes_array as $key => $value) {
if ($value['has_archive'] == $listing_slug) {
$error[] = __('Listing Slug already exists.', GEODIR_CP_TEXTDOMAIN);
break;
}
}
} else {
$post_type = preg_replace('/gd_/', '', $_REQUEST['posttype'], 1);
$custom_post_type = $_REQUEST['posttype'];
$is_custom = isset($post_type_array['is_custom']) ? $post_type_array['is_custom'] : '';
/*check post type create by custom or any other add-once */
//Edit case check duplicate listing slug
if ($post_type_array['has_archive'] != $listing_slug) {
$posttypes_array = get_option('geodir_post_types');
foreach ($posttypes_array as $key => $value) {
if ($value['has_archive'] == $listing_slug) {
$error[] = __('Listing Slug already exists.', GEODIR_CP_TEXTDOMAIN);
break;
}
}
}
}
if (empty($error)) {
/**
* Include any functions needed for upgrades.
*
* @since 1.1.7
*/
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
if (!empty($post_type_array)) {
if (!$categories) {
$geodir_taxonomies = get_option('geodir_taxonomies');
if (array_key_exists($custom_post_type . 'category', $geodir_taxonomies)) {
unset($geodir_taxonomies[$custom_post_type . 'category']);
update_option('geodir_taxonomies', $geodir_taxonomies);
}
}
if (!$tags) {
$geodir_taxonomies = get_option('geodir_taxonomies');
if (array_key_exists($custom_post_type . '_tags', $geodir_taxonomies)) {
unset($geodir_taxonomies[$custom_post_type . '_tags']);
update_option('geodir_taxonomies', $geodir_taxonomies);
}
//.........这里部分代码省略.........
示例13: front_end_editor_shortcodes
public function front_end_editor_shortcodes($attr)
{
global $wp, $current_screen, $wp_meta_boxes, $post;
$is_bac = $this->is_bac();
$output = '';
/**
* Start Checking the Conditional needed to render editor
* Define Variable needed for use in whole function
*
*
*/
if (!is_user_logged_in()) {
if ($is_bac === true) {
wp_safe_redirect(bon_accounts()->my_account_url());
} else {
if (is_woocommerce_activated()) {
wp_safe_redirect(get_permalink(wc_get_page_id('myaccount')));
}
}
} else {
if (!$this->is_edit()) {
return;
}
$object_id = $this->get_post_to_edit();
if (!$object_id) {
bon_error_notice()->add('invalid_post', __('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?'), 'error');
return;
}
$post_object = get_post($this->get_post_to_edit());
setup_postdata($GLOBALS['post'] =& $post_object);
$current_post_type = get_post_type($object_id);
if (!$post_object) {
bon_error_notice()->add('invalid_post', __('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?'), 'error');
return;
}
if (!current_user_can('edit_post', $object_id)) {
bon_error_notice()->add('permission_denied', __('You are not allowed to edit this item.'), 'error');
return;
}
if (!post_type_supports($post_object->post_type, 'front-end-editor')) {
bon_error_notice()->add('unsupported_posttype', __('The post type assigned is not supporting front end post', 'bon'), 'error');
}
$form_extra = '';
$notice = false;
if ($post_object->post_status === 'auto-draft') {
$post_object->post_title = '';
$post_object->comment_status = get_option('default_comment_status');
$post_object->ping_status = get_option('default_ping_status');
$autosave = false;
$form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />";
} else {
$autosave = wp_get_post_autosave($object_id);
}
$form_action = 'editpost';
$nonce_action = 'update-post_' . $object_id;
$form_extra .= "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr($object_id) . "' />";
$content_css = array(trailingslashit(get_stylesheet_directory_uri()) . 'assets/css/editor-styles.css', trailingslashit(includes_url()) . 'css/dashicons.min.css', trailingslashit(includes_url()) . 'js/mediaelement/mediaelementplayer.min.css', trailingslashit(includes_url()) . 'js/mediaelement/wp-mediaelement.css', trailingslashit(includes_url()) . 'js/tinymce/skins/wordpress/wp-content.css', trailingslashit(includes_url()) . 'css/editor.min.css');
$content_css = join(',', array_map('esc_url', array_unique($content_css)));
$args = array('post_ID' => $object_id, 'post_type' => $current_post_type, 'user_ID' => get_current_user_id(), 'post' => $post_object, 'post_type_object' => get_post_type_object($current_post_type), 'autosave' => $autosave, 'form_extra' => $form_extra, 'form_action' => $form_action, 'nonce_action' => $nonce_action, 'editor_settings' => array('dfw' => true, 'drag_drop_upload' => true, 'tabfocus_elements' => 'insert-media-button, save-post', 'editor_height' => 360, 'tinymce' => array('resize' => false, 'add_unload_trigger' => false, 'content_css' => $content_css)));
ob_start();
bon_get_template('posts/editor.php', $args);
$args['editor'] = ob_get_clean();
unset($args['editor_settings']);
set_current_screen($current_post_type);
$current_screen->set_parentage('edit.php?post_type=' . $current_post_type);
if (!wp_check_post_lock($object_id)) {
$args['active_post_lock'] = wp_set_post_lock($object_id);
}
$messages = $this->get_wp_messages($post_object);
$message = false;
if (isset($_GET['message'])) {
$_GET['message'] = absint($_GET['message']);
if (isset($messages[$current_post_type][$_GET['message']])) {
$message = $messages[$current_post_type][$_GET['message']];
} elseif (!isset($messages[$current_post_type]) && isset($messages['post'][$_GET['message']])) {
$message = $messages['post'][$_GET['message']];
}
}
// Detect if there exists an autosave newer than the post and if that autosave is different than the post
if ($autosave && mysql2date('U', $autosave->post_modified_gmt, false) > mysql2date('U', $post_object->post_modified_gmt, false)) {
foreach (_wp_post_revision_fields() as $autosave_field => $_autosave_field) {
if (normalize_whitespace($autosave->{$autosave_field}) != normalize_whitespace($post_object->{$autosave_field})) {
bon_error_notice()->add('autosave_exists', sprintf(__('There is an autosave of this post that is more recent than the version below. <a href="%s">View the autosave</a>'), get_edit_post_link($autosave->ID)), 'notice');
break;
}
}
// If this autosave isn't different from the current post, begone.
if (!$notice) {
wp_delete_post_revision($autosave->ID);
}
unset($autosave_field, $_autosave_field);
}
bon_get_template('posts/post.php', $args);
unset($GLOBALS['current_screen']);
wp_reset_postdata();
}
}
示例14: get_autosave_version_if_newer
/**
* find newer version of post, or return null if there is no newer autosave version
*
* @param $pid
* @return mixed|null
*/
public function get_autosave_version_if_newer($pid)
{
// Detect if there exists an autosave newer than the post and if that autosave is different than the post
$autosave = wp_get_post_autosave($pid);
$post = get_post($pid);
$newer_revision = null;
if ($autosave && $post && mysql2date('U', $autosave->post_modified_gmt, false) >= mysql2date('U', $post->post_modified_gmt, false)) {
foreach (_wp_post_revision_fields() as $autosave_field => $_autosave_field) {
if (normalize_whitespace($autosave->{$autosave_field}) != normalize_whitespace($post->{$autosave_field})) {
if ($autosave_field === 'post_content') {
$newer_revision = $autosave->{$autosave_field};
}
}
}
unset($autosave_field, $_autosave_field);
}
return $newer_revision;
}
示例15: get_diff
/**
* Performs a three-way merge with a fork, it's parent revision, and the current version of the post
* Caches so that multiple calls to get_diff within the same page load will not re-run the diff each time
* Passing an object (rather than a fork id) will bypass the cache (to allow for on-the-fly diffing on save
*/
function get_diff($fork)
{
if (!is_object($fork) && ($diff = wp_cache_get($fork, 'Fork_Diff'))) {
return $diff;
}
if (!is_object($fork)) {
$fork = get_post($fork);
}
$fork_id = $fork->ID;
//grab the three elments
$parent = $this->parent->revisions->get_parent_revision($fork);
$current = $fork->post_parent;
//normalize whitespace and convert string -> array
foreach (array('fork', 'parent', 'current') as $string) {
${$string} = get_post(${$string})->post_content;
${$string} = normalize_whitespace(${$string});
${$string} = explode("\n", ${$string});
}
//diff, cache, return
$diff = new Text_Diff3($parent, $fork, $current);
wp_cache_set($fork_id, $diff, 'Fork_Diff', $this->ttl);
return $diff;
}