Esempio n. 1
0
function bon_show_error($echo = true)
{
    if ($codes = bon_error_notice()->get_error_codes()) {
        if (!isset($echo) || $echo == null) {
            $echo = true;
        }
        $output = '';
        foreach ($codes as $code) {
            $data = bon_error_notice()->get_error_data($code);
            $message = bon_error_notice()->get_error_message($code);
            $error_classes = array('bon-wp-error');
            $error_class = '';
            $error_text = '';
            if ($data) {
                $error_class = 'bon-message-' . $data;
                if ($data == 'error') {
                    $error_text = '<strong>' . __('ERROR', 'bon') . '</strong>: ';
                } elseif ($data == 'success') {
                    $error_text = '<strong>' . __('SUCCESS', 'bon') . '</strong>: ';
                } elseif ($data == 'notice') {
                    $error_text = '<strong>' . __('NOTICE', 'bon') . '</strong>: ';
                } elseif ($data == 'error-user') {
                    $error_class = 'bon-message-error';
                }
            }
            $error_classes[] = $error_class;
            $error_classes = apply_filters('bon_error_classes', $error_classes, $data);
            $error_text = apply_filters('bon_error_text', $error_text, $data);
            /* Sanitize and join all classes. */
            $class = join(' ', array_map('sanitize_html_class', array_unique($error_classes)));
            if ($message) {
                $output .= '<div class="' . $class . ' ">' . $error_text . $message . '</div>';
            }
        }
        if (!empty($output)) {
            if ($echo == true) {
                echo $output;
            } else {
                return $output;
            }
        }
    }
}
Esempio n. 2
0
 /**
  * Retrieves a user row based on password reset key and login
  *
  * @uses $wpdb WordPress Database object
  *
  * @access public
  * @param string $key Hash to validate sending user's password
  * @param string $login The user login
  * @return object|bool User's database row on success, false for invalid keys
  */
 public static function _check_password_reset_key($key, $login)
 {
     global $wpdb;
     $key = preg_replace('/[^a-z0-9]/i', '', $key);
     if (empty($key) || !is_string($key)) {
         bon_error_notice()->add('invalid_key', __('Invalid Key.', 'bon'), 'error');
         return false;
     }
     if (empty($login) || !is_string($login)) {
         bon_error_notice()->add('invalid_key', __('Invalid Key.', 'bon'), 'error');
         return false;
     }
     $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->users} WHERE user_activation_key = %s AND user_login = %s", $key, $login));
     if (empty($user)) {
         bon_accounts()->error_notice()->add('invalid_key', __('Invalid Key.', 'bon'), 'error');
         return false;
     }
     return $user;
 }
 public function front_end_editor_shortcodes($attr)
 {
     global $wp, $current_screen, $wp_meta_boxes, $post;
     $is_bac = $this->is_bac();
     $output = '';
     /**
      * Start Checking the Conditional needed to render editor
      * Define Variable needed for use in whole function
      *  
      *
      */
     if (!is_user_logged_in()) {
         if ($is_bac === true) {
             wp_safe_redirect(bon_accounts()->my_account_url());
         } else {
             if (is_woocommerce_activated()) {
                 wp_safe_redirect(get_permalink(wc_get_page_id('myaccount')));
             }
         }
     } else {
         if (!$this->is_edit()) {
             return;
         }
         $object_id = $this->get_post_to_edit();
         if (!$object_id) {
             bon_error_notice()->add('invalid_post', __('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'), 'error');
             return;
         }
         $post_object = get_post($this->get_post_to_edit());
         setup_postdata($GLOBALS['post'] =& $post_object);
         $current_post_type = get_post_type($object_id);
         if (!$post_object) {
             bon_error_notice()->add('invalid_post', __('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'), 'error');
             return;
         }
         if (!current_user_can('edit_post', $object_id)) {
             bon_error_notice()->add('permission_denied', __('You are not allowed to edit this item.'), 'error');
             return;
         }
         if (!post_type_supports($post_object->post_type, 'front-end-editor')) {
             bon_error_notice()->add('unsupported_posttype', __('The post type assigned is not supporting front end post', 'bon'), 'error');
         }
         $form_extra = '';
         $notice = false;
         if ($post_object->post_status === 'auto-draft') {
             $post_object->post_title = '';
             $post_object->comment_status = get_option('default_comment_status');
             $post_object->ping_status = get_option('default_ping_status');
             $autosave = false;
             $form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />";
         } else {
             $autosave = wp_get_post_autosave($object_id);
         }
         $form_action = 'editpost';
         $nonce_action = 'update-post_' . $object_id;
         $form_extra .= "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr($object_id) . "' />";
         $content_css = array(trailingslashit(get_stylesheet_directory_uri()) . 'assets/css/editor-styles.css', trailingslashit(includes_url()) . 'css/dashicons.min.css', trailingslashit(includes_url()) . 'js/mediaelement/mediaelementplayer.min.css', trailingslashit(includes_url()) . 'js/mediaelement/wp-mediaelement.css', trailingslashit(includes_url()) . 'js/tinymce/skins/wordpress/wp-content.css', trailingslashit(includes_url()) . 'css/editor.min.css');
         $content_css = join(',', array_map('esc_url', array_unique($content_css)));
         $args = array('post_ID' => $object_id, 'post_type' => $current_post_type, 'user_ID' => get_current_user_id(), 'post' => $post_object, 'post_type_object' => get_post_type_object($current_post_type), 'autosave' => $autosave, 'form_extra' => $form_extra, 'form_action' => $form_action, 'nonce_action' => $nonce_action, 'editor_settings' => array('dfw' => true, 'drag_drop_upload' => true, 'tabfocus_elements' => 'insert-media-button, save-post', 'editor_height' => 360, 'tinymce' => array('resize' => false, 'add_unload_trigger' => false, 'content_css' => $content_css)));
         ob_start();
         bon_get_template('posts/editor.php', $args);
         $args['editor'] = ob_get_clean();
         unset($args['editor_settings']);
         set_current_screen($current_post_type);
         $current_screen->set_parentage('edit.php?post_type=' . $current_post_type);
         if (!wp_check_post_lock($object_id)) {
             $args['active_post_lock'] = wp_set_post_lock($object_id);
         }
         $messages = $this->get_wp_messages($post_object);
         $message = false;
         if (isset($_GET['message'])) {
             $_GET['message'] = absint($_GET['message']);
             if (isset($messages[$current_post_type][$_GET['message']])) {
                 $message = $messages[$current_post_type][$_GET['message']];
             } elseif (!isset($messages[$current_post_type]) && isset($messages['post'][$_GET['message']])) {
                 $message = $messages['post'][$_GET['message']];
             }
         }
         // Detect if there exists an autosave newer than the post and if that autosave is different than the post
         if ($autosave && mysql2date('U', $autosave->post_modified_gmt, false) > mysql2date('U', $post_object->post_modified_gmt, false)) {
             foreach (_wp_post_revision_fields() as $autosave_field => $_autosave_field) {
                 if (normalize_whitespace($autosave->{$autosave_field}) != normalize_whitespace($post_object->{$autosave_field})) {
                     bon_error_notice()->add('autosave_exists', sprintf(__('There is an autosave of this post that is more recent than the version below. <a href="%s">View the autosave</a>'), get_edit_post_link($autosave->ID)), 'notice');
                     break;
                 }
             }
             // If this autosave isn't different from the current post, begone.
             if (!$notice) {
                 wp_delete_post_revision($autosave->ID);
             }
             unset($autosave_field, $_autosave_field);
         }
         bon_get_template('posts/post.php', $args);
         unset($GLOBALS['current_screen']);
         wp_reset_postdata();
     }
 }