digitoimistodude/dude-really-simple-ads

管理、跟踪和展示广告的简单方式

1.2.4 2024-06-11 08:44 UTC

This package is auto-updated.

Last update: 2024-09-11 09:15:36 UTC


README

注意 此广告插件被认为是过时的。您应该真正考虑使用 air-ads

非常简单的广告

version_1.2.2 Tested_up_to WordPress_5.6 Compatible_with PHP_7.0

Digitoimisto Dude Oy 是一家位于约维萨市中心的爱沙尼亚精品数字代理机构。

目录

请注意在使用前

使用此代码库时,您同意任何内容都可以在不警告的情况下改变方向。

功能

基本功能列表包括

  • 多个广告位置
  • 包含多个广告的活动
  • 具有开始和结束时间的计划广告
  • 具有开始和结束时间的计划活动
  • 每个广告的简单查看和点击计数器 (JavaScript)
  • 广告查看节流防止,因此F5不会增加显示计数 (JavaScript)
  • 广告和活动的私人笔记

使用方法

注册广告位置

使用 drsa_ad_placement_sizes 钩子注册广告位置。您应该传递一个嵌套数组,每个广告位置包含一个数组元素。下面是一个基本示例。

add_filter( 'drsa_ad_placement_sizes', 'myprefix_register_ad_places' );
function myprefix_register_ad_places() {
    $spots = array(
        array(
            // title whichs shows when adding ads
            'name'      => __( 'Frontpage default' ),

            // unique identified for this placed, used to get ads
            'id'        => 'frontpage-default',

            // add size, uploaded image will be tested against these values
            'width'     => 480,
            'height'    => 480,

            // for having multiple ads in the same place, ads will be shown in the order of least shown to most shown
            'multiple'  => true,
        ),
    );

    return $spots;
}

获取活动广告

获取活动广告相当简单,只需使用 get_the_active_ad 函数并传递用作参数的使用的广告位置。

如果该广告位置有活动活动,将返回分配给选定位置的随机活动广告。如果没有活动活动,则返回位置的活动单个广告。如果没有找到活动活动或广告,将返回默认广告和链接,如果没有默认项,则返回值为false。

如果存在广告,则返回包含广告位置名称、图像src、目标地址和点击计数器类的数组。以下是一个简单的示例,但您可以根据需要修改它。点击计数器类需要与目标href在同一元素中。

$ad = false;
if ( function_exists( 'get_the_active_ad' ) ) {
    $ad = get_the_active_ad( 'frontpage-default' );
}

if ( $ad ) {
    echo '<a href="' . $ad['target'] . '" target="_blank" class="' . $ad['click_counter_class'] . '"><img src="' . $ad['src'] . '" class="ad ad-place-' . $ad['place'] . '"/></a>';
}

始终检查函数的存在。

添加短代码以将广告嵌入内容

您可以在需要广告的任何位置创建自己的短代码,例如在博客文章的内容中。下面是短代码使用的一个简单示例。

add_shortcode( 'ad', 'myprefix_shortcode_show_ad' );
function myprefix_shortcode_show_ad( $atts ) {
    if ( ! function_exists( 'get_the_active_ad' ) ) {
        return; // plugin not active, bail
    }

    if ( empty( $atts ) ) {
        return; // no attributes to shortcode, bail
    }

    // no ad place defined, show error to user and bail if visitor
    if ( ! isset( $atts['place'] ) ) {
        if ( is_user_logged_in() && current_user_can( 'edit_others_posts' ) ) {
            return __( 'No ad place defined', 'textdomain' );
        } else {
            return;
        }
    }

    // get the ad
    $ad = get_the_active_ad( $atts['place'] );

    // no active ad, show error to user and bail if visitor
    if ( ! $ad ) {
        if ( is_user_logged_in() && current_user_can( 'edit_others_posts' ) ) {
            return __( 'No active ads or campaigns', 'textdomain' );
        } else {
            return;
        }
    }

    // return ad html
    return '<a href="' . $ad['target'] . '" target="_blank" class="' . $ad['click_counter_class'] . '"><img src="' . $ad['src'] . '" class="ad ad-place-' . $ad['place'] . '"/></a>';
}

钩子

插件包含一系列钩子,您可以使用和修改插件的行为。

设置默认广告和链接

如果没有为该位置设置活动广告,您可以使用两个不同的钩子设置该广告位置的问题的默认图像和链接。

使用过滤器 drsa_default_ad/{place-id} 设置默认广告图像src。使用过滤器 drsa_default_ad_target/{place-id} 设置默认广告地址。

禁用广告目标URL中的UTM标签

默认情况下,将自动向广告目标地址插入UTM标签,使用过滤器 drsa_use_utm 禁用它。

要全局禁用,请使用 add_filter( 'drsa_use_utm', '__return_false' ); 要按广告位置禁用,请使用 add_filter( 'drsa_use_utm\{place-id}', '__return_false' ); 要按单个广告禁用,请使用 add_filter( 'drsa_use_utm\ad\{ad-id}', '__return_false' );

禁用或更改广告查看节流时间

如果访客在首次访问后的30秒内重新加载页面或在同一页面再次访问,则新的访问不计入广告观看次数。如果相同的广告在多个页面中显示,每个页面都有其自己的节流预防。例如,如果广告在侧边栏中,首页在30秒内重新加载不计入新观看次数,但在其他页面中的访问会计算在内。

这是一种简单的预防措施,以确保观看次数的准确性。

使用过滤器 drsa_counter_cookie_timeout 修改节流时间,以毫秒为单位返回节流时间。要禁用此功能,请返回零。

在达到特定观看次数后结束广告显示

将过滤器 drsa_end_ads_by_show_count 设置为 true,以将广告结束从日期切换到观看次数。

允许广告有替代图片

将过滤器 drsa_allow_alternative_image 设置为 true,以允许广告有替代图片。这将在广告编辑屏幕中添加一个替代图片字段。使用过滤器 drsa_alternative_image_description_text 修改字段的描述。默认为 ''。

变更日志

更改日志可以在发布页面找到。

贡献

如果您对插件有任何想法或发现问题,请告诉我们。在贡献想法或报告有关“缺失”功能或该问题性质的问题之前,请阅读请注意部分。非常感谢。

待办事项

[ ] 更好的内联注释