/**
*	AJAX action for preview export row
*/
function pmxe_wp_ajax_wpae_preview()
{
    if (!check_ajax_referer('wp_all_export_secure', 'security', false)) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    if (!current_user_can(PMXE_Plugin::$capabilities)) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    XmlExportEngine::$is_preview = true;
    $custom_xml_valid = true;
    ob_start();
    $values = array();
    parse_str($_POST['data'], $values);
    $export_id = isset($_GET['id']) ? stripcslashes($_GET['id']) : 0;
    $exportOptions = $values + (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + PMXE_Plugin::get_default_import_options();
    $exportOptions['custom_xml_template'] = isset($_POST['custom_xml']) ? stripcslashes($_POST['custom_xml']) : '';
    $exportOptions['custom_xml_template'] = str_replace('<ID>', '<id>', $exportOptions['custom_xml_template']);
    $exportOptions['custom_xml_template'] = str_replace('</ID>', '</id>', $exportOptions['custom_xml_template']);
    if (!empty($exportOptions['custom_xml_template'])) {
        $custom_xml_template_line_count = substr_count($exportOptions['custom_xml_template'], "\n");
    }
    $errors = new WP_Error();
    $engine = new XmlExportEngine($exportOptions, $errors);
    XmlExportEngine::$exportOptions = $exportOptions;
    XmlExportEngine::$is_user_export = $exportOptions['is_user_export'];
    XmlExportEngine::$is_comment_export = $exportOptions['is_comment_export'];
    XmlExportEngine::$exportID = $export_id;
    if (in_array(XmlExportEngine::$exportOptions['xml_template_type'], array('custom', 'XmlGoogleMerchants'))) {
        if (empty(XmlExportEngine::$exportOptions['custom_xml_template'])) {
            $errors->add('form-validation', __('XML template is empty.', 'wp_all_export_plugin'));
        }
        if (!empty(XmlExportEngine::$exportOptions['custom_xml_template'])) {
            $engine->init_additional_data();
            $engine->init_available_data();
            $result = $engine->parse_custom_xml_template();
            $line_numbers = $result['line_numbers'];
            if (!$errors->get_error_codes()) {
                XmlExportEngine::$exportOptions = array_merge(XmlExportEngine::$exportOptions, $result);
            }
            $originalXmlTemplate = $exportOptions['custom_xml_template'];
            libxml_use_internal_errors(true);
            libxml_clear_errors();
            //Add root se we make sure there is a root tag
            $result['original_post_loop'] = '<root>' . $result['original_post_loop'] . '</root>';
            $custom_xml_template = simplexml_load_string($result['original_post_loop']);
            if ($custom_xml_template === false) {
                $custom_xml_template_errors = libxml_get_errors();
                libxml_clear_errors();
                $custom_xml_valid = false;
                // Remove one line because we added root
                $line_difference = $custom_xml_template_line_count - $line_numbers - 1;
            }
            $exportOptions['custom_xml_template'] = str_replace("<!-- BEGIN POST LOOP -->", "<!-- BEGIN LOOP -->", $exportOptions['custom_xml_template']);
            $exportOptions['custom_xml_template'] = str_replace("<!-- END POST LOOP -->", "<!-- END LOOP -->", $exportOptions['custom_xml_template']);
        }
    }
    if (isset($_GET['show_cdata'])) {
        XmlExportEngine::$exportOptions['show_cdata_in_preview'] = (bool) $_GET['show_cdata'];
    } else {
        XmlExportEngine::$exportOptions['show_cdata_in_preview'] = false;
    }
    if ($errors->get_error_codes()) {
        $msgs = $errors->get_error_messages();
        if (!is_array($msgs)) {
            $msgs = array($msgs);
        }
        foreach ($msgs as $msg) {
            ?>
			<div class="error"><p><?php 
            echo $msg;
            ?>
</p></div>
		<?php 
        }
        exit(json_encode(array('html' => ob_get_clean())));
    }
    if ('advanced' == $exportOptions['export_type']) {
        if (XmlExportEngine::$is_user_export) {
            $exportQuery = eval('return new WP_User_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => 0, \'number\' => 10));');
        } elseif (XmlExportEngine::$is_comment_export) {
            $exportQuery = eval('return new WP_Comment_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => 0, \'number\' => 10));');
        } else {
            $exportQuery = eval('return new WP_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => 0, \'posts_per_page\' => 10));');
        }
    } else {
        XmlExportEngine::$post_types = $exportOptions['cpt'];
        if (in_array('users', $exportOptions['cpt']) or in_array('shop_customer', $exportOptions['cpt'])) {
            add_action('pre_user_query', 'wp_all_export_pre_user_query', 10, 1);
            $exportQuery = new WP_User_Query(array('orderby' => 'ID', 'order' => 'ASC', 'number' => 10));
            remove_action('pre_user_query', 'wp_all_export_pre_user_query');
        } elseif (in_array('comments', $exportOptions['cpt'])) {
            add_action('comments_clauses', 'wp_all_export_comments_clauses', 10, 1);
            global $wp_version;
            if (version_compare($wp_version, '4.2.0', '>=')) {
                $exportQuery = new WP_Comment_Query(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10));
            } else {
                $exportQuery = get_comments(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10));
            }
            remove_action('comments_clauses', 'wp_all_export_comments_clauses');
        } else {
            remove_all_actions('parse_query');
            remove_all_actions('pre_get_posts');
            remove_all_filters('posts_clauses');
            add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
            add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
            $exportQuery = new WP_Query(array('post_type' => $exportOptions['cpt'], 'post_status' => 'any', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => 10));
            remove_filter('posts_where', 'wp_all_export_posts_where');
            remove_filter('posts_join', 'wp_all_export_posts_join');
        }
    }
    XmlExportEngine::$exportQuery = $exportQuery;
    $engine->init_additional_data();
    ?>

	<div id="post-preview" class="wpallexport-preview">
		
		<p class="wpallexport-preview-title"><?php 
    echo sprintf("Preview first 10 %s", wp_all_export_get_cpt_name($exportOptions['cpt'], 10));
    ?>
