Ejemplo n.º 1
0
    /**
     * Display the logo or site title
     */
    function siteorigin_north_display_logo()
    {
        $logo = siteorigin_setting('branding_logo');
        if (!empty($logo)) {
            $logo_id = attachment_url_to_postid($logo);
            $attrs = apply_filters('siteorigin_north_logo_attributes', array());
            ?>
<a href="<?php 
            echo esc_url(home_url('/'));
            ?>
" rel="home"><?php 
            echo wp_get_attachment_image($logo_id, 'full', false, $attrs);
            ?>
</a><?php 
        } else {
            ?>
<h1 class="site-title"><a href="<?php 
            echo esc_url(home_url('/'));
            ?>
" rel="home"><?php 
            bloginfo('name');
            ?>
</a></h1><?php 
        }
    }
Ejemplo n.º 2
0
function jr_mt_convert_url_arrays($settings)
{
    global $jr_mt_url_types;
    foreach ($jr_mt_url_types as $setting_key) {
        if (isset($settings[$setting_key]) && is_array($settings[$setting_key])) {
            foreach ($settings[$setting_key] as $url_key => $url_array) {
                $url = $url_array['url'];
                if (jr_mt_same_prefix_url(JR_MT_HOME_URL, $url)) {
                    $new_url_array['url'] = $url_array['url'];
                    $new_url_array['theme'] = $url_array['theme'];
                    $rel_url = jr_mt_relative_url($url, JR_MT_HOME_URL);
                    $new_url_array['rel'] = $rel_url;
                    /*	Create the URL Prep array for each of the current Site Aliases,
                    				including the Current Site URL
                    			*/
                    $new_url_array['prep'] = array();
                    foreach ($settings['aliases'] as $index => $alias) {
                        $new_url_array['prep'][] = jr_mt_prep_url($alias['url'] . '/' . $rel_url);
                    }
                    /*	Only for URL type Setting, not Prefix types.
                     */
                    if ('url' === $setting_key) {
                        /*	Try and figure out ID and WordPress Query Keyword for Type, if possible and relevant
                         */
                        if (0 === ($id = url_to_postid($url)) && version_compare(get_bloginfo('version'), '4', '>=')) {
                            $id = attachment_url_to_postid($url);
                        }
                        if (!empty($id)) {
                            $new_url_array['id'] = (string) $id;
                            if (NULL !== ($post = get_post($id))) {
                                switch ($post->post_type) {
                                    case 'post':
                                        $new_url_array['id_kw'] = 'p';
                                        break;
                                    case 'page':
                                        $new_url_array['id_kw'] = 'page_id';
                                        break;
                                    case 'attachment':
                                        $new_url_array['id_kw'] = 'attachment_id';
                                        break;
                                }
                            }
                        }
                    }
                    $settings[$setting_key][$url_key] = $new_url_array;
                } else {
                    /*	Error:
                    				Cannot convert, as URL is from a different Site Home URL,
                    				so have to delete this URL entry.
                    			*/
                    unset($settings[$setting_key][$url_key]);
                    jr_mt_messages('Setting deleted during Conversion to Version 6 format because Site URL has changed');
                }
            }
        }
    }
    return $settings;
}
Ejemplo n.º 3
0
 /**
  * Display widget content on frontend
  *
  * @param array  $data
  * @param string $id
  * @param int    $number
  */
 public static function render_widget(array $data, $id, $number)
 {
     if (!empty($data['video'])) {
         echo wp_oembed_get($data['video']);
     }
     if (!empty($data['thumbnail']) && ($image_id = absint(attachment_url_to_postid($data['thumbnail']))) && wp_attachment_is_image($image_id)) {
         echo wp_get_attachment_image($image_id, 'medium');
     }
 }
 /**
  * Refresh the parameters passed to the JavaScript via JSON.
  *
  * @since 3.4.0
  *
  * @uses WP_Customize_Media_Control::to_json()
  */
 public function to_json()
 {
     parent::to_json();
     $value = $this->value();
     if ($value) {
         // Get the attachment model for the existing file.
         $attachment_id = attachment_url_to_postid($value);
         if ($attachment_id) {
             $this->json['attachment'] = wp_prepare_attachment_for_js($attachment_id);
         }
     }
 }
Ejemplo n.º 5
0
    /**
     * Front-end display of widget.
     *
     * @see WP_Widget::widget()
     *
     * @param array $args     Widget arguments.
     * @param array $instance Saved values from database.
     */
    public function widget($args, $instance)
    {
        extract($args);
        extract($instance);
        $client_image = empty($instance['client_image']) ? false : $instance['client_image'];
        $client_name = empty($instance['client_name']) ? false : $instance['client_name'];
        $client_designation = empty($instance['client_designation']) ? false : $instance['client_designation'];
        $client_testimonial = empty($instance['client_testimonial']) ? false : $instance['client_testimonial'];
        $img_id = attachment_url_to_postid($client_image);
        $image = wp_get_attachment_image_src($img_id, 'accesspress-basic-testimonial-thumbnail');
        echo $before_widget;
        ?>
                <div class="testimonials-wrap clearfix">
                    <figure class="testimonial-image-wrap">
                        <div class="testimonial-img">
                            <?php 
        if (!empty($image[0])) {
            ?>
                                <img src="<?php 
            echo $image[0];
            ?>
" />
                            <?php 
        } else {
            ?>
                                <img src="<?php 
            echo get_template_directory_uri() . '/images/no-testimonial-thumbnail.png';
            ?>
" />
                            <?php 
        }
        ?>
                        </div>
                        <span class="client-name"><?php 
        echo esc_attr($client_name);
        ?>
</span>
                        <span class="client-designation"><?php 
        echo esc_attr($client_designation);
        ?>
</span>                            
                    </figure>
                    <div class="testimonial">
                        <?php 
        echo esc_textarea($client_testimonial);
        ?>
                    </div>
                </div>
            <?php 
        echo $after_widget;
    }
 protected function create_image()
 {
     $attachment_id = attachment_url_to_postid($this->main_image_url);
     if (!$attachment_id) {
         die(__('Unknown attachment.', 'crb'));
     }
     $image_sizes = Helper::get_image_sizes();
     $image_size_name = $this->find_attachment_image_size($attachment_id, $this->requested_image_width, $this->requested_image_height);
     if (empty($image_size_name) || empty($image_sizes[$image_size_name])) {
         die(__('Unknown image size.', 'crb'));
     }
     $image_details = Helper::get_image_src($attachment_id, $image_size_name);
     $this->new_image_url = $image_details['src'];
     $this->new_image_path = str_replace($this->upload_dir['baseurl'], $this->upload_dir['basedir'], $this->new_image_url);
     return $this;
 }
 public static function extract_from_attachment_metadata($dimensions, $url)
 {
     if (is_array($dimensions)) {
         return $dimensions;
     }
     $url = strtok($url, '?');
     $attachment_id = attachment_url_to_postid($url);
     if (empty($attachment_id)) {
         return false;
     }
     $metadata = wp_get_attachment_metadata($attachment_id);
     if (!$metadata) {
         return false;
     }
     return array($metadata['width'], $metadata['height']);
 }
