[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-forums/bbpress/bb-admin/ -> options-wordpress.php (source)

   1  <?php
   2  
   3  require_once ('admin.php');
   4  
   5  if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) )
   6      $action = @$_POST['action'];
   7  else
   8      $action = false;
   9  
  10  if ( in_array( $action, array('update-users', 'update-options') ) ) {
  11      bb_check_admin_referer( 'options-wordpress-' . $action );
  12      
  13      // Deal with advanced user database checkbox when it isn't checked
  14      if (!isset($_POST['user_bbdb_advanced'])) {
  15          $_POST['user_bbdb_advanced'] = false;
  16      }
  17      
  18      foreach ( (array) $_POST as $option => $value ) {
  19          if ( !in_array( $option, array('_wpnonce', '_wp_http_referer', 'action', 'submit') ) ) {
  20              $option = trim( $option );
  21              $value = is_array( $value ) ? $value : trim( $value );
  22              $value = stripslashes_deep( $value );
  23              if ( ( $option == 'wp_siteurl' || $option == 'wp_home' ) && !empty( $value ) ) {
  24                  $value = rtrim( $value, " \t\n\r\0\x0B/" ) . '/';
  25              }
  26              if ( $value ) {
  27                  bb_update_option( $option, $value );
  28              } else {
  29                  bb_delete_option( $option );
  30              }
  31          }
  32      }
  33      
  34      if ($action == 'update-users') {
  35          bb_apply_wp_role_map_to_orphans();
  36      }
  37      
  38      $goback = add_query_arg('updated', $action, wp_get_referer());
  39      bb_safe_redirect($goback);
  40      exit;
  41  }
  42  
  43  switch (@$_GET['updated']) {
  44      case 'update-users':
  45          bb_admin_notice( __( '<strong>User role mapping saved.</strong>' ) );
  46          break;
  47      case 'update-options':
  48          bb_admin_notice( __( '<strong>User integration settings saved.</strong>' ) );
  49          break;
  50  }
  51  
  52  
  53  
  54  $bb_role_names[''] = _c( 'none|no bbPress role' );
  55  $bb_role_names = array_merge( $bb_role_names, array_map( create_function( '$a', 'return sprintf( _c( "bbPress %s|bbPress role" ), $a );' ), $wp_roles->get_names() ) );
  56  
  57  $wpRoles = array(
  58      'administrator' => __('WordPress Administrator'),
  59      'editor'        => __('WordPress Editor'),
  60      'author'        => __('WordPress Author'),
  61      'contributor'   => __('WordPress Contributor'),
  62      'subscriber'    => __('WordPress Subscriber')
  63  );
  64  
  65  $wpRoles = apply_filters( 'role_map_wp_roles', $wpRoles );
  66  
  67  $cookie_options = array(
  68      'wp_siteurl' => array(
  69          'title' => __( 'WordPress address (URL)' ),
  70          'class' => 'long',
  71          'note' => __( 'This value should exactly match the <strong>WordPress address (URL)</strong> setting in your WordPress general settings.' )
  72      ),
  73      'wp_home' => array(
  74          'title' => __( 'Blog address (URL)' ),
  75          'class' => 'long',
  76          'note' => __( 'This value should exactly match the <strong>Blog address (URL)</strong> setting in your WordPress general settings.' )
  77      ),
  78      'bb_auth_salt' => array(
  79          'title' => __( 'WordPress "auth" cookie salt' ),
  80          'note' => __( 'This must match the value of the WordPress setting named "auth_salt" in your WordPress site. Look for the option labeled "auth_salt" in <a href="#" id="getAuthSaltOption" onclick="window.open(this.href); return false;">this WordPress admin page</a>.' )
  81      ),
  82      'bb_secure_auth_salt' => array(
  83          'title' => __( 'WordPress "secure auth" cookie salt' ),
  84          'note' => __( 'This must match the value of the WordPress setting named "secure_auth_salt" in your WordPress site. Look for the option labeled "secure_auth_salt" in <a href="#" id="getSecureAuthSaltOption" onclick="window.open(this.href); return false;">this WordPress admin page</a>. Sometimes this value is not set in WordPress, in that case you can leave this setting blank as well.' )
  85      ),
  86      'bb_logged_in_salt' => array(
  87          'title' => __( 'WordPress "logged in" cookie salt' ),
  88          'note' => __( 'This must match the value of the WordPress setting named "logged_in_salt" in your WordPress site. Look for the option labeled "logged_in_salt" in <a href="#" id="getLoggedInSaltOption" onclick="window.open(this.href); return false;">this WordPress admin page</a>.' )
  89      )
  90  );
  91  
  92  foreach ( array( 'bb_auth_salt', 'bb_secure_auth_salt', 'bb_logged_in_salt' ) as $salt_constant ) {
  93      if ( defined( strtoupper( $salt_constant ) ) ) {
  94          $cookie_options[$salt_constant]['note'] = array(
  95              sprintf( __( 'You have defined the "%s" constant which locks this setting.' ), strtoupper( $salt_constant ) ),
  96              $cookie_options[$salt_constant]['note'],
  97          );
  98          $cookie_options[$salt_constant]['value'] = constant( strtoupper( $salt_constant ) );
  99          $bb_hardcoded[$salt_constant] = true;
 100      }
 101  }
 102  
 103  $user_db_options = array(
 104      'wp_table_prefix' => array(
 105          'title' => __( 'User database table prefix' ),
 106          'note'  => __( 'If your bbPress and WordPress sites share the same database, then this is the same value as <code>$table_prefix</code> in your WordPress <code>wp-config.php</code> file. It is usually <strong>wp_</strong>.' )
 107      ),
 108      'wordpress_mu_primary_blog_id' => array(
 109          'title' => __( 'WordPress MU primary blog ID' ),
 110          'note'  => __( 'If you are integrating with a WordPress MU site you need to specify the primary blog ID for that site. It is usually <strong>1</strong>. You should probably leave this blank if you are integrating with a standard WordPress site' )
 111      ),
 112      'user_bbdb_advanced' => array(
 113          'title' => __( 'Show advanced database settings' ),
 114          'type' => 'checkbox',
 115          'options' => array(
 116              1 => array(
 117                  'label' => __( 'If your bbPress and WordPress site do not share the same database, then you will need to add advanced settings.' ),
 118                  'attributes' => array( 'onclick' => 'toggleAdvanced(this);' )
 119              )
 120          )
 121      )
 122  );
 123  
 124  $advanced_user_db_options = array(
 125      'user_bbdb_name' => array(
 126          'title' => __( 'User database name' ),
 127          'note' => __( 'The name of the database in which your user tables reside.' )
 128      ),
 129      'user_bbdb_user' => array(
 130          'title' => __( 'User database user' ),
 131          'note' => __( 'The database user that has access to that database.' )
 132      ),
 133      'user_bbdb_password' => array(
 134          'title' => __( 'User database password' ),
 135          'note' => __( 'That database user\'s password.' )
 136      ),
 137      'user_bbdb_host' => array(
 138          'title' => __( 'User database host' ),
 139          'note' => __( 'The domain name or IP address of the server where the database is located. If the database is on the same server as the web site, then this probably should be <strong>localhost</strong>.' )
 140      ),
 141      'user_bbdb_charset' => array(
 142          'title' => __( 'User database character set' ),
 143          'note' => __( 'The best choice is <strong>utf8</strong>, but you will need to match the character set which you created the database with.' )
 144      ),
 145      'user_bbdb_collate' => array(
 146          'title' => __( 'User database character collation' ),
 147          'note' => __( 'The character collation value set when the user database was created.' )
 148      )
 149  );
 150  
 151  $custom_table_options = array(
 152      'custom_user_table' => array(
 153          'title' => __( 'User database "user" table' ),
 154          'note' => __( 'The complete table name, including any prefix.' ),
 155      ),
 156      'custom_user_meta_table' => array(
 157          'title' => __( 'User database "user meta" table' ),
 158          'note' => __( 'The complete table name, including any prefix.' ),
 159      ),
 160  );
 161  
 162  $advanced_display = bb_get_option( 'user_bbdb_advanced' ) ? 'block' : 'none';
 163  
 164  $bb_admin_body_class = ' bb-admin-settings';
 165  
 166  bb_get_admin_header();
 167  
 168  ?>
 169  
 170  <div class="wrap">
 171  
 172  <h2><?php _e( 'WordPress Integration Settings' ); ?></h2>
 173  <?php do_action( 'bb_admin_notices' ); ?>
 174  
 175  <form class="settings" method="post" action="<?php bb_uri('bb-admin/options-wordpress.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_ADMIN); ?>">
 176      <fieldset>
 177          <legend><?php _e('User Role Map'); ?></legend>
 178          <p><?php _e('Here you can match WordPress roles to bbPress roles.'); ?></p>
 179          <p><?php _e('This will have no effect until your user tables are integrated below. Only standard WordPress roles are supported. Changes do not affect users with existing roles in both WordPress and bbPress.'); ?></p>
 180  <?php foreach ( $wpRoles as $wpRole => $wpRoleName ) bb_option_form_element( "wp_roles_map[$wpRole]", array( 'title' => $wpRoleName, 'type' => 'select', 'options' => $bb_role_names ) ); ?>
 181      </fieldset>
 182      <fieldset class="submit">
 183          <?php bb_nonce_field( 'options-wordpress-update-users' ); ?>
 184          <input type="hidden" name="action" value="update-users" />
 185          <input class="submit" type="submit" name="submit" value="<?php _e('Save Changes') ?>" />
 186      </fieldset>
 187  </form>
 188  
 189  <hr class="settings" />
 190  
 191  <div class="settings">
 192      <h3><?php _e('User Integration'); ?></h3>
 193      <p><?php _e('Usually, you will have to specify both cookie integration and user database integration settings. Make sure you have a "User role map" setup above before trying to add user integration.'); ?></p>
 194      <p><?php _e('<em><strong>Note:</strong> changing the settings below may cause you to be logged out!</em>'); ?></p>
 195  </div>
 196  
 197  <form class="settings" method="post" action="<?php bb_uri('bb-admin/options-wordpress.php', null, BB_URI_CONTEXT_FORM_ACTION + BB_URI_CONTEXT_BB_ADMIN); ?>">
 198      <fieldset>
 199          <legend><?php _e('Cookies'); ?></legend>
 200          <p><?php _e('Cookie sharing allows users to log in to either your bbPress or your WordPress site, and have access to both.'); ?></p>
 201      <?php foreach ( $cookie_options as $option => $args ) bb_option_form_element( $option, $args ); ?>
 202          <script type="text/javascript" charset="utf-8">
 203  /* <![CDATA[ */
 204  			function updateWordPressOptionURL () {
 205                  var siteURLInputValue = document.getElementById('wp-siteurl').value;
 206                  if (siteURLInputValue && siteURLInputValue.substr(-1,1) != '/') {
 207                      siteURLInputValue += '/';
 208                  }
 209                  var authSaltAnchor = document.getElementById('getAuthSaltOption');
 210                  var secureAuthSaltAnchor = document.getElementById('getSecureAuthSaltOption');
 211                  var loggedInSaltAnchor = document.getElementById('getLoggedInSaltOption');
 212                  if (siteURLInputValue) {
 213                      authSaltAnchor.href = siteURLInputValue + 'wp-admin/options.php';
 214                      secureAuthSaltAnchor.href = siteURLInputValue + 'wp-admin/options.php';
 215                      loggedInSaltAnchor.href = siteURLInputValue + 'wp-admin/options.php';
 216                  } else {
 217                      authSaltAnchor.href = '';
 218                      secureAuthSaltAnchor.href = '';
 219                      loggedInSaltAnchor.href = '';
 220                  }
 221              }
 222              var siteURLInput = document.getElementById('wp-siteurl');
 223              if (siteURLInput.value) {
 224                  updateWordPressOptionURL();
 225              }
 226              siteURLInput.onkeyup = updateWordPressOptionURL;
 227              siteURLInput.onblur = updateWordPressOptionURL;
 228              siteURLInput.onclick = updateWordPressOptionURL;
 229              siteURLInput.onchange = updateWordPressOptionURL;
 230  /* ]]> */
 231          </script>
 232  <?php
 233  $cookie_settings = array(
 234      'cookiedomain' => 'COOKIE_DOMAIN',
 235      'cookiepath' => 'COOKIEPATH'
 236  );
 237  $wp_settings = '';
 238  foreach ($cookie_settings as $bb_setting => $wp_setting) {
 239      if ( isset($bb->$bb_setting) ) {
 240          $wp_settings .= 'define(\'' . $wp_setting . '\', \'' . $bb->$bb_setting . '\');' . "\n";
 241      }
 242  }
 243  ?>
 244          <p><?php printf(__('To complete cookie integration, you will need to add some settings to your <code>wp-config.php</code> file in the root directory of your WordPress installation. To get those settings, you will need to install and configure the <a href="%s">"bbPress Integration" plugin for WordPress</a>.'), 'http://wordpress.org/extend/plugins/bbpress-integration/'); ?></p>
 245          <p><?php _e('You will also have to manually ensure that the following constants are equivalent in WordPress\' and bbPress\' respective config files.'); ?></p>
 246          <div class="table">
 247              <table>
 248                  <tr>
 249                      <th><?php _e('WordPress'); ?></th>
 250                      <td></td>
 251                      <th><?php _e('bbPress'); ?></th>
 252                  </tr>
 253                  <tr>
 254                      <td>AUTH_KEY</td>
 255                      <td>&lt;=&gt;</td>
 256                      <td>BB_AUTH_KEY</td>
 257                  </tr>
 258                  <tr>
 259                      <td>SECURE_AUTH_KEY</td>
 260                      <td>&lt;=&gt;</td>
 261                      <td>BB_SECURE_AUTH_KEY</td>
 262                  </tr>
 263                  <tr>
 264                      <td>LOGGED_IN_KEY</td>
 265                      <td>&lt;=&gt;</td>
 266                      <td>BB_LOGGED_IN_KEY</td>
 267                  </tr>
 268              </table>
 269          </div>
 270      </fieldset>
 271  
 272      <fieldset>
 273          <legend><?php _e('User database'); ?></legend>
 274          <p><?php _e('User database sharing allows you to store user data in your WordPress database.'); ?></p>
 275          <p><?php _e('You should setup a "User role map" before'); ?></p>
 276          <script type="text/javascript" charset="utf-8">
 277  			function toggleAdvanced(checkedObj) {
 278                  var advanced1 = document.getElementById('advanced1');
 279                  var advanced2 = document.getElementById('advanced2');
 280                  if (checkedObj.checked) {
 281                      advanced1.style.display = 'block';
 282                      advanced2.style.display = 'block';
 283                  } else {
 284                      advanced1.style.display = 'none';
 285                      advanced2.style.display = 'none';
 286                  }
 287              }
 288          </script>
 289      <?php foreach ( $user_db_options as $option => $args ) bb_option_form_element( $option, $args ); ?>
 290      </fieldset>
 291      <fieldset id="advanced1" style="display:<?php echo $advanced_display; ?>">
 292          <legend><?php _e('Separate user database settings'); ?></legend>
 293          <p><?php _e('Most of the time these settings are <em>not</em> required. Look before you leap!'); ?></p>
 294          <p><?php _e('All settings except for the character set must be specified.'); ?></p>
 295      <?php foreach ( $advanced_user_db_options as $option => $args ) bb_option_form_element( $option, $args ); ?>
 296      </fieldset>
 297      <fieldset id="advanced2" style="display:<?php echo $advanced_display; ?>">
 298          <legend><?php _e('Custom user tables'); ?></legend>
 299          <p><?php _e('Only set these values if your user tables differ from the default WordPress naming convention.'); ?></p>
 300      <?php foreach ( $custom_table_options as $option => $args ) bb_option_form_element( $option, $args ); ?>
 301      </fieldset>
 302      <fieldset class="submit">
 303          <?php bb_nonce_field( 'options-wordpress-update-options' ); ?>
 304          <input type="hidden" name="action" value="update-options" />
 305          <input class="submit" type="submit" name="submit" value="<?php _e('Save Changes') ?>" />
 306      </fieldset>
 307  </form>
 308  
 309  </div>
 310  
 311  <?php
 312  bb_get_admin_footer();
 313  ?>


Generated: Thu Dec 7 01:01:35 2017 Cross-referenced by PHPXref 0.7.1