• Resolved crossi72

    (@crossi72)


    I use CMB2 to generate a set of custom metaboxes but sometimes (I can’t reproduce the condition that causes issue) those data are deleted from database.

    When this occurs the data are deleted in every post, not only in the post being edited, sometimes the issue occurs even without any user logged.

    I post my code:

    <?php

    //support function for CMB2 metaboxes
    function AddFieldToMetabox($box, $prefix, $label, $name, $type, $repeatable = false, $previewSize = ”, $sanitize_callback = ”){
    $args = array(
    ‘name’ => __( $label, ‘cmb2’ ),
    ‘id’ => ‘_esl_’ . $prefix . $name,
    ‘type’ => $type,
    ‘repeatable’ => $repeatable,
    );

    if ( $previewSize != ”){
    $args[‘preview_size’] = $previewSize;
    }

    if ( $sanitize_callback != ”){
    $args[‘sanitization_cb’] = $sanitize_callback;
    } else {
    $args[‘sanitization_cb’] = ‘sanitize_text_field’;
    }

    $box->add_field( $args );
    }

    add_filter( ‘cmb2_sanitize_gmap’, ‘cmb2_sanitize_map_callback’, 10, 2 );
    add_action( ‘cmb2_render_gmap’, ‘sm_cmb_render_gmap’, 10, 5 );
    add_filter( ‘cmb2_sanitize_smartslider’, ‘cmb2_sanitize_smartslider_callback’, 10, 2 );
    add_action( ‘cmb2_render_smartslider’, ‘sm_cmb_render_smartslider’, 10, 5 );

    //removes iframe tag and google classes from Gmap
    function cmb2_sanitize_map_callback( $override_value, $value ) {
    // check if is gmaps iframe
    if ( substr ( $value, 0 , 13 ) == ‘<iframe src=”‘) {
    // remove iframe code
    $value = substr ( $value, 13 , strlen($value) );
    $value = substr ( $value, 0, strpos( $value, ‘”‘));
    }
    return $value;
    }

    function sm_cmb_render_gmap( $field, $escaped_value, $object_id, $object_type, $field_type_object ) {
    echo $field_type_object->input( array( ‘class’ => ‘regular-text’, ‘type’ => ‘text’ ) );
    }

    // Metabox definition functions association to WordPress hook
    add_action( ‘cmb2_admin_init’, ‘categorie_meta_box_taxonomy’ );
    add_action( ‘cmb2_admin_init’, ‘add_metabox_contatti’ );
    add_action( ‘cmb2_admin_init’, ‘add_metabox_galleria’ );
    add_action( ‘cmb2_admin_init’, ‘add_metabox_mappa’ );
    add_action( ‘cmb2_admin_init’, ‘add_metabox_slideshow’ );
    add_action( ‘cmb2_admin_init’, ‘add_metabox_offerte’ );
    add_action( ‘cmb2_admin_init’, ‘add_metabox_attrazione_home’ );

    function categorie_meta_box_taxonomy() {
    $prefix = ‘_categoria’;

    $cmb_term = new_cmb2_box( array(
    ‘id’ => $prefix . ‘edit’,
    ‘title’ => __( ‘Immagine Categoria’, ‘cmb2’ ),
    ‘object_types’ => array( ‘term’ ),
    ‘taxonomies’ => array( ‘categoria’ )
    ) );

    AddFieldToMetabox($cmb_term, $prefix, ‘Immagine categoria’, ‘immagine’, ‘file’);
    }

    function add_metabox_contatti() {
    $prefix = ”;

    $cmb = new_cmb2_box(
    array(
    ‘id’ => $prefix . ‘contatti’,
    ‘title’ => __( ‘Contatti’, ‘cmb2’ ),
    ‘object_types’ => array(‘hotel’, ‘residence’),
    ‘show_names’ => true
    )
    );

    $group_field_id = $cmb->add_field( array(
    ‘id’ => $prefix . ‘_field_indirizzo’,
    ‘type’ => ‘group’,
    ‘description’ => __( ‘Indirizzo’, ‘cmb2’ ),
    ‘repeatable’ => false,
    ‘options’ => array( ‘group_title’ => __( ‘Indirizzo’, ‘cmb2’ ) ),
    ) );

    // Id’s for group’s fields only need to be unique for the group. Prefix is not needed.
    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Via’,
    ‘id’ => ‘via’,
    ‘type’ => ‘text’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘CAP’,
    ‘id’ => ‘cap’,
    ‘type’ => ‘text’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Citta’,
    ‘id’ => ‘citta’,
    ‘type’ => ‘text’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Prov’,
    ‘id’ => ‘provincia’,
    ‘type’ => ‘text_small’
    ) );

    $group_field_id = $cmb->add_field( array(
    ‘id’ => $prefix . ‘_field_consigliato’,
    ‘type’ => ‘group’,
    ‘description’ => __( ‘Dati per mostrare la struttura prima delle altre nelle ricerche’, ‘cmb2’ ),
    ‘repeatable’ => false,
    ‘options’ => array( ‘group_title’ => __( ‘Consigliato’, ‘cmb2’ ) ),
    ) );

    // Id’s for group’s fields only need to be unique for the group. Prefix is not needed.
    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Consigliato’,
    ‘id’ => ‘consigliato’,
    ‘type’ => ‘checkbox’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Dal’,
    ‘id’ => ‘dal’,
    ‘type’ => ‘text_date’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Al’,
    ‘id’ => ‘al’,
    ‘type’ => ‘text_date’
    ) );

    $group_field_id = $cmb->add_field( array(
    ‘id’ => $prefix . ‘_field_contatti’,
    ‘type’ => ‘group’,
    ‘description’ => __( ‘Dati di contatto’, ‘cmb2’ ),
    ‘repeatable’ => false,
    ‘options’ => array( ‘group_title’ => __( ‘Contatti’, ‘cmb2’ ) ),
    ) );

    // Id’s for group’s fields only need to be unique for the group. Prefix is not needed.
    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Telefono’,
    ‘id’ => ‘telefono’,
    ‘type’ => ‘text_small’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Email’,
    ‘id’ => ’email’,
    ‘type’ => ‘text_email’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Dal’,
    ‘id’ => ‘dal’,
    ‘type’ => ‘text_date’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Al’,
    ‘id’ => ‘al’,
    ‘type’ => ‘text_date’
    ) );
    }

    function add_metabox_offerte(){
    $prefix = ”;

    $cmb = new_cmb2_box(
    array(
    ‘id’ => $prefix . ‘offerte’,
    ‘title’ => __( ‘Offerte’, ‘cmb2’ ),
    ‘object_types’ => array(‘hotel’, ‘residence’),
    ‘show_names’ => true
    )
    );

    AddFieldToMetabox($cmb, $prefix, ‘Fascia di prezzo’, ‘fascia_prezzo’, ‘text’);

    $group_field_id = $cmb->add_field( array(
    ‘id’ => $prefix . ‘_field_offerta’,
    ‘type’ => ‘group’,
    ‘description’ => __( ‘Offerte’, ‘cmb2’ ),
    ‘repeatable’ => true,
    ‘options’ => array(
    ‘group_title’ => __( ‘Offerta {#}’, ‘cmb2’ ),
    ‘add_button’ => __( ‘Aggiungi’, ‘cmb2’ ),
    ‘remove_button’ => __( ‘Rimuovi’, ‘cmb2’ )
    ),
    ) );

    // Id’s for group’s fields only need to be unique for the group. Prefix is not needed.
    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Titolo’,
    ‘id’ => ‘titolo’,
    ‘type’ => ‘text’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Descrizione’,
    ‘id’ => ‘descrizione’,
    ‘type’ => ‘text’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Prezzo (€)’,
    ‘id’ => ‘prezzo’,
    ‘type’ => ‘text_small’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Trattamento’,
    ‘id’ => ‘trattamento’,
    ‘type’ => ‘text’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Dal’,
    ‘id’ => ‘dal’,
    ‘type’ => ‘text_date’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Al’,
    ‘id’ => ‘al’,
    ‘type’ => ‘text_date’
    ) );

    $group_field_id = $cmb->add_field( array(
    ‘id’ => $prefix . ‘_field_lastminute’,
    ‘type’ => ‘group’,
    ‘description’ => __( ‘Last minute’, ‘cmb2’ ),
    ‘repeatable’ => true,
    ‘options’ => array(
    ‘group_title’ => __( ‘Last minute {#}’, ‘cmb2’ ),
    ‘add_button’ => __( ‘Aggiungi’, ‘cmb2’ ),
    ‘remove_button’ => __( ‘Rimuovi’, ‘cmb2’ )
    ),
    ) );

    // Id’s for group’s fields only need to be unique for the group. Prefix is not needed.
    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Titolo’,
    ‘id’ => ‘titolo’,
    ‘type’ => ‘text’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Descrizione’,
    ‘id’ => ‘descrizione’,
    ‘type’ => ‘text’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Prezzo (€)’,
    ‘id’ => ‘prezzo’,
    ‘type’ => ‘text_small’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Trattamento’,
    ‘id’ => ‘trattamento’,
    ‘type’ => ‘text’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Dal’,
    ‘id’ => ‘dal’,
    ‘type’ => ‘text_date’
    ) );

    $cmb->add_group_field( $group_field_id, array(
    ‘name’ => ‘Al’,
    ‘id’ => ‘al’,
    ‘type’ => ‘text_date’
    ) );
    }

    function add_metabox_galleria() {
    $prefix = ”;

    $cmb = new_cmb2_box(
    array(
    ‘id’ => $prefix . ‘galleria’,
    ‘title’ => __( ‘Galleria’, ‘cmb2’ ),
    ‘object_types’ => array(‘hotel’, ‘residence’),
    ‘show_names’ => true
    )
    );

    AddFieldToMetabox($cmb, $prefix, ‘Galleria’, ‘galleria’, ‘file_list’, false, array( 150, 150 ));
    }

    function add_metabox_slideshow(){
    global $wpdb;

    $prefix = ‘_esl_’;

    $cmb = new_cmb2_box(
    array(
    ‘id’ => $prefix . ‘slideshow’,
    ‘title’ => __( ‘Slideshow’, ‘cmb2’ ),
    ‘object_types’ => array(‘hotel’, ‘residence’),
    ‘show_names’ => true
    )
    );

    //load slider from Smart Slider 3 table
    $sliders = $wpdb->get_results( ‘SELECT * FROM hot_nextend2_smartslider3_sliders ORDER BY title’, ARRAY_N );

    $options = array();

    if ( count( $sliders) > 0){
    //slider found
    for ( $i = 0; $i < count($sliders); $i++ ){
    $options[$sliders[$i][0]] = $sliders[$i][1];
    }
    }

    //output Select
    $cmb->add_field( array(
    ‘name’ => ‘slideshow’,
    ‘desc’ => ‘Seleziona uno slider’,
    ‘id’ => ‘_slideshow’,
    ‘type’ => ‘select’,
    ‘show_option_none’ => true,
    ‘default’ => ”,
    ‘options’ => $options,
    ) );

    }

    function add_metabox_mappa(){
    $prefix = ”;

    $cmb = new_cmb2_box(
    array(
    ‘id’ => $prefix . ‘mappa’,
    ‘title’ => __( ‘Mappa’, ‘cmb2’ ),
    ‘object_types’ => array(‘hotel’, ‘residence’),
    ‘show_names’ => true
    )
    );

    AddFieldToMetabox($cmb, $prefix, ‘Mappa’, ‘mappa’, ‘gmap’, ”);
    }

    function add_metabox_attrazione_home(){
    $prefix = ”;

    $cmb = new_cmb2_box(
    array(
    ‘id’ => $prefix . ‘in_home’,
    ‘title’ => __( ‘In home’, ‘cmb2’ ),
    ‘object_types’ => array(‘attrazioni’, ‘eventi’),
    ‘show_names’ => true
    )
    );

    AddFieldToMetabox($cmb, $prefix, ‘In home’, ‘in_home’, ‘checkbox’);
    }

    ?>

Viewing 8 replies - 16 through 23 (of 23 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Thus far, just leaving it alone hasn’t resulted in data loss. I keep checking the database and the key/fields I set are still there.

    Thread Starter crossi72

    (@crossi72)

    You are right: is impossibile that any data you added have been modified by my query.

    I’ll check on my production and development servers if something similar has happened.

    C.

    Thread Starter crossi72

    (@crossi72)

    I’ve got an error on my production server log, the error is

    Access denied with code 400 (phase 2). Pattern match “/xmlrpc\\\\.php$” at REQUEST_URI. [file ***] [line ***] [id ***] [msg “DDoS xmlrpc”] [hostname “www.hoteleresidence.it”] [uri “/xmlrpc.php”]

    It seems an attack, more or less in the same moment my custom postmeta disappeared, maybe this error can be the cause?

    I disable the xmlrpc, is not needed on this site so I had to disable it in origin.

    I’ll let you know if the data will disappear again.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Curious…hopefully that helps take care of the disappearing data issue.

    Thread Starter crossi72

    (@crossi72)

    I found a (big) problem: the field meta_id in table wp_postmeta lost auto_increment attribute, this created those meta_id = 0 all over the table.

    Now I fixed the db problem, I’ll check for further issue.

    Thank again for your support.
    C.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Thanks for the update.

    Thread Starter crossi72

    (@crossi72)

    Everything seems to run smooth now, the origin of the issue was (hopefully) only the wp_postmeta misconfiguration.

    I’m sorry to have wasted your time with a false plugin problem -.-‘

    Thanks for your support.
    C.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    No worries, and no waste time. It was definitely a curious issue, and good to know that that type of thing can happen.

Viewing 8 replies - 16 through 23 (of 23 total)
  • The topic ‘metadata generated from CMB2 disappears from DB’ is closed to new replies.