</p>

		<div class="wpallexport-preview-content">
			
		<?php 
    if (!$custom_xml_valid) {
        $error_msg = '<strong class="error">' . __('Invalid XML', 'wp_all_import_plugin') . '</strong><ul  class="error">';
        foreach ($custom_xml_template_errors as $error) {
            $error_msg .= '<li>';
            $error_msg .= __('Line', 'wp_all_import_plugin') . ' ' . ($error->line + $line_difference) . ', ';
            $error_msg .= __('Column', 'wp_all_import_plugin') . ' ' . $error->column . ', ';
            $error_msg .= __('Code', 'wp_all_import_plugin') . ' ' . $error->code . ': ';
            $error_msg .= '<em>' . trim(esc_html($error->message)) . '</em>';
            $error_msg .= '</li>';
        }
        $error_msg .= '</ul>';
        echo $error_msg;
        exit(json_encode(array('html' => ob_get_clean())));
    }
    $wp_uploads = wp_upload_dir();
    $functions = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'functions.php';
    if (@file_exists($functions)) {
        require_once $functions;
    }
    switch ($exportOptions['export_to']) {
        case 'xml':
            $dom = new DOMDocument('1.0', $exportOptions['encoding']);
            libxml_use_internal_errors(true);
            try {
                $xml = XmlCsvExport::export_xml(true);
            } catch (WpaeMethodNotFoundException $e) {
                // Find the line where the function is
                $errorMessage = '';
                $functionName = $e->getMessage();
                $txtParts = explode("\n", $originalXmlTemplate);
                for ($i = 0, $length = count($txtParts); $i < $length; $i++) {
                    $tmp = strstr($txtParts[$i], $functionName);
                    if ($tmp) {
                        $errorMessage .= 'Error parsing XML feed: Call to undefined function <em>"' . $functionName . '"</em> on Line ' . ($i + 1);
                    }
                }
                $error_msg = '<span class="error">' . __($errorMessage, 'wp_all_import_plugin') . '</span>';
                echo $error_msg;
                exit(json_encode(array('html' => ob_get_clean())));
            } catch (WpaeInvalidStringException $e) {
                // Find the line where the function is
                $errorMessage = '';
                $functionName = $e->getMessage();
                $txtParts = explode("\n", $originalXmlTemplate);
                for ($i = 0, $length = count($txtParts); $i < $length; $i++) {
                    $tmp = strstr($txtParts[$i], $functionName);
                    if ($tmp) {
                        $errorMessage .= 'Error parsing XML feed: Unterminated string on line ' . ($i + 1);
                    }
                }
                $error_msg = '<span class="error">' . __($errorMessage, 'wp_all_import_plugin') . '</span>';
                echo $error_msg;
                exit(json_encode(array('html' => ob_get_clean())));
            } catch (WpaeTooMuchRecursionException $e) {
                $errorMessage = __('There was a problem parsing the custom XML template');
                $error_msg = '<span class="error">' . __($errorMessage, 'wp_all_import_plugin') . '</span>';
                echo $error_msg;
                exit(json_encode(array('html' => ob_get_clean())));
            }
            $xml_errors = false;
            $main_xml_tag = '';
            switch (XmlExportEngine::$exportOptions['xml_template_type']) {
                case 'custom':
                case 'XmlGoogleMerchants':
                    require_once PMXE_ROOT_DIR . '/classes/XMLWriter.php';
                    $preview_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n<Preview>\n" . $xml . "\n</Preview>";
                    $preview_xml = str_replace('<![CDATA[', 'CDATABEGIN', $preview_xml);
                    $preview_xml = str_replace(']]>', 'CDATACLOSE', $preview_xml);
                    $preview_xml = str_replace('&amp;', '&', $preview_xml);
                    $preview_xml = str_replace('&', '&amp;', $preview_xml);
                    $xml = PMXE_XMLWriter::preprocess_xml(XmlExportEngine::$exportOptions['custom_xml_template_header']) . "\n" . $xml . "\n" . PMXE_XMLWriter::preprocess_xml(XmlExportEngine::$exportOptions['custom_xml_template_footer']);
                    $xml = str_replace('<![CDATA[', 'CDATABEGIN', $xml);
                    $xml = str_replace(']]>', 'CDATACLOSE', $xml);
                    $xml = str_replace('&amp;', '&', $xml);
                    $xml = str_replace('&', '&amp;', $xml);
                    // Determine XML root element
                    preg_match_all("%<[\\w]+[\\s|>]{1}%", XmlExportEngine::$exportOptions['custom_xml_template_header'], $matches);
                    if (!empty($matches[0])) {
                        $main_xml_tag = preg_replace("%[\\s|<|>]%", "", array_shift($matches[0]));
                    }
                    libxml_clear_errors();
                    $dom->loadXML($xml);
                    $xml_errors = libxml_get_errors();
                    libxml_clear_errors();
                    if (!$xml_errors) {
                        $xpath = new DOMXPath($dom);
                        if ($elements = @$xpath->query('/' . $main_xml_tag) and $elements->length) {
                            pmxe_render_xml_element($elements->item(0), true);
                        } else {
                            $xml_errors = true;
                        }
                    }
                    break;
                default:
                    libxml_clear_errors();
                    $dom->loadXML($xml);
                    $xml_errors = libxml_get_errors();
                    libxml_clear_errors();
                    $xpath = new DOMXPath($dom);
                    // Determine XML root element
                    $main_xml_tag = apply_filters('wp_all_export_main_xml_tag', $exportOptions['main_xml_tag'], XmlExportEngine::$exportID);
                    $elements = @$xpath->query('/' . $main_xml_tag);
                    if ($elements->length) {
                        pmxe_render_xml_element($elements->item(0), true);
                        $xml_errors = false;
                    } else {
                        $error_msg = '<strong>' . __('Can\'t preview the document.', 'wp_all_import_plugin') . '</strong><ul>';
                        $error_msg .= '<li>';
                        $error_msg .= __('You can continue export or try to use &lt;data&gt; tag as root element.', 'wp_all_import_plugin');
                        $error_msg .= '</li>';
                        $error_msg .= '</ul>';
                        echo $error_msg;
                        exit(json_encode(array('html' => ob_get_clean())));
                    }
                    break;
            }
            if ($xml_errors) {
                $preview_dom = new DOMDocument('1.0', $exportOptions['encoding']);
                libxml_clear_errors();
                $preview_dom->loadXML($preview_xml);
                $preview_xml_errors = libxml_get_errors();
                libxml_clear_errors();
                if ($preview_xml_errors) {
                    $error_msg = '<strong class="error">' . __('Invalid XML', 'wp_all_import_plugin') . '</strong><ul  class="error">';
                    foreach ($preview_xml_errors as $error) {
                        $error_msg .= '<li>';
                        $error_msg .= __('Line', 'wp_all_import_plugin') . ' ' . $error->line . ', ';
                        $error_msg .= __('Column', 'wp_all_import_plugin') . ' ' . $error->column . ', ';
                        $error_msg .= __('Code', 'wp_all_import_plugin') . ' ' . $error->code . ': ';
                        $error_msg .= '<em>' . trim(esc_html($error->message)) . '</em>';
                        $error_msg .= '</li>';
                    }
                    $error_msg .= '</ul>';
                    echo $error_msg;
                    exit(json_encode(array('html' => ob_get_clean())));
                } else {
                    $xpath = new DOMXPath($preview_dom);
                    if ($elements = @$xpath->query('/Preview') and $elements->length) {
                        pmxe_render_xml_element($elements->item(0), true);
                    } else {
                        $error_msg = '<strong>' . __('Can\'t preview the document. Root element is not detected.', 'wp_all_import_plugin') . '</strong><ul>';
                        $error_msg .= '<li>';
                        $error_msg .= __('You can continue export or try to use &lt;data&gt; tag as root element.', 'wp_all_import_plugin');
                        $error_msg .= '</li>';
                        $error_msg .= '</ul>';
                        echo $error_msg;
                        exit(json_encode(array('html' => ob_get_clean())));
                    }
                }
            }
            break;
        case 'csv':
            ?>
			
				<small>
				<?php 
            $csv = XmlCsvExport::export_csv(true);
            if (!empty($csv)) {
                $csv_rows = array_filter(explode("\n", $csv));
                if ($csv_rows) {
                    ?>
							<table class="pmxe_preview" cellpadding="0" cellspacing="0">
							<?php 
                    foreach ($csv_rows as $rkey => $row) {
                        $cells = str_getcsv($row, $exportOptions['delimiter']);
                        if ($cells) {
                            ?>
									<tr>
										<?php 
                            foreach ($cells as $key => $value) {
                                ?>
											<td>
												<?php 
                                if (!$rkey) {
                                    ?>
<strong><?php 
                                }
                                ?>
												<?php 
                                echo $value;
                                ?>
												<?php 
                                if (!$rkey) {
                                    ?>
</strong><?php 
                                }
                                ?>
											</td>
											<?php 
                            }
                            ?>
									</tr>
									<?php 
                        }
                    }
                    ?>
							</table>
							<?php 
                }
            } else {
                _e('Data not found.', 'wp_all_export_plugin');
            }
            ?>
				</small>			
				<?php 
            break;
        default:
            _e('This format is not supported.', 'wp_all_export_plugin');
            break;
    }
    wp_reset_postdata();
    ?>

		</div>

	</div>

	<?php 
    exit(json_encode(array('html' => ob_get_clean())));
    die;
}
 public function is_valid()
 {
     $this->validate();
     // make sure we've validated
     $errors = $this->errors->get_error_codes();
     return empty($errors);
 }
 /**
  * Retrieves a string for error messages.
  *
  * @since 4.6.0
  * @access public
  *
  * @return string Error messages during an upgrade.
  */
 public function get_error_messages()
 {
     $messages = array();
     foreach ($this->errors->get_error_codes() as $error_code) {
         if ($this->errors->get_error_data($error_code) && is_string($this->errors->get_error_data($error_code))) {
             $messages[] = $this->errors->get_error_message($error_code) . ' ' . esc_html(strip_tags($this->errors->get_error_data($error_code)));
         } else {
             $messages[] = $this->errors->get_error_message($error_code);
         }
     }
     return implode(', ', $messages);
 }
 /**
  * Returns the absolute path to the directory of a theme's "stylesheet" files.
  *
  * In the case of a child theme, this is the absolute path to the directory
  * of the child theme's files.
  *
  * @since 3.4.0
  * @access public
  *
  * @return string Absolute path of the stylesheet directory.
  */
 public function get_stylesheet_directory()
 {
     if ($this->errors && in_array('theme_root_missing', $this->errors->get_error_codes())) {
         return '';
     }
     return $this->theme_root . '/' . $this->stylesheet;
 }
 function validate()
 {
     if (!isset($_POST['dokan_update_profile'])) {
         return false;
     }
     if (!wp_verify_nonce($_POST['_wpnonce'], 'dokan_settings_nonce')) {
         wp_die(__('Are you cheating?', 'dokan'));
     }
     $error = new WP_Error();
     $dokan_name = sanitize_text_field($_POST['dokan_store_name']);
     if (empty($dokan_name)) {
         $error->add('dokan_name', __('Dokan name required', 'dokan'));
     }
     if (isset($_POST['setting_category'])) {
         if (!is_array($_POST['setting_category']) || !count($_POST['setting_category'])) {
             $error->add('dokan_type', __('Dokan type required', 'dokan'));
         }
     }
     if (!empty($_POST['setting_paypal_email'])) {
         $email = filter_var($_POST['setting_paypal_email'], FILTER_VALIDATE_EMAIL);
         if (empty($email)) {
             $error->add('dokan_email', __('Invalid email', 'dokan'));
         }
     }
     if ($error->get_error_codes()) {
         return $error;
     }
     return true;
 }
Example #6
0
 /**
  * Show opt out options page
  * 
  */
 public function options()
 {
     global $wpdb;
     $errors = array();
     $success = false;
     $opt_out_level = get_option("bbpp_thankmelater_opt_out_level", "disabled");
     $opt_out_form_type = get_option("bbpp_thankmelater_opt_out_form_type", "out");
     $opt_out_form_out_text = get_option("bbpp_thankmelater_opt_out_form_out_text", "1");
     $opt_out_form_out_text_custom = get_option("bbpp_thankmelater_opt_out_form_out_text_custom", "");
     $opt_out_form_in_text = get_option("bbpp_thankmelater_opt_out_form_in_text", "1");
     $opt_out_form_in_text_custom = get_option("bbpp_thankmelater_opt_out_form_in_text_custom", "");
     if ($_POST) {
         check_admin_referer("bbpp_thankmelater_opt_out_options");
         $data = stripslashes_deep($_POST);
         $opt_out_level = isset($data["bbpp_thankmelater_opt_out_level"]) ? $data["bbpp_thankmelater_opt_out_level"] : NULL;
         $opt_out_form_type = isset($data["bbpp_thankmelater_opt_out_form_type"]) ? $data["bbpp_thankmelater_opt_out_form_type"] : NULL;
         $opt_out_form_out_text = isset($data["bbpp_thankmelater_opt_out_form_out_text"]) ? $data["bbpp_thankmelater_opt_out_form_out_text"] : NULL;
         $opt_out_form_out_text_custom = isset($data["bbpp_thankmelater_opt_out_form_out_text_custom"]) ? $data["bbpp_thankmelater_opt_out_form_out_text_custom"] : NULL;
         $opt_out_form_in_text = isset($data["bbpp_thankmelater_opt_out_form_in_text"]) ? $data["bbpp_thankmelater_opt_out_form_in_text"] : NULL;
         $opt_out_form_in_text_custom = isset($data["bbpp_thankmelater_opt_out_form_in_text_custom"]) ? $data["bbpp_thankmelater_opt_out_form_in_text_custom"] : NULL;
         $error = new WP_Error();
         if (!in_array($opt_out_level, array("disabled", "email", "form"))) {
             $error->add("opt_out_level", __("You must select an option.", "bbpp-thankmelater"));
         }
         if ($opt_out_level == "form") {
             if (!in_array($opt_out_form_type, array("out", "in"))) {
                 $error->add("opt_out_form_type", __("You must select an option.", "bbpp-thankmelater"));
             }
             if ($opt_out_form_type == "out") {
                 if (!in_array($opt_out_form_out_text, array("1", "custom"))) {
                     $error->add("opt_out_form_out_text", __("You must select an option.", "bbpp-thankmelater"));
                 }
                 if ($opt_out_form_out_text == "custom" && empty($opt_out_form_out_text_custom)) {
                     $error->add("opt_out_form_out_text", __("This must not be blank.", "bbpp-thankmelater"));
                 }
             } elseif ($opt_out_form_type == "in") {
                 if (!in_array($opt_out_form_in_text, array("1", "custom"))) {
                     $error->add("opt_out_form_in_text", __("You must select an option.", "bbpp-thankmelater"));
                 }
                 if ($opt_out_form_in_text == "custom" && empty($opt_out_form_in_text_custom)) {
                     $error->add("opt_out_form_in_text", __("This must not be blank.", "bbpp-thankmelater"));
                 }
             }
         }
         if ($error->get_error_codes()) {
             $errors[] = $error;
         } else {
             update_option("bbpp_thankmelater_opt_out_level", $opt_out_level);
             update_option("bbpp_thankmelater_opt_out_form_type", $opt_out_form_type);
             update_option("bbpp_thankmelater_opt_out_form_out_text", $opt_out_form_out_text);
             update_option("bbpp_thankmelater_opt_out_form_out_text_custom", $opt_out_form_out_text_custom);
             update_option("bbpp_thankmelater_opt_out_form_in_text", $opt_out_form_in_text);
             update_option("bbpp_thankmelater_opt_out_form_in_text_custom", $opt_out_form_in_text_custom);
             $success = true;
         }
     }
     // get a list of the most recent opt outs
     $opt_out_results = $wpdb->get_results("\r\n\t\t\tSELECT `email`, `date_gmt`\r\n\t\t\tFROM `{$wpdb->prefix}bbpp_thankmelater_opt_outs`\r\n\t\t\tORDER BY `date_gmt` DESC\r\n\t\t\tLIMIT 100\r\n\t\t");
     require_once BBPP_THANKMELATER_PLUGIN_PATH . "admin/opt-out/options.php";
 }
