/** * Adds the "content" att to shortcodes on the Widgets page. * * @since 1.0.0 * * @param array $atts The current shortcode's atts. * @param string $code The code of the current shortcode. * @param array $shortcode The current shortcode properties. * @return array The new attributes */ function _render_add_content_to_atts($atts, $code, $shortcode) { if ($shortcode['wrapping']) { $content_att = Render::parse_shortcode_att(array('type' => 'textarea', 'label' => __('Content', 'Render'), 'required' => true)); // Add to repeater here instead for nested shortcodes if (isset($shortcode['render']['nested']['child'])) { $atts['nested_children']['properties']['fields']['content'] = $content_att; // Remove the dummy field, if it's set. Having the content makes it no longer necessary unset($atts['nested_children']['properties']['fields']['dummy_field']); } else { $atts = array_merge(array('content' => $content_att), $atts); } } return $atts; }
/** * Sets up the shortcode attribute's defaults. * * @since 1.1-beta-2 * * @param array $att The att to parse. * @return array The parsed att. */ public static function parse_shortcode_att($att) { // Establish default attribute properties (if any exist) $att = wp_parse_args($att, self::$att_defaults); // Apply defaults to repeater fields as well if (isset($att['properties']['fields'])) { array_walk($att['properties']['fields'], function (&$properties) { $properties = Render::parse_shortcode_att($properties); }); } // Setup conditionals if ($att['conditional'] !== false) { // Flip array key / value and set the value to an empty array for populate conditionals. // This makes it easier when creating the shortcode array because you can input a single // dimensional, non-associative array. if (isset($att['conditional']['populate'])) { $att['conditional']['populate']['atts'] = array_flip($att['conditional']['populate']['atts']); array_walk($att['conditional']['populate']['atts'], function (&$value) { $value = array(); }); } } return $att; }
/** * Outputs the field HTML of the repeater attribute. * * @since 1.0.0 * @access private * * @param string $att_id The attribute ID. * @param array $att Properties of the attribute. * @param array $properties Properties of the attribute field type. */ private static function att_type_repeater($att_id, $att, $properties) { // Setup defaults; $properties = wp_parse_args($properties, array('fields' => array('dummy_field' => array('type' => 'hidden', 'default' => 1)), 'startWith' => 1)); // Add content for nested shortcodes if ($att_id == 'nested_children' && !isset($properties['fields']['content'])) { $properties['fields']['content'] = Render::parse_shortcode_att(array('type' => 'hidden')); } foreach ($properties['fields'] as $field_ID => $field) { $properties['fields'][$field_ID]['disabled'] = true; } for ($i = 0; $i < intval($properties['startWith']) + 1; $i++) { // Make sure the dummy field (the first field) doesn't init any atts if ($i == 0) { foreach ($properties['fields'] as $field_ID => $field) { $properties['fields'][$field_ID]['noInit'] = true; } } else { foreach ($properties['fields'] as $field_ID => $field) { $properties['fields'][$field_ID]['noInit'] = false; } } ?> <div class="render-modal-repeater-field <?php echo $i == 0 ? 'dummy-field' : ''; ?> " <?php echo $i == 0 ? 'style="display:none"' : ''; ?> <?php echo isset($properties['max']) ? "data-max='{$properties['max']}'" : ''; ?> > <?php // Dummy input to trigger field ?> <input type="hidden" name="<?php echo $att_id; ?> " class="render-modal-att-input"/> <div class="render-modal-repeater-inputs"> <?php if (!$properties['fields']) { echo isset($properties['noFields']) ? $properties['noFields'] : __('No fields set'); } else { self::_atts_loop($properties['fields']); } ?> </div> <div class="render-modal-repeater-actions"> <span class="render-modal-repeater-remove render-modal-button dashicons dashicons-minus"></span> <span class="render-modal-repeater-add render-modal-button dashicons dashicons-plus"></span> </div> </div> <?php } }