Skip to content

Commit

Permalink
post thumbnail update
Browse files Browse the repository at this point in the history
user avatar upd
  • Loading branch information
Aleksei Tikhomirov committed Aug 31, 2023
1 parent ac60322 commit b392841
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 101 deletions.
13 changes: 1 addition & 12 deletions assets/js/tinymce/button.js
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
(function () {
tinymce.PluginManager.add('ot_button', function (editor, url) {
editor.addButton('ot_button', {
title: 'Button',
image: 'https://img.icons8.com/ios/50/000000/button2.png',
//icon: 'ot',
onclick: function () {
editor.insertContent('[ot_button]');
}
});
});
})();

2 changes: 1 addition & 1 deletion functions/TinyMCE/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function tiny_advanced()
}*/
$in['toolbar2'] = 'formatselect fontselect fontsizeselect | table | subscript superscript removeformat | insert unlink openlink charmap code | cut copy paste pastetext';

$in['fontsize_formats'] = '12px 14px 15px 18px 20px 24px 28px 30px 32px 36px 48px';
$in['fontsize_formats'] = '10px 12px 14px 15px 18px 20px 24px 28px 30px 32px 36px 48px';
$in['font_formats'] .= 'Open Sans=Open Sans,sans-serif;';
$in['menubar'] = 'file edit insert view format table tools help';