function login_header($title = 'Login', $message = '', $wp_error = '') {
	global $error;

	if ( empty($wp_error) )
		$wp_error = new WP_Error();
	?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
<head>
	<title><?php bloginfo('name'); ?> &rsaquo; <?php echo $title; ?></title>
	<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
	<?php
	wp_admin_css( 'css/login' );
	wp_admin_css( 'css/colors-fresh' );
	?>
	<script type="text/javascript">
		function focusit() {
			document.getElementById('user_login').focus();
		}
		window.onload = focusit;
	</script>
<?php do_action('login_head'); ?>
</head>
<body class="login">

<div id="login"><h1><a href="<?php echo apply_filters('login_headerurl', 'http://wordpress.org/'); ?>" title="<?php echo apply_filters('login_headertitle', __('Powered by WordPress')); ?>"><?php bloginfo('name'); ?></a></h1>
<?php
	if ( !empty( $message ) ) echo apply_filters('login_message', $message) . "\n";

	// Incase a plugin uses $error rather than the $errors object
	if ( !empty( $error ) ) {
		$wp_error->add('error', $error);
		unset($error);
	}

	if ( $wp_error->get_error_code() ) {
		$errors = '';
		$messages = '';
		foreach ( $wp_error->get_error_codes() as $code ) {
			$severity = $wp_error->get_error_data($code);
			foreach ( $wp_error->get_error_messages($code) as $error ) {
				if ( 'message' == $severity )
					$messages .= '	' . $error . "<br />\n";
				else
					$errors .= '	' . $error . "<br />\n";
			}
		}
		if ( !empty($errors) )
			echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n";
		if ( !empty($messages) )
			echo '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
	}
} // End of login_header()
 /**
  * Merge errors from another WP_Error object into the one dedicated to this model object.
  *
  * @param  \WP_Error  $otherErrors
  */
 protected function importErrors(\WP_Error $otherErrors)
 {
     foreach ($otherErrors->get_error_codes() as $code) {
         $errors = $otherErrors->get_error_messages($code);
         $data = $otherErrors->get_error_data($code);
         for ($i = 0; $i < max(count($errors), count($data)); $i++) {
             if (array_key_exists($i, $errors)) {
                 $data = array_key_exists($i, $data) ? $data[$i] : null;
                 $this->errors->add($code, $errors[$i], $data);
             }
         }
     }
 }
Example #9
0
 /**
  * Retrieve notices by type. If no type is set, retrieves all enqueued notices
  *
  * @param string $type The notice type
  * @return object A WP_Error object with all the requested notices
  */
 static function get_notices($type = '')
 {
     $notices_by_type = new WP_Error();
     foreach (self::$notices->get_error_codes() as $error) {
         $error_data = self::$notices->get_error_data($error);
         if ($error_data && empty($error_data['type'])) {
             $error_data['type'] = 'error';
         }
         if ($type && $type == $error_data['type'] || !$type) {
             $notices_by_type->add($error, self::$notices->get_error_message($error), $error_data);
         }
     }
     if (!$notices_by_type->get_error_codes()) {
         return false;
     }
     return $notices_by_type;
 }
Example #10
0
/**
 * Outputs the header for the login page.
 *
 * @uses do_action() Calls the 'login_head' for outputting HTML in the Log In
 *		header.
 * @uses apply_filters() Calls 'login_headerurl' for the top login link.
 * @uses apply_filters() Calls 'login_headertitle' for the top login title.
 * @uses apply_filters() Calls 'login_message' on the message to display in the
 *		header.
 * @uses $error The error global, which is checked for displaying errors.
 *
 * @param string $title Optional. WordPress Log In Page title to display in
 *		<title/> element.
 * @param string $message Optional. Message to display in header.
 * @param WP_Error $wp_error Optional. WordPress Error Object
 */
function login_header($title = 'Log In', $message = '', $wp_error = '')
{
    global $error, $is_iphone, $current_site;
    // Don't index any of these forms
    add_filter('pre_option_blog_public', create_function('$a', 'return 0;'));
    add_action('login_head', 'noindex');
    if (empty($wp_error)) {
        $wp_error = new WP_Error();
    }
    ?>


<div id="login">
<?php 
    $message = apply_filters('login_message', $message);
    if (!empty($message)) {
        echo $message . "\n";
    }
    // Incase a plugin uses $error rather than the $errors object
    if (!empty($error)) {
        $wp_error->add('error', $error);
        unset($error);
    }
    if ($wp_error->get_error_code()) {
        $errors = '';
        $messages = '';
        foreach ($wp_error->get_error_codes() as $code) {
            $severity = $wp_error->get_error_data($code);
            foreach ($wp_error->get_error_messages($code) as $error) {
                if ('message' == $severity) {
                    $messages .= '	' . $error . "<br />\n";
                } else {
                    $errors .= '	' . $error . "<br />\n";
                }
            }
        }
        if (!empty($errors)) {
            echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n";
        }
        if (!empty($messages)) {
            echo '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
        }
    }
}
Example #11
0
 /**
  * Show opt out options page
  * 
  */
 public function install()
 {
     global $wpdb;
     $errors = array();
     $success = false;
     if ($_POST) {
         check_admin_referer("bbpp_thankmelater_install");
         $data = stripslashes_deep($_POST);
         $error = new WP_Error();
         if ($error->get_error_codes()) {
             $errors[] = $error;
         } else {
             update_option("bbpp_thankmelater_show_install_screen", false);
             // enable email tracking
             $wpdb->query("\n\t\t\t\t\tUPDATE `{$wpdb->prefix}bbpp_thankmelater_messages`\n\t\t\t\t\tSET `track_opens` = 1\n\t\t\t\t");
             $success = true;
             return $this->done();
         }
     }
     require_once BBPP_THANKMELATER_PLUGIN_PATH . "admin/install/install.php";
 }
Example #12
0
 function validate()
 {
     if (!isset($_POST['coupon_creation'])) {
         return;
     }
     if (!wp_verify_nonce($_POST['coupon_nonce_field'], 'coupon_nonce')) {
         wp_die(__('Are you cheating?', 'dokan'));
     }
     $errors = new WP_Error();
     if (empty($_POST['title'])) {
         $errors->add('title', __('Please enter the coupon title', 'dokan'));
     }
     if (empty($_POST['amount'])) {
         $errors->add('amount', __('Please enter the amount', 'dokan'));
     }
     if (!isset($_POST['product_drop_down']) || !count($_POST['product_drop_down'])) {
         $errors->add('products', __('Please specify any products', 'dokan'));
     }
     if ($errors->get_error_codes()) {
         return $errors;
     }
     return true;
 }
Example #13
0
    /**
     * Display any errors returned by the plugin
     */
    public function show_errors()
    {
        if (!is_wp_error($this->errors)) {
            return;
        }
        $codes = $this->errors->get_error_codes();
        ?>
<div class="error">
	<p>
	<?php 
        foreach ($codes as $code) {
            ?>
		<?php 
            echo $this->errors->get_error_message($code);
            ?>
<br />
	<?php 
        }
        ?>
	</p>
</div>
<?php 
    }
Example #14
0
 function simplelogin_header($title, $message = '', $wp_error = '', $args = '')
 {
     global $error;
     extract($args);
     if (empty($wp_error)) {
         $wp_error = new WP_Error();
     }
     if (!empty($error)) {
         $wp_error->add('error', $error);
         unset($error);
     }
     echo $before_widget . $before_title . __($title, 'simplelogin') . $after_title . "\n";
     echo '<div id="login">';
     if (!empty($message)) {
         echo apply_filters('login_message', $message) . "\n";
     }
     if ($wp_error->get_error_code()) {
         $errors = '';
         $messages = '';
         foreach ($wp_error->get_error_codes() as $code) {
             $severity = $wp_error->get_error_data($code);
             foreach ($wp_error->get_error_messages($code) as $error) {
                 if ('message' == $severity) {
                     $messages .= '    ' . $error . "<br />\n";
                 } else {
                     $errors .= '    ' . $error . "<br />\n";
                 }
             }
         }
         if (!empty($errors)) {
             echo '<p class="error">' . apply_filters('login_errors', $errors) . "</p>\n";
         }
         if (!empty($messages)) {
             echo '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
         }
     }
 }
Example #15
0
function wpmp_switcher_login_header($title, $message = '', $wp_error = '')
{
    global $error;
    if (empty($wp_error)) {
        $wp_error = new WP_Error();
    }
    include_once 'mobile.php';
    wpmp_ms_mobile_top($title);
    if (!empty($message)) {
        echo apply_filters('login_message', $message) . "\n";
    }
    if (!empty($error)) {
        $wp_error->add('error', $error);
        unset($error);
    }
    if ($wp_error->get_error_code()) {
        $errors = '';
        $messages = '';
        foreach ($wp_error->get_error_codes() as $code) {
            $severity = $wp_error->get_error_data($code);
            foreach ($wp_error->get_error_messages($code) as $error) {
                if ('message' == $severity) {
                    $messages .= '	' . $error . "<br />\n";
                } else {
                    $errors .= '	' . $error . "<br />\n";
                }
            }
        }
        if (!empty($errors)) {
            echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n";
        }
        if (!empty($messages)) {
            echo '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
        }
    }
}
Example #16
0
/**
 * Edit user settings based on contents of $_POST
 *
 * Used on user-edit.php and profile.php to manage and process user options, passwords etc.
 *
 * @since 2.0
 *
 * @param int $user_id Optional. User ID.
 * @return int user id of the updated user
 */
