I have a own option-page in the backend-sidebar with this repeatable fields in it. (not a metabox) I cant figure out, how to display the data from the group field in the frontend.
function ww_register_theme_options() {
$ww_prefix = '_ww_';
$ww_contacts = new_cmb2_box( array(
'id' => $ww_prefix . 'ww_option_plugin',
'title' => esc_html__( 'Ansprechpartner', 'ww-contact' ),
'icon_url' => '/wp-content/plugins/ww-contact/assets/images/icons/ww-icon-white.png',
'object_types' => array( 'options-page' ),
'option_key' => 'ww_options',
) );
$ww_group_field = $ww_contacts->add_field(array(
'id' => $ww_prefix . 'contact_repeat_group',
'type' => 'group',
'description' => __('Ansprechparter Liste', 'ww-contact'),
'repeatable' => true,
'options' => array(
'group_title' => 'Ansprechpartner {#}',
'add_button' => __('neuer Ansprechpartner', 'ww-contact'),
'remove_button' => __('Entfernen', 'ww-contact'),
'sortable' => true,
),
));
$ww_contacts->add_group_field($ww_group_field, array(
'name' => 'Vorname',
'id' => $ww_prefix . 'forname',
'type' => 'text',
));
$ww_contacts->add_group_field($ww_group_field, array(
'name' => 'Vorname',
'id' => $ww_prefix . 'surname',
'type' => 'text',
));
}
Remove the prefix from your add_group_field ids they aren't needed. Then loop through like so...
$entries = get_post_meta( $parent, 'ww_contact_repeat_group', true );
if($entries){
foreach ( (array) $entries as $key => $entry ) {
if ( isset( $entry['forname'] ) ) {
$forname = $entry['forname'];
}
}
}
Related
I want to import a large quantity of products, the plugin is there and everything works, but I want to replace one word (different) in the product names with another word. 32,000 products, one product cannot be made.
I've tried different options, the only one that doesn't get into the wordpress error is the code below, but it doesn't work, I won't actually import the products.
** part between invalid
protected function generate_product_data($product){
$categories = array_values(array_unique(array_map('trim', explode('>', $product['Category']))));
$sku_prefix = get_option(PREFIX . '_sku_prefix', '');
$images = $this->get_images($product);
$sku_raw = $product['SKU'];
$sku = empty($sku_prefix) ? $sku_raw : "{$sku_prefix}{$sku_raw}";
$webshop_price = empty(Utility::rgar($product, 'Webshop_price')) ? null : Utility::clean_price( $product['Webshop_price'] );
$drop_price = empty(Utility::rgar($product, 'drop_Price')) ? $webshop_price : Utility::clean_price( $product['drop_Price'] );
$price = $this->get_price($product);
**
function replace_text($replace){
$replace = str_replace("badword", "goodword",$replace);
$replace = str_replace("badword1", "goodword1",$replace);
return $replace;}
$data = array(
'title' => $product[replace_text('Product_title')],**
'description' => $product['HTML_description'],
'excerpt' => $product['Properties'],
'categories' => $categories,
'images' => $images,
'attributes' => array(
'Color' => $product['Color'],
'Gender' => $product['Gender'],
'Diameter' => Product::measurements_number( $product['Diameter'] ),
'Size' => Product::measurements_number( $product['Size'] ),
'Shipping_time' => $this->get_shipping_time($product),
'Number_of_packages' => $product['Number_of_packages'],
),
'meta' => array(
'_regular_price' => $price,
'_price' => $price,
'B2B_price' => Utility::clean_price( $product['B2B_price'] ),
'RRP_price' => Utility::clean_price( $product['RRP'] ),
'drop_price' => $drop_price,
'_sku' => $sku,
'_manage_stock' => 'yes',
'_stock' => $product['Stock'],
'_stock_status' => $product['Stock'] == '0' ? 'outofstock' : 'instock',
'_weight' => Product::measurements_number( $product['Weight'] ),
PREFIX . '_ean' => $product['EAN'],
PREFIX . '_sku_raw' => $sku_raw,
PREFIX . '_image_urls' => $images,
PREFIX . '_shipping_time' => $this->get_shipping_time($product),
PREFIX . '_parcel_or_pallet' => $product['Parcel_or_pallet'],
PREFIX . '_number_of_packages' => $product['Number_of_packages'],
)
);
return $data;
}
How do I hide/display a link in BuddyPress toolbar if the user has a particular role?
function your_bp_admin_bar_add() {
global $wp_admin_bar, $bp;
if ( !bp_use_wp_admin_bar() || defined( 'DOING_AJAX' ) )
return;
$user_domain = bp_loggedin_user_domain();
if (current_user_can('lp_teacher')) {
$wp_admin_bar->add_menu( array(
'parent' => $bp->my_account_menu_id,
'id' => 'my-create-course',
'title' => __( 'Create Course', 'your-plugin-domain' ),
'href' => trailingslashit( 'https://mywebsite.com/wp-admin/post-new.php?post_type=lp_course&tab=course_settings' ),
'meta' => array( 'class' => 'menupop' )
) );
}
$wp_admin_bar->add_menu( array(
'parent' => $bp->my_account_menu_id,
'id' => 'my-account-dogs',
'title' => __( 'Become an Instructor', 'your-plugin-domain' ),
'href' => trailingslashit( 'https://mywebsite.com/become-a-teacher-2/' ),
'meta' => array( 'class' => 'menupop' )
) );
}
add_action( 'bp_setup_admin_bar', 'your_bp_admin_bar_add', 300 );
I don't understand why it only displays Become an Instructor even when the logged-in user is an instructor. It is supposed to display Create Course.
I don't understand why it only displays Become an Instructor even when the logged-in user is an instructor.
Are you sure that the role / capability for instructors is lp_teacher?
If you want to only show Create Course to instructors, then try adding an else:
if (current_user_can('lp_teacher')) {
$wp_admin_bar->add_menu( array(
'parent' => $bp->my_account_menu_id,
'id' => 'my-create-course',
'title' => __( 'Create Course', 'your-plugin-domain' ),
'href' => trailingslashit( 'https://mywebsite.com/wp-admin/post-new.php?post_type=lp_course&tab=course_settings' ),
'meta' => array( 'class' => 'menupop' )
) );
} else {
$wp_admin_bar->add_menu( array(
'parent' => $bp->my_account_menu_id,
'id' => 'my-account-dogs',
'title' => __( 'Become an Instructor', 'your-plugin-domain' ),
'href' => trailingslashit( 'https://mywebsite.com/become-a-teacher-2/' ),
'meta' => array( 'class' => 'menupop' )
) );
}
I don't understand how the genesis_markup function turns:
array(
'open' => '<aside class="widget-areainfo-onder-content">',
'context' => 'widget-area-wrap',
'echo' => false,
'params' => array(
'id' => $id,
)
into
"<div class="widget-area">"
I do not understand why the id is not used in the output at all and the aside class is also not used....I would have thought that it should be.....
When I do this in the code:
$before_markup_args = array(
'open' => '<aside class="widget-areainfo-onder-content">',
'context' => 'widget-area-wrap',
'echo' => false,
'params' => array(
'id' => $id,
)
);
d($before_markup_args);
d(genesis_markup( $before_markup_args ));
First, I would like to confirm the missing space:
```
$before_markup_args = array(
'open' => '<aside class="widget-area info-onder-content">',
'context' => 'widget-area-wrap',
'echo' => false,
'params' => array(
'id' => $id,
)
);
```
"Onder" is Dutch for "Below". Thus, "info-onder-content" means "info-below-content". Possibly a title for the widget area.
This is a code example that is used for the genesis_widget_area function, typically found in a functions.php file in a WordPress Genesis child theme.
$widget_area_args = array('before' => genesis_markup($before_markup_args),
);
genesis_widget_area($id, $widget_area_args);
We can understand how this works by looking up the definition of the genesis_widget_area function in the /var/www/html/wp-content/themes/genesis/lib/functions/widgetize.php file.
function genesis_widget_area( $id, $args = array() ) {
if ( ! $id ) {
return false;
}
$defaults = apply_filters(
'genesis_widget_area_defaults',
array(
'before' => genesis_markup(
array(
'open' => '<aside class="widget-area">' . genesis_sidebar_title( $id ),
'context' => 'widget-area-wrap',
'echo' => false,
'params' => array(
'id' => $id,
),
)
),
'after' => genesis_markup(
array(
'close' => '</aside>',
'context' => 'widget-area-wrap',
'echo' => false,
)
),
'default' => '',
'show_inactive' => 0,
'before_sidebar_hook' => 'genesis_before_' . $id . '_widget_area',
'after_sidebar_hook' => 'genesis_after_' . $id . '_widget_area',
),
$id,
$args
);
$args = wp_parse_args( $args, $defaults );
if ( ! $args['show_inactive'] && ! is_active_sidebar( $id ) ) {
return false;
}
Adding OptionTree pages is simple with the code below, but does anyone know how to retrieve the stored data?
/**
* Hook to register admin pages
*/
add_action( 'init', 'register_options_pages' );
/**
* Registers all the required admin pages.
*/
function register_options_pages() {
// Only execute in admin & if OT is installed
if ( is_admin() && function_exists( 'ot_register_settings' ) ) {
// Register the pages
ot_register_settings(
array(
array(
'id' => 'custom_options',
'pages' => array(
array(
'id' => 'test_page',
'parent_slug' => 'options-general.php',
'page_title' => 'Test Page',
'menu_title' => 'Test Page',
'capability' => 'edit_theme_options',
'menu_slug' => 'test-page',
'icon_url' => null,
'position' => null,
'updated_message' => 'Test Page updated.',
'reset_message' => 'Test Page reset.',
'button_text' => 'Save Changes',
'show_buttons' => true,
'screen_icon' => 'options-general',
'contextual_help' => null,
'sections' => array(
array(
'id' => 'test_section',
'title' => __( 'Test Section', 'motif-core' )
)
),
'settings' => array(
array(
'id' => 'test_section_input',
'label' => 'Test Input',
'desc' => 'Pretty freaking awesome!',
'std' => '',
'type' => 'text',
'section' => 'test_section',
'class' => ''
)
)
)
)
)
)
);
I tried this $my_plugin_options = get_option('custom_options'); but it only shows the word 'array' on the front end?
This is how to retrieve the stored data:
$my_plugin_options = get_option('custom_options');
echo $my_plugin_options['test_section_input'];
I want to add a custom field options to checkout page. I am using the following code :
$fields['billing']['billing_options'] = array(
'label' => __('Options', 'woocommerce'),
'placeholder' => _x('', 'placeholder', 'woocommerce'),
'required' => false,
'clear' => false,
'type' => 'select',
'options' => array(
'option_a' => __('option a', 'woocommerce' ),
'option_b' => __('option b', 'woocommerce' )
)
);
I want to show the options (option_a,option_b) from database or
I want to use dynamic data and want to use for loop in the options menu
How can I use for loop inside this function ?
Just do it before, like this:
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function my_custom_checkout_fields( $fields ) {
$args = array(
'post_type' => array('options'),
'posts_per_page' => -1
);
$posts = new WP_Query($args);
$options = array();
foreach ($posts as $post) {
$options[$post->ID] => attr_esc($post->post_title);
}
$fields['billing']['billing_options'] = array(
'label' => __('Options', 'woocommerce'),
'placeholder' => _x('', 'placeholder', 'woocommerce'),
'required' => false,
'clear' => false,
'type' => 'select',
'options' => $options
);
return $fields;
}