Ejemplo n.º 8
0
 /**
  * Convert markdown image to html image tag
  *
  * @return string
  */
 public function convert()
 {
     $time = get_the_time('Y/m', $this->post_id);
     $wp_upload_dir = wp_upload_dir($time, $this->post_id);
     $this->upload_url = untrailingslashit($wp_upload_dir['url']);
     return preg_replace_callback('/\\!\\[(.*?)\\]\\((.+?)\\)/sm', function ($matches) {
         $pathinfo = pathinfo($matches[2]);
         $Unicode_Normalization = new Markdown_Importer_Unicode_Normalization($matches[2]);
         $filename = $Unicode_Normalization->convert();
         $filename = sha1($filename) . '.' . $pathinfo['extension'];
         $attachment_url = $this->upload_url . '/' . $filename;
         $attachment_id = attachment_url_to_postid($attachment_url);
         $full = wp_get_attachment_image_url($attachment_id, 'full');
         $large = wp_get_attachment_image_url($attachment_id, 'large');
         if (!$full || !$large) {
             return;
         }
         return sprintf('<a class="markdown-importer-image-link" href="%1$s"><img class="size-large wp-image-%2$d markdown-importer-image" src="%3$s" alt="%4$s" /></a>', esc_url($full), esc_attr($attachment_id), esc_url($large), esc_attr($matches[1]));
     }, $this->content);
 }
Ejemplo n.º 9
0
 /**
  * Overwrites the `update()` method so we can save some extra data.
  *
  * @since  3.0.0
  * @access public
  * @param  string  $value
  * @return string
  */
 protected function update($value)
 {
     if ($value) {
         $post_id = attachment_url_to_postid($value);
         if ($post_id) {
             $image = wp_get_attachment_image_src($post_id);
             if ($image) {
                 // Set up a custom array of data to save.
                 $data = array('url' => esc_url_raw($image[0]), 'width' => absint($image[1]), 'height' => absint($image[2]), 'id' => absint($post_id));
                 set_theme_mod("{$this->id_data['base']}_data", $data);
             }
         }
     }
     // No media? Remove the data mod.
     if (empty($value) || empty($post_id) || empty($image)) {
         remove_theme_mod("{$this->id_data['base']}_data");
     }
     // Let's send this back up and let the parent class do its thing.
     return parent::update($value);
 }
 /**
  * Refresh the parameters passed to the JavaScript via JSON.
  *
  *
  * highly based on WP_Customize_Media_Control merged with WP_Customize_Upload_Control ::to_json()
  */
 public function to_json()
 {
     $this->json['mime_type'] = $this->mime_type;
     $this->json['button_labels'] = $this->button_labels;
     $this->json['bg_repeat_options'] = $this->bg_repeat_options;
     $this->json['bg_attachment_options'] = $this->bg_attachment_options;
     $this->json['bg_position_options'] = $this->bg_position_options;
     $this->json['canUpload'] = current_user_can('upload_files');
     $this->json['default_model'] = $this->default_model;
     $value = $this->value();
     if (isset($this->setting) && is_object($this->setting)) {
         $_defaults = isset($this->setting->default) ? $this->setting->default : null;
         $default_bg_img = isset($_defaults['background-image']) ? $_defaults['background-image'] : null;
     }
     $default_bg_im = isset($default_bg_img) ? $default_bg_img : null;
     if ($default_bg_img) {
         // Fake an attachment model - needs all fields used by template.
         // Note that the default value must be a URL, NOT an attachment ID.
         $type = in_array(substr($default_bg_img, -3), array('jpg', 'png', 'gif', 'bmp', 'svg')) ? 'image' : 'document';
         $default_attachment = array('id' => 1, 'url' => $default_bg_img, 'type' => $type, 'icon' => wp_mime_type_icon($type), 'title' => basename($default_bg_img));
         $default_attachment['sizes'] = array('full' => array('url' => $default_bg_img));
         $this->json['defaultAttachment'] = $default_attachment;
     }
     $background_image = isset($value['background-image']) ? $value['background-image'] : null;
     if ($background_image && $default_bg_img && $background_image === $default_bg_img) {
         // Set the default as the attachment.
         $this->json['attachment'] = $this->json['defaultAttachment'];
     } elseif ($background_image) {
         $attachment_id = attachment_url_to_postid($background_image);
         if ($attachment_id) {
             $this->json['attachment'] = wp_prepare_attachment_for_js($attachment_id);
         } else {
             //already an id
             $this->json['attachment'] = wp_prepare_attachment_for_js($background_image);
         }
     }
     parent::to_json();
 }
 /**
  * Refresh the parameters passed to the JavaScript via JSON.
  *
  *
  * @Override
  * @see WP_Customize_Control::to_json()
  */
 public function to_json()
 {
     parent::to_json();
     $this->json['title'] = !empty($this->title) ? esc_html($this->title) : '';
     $this->json['notice'] = !empty($this->notice) ? $this->notice : '';
     $this->json['dst_width'] = isset($this->dst_width) ? $this->dst_width : $this->width;
     $this->json['dst_height'] = isset($this->dst_height) ? $this->dst_height : $this->height;
     //overload WP_Customize_Upload_Control
     //we need to re-build the absolute url of the logo src set in old Customizr
     $value = $this->value();
     if ($value) {
         //re-build the absolute url if the value isn't an attachment id before retrieving the id
         if ((int) esc_attr($value) < 1) {
             $upload_dir = wp_upload_dir();
             $value = false !== strpos($value, '/wp-content/') ? $value : $upload_dir['baseurl'] . $value;
         }
         // Get the attachment model for the existing file.
         $attachment_id = attachment_url_to_postid($value);
         if ($attachment_id) {
             $this->json['attachment'] = wp_prepare_attachment_for_js($attachment_id);
         }
     }
     //end overload
 }
Ejemplo n.º 12
0
Archivo: media.php Proyecto: nkeat12/dv
 /**
  * @ticket 31044
  */
 function test_attachment_url_to_postid_with_empty_url()
 {
     $post_id = attachment_url_to_postid('');
     $this->assertInternalType('int', $post_id);
     $this->assertEquals(0, $post_id);
 }
Ejemplo n.º 13
0
/**
 * @package Accesspress Pro
 */
