/** * Override the get_avatar by default from WP */ protected static function getAvatar() { /* * We will get the avatar from our models */ add_filter('get_avatar', function ($avatar = '', $id_or_email, $size = User::AVATAR_SIZE_DEFAULT, $default = '', $alt = '') { if (is_numeric($id_or_email)) { $user_id = (int) $id_or_email; } elseif (is_string($id_or_email) && ($user = get_user_by('email', $id_or_email))) { $user_id = $user->ID; } elseif (is_object($id_or_email) && !empty($id_or_email->user_id)) { $user_id = (int) $id_or_email->user_id; } $user = User::find($user_id); if (!$user) { return Utils::getUrlAvatarDefault($size); } if (!Utils::isValidStr($alt)) { $alt = $user->getDisplayName() . ' avatar'; } $img = '<img alt="' . esc_attr($alt) . '" src="' . $user->getAvatar($size) . '" '; $img .= 'class="avatar photo" height="' . $size . '" width="' . $size . '">'; return $img; }, 10, 5); }
/** * Devuelve el src del thumbnail del post * * @param string $size * size */ public function getThumbnail($size = self::IMG_SIZE_THUMBNAIL) { /* * Define a func for to get the attachment-src from the post_id */ $getSrc = function ($_id) use($size) { $imageObject = wp_get_attachment_image_src(get_post_thumbnail_id($_id), $size); if (empty($imageObject)) { return false; } return $imageObject[0]; }; if ($imageObject = $getSrc($this->ID)) { return $imageObject; } // if they aren't, we get the first img from the post, and let it as thumbnail preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $this->post_content, $matches); $src = $matches[1]; $attachmentId = Utils::getAttachmentIdFromUrl($src); // try to set the first img as thumbnail set_post_thumbnail($this->ID, $attachmentId); /* * In case we found it return the img src from wp_get_attachment_image_src() * Othercase return the raw source */ if ($imageObject = $getSrc($this->ID)) { return $imageObject; } return $src; }
/** * Return the associative array (the file language) * * @param string $lang The 2 first chars of the language * @param string $file Filename language */ public static function getLangFile($file, $lang = false) { if (!$lang) { $lang = static::getLangBrowserByCurrentUser(); if (!$lang) { $lang = Utils::getLangBrowser(); } } return require '/' . APP_DIR . "/i18n/{$lang}/{$file}.php"; }
use Libs\Actions; use Libs\Filters; use Libs\Widgets; use Knob\Libs\Utils; // -------------------------------------------------------------- // Some constants // -------------------------------------------------------------- // BASE DIRECTORIES define('PROJECT_DIR', dirname(__FILE__)); define('VENDOR_DIR', PROJECT_DIR . '/vendor'); define('VENDOR_KNOB_BASE_DIR', VENDOR_DIR . '/chemaclass/knob-base'); define('VENDOR_KNOB_BASE_WP_DIR', VENDOR_KNOB_BASE_DIR . '/wp'); define('APP_DIR', PROJECT_DIR . '/app'); define('PAGES_DIR', APP_DIR . '/pages'); define('CONFIG_DIR', APP_DIR . '/config'); $configFile = Utils::getConfigFile(); $env = isset($configFile['env']) ? $configFile['env'] : []; $siteUrl = get_site_url(); // URL ENVEROMENTS define('URL_PRO', isset($env['pro']) ? $env['pro'] : $siteUrl); define('URL_DEV', isset($env['dev']) ? $env['dev'] : $siteUrl); define('URL_LOC', isset($env['loc']) ? $env['loc'] : $siteUrl); // SOME DIRECTORIES define('PUBLIC_DIR', get_template_directory_uri() . '/public'); define('COMPONENTS_DIR', get_template_directory_uri() . '/vendor/components'); // BLOG_INFO function getBlogTitle() { if (is_home()) { return get_bloginfo('name'); } else {