/**
  * Renders a Connections compatible form opening.
  *
  * @access public
  * @since  0.8
  * @static
  *
  * @global $wp_rewrite
  *
  * @uses   get_permalink()
  * @uses   is_front_page()
  * @uses   is_page()
  *
  * @param  array $atts
  *
  * @return string
  */
 public static function formOpen($atts = array())
 {
     /** @var WP_Rewrite $wp_rewrite */
     global $wp_rewrite;
     $defaults = array('return' => FALSE);
     /**
      * Filter the default attributes array.
      *
      * @since 8.5.14
      */
     $defaults = apply_filters('cn_form_open_default_atts', $defaults);
     $atts = wp_parse_args($atts, $defaults);
     /**
      * Filter the user supplied attributes.
      *
      * @since 8.5.14
      */
     $atts = apply_filters('cn_form_open_atts', $atts);
     $out = '';
     if (is_customize_preview()) {
         return self::echoOrReturn($atts['return'], $out);
     }
     // Get the directory home page ID.
     $homeID = $atts['force_home'] ? cnSettingsAPI::get('connections', 'home_page', 'page_id') : $atts['home_id'];
     // The base post permalink is required, do not filter the permalink thru cnSEO.
     cnSEO::doFilterPermalink(FALSE);
     if ($wp_rewrite->using_permalinks()) {
         //$addAction = $homeID != $atts['home_id'] ? TRUE : FALSE;
         $addAction = cnSettingsAPI::get('connections', 'home_page', 'page_id') != $atts['home_id'] ? TRUE : FALSE;
         $permalink = get_permalink($homeID);
         /**
          * Filter the form action attribute.
          *
          * @since 8.5.15
          */
         $permalink = apply_filters('cn_form_open_action', $permalink, $atts);
         $permalink = cnURL::makeRelative($permalink);
         //if ( is_customize_preview() ) {
         //
         //	$addAction = TRUE;
         //	$permalink = get_permalink( $homeID );
         //}
         // Changed `$addAction` to `TRUE` in for action attribute ternary so the search is always off the page root.
         // See this issue: http://connections-pro.com/support/topic/image-grid-category-dropdown/#post-395856
         // Doesn't seem to cause any issues, but I can not remember the purpose of defaulting to  the current page
         // for the form action when home_id always should default to the current page unless set otherwise.
         // @see https://connections-pro.com/support/topic/cross-referencing-search-terms/
         // @see http://connections-pro.com/support/topic/cross-referencing-using-different-fields/
         //
         // Reverted the above change due to
         // @see http://connections-pro.com/support/topic/image-grid-category-dropdown/#post-395816
         $out .= '<form class="cn-form" id="cn-cat-select"' . ($addAction || $atts['force_home'] ? ' action="' . $permalink . '"' : '') . ' method="get">';
         if (is_front_page()) {
             $out .= '<input type="hidden" name="page_id" value="' . $homeID . '">';
         }
     } else {
         $out .= '<form class="cn-form" id="cn-cat-select" method="get">';
         $out .= '<input type="hidden" name="' . (is_page() ? 'page_id' : 'p') . '" value="' . $homeID . '">';
     }
     //if ( is_customize_preview() ) {
     //
     //	$out .= '<input type="hidden" name="cn-customize-template" value="true">';
     //	$out .= '<input type="hidden" name="cn-template" value="cmap">';
     //}
     // Add the cnSEO permalink filter.
     cnSEO::doFilterPermalink();
     return self::echoOrReturn($atts['return'], $out);
 }
 /**
  * Renders a Connections compatible form opening.
  *
  * @access public
  * @since  0.8
  * @static
  *
  * @global $wp_rewrite
  *
  * @uses   get_permalink()
  * @uses   is_front_page()
  * @uses   is_page()
  *
  * @param  array $atts
  *
  * @return string
  */
 public static function formOpen($atts = array())
 {
     /** @var WP_Rewrite $wp_rewrite */
     global $wp_rewrite;
     $defaults = array('return' => FALSE);
     $atts = wp_parse_args($atts, $defaults);
     $out = '';
     if (is_customize_preview()) {
         return self::echoOrReturn($atts['return'], $out);
     }
     // Get the directory home page ID.
     $homeID = $atts['force_home'] ? cnSettingsAPI::get('connections', 'home_page', 'page_id') : $atts['home_id'];
     // The base post permalink is required, do not filter the permalink thru cnSEO.
     cnSEO::doFilterPermalink(FALSE);
     if ($wp_rewrite->using_permalinks()) {
         //$addAction = $homeID != $atts['home_id'] ? TRUE : FALSE;
         $addAction = cnSettingsAPI::get('connections', 'home_page', 'page_id') != $atts['home_id'] ? TRUE : FALSE;
         $permalink = get_permalink($homeID);
         //$permalink = apply_filters( 'cn_permalink', $permalink, $atts );
         $permalink = cnURL::makeRelative($permalink);
         //if ( is_customize_preview() ) {
         //
         //	$addAction = TRUE;
         //	$permalink = get_permalink( $homeID );
         //}
         $out .= '<form class="cn-form" id="cn-cat-select" action="' . ($addAction || $atts['force_home'] ? $permalink : '') . '" method="get">';
         if (is_front_page()) {
             $out .= '<input type="hidden" name="page_id" value="' . $homeID . '">';
         }
     } else {
         $out .= '<form class="cn-form" id="cn-cat-select" method="get">';
         $out .= '<input type="hidden" name="' . (is_page() ? 'page_id' : 'p') . '" value="' . $homeID . '">';
     }
     //if ( is_customize_preview() ) {
     //
     //	$out .= '<input type="hidden" name="cn-customize-template" value="true">';
     //	$out .= '<input type="hidden" name="cn-template" value="cmap">';
     //}
     // Add the cnSEO permalink filter.
     cnSEO::doFilterPermalink();
     return self::echoOrReturn($atts['return'], $out);
 }