Спрашиваем и отвечаем по Wordpress-6

J
На сайте с 21.08.2011
Offline
78
#211
Kordi:
Обновился на 3.7. Интересно столкнулся еще кто то с такой проблемой?

Есть такая фича, если пишешь описание к фото - вокруг нее появляется рамка серенькая и текст под фото (wp-caption).

Да, та же фигня, но у меня 10300пикс. Было бы веселее со 100500 :D

Походу, JS косячит, ибо в инлайн стайле:

<dl class="wp-caption aligncenter" id="attachment_558" style="width: 10300px" data-mce-style="width: 10300px;">



---------- Добавлено 25.10.2013 в 22:12 ----------

And-rey:
Изменения внесены только в файлы readme.html и wp-config-sample.php,

Такого не может быть -- 100%.

Добавлено куча всего.

---------- Добавлено 25.10.2013 в 22:19 ----------

Для себя выделил вот такие маленькие вкусности в версии 3.7, упрощающие кастомайз ВордПресса:

img_caption_shortcode_width

Находится в \wp-includes\media.php


add_shortcode('wp_caption', 'img_caption_shortcode');
add_shortcode('caption', 'img_caption_shortcode');

/**
* The Caption shortcode.
*
* Allows a plugin to replace the content that would otherwise be returned. The
* filter is 'img_caption_shortcode' and passes an empty string, the attr
* parameter and the content parameter values.
*
* The supported attributes for the shortcode are 'id', 'align', 'width', and
* 'caption'.
*
* @since 2.6.0
*
* @param array $attr Attributes attributed to the shortcode.
* @param string $content Optional. Shortcode content.
* @return string
*/
function img_caption_shortcode($attr, $content = null) {
// New-style shortcode with the caption inside the shortcode with the link and image tags.
if ( ! isset( $attr['caption'] ) ) {
if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) {
$content = $matches[1];
$attr['caption'] = trim( $matches[2] );
}
}

// Allow plugins/themes to override the default caption template.
$output = apply_filters('img_caption_shortcode', '', $attr, $content);
if ( $output != '' )
return $output;

$atts = shortcode_atts( array(
'id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => ''
), $attr, 'caption' );

$atts['width'] = (int) $atts['width'];
if ( $atts['width'] < 1 || empty( $atts['caption'] ) )
return $content;

if ( ! empty( $atts['id'] ) )
$atts['id'] = 'id="' . esc_attr( $atts['id'] ) . '" ';

$caption_width = 10 + $atts['width'];

/**
* Filter the width of an image's caption.
*
* By default, the caption is 10 pixels greater than the width of the image,
* to prevent post content from running up against a floated image.
*
* @since 3.7.0

*
* @param int $caption_width Width in pixels. To remove this inline style, return zero.
* @param array $atts {
* The attributes of the caption shortcode.
*
* @type string 'id' The ID of the div element for the caption.
* @type string 'align' The class name that aligns the caption. Default 'alignnone'.
* @type int 'width' The width of the image being captioned.
* @type string 'caption' The image's caption.
* }
* @param string $content The image element, possibly wrapped in a hyperlink.
*/
$caption_width = apply_filters( 'img_caption_shortcode_width', $caption_width, $atts, $content );

$style = '';
if ( $caption_width )
$style = 'style="width: ' . (int) $caption_width . 'px" ';

return '<div ' . $atts['id'] . $style . 'class="wp-caption ' . esc_attr( $atts['align'] ) . '">'
. do_shortcode( $content ) . '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
}

Щас ещё напишу, ждём. :D

K
На сайте с 02.07.2012
Offline
9
#212

Очень похоже что эта цифра - это ширина картинки +10000 px

J
На сайте с 21.08.2011
Offline
78
#213

Аудио- и видео-шорткоды (не от слова "шорты", а от слова "short"🤪 ) теперь легко кастомайзить (добавили фильтры для них):

Всё в том же media.php находится.