function accesspress_basic_widgets_show_widget_field($instance = '', $widget_field = '', $athm_field_value = '')
{
    // Store Posts in array
    $accesspress_pro_postlist[0] = array('value' => 0, 'label' => '--choose--');
    $arg = array('posts_per_page' => -1);
    $accesspress_pro_posts = get_posts($arg);
    $i = 1;
    foreach ($accesspress_pro_posts as $accesspress_pro_post) {
        $accesspress_pro_postlist[$accesspress_pro_post->ID] = array('value' => $accesspress_pro_post->ID, 'label' => $accesspress_pro_post->post_title);
        $i++;
    }
    $accesspress_basic_pagelist[0] = array('value' => 0, 'label' => '--choose--');
    $accesspress_basic_pages = get_pages($arg);
    foreach ($accesspress_basic_pages as $accesspress_basic_page) {
        $accesspress_basic_pagelist[$accesspress_basic_page->ID] = array('value' => $accesspress_basic_page->ID, 'label' => $accesspress_basic_page->post_title);
    }
    //print_r($widget_field);
    extract($widget_field);
    switch ($apbasic_widgets_field_type) {
        // Standard text field
        case 'text':
            ?>
			<p>
				<label for="<?php 
            echo $instance->get_field_id($apbasic_widgets_name);
            ?>
"><?php 
            echo $apbasic_widgets_title;
            ?>
:</label>
				<input class="widefat" id="<?php 
            echo $instance->get_field_id($apbasic_widgets_name);
            ?>
" name="<?php 
            echo $instance->get_field_name($apbasic_widgets_name);
            ?>
" type="text" value="<?php 
            echo $athm_field_value;
            ?>
" />
				
				<?php 
            if (isset($apbasic_widgets_description)) {
                ?>
				<br />
				<small><?php 
                echo $apbasic_widgets_description;
                ?>
</small>
				<?php 
            }
            ?>
			</p>
			<?php 
            break;
            // Textarea field
        // Textarea field
        case 'textarea':
            ?>
			<p>
				<label for="<?php 
            echo $instance->get_field_id($apbasic_widgets_name);
            ?>
"><?php 
            echo $apbasic_widgets_title;
            ?>
:</label>
				<textarea class="widefat" rows="6" id="<?php 
            echo $instance->get_field_id($apbasic_widgets_name);
            ?>
" name="<?php 
            echo $instance->get_field_name($apbasic_widgets_name);
            ?>
"><?php 
            echo $athm_field_value;
            ?>
</textarea>
			</p>
			<?php 
            break;
            // Checkbox field
        // Checkbox field
        case 'checkbox':
            ?>
			<p>
				<input id="<?php 
            echo $instance->get_field_id($apbasic_widgets_name);
            ?>
" name="<?php 
            echo $instance->get_field_name($apbasic_widgets_name);
            ?>
" type="checkbox" value="1" <?php 
            checked('1', $athm_field_value);
            ?>
/>
				<label for="<?php 
            echo $instance->get_field_id($apbasic_widgets_name);
            ?>
"><?php 
            echo $apbasic_widgets_title;
            ?>
</label>

				<?php 
            if (isset($apbasic_widgets_description)) {
                ?>
				<br />
				<small><?php 
                echo $apbasic_widgets_description;
                ?>
</small>
				<?php 
            }
            ?>
			</p>
			<?php 
            break;
            // Radio fields
        // Radio fields
        case 'radio':
            ?>
			<p>
				<?php 
            echo $apbasic_widgets_title;
            echo '<br />';
            foreach ($apbasic_widgets_field_options as $athm_option_name => $athm_option_title) {
                ?>
					<input id="<?php 
                echo $instance->get_field_id($athm_option_name);
                ?>
" name="<?php 
                echo $instance->get_field_name($apbasic_widgets_name);
                ?>
" type="radio" value="<?php 
                echo $athm_option_name;
                ?>
" <?php 
                checked($athm_option_name, $athm_field_value);
                ?>
 />
					<label for="<?php 
                echo $instance->get_field_id($athm_option_name);
                ?>
"><?php 
                echo $athm_option_title;
                ?>
</label>
					<br />
				<?php 
            }
            ?>
				
				<?php 
            if (isset($apbasic_widgets_description)) {
                ?>
				<small><?php 
                echo $apbasic_widgets_description;
                ?>
</small>
				<?php 
            }
            ?>
			</p>
			<?php 
            break;
            // Select field
        // Select field
        case 'select':
            ?>
			<p>
				<label for="<?php 
            echo $instance->get_field_id($apbasic_widgets_name);
            ?>
"><?php 
            echo $apbasic_widgets_title;
            ?>
:</label>
				<select name="<?php 
            echo $instance->get_field_name($apbasic_widgets_name);
            ?>
" id="<?php 
            echo $instance->get_field_id($apbasic_widgets_name);
            ?>
" class="widefat">
					<?php 
            foreach ($apbasic_widgets_field_options as $athm_option_name => $athm_option_title) {
                ?>
						<option value="<?php 
                echo $athm_option_name;
                ?>
" id="<?php 
                echo $instance->get_field_id($athm_option_name);
                ?>
" <?php 
                selected($athm_option_name, $athm_field_value);
                ?>
><?php 
                echo $athm_option_title;
                ?>
</option>
					<?php 
            }
            ?>
				</select>

				<?php 
            if (isset($apbasic_widgets_description)) {
                ?>
				<br />
				<small><?php 
                echo $apbasic_widgets_description;
                ?>
</small>
				<?php 
            }
            ?>
			</p>
			<?php 
            break;
        case 'number':
            ?>
			<p>
				<label for="<?php 
            echo $instance->get_field_id($apbasic_widgets_name);
            ?>
"><?php 
            echo $apbasic_widgets_title;
            ?>
:</label><br />
				<input name="<?php 
            echo $instance->get_field_name($apbasic_widgets_name);
            ?>
" type="number" step="1" min="1" id="<?php 
            echo $instance->get_field_id($apbasic_widgets_name);
            ?>
" value="<?php 
            echo $athm_field_value;
            ?>
" class="small-text" />
				
				<?php 
            if (isset($apbasic_widgets_description)) {
                ?>
				<br />
				<small><?php 
                echo $apbasic_widgets_description;
                ?>
</small>
				<?php 
            }
            ?>
			</p>
			<?php 
            break;
            // Select field
        // Select field
        case 'selectpost':
            ?>
			<p>
				<label for="<?php 
            echo $instance->get_field_id($apbasic_widgets_name);
            ?>
"><?php 
            echo $apbasic_widgets_title;
            ?>
:</label>
				<select name="<?php 
            echo $instance->get_field_name($apbasic_widgets_name);
            ?>
" id="<?php 
            echo $instance->get_field_id($apbasic_widgets_name);
            ?>
" class="widefat">
					<?php 
            foreach ($accesspress_pro_postlist as $accesspress_basic_single_page) {
                ?>
						<option value="<?php 
                echo $accesspress_basic_single_page['value'];
                ?>
" id="<?php 
                echo $instance->get_field_id($accesspress_basic_single_page['label']);
                ?>
" <?php 
                selected($accesspress_basic_single_page['value'], $athm_field_value);
                ?>
><?php 
                echo $accesspress_basic_single_page['label'];
                ?>
</option>
					<?php 
            }
            ?>
				</select>

				<?php 
            if (isset($apbasic_widgets_description)) {
                ?>
				<br />
				<small><?php 
                echo $apbasic_widgets_description;
                ?>
</small>
				<?php 
            }
            ?>
			</p>
			<?php 
            break;
            // Select field
        // Select field
        case 'selectpage':
            ?>
			<p>
				<label for="<?php 
            echo $instance->get_field_id($apbasic_widgets_name);
            ?>
"><?php 
            echo $apbasic_widgets_title;
            ?>
 :</label>
				<select name="<?php 
            echo $instance->get_field_name($apbasic_widgets_name);
            ?>
" id="<?php 
            echo $instance->get_field_id($apbasic_widgets_name);
            ?>
" class="widefat">
					<?php 
            foreach ($accesspress_basic_pagelist as $accesspress_basic_single_page) {
                ?>
						<option value="<?php 
                echo $accesspress_basic_single_page['value'];
                ?>
" id="<?php 
                echo $instance->get_field_id($accesspress_basic_single_page['label']);
                ?>
" <?php 
                selected($accesspress_basic_single_page['value'], $athm_field_value);
                ?>
><?php 
                echo $accesspress_basic_single_page['label'];
                ?>
</option>
					<?php 
            }
            ?>
				</select>

				<?php 
            if (isset($apbasic_widgets_description)) {
                ?>
				<br />
				<small><?php 
                echo $apbasic_widgets_description;
                ?>
</small>
				<?php 
            }
            ?>
			</p>
			<?php 
            break;
        case 'upload':
            $output = '';
            $id = $instance->get_field_id($apbasic_widgets_name);
            $class = '';
            $int = '';
            $value = $athm_field_value;
            $name = $instance->get_field_name($apbasic_widgets_name);
            if ($value) {
                $class = ' has-file';
            }
            $output .= '<div class="sub-option widget-upload">';
            $output .= '<label for="' . $instance->get_field_id($apbasic_widgets_name) . '">' . $apbasic_widgets_title . '</label><br/>';
            $output .= '<input id="' . $id . '" class="upload' . $class . '" type="text" name="' . $name . '" value="' . $value . '" placeholder="' . __('No file chosen', 'accesspress-basic') . '" />' . "\n";
            if (function_exists('wp_enqueue_media')) {
                //if (( $value == '')) {
                $output .= '<input id="upload-' . $id . '" class="upload-button button" type="button" value="' . __('Upload', 'accesspress-basic') . '" />' . "\n";
                //} else {
                //   $output .= '<input id="remove-' . $id . '" class="remove-file button" type="button" value="' . __('Remove', 'accesspress-basic') . '" />' . "\n";
                //}
            } else {
                $output .= '<p><i>' . __('Upgrade your version of WordPress for full media support.', 'accesspress-basic') . '</i></p>';
            }
            $output .= '<div class="screenshot team-thumb" id="' . $id . '-image">' . "\n";
            if ($value != '') {
                $remove = '<a class="remove-image remove-screenshot">Remove</a>';
                $attachment_id = attachment_url_to_postid($value);
                $image_array = wp_get_attachment_image_src($attachment_id, 'medium');
                $image = preg_match('/(^.*\\.jpg|jpeg|png|gif|ico*)/i', $value);
                if ($image) {
                    $output .= '<img src="' . $image_array[0] . '" alt="" />' . $remove;
                } else {
                    $parts = explode("/", $value);
                    for ($i = 0; $i < sizeof($parts); ++$i) {
                        $title = $parts[$i];
                    }
                    // No output preview if it's not an image.
                    $output .= '';
                    // Standard generic output if it's not an image.
                    $title = __('View File', 'textdomain');
                    $output .= '<div class="no-image"><span class="file_link"><a href="' . $value . '" target="_blank" rel="external">' . $title . '</a></span></div>';
                }
            }
            $output .= '</div></div>' . "\n";
            echo $output;
            break;
        case 'select_theme':
            ?>
			<p>
				<label for="<?php 
            echo $instance->get_field_id($apbasic_widgets_name);
            ?>
"><?php 
            echo $apbasic_widgets_title;
            ?>
 :</label>
				<select name="<?php 
            echo $instance->get_field_name($apbasic_widgets_name);
            ?>
" id="<?php 
            echo $instance->get_field_id($apbasic_widgets_name);
            ?>
" class="widefat">
					<?php 
            foreach ($twitter_themes as $twitter_theme) {
                ?>
						<option value="<?php 
                echo $twitter_theme['value'];
                ?>
" id="<?php 
                echo $instance->get_field_id($twitter_theme['label']);
                ?>
" <?php 
                selected($twitter_theme['value'], $athm_field_value);
                ?>
><?php 
                echo $twitter_theme['label'];
                ?>
</option>
					<?php 
            }
            ?>
				</select>

				<?php 
            if (isset($apbasic_widgets_description)) {
                ?>
				<br />
				<small><?php 
                echo $apbasic_widgets_description;
                ?>
</small>
				<?php 
            }
            ?>
			</p>
			<?php 
            break;
    }
}
Ejemplo n.º 14
0
 /**
  * For users upgrading Reach who are on WordPress 4.5, migrate core's Custom Logo.
  *
  * @return  void
  * @access  public
  * @since   1.0.3
  */
 public function maybe_convert_to_custom_logo()
 {
     /* Return if update has already been run */
     if (-1 != get_theme_mod('custom_logo', -1)) {
         return;
     }
     /* Make sure we're on WP 4.5 */
     if (!function_exists('the_custom_logo')) {
         return;
     }
     $custom_logo = false;
     $current_logo = reach_get_customizer_image_data('logo');
     if ($current_logo) {
         /* Bail early if we don't have a valid logo anyway. */
         if (!isset($current_logo['image'])) {
             set_theme_mod('custom_logo', $custom_logo);
             return;
         }
         /* Swap the retina image for the standard. */
         if (isset($current_logo['id'])) {
             $logo = intval($current_logo['id']);
         } else {
             $logo = attachment_url_to_postid($current_logo['image']);
         }
         if (is_int($logo)) {
             $custom_logo = $logo;
         }
         remove_theme_mod('logo');
     }
     set_theme_mod('custom_logo', $custom_logo);
 }
 /**
  * Add custom parameters to pass to the JS via JSON.
  *
  * @since  1.0.0
  * @access public
  * @return void
  */
 public function to_json()
 {
     parent::to_json();
     $background_choices = $this->background_choices;
     $field_labels = $this->field_labels;
     // Loop through each of the settings and set up the data for it.
     foreach ($this->settings as $setting_key => $setting_id) {
         $this->json[$setting_key] = array('link' => $this->get_link($setting_key), 'value' => $this->value($setting_key), 'label' => isset($field_labels[$setting_key]) ? $field_labels[$setting_key] : '');
         if ('image_url' === $setting_key) {
             if ($this->value($setting_key)) {
                 // Get the attachment model for the existing file.
                 $attachment_id = attachment_url_to_postid($this->value($setting_key));
                 if ($attachment_id) {
                     $this->json['attachment'] = wp_prepare_attachment_for_js($attachment_id);
                 }
             }
         } elseif ('repeat' === $setting_key) {
             $this->json[$setting_key]['choices'] = $background_choices['repeat'];
         } elseif ('size' === $setting_key) {
             $this->json[$setting_key]['choices'] = $background_choices['size'];
         } elseif ('position' === $setting_key) {
             $this->json[$setting_key]['choices'] = $background_choices['position'];
         } elseif ('attach' === $setting_key) {
             $this->json[$setting_key]['choices'] = $background_choices['attach'];
         }
     }
 }
 /**
  * Find the element properties
  *
  * Implements the abstract method from Instant_Articles_DOM_Transform_Filter
  *
  * @since 0.1
  * @param $DOMNode  $DOMNode  The original domnode
  * @return stdClass  The element properties used for building the new fragment
  */
 protected function get_properties($DOMNode)
 {
     $src = $DOMNode->getAttribute('src');
     if (function_exists('wpcom_vip_attachment_url_to_postid')) {
         $attachment_id = wpcom_vip_attachment_url_to_postid($src);
     } else {
         $attachment_id = attachment_url_to_postid($src);
     }
     $properties = new stdClass();
     $properties->img = new stdClass();
     /* Try to use WP internals to get an image of the recommended size. Fallback to use the URL from the original img src in the post. */
     if ($attachment_id) {
         // The recommended resolution is 2048x2048 pixels.
         $img_props = wp_get_attachment_image_src($attachment_id, array(2048, 2048));
         // Returns an array (url, width, height), or false, if no image is available.
     } else {
         $imagesize = getimagesize($src);
         if (is_array($imagesize)) {
             $img_props = array($src, $imagesize[0], $imagesize[1]);
         }
     }
     if (is_array($img_props)) {
         list($properties->img->url, $properties->img->width, $properties->img->height) = $img_props;
     } else {
         $properties->img->url = $src;
         $properties->img->width = '';
         $properties->img->height = '';
     }
     /**
      * Filter the image properties
      *
      * @since 0.1
      * @param object  $img_props      The element properties
      * @param int     $post_id        The post ID of the current post
      * @param int     $attachment_id  The attachment ID (post ID) to the image (if reverse lookup from url to postid worked)
      */
     $properties = apply_filters('instant_articles_image_properties', $properties, $this->_post_id, $attachment_id);
     return $properties;
 }
