I'll try to be short:
Multilingual Wordpress site with custom post type registered in functions.php and CMB2 for creating custom forms. The plugin for multilingual is q-translate-x and also using CMB2-qTranslate.
My problem is that I'm losing all line breaks and all <p> tags when I switch the language but it only fails if the editor is contained in a repeatable group. If I add the wysiwyg edit as normal field It works fine.
-Relevant code for the normal field (this works fine):
$cmb_tb->add_field( array(
'name' => esc_html__( 'Historia', 'cmb2' ),
'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'historia',
'type' => 'wysiwyg',
'options' => array( 'textarea_rows' => 5, 'editor_class' => 'cmb2-qtranslate'),
) );
-Relevant code for repeatable field (this loses line breaks and <p> tags on language switching):
<pre><code>
$group_field_id = $cmb_tb->add_field( array(
'id' => 'Fincas',
'type' => 'group',
'description' => __( 'Fincas', 'cmb2' ),
// 'repeatable' => false, // use false if you want non-repeatable group
'options' => array(
'group_title' => __( 'Finca {#}', 'cmb2' ), // since version 1.1.4, {#} gets replaced by row number
'add_button' => __( 'Añadir otra Finca', 'cmb2' ),
'remove_button' => __( 'Eliminar Finca', 'cmb2' ),
// 'sortable' => true, // beta
'closed' => false, // true to have the groups closed by default
),
) );
$cmb_tb->add_group_field($group_field_id, array(
'name' => esc_html__( 'Nombre Finca', 'cmb2' ),
'desc' => esc_html__( '', 'cmb2' ),
'id' => $prefix . 'nombre_finca',
'type' => 'wysiwyg',
'options' => array( 'textarea_rows' => 5, 'editor_class' => 'cmb2-qtranslate')
) );
</code></pre>
This is driving me crazy. I've created a sample website with this problem for testing. I can give access to anyone who feels that can help.
Many thanks in advance.
Finally, I figured out.
It was as easy to add 'wpautop' => false to options array
Related
I have a strange display and I don't know how to display it correctly.
When entering the link looks ok. But after saving it will be a long cryptic link.
In the frontend everything works and looks good.
Where is the mistake?
Backend Picture
Below is the code
function darkteaser_vc_map_init() {
$settings = array(
'name' => __( 'kleine Teaserbox mit Bild', 'js_composer' ), // shortcode name
'base' => 'my_darkteaser_element', // shortcode base [my_darkteaser_element.php]
'category' => __( 'Meine Elemente', 'js_composer' ), // param category tab in add elements view
'icon' => get_template_directory_uri() . '/image/darkteaser.png', // Simply pass url to your icon here
'description' => __( 'kleine Teaserbox mit Bild und Text', 'js_composer' ), // element description in add elements view
'show_settings_on_create' => false,
// don't show params window after adding
'weight' => - 5,
// Depends on ordering in list, Higher weight first
'html_template' => dirname( __FILE__ ) . '/vc_templates/my_darkteaser_element.php',
// if you extend VC within your theme then you don't need this, VC will look for shortcode template in "wp-content/themes/your_theme/vc_templates/my_darkteaser_element.php" automatically. In this example we are extending VC from plugin, so we rewrite template
'front_enqueue_css' => preg_replace( '/\s/', '%20', plugins_url( 'assets/front_enqueue_css.css', __FILE__ ) ),
// This will load extra css file in frontend editor (when you edit page with VC)
'params' => array(
array(
'type' => 'attach_image',
'class' => 'teaserboxPicDunkel',
'heading' => __( 'Bild auswählen', 'js_composer' ),
'param_name' => 'bildteaser',
'value' => __(''),
'description' => 'Bild für Teaserbox hinzufügen.'
),
array(
'type' => 'textarea_html',
'holder' => 'div',
'class' => 'teaserboxtextDunkel',
'heading' => __( 'Text eingeben', 'js_composer' ),
'param_name' => 'content', //param_name for textarea_html must be named "content"
'value' => __( '', 'js_composer' ),
'description' => __( 'Text für Teaserbox.', 'js_composer' )
),
array(
'type' => 'vc_link',
'holder' => 'div',
'class' => 'teaserboxbuttonDunkel',
'heading' => __( 'Link setzen', 'js_composer' ),
'param_name' => 'linkteaser',
'value' => __( '', 'js_composer' ),
'description' => 'Link zur Seite'
),
)
);
vc_map( $settings );
}
add_action('vc_after_init', 'darkteaser_vc_map_init');
I have implemented the CMB2/cmb2-attached-post library in my wordpress installation and created a custom post type in which to use it.
I have implemented the example described in the example-field-setup-php, specifically, in this way:
$example_meta = new_cmb2_box( array(
'id' => 'cmb2_attached_posts_field',
'title' => __( 'Attached Posts', 'yourtextdomain' ),
'object_types' => array( 'luogo' ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
) );
$example_meta->add_field( array(
'name' => __( 'Attached Posts', 'yourtextdomain' ),
'desc' => __( 'Drag ...', 'yourtextdomain' ),
'id' => 'attached_cmb2_attached_posts',
'type' => 'custom_attached_posts',
'column' => true,
'options' => array(
'show_thumbnails' => true,
'filter_boxes' => true,
'query_args' => array(
'posts_per_page' => 10,
'post_type' => 'page',
),
),
) );
$example_meta->add_field( array(
'name' => __( 'Attached Users', 'yourtextdomain' ),
'desc' => __( 'Drag ...', 'yourtextdomain' ),
'id' => 'attached_cmb2_attached_users',
'type' => 'custom_attached_posts',
'column' => true,
'options' => array(
'show_thumbnails' => true,
'filter_boxes' => true,
'query_users' => true,
),
) );
The result I get graphically is this:
Which is visibly broken and malfunctioning.
What I got as a result is the following: (as shown on the library repo).
Why do I get a broken result if the library has been integrated as per the documentation?
Is something missing?
What I have done for use is:
Installing the library with composer and the inclusion of the library in the .php file where I create the custom post type:
require_once ( get_template_directory() . /vendor/webdevstudios/cmb2-attached-posts/init.php' );
This is my first WP plugin. And I have been able to get it working perfectly with the settings page and also showing the shipping method on the checkout page. On a requested feature I need to have another field in my settings page that will have multiple checkboxes to allow users to service types they prefer on their site. This is an example of what I am trying to achieve:
The shot above was taken on from the Woocommerce product settings page. Hence I had to look at the code from WC's files. I found the snippet below but I can't get it to work on my settings page:
array(
'title' => __( 'Enable reviews', 'woocommerce' ),
'desc' => __( 'Enable product reviews', 'woocommerce' ),
'id' => 'woocommerce_enable_reviews',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'show_if_checked' => 'option',
),
array(
'desc' => __( 'Show "verified owner" label on customer reviews', 'woocommerce' ),
'id' => 'woocommerce_review_rating_verification_label',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
'show_if_checked' => 'yes',
'autoload' => false,
),
array(
'desc' => __( 'Reviews can only be left by "verified owners"', 'woocommerce' ),
'id' => 'woocommerce_review_rating_verification_required',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'show_if_checked' => 'yes',
'autoload' => false,
),
All the fields I have currently displayed on my settings page was done in this manner:
$this->form_fields = array(
'is_enabled' => array(
'title' => __('Enable', 'plugin_id'),
'type' => 'checkbox',
'description' => __('Enable this shipping.','plugin_id'),
'default' => 'no'
),
'api_key' => array(
'title' => __('API Key', 'plugin_id'),
'type' => 'text',
'description' => __('Obtain API key from Lastmal DIP','plugin_id'),
'default' => null
),
...
)
How can I add the multiple checkboxes to my fields and save them along with the other settings I have?
I am trying to use Redux inside the wordpress theme and not as a plugin. In functions.php I included both redux-framework.php and sample-config.php .
Now I need to create a repeater field.
From Redux doc, I got the following code to use in order to create a repeater field:
$this->sections[] = array(
'title' => __('Repeater Field', 'redux-framework-demo' ),
'icon' => 'el-icon-thumbs-up',
'fields' => array(
array(
'id' => 'repeater-field-id',
'type' => 'repeater',
'title' => __( 'Title', 'redux-framework-demo' ),
'subtitle' => __( '', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
//'group_values' => true, // Group all fields below within the repeater ID
//'item_name' => '', // Add a repeater block name to the Add and Delete buttons
//'bind_title' => '', // Bind the repeater block title to this field ID
//'static' => 2, // Set the number of repeater blocks to be output
//'limit' => 2, // Limit the number of repeater blocks a user can create
//'sortable' => false, // Allow the users to sort the repeater blocks or not
'fields' => array(
array(
'id' => 'title_field',
'type' => 'text',
'placeholder' => __( 'Title', 'redux-framework-demo' ),
),
array(
'id' => 'text_field',
'type' => 'text',
'placeholder' => __( 'Text Field', 'redux-framework-demo' ),
),
array(
'id' => 'select_field',
'type' => 'select',
'title' => __( 'Select Field', 'redux-framework-demo' ),
'options' => array(
'1' => __( 'Option 1', 'redux-framework-demo' ),
'2' => __( 'Option 2', 'redux-framework-demo' ),
'3' => __( 'Option 3', 'redux-framework-demo' ),
),
'placeholder' => __( 'Listing Field', 'redux-framework-demo' ),
),
)
)
)
);
but if I place the code inside functions.php, what will the $this variable refer to? It'll produce errors. So how to use the snippet so that I can retrieve the values from template files as well?
You have to tried an old version system to create a section. You can try the new version system, I'm not sure if this works or not, but you can try this way:
Redux::setSection($opt_name, array(
'title' => __('Ads Sections', 'cbnews'),
'id' => 'ads-sections',
'desc' => __('You can manage your ads', 'cbnews'),
'icon' => 'dashicons dashicons-dashboard',
'fields' => array(
array(
'id' => 'repeater-field-id',
'type' => 'repeater',
'title' => __( 'Title', 'redux-framework-demo' ),
'subtitle' => __( '', 'redux-framework-demo' ),
'desc' => __( '', 'redux-framework-demo' ),
//'group_values' => true, // Group all fields below within the repeater ID
//'item_name' => '', // Add a repeater block name to the Add and Delete buttons
//'bind_title' => '', // Bind the repeater block title to this field ID
//'static' => 2, // Set the number of repeater blocks to be output
//'limit' => 2, // Limit the number of repeater blocks a user can create
//'sortable' => false, // Allow the users to sort the repeater blocks or not
'fields' => array(
array(
'id' => 'title_field',
'type' => 'text',
'placeholder' => __( 'Title', 'redux-framework-demo' ),
),
array(
'id' => 'text_field',
'type' => 'text',
'placeholder' => __( 'Text Field', 'redux-framework-demo' ),
),
array(
'id' => 'select_field',
'type' => 'select',
'title' => __( 'Select Field', 'redux-framework-demo' ),
'options' => array(
'1' => __( 'Option 1', 'redux-framework-demo' ),
'2' => __( 'Option 2', 'redux-framework-demo' ),
'3' => __( 'Option 3', 'redux-framework-demo' ),
),
'placeholder' => __( 'Listing Field', 'redux-framework-demo' ),
),
)
)
)
));
I have a metabox in my post editor which allows me to pick a single category, I would like this changed to a checkbox where more than one can be picked. I have worked on the following, I would imagine it's a case of changing taxonomy_radio to something like taxonomy_checkbox, however that crashes the metabox completely:
$meta_boxes['test_metabox'] = array(
'id' => 'test_metabox',
'title' => __( 'TEST', 'cmb' ),
'pages' => array( 'post', ),
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
'fields' => array(
array(
'name' => __( 'Category', 'cmb' ),
'desc' => __( 'field description (optional)', 'cmb' ),
'id' => 'test-cat',
'type' => 'taxonomy_radio',
'taxonomy' => 'category'
),
Any help would be great.
Just found out that it needs to be changed to taxonomy_multicheck