function wp_audio_shortcode( $attr, $content = '' ) {
$post_id = get_post() ? get_the_ID() : 0;

static $instances = 0;
$instances++;

/**
* Override the default audio shortcode.
*
* @since 3.7.0
*
* @param null Empty variable to be replaced with shortcode markup.
* @param array $attr Attributes of the shortcode.
* @param string $content Shortcode content.
* @param int $instances Unique numeric ID of this audio shortcode instance.

*/
$html = apply_filters( 'wp_audio_shortcode_override', '', $attr, $content, $instances );
if ( '' !== $html )
return $html;

$audio = null;

$default_types = wp_get_audio_extensions();
$defaults_atts = array(
'src' => '',
'loop' => '',
'autoplay' => '',
'preload' => 'none'
);
foreach ( $default_types as $type )
$defaults_atts[$type] = '';

$atts = shortcode_atts( $defaults_atts, $attr, 'audio' );
extract( $atts );

$primary = false;
if ( ! empty( $src ) ) {
$type = wp_check_filetype( $src, wp_get_mime_types() );
if ( ! in_array( strtolower( $type['ext'] ), $default_types ) )
return sprintf( '<a class="wp-embedded-audio" href="%s">%s</a>', esc_url( $src ), esc_html( $src ) );
$primary = true;
array_unshift( $default_types, 'src' );
} else {
foreach ( $default_types as $ext ) {
if ( ! empty( $$ext ) ) {
$type = wp_check_filetype( $$ext, wp_get_mime_types() );
if ( strtolower( $type['ext'] ) === $ext )
$primary = true;
}
}
}

if ( ! $primary ) {
$audios = get_attached_media( 'audio', $post_id );
if ( empty( $audios ) )
return;

$audio = reset( $audios );
$src = wp_get_attachment_url( $audio->ID );
if ( empty( $src ) )
return;

array_unshift( $default_types, 'src' );
}

$library = apply_filters( 'wp_audio_shortcode_library', 'mediaelement' );
if ( 'mediaelement' === $library && did_action( 'init' ) ) {
wp_enqueue_style( 'wp-mediaelement' );
wp_enqueue_script( 'wp-mediaelement' );
}

$atts = array(
'class' => apply_filters( 'wp_audio_shortcode_class', 'wp-audio-shortcode' ),
'id' => sprintf( 'audio-%d-%d', $post_id, $instances ),
'loop' => $loop,
'autoplay' => $autoplay,
'preload' => $preload,
'style' => 'width: 100%',
);

// These ones should just be omitted altogether if they are blank
foreach ( array( 'loop', 'autoplay', 'preload' ) as $a ) {
if ( empty( $atts[$a] ) )
unset( $atts[$a] );
}

$attr_strings = array();
foreach ( $atts as $k => $v ) {
$attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
}

$html = '';
if ( 'mediaelement' === $library && 1 === $instances )
$html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
$html .= sprintf( '<audio %s controls="controls">', join( ' ', $attr_strings ) );

$fileurl = '';
$source = '<source type="%s" src="%s" />';
foreach ( $default_types as $fallback ) {
if ( ! empty( $$fallback ) ) {
if ( empty( $fileurl ) )
$fileurl = $$fallback;
$type = wp_check_filetype( $$fallback, wp_get_mime_types() );
$html .= sprintf( $source, $type['type'], esc_url( $$fallback ) );
}
}

if ( 'mediaelement' === $library )
$html .= wp_mediaelement_fallback( $fileurl );
$html .= '</audio>';

return apply_filters( 'wp_audio_shortcode', $html, $atts, $audio, $post_id, $library );
}
add_shortcode( 'audio', 'wp_audio_shortcode' );

/**
* Return a filtered list of WP-supported video formats
*
* @since 3.6.0
* @return array
*/
function wp_get_video_extensions() {
return apply_filters( 'wp_video_extensions', array( 'mp4', 'm4v', 'webm', 'ogv', 'wmv', 'flv' ) );
}

/**
* The Video shortcode.
*
* This implements the functionality of the Video Shortcode for displaying
* WordPress mp4s in a post.
*
* @since 3.6.0
*
* @param array $attr Attributes of the shortcode.
* @param string $content Optional. Shortcode content.
* @return string HTML content to display video.
*/
function wp_video_shortcode( $attr, $content = '' ) {
global $content_width;
$post_id = get_post() ? get_the_ID() : 0;

static $instances = 0;
$instances++;

/**
* Override the default video shortcode.
*
* @since 3.7.0
*
* @param null Empty variable to be replaced with shortcode markup.
* @param array $attr Attributes of the shortcode.
* @param string $content Shortcode content.
* @param int $instances Unique numeric ID of this video shortcode instance.

*/
$html = apply_filters( 'wp_video_shortcode_override', '', $attr, $content, $instances );
if ( '' !== $html )
return $html;

$video = null;

$default_types = wp_get_video_extensions();
$defaults_atts = array(
'src' => '',
'poster' => '',
'loop' => '',
'autoplay' => '',
'preload' => 'metadata',
'height' => 360,
'width' => empty( $content_width ) ? 640 : $content_width,
);

foreach ( $default_types as $type )
$defaults_atts[$type] = '';

$atts = shortcode_atts( $defaults_atts, $attr, 'video' );
extract( $atts );

$w = $width;
$h = $height;
if ( is_admin() && $width > 600 )
$w = 600;
elseif ( ! is_admin() && $w > $defaults_atts['width'] )
$w = $defaults_atts['width'];

if ( $w < $width )
$height = round( ( $h * $w ) / $width );

$width = $w;

$primary = false;
if ( ! empty( $src ) ) {
$type = wp_check_filetype( $src, wp_get_mime_types() );
if ( ! in_array( strtolower( $type['ext'] ), $default_types ) )
return sprintf( '<a class="wp-embedded-video" href="%s">%s</a>', esc_url( $src ), esc_html( $src ) );
$primary = true;
array_unshift( $default_types, 'src' );
} else {
foreach ( $default_types as $ext ) {
if ( ! empty( $$ext ) ) {
$type = wp_check_filetype( $$ext, wp_get_mime_types() );
if ( strtolower( $type['ext'] ) === $ext )
$primary = true;
}
}
}

if ( ! $primary ) {
$videos = get_attached_media( 'video', $post_id );
if ( empty( $videos ) )
return;

$video = reset( $videos );
$src = wp_get_attachment_url( $video->ID );
if ( empty( $src ) )
return;

array_unshift( $default_types, 'src' );
}

$library = apply_filters( 'wp_video_shortcode_library', 'mediaelement' );
if ( 'mediaelement' === $library && did_action( 'init' ) ) {
wp_enqueue_style( 'wp-mediaelement' );
wp_enqueue_script( 'wp-mediaelement' );
}

$atts = array(
'class' => apply_filters( 'wp_video_shortcode_class', 'wp-video-shortcode' ),
'id' => sprintf( 'video-%d-%d', $post_id, $instances ),
'width' => absint( $width ),
'height' => absint( $height ),
'poster' => esc_url( $poster ),
'loop' => $loop,
'autoplay' => $autoplay,
'preload' => $preload,
);

// These ones should just be omitted altogether if they are blank
foreach ( array( 'poster', 'loop', 'autoplay', 'preload' ) as $a ) {
if ( empty( $atts[$a] ) )
unset( $atts[$a] );
}

$attr_strings = array();
foreach ( $atts as $k => $v ) {
$attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
}

$html = '';
if ( 'mediaelement' === $library && 1 === $instances )
$html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n";
$html .= sprintf( '<video %s controls="controls">', join( ' ', $attr_strings ) );

$fileurl = '';
$source = '<source type="%s" src="%s" />';
foreach ( $default_types as $fallback ) {
if ( ! empty( $$fallback ) ) {
if ( empty( $fileurl ) )
$fileurl = $$fallback;
$type = wp_check_filetype( $$fallback, wp_get_mime_types() );
// m4v sometimes shows up as video/mpeg which collides with mp4
if ( 'm4v' === $type['ext'] )
$type['type'] = 'video/m4v';
$html .= sprintf( $source, $type['type'], esc_url( $$fallback ) );
}
}
if ( 'mediaelement' === $library )
$html .= wp_mediaelement_fallback( $fileurl );
$html .= '</video>';

$html = sprintf( '<div style="width: %dpx; max-width: 100%%;">%s</div>', $width, $html );
return apply_filters( 'wp_video_shortcode', $html, $atts, $video, $post_id, $library );
}
add_shortcode( 'video', 'wp_video_shortcode' );
Kordi:
Очень похоже что эта цифра - это ширина картинки +10000 px

