WordPress - 覆盖模板插件简码

WordPress - Overwriting a template plugin Shortcode

我是 php 和 wordpress 的新手。 当我从管理面板中的主题编辑图标框时,我有几个字段,例如 "title" 和 "content"。标题在<h4> </h4>内,内容在<p> </p>内 我需要在内容后添加另一个 <p style='iconbox_price'></p>,以便我可以在管理面板中编辑它。

这是图标框的代码。我怎样才能将它添加到它,所以它会成功。

<?php
function easyweb_webnus_iconbox( $attributes, $content = null ) {

extract(shortcode_atts(array(
    "type"=>'',
    'icon_title'=>'',
    'icon_link_url'=>'',
    'icon_link_text'=>'',
    "icon_name"=>'',
    "iconbox_content"=>'',
    "icon_size"=>'',
    "icon_color"=>'',
    "title_color"=>'',
    "content_color"=>'',
    "link_color"=>'',
    "icon_image"=>'',
    "featured"=>'',
    "border_left"=>'',
    "border_right"=>'',
), $attributes));
ob_start();

$type =  ( $type == 0 ) ? '' : $type ;

$iconbox_style = $type17_start_wrap = $type17_end_wrap = '';
if ( $type==17 ) {
    $iconbox_style = ( !empty($icon_color) ) ? ' style="color: ' . esc_attr($icon_color) . '"' : '' ;
    $type17_start_wrap = '<div class="icon-wrap" style="background-color:' . esc_attr($icon_color) . '">';
    $type17_end_wrap   = '</div>';
}

$iconbox22_class = '';
if ( $type == 22 ) {
    $iconbox22_class .= $featured ? ' ' . $featured : '';
    $iconbox22_class .= $border_left ? ' ' . $border_left : '';
    $iconbox22_class .= $border_right ? ' ' . $border_right : '';
}

echo '<article class="icon-box' . $type . $iconbox22_class . '" ' . $iconbox_style . '>';

    if(!empty($icon_name) && $icon_name != 'none') :
        if(!empty($icon_link_url))
            echo '' . $type17_start_wrap . '<a href="' . esc_url($icon_link_url) . '">'  . do_shortcode(  "[icon name='$icon_name' size='$icon_size' color='$icon_color']" ).'</a>' . $type17_end_wrap . '';
        else
            echo $type17_start_wrap . do_shortcode(  "[icon name='$icon_name' size='$icon_size' color='$icon_color']" ) . $type17_end_wrap;
    elseif(!empty($icon_image)) :
        if(is_numeric($icon_image)){
            $icon_image = wp_get_attachment_url( $icon_image );
        }
        if(!empty($icon_link_url))
            echo "<a href='$icon_link_url'>" . '<img src="'.$icon_image.'" alt="" />' . '</a>' ;
        else
            echo '<img src="'.$icon_image.'" alt="" />';
    endif;

    $title_style = !empty($title_color)?' style="color:'.$title_color.'"':'';
     echo '<h4'.$title_style.'>' . $icon_title . '</h4>';
     $content_style = !empty($content_color)?' style="color:'.$content_color.'"':'';
     echo '<p'.$content_style.'>'.$iconbox_content .'</p>' ;
     $link_style = !empty($link_color)?' style="color:'.$link_color.'"':'';
     echo (!empty($icon_link_url) &&  (!empty($icon_link_text)) )?"<a".$link_style." class=\"magicmore\" href=\"{$icon_link_url}\">{$icon_link_text}</a>":'';

echo '</article>';

$out = ob_get_contents();
ob_end_clean();
$out = str_replace('<p></p>','',$out);
    return $out;
 }
 add_shortcode('iconbox', 'easyweb_webnus_iconbox');

在html中这是生成的代码:

<article class="icon-box14">
    <a href="/razrabotka-saitov/">
    <i class="sl-screen-desktop" style=" font-size:42px;"></i>
    </a>
    <h4 style="height: 22px;">Title</h4>
    <p style="height: 116px;">Content<br></p>
    <a class="magicmore" href="#">More</a>
</article>

你看到那一行:

echo '<p'.$content_style.'>'.$iconbox_content .'</p>' ;

您可以将自定义段落添加到该行:

echo '<p'.$content_style.'>'.$iconbox_content .'</p>
<p style='iconbox_price'></p>' ;

我在我的案例中找到了解决方案。也许它会帮助别人。我不得不编辑两个文件。在我的例子中,这是第一个文件所在的位置。

wp-content/plugins/'theme'-shortcodes/shortcodes/iconbox.php

我试图寻找变量 $iconbox_content 的来源,并在此时从上面的代码中从数组中提取了它:

extract(shortcode_atts(array(
        "type"=>'',
        'icon_title'=>'',
        'icon_link_url'=>'',
        'icon_link_text'=>'',
        "icon_name"=>'',
        "iconbox_content"=>'',
        "icon_size"=>'',
        "icon_color"=>'',
        "title_color"=>'',
        "content_color"=>'',
        "link_color"=>'',
        "icon_image"=>'',
        "featured"=>'',
        "border_left"=>'',
        "border_right"=>'',
    ), $attributes));

所以我搜索了所有 wordpress 目录文件,因为我什至不知道在哪里可以找到它。 并在 themes => 'my theme' => 'my theme' => visualcomposer => shortcodes 目录中找到它作为 03-iconbox.php

我有不同的数组,例如:

    array(
        "type"=>'textarea',
        "heading"=>esc_html__('Content', 'ew'),
        "param_name"=> "iconbox_content",
        "value"=>"",
        "description" => esc_html__( "IconBox Content Goes Here", 'ew') 
    ),

所以我想,我所做的另一半已经很合乎逻辑了,但无论如何:

我在这个文件中添加了一个数组:

    array(
        "type"=>'textarea',
        "heading"=>esc_html__('Price', 'ew'),
        "param_name"=> "iconbox_price",
        "value"=>"",
        "description" => esc_html__( "Price goes here", 'ew')   
    ),

在第一个文件中: 提取 "iconbox_price" =>'',

及以下:echo '<p class="iconbox_price">'.$iconbox_price .'</p>' ;

希望这对某人有所帮助!