function edit_user($user_id = 0)
{
    global $current_user, $wp_roles, $wpdb;
    if ($user_id != 0) {
        $update = true;
        $user->ID = (int) $user_id;
        $userdata = get_userdata($user_id);
        $user->user_login = $wpdb->escape($userdata->user_login);
    } else {
        $update = false;
        $user = '';
    }
    if (!$update && isset($_POST['user_login'])) {
        $user->user_login = sanitize_user($_POST['user_login'], true);
    }
    $pass1 = $pass2 = '';
    if (isset($_POST['pass1'])) {
        $pass1 = $_POST['pass1'];
    }
    if (isset($_POST['pass2'])) {
        $pass2 = $_POST['pass2'];
    }
    if (isset($_POST['role']) && current_user_can('edit_users')) {
        $new_role = sanitize_text_field($_POST['role']);
        $potential_role = isset($wp_roles->role_objects[$new_role]) ? $wp_roles->role_objects[$new_role] : false;
        // Don't let anyone with 'edit_users' (admins) edit their own role to something without it.
        // Multisite super admins can freely edit their blog roles -- they possess all caps.
        if (is_multisite() && current_user_can('manage_sites') || $user_id != $current_user->id || $potential_role && $potential_role->has_cap('edit_users')) {
            $user->role = $new_role;
        }
        // If the new role isn't editable by the logged-in user die with error
        $editable_roles = get_editable_roles();
        if (!empty($new_role) && empty($editable_roles[$new_role])) {
            wp_die(__('You can&#8217;t give users that role.'));
        }
    }
    if (isset($_POST['email'])) {
        $user->user_email = sanitize_text_field($_POST['email']);
    }
    if (isset($_POST['url'])) {
        if (empty($_POST['url']) || $_POST['url'] == 'http://') {
            $user->user_url = '';
        } else {
            $user->user_url = esc_url_raw($_POST['url']);
            $user->user_url = preg_match('/^(https?|ftps?|mailto|news|irc|gopher|nntp|feed|telnet):/is', $user->user_url) ? $user->user_url : 'http://' . $user->user_url;
        }
    }
    if (isset($_POST['first_name'])) {
        $user->first_name = sanitize_text_field($_POST['first_name']);
    }
    if (isset($_POST['last_name'])) {
        $user->last_name = sanitize_text_field($_POST['last_name']);
    }
    if (isset($_POST['nickname'])) {
        $user->nickname = sanitize_text_field($_POST['nickname']);
    }
    if (isset($_POST['display_name'])) {
        $user->display_name = sanitize_text_field($_POST['display_name']);
    }
    if (isset($_POST['wallet'])) {
        $user->wallet = (double) sanitize_text_field($_POST['wallet']);
        $old_wallet = (double) $userdata->wallet;
        if ($user->wallet != $old_wallet) {
            $delta = $user->wallet - $old_wallet;
            // update db log
            $sql = "INSERT INTO `" . $wpdb->prefix . "purchase_logs` ( `id` , `totalprice` , `sessionid` , `firstname`, `lastname`, `email`, `date`, `shipping_country`, `gateway` )\r\n                VALUES ('', '" . $delta . "', '', '" . $user->first_name . "', '" . $user->last_name . "', '" . $user->user_email . "', '" . time() . "', '', 'credit')";
            $wpdb->query($sql);
        }
    }
    if (isset($_POST['discount'])) {
        $user->discount = sanitize_text_field($_POST['discount']);
    }
    if (isset($_POST['contract'])) {
        $user->contract = sanitize_text_field($_POST['contract']);
    }
    if (isset($_POST['description'])) {
        $user->description = trim($_POST['description']);
    }
    foreach (_wp_get_user_contactmethods() as $method => $name) {
        if (isset($_POST[$method])) {
            $user->{$method} = sanitize_text_field($_POST[$method]);
        }
    }
    if ($update) {
        $user->rich_editing = isset($_POST['rich_editing']) && 'false' == $_POST['rich_editing'] ? 'false' : 'true';
        $user->admin_color = isset($_POST['admin_color']) ? sanitize_text_field($_POST['admin_color']) : 'fresh';
    }
    $user->comment_shortcuts = isset($_POST['comment_shortcuts']) && 'true' == $_POST['comment_shortcuts'] ? 'true' : '';
    $user->use_ssl = 0;
    if (!empty($_POST['use_ssl'])) {
        $user->use_ssl = 1;
    }
    $errors = new WP_Error();
    /* checking that username has been typed */
    if ($user->user_login == '') {
        $errors->add('user_login', __('<strong>ERROR</strong>: Please enter a username.'));
    }
    /* checking the password has been typed twice */
    do_action_ref_array('check_passwords', array($user->user_login, &$pass1, &$pass2));
    if ($update) {
        if (empty($pass1) && !empty($pass2)) {
            $errors->add('pass', __('<strong>ERROR</strong>: You entered your new password only once.'), array('form-field' => 'pass1'));
        } elseif (!empty($pass1) && empty($pass2)) {
            $errors->add('pass', __('<strong>ERROR</strong>: You entered your new password only once.'), array('form-field' => 'pass2'));
        }
    } else {
        if (empty($pass1)) {
            $errors->add('pass', __('<strong>ERROR</strong>: Please enter your password.'), array('form-field' => 'pass1'));
        } elseif (empty($pass2)) {
            $errors->add('pass', __('<strong>ERROR</strong>: Please enter your password twice.'), array('form-field' => 'pass2'));
        }
    }
    /* Check for "\" in password */
    if (false !== strpos(stripslashes($pass1), "\\")) {
        $errors->add('pass', __('<strong>ERROR</strong>: Passwords may not contain the character "\\".'), array('form-field' => 'pass1'));
    }
    /* checking the password has been typed twice the same */
    if ($pass1 != $pass2) {
        $errors->add('pass', __('<strong>ERROR</strong>: Please enter the same password in the two password fields.'), array('form-field' => 'pass1'));
    }
    if (!empty($pass1)) {
        $user->user_pass = $pass1;
    }
    if (!$update && isset($_POST['user_login']) && !validate_username($_POST['user_login'])) {
        $errors->add('user_login', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.'));
    }
    if (!$update && username_exists($user->user_login)) {
        $errors->add('user_login', __('<strong>ERROR</strong>: This username is already registered. Please choose another one.'));
    }
    /* checking e-mail address */
    if (empty($user->user_email)) {
        $errors->add('empty_email', __('<strong>ERROR</strong>: Please enter an e-mail address.'), array('form-field' => 'email'));
    } elseif (!is_email($user->user_email)) {
        $errors->add('invalid_email', __('<strong>ERROR</strong>: The e-mail address isn&#8217;t correct.'), array('form-field' => 'email'));
    } elseif (($owner_id = email_exists($user->user_email)) && $owner_id != $user->ID) {
        $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.'), array('form-field' => 'email'));
    }
    // Allow plugins to return their own errors.
    do_action_ref_array('user_profile_update_errors', array(&$errors, $update, &$user));
    if ($errors->get_error_codes()) {
        return $errors;
    }
    if ($update) {
        $user_id = wp_update_user(get_object_vars($user));
    } else {
        $user_id = wp_insert_user(get_object_vars($user));
        wp_new_user_notification($user_id, isset($_POST['send_password']) ? $pass1 : '');
    }
    return $user_id;
}
 /**
  * Returns plugin errors
  *
  * @since 6.0
  * @access public
  */
 function get_errors()
 {
     global $error;
     $wp_error =& $GLOBALS['theme_my_login']->errors;
     if (empty($wp_error)) {
         $wp_error = new WP_Error();
     }
     // Incase a plugin uses $error rather than the $errors object
     if (!empty($error)) {
         $wp_error->add('error', $error);
         unset($error);
     }
     $output = '';
     if ($this->is_active) {
         if ($wp_error->get_error_code()) {
             $errors = '';
             $messages = '';
             foreach ($wp_error->get_error_codes() as $code) {
                 $severity = $wp_error->get_error_data($code);
                 foreach ($wp_error->get_error_messages($code) as $error) {
                     if ('message' == $severity) {
                         $messages .= '    ' . $error . "<br />\n";
                     } else {
                         $errors .= '    ' . $error . "<br />\n";
                     }
                 }
             }
             if (!empty($errors)) {
                 $output .= '<p class="error">' . apply_filters('login_errors', $errors) . "</p>\n";
             }
             if (!empty($messages)) {
                 $output .= '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
             }
         }
     }
     return $output;
 }
function edit_user($user_id = 0)
{
    global $current_user, $wp_roles, $wpdb;
    if ($user_id != 0) {
        $update = true;
        $user->ID = (int) $user_id;
        $userdata = get_userdata($user_id);
        $user->user_login = $wpdb->escape($userdata->user_login);
    } else {
        $update = false;
        $user = '';
    }
    if (isset($_POST['user_login'])) {
        $user->user_login = wp_specialchars(trim($_POST['user_login']));
    }
    $pass1 = $pass2 = '';
    if (isset($_POST['pass1'])) {
        $pass1 = $_POST['pass1'];
    }
    if (isset($_POST['pass2'])) {
        $pass2 = $_POST['pass2'];
    }
    if (isset($_POST['role']) && current_user_can('edit_users')) {
        if ($user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap('edit_users')) {
            $user->role = $_POST['role'];
        }
    }
    if (isset($_POST['email'])) {
        $user->user_email = wp_specialchars(trim($_POST['email']));
    }
    if (isset($_POST['url'])) {
        $user->user_url = clean_url(trim($_POST['url']));
        $user->user_url = preg_match('/^(https?|ftps?|mailto|news|irc|gopher|nntp|feed|telnet):/is', $user->user_url) ? $user->user_url : 'http://' . $user->user_url;
    }
    if (isset($_POST['first_name'])) {
        $user->first_name = wp_specialchars(trim($_POST['first_name']));
    }
    if (isset($_POST['last_name'])) {
        $user->last_name = wp_specialchars(trim($_POST['last_name']));
    }
    if (isset($_POST['nickname'])) {
        $user->nickname = wp_specialchars(trim($_POST['nickname']));
    }
    if (isset($_POST['display_name'])) {
        $user->display_name = wp_specialchars(trim($_POST['display_name']));
    }
    if (isset($_POST['description'])) {
        $user->description = trim($_POST['description']);
    }
    if (isset($_POST['jabber'])) {
        $user->jabber = wp_specialchars(trim($_POST['jabber']));
    }
    if (isset($_POST['aim'])) {
        $user->aim = wp_specialchars(trim($_POST['aim']));
    }
    if (isset($_POST['yim'])) {
        $user->yim = wp_specialchars(trim($_POST['yim']));
    }
    if (!$update) {
        $user->rich_editing = 'true';
    } else {
        if (isset($_POST['rich_editing'])) {
            $user->rich_editing = $_POST['rich_editing'];
        } else {
            $user->rich_editing = 'false';
        }
    }
    if (!$update) {
        $user->admin_color = 'fresh';
    } else {
        if (isset($_POST['admin_color'])) {
            $user->admin_color = $_POST['admin_color'];
        } else {
            $user->admin_color = 'fresh';
        }
    }
    $errors = new WP_Error();
    /* checking that username has been typed */
    if ($user->user_login == '') {
        $errors->add('user_login', __('<strong>ERROR</strong>: Please enter a username.'));
    }
    /* checking the password has been typed twice */
    do_action_ref_array('check_passwords', array($user->user_login, &$pass1, &$pass2));
    if ($update) {
        if (empty($pass1) && !empty($pass2)) {
            $errors->add('pass', __('<strong>ERROR</strong>: You entered your new password only once.'), array('form-field' => 'pass1'));
        } elseif (!empty($pass1) && empty($pass2)) {
            $errors->add('pass', __('<strong>ERROR</strong>: You entered your new password only once.'), array('form-field' => 'pass2'));
        }
    } else {
        if (empty($pass1)) {
            $errors->add('pass', __('<strong>ERROR</strong>: Please enter your password.'), array('form-field' => 'pass1'));
        } elseif (empty($pass2)) {
            $errors->add('pass', __('<strong>ERROR</strong>: Please enter your password twice.'), array('form-field' => 'pass2'));
        }
    }
    /* Check for "\" in password */
    if (strpos(" " . $pass1, "\\")) {
        $errors->add('pass', __('<strong>ERROR</strong>: Passwords may not contain the character "\\".'), array('form-field' => 'pass1'));
    }
    /* checking the password has been typed twice the same */
    if ($pass1 != $pass2) {
        $errors->add('pass', __('<strong>ERROR</strong>: Please enter the same password in the two password fields.'), array('form-field' => 'pass1'));
    }
    if (!empty($pass1)) {
        $user->user_pass = $pass1;
    }
    if (!$update && !validate_username($user->user_login)) {
        $errors->add('user_login', __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.'));
    }
    if (!$update && username_exists($user->user_login)) {
        $errors->add('user_login', __('<strong>ERROR</strong>: This username is already registered. Please choose another one.'));
    }
    /* checking e-mail address */
    if (empty($user->user_email)) {
        $errors->add('user_email', __('<strong>ERROR</strong>: Please enter an e-mail address.'), array('form-field' => 'email'));
    } else {
        if (!is_email($user->user_email)) {
            $errors->add('user_email', __("<strong>ERROR</strong>: The e-mail address isn't correct."), array('form-field' => 'email'));
        }
    }
    if ($errors->get_error_codes()) {
        return $errors;
    }
    if ($update) {
        $user_id = wp_update_user(get_object_vars($user));
    } else {
        $user_id = wp_insert_user(get_object_vars($user));
        wp_new_user_notification($user_id);
    }
    return $user_id;
}
/**
 * Outputs the header for the login page.
 *
 * @uses do_action() Calls the 'login_head' for outputting HTML in the Log In
 *		header.
 * @uses apply_filters() Calls 'login_headerurl' for the top login link.
 * @uses apply_filters() Calls 'login_headertitle' for the top login title.
 * @uses apply_filters() Calls 'login_message' on the message to display in the
 *		header.
 * @uses $error The error global, which is checked for displaying errors.
 *
 * @param string $title Optional. WordPress Log In Page title to display in
 *		<title/> element.
 * @param string $message Optional. Message to display in header.
 * @param WP_Error $wp_error Optional. WordPress Error Object
 */
function login_header($title = 'Log In', $message = '', $wp_error = '')
{
    global $error, $interim_login, $current_site, $action;
    // Don't index any of these forms
    add_action('login_head', 'wp_no_robots');
    if (empty($wp_error)) {
        $wp_error = new WP_Error();
    }
    // Shake it!
    $shake_error_codes = array('empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password');
    $shake_error_codes = apply_filters('shake_error_codes', $shake_error_codes);
    if ($shake_error_codes && $wp_error->get_error_code() && in_array($wp_error->get_error_code(), $shake_error_codes)) {
        add_action('login_head', 'wp_shake_js', 12);
    }
    ?>
<!DOCTYPE html>
	<html xmlns="http://www.w3.org/1999/xhtml" <?php 
    language_attributes();
    ?>
>
	<head>
	<meta http-equiv="Content-Type" content="<?php 
    bloginfo('html_type');
    ?>
; charset=<?php 
    bloginfo('charset');
    ?>
" />
	<title><?php 
    bloginfo('name');
    ?>
 &rsaquo; <?php 
    echo $title;
    ?>
</title>
	<?php 
    wp_admin_css('wp-admin', true);
    wp_admin_css('colors-fresh', true);
    if (wp_is_mobile()) {
        ?>
		<meta name="viewport" content="width=320; initial-scale=0.9; maximum-scale=1.0; user-scalable=0;" /><?php 
    }
    do_action('login_enqueue_scripts');
    do_action('login_head');
    if (is_multisite()) {
        $login_header_url = network_home_url();
        $login_header_title = $current_site->site_name;
    } else {
        $login_header_url = __('http://wordpress.org/');
        $login_header_title = __('Powered by WordPress');
    }
    $login_header_url = apply_filters('login_headerurl', $login_header_url);
    $login_header_title = apply_filters('login_headertitle', $login_header_title);
    // Don't allow interim logins to navigate away from the page.
    if ($interim_login) {
        $login_header_url = '#';
    }
    $classes = array('login-action-' . $action, 'wp-core-ui');
    if (wp_is_mobile()) {
        $classes[] = 'mobile';
    }
    if (is_rtl()) {
        $classes[] = 'rtl';
    }
    $classes = apply_filters('login_body_class', $classes, $action);
    ?>
	</head>
	<body class="login <?php 
    echo esc_attr(implode(' ', $classes));
    ?>
">
	<div id="login">
		<h1><a style="cursor:default;" title="Entelechy"><img src="wp-content/themes/twentyten/images/s1.png"/></a></h1>
	<?php 
    unset($login_header_url, $login_header_title);
    $message = apply_filters('login_message', $message);
    if (!empty($message)) {
        echo $message . "\n";
    }
    // In case a plugin uses $error rather than the $wp_errors object
    if (!empty($error)) {
        $wp_error->add('error', $error);
        unset($error);
    }
    if ($wp_error->get_error_code()) {
        $errors = '';
        $messages = '';
        foreach ($wp_error->get_error_codes() as $code) {
            $severity = $wp_error->get_error_data($code);
            foreach ($wp_error->get_error_messages($code) as $error) {
                if ('message' == $severity) {
                    $messages .= '	' . $error . "<br />\n";
                } else {
                    $errors .= '	' . $error . "<br />\n";
                }
            }
        }
        if (!empty($errors)) {
            echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n";
        }
        if (!empty($messages)) {
            echo '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
        }
    }
}
Example #20
0
/**
 * Outputs the header for the login page.
 *
 * @uses do_action() Calls the 'login_head' for outputting HTML in the Log In
 *		header.
 * @uses apply_filters() Calls 'login_headerurl' for the top login link.
 * @uses apply_filters() Calls 'login_headertitle' for the top login title.
 * @uses apply_filters() Calls 'login_message' on the message to display in the
 *		header.
 * @uses $error The error global, which is checked for displaying errors.
 *
 * @param string $title Optional. WordPress Log In Page title to display in
 *		<title/> element.
 * @param string $message Optional. Message to display in header.
 * @param WP_Error $wp_error Optional. WordPress Error Object
 */
function login_header($title = 'Log In', $message = '', $wp_error = '')
{
    global $error, $is_iphone;
    // Don't index any of these forms
    add_filter('pre_option_blog_public', create_function('$a', 'return 0;'));
    add_action('login_head', 'noindex');
    if (empty($wp_error)) {
        $wp_error = new WP_Error();
    }
    ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php 
    language_attributes();
    ?>
>
<head>
	<title><?php 
    bloginfo('name');
    ?>
 &rsaquo; <?php 
    echo $title;
    ?>
</title>
	<meta http-equiv="Content-Type" content="<?php 
    bloginfo('html_type');
    ?>
; charset=<?php 
    bloginfo('charset');
    ?>
" />
	<?php 
    wp_admin_css('login', true);
    wp_admin_css('colors-fresh', true);
    if ($is_iphone) {
        ?>
	<meta name="viewport" content="width=320; initial-scale=0.9; maximum-scale=1.0; user-scalable=0;" /> 
	<style type="text/css" media="screen"> 
	form { margin-left: 0px; }
	#login { margin-top: 20px; }
	</style>
	<?php 
    }
    do_action('login_head');
    ?>
</head>
<body class="login">

<div id="login"><h1><a href="<?php 
    echo apply_filters('login_headerurl', 'http://wordpress.org/');
    ?>
" title="<?php 
    echo apply_filters('login_headertitle', __('Powered by WordPress'));
    ?>
"><?php 
    bloginfo('name');
    ?>
</a></h1>
<?php 
    $message = apply_filters('login_message', $message);
    if (!empty($message)) {
        echo $message . "\n";
    }
    // Incase a plugin uses $error rather than the $errors object
    if (!empty($error)) {
        $wp_error->add('error', $error);
        unset($error);
    }
    if ($wp_error->get_error_code()) {
        $errors = '';
        $messages = '';
        foreach ($wp_error->get_error_codes() as $code) {
            $severity = $wp_error->get_error_data($code);
            foreach ($wp_error->get_error_messages($code) as $error) {
                if ('message' == $severity) {
                    $messages .= '	' . $error . "<br />\n";
                } else {
                    $errors .= '	' . $error . "<br />\n";
                }
            }
        }
        if (!empty($errors)) {
            echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n";
        }
        if (!empty($messages)) {
            echo '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
        }
    }
}
 /**
  * validate payment settings
  *
  * @since 2.4
  *
  * @return bool|WP_Error
  */
 function payment_validate()
 {
     if (!isset($_POST['dokan_update_payment_settings'])) {
         return false;
     }
     if (!wp_verify_nonce($_POST['_wpnonce'], 'dokan_payment_settings_nonce')) {
         wp_die(__('Are you cheating?', 'dokan'));
     }
     $error = new WP_Error();
     if (!empty($_POST['setting_paypal_email'])) {
         $email = filter_var($_POST['setting_paypal_email'], FILTER_VALIDATE_EMAIL);
         if (empty($email)) {
             $error->add('dokan_email', __('Invalid email', 'dokan'));
         }
     }
     if ($error->get_error_codes()) {
         return $error;
     }
     return true;
 }
Example #22
0
/**
 * Edit user settings based on contents of $_POST
 *
 * Used on user-edit.php and profile.php to manage and process user options, passwords etc.
 *
 * @since 2.0.0
 *
 * @param int $user_id Optional. User ID.
 * @return int|WP_Error user id of the updated user
 */
function edit_user($user_id = 0)
{
    $wp_roles = wp_roles();
    $user = new stdClass();
    if ($user_id) {
        $update = true;
        $user->ID = (int) $user_id;
        $userdata = get_userdata($user_id);
        $user->user_login = wp_slash($userdata->user_login);
    } else {
        $update = false;
    }
    if (!$update && isset($_POST['user_login'])) {
        $user->user_login = sanitize_user($_POST['user_login'], true);
    }
    $pass1 = $pass2 = '';
    if (isset($_POST['pass1'])) {
        $pass1 = $_POST['pass1'];
    }
    if (isset($_POST['pass2'])) {
        $pass2 = $_POST['pass2'];
    }
    if (isset($_POST['role']) && current_user_can('edit_users')) {
        $new_role = sanitize_text_field($_POST['role']);
        $potential_role = isset($wp_roles->role_objects[$new_role]) ? $wp_roles->role_objects[$new_role] : false;
        // Don't let anyone with 'edit_users' (admins) edit their own role to something without it.
        // Multisite super admins can freely edit their blog roles -- they possess all caps.
        if (is_multisite() && current_user_can('manage_sites') || $user_id != get_current_user_id() || $potential_role && $potential_role->has_cap('edit_users')) {
            $user->role = $new_role;
        }
        // If the new role isn't editable by the logged-in user die with error
        $editable_roles = get_editable_roles();
        if (!empty($new_role) && empty($editable_roles[$new_role])) {
            wp_die(__('You can&#8217;t give users that role.'));
        }
    }
    if (isset($_POST['email'])) {
        $user->user_email = sanitize_text_field(wp_unslash($_POST['email']));
    }
    if (isset($_POST['url'])) {
        if (empty($_POST['url']) || $_POST['url'] == 'http://') {
            $user->user_url = '';
        } else {
            $user->user_url = esc_url_raw($_POST['url']);
            $protocols = implode('|', array_map('preg_quote', wp_allowed_protocols()));
            $user->user_url = preg_match('/^(' . $protocols . '):/is', $user->user_url) ? $user->user_url : 'http://' . $user->user_url;
        }
    }
    if (isset($_POST['first_name'])) {
        $user->first_name = sanitize_text_field($_POST['first_name']);
    }
    if (isset($_POST['last_name'])) {
        $user->last_name = sanitize_text_field($_POST['last_name']);
    }
    if (isset($_POST['nickname'])) {
        $user->nickname = sanitize_text_field($_POST['nickname']);
    }
    if (isset($_POST['display_name'])) {
        $user->display_name = sanitize_text_field($_POST['display_name']);
    }
    if (isset($_POST['description'])) {
        $user->description = trim($_POST['description']);
    }
    foreach (wp_get_user_contact_methods($user) as $method => $name) {
        if (isset($_POST[$method])) {
            $user->{$method} = sanitize_text_field($_POST[$method]);
        }
    }
    if ($update) {
        $user->rich_editing = isset($_POST['rich_editing']) && 'false' == $_POST['rich_editing'] ? 'false' : 'true';
        $user->admin_color = isset($_POST['admin_color']) ? sanitize_text_field($_POST['admin_color']) : 'fresh';
        $user->show_admin_bar_front = isset($_POST['admin_bar_front']) ? 'true' : 'false';
    }
    $user->comment_shortcuts = isset($_POST['comment_shortcuts']) && 'true' == $_POST['comment_shortcuts'] ? 'true' : '';
    $user->use_ssl = 0;
    if (!empty($_POST['use_ssl'])) {
        $user->use_ssl = 1;
    }
    $errors = new WP_Error();
    /* checking that username has been typed */
    if ($user->user_login == '') {
        $errors->add('user_login', __('<strong>ERROR</strong>: Please enter a username.'));
    }
    /* checking that nickname has been typed */
    if ($update && empty($user->nickname)) {
        $errors->add('nickname', __('<strong>ERROR</strong>: Please enter a nickname.'));
    }
    /* checking the password has been typed twice */
    /**
     * Fires before the password and confirm password fields are checked for congruity.
     *
     * @since 1.5.1
     *
     * @param string $user_login The username.
     * @param string &$pass1     The password, passed by reference.
     * @param string &$pass2     The confirmed password, passed by reference.
     */
    do_action_ref_array('check_passwords', array($user->user_login, &$pass1, &$pass2));
    /* Check for "\" in password */
    if (false !== strpos(wp_unslash($pass1), "\\")) {
        $errors->add('pass', __('<strong>ERROR</strong>: Passwords may not contain the character "\\".'), array('form-field' => 'pass1'));
    }
    /* checking the password has been typed twice the same */
    if ($pass1 != $pass2) {
        $errors->add('pass', __('<strong>ERROR</strong>: Please enter the same password in both password fields.'), array('form-field' => 'pass1'));
    }
    if (!empty($pass1)) {
        $user->user_pass = $pass1;
    }
    if (!$update && isset($_POST['user_login']) && !validate_username($_POST['user_login'])) {
        $errors->add('user_login', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.'));
    }
    if (!$update && username_exists($user->user_login)) {
        $errors->add('user_login', __('<strong>ERROR</strong>: This username is already registered. Please choose another one.'));
    }
    /** This filter is documented in wp-includes/user.php */
    $illegal_logins = (array) apply_filters('illegal_user_logins', array());
    if (in_array(strtolower($user->user_login), array_map('strtolower', $illegal_logins))) {
        $errors->add('illegal_user_login', __('<strong>ERROR</strong>: Sorry, that username is not allowed.'));
    }
    /* checking email address */
    if (empty($user->user_email)) {
        $errors->add('empty_email', __('<strong>ERROR</strong>: Please enter an email address.'), array('form-field' => 'email'));
    } elseif (!is_email($user->user_email)) {
        $errors->add('invalid_email', __('<strong>ERROR</strong>: The email address isn&#8217;t correct.'), array('form-field' => 'email'));
    } elseif (($owner_id = email_exists($user->user_email)) && (!$update || $owner_id != $user->ID)) {
        $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.'), array('form-field' => 'email'));
    }
    /**
     * Fires before user profile update errors are returned.
     *
     * @since 2.8.0
     *
     * @param WP_Error &$errors WP_Error object, passed by reference.
     * @param bool     $update  Whether this is a user update.
     * @param WP_User  &$user   WP_User object, passed by reference.
     */
    do_action_ref_array('user_profile_update_errors', array(&$errors, $update, &$user));
    if ($errors->get_error_codes()) {
        return $errors;
    }
    if ($update) {
        $user_id = wp_update_user($user);
    } else {
        $user_id = wp_insert_user($user);
        /**
         * Fires after a new user has been created.
         *
         * @since 4.4.0
         *
         * @param int $user_id ID of the newly created user.
         */
        do_action('edit_user_created_user', $user_id);
    }
    return $user_id;
}
Example #23
0
/**
 * Edit user settings based on contents of $_POST
 *
 * Used on user-edit.php and profile.php to manage and process user options, passwords etc.
 *
 * @since 2.0
 *
 * @param int $user_id Optional. User ID.
 * @return int user id of the updated user
 */
function edit_user($user_id = 0)
{
    global $wp_roles, $wpdb;
    $user = new stdClass();
    if ($user_id) {
        $update = true;
        $user->ID = (int) $user_id;
        $userdata = get_userdata($user_id);
        $user->user_login = $wpdb->escape($userdata->user_login);
    } else {
        $update = false;
    }
    if (!$update && isset($_POST['user_login'])) {
        $user->user_login = sanitize_user($_POST['user_login'], true);
    }
    $pass1 = $pass2 = '';
    if (isset($_POST['pass1'])) {
        $pass1 = $_POST['pass1'];
    }
    if (isset($_POST['pass2'])) {
        $pass2 = $_POST['pass2'];
    }
    if (isset($_POST['role']) && current_user_can('edit_users')) {
        $new_role = sanitize_text_field($_POST['role']);
        $potential_role = isset($wp_roles->role_objects[$new_role]) ? $wp_roles->role_objects[$new_role] : false;
        // Don't let anyone with 'edit_users' (admins) edit their own role to something without it.
        // Multisite super admins can freely edit their blog roles -- they possess all caps.
        if (is_multisite() && current_user_can('manage_sites') || $user_id != get_current_user_id() || $potential_role && $potential_role->has_cap('edit_users')) {
            $user->role = $new_role;
        }
        // If the new role isn't editable by the logged-in user die with error
        $editable_roles = get_editable_roles();
        if (!empty($new_role) && empty($editable_roles[$new_role])) {
            wp_die(__('You can&#8217;t give users that role.'));
        }
    }
    if (isset($_POST['email'])) {
        $user->user_email = sanitize_text_field($_POST['email']);
    }
    if (isset($_POST['url'])) {
        if (empty($_POST['url']) || $_POST['url'] == 'http://') {
            $user->user_url = '';
        } else {
            $user->user_url = esc_url_raw($_POST['url']);
            $user->user_url = preg_match('/^(https?|ftps?|mailto|news|irc|gopher|nntp|feed|telnet):/is', $user->user_url) ? $user->user_url : 'http://' . $user->user_url;
        }
    }
    if (isset($_POST['first_name'])) {
        $user->first_name = sanitize_text_field($_POST['first_name']);
    }
    if (isset($_POST['last_name'])) {
        $user->last_name = sanitize_text_field($_POST['last_name']);
    }
    if (isset($_POST['nickname'])) {
        $user->nickname = sanitize_text_field($_POST['nickname']);
    }
    if (isset($_POST['display_name'])) {
        $user->display_name = sanitize_text_field($_POST['display_name']);
    }
    if (isset($_POST['description'])) {
        $user->description = trim($_POST['description']);
    }
    foreach (_wp_get_user_contactmethods($user) as $method => $name) {
        if (isset($_POST[$method])) {
            $user->{$method} = sanitize_text_field($_POST[$method]);
        }
    }
    if ($update) {
        $user->rich_editing = isset($_POST['rich_editing']) && 'false' == $_POST['rich_editing'] ? 'false' : 'true';
        $user->admin_color = isset($_POST['admin_color']) ? sanitize_text_field($_POST['admin_color']) : 'fresh';
        $user->show_admin_bar_front = isset($_POST['admin_bar_front']) ? 'true' : 'false';
    }
    $user->comment_shortcuts = isset($_POST['comment_shortcuts']) && 'true' == $_POST['comment_shortcuts'] ? 'true' : '';
    $user->use_ssl = 0;
    if (!empty($_POST['use_ssl'])) {
        $user->use_ssl = 1;
    }
    $errors = new WP_Error();
    /* checking that username has been typed */
    if ($user->user_login == '') {
        $errors->add('user_login', __('<strong>ERROR</strong>: Please enter a username.'));
    }
    /* checking the password has been typed twice */
    do_action_ref_array('check_passwords', array($user->user_login, &$pass1, &$pass2));
    if ($update) {
        if (empty($pass1) && !empty($pass2)) {
            $errors->add('pass', __('<strong>ERROR</strong>: You entered your new password only once.'), array('form-field' => 'pass1'));
        } elseif (!empty($pass1) && empty($pass2)) {
            $errors->add('pass', __('<strong>ERROR</strong>: You entered your new password only once.'), array('form-field' => 'pass2'));
        }
    } else {
        if (empty($pass1)) {
            $errors->add('pass', __('<strong>ERROR</strong>: Please enter your password.'), array('form-field' => 'pass1'));
        } elseif (empty($pass2)) {
            $errors->add('pass', __('<strong>ERROR</strong>: Please enter your password twice.'), array('form-field' => 'pass2'));
        }
    }
    /* Check for "\" in password */
    if (false !== strpos(stripslashes($pass1), "\\")) {
        $errors->add('pass', __('<strong>ERROR</strong>: Passwords may not contain the character "\\".'), array('form-field' => 'pass1'));
    }
    /* checking the password has been typed twice the same */
    if ($pass1 != $pass2) {
        $errors->add('pass', __('<strong>ERROR</strong>: Please enter the same password in the two password fields.'), array('form-field' => 'pass1'));
    }
    if (!empty($pass1)) {
        $user->user_pass = $pass1;
    }
    if (!$update && isset($_POST['user_login']) && !validate_username($_POST['user_login'])) {
        $errors->add('user_login', __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.'));
    }
    if (!$update && username_exists($user->user_login)) {
        $errors->add('user_login', __('<strong>ERROR</strong>: This username is already registered. Please choose another one.'));
    }
    /* checking e-mail address */
    if (empty($user->user_email)) {
        $errors->add('empty_email', __('<strong>ERROR</strong>: Please enter an e-mail address.'), array('form-field' => 'email'));
    } elseif (!is_email($user->user_email)) {
        $errors->add('invalid_email', __('<strong>ERROR</strong>: The e-mail address isn&#8217;t correct.'), array('form-field' => 'email'));
    } elseif (($owner_id = email_exists($user->user_email)) && (!$update || $owner_id != $user->ID)) {
        $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.'), array('form-field' => 'email'));
    }
    // Allow plugins to return their own errors.
    do_action_ref_array('user_profile_update_errors', array(&$errors, $update, &$user));
    if ($errors->get_error_codes()) {
        return $errors;
    }
    if ($update) {
        $user_id = wp_update_user(get_object_vars($user));
        // EKLEME USER DISABILITY DB UPDATE
        //require_once('./dbconnect.php');
        $connect = mysql_pconnect("localhost", "root", "");
        mysql_select_db("erisimdb", $connect);
        $updateDisSql = "UPDATE er_disability_user SET disability_id = " . $_POST['engelUserUpdate'] . " WHERE user_id = " . $user_id;
        mysql_query($updateDisSql);
        mysql_close($connect);
        //
    } else {
        $user_id = wp_insert_user(get_object_vars($user));
        wp_new_user_notification($user_id, isset($_POST['send_password']) ? $pass1 : '');
    }
    return $user_id;
}
Example #24
0
/**
 * The logic to process and validate form entry
 * 
 * @global array $current_user
 * @return object WP_ERROR
 */
function cpm_page_new_process()
{
    global $current_user;
    get_currentuserinfo();
    $cpm_errors = new WP_Error();
    if (!cpm_currentUserCanStartThread()) {
        $cpm_errors->add('noPermission', __('You do not have the permission to send new PMs.', 'cubepm'));
        return $cpm_errors;
    }
    $recipients = (array) explode(',', $_POST['cpm_recipient']);
    $valid_recipients = array();
    $invalid_recipients = array();
    foreach ($recipients as $recipient) {
        $recipient = trim($recipient);
        if ($recipient != '') {
            $user = get_user_by('login', $recipient);
            if ($user) {
                $valid_recipients[] = $user->ID;
            } else {
                $invalid_recipients[] = $recipient;
            }
            $valid_recipients = array_unique($valid_recipients);
            $invalid_recipients = array_unique($invalid_recipients);
        }
    }
    if (count($invalid_recipients) > 0) {
        $cpm_errors->add('invalidRecipient', __('One or more users you entered is invalid.', 'cubepm'));
    } else {
        if (count($valid_recipients) == 0) {
            $cpm_errors->add('emptyRecipient', __('Please enter the user you would like to send your PM to.', 'cubepm'));
        } else {
            if (in_array($current_user->ID, $valid_recipients)) {
                $cpm_errors->add('selfRecipient', __('You cannot send a PM to yourself!', 'cubepm'));
            }
        }
    }
    $subject = trim($_POST['cpm_subject']);
    if ($subject == '') {
        $cpm_errors->add('emptySubject', __('Please enter a subject!', 'cubepm'));
    }
    $message = trim($_POST['cpm_message']);
    if ($message == '') {
        $cpm_errors->add('emptyMessage', __('Please enter a message!', 'cubepm'));
    }
    if (count($cpm_errors->get_error_codes()) == 0) {
        cpm_new_thread($current_user->ID, $valid_recipients, apply_filters('cpm_subject', $subject), apply_filters('cpm_message', $message));
    }
    return $cpm_errors;
}
 private function printError(WP_Error $error)
 {
     foreach ($error->get_error_codes() as $code) {
         foreach ($error->get_error_messages($code) as $message) {
             if (!empty($message)) {
                 $this->printNotice($message . "\n<br>Error code: <code>" . htmlentities($code) . '</code>', 'error');
             }
         }
     }
 }
/**
 * Edit user settings based on contents of $_POST
 *
 * Used on user-edit.php and profile.php to manage and process user options, passwords etc.
 *
 * @since 2.0
 *
 * @param int $user_id Optional. User ID.
 * @return int user id of the updated user
 */
function edit_user( $user_id = 0 ) {
	global $current_user, $wp_roles, $wpdb;
	if ( $user_id != 0 ) {
		$update = true;
		$user->ID = (int) $user_id;
		$userdata = get_userdata( $user_id );
		$user->user_login = $wpdb->escape( $userdata->user_login );
	} else {
		$update = false;
		$user = '';
	}

	if ( isset( $_POST['user_login'] ))
		$user->user_login = esc_html( trim( $_POST['user_login'] ));

	$pass1 = $pass2 = '';
	if ( isset( $_POST['pass1'] ))
		$pass1 = $_POST['pass1'];
	if ( isset( $_POST['pass2'] ))
		$pass2 = $_POST['pass2'];

	if ( isset( $_POST['role'] ) && current_user_can( 'edit_users' ) ) {

		// Don't let anyone with 'edit_users' (admins) edit their own role to something without it.
		if( $user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap( 'edit_users' ))
			$user->role = $_POST['role'];

		// If the new role isn't editable by the logged-in user die with error
		$editable_roles = get_editable_roles();
		if (!$editable_roles[$_POST['role']])
			wp_die(__('You can&#8217;t give users that role.'));
	}

	if ( isset( $_POST['email'] ))
		$user->user_email = esc_html( trim( $_POST['email'] ));
	if ( isset( $_POST['url'] ) ) {
		if ( empty ( $_POST['url'] ) || $_POST['url'] == 'http://' ) {
			$user->user_url = '';
		} else {
			$user->user_url = esc_url( trim( $_POST['url'] ));
			$user->user_url = preg_match('/^(https?|ftps?|mailto|news|irc|gopher|nntp|feed|telnet):/is', $user->user_url) ? $user->user_url : 'http://'.$user->user_url;
		}
	}
	if ( isset( $_POST['first_name'] ))
		$user->first_name = esc_html( trim( $_POST['first_name'] ));
	if ( isset( $_POST['last_name'] ))
		$user->last_name = esc_html( trim( $_POST['last_name'] ));
	if ( isset( $_POST['nickname'] ))
		$user->nickname = esc_html( trim( $_POST['nickname'] ));
	if ( isset( $_POST['display_name'] ))
		$user->display_name = esc_html( trim( $_POST['display_name'] ));
	if ( isset( $_POST['description'] ))
		$user->description = trim( $_POST['description'] );
	if ( isset( $_POST['jabber'] ))
		$user->jabber = esc_html( trim( $_POST['jabber'] ));
	if ( isset( $_POST['aim'] ))
		$user->aim = esc_html( trim( $_POST['aim'] ));
	if ( isset( $_POST['yim'] ))
		$user->yim = esc_html( trim( $_POST['yim'] ));
	if ( !$update )
		$user->rich_editing = 'true';  // Default to true for new users.
	else if ( isset( $_POST['rich_editing'] ) )
		$user->rich_editing = $_POST['rich_editing'];
	else
		$user->rich_editing = 'true';

	$user->comment_shortcuts = isset( $_POST['comment_shortcuts'] )? $_POST['comment_shortcuts'] : '';

	$user->use_ssl = 0;
	if ( !empty($_POST['use_ssl']) )
		$user->use_ssl = 1;

	if ( !$update )
		$user->admin_color = 'fresh';  // Default to fresh for new users.
	else if ( isset( $_POST['admin_color'] ) )
		$user->admin_color = $_POST['admin_color'];
	else
		$user->admin_color = 'fresh';

	$errors = new WP_Error();

	/* checking that username has been typed */
	if ( $user->user_login == '' )
		$errors->add( 'user_login', __( '<strong>ERROR</strong>: Please enter a username.' ));

	/* checking the password has been typed twice */
	do_action_ref_array( 'check_passwords', array ( $user->user_login, & $pass1, & $pass2 ));

	if ( $update ) {
		if ( empty($pass1) && !empty($pass2) )
			$errors->add( 'pass', __( '<strong>ERROR</strong>: You entered your new password only once.' ), array( 'form-field' => 'pass1' ) );
		elseif ( !empty($pass1) && empty($pass2) )
			$errors->add( 'pass', __( '<strong>ERROR</strong>: You entered your new password only once.' ), array( 'form-field' => 'pass2' ) );
	} else {
		if ( empty($pass1) )
			$errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password.' ), array( 'form-field' => 'pass1' ) );
		elseif ( empty($pass2) )
			$errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password twice.' ), array( 'form-field' => 'pass2' ) );
	}

	/* Check for "\" in password */
	if ( false !== strpos( stripslashes($pass1), "\\" ) )
		$errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' ), array( 'form-field' => 'pass1' ) );

	/* checking the password has been typed twice the same */
	if ( $pass1 != $pass2 )
		$errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter the same password in the two password fields.' ), array( 'form-field' => 'pass1' ) );

	if (!empty ( $pass1 ))
		$user->user_pass = $pass1;

	if ( !$update && !validate_username( $user->user_login ) )
		$errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid. Please enter a valid username.' ));

	if (!$update && username_exists( $user->user_login ))
		$errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ));

	/* checking e-mail address */
	if ( empty ( $user->user_email ) ) {
		$errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please enter an e-mail address.' ), array( 'form-field' => 'email' ) );
	} elseif (!is_email( $user->user_email ) ) {
		$errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The e-mail address isn&#8217;t correct.' ), array( 'form-field' => 'email' ) );
	} elseif ( ( $owner_id = email_exists($user->user_email) ) && $owner_id != $user->ID ) {
		$errors->add( 'email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.'), array( 'form-field' => 'email' ) );
	}

	// Allow plugins to return there own errors.
	do_action_ref_array('user_profile_update_errors', array ( &$errors, $update, &$user ) );

	if ( $errors->get_error_codes() )
		return $errors;

	if ( $update ) {
		$user_id = wp_update_user( get_object_vars( $user ));
	} else {
		$user_id = wp_insert_user( get_object_vars( $user ));
		wp_new_user_notification( $user_id, isset($_POST['send_password']) ? $pass1 : '' );
	}
	return $user_id;
}
Example #27
0
/**
 * Output the login page header.
 *
 * @param string   $title    Optional. WordPress login Page title to display in the `<title>` element.
 *                           Default 'Log In'.
 * @param string   $message  Optional. Message to display in header. Default empty.
 * @param WP_Error $wp_error Optional. The error to pass. Default empty.
 */
function login_header($title = 'Log In', $message = '', $wp_error = '')
{
    global $error, $interim_login, $action;
    // Don't index any of these forms
    add_action('login_head', 'wp_no_robots');
    if (wp_is_mobile()) {
        add_action('login_head', 'wp_login_viewport_meta');
    }
    if (empty($wp_error)) {
        $wp_error = new WP_Error();
    }
    // Shake it!
    $shake_error_codes = array('empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password');
    /**
     * Filter the error codes array for shaking the login form.
     *
     * @since 3.0.0
     *
     * @param array $shake_error_codes Error codes that shake the login form.
     */
    $shake_error_codes = apply_filters('shake_error_codes', $shake_error_codes);
    if ($shake_error_codes && $wp_error->get_error_code() && in_array($wp_error->get_error_code(), $shake_error_codes)) {
        add_action('login_head', 'wp_shake_js', 12);
    }
    ?>
<!DOCTYPE html>
	<!--[if IE 8]>
		<html xmlns="http://www.w3.org/1999/xhtml" class="ie8" <?php 
    language_attributes();
    ?>
>
	<![endif]-->
	<!--[if !(IE 8) ]><!-->
		<html xmlns="http://www.w3.org/1999/xhtml" <?php 
    language_attributes();
    ?>
>
	<!--<![endif]-->
	<head>
	<meta http-equiv="Content-Type" content="<?php 
    bloginfo('html_type');
    ?>
; charset=<?php 
    bloginfo('charset');
    ?>
" />
	<title><?php 
    bloginfo('name');
    ?>
 &rsaquo; <?php 
    echo $title;
    ?>
</title>
	<?php 
    wp_admin_css('login', true);
    /*
     * Remove all stored post data on logging out.
     * This could be added by add_action('login_head'...) like wp_shake_js(),
     * but maybe better if it's not removable by plugins
     */
    if ('loggedout' == $wp_error->get_error_code()) {
        ?>
		<script>if("sessionStorage" in window){try{for(var key in sessionStorage){if(key.indexOf("wp-autosave-")!=-1){sessionStorage.removeItem(key)}}}catch(e){}};</script>
		<?php 
    }
    /**
     * Enqueue scripts and styles for the login page.
     *
     * @since 3.1.0
     */
    do_action('login_enqueue_scripts');
    /**
     * Fires in the login page header after scripts are enqueued.
     *
     * @since 2.1.0
     */
    do_action('login_head');
    if (is_multisite()) {
        $login_header_url = network_home_url();
        $login_header_title = get_current_site()->site_name;
    } else {
        $login_header_url = __('https://wordpress.org/');
        $login_header_title = __('Powered by WordPress');
    }
    /**
     * Filter link URL of the header logo above login form.
     *
     * @since 2.1.0
     *
     * @param string $login_header_url Login header logo URL.
     */
    $login_header_url = apply_filters('login_headerurl', $login_header_url);
    /**
     * Filter the title attribute of the header logo above login form.
     *
     * @since 2.1.0
     *
     * @param string $login_header_title Login header logo title attribute.
     */
    $login_header_title = apply_filters('login_headertitle', $login_header_title);
    $classes = array('login-action-' . $action, 'wp-core-ui');
    if (wp_is_mobile()) {
        $classes[] = 'mobile';
    }
    if (is_rtl()) {
        $classes[] = 'rtl';
    }
    if ($interim_login) {
        $classes[] = 'interim-login';
        ?>
		<style type="text/css">html{background-color: transparent;}</style>
		<?php 
        if ('success' === $interim_login) {
            $classes[] = 'interim-login-success';
        }
    }
    $classes[] = ' locale-' . sanitize_html_class(strtolower(str_replace('_', '-', get_locale())));
    /**
     * Filter the login page body classes.
     *
     * @since 3.5.0
     *
     * @param array  $classes An array of body classes.
     * @param string $action  The action that brought the visitor to the login page.
     */
    $classes = apply_filters('login_body_class', $classes, $action);
    ?>
	</head>
	<body class="login <?php 
    echo esc_attr(implode(' ', $classes));
    ?>
">
	<div id="login">
		<h1><a href="<?php 
    echo esc_url($login_header_url);
    ?>
" title="<?php 
    echo esc_attr($login_header_title);
    ?>
" tabindex="-1"><?php 
    bloginfo('name');
    ?>
</a></h1>
	<?php 
    unset($login_header_url, $login_header_title);
    /**
     * Filter the message to display above the login form.
     *
     * @since 2.1.0
     *
     * @param string $message Login message text.
     */
    $message = apply_filters('login_message', $message);
    if (!empty($message)) {
        echo $message . "\n";
    }
    // In case a plugin uses $error rather than the $wp_errors object
    if (!empty($error)) {
        $wp_error->add('error', $error);
        unset($error);
    }
    if ($wp_error->get_error_code()) {
        $errors = '';
        $messages = '';
        foreach ($wp_error->get_error_codes() as $code) {
            $severity = $wp_error->get_error_data($code);
            foreach ($wp_error->get_error_messages($code) as $error_message) {
                if ('message' == $severity) {
                    $messages .= '	' . $error_message . "<br />\n";
                } else {
                    $errors .= '	' . $error_message . "<br />\n";
                }
            }
        }
        if (!empty($errors)) {
            /**
             * Filter the error messages displayed above the login form.
             *
             * @since 2.1.0
             *
             * @param string $errors Login error message.
             */
            echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n";
        }
        if (!empty($messages)) {
            /**
             * Filter instructional messages displayed above the login form.
             *
             * @since 2.5.0
             *
             * @param string $messages Login messages.
             */
            echo '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
        }
    }
}
Example #28
0
/**
 * Outputs the header for the login page.
 *
 * @uses do_action() Calls the 'login_head' for outputting HTML in the Log In
 *		header.
 * @uses apply_filters() Calls 'login_headerurl' for the top login link.
 * @uses apply_filters() Calls 'login_headertitle' for the top login title.
 * @uses apply_filters() Calls 'login_message' on the message to display in the
 *		header.
 * @uses $error The error global, which is checked for displaying errors.
 *
 * @param string $title Optional. WordPress Log In Page title to display in
 *		<title/> element.
 * @param string $message Optional. Message to display in header.
 * @param WP_Error $wp_error Optional. WordPress Error Object
 */
function login_header($title = 'Log In', $message = '', $wp_error = '') {
	global $error, $is_iphone, $interim_login, $current_site;

	// Don't index any of these forms
	add_filter( 'pre_option_blog_public', '__return_zero' );
	add_action( 'login_head', 'noindex' );

	if ( empty($wp_error) )
		$wp_error = new WP_Error();

	// Shake it!
	$shake_error_codes = array( 'empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password' );
	$shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes );

	if ( $shake_error_codes && $wp_error->get_error_code() && in_array( $wp_error->get_error_code(), $shake_error_codes ) )
		add_action( 'login_head', 'wp_shake_js', 12 );

	?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
<head>
	<title><?php bloginfo('name'); ?> &rsaquo; <?php echo $title; ?></title>
	<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<?php
	wp_admin_css( 'login', true );
	wp_admin_css( 'colors-fresh', true );

	if ( $is_iphone ) { ?>
	<meta name="viewport" content="width=320; initial-scale=0.9; maximum-scale=1.0; user-scalable=0;" />
	<style type="text/css" media="screen">
	form { margin-left: 0px; }
	#login { margin-top: 20px; }
	</style>
<?php
	} elseif ( isset($interim_login) && $interim_login ) { ?>
	<style type="text/css" media="all">
	.login #login { margin: 20px auto; }
	</style>
<?php
	}

	do_action('login_head'); ?>
</head>
<body class="login">
<?php   if ( !is_multisite() ) { ?>
<div id="login"><h1><a href="<?php echo apply_filters('login_headerurl', 'http://wordpress.org/'); ?>" title="<?php echo apply_filters('login_headertitle', __('Powered by WordPress')); ?>"><?php bloginfo('name'); ?></a></h1>
<?php   } else { ?>
<div id="login"><h1><a href="<?php echo apply_filters('login_headerurl', network_home_url() ); ?>" title="<?php echo apply_filters('login_headertitle', $current_site->site_name ); ?>"><span class="hide"><?php bloginfo('name'); ?></span></a></h1>
<?php   }

	$message = apply_filters('login_message', $message);
	if ( !empty( $message ) ) echo $message . "\n";

	// Incase a plugin uses $error rather than the $errors object
	if ( !empty( $error ) ) {
		$wp_error->add('error', $error);
		unset($error);
	}

	if ( $wp_error->get_error_code() ) {
		$errors = '';
		$messages = '';
		foreach ( $wp_error->get_error_codes() as $code ) {
			$severity = $wp_error->get_error_data($code);
			foreach ( $wp_error->get_error_messages($code) as $error ) {
				if ( 'message' == $severity )
					$messages .= '	' . $error . "<br />\n";
				else
					$errors .= '	' . $error . "<br />\n";
			}
		}
		if ( !empty($errors) )
			echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n";
		if ( !empty($messages) )
			echo '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
	}
} // End of login_header()
Example #29
0
function g1_simple_slider_move_slide()
{
    $ajax_data = $_POST['ajax_data'];
    check_ajax_referer('g1_simple_slider-move_slide' . $ajax_data['slide_id']);
    $error_response = $success_response = new WP_Ajax_Response();
    $errors = new WP_Error();
    $post = get_post(absint($ajax_data['post_id']));
    $slide_id = absint($ajax_data['slide_id']);
    $after_slide_id = absint($ajax_data['after_slide_id']);
    $after_slide_post = $after_slide_id ? get_post($after_slide_id) : null;
    $slide_post = get_post($slide_id);
    if (!$post || !$slide_post || $after_slide_id && !$after_slide_post) {
        $errors->add('incorrect_input_data', 'At least one of the slides does not exist!');
    }
    if (count($errors->get_error_codes()) > 0) {
        $error_response->add(array('what' => 'errors', 'id' => $errors));
        $error_response->send();
        exit;
    }
    $slider = G1_Slider_Factory::get_simple_slider($post);
    $slide = $slider->get_slide($slide_post->ID);
    if ($after_slide_post) {
        $after_slide = $slider->get_slide($after_slide_post->ID);
        $slider->move_slide_after_slide($slide, $after_slide);
    } else {
        $first_slide = $slider->get_first_slide();
        $slider->move_slide_before_slide($slide, $first_slide);
    }
    $slider->save();
    $success_response->add(array('what' => 'success', 'id' => 1));
    $success_response->send();
    exit;
}
 /**
  * Join array of statuses into one status
  *
  * @since 2.0
  * @access public
  *
  * @param array of WP_Errors objects $statuses
  * @param ( object | array of object ) $join_status second status to join may be single WP_Error object or array of WP_Error objects
  * @return object WP_Error 
  */
 function join_errors($statuses = array(), $join_status = null)
 {
     $return = new WP_Error();
     // If multiple arguments were passed join different wp errors
     if (!empty($join_status)) {
         if (is_array($statuses)) {
             $statuses[] = $join_status;
         } else {
             $statuses = array($statuses, $join_status);
         }
     }
     if (empty($statuses)) {
         return $return;
     }
     // Loop through statuses
     foreach ($statuses as $status) {
         // Skip empty statuses
         if (!is_wp_error($status) or !$status->get_error_codes()) {
             continue;
         }
         foreach ($status->get_error_codes() as $code) {
             // Add messages first
             $messages = $status->get_error_messages($code);
             // we need only unique messages
             if (in_array($code, $return->get_error_codes())) {
                 $messages = array_diff($messages, $return->get_error_messages($code));
             }
             // add messages if they present
             if (!empty($messages)) {
                 foreach ($messages as $message) {
                     $return->add($code, $message);
                 }
             }
             // Add code data
             $data = $status->get_error_data($code);
             // Join return data and our data
             if (!empty($data) and $return->get_error_data($code)) {
                 // add new data according to return data type
                 if (is_array($return->get_error_data($code))) {
                     // passed data is array
                     $data = array_merge($data, $return->get_error_data($code));
                 } elseif (is_array($data)) {
                     $data[] = $return->get_error_data($code);
                 } elseif (is_array($return->get_error_data($code))) {
                     $data = array_push($return->get_error_data($code), $data);
                 } elseif (is_string($data) and is_string($return->get_error_data($code))) {
                     $data = $return->get_error_data($code) . $data;
                 }
             }
             if (!empty($data)) {
                 $return->add_data($data, $code);
             }
         }
         // Loop for each code inside status
     }
     // Loop for each passed statuses
     return $return;
 }