Именно!

----------

Ещё вот этот полезный фильтр добавили: ajax_query_attachments_args

-------

Тоже приятная возможность: http://wphooks.info/filters/posts_search_orderby/

exarh
На сайте с 28.03.2010
Offline
503
#214

В ДЛЕ , удаляются все картинки, которые не привязаны к той или иной новости.

В Вордпресе же, у меня много картинок , не используемых в новостях.

Есть ли плагин какй или скрипт , удаляющий картинки неиспользуемые.

В ручную ковырять жутко))

Монетизируй (https://publishers.propellerads.com/#/pub/auth/signUp?ref_id=tnE) свой сайт с выгодой
J
На сайте с 21.08.2011
Offline
78
#215

exarh, можно самому написать, не? Не плагин, а скриптик, который бы выудил из базы все *.jpg( + *.png + .etc), а затем удалить все файлы, которые не нашлись в БД.

exarh
На сайте с 28.03.2010
Offline
503
#216
Jovian:
exarh, можно самому написать, не? Не плагин, а скриптик, который бы выудил из базы все *.jpg( + *.png + .etc), а затем удалить все файлы, которые не нашлись в БД.

Думал об этом, но мой прогер на выходных уже, а сам я такое не осилю )). Вот и подумал может есть готовое решение. Погуглив - не увидел, решил спросить.

нашел DNUI Delete not used image, буду пробовать

SeVlad
На сайте с 03.11.2008
Offline
1609
#217
exarh:

Есть ли плагин какй или скрипт , удаляющий картинки неиспользуемые.

Есть. Названий не помню, но найти сможешь и сам

Делаю хорошие сайты хорошим людям. Предпочтение коммерческим направлениям. Связь со мной через http://wp.me/P3YHjQ-3.
MrDesigner
На сайте с 31.01.2008
Offline
210
#218
Kordi:
Да! И если убрать подпись под фото - все становится красиво и обтекает как положено.

Проверил на нескольких сайтах. До обновления все в порядке - после обновления - баг. Шаблоны на всех разные.

Может подскажет кто?

Проблема временно решается с помощью костыля.

в файл wp-config.php добавить строчку

define('SCRIPT_DEBUG', true);

А так - ждём официального апдейта.

J
На сайте с 21.08.2011
Offline
78
#219

Что-то я не нашёл, где в админке контролируются параметры автоматических апдейтов. Или только хардкодить переменные?

Cchale
На сайте с 08.07.2012
Offline
76
#220
Vladist:
Чтобы отключить редакции записей, надо в файл wp-config.php поместить такой код:

define('WP_POST_REVISIONS', false );


или такой:

define('WP_POST_REVISIONS', 0 );

доброе время суток, пробовал оба кода в конфиг вставить. Не помогло - редакции снова создаются.

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий