0

For example, I have the following code:

<?php 

$options = array( 

    array(
        "type" => "section",
        "icon" => "acera-icon-preference",
        "title" => "General Settings",
        "id" => "general",
        "expanded" => "true"
    ),
array(
        "under_section" => "ajax_login",
        "type" => "checkbox",
        "name" => "Who's Online Options",
        "id" => array("tigu_whosonline_list", "tigu_whosonline_avatar"),
        "display_checkbox_id" => "tigu_show_whosonline",
        "img_desc" => "", 
        "options" => array("Who's Online List", "Who's Online Avatars"),
        "desc" => "",
        "default" => array("checked", "checked")

) );

?>

There a more arrays but I shortened the code to save space. The question is: How can I include only the following code

 array(
            "type" => "section",
            "icon" => "acera-icon-preference",
            "title" => "General Settings",
            "id" => "general",
            "expanded" => "true"
        ),

in a conditional if somethink like this code (that get errors):

if(function_exists('bp_is_active') ): 

  array(
                "type" => "section",
                "icon" => "acera-icon-preference",
                "title" => "General Settings",
                "id" => "general",
                "expanded" => "true"
            ),

endif;

The function bp_is_active it check if BuddyPress plugin is instaled. I need that code to be displayed on my wp admin panel only if BuddyPress plugin is instaled.

Thanks!

4

2 に答える 2

0

?:三項条件演算子を使用できます。

$options = array(
  function_exists('bp_is_active') // condition
    ? array(...stuff...)          // if true
    : array(),                    // if false
  ...more arrays...
);

条件が false の場合、空の配列が使用されます。( とは対照的にarray()) そこに何も必要ない場合は、もっと複雑なものが必要になります。

于 2013-04-14T07:42:50.913 に答える
0

(;)次のコードは有効です。

 if(function_exists('bp_is_active') ): 
     array(
            "type" => "section",
            "icon" => "acera-icon-preference",
            "title" => "General Settings",
            "id" => "general",
            "expanded" => "true"
          ); // <<--here

    endif;

またはなしendif:

     if(function_exists('bp_is_active') ){ 
     array(
            "type" => "section",
            "icon" => "acera-icon-preference",
            "title" => "General Settings",
            "id" => "general",
            "expanded" => "true"
          ); // <<--here
     }
于 2013-04-14T07:45:23.693 に答える