Kirki_Helper::get_image_from_url PHP Method

get_image_from_url() public static method

Returns an array of the attachment's properties.
public static get_image_from_url ( string $url ) : array
$url string URL to the image.
return array
        public static function get_image_from_url($url)
        {
            $image_id = self::get_image_id($url);
            $image = wp_get_attachment_image_src($image_id, 'full');
            return array('url' => $image[0], 'width' => $image[1], 'height' => $image[2], 'thumbnail' => $image[3]);
        }

Usage Example

Beispiel #1
0
 /**
  * Get the value of an option from the db.
  *
  * @var 	string	the ID of the configuration corresponding to this field
  * @var		string	the field_id (defined as 'settings' in the field arguments)
  *
  * @return 	mixed 	the saved value of the field.
  *
  */
 public static function get_option($config_id = '', $field_id = '')
 {
     /**
      * Make sure value is defined
      */
     $value = '';
     /**
      * This allows us to skip the $config_id argument.
      * If we skip adding a $config_id, use the 'global' configuration.
      */
     if ('' == $field_id && '' != $config_id) {
         $field_id = $config_id;
         $config_id = 'global';
     }
     /**
      * If $config_id is empty, set it to 'global'.
      */
     $config_id = '' == $config_id ? 'global' : $config_id;
     if ('theme_mod' == self::$config[$config_id]['option_type']) {
         /**
          * We're using theme_mods.
          * so just get the value using get_theme_mod
          */
         $value = get_theme_mod($field_id, self::$fields[$field_id]['default']);
         /**
          * If the field is a background field, then get the sub-fields
          * and return an array of the values.
          */
         if ('background' == self::$fields[$field_id]['type']) {
             $value = array();
             foreach (self::$fields[$field_id]['default'] as $property_key => $property_default) {
                 $value[$property_key] = get_theme_mod($field_id . '_' . $property_key, $property_default);
             }
         }
     } elseif ('option' == self::$config[$config_id]['option_type']) {
         /**
          * We're using options.
          */
         if ('' != self::$config[$config_id]['option_name']) {
             /**
              * Options are serialized as a single option in the db.
              * We'll have to get the option and then get the item from the array.
              */
             $options = get_option(self::$config[$config_id]['option_name']);
             if (!isset(self::$fields[$field_id]) && isset(self::$fields[self::$config[$config_id]['option_name'] . '[' . $field_id . ']'])) {
                 $field_id = self::$config[$config_id]['option_name'] . '[' . $field_id . ']';
             }
             $setting_modified = str_replace(']', '', str_replace(self::$config[$config_id]['option_name'] . '[', '', $field_id));
             /**
              * If this is a background field, get the individual sub-fields and return an array.
              */
             if ('background' == self::$fields[$field_id]['type']) {
                 $value = array();
                 foreach (self::$fields[$field_id]['default'] as $property => $property_default) {
                     if (isset($options[$setting_modified . '_' . $property])) {
                         $value[$property] = $options[$setting_modified . '_' . $property];
                     } else {
                         $value[$property] = $property_default;
                     }
                 }
             } else {
                 /**
                  * This is not a background field so continue and get the value.
                  */
                 $value = isset($options[$setting_modified]) ? $options[$setting_modified] : self::$fields[$field_id]['default'];
                 $value = maybe_unserialize($value);
             }
         } else {
             /**
              * Each option separately saved in the db
              */
             $value = get_option($field_id, self::$fields[$field_id]['default']);
             /**
              * If the field is a background field, then get the sub-fields
              * and return an array of the values.
              */
             if ('background' == self::$fields[$field_id]['type']) {
                 $value = array();
                 foreach (self::$fields[$field_id]['default'] as $property_key => $property_default) {
                     $value[$property_key] = get_option($field_id . '_' . $property_key, $property_default);
                 }
             }
         }
     }
     /**
      * reduxframework compatibility tweaks.
      * If KIRKI_REDUX_COMPATIBILITY is defined as true then modify the output of the values
      * and make them compatible with Redux.
      */
     if (defined('KIRKI_REDUX_COMPATIBILITY') && KIRKI_REDUX_COMPATIBILITY) {
         switch (self::$fields[$field_id]['type']) {
             case 'image':
                 $value = Kirki_Helper::get_image_from_url($value);
                 break;
         }
     }
     return $value;
 }
All Usage Examples Of Kirki_Helper::get_image_from_url