Expand Down
2 changes: 1 addition & 1 deletion functions/debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function show_in_console(){
global $wp_query;
if(!$wp_query->debug_showed) {
if(!is_string($wp_query->debug_log)){
$wp_query->debug_log = print_r( $wp_query->debug_log, true);
$wp_query->debug_log = json_encode( $wp_query->debug_log, true);
} else {
$wp_query->debug_log = "'$wp_query->debug_log'";
}
Expand Down
85 changes: 38 additions & 47 deletions functions/posts/ShowThumbnail.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,56 @@ class ShowThumbnail{
public function __construct()
{
add_action('init', [$this , 'add_post_thumbs_in_post_list_table'], 20);
add_action('admin_head', [$this, 'admin_style']);

add_action('admin_footer', function () {
$theme = wp_get_theme();
$ver = defined('WP_DEBUG_SCRIPT') ? current_time('timestamp') : $theme->get( 'Version' );
$dir_uri = get_template_directory_uri();
$dir_path = get_template_directory();

// js
if( file_exists($dir_path . '/assets/js/plugins/lightcase.js') ) {
wp_register_script('lightcase', $dir_uri . '/assets/js/plugins/lightcase.js', ['jquery'], $ver, false);
} else {
wp_register_script('lightcase', 'https://cdnjs.cloudflare.com/ajax/libs/lightcase/2.5.0/js/lightcase.min.js', ['jquery'], $ver, false);
}
// css
if( file_exists($dir_path . '/assets/css/plugins/lightcase.min.css') ) {
wp_register_style('lightcase', $dir_uri . '/assets/css/plugins/lightcase.min.css', $ver);
} else {
wp_register_style('lightcase', 'https://cdnjs.cloudflare.com/ajax/libs/lightcase/2.5.0/css/lightcase.min.css', $ver);
}

wp_enqueue_script('lightcase');
wp_enqueue_style('lightcase');

?>
<script type="text/javascript">
jQuery(document).ready(function($){
$('a[data-rel^=lightcase]').lightcase({
typeMapping: {
'image': 'webp,jpg,jpeg,gif,png,bmp',
},
});
});
</script>
<?php
});
add_action('admin_enqueue_scripts', [$this, 'admin_enqueue_scripts'],99);
}

public function admin_enqueue_scripts(){

public function admin_style(){ ?>
<style type="text/css" rel="stylesheet">
.thumbnail .dashicons.dashicons-format-image {
width: 80px;
height: 80px;
$theme = wp_get_theme();
$ver = defined('WP_DEBUG_SCRIPT') ? current_time('timestamp') : $theme->get( 'Version' );
$dir_uri = get_template_directory_uri();
$dir_path = get_template_directory();

// js
if( file_exists($dir_path . '/assets/js/plugins/lightcase.js') ) {
wp_register_script('lightcase', $dir_uri . '/assets/js/plugins/lightcase.js', ['jquery'], $ver, false);
} else {
wp_register_script('lightcase', 'https://cdnjs.cloudflare.com/ajax/libs/lightcase/2.5.0/js/lightcase.min.js', ['jquery'], $ver, false);
}
// css
if( file_exists($dir_path . '/assets/css/plugins/lightcase.min.css') ) {
wp_register_style('lightcase', $dir_uri . '/assets/css/plugins/lightcase.min.css', $ver);
} else {
wp_register_style('lightcase', 'https://cdnjs.cloudflare.com/ajax/libs/lightcase/2.5.0/css/lightcase.min.css', $ver);
}

wp_enqueue_script('lightcase');
wp_enqueue_style('lightcase');

wp_add_inline_script('lightcase', 'jQuery(document).ready(function($){
$("a[data-rel^=lightcase]").lightcase({
typeMapping: {
"image": "webp,jpg,jpeg,gif,png,bmp",
},
});
});');

wp_add_inline_style('lightcase', '
.thumbnail .dashicons.dashicons-format-image {
width: 90px;
height: 90px;
font-size: 90px;
text-align: center;
}
.thumbnail img{
.thumbnail img {
border-radius: 8px;
}
.manage-column.column-thumbnail {
width: 110px;
text-align: center;
}
</style>
<?php
}');
}


public function add_post_thumbs_in_post_list_table()
{
// проверим какие записи поддерживают миниатюры
Expand Down Expand Up @@ -105,7 +96,7 @@ public function add_thumb_column($columns)
public function add_thumb_value($colname, $post_id)
{
if ('thumbnail' === $colname) {
$width = $height = 100;
$width = $height = 90;

/*if( class_exists('\theme\Theme') ){
$thumb = Theme::get_post_thumb('gillion-square-micro', $post_id, 'a');
Expand Down
84 changes: 49 additions & 35 deletions functions/theme/funсtions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@

/**
* @param int|WP_Post $post
*
* @return int
*/
function get_post_views($post = null)
{
$post = get_post($post);
$post = $post instanceof WP_Post ? $post->ID : get_the_ID();
return get_post_meta($post,'views', true) ?: 0;
return get_post_meta($post, 'views', true) ?: 0;
}

/**
* @param int|WP_Post $post
*
* @return string
*/
function get_post_subtitle($post = null)
{
$post = get_post($post);
$post = $post instanceof WP_Post ? $post->ID : get_the_ID();
return get_post_meta($post,'subtitle', true);
return get_post_meta($post, 'subtitle', true);
}

function the_subtitle($before, $after)
{
$string = get_post_subtitle();
if($string) {
if ($string) {
echo $before . $string . $after;
}
}
Expand All @@ -34,40 +36,52 @@ function the_subtitle($before, $after)
/**
* Get thumbnail
*/
if(!function_exists('thumbnail')):
function thumbnail($width = '420', $height = '280', $crop = true, $post_id = null, $show_placeholder = true)
{
$thumb = null;
if($show_placeholder) {
$thumb = get_option('kama_thumbnail', ['no_photo_url' => RW_PLUGIN_URL . '/wp-content/uploads/2023/08/no_img.jpg'])['no_photo_url'];
}

$attachments = get_children([
'post_parent' => $post_id ?? get_the_ID(),
'post_mime_type' => 'image',
'post_type' => 'attachment',
'numberposts' => 1,
'order' => 'DESC',
]);
if (!function_exists('get_post_thumbnail')):
function get_post_thumbnail($attr = null)
{
$thumbnail = null;
$attr = wp_parse_args($attr, [
'width' => '480',
'height' => '340',
'crop' => true,
'post_id' => null,
'show_placeholder' => true,
'attach_id' => null,
'class' => 'img-fluid rounded',
'attr' => ''
]);
extract($attr);

$attach_id = get_post_thumbnail_id($post_id ?? get_the_ID());
if (empty($attach_id) && !empty($attachments)) {
$attach_id = array_values($attachments)[0]->ID;
}
if ($show_placeholder) {
$thumbnail = get_option('kama_thumbnail', ['no_photo_url' => RW_PLUGIN_URL . '/wp-content/uploads/2023/08/no_img.jpg'])['no_photo_url'];
}

if (function_exists( 'kama_thumb_img' )) {
$thumb = kama_thumb_img([
'width' => $width,
'height' => $height,
'crop' => $crop,
'class' => 'rounded',
'stub_url' => $show_placeholder ? $thumb : '',
'attach_id' => $attach_id ?: null
$attachments = get_children([
'post_parent' => $post_id ?: get_the_ID(),
'post_mime_type' => 'image',
'post_type' => 'attachment',
'numberposts' => 1,
'order' => 'DESC',
]);
} else {
$thumb = !empty($attach_id) ? wp_get_attachment_image($attach_id, [$width, $height], true) : null;
}

return $thumb;
}
$attach_id = get_post_thumbnail_id($post_id ?? get_the_ID());
if (empty($attach_id) && !empty($attachments)) {
$attach_id = array_values($attachments)[0]->ID;
}

if (function_exists('kama_thumb_img')) {
$thumbnail = kama_thumb_img([
'width' => $width,
'height' => $height,
'crop' => $crop,
'class' => $class,
'stub_url' => $show_placeholder ? $thumbnail : '',
'attach_id' => $attach_id ?: null
]);
} else {
$thumbnail = !empty($attach_id) ? wp_get_attachment_image($attach_id, [$width, $height], true) : null;
}

return $thumbnail;
}
endif;
7 changes: 3 additions & 4 deletions functions/users/UserAvatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

class UserAvatar
{

/** @var string */
public $url;

public function __construct( string $url = '')
{
add_filter('avatar_defaults', [$this, 'new_default_avatar'], 10);
add_filter('get_avatar', [$this, 'media_get_avatar'], 10, 6);

$this->url = $url ?: RW_PLUGIN_URL . 'assets/images/user_gray.svg';
$this->url = !empty($url) ? $url : RW_PLUGIN_URL . 'assets/images/user_gray.svg';
}

/**
Expand Down Expand Up @@ -49,8 +49,7 @@ public function new_default_avatar($avatar_defaults)
public function media_get_avatar($avatar, $id_or_email, $size, $default, $alt, $args): string
{
if ($default === $this->url) { // путь к файлу
$avatar = '<img src="' . $args['default'] . '" width="32px" height="32px"
class="avatar avatar-32 photo avatar-default" alt="' . __('User avatar', 'wp-addon') . '">';
$avatar = '<img src="' . $args['default'] . '" width="32px" height="32px" class="avatar avatar-32 photo avatar-default" alt="' . __('User avatar', 'wp-addon') . '">';
// $args['default']
}

Expand Down
2 changes: 1 addition & 1 deletion functions/users/UserFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function filter_users_by_role_section(WP_User_Query $query): WP_User_Quer
global $pagenow;

if ( is_admin() && isset($_GET["role_filter"]) && 'users.php' === $pagenow ) {
// figure out which button was clicked. The $which in filter_by_job_role()

if ( !empty($_GET['role_filter']) ) {
$query->set('role', $_GET['role_filter']);
$query->set('role__in', [$_GET['role_filter']]);
Expand Down

0 comments on commit b392841

Please sign in to comment.