Risposte nei forum create
-
AutorePost
-
giangel84Partecipante
Grazie mille!! questo è ancora meglio!!
giangel84PartecipanteAh ovviamente tale codice serve solo se si deve conoscere il prefisso di base.
Ad esempio se il mio plugin dovesse creare una tabella nel blog principale e lavorare su quella anche con i sotto-blog.
Se dovete scrivere un plugin che lavora solo sulla tabella users, invece di usare la funzione qui sopra e scrivere
$table_users = $table_prefix . “users”, la si può ricavare richiamando la global $wpdb;
e utilizzando
$table_users = $wpdb->users;
a buon rendere.
giangel84PartecipanteHo trovato la soluzione!!!
La posto per tutti (cosଠWolly può confermare se è corretto il metodo):
Per recuperare il table prefix base, basta fare cosà¬.
global $wpdb;
$user_table = $wpdb->users;
$new_prefix = substr($user_table, 0, -5);
$table_prefix = $new_prefix;
In questo modo
$user_table conterrà la stringa con il nome completo di prefisso della tabella users.
ad esempio se il prefix base fosse "myblog12_3_" oppure semplicemente "wp_"
$user_table diventa "myblog_12_3_users" oppure semplicemente "wp_users"
Infatti lo scopo è quello di ottenere sempre il prefix di base, indipendentemente dal nome.
a questo punto per ottenere il prefix base è sufficiente eliminare "users" dalla stringa, che sono gli ultimi 5 caratteri.
Lo si fà con la funzione:
$new_prefix = substr($user_table, 0, -5);
a questo punto $new_prefix sarà sempre il prefisso di base.
Ora non credo che qualcuno si metta a modificare anche il nome della tabella users, per cui tale funzione sarà compatibile con il 99,9% dei blog wordpress.
Sono sicuro che ci siano altri metodi ma con questo ho eliminato tanto tanto codice inutile.
(Come ho trovato la soluzione? Analizzando il file /wp-admin/install.php)
giangel84PartecipanteGrazie Wolly e scusami se sono stato poco chiaro fin dall’inizio, non specificando che dovevo lavorare con la tabella users.
Mi sarebbe di grande aiuto riuscire a recuperare il table_prefix base!
Sono sicuro che un metodo c’è ma nel codex non l’ho trovato.
Il problema è che il table prefix può essere scelto dall’utente in fase di installazione e quindi, potrebbe essere una stringa qualsiasi, pertanto il metodo di confronto da me adottato avrebbe poco senso.
Sono sicuro che il 95% dei blog installati abbiano tutti il prefix standard “wp_” ma vorrei scrivere un codice compatibile con il 100% dei blog wordpress.
Grazie ancora per l’aiuto!
giangel84PartecipanteNon per fare il guasta feste, anzi, apprezzo l’esempio di aiuto ma non c’è nessuna differenza tra:
$table_name = $wpdb->prefix
e quello che ho detto io
$db_prefix = $GLOBALS;
poichè se tento di eseguire il plugin dal "blog1" il prefix avrà come valore "wp_" e andrebbe bene
ma se tento di farlo dal sotto-blog "blog2" il prefix avrà come valore "wp_2_" e non andrebbe bene poichè il plugin lavora con la tabella utenti "user"
Se impostassi sempre "wp_user" al posto di
$table_prefix . "user"
non avrei problemi di funzionamento, ma chi per sicurezza, cambia il prefix???
Io in parte ho risolto il problema, ho pensato di fare cosà¬:
if ($table_prefix <> 'wp_') {
$new_prefix="";
for ($i=0;$i<strlen($table_prefix);$i++){
if (!is_numeric($table_prefix{$i}))
$new_prefix=$new_prefix.$table_prefix{$i};
}
$new_prefix = substr($new_prefix, 0, -1);
$table_prefix = $new_prefix;
//validate prefix
$table_users = $table_prefix . "users";
$admin_exist = $wpdb->get_var("SELECT ID FROM $table_users WHERE user_login='admin'");
if ($admin_exist) {
$install = true;
} else {
$install = false;
}
Funziona, ma non so se è la maniera corretta.
Infatti darebbe come risultato false se i prefix fossero (ad esempio) "blog1_" "blog2_" ecc...
Allo stesso modo non funzionerebbe se il prefix fosse "blog_1_" e "blog_2_"
Ma funzionerebbe solo se fosse "blog_" e "blog_2_" proprio come fa wordpress normalmente con il prefix standard e i sottoblog.
Infatti la funzione non fa altro che controllare se la stringa table_prefix contiene un numero.
Se ne ha uno lo toglie ed elimina l'ulitmo carattere, ovvero l'underscore...
L'ideale sarebbe poter inserire la suddetta funzione, per l'installazione automatica.
Se la funzione genera false, allora lasciare all'utente la possibilità di inserire autonomamente il prefix...
Solo che a questo punto tale controllo non andrebbe fatto in fase di installazione del plugin, o in fase di attivazione....ma quando si apre per la prima volta la parte amministrativa...
Giusto?
Credevo ci fossero modi più semplici, del tipo "prendi solo il prefix del blog principale o della tabella utenti".
Mi sembra uno spreco di codice scritto cosà¬.
giangel84Partecipantegrazie mille ha funzionato!
Inizio a capirci qualcosa di più adesso!
Sei stato gentilissimo!
giangel84PartecipanteNon hai anche un backup del db?!
Io con Aruba ho attivato anche il MySQL backup…e tutti i giorni e tutte le settimane ho le copie automatiche del database.
E’ davvero molto molto comodo….
giangel84PartecipanteSiete stati molto gentili.
Credo che lavorerò un po’ sull’arrastheme, che sembra fare esattamente quello che serve a me.
Anche se in realtà mi sembra un pochino lento nel caricare le immagini relative ai link.
Tempo fà avevo messo mano ad uno script in java che farebbe esattamente quel che cerco io, ma dovrei recuperare quello script ed adattarlo.
Appena trovo una soluzione ideale, posterò le modifiche da effettuare al template nel caso potesse tornare utile in futuro, ad altri utenti.
Nel frattempo grazie ancora!
giangel84PartecipanteNon semplice da capire ma ci sono arrivato.
Il plugin cosଠcome lo si trova cercandolo dal pannello dei plugin di wordpress, contiene il css con lo stile del calendario. Esso và copiato e si deve andare a sostituire la parte di codice del css del template con questa parte.
Fatto questo si deve andare a modificare il file amr_props_sample.php rinominandolo in amr_props.php, che trovate nella directory del plugin.
All’interno di quest’ultimo si vanno a specificare il numero ed il nome delle stanze disponibili.
Poi si crea una pagina per ogni stanza disponibile e si và ad inserire tramite editor, sotto alla descrizione della stanza (fatta da voi) il seguente shortcode:
[amr-clearskys-bookings property=1 months=12]
Dove property=n , è il numero della stanza che avrete specificato nel file amr_props.php.
Questo shortcode visualizza il calendario 12 mesi con la disponibilità della stanza 1, nei vari giorni.
Poi dal pannello di amministrazione si inseriscono manualmente le prenotazioni stanza per stanza.
Lo shortcode descritto prima si collega al database dove sono salvate le date e gli orari delle prenotazioni e fà visualizzare il calendario con le disponibilità in base alle prenotazioni salvate in precedenza.
Sostanzialmente l’inserimento delle prenotazioni viene fatto manualmente e per gestire le richieste dovreste creare un form di contatto apposito con un altro plug-in.
Spero di aver chiarito l’utilizzo di questo plugin.
L’unica cosa che mi rimane da capire, visto che un widget sembrava disponibile ma non più scaricabile, è se quel widget appunto mi permetteva di fare le richieste o le prenotazioni in modo più automatizzato.
-
AutorePost