如何判断Jetpack的光子是否处于活动状态?

时间:2012-12-06 作者:m-torin

有多种方法可以确定插件是否处于活动状态(here\'s one) 但我们如何识别特定的喷气式飞机组件是否处于活动状态,例如Photon?

2 个回复
最合适的回答,由SO网友:George Stephanis 整理而成

我们刚刚向Jetpack Trunk提交了一个新功能,它应该在下一个版本中启用,Jetpack::is_module_active() --

http://plugins.trac.wordpress.org/changeset/716884

然后你可以打电话:

if( class_exists( \'Jetpack\' ) && Jetpack::is_module_active( \'contact-form\' ) ) {}
或者至少,您将在下一个版本发布后,用户将更新其Jetpack。:)如果要保持向后兼容性,可以执行以下操作:

if( class_exists( \'Jetpack\' ) && in_array( \'contact-form\', Jetpack::get_active_modules() ) {}
这是一种比直接查询选项稍微整洁的方法。

SO网友:brasofilo

检查选项值jetpack_active_modules.

database option value

正在搜索photon 在wp\\U选项中option_name.

以下内容将该选项打印为管理通知:

add_action( \'admin_notices\', \'wpse_75103_active_jetpack_modules\' );

function wpse_75103_active_jetpack_modules() 
{
    if( !current_user_can( \'delete_users\' ) )
        return;

    $jetp = get_option( \'jetpack_active_modules\' );

    $photon_active = ( in_array( \'photon\', $jetp ) ) ? \'is\' : \'is not\';
    echo \'<h1>Photon \' . $photon_active . \' active</h1>\';

    echo \'<h2>All JetPack Options</h2>\';
    echo \'<pre>\' . print_r( $jetp, true ) . \'</pre>\';
}
以下是所有模块激活后的结果
The key numbers are in the order by which the modules were activated and should not be used as reference.
in a local host installation )

Array
(
    [0] => vaultpress
    [1] => photon
    [3] => notes
    [5] => publicize
    [7] => stats
    [9] => comments
    [11] => subscriptions
    [13] => post-by-email
    [15] => carousel
    [17] => sharedaddy
    [19] => after-the-deadline
    [21] => infinite-scroll
    [23] => enhanced-distribution
    [25] => json-api
    [27] => mobile-push
    [29] => widgets
    [31] => latex
    [33] => gravatar-hovercards
    [35] => contact-form
    [37] => minileven
    [39] => custom-css
    [41] => shortcodes
    [43] => shortlinks
)

结束