function wpcom_vip_attachment_url_to_postid($url)
{
    $id = wp_cache_get("wpcom_vip_attachment_url_post_id_" . md5($url));
    if (false === $id) {
        $id = attachment_url_to_postid($url);
        wp_cache_set("wpcom_vip_attachment_url_post_id_" . md5($url), $id, 'default', 3 * HOUR_IN_SECONDS);
    }
    return $id;
}
function wpcom_vip_attachment_url_to_postid($url)
{
    $id = wp_cache_get('wpcom_vip_attachment_url_post_id_' . md5($url));
    if (false === $id) {
        $id = attachment_url_to_postid($url);
        if (empty($id)) {
            wp_cache_set('wpcom_vip_attachment_url_post_id_' . md5($url), 'not_found', 'default', 12 * HOUR_IN_SECONDS + mt_rand(0, 4 * HOUR_IN_SECONDS));
        } else {
            wp_cache_set('wpcom_vip_attachment_url_post_id_' . md5($url), $id, 'default', 24 * HOUR_IN_SECONDS + mt_rand(0, 12 * HOUR_IN_SECONDS));
        }
    } elseif ('not_found' === $id) {
        return false;
    }
    return $id;
}
Ejemplo n.º 19
0
<?php

$image = get_theme_mod('logo_upload');
if ($image) {
    $image_alt = get_post_meta(attachment_url_to_postid($image), '_wp_attachment_image_alt', true);
    if (empty($image_alt)) {
        $image_alt = esc_attr(get_bloginfo('name'));
    }
    $logo = "<span class='screen-reader-text'>" . get_bloginfo('name') . "</span><img class='logo' src='" . esc_url(get_theme_mod('logo_upload')) . "' alt='" . $image_alt . "' />";
} else {
    $logo = get_bloginfo('name');
}
$output = "<div id='site-title' class='site-title'>";
$output .= "<a href='" . esc_url(home_url()) . "'>";
$output .= $logo;
$output .= "</a>";
$output .= "</div>";
echo $output;
Ejemplo n.º 20
0
/**
 * Retrieve the attachment post id from HTML containing an image.
 *
 * @since 3.6.0
 *
 * @param string $html The html, possibly with an image
 * @param string $matched_html Passed by reference, will be set to to the matched img string
 * @return int The attachment id if found, or 0.
 */
function img_html_to_post_id($html, &$matched_html = null)
{
    $attachment_id = 0;
    // Look for an <img /> tag
    if (!preg_match('#' . get_tag_regex('img') . '#i', $html, $matches) || empty($matches)) {
        return $attachment_id;
    }
    $matched_html = $matches[0];
    // Look for attributes.
    if (!preg_match_all('#(src|class)=([\'"])(.+?)\\2#is', $matched_html, $matches) || empty($matches)) {
        return $attachment_id;
    }
    $attr = array();
    foreach ($matches[1] as $key => $attribute_name) {
        $attr[$attribute_name] = $matches[3][$key];
    }
    if (!empty($attr['class']) && false !== strpos($attr['class'], 'wp-image-')) {
        if (preg_match('#wp-image-([0-9]+)#i', $attr['class'], $matches)) {
            $attachment_id = absint($matches[1]);
        }
    }
    if (!$attachment_id && !empty($attr['src'])) {
        $attachment_id = attachment_url_to_postid($attr['src']);
    }
    return $attachment_id;
}
Ejemplo n.º 21
0
	/**
	 * @ticket 30346
	 */
	function test_attachment_url_to_postid() {
		$image_path = '2014/11/' . $this->img_name;
		$attachment_id = $this->factory->attachment->create_object( $image_path, 0, array(
			'post_mime_type' => 'image/jpeg',
			'post_type'      => 'attachment',
		) );

		$image_url  = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_path;
		$this->assertEquals( $attachment_id, attachment_url_to_postid( $image_url ) );

		add_filter( 'upload_dir', array( $this, '_upload_dir' ) );
		$image_url = 'http://192.168.1.20.com/wp-content/uploads/' . $image_path;
		$this->assertEquals( $attachment_id, attachment_url_to_postid( $image_url ) );
		remove_filter( 'upload_dir', array( $this, '_upload_dir' ) );
	}
Ejemplo n.º 22
0
/**
 * Returns the first image from the post content for a image post
 * and the first image from the gallery for a gallery post.
 *
 * @param $size , $post
 *
 * @return void
 */
function hannover_image_from_gallery_or_image_post($size, $post)
{
    if (has_post_thumbnail()) {
        the_post_thumbnail($size);
    } else {
        $post_format = get_post_format($post);
        if ($post_format == 'gallery') {
            $images = hannover_get_gallery_images($post->ID);
            $image = array_shift($images);
            $img_tag = wp_get_attachment_image($image->ID, $size);
        } elseif ($post_format == 'image') {
            $first_img_url = hannover_get_first_image_from_post_content();
            $pattern = '/-\\d+x\\d+(\\.\\w{3,4}$)/i';
            $first_img_url = preg_replace($pattern, '${1}', $first_img_url);
            $first_img_id = attachment_url_to_postid($first_img_url);
            if ($first_img_id == 0) {
                $attachments = get_children(array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order'));
                $first_img = array_shift($attachments);
                $img_tag = wp_get_attachment_image($first_img->ID, $size);
            } else {
                $img_tag = wp_get_attachment_image($first_img_id, $size);
            }
        }
        echo $img_tag;
    }
}
Ejemplo n.º 23
0
 /**
  * retrieve the image id from the given image url
  * @since: 5.0
  */
 public static function get_image_id_by_url($image_url)
 {
     global $wpdb;
     $attachment_id = 0;
     if (function_exists('attachment_url_to_postid')) {
         $attachment_id = attachment_url_to_postid($image_url);
         //0 if failed
     }
     if (0 == $attachment_id) {
         //try to get it old school way
         //for WP < 4.0.0
         $attachment_id = false;
         // If there is no url, return.
         if ('' == $image_url) {
             return;
         }
         // Get the upload directory paths
         $upload_dir_paths = wp_upload_dir();
         // Make sure the upload path base directory exists in the attachment URL, to verify that we're working with a media library image
         if (false !== strpos($image_url, $upload_dir_paths['baseurl'])) {
             // If this is the URL of an auto-generated thumbnail, get the URL of the original image
             $image_url = preg_replace('/-\\d+x\\d+(?=\\.(jpg|jpeg|png|gif)$)/i', '', $image_url);
             // Remove the upload path base directory from the attachment URL
             $image_url = str_replace($upload_dir_paths['baseurl'] . '/', '', $image_url);
             // Finally, run a custom database query to get the attachment ID from the modified attachment URL
             $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT wposts.ID FROM {$wpdb->posts} wposts, {$wpdb->postmeta} wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = '_wp_attached_file' AND wpostmeta.meta_value = '%s' AND wposts.post_type = 'attachment'", $image_url));
         }
     }
     return $attachment_id;
 }
Ejemplo n.º 24
0
function one_paze_slider_bxr()
{
    $enable_slider_overlay = esc_attr(get_theme_mod('enable_slider_overlay'));
    $slides = array();
    for ($i = 1; $i < 5; $i++) {
        $sl_imageo = esc_attr(get_theme_mod('slide' . $i . '_image'));
        $img_id = attachment_url_to_postid(esc_url($sl_imageo));
        $img_arr = wp_get_attachment_image_src($img_id, 'one-paze-slider-image-size');
        $sl_image = $img_arr[0];
        $sl_cap_title = wp_kses_post(get_theme_mod('slide' . $i . '_caption_title'));
        $sl_cap_descr = wp_kses_post(get_theme_mod('slide' . $i . '_caption_descr'));
        $sl_btn_text = esc_attr(get_theme_mod('slide' . $i . '_button_text'));
        $sl_btn_link = esc_attr(get_theme_mod('slide' . $i . '_button_link'));
        if ($sl_image != '') {
            $slides[] = array('image' => $sl_image, 'caption_title' => $sl_cap_title, 'caption_descr' => $sl_cap_descr, 'btn_text' => $sl_btn_text, 'btn_link' => $sl_btn_link);
        }
    }
    if (!empty($slides)) {
        ?>
        <section id="plx-slider-section">
            <ul class='main-slider'>
                <?php 
        foreach ($slides as $slide) {
            ?>
                    <li class="slide">
                        <img src="<?php 
            echo esc_url($slide['image']);
            ?>
" />
                        <?php 
            if ($enable_slider_overlay == 1) {
                ?>
                            <div class="slider-overlay1">
                            </div>
                        <?php 
            }
            ?>
                        <div class="slide-caption">
                            <span class="caption-title"><?php 
            echo $slide['caption_title'];
            ?>
</span>
                            <span class="caption-descr"><?php 
            echo $slide['caption_descr'];
            ?>
</span>
                            <a class="cta_read" href="<?php 
            echo esc_url($slide['btn_link']);
            ?>
" >
                                <?php 
            echo $slide['btn_text'];
            ?>
                                <!--<div class="card">
                                    <div class="face front">
                                <?php 
            echo $slide['btn_text'];
            ?>
                                    </div>
                                    <div class="face back">
                                <?php 
            echo $slide['btn_text'];
            ?>
                                    </div>
                                </div>-->

                            </a>
                        </div>
                    </li>                          
                    <?php 
        }
        ?>
            </ul>
            <div class="slider-down-btn">
                <span class="next-page">
                    <a href="#plx_about_section"><i class="fa fa-angle-double-down"></i></a>
                </span>
            </div>
        </section>
        <?php 
    }
}
Ejemplo n.º 25
0
 /**
  * Get attachment id by url function, adjusted to work cropped images
  * 
  * @param string $url
  * @return int
  */
 public function get_attachment_id_by_url($url)
 {
     $post_id = attachment_url_to_postid($url);
     if (!$post_id) {
         $dir = wp_upload_dir();
         $path = $url;
         if (0 === strpos($path, $dir['baseurl'] . '/')) {
             $path = substr($path, strlen($dir['baseurl'] . '/'));
         }
         if (preg_match('/^(.*)(\\-\\d*x\\d*)(\\.\\w{1,})/i', $path, $matches)) {
             $url = $dir['baseurl'] . '/' . $matches[1] . $matches[3];
             $post_id = attachment_url_to_postid($url);
         }
     }
     return (int) $post_id;
 }
 /**
  * Refresh the parameters passed to the JavaScript via JSON.
  *
  * @since 3.4.0
  * @uses WP_Customize_Control::to_json()
  */
 public function to_json()
 {
     parent::to_json();
     $this->json['mime_type'] = $this->mime_type;
     $this->json['button_labels'] = $this->button_labels;
     $value = $this->value();
     if (is_object($this->setting)) {
         if ($this->setting->default) {
             // Fake an attachment model - needs all fields used by template.
             $type = in_array(substr($this->setting->default, -3), array('jpg', 'png', 'gif', 'bmp')) ? 'image' : 'document';
             $default_attachment = array('id' => 1, 'url' => $this->setting->default, 'type' => $type, 'icon' => wp_mime_type_icon($type), 'title' => basename($this->setting->default));
             if ('image' === $type) {
                 $default_attachment['sizes'] = array('full' => array('url' => $this->setting->default));
             }
             $this->json['defaultAttachment'] = $default_attachment;
         }
         if ($value && $this->setting->default && $value === $this->setting->default) {
             // Set the default as the attachment.
             $this->json['attachment'] = $this->json['defaultAttachment'];
         } elseif ($value) {
             // Get the attachment model for the existing file.
             $attachment_id = attachment_url_to_postid($value);
             if ($attachment_id) {
                 $this->json['attachment'] = wp_prepare_attachment_for_js($attachment_id);
             }
         }
     }
 }
Ejemplo n.º 27
0
 /**
  * Parses a value for the field.
  *
  * @since 0.5.0
  * @param mixed $val the current value of the field
  * @param bool|array $formatted whether to also format the value (default is false)
  * @return integer|string the correctly parsed value (string if $formatted is true)
  */
 public function parse($val, $formatted = false)
 {
     if ('url' === $this->args['store']) {
         $val = FieldManager::format($val, 'url', 'input');
     } else {
         $val = absint($val);
     }
     if ($formatted) {
         if (!is_array($formatted)) {
             $formatted = array();
         }
         $formatted = wp_parse_args($formatted, array('mode' => 'field', 'field' => 'url', 'template' => ''));
         $attachment_id = $val;
         if ('url' === $this->args['store']) {
             if ('field' === $formatted['mode'] && 'url' === $formatted['field']) {
                 return $val;
             }
             $attachment_id = attachment_url_to_postid($val);
         }
         return $this->format_attachment($attachment_id, $formatted);
     }
     return $val;
 }
Ejemplo n.º 28
0
    /**
     * Display slider
     */
    public function display()
    {
        if (!$this->items) {
            return;
        }
        ?>
		<div class="habakiri-slider">
			<div class="habakiri-slider__list">
				<?php 
        foreach ($this->items as $slide) {
            $attachment_id = attachment_url_to_postid($slide['image']);
            // The image uploaded by user
            if ($attachment_id) {
                $src = wp_get_attachment_image_src($attachment_id, 'full', false);
                if (!$src) {
                    continue;
                }
                $image_url = $src[0];
                $height = $src[2];
            } else {
                $image_url = $slide['image'];
                $height = 741;
                // height of default image
            }
            $item = sprintf('<div class="habakiri-slider__item-wrapper col-xs-10 col-xs-offset-1 col-md-8 col-md-offset-2">
							<div class="habakiri-slider__item-content col-xs-12">
								%s
							</div>
						</div>
						<img src="%s" alt="" class="habakiri-slider__image" style="min-height:%dpx" />', $slide['content'], esc_url($image_url), esc_attr(floor($height / 2)));
            if ($slide['url']) {
                $item = sprintf('<a class="habakiri-slider__link" href="%s" target="%s">%s</a>', esc_url($slide['url']), esc_attr($slide['target'] ? '_blank' : '_self'), $item);
            }
            printf('<section class="habakiri-slider__item" style="background-image: url( %s );">
							<div class="habakiri-slider__transparent-layer">
								%s
							</div>
						</section>', esc_url($image_url), $item);
        }
        ?>
			</div>
		</div>
		<?php 
    }
Ejemplo n.º 29
0
/**
 * AJAX handler for setting the featured image for an attachment.
 *
 * @since 4.0.0
 *
 * @see set_post_thumbnail()
 */
function wp_ajax_set_attachment_thumbnail()
{
    if (empty($_POST['urls']) || !is_array($_POST['urls'])) {
        wp_send_json_error();
    }
    $thumbnail_id = (int) $_POST['thumbnail_id'];
    if (empty($thumbnail_id)) {
        wp_send_json_error();
    }
    $post_ids = array();
    // For each URL, try to find its corresponding post ID.
    foreach ($_POST['urls'] as $url) {
        $post_id = attachment_url_to_postid($url);
        if (!empty($post_id)) {
            $post_ids[] = $post_id;
        }
    }
    if (empty($post_ids)) {
        wp_send_json_error();
    }
    $success = 0;
    // For each found attachment, set its thumbnail.
    foreach ($post_ids as $post_id) {
        if (!current_user_can('edit_post', $post_id)) {
            continue;
        }
        if (set_post_thumbnail($post_id, $thumbnail_id)) {
            $success++;
        }
    }
    if (0 === $success) {
        wp_send_json_error();
    } else {
        wp_send_json_success();
    }
    wp_send_json_error();
}
Ejemplo n.º 30
0
function jr_mt_validate_settings($input)
{
    global $jr_mt_kwvalsep;
    $valid = array();
    $prefix_types = array('false' => 'url', 'prefix' => 'url_prefix', '*' => 'url_asterisk');
    $settings = get_option('jr_mt_settings');
    $query = $settings['query'];
    $aliases = $settings['aliases'];
    /*	Begin by deciding which Tab to display on the plugin's Settings page
    	
    		Default value should never be used if plugin is written correctly.
    	*/
    $tab = 1;
    for ($i = 1; $i <= 6; $i++) {
        if (isset($input["tab{$i}"])) {
            $tab = $i;
            break;
        }
    }
    set_transient('jr_mt_' . get_current_user_id() . '_tab', $tab, 5);
    if (isset($input['permalink'])) {
        $internal_settings = get_option('jr_mt_internal_settings');
        $internal_settings['permalink'] = get_option('permalink_structure');
        update_option('jr_mt_internal_settings', $internal_setting);
    }
    foreach (array('all_pages', 'all_posts', 'site_home', 'current') as $thing) {
        $valid[$thing] = $input[$thing];
    }
    foreach ($prefix_types as $key => $thing) {
        $valid[$thing] = $settings[$thing];
    }
    $remember = array('query' => array());
    if (isset($input['sticky_query_entry'])) {
        foreach ($input['sticky_query_entry'] as $query_entry) {
            list($keyword, $value) = explode($jr_mt_kwvalsep, $query_entry);
            /*	Data Sanitization not required as
            				Keyword and Value are not entered by a human,
            				but extracted from previously-generated HTML.
            			*/
            $remember['query'][$keyword][$value] = TRUE;
        }
    }
    $override = array('query' => array());
    if (isset($input['override_query_entry'])) {
        foreach ($input['override_query_entry'] as $query_entry) {
            list($keyword, $value) = explode($jr_mt_kwvalsep, $query_entry);
            /*	Data Sanitization not required as
            				Keyword and Value are not entered by a human,
            				but extracted from previously-generated HTML.
            			*/
            $override['query'][$keyword][$value] = TRUE;
        }
    }
    if (isset($input['del_entry'])) {
        foreach ($input['del_entry'] as $del_entry) {
            $del_array = explode('=', $del_entry, 3);
            if ('query' === $del_array[0]) {
                unset($query[$del_array[1]][$del_array[2]]);
                if (empty($query[$del_array[1]])) {
                    unset($query[$del_array[1]]);
                }
                /*	unset() does nothing if a variable or array element does not exist.
                 */
                unset($remember['query'][$del_array[1]][$del_array[2]]);
                if (empty($remember['query'][$del_array[1]])) {
                    unset($remember['query'][$del_array[1]]);
                }
                unset($override['query'][$del_array[1]][$del_array[2]]);
                if (empty($override['query'][$del_array[1]])) {
                    unset($override['query'][$del_array[1]]);
                }
            } else {
                /*	Check for a URL entry
                 */
                if ('url' === jr_mt_substr($del_array[0], 0, 3)) {
                    foreach ($valid[$del_array[0]] as $i => $entry_array) {
                        if ($entry_array['url'] === $del_array[2]) {
                            /*	Cannot unset $entry_array, even if prefixed by & in foreach
                             */
                            unset($valid[$del_array[0]][$i]);
                            break;
                        }
                    }
                } else {
                    /*	Must be Home, All Pages or Posts, or Everything
                     */
                    $valid[$del_array[0]] = '';
                }
            }
        }
    }
    /*	Handle troublesome %E2%80%8E UTF Left-to-right Mark (LRM) suffix first.
     */
    $url = jr_mt_sanitize_url($input['add_path_id']);
    if (empty($input['add_theme']) && !empty($url) || !empty($input['add_theme']) && empty($url)) {
        add_settings_error('jr_mt_settings', 'jr_mt_emptyerror', 'Both URL and Theme must be specified to add an Individual entry', 'error');
    } else {
        if (!empty($url)) {
            if (jr_mt_same_prefix_url(JR_MT_HOME_URL, $url)) {
                if ('*' !== $input['add_is_prefix'] && FALSE !== strpos($url, '*')) {
                    add_settings_error('jr_mt_settings', 'jr_mt_queryerror', 'Asterisk ("*") only allowed when "URL Prefix with Asterisk" selected: <code>' . $url . '</code>', 'error');
                } else {
                    $prep_url = jr_mt_prep_url($url);
                    if ('false' === $input['add_is_prefix']) {
                        if (jr_mt_same_url($prep_url, JR_MT_HOME_URL)) {
                            add_settings_error('jr_mt_settings', 'jr_mt_homeerror', 'Please use "Select Theme for Site Home" field instead of specifying Site Home URL as an individual entry.', 'error');
                        } else {
                            if (jr_mt_same_prefix_url($prep_url, admin_url())) {
                                add_settings_error('jr_mt_settings', 'jr_mt_adminerror', 'Admin Page URLs are not allowed because no known Themes alter the appearance of Admin pages: <code>' . $url . '</code>', 'error');
                            }
                        }
                    } else {
                        if ('*' === $input['add_is_prefix']) {
                            $url_dirs = explode('/', str_replace('\\', '/', $url));
                            foreach ($url_dirs as $dir) {
                                if (FALSE !== strpos($dir, '*')) {
                                    $asterisk_found = TRUE;
                                    if ('*' !== $dir) {
                                        $asterisk_not_alone = TRUE;
                                    }
                                    break;
                                }
                            }
                            if (isset($asterisk_found)) {
                                if (isset($asterisk_not_alone)) {
                                    add_settings_error('jr_mt_settings', 'jr_mt_queryerror', 'An Asterisk ("*") may only replace a full subdirectory name, not just a portion of it: <code>' . $url . '</code>', 'error');
                                }
                            } else {
                                add_settings_error('jr_mt_settings', 'jr_mt_queryerror', 'No Asterisk ("*") specified but "URL Prefix with Asterisk" selected: <code>' . $url . '</code>', 'error');
                            }
                        }
                    }
                    function jr_mt_settings_errors()
                    {
                        $errors = get_settings_errors();
                        if (!empty($errors)) {
                            foreach ($errors as $error_array) {
                                if ('error' === $error_array['type']) {
                                    return TRUE;
                                }
                            }
                        }
                        return FALSE;
                    }
                    /*	If there have been no errors detected,
                    				create the new URL setting entry.
                    			*/
                    if (!jr_mt_settings_errors()) {
                        /*	['url'], ['url_prefix'] or ['url_asterisk']
                         */
                        $key = $prefix_types[$input['add_is_prefix']];
                        $rel_url = jr_mt_relative_url($url, JR_MT_HOME_URL);
                        $valid[$key][] = array('url' => $url, 'rel_url' => $rel_url, 'theme' => $input['add_theme']);
                        /*	Get index of element just added to array $valid[ $key ]
                         */
                        end($valid[$key]);
                        $valid_key = key($valid[$key]);
                        /*	Create the URL Prep array for each of the current Site Aliases,
                        				including the Current Site URL
                        			*/
                        foreach ($aliases as $index => $alias) {
                            $valid[$key][$valid_key]['prep'][] = jr_mt_prep_url($alias['url'] . '/' . $rel_url);
                        }
                        /*	Only for URL type Setting, not Prefix types.
                         */
                        if ('url' === $key) {
                            /*	Try and figure out ID and WordPress Query Keyword for Type, if possible and relevant
                             */
                            if (0 === ($id = url_to_postid($url)) && version_compare(get_bloginfo('version'), '4', '>=')) {
                                $id = attachment_url_to_postid($url);
                            }
                            if (!empty($id)) {
                                $valid[$key][$valid_key]['id'] = $id;
                                if (NULL !== ($post = get_post($id))) {
                                    switch ($post->post_type) {
                                        case 'post':
                                            $valid[$key][$valid_key]['id_kw'] = 'p';
                                            break;
                                        case 'page':
                                            $valid[$key][$valid_key]['id_kw'] = 'page_id';
                                            break;
                                        case 'attachment':
                                            $valid[$key][$valid_key]['id_kw'] = 'attachment_id';
                                            break;
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                add_settings_error('jr_mt_settings', 'jr_mt_urlerror', ' URL specified is not part of current WordPress web site: <code>' . $url . '</code>.  URL must begin with <code>' . JR_MT_HOME_URL . '</code>.', 'updated');
            }
        }
    }
    /*	Make sure reserved characters are not used
    		in URL Query keyword or value fields on Settings page.
    	*/
    function jr_mt_query_chars($element, $where)
    {
        foreach (array('=' => 'Equals Sign', '?' => 'Question Mark', '&' => 'Ampersand', ' ' => 'Blank', '#' => 'Number Sign', '/' => 'Slash', '\\' => 'Backslash', '[' => 'Square Bracket', ']' => 'Square Bracket') as $char => $name) {
            if (FALSE !== strpos($element, $char)) {
                add_settings_error('jr_mt_settings', 'jr_mt_queryerror', 'Illegal character used in ' . $where . ': ' . $name . ' ("' . $char . '") in "' . $element . '"', 'error');
                return FALSE;
            }
        }
        return TRUE;
    }
    /*	Data Sanitization needed here
     */
    $keyword = jr_mt_prep_query_keyword($input['add_querykw_keyword']);
    if (!empty($input['add_querykw_theme']) && !empty($keyword)) {
        if (jr_mt_query_chars($keyword, 'Query Keyword')) {
            /*	If there is an existing entry for the Keyword,
            				then replace it.
            				Otherwise, create a new entry.
            			*/
            $query[$keyword]['*'] = $input['add_querykw_theme'];
        }
    } else {
        if (!(empty($input['add_querykw_theme']) && empty($keyword))) {
            add_settings_error('jr_mt_settings', 'jr_mt_emptyerror', 'Both Query Keyword and Theme must be specified to add an Individual Query Keyword entry', 'error');
        }
    }
    /*	Data Sanitization needed here
     */
    $keyword = jr_mt_prep_query_keyword($input['add_query_keyword']);
    $value = jr_mt_prep_query_value($input['add_query_value']);
    if (!empty($input['add_query_theme']) && !empty($keyword) && !empty($value)) {
        if (jr_mt_query_chars($keyword, 'Query Keyword') && jr_mt_query_chars($value, 'Query Value')) {
            /*	If there is an existing entry for the Keyword and Value pair,
            				then replace it.
            				Otherwise, create a new entry.
            			*/
            $query[$keyword][$value] = $input['add_query_theme'];
        }
    } else {
        if (!(empty($input['add_query_theme']) && empty($keyword) && empty($value))) {
            add_settings_error('jr_mt_settings', 'jr_mt_emptyerror', 'Query Keyword, Value and Theme must all be specified to add an Individual Query entry', 'error');
        }
    }
    if ('true' === $input['query_present']) {
        $valid['query_present'] = TRUE;
    } else {
        if ('false' === $input['query_present']) {
            $valid['query_present'] = FALSE;
        }
    }
    /*	Handle Alias tab
    	
    		Always handle Delete first, to allow Replacement (Delete then Add)
    	*/
    if (isset($input['del_alias_entry'])) {
        foreach ($input['del_alias_entry'] as $del_alias_entry) {
            $int_key = (int) $del_alias_entry;
            unset($aliases[$int_key]);
            /*	Now go through all the URL-based Settings,
            				and delete the Prep for the deleted Alias.
            					
            				$int_key is the array integer key of the just-deleted
            				Alias, as that will also be the array key for each of the
            				Settings ['prep'] arrays.
            			*/
            foreach ($prefix_types as $form_prefix => $settings_prefix) {
                foreach ($valid[$settings_prefix] as $key => $url_entry) {
                    unset($valid[$settings_prefix][$key]['prep'][$int_key]);
                }
            }
        }
    }
    $alias_url = jr_mt_sanitize_url($input['add_alias']);
    if (!empty($alias_url)) {
        /*	URL has been trimmed but Case has not been altered
         */
        if (0 !== substr_compare($alias_url, 'http://', 0, 7, TRUE) && 0 !== substr_compare($alias_url, 'https://', 0, 8, TRUE) || FALSE === ($parse_url = parse_url($alias_url))) {
            add_settings_error('jr_mt_settings', 'jr_mt_badurlerror', "Alias URL specified is invalid: <code>{$url}</code>", 'error');
        } else {
            $url_ok = TRUE;
            foreach (array('user', 'pass', 'query', 'fragment') as $component) {
                if (isset($parse_url[$component])) {
                    $url_ok = FALSE;
                    break;
                }
            }
            if ($url_ok) {
                /*	Be sure there is NOT a trailing slash
                 */
                $alias_url = rtrim($alias_url, '/\\');
                $aliases[] = array('url' => $alias_url, 'prep' => jr_mt_prep_url($alias_url), 'home' => FALSE);
                /*	Now go through all the URL-based Settings,
                				and add a Prep for the new Alias.
                				
                				First, determine the array integer key of the newly-added
                				Alias, as that will also be the array key for each of the
                				Settings ['prep'] arrays.
                			*/
                end($aliases);
                $prep_key = key($aliases);
                foreach ($prefix_types as $form_prefix => $settings_prefix) {
                    foreach ($valid[$settings_prefix] as $key => $url_entry) {
                        $valid[$settings_prefix][$key]['prep'][$prep_key] = jr_mt_prep_url($alias_url . '/' . $valid[$settings_prefix][$key]['rel_url']);
                    }
                }
            } else {
                add_settings_error('jr_mt_settings', 'jr_mt_badurlerror', 'Alias URL cannot contain user, password, query ("?") or fragment ("#"): <code>' . "{$url}</code>", 'error');
            }
        }
    }
    $errors = get_settings_errors();
    if (empty($errors)) {
        add_settings_error('jr_mt_settings', 'jr_mt_saved', 'Settings Saved', 'updated');
    }
    $valid['query'] = $query;
    $valid['remember'] = $remember;
    $valid['override'] = $override;
    $valid['aliases'] = $aliases;
    return $valid;
}