function nectar_options_img($image_url) { $image_id = fjarrett_get_attachment_id_from_url($image_url); if (!is_null($image_id) && !empty($image_id)) { $image = wp_get_attachment_image_src($image_id, 'full'); return $image[0]; } else { return $image_url; } }
/** * Field Render Function. * Takes the vars and outputs the HTML for the field in the settings * * @since 1.0.0 * @access public * @return void */ public function render() { $old_options = get_option('salient'); global $salient_redux; // No errors please $defaults = array('id' => '', 'url' => '', 'width' => '', 'height' => '', 'thumbnail' => ''); $this->value = wp_parse_args($this->value, $defaults); //upgrade proof $fixed_ID = $this->field['id']; $legacy_media = !empty($old_options[$fixed_ID]) ? $old_options[$fixed_ID] : '-'; $old_image_id = $legacy_media != '-' ? fjarrett_get_attachment_id_from_url($legacy_media) : '-'; $display_val = isset($salient_redux[$this->field['id']]['id']) || $legacy_media == '-' ? $this->value['id'] : $old_image_id; if (isset($this->field['mode']) && $this->field['mode'] == false) { $this->field['mode'] = 0; } if (!isset($this->field['mode'])) { $this->field['mode'] = "image"; } if (!isset($this->field['library_filter'])) { $libFilter = ''; } else { if (!is_array($this->field['library_filter'])) { $this->field['library_filter'] = array($this->field['library_filter']); } $mimeTypes = get_allowed_mime_types(); $libArray = $this->field['library_filter']; $jsonArr = array(); // Enum mime types foreach ($mimeTypes as $ext => $type) { if (strpos($ext, '|')) { $expArr = explode('|', $ext); foreach ($expArr as $ext) { if (in_array($ext, $libArray)) { $jsonArr[$ext] = $type; } } } elseif (in_array($ext, $libArray)) { $jsonArr[$ext] = $type; } } $libFilter = urlencode(json_encode($jsonArr)); } if (empty($this->value) && !empty($this->field['default'])) { // If there are standard values and value is empty if (is_array($this->field['default'])) { if (!empty($this->field['default']['id'])) { $this->value['id'] = $this->field['default']['id']; } if (!empty($this->field['default']['url'])) { $this->value['url'] = $this->field['default']['url']; } } else { if (is_numeric($this->field['default'])) { // Check if it's an attachment ID $this->value['id'] = $this->field['default']; } else { // Must be a URL $this->value['url'] = $this->field['default']; } } } if (empty($this->value['url']) && !empty($display_val)) { $img = wp_get_attachment_image_src($display_val, 'full'); $this->value['url'] = $img[0]; $this->value['width'] = $img[1]; $this->value['height'] = $img[2]; } $hide = 'hide '; if (isset($this->field['preview']) && $this->field['preview'] === false) { $this->field['class'] .= " noPreview"; } if (!empty($this->field['url']) && $this->field['url'] === true || isset($this->field['preview']) && $this->field['preview'] === false) { $hide = ''; } $placeholder = isset($this->field['placeholder']) ? $this->field['placeholder'] : __('No media selected', 'redux-framework'); $readOnly = ' readonly="readonly"'; if (isset($this->field['readonly']) && $this->field['readonly'] === false) { $readOnly = ''; } echo '<input placeholder="' . $placeholder . '" type="text" class="' . $hide . 'upload large-text ' . $this->field['class'] . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[url]" id="' . $this->parent->args['opt_name'] . '[' . $this->field['id'] . '][url]" value="' . $this->value['url'] . '"' . $readOnly . '/>'; echo '<input type="hidden" class="data" data-mode="' . $this->field['mode'] . '" />'; echo '<input type="hidden" class="library-filter" data-lib-filter="' . $libFilter . '" />'; echo '<input type="hidden" class="upload-id ' . $this->field['class'] . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[id]" id="' . $this->parent->args['opt_name'] . '[' . $this->field['id'] . '][id]" value="' . $display_val . '" />'; echo '<input type="hidden" class="upload-height" name="' . $this->field['name'] . $this->field['name_suffix'] . '[height]" id="' . $this->parent->args['opt_name'] . '[' . $this->field['id'] . '][height]" value="' . $this->value['height'] . '" />'; echo '<input type="hidden" class="upload-width" name="' . $this->field['name'] . $this->field['name_suffix'] . '[width]" id="' . $this->parent->args['opt_name'] . '[' . $this->field['id'] . '][width]" value="' . $this->value['width'] . '" />'; echo '<input type="hidden" class="upload-thumbnail" name="' . $this->field['name'] . $this->field['name_suffix'] . '[thumbnail]" id="' . $this->parent->args['opt_name'] . '[' . $this->field['id'] . '][thumbnail]" value="' . $this->value['thumbnail'] . '" />'; //Preview $hide = ''; if (isset($this->field['preview']) && $this->field['preview'] === false || empty($this->value['url'])) { $hide = 'hide '; } if (empty($this->value['thumbnail']) && !empty($this->value['url'])) { // Just in case if (!empty($display_val)) { $image = wp_get_attachment_image_src($display_val, array(150, 150)); if (empty($image[0]) || $image[0] == '') { $this->value['thumbnail'] = $this->value['url']; } else { $this->value['thumbnail'] = $image[0]; } } else { $this->value['thumbnail'] = $this->value['url']; } } echo '<div class="' . $hide . 'screenshot">'; echo '<a class="of-uploaded-image" href="' . $this->value['url'] . '" target="_blank">'; echo '<img class="redux-option-image" id="image_' . $this->field['id'] . '" src="' . $this->value['thumbnail'] . '" alt="" target="_blank" rel="external" />'; echo '</a>'; echo '</div>'; //Upload controls DIV echo '<div class="upload_button_div">'; //If the user has WP3.5+ show upload/remove button echo '<span class="button media_upload_button" id="' . $this->field['id'] . '-media">' . __('Upload', 'redux-framework') . '</span>'; $hide = ''; if (empty($this->value['url']) || $this->value['url'] == '') { $hide = ' hide'; } echo '<span class="button remove-image' . $hide . '" id="reset_' . $this->field['id'] . '" rel="' . $this->field['id'] . '">' . __('Remove', 'redux-framework') . '</span>'; echo '</div>'; }
function nectar_options_img($image_arr_or_str) { //dummy data import from external if (isset($image_arr_or_str['thumbnail']) && strpos($image_arr_or_str['thumbnail'], 'http://themenectar.com') !== false && $_SERVER['SERVER_NAME'] != 'themenectar.com') { return $image_arr_or_str['thumbnail']; } //check if URL or ID is passed if (isset($image_arr_or_str['id'])) { $image = wp_get_attachment_image_src($image_arr_or_str['id'], 'full'); return $image[0]; } else { if (isset($image_arr_or_str['url'])) { return $image_arr_or_str['url']; } else { $image_id = fjarrett_get_attachment_id_from_url($image_arr_or_str); if (!is_null($image_id) && !empty($image_id)) { $image = wp_get_attachment_image_src($image_id, 'full'); return $image[0]; } else { return $image_arr_or_str; } } } }
/** * Register Option for use * * @since 1.0.0 * @access public * @return void */ public function _register_settings() { // TODO - REMOVE // Not used by new sample-config, but in here for legacy builds // This is bad and can break things. Hehe. if (!function_exists('wp_get_current_user')) { require_once ABSPATH . "wp-includes/pluggable.php"; } if ($this->args['options_api'] == true) { register_setting($this->args['opt_name'] . '_group', $this->args['opt_name'], array($this, '_validate_options')); } if (is_null($this->sections)) { return; } if (empty($this->options_defaults)) { $this->options_defaults = $this->_default_values(); } $runUpdate = false; foreach ($this->sections as $k => $section) { if (isset($section['type']) && $section['type'] == 'divide') { continue; } $display = true; if (isset($_GET['page']) && $_GET['page'] == $this->args['page_slug']) { if (isset($section['panel']) && $section['panel'] == false) { $display = false; } } // DOVY! Replace $k with $section['id'] when ready /** * filter 'redux-section-{index}-modifier-{opt_name}' * * @param array $section section configuration */ $section = apply_filters("redux-section-{$k}-modifier-{$this->args['opt_name']}", $section); /** * filter 'redux/options/{opt_name}/section/{section.id}' * * @param array $section section configuration */ if (isset($section['id'])) { $section = apply_filters("redux/options/{$this->args['opt_name']}/section/{$section['id']}", $section); } if (empty($section)) { unset($this->sections[$k]); continue; } if (!isset($section['title'])) { $section['title'] = ""; } if (isset($section['customizer_only']) && $section['customizer_only'] == true) { $section['panel'] = false; $this->sections[$k] = $section; } $heading = isset($section['heading']) ? $section['heading'] : $section['title']; if (isset($section['permissions'])) { if (!current_user_can($section['permissions'])) { $this->hidden_perm_sections[] = $section['title']; foreach ($section['fields'] as $num => $field_data) { $field_type = $field_data['type']; if ($field_type != 'section' || $field_type != 'divide' || $field_type != 'info' || $field_type != 'raw') { $field_id = $field_data['id']; $default = isset($this->options_defaults[$field_id]) ? $this->options_defaults[$field_id] : ''; $data = isset($this->options[$field_id]) ? $this->options[$field_id] : $default; $this->hidden_perm_fields[$field_id] = $data; } } continue; } } if (!$display || !function_exists('add_settings_section')) { $this->no_panel_section[$k] = $section; } else { add_settings_section($this->args['opt_name'] . $k . '_section', $heading, array(&$this, '_section_desc'), $this->args['opt_name'] . $k . '_section_group'); } $sectionIndent = false; if (isset($section['fields'])) { foreach ($section['fields'] as $fieldk => $field) { if (!isset($field['type'])) { continue; // You need a type! } if ($field['type'] == "info" && isset($field['raw_html']) && $field['raw_html'] == true) { $field['type'] = "raw"; $field['content'] = $field['desc']; $field['desc'] = ""; $this->sections[$k]['fields'][$fieldk] = $field; } else { if ($field['type'] == "info") { if (!isset($field['full_width'])) { $field['full_width'] = true; $this->sections[$k]['fields'][$fieldk] = $field; } } } if ($field['type'] == "raw") { if (isset($field['align'])) { $field['full_width'] = $field['align'] ? false : true; unset($field['align']); } else { if (!isset($field['full_width'])) { $field['full_width'] = true; } } $this->sections[$k]['fields'][$fieldk] = $field; } /** * filter 'redux/options/{opt_name}/field/{field.id}' * * @param array $field field config */ $field = apply_filters("redux/options/{$this->args['opt_name']}/field/{$field['id']}/register", $field); $this->field_types[$field['type']] = isset($this->field_types[$field['type']]) ? $this->field_types[$field['type']] : array(); $this->field_sections[$field['type']][$field['id']] = $k; $display = true; if (isset($_GET['page']) && $_GET['page'] == $this->args['page_slug']) { if (isset($field['panel']) && $field['panel'] == false) { $display = false; } } if (isset($field['customizer_only']) && $field['customizer_only'] == true) { $display = false; } if (isset($section['customizer'])) { $field['customizer'] = $section['customizer']; $this->sections[$k]['fields'][$fieldk] = $field; } if (isset($field['permissions'])) { if (!current_user_can($field['permissions'])) { $data = isset($this->options[$field['id']]) ? $this->options[$field['id']] : $this->options_defaults[$field['id']]; $this->hidden_perm_fields[$field['id']] = $data; continue; } } if (!isset($field['id'])) { echo '<br /><h3>No field ID is set.</h3><pre>'; print_r($field); echo "</pre><br />"; continue; } if (isset($field['type']) && $field['type'] == "section") { if (isset($field['indent']) && $field['indent'] == true) { $sectionIndent = true; } else { $sectionIndent = false; } } if (isset($field['type']) && $field['type'] == "info" && $sectionIndent) { $field['indent'] = $sectionIndent; } $th = $this->get_header_html($field); $field['name'] = $this->args['opt_name'] . '[' . $field['id'] . ']'; // Set the default value if present $this->options_defaults[$field['id']] = isset($this->options_defaults[$field['id']]) ? $this->options_defaults[$field['id']] : ''; // Set the defaults to the value if not present $doUpdate = false; // Check fields for values in the default parameter if (!isset($this->options[$field['id']]) && isset($field['default'])) { $this->options_defaults[$field['id']] = $this->options[$field['id']] = $field['default']; $doUpdate = true; // Check fields that hae no default value, but an options value with settings to // be saved by default } elseif (!isset($this->options[$field['id']]) && isset($field['options'])) { // If sorter field, check for options as save them as defaults if ($field['type'] == 'sorter' || $field['type'] == 'sortable') { $this->options_defaults[$field['id']] = $this->options[$field['id']] = $field['options']; $doUpdate = true; } } // CORRECT URLS if media URLs are wrong, but attachment IDs are present. if ($field['type'] == "media") { if (isset($this->options[$field['id']]['id']) && isset($this->options[$field['id']]['url']) && !empty($this->options[$field['id']]['url']) && strpos($this->options[$field['id']]['url'], str_replace('http://', '', WP_CONTENT_URL)) === false) { $data = wp_get_attachment_url($this->options[$field['id']]['id']); if (isset($data) && !empty($data)) { $this->options[$field['id']]['url'] = $data; $data = wp_get_attachment_image_src($this->options[$field['id']]['id'], array(150, 150)); $this->options[$field['id']]['thumbnail'] = $data[0]; $doUpdate = true; } } } if ($field['type'] == "background") { if (isset($this->options[$field['id']]['media']['id']) && isset($this->options[$field['id']]['background-image']) && !empty($this->options[$field['id']]['background-image']) && strpos($this->options[$field['id']]['background-image'], str_replace('http://', '', WP_CONTENT_URL)) === false) { $data = wp_get_attachment_url($this->options[$field['id']]['media']['id']); if (isset($data) && !empty($data)) { $this->options[$field['id']]['background-image'] = $data; $data = wp_get_attachment_image_src($this->options[$field['id']]['media']['id'], array(150, 150)); $this->options[$field['id']]['media']['thumbnail'] = $data[0]; $doUpdate = true; } } } if ($field['type'] == "slides") { if (isset($this->options[$field['id']]) && is_array($this->options[$field['id']]) && isset($this->options[$field['id']][0]['attachment_id']) && isset($this->options[$field['id']][0]['image']) && !empty($this->options[$field['id']][0]['image']) && strpos($this->options[$field['id']][0]['image'], str_replace('http://', '', WP_CONTENT_URL)) === false) { foreach ($this->options[$field['id']] as $key => $val) { $data = wp_get_attachment_url($val['attachment_id']); if (isset($data) && !empty($data)) { $this->options[$field['id']][$key]['image'] = $data; $data = wp_get_attachment_image_src($val['attachment_id'], array(150, 150)); $this->options[$field['id']][$key]['thumb'] = $data[0]; $doUpdate = true; } } } } // END -> CORRECT URLS if media URLs are wrong, but attachment IDs are present. if (true == $doUpdate && !isset($this->never_save_to_db)) { if ($this->args['save_defaults']) { // Only save that to the DB if allowed to //$runUpdate = true; //upgrade proof global $salient_redux; $theme_options = get_option('salient', array()); if (empty($salient_redux) && !empty($theme_options)) { $redux = ReduxFrameworkInstances::get_instance('salient_redux'); foreach ($theme_options as $k => $v) { $redux->set($k, $v); } //updates fonts separate due to different formatting $font_fields = array('navigation_font_family', 'navigation_dropdown_font_family', 'page_heading_font_family', 'page_heading_subtitle_font_family', 'off_canvas_nav_font_family', 'off_canvas_nav_subtext_font_family', 'body_font_family', 'h1_font_family', 'h2_font_family', 'h3_font_family', 'h4_font_family', 'h5_font_family', 'h6_font_family', 'i_font_family', 'label_font_family', 'nectar_slider_heading_font_family', 'home_slider_caption_font_family', 'testimonial_font_family', 'sidebar_footer_h_font_family', 'team_member_h_font_family', 'nectar_dropcap_font_family'); foreach ($font_fields as $k => $v) { $family = isset($theme_options[str_replace('_family', '', $v)]) && $theme_options[str_replace('_family', '', $v)] != '-' ? $theme_options[str_replace('_family', '', $v)] : ''; $size = isset($theme_options[str_replace('_family', '', $v) . '_size']) && $theme_options[str_replace('_family', '', $v) . '_size'] != '-' ? $theme_options[str_replace('_family', '', $v) . '_size'] : ''; $height = isset($theme_options[str_replace('_family', '', $v) . '_line_height']) && $theme_options[str_replace('_family', '', $v) . '_line_height'] != '-' ? $theme_options[str_replace('_family', '', $v) . '_line_height'] : ''; $spacing = isset($theme_options[str_replace('_family', '', $v) . '_spacing']) && $theme_options[str_replace('_family', '', $v) . '_spacing'] != '-' ? $theme_options[str_replace('_family', '', $v) . '_spacing'] : ''; $transform = isset($theme_options[str_replace('_family', '', $v) . '_transform']) && $theme_options[str_replace('_family', '', $v) . '_transform'] != '-' ? $theme_options[str_replace('_family', '', $v) . '_transform'] : ''; $style = ''; $weight = ''; if (isset($theme_options[str_replace('_family', '', $v) . '_style']) && $theme_options[str_replace('_family', '', $v) . '_style'] != '-') { $font_style = $theme_options[str_replace('_family', '', $v) . '_style']; if (strpos($font_style, '0italic') !== false) { $weight = str_replace('italic', '', $font_style); $style = 'italic'; } else { if (strpos($font_style, 'italic') !== false) { $weight = '400'; $style = 'italic'; } else { if ($font_style == 'regular') { $weight = '400'; $style = ''; } else { $weight = $font_style; $style = ''; } } } } $font_arr = array('font-family' => $family, 'font-size' => $size, 'line-height' => $height, 'letter-spacing' => $spacing, 'font-weight' => $weight, 'text-transform' => $transform, 'font-style' => $style); $redux->set($v, $font_arr); } //images separately too $image_fields = array('favicon', 'background_image', 'logo', 'retina-logo', 'header-starting-logo', 'header-starting-retina-logo', 'header-starting-logo-dark', 'header-starting-retina-logo-dark', 'loading-image'); foreach ($image_fields as $k => $v) { if (isset($theme_options[$v]) && $theme_options[$v] != '' && strpos($theme_options[$v], ".") !== false) { $img_id = fjarrett_get_attachment_id_from_url($theme_options[$v]); $img_arr = array('id' => $img_id, 'height' => '', 'width' => '', 'thumbnail' => $theme_options[$v], 'url' => $theme_options[$v]); $redux->set($v, $img_arr); } } } else { $runUpdate = true; } } // elseif($this->saved != '' && $this->saved != false) { // $runUpdate = true; //} } if (!isset($field['class'])) { // No errors please $field['class'] = ""; } $id = $field['id']; /** * filter 'redux-field-{field.id}modifier-{opt_name}' * * @deprecated * * @param array $field field config */ $field = apply_filters("redux-field-{$field['id']}modifier-{$this->args['opt_name']}", $field); // REMOVE LATER /** * filter 'redux/options/{opt_name}/field/{field.id}' * * @param array $field field config */ $field = apply_filters("redux/options/{$this->args['opt_name']}/field/{$field['id']}", $field); if (empty($field) || !$field || $field == false) { unset($this->sections[$k]['fields'][$fieldk]); continue; } if (!empty($this->folds[$field['id']]['parent'])) { // This has some fold items, hide it by default $field['class'] .= " fold"; } if (!empty($this->folds[$field['id']]['children'])) { // Sets the values you shoe fold children on $field['class'] .= " foldParent"; } if (!empty($field['compiler'])) { $field['class'] .= " compiler"; $this->compiler_fields[$field['id']] = 1; } if (isset($field['unit']) && !isset($field['units'])) { $field['units'] = $field['unit']; unset($field['unit']); } $this->sections[$k]['fields'][$fieldk] = $field; if (isset($this->args['display_source'])) { $th .= '<div id="' . $field['id'] . '-settings" style="display:none;"><pre>' . var_export($this->sections[$k]['fields'][$fieldk], true) . '</pre></div>'; $th .= '<br /><a href="#TB_inline?width=600&height=800&inlineId=' . $field['id'] . '-settings" class="thickbox"><small>View Source</small></a>'; } /** * action 'redux/options/{opt_name}/field/field.type}/register' */ do_action("redux/options/{$this->args['opt_name']}/field/{$field['type']}/register", $field); $this->check_dependencies($field); $this->field_head[$field['id']] = $th; if (!$display || isset($this->no_panel_section[$k])) { $this->no_panel[] = $field['id']; } else { if (isset($field['hidden']) && $field['hidden']) { $field['label_for'] = 'redux_hide_field'; } if ($this->args['options_api'] == true) { add_settings_field("{$fieldk}_field", $th, array(&$this, '_field_input'), "{$this->args['opt_name']}{$k}_section_group", "{$this->args['opt_name']}{$k}_section", $field); } } } } } /** * action 'redux-register-settings-{opt_name}' * * @deprecated */ do_action("redux-register-settings-{$this->args['opt_name']}"); // REMOVE /** * action 'redux/options/{opt_name}/register' * * @param array option sections */ do_action("redux/options/{$this->args['opt_name']}/register", $this->sections); if ($runUpdate && !isset($this->never_save_to_db)) { // Always update the DB with new fields $this->set_options($this->options); //$this->ajax_save(); } if (isset($this->transients['run_compiler']) && $this->transients['run_compiler']) { $this->no_output = true; $this->_enqueue_output(); /** * action 'redux-compiler-{opt_name}' * * @deprecated * * @param array options * @param string CSS that get sent to the compiler hook */ do_action("redux-compiler-{$this->args['opt_name']}", $this->options, $this->compilerCSS, $this->transients['changed_values']); // REMOVE /** * action 'redux/options/{opt_name}a' * * @param array options * @param string CSS that get sent to the compiler hook */ do_action("redux/options/{$this->args['opt_name']}/compiler", $this->options, $this->compilerCSS, $this->transients['changed_values']); /** * action 'redux/options/{opt_name}/compiler/advanced' * * @param array options * @param string CSS that get sent to the compiler hook, which sends the full Redux object */ do_action("redux/options/{$this->args['opt_name']}/compiler/advanced", $this); unset($this->transients['run_compiler']); $this->set_transients(); } }