i tired to fix this
i have problem with redux framework options
options-init.php
Redux::setSection( $opt_name, array(
'title' => __( 'Basic Field', 'redux-framework-demo' ),
'id' => 'basic',
'desc' => __( 'Basic field with no subsections.', 'redux-framework-demo' ),
'icon' => 'el el-home',
'fields' => array(
array(
'id' => 'opt-text',
'type' => 'text',
'title' => __('Text Option - Email Validated', 'redux-framework-demo'),
'subtitle' => __('This is a little space under the Field Title in the Options table, additional info is good in here.', 'redux-framework-demo'),
'desc' => __('This is the description field, again good for additional info.', 'redux-framework-demo'),
'validate' => 'email',
'msg' => 'custom error message',
'default' => 'test#test.com'
)
)
) );
this is my index.php
<h1><?php global $opt_name; echo 'Text value: ' . $opt_name['opt-text']; ?></h1>
i get this error
Warning: Illegal string offset 'opt-text' in C:\xampp\htdocs\wordpress\wp-content\themes\ZoXX\index.php on line 2
Redux hasn't loaded yet. Delay your use of the variable, or run:
Redux::init('OPT_NAME')
Good luck!
Related
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'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
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' ),
),
)
)
)
));
Im trying to add variables instead of custom field IDs in my metaboxes file using this script
I added some options in redux framework to give possibility to change the custom fields.
<?php
/*global from framework*/
global $redux;
/*custom fields options retrieved from redux framework*/
$custom_videourl = $redux['mytheme_videourl'];
$custom_duration = $redux['mytheme_duration'];
$custom_description = $redux['mytheme_desc'];
$fields = array(
array(
'label' => __( 'MP4/FLV & Youtube Url', 'framework' ),
'desc' => __( 'Here you can add videos with mp4 format', 'framework' ),
'id' => $custom_videourl,
'type' => 'text'
),
array(
'label' => __( 'Video Duration', 'framework' ),
'desc' => __( 'Example: 5:20', 'framework' ),
'id' => $custom_duration,
'type' => 'text'
),
array(
'label' => __( 'Video Description', 'framework' ),
'id' => $custom_description,
'desc' => __( 'Here you can write a description', 'framework' ),
'type' => 'editor'
)
);
$my_metaboxes = new custom_add_meta_box( 'mytheme_metaboxes', __( 'Video - Additional Information', 'framework' ), $fields, 'post', true );
But with the above example I got Notice: Array to string conversion in /var/www/html/mytheme/wp-includes/formatting.php on line 1025
So if I add the custom field without variable metaboxes are working fine like below content:
$fields = array(
array(
'label' => __( 'MP4/FLV & Youtube Url', 'framework' ),
'desc' => __( 'Here you can add videos with mp4 format', 'framework' ),
'id' => 'mytheme_videourl',
'type' => 'text'
),
array(
'label' => __( 'Video Duration', 'framework' ),
'desc' => __( 'Example: 5:20', 'framework' ),
'id' => 'mytheme_duration',
'type' => 'text'
),
array(
'label' => __( 'Video Description', 'framework' ),
'id' => 'mytheme_desc',
'desc' => __( 'Here you can write a description', 'framework' ),
'type' => 'editor'
)
);
$my_metaboxes = new custom_add_meta_box( 'mytheme_metaboxes', __( 'Video - Additional Information', 'framework' ), $fields, 'post', true );
I have tried using print_r but metaboxes don't save than. Is there any way to make the first code working? Using variables instead of custom field IDs?
It seems really likely that one of your redux variables contains an Array instead of a String. Knowing that, you just need to figure out which one it is and figure out where the actual piece of data that you are looking for is.
One way you could debug this is to do an explicit conversion of all three of the redux variables to strings. (e.g. 'id' => implode("***", $custom_videourl)). Then, once you've figured out which one (or more than one) is an array, you'll probably know how to access the piece of data you actually want.
If that doesn't do it for you, I would suggest adding this to your wp-config.php file: define( 'WP_DEBUG_LOG', true );
This will create a debug log for you. You can then log out to it (e.g. error_log( print_r( $custom_videourl ) );
I believe it usually stores the debug.log file in the wp-content folder.
i have this custom Metabox field group from https://github.com/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Field-Types#group containing 3 fields and displayed on the Products page template, i want to call the latest posts the client add to display them on my front-page. here is the code of the custom fields.
/**
* Repeatable Field Groups
*/
$meta_boxes['field_group'] = array(
'id' => 'field_group',
'title' => __( 'Manage your products here', 'cmb2' ),
'show_on' => array( 'id' => array( 11, ) ), // Specific post IDs to display this metabox
'object_types' => array( 'page', ),
'fields' => array(
array(
'id' => $prefix . 'repeat_group',
'type' => 'group',
'options' => array(
'group_title' => __( 'Product {#}', 'cmb2' ), // {#} gets replaced by row number
'add_button' => __( 'Add Another Product', 'cmb2' ),
'remove_button' => __( 'Remove Product', 'cmb2' ),
'sortable' => true, // beta
),
'fields' => array(
array(
'name' => 'Product Name',
'id' => 'product_name',
'type' => 'text',
),
array(
'name' => 'Product Description',
'description' => 'Write a short description for this Product',
'id' => 'product_description',
'type' => 'textarea',
),
array(
'name' => 'Product Image',
'id' => 'product_image',
'type' => 'file',
),
),
),
),
);
UPDATE:
i found this http://codex.wordpress.org/Function_Reference/wp_get_recent_posts but i still can't figure out how to make it get the posts from the custom fields