Answers.Body: <p>The solution was to make sure the Civi scripts loaded on the page. <a href="https://civicrm.stackexchange.com/questions/16718/enable-use-of-do-shortcode-when-using-civicrm-and-wordpress-templates">This answer provides guidance</a> on how to do that.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-01T17:22:50.420Z
Answers.LastActivityDate: 2021-02-01T17:22:50.420Z
Answers.UserDisplayName: Sara Clark
Answers.Body: <p>Did you find a solution? This is still happening with:
  Wordpress version: 5.6
  CiviCRM version: 5.32.2</p>
  <p>I'm having a consulting team investigate, I'll report back if they find a solution.</p>
  <p>UPDATE:
  I found a VERY hacky workaround. I added this block to civicrm.shortcodes.php inside &quot;prerender&quot; function:</p>
  <pre><code>          // default regex FAILED. Support nested shortcodes with custom regex.
        if (empty($shortcodes_array)) {
          preg_match_all('/\[civicrm component=&quot;(contribution|event|profile|user-dashboard|petition)&quot;( action=&quot;[a-z]+&quot;| mode=&quot;[a-z]+&quot;)?( id=&quot;[0-9]&quot;)?( gid=&quot;[0-9]&quot;)?\]/', $post-&gt;post_content, $located);
          if (!empty($located) &amp;&amp; !empty($located[0])) {
            $shortcodes_array = $located[0];
          }
        }
  </code></pre>
  <p>Here is the entire function with my custom block included:</p>
  <pre><code>  public function prerender( $wp ) {
  
  /*
   * At this point, all conditional tags are available
   * @see http://codex.wordpress.org/Conditional_Tags
   */
  
  // Bail if this is a 404
  if ( is_404() ) return;
  
  // A counter's useful
  $shortcodes_present = 0;
  
  /*
   * Let's loop through the results
   * This also has the effect of bypassing the logic in
   * https://github.com/civicrm/civicrm-wordpress/pull/36
   */
  if ( have_posts() ) {
    while ( have_posts() ) : the_post();
  
      global $post;
  
      // Check for existence of shortcode in content
      if ( has_shortcode( $post-&gt;post_content, 'civicrm' ) ) {
  
        // Get CiviCRM shortcodes in this post
        $shortcodes_array = $this-&gt;get_for_post( $post-&gt;post_content );
  
        // default regex FAILED. Support nested shortcodes with custom regex.
        if (empty($shortcodes_array)) {
          preg_match_all('/\[civicrm component=&quot;(contribution|event|profile|user-dashboard|petition)&quot;( action=&quot;[a-z]+&quot;| mode=&quot;[a-z]+&quot;)?( id=&quot;[0-9]&quot;)?( gid=&quot;[0-9]&quot;)?\]/', $post-&gt;post_content, $located);
          if (!empty($located) &amp;&amp; !empty($located[0])) {
            $shortcodes_array = $located[0];
          }
        }
  
        // Sanity check
        if ( !empty( $shortcodes_array ) ) {
  
          // Add it to our property
          $this-&gt;shortcodes[$post-&gt;ID] = $shortcodes_array;
  
          // Bump shortcode counter
          $shortcodes_present += count( $this-&gt;shortcodes[$post-&gt;ID] );
  
        }
  
      }
  
    endwhile;
  }
  
  // Reset loop
  rewind_posts();
  
  // Did we get any?
  if ( $shortcodes_present ) {
  
    // We need CiviCRM initialised prior to parsing shortcodes
    if (!$this-&gt;civi-&gt;initialize()) {
      return;
    }
  
    // How should we handle multiple shortcodes?
    if ( $shortcodes_present &gt; 1 ) {
  
      // Add CSS resources for front end
      add_action( 'wp_enqueue_scripts', array( $this-&gt;civi, 'front_end_css_load' ), 100 );
  
      // Let's add dummy markup
      foreach( $this-&gt;shortcodes AS $post_id =&gt; $shortcode_array ) {
  
        // Set flag if there are multple shortcodes in this post
        $multiple = ( count( $shortcode_array ) &gt; 1 ) ? 1 : 0;
  
        foreach( $shortcode_array AS $shortcode ) {
  
          // Mimic invoke in multiple shortcode context
          $this-&gt;shortcode_markup[$post_id][] = $this-&gt;render_multiple( $post_id, $shortcode, $multiple );
  
        }
  
      }
  
    } else {
  
      // Add core resources for front end
      add_action( 'wp', array( $this-&gt;civi, 'front_end_page_load' ), 100 );
  
      /*
       * Since we have only one shortcode, run the_loop again
       * the DB query has already been done, so this has no significant impact
       */
      if ( have_posts() ) {
        while ( have_posts() ) : the_post();
  
          global $post;
  
          // Is this the post?
          if ( ! array_key_exists( $post-&gt;ID, $this-&gt;shortcodes ) ) {
            continue;
          }
  
          // The shortcode must be the first item in the shortcodes array
          $shortcode = $this-&gt;shortcodes[$post-&gt;ID][0];
  
          // Check to see if a shortcode component has been repeated?
          $atts = $this-&gt;get_atts( $shortcode );
  
          // Test for hijacking
          if ( isset( $atts['hijack'] ) AND $atts['hijack'] == '1' ) {
            add_filter( 'civicrm_context', array( $this, 'get_context' ) );
          }
  
          // Store corresponding markup
          $this-&gt;shortcode_markup[$post-&gt;ID][] = do_shortcode( $shortcode );
  
          // Test for hijacking
          if ( isset( $atts['hijack'] ) AND $atts['hijack'] == '1' ) {
  
            // Ditch the filter
            remove_filter( 'civicrm_context', array( $this, 'get_context' ) );
  
            // Set title
            global $civicrm_wp_title;
            $post-&gt;post_title = $civicrm_wp_title;
  
            // Override page title
            add_filter( 'single_post_title', array( $this-&gt;civi, 'single_page_title' ), 50, 2 );
  
            // Overwrite content
            add_filter( 'the_content', array( $this, 'get_content' ) );
  
          }
  
        endwhile;
      }
  
      // Reset loop
      rewind_posts();
  
    }
  
  }
  
  // Flag that we have parsed shortcodes
  $this-&gt;shortcodes_parsed = TRUE;
  
  /**
   * Broadcast that shortcodes have been parsed.
   *
   * @since 4.6
   */
  do_action( 'civicrm_shortcodes_parsed' );
  </code></pre>
  <p>}</p>
  <p>Please reply if there's a better way to do this!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-29T15:27:23.460Z
Answers.LastActivityDate: 2021-02-01T18:15:23.830Z
Answers.LastEditDate: 2021-02-01T18:15:23.830Z
Answers.UserDisplayName: dsmith63
Body: <p>I'm using CiviCRM 4.7.31 on WordPress with the Members plugin. I created a new profile, then embedded that form in edit mode within a WordPress page:</p>
  
  <pre><code>[civicrm component="profile" gid="35" mode="edit" hijack="0"]
  </code></pre>
  
  <p>As expected, the WordPress page generates an error if a user is not logged in: </p>
  
  <blockquote>
    <p>"No user/contact ID was specified, so the Profile cannot be used in
    edit mode."</p>
  </blockquote>
  
  <p>This error persists even when I set the page's Content Permissions to limit access to users in selected roles.</p>
  
  <p>The error disappears when I wrap the civicrm shortcode within the members_logged_in shortcode:</p>
  
  <pre><code>[members_logged_in]
  [civicrm component="profile" gid="35" mode="edit" hijack="0"]
  [/members_logged_in]
  </code></pre>
  
  <p>But then the profile form loses its formatting; it seems like some Javascript/CSS is not loaded on the page when the shortcode is nested.</p>
  
  <p>Is there a way to make this work correctly? Do I need to switch to Caldera Forms with the Caldera Forms CiviCRM plugin?</p>
  
  <p>Thanks for your help.</p>
  
Tags: <wordpress><profile>
Title: Request login on edit mode profile form
ThreadText: # Request login on edit mode profile form
  
  (Asked by: username_0 on 2018-12-27)
  
  I'm using CiviCRM 4.7.31 on WordPress with the Members plugin. I created a new profile, then embedded that form in edit mode within a WordPress page:
  [civicrm component="profile" gid="35" mode="edit" hijack="0"]
  
  As expected, the WordPress page generates an error if a user is not logged in: 
  
  "No user/contact ID was specified, so the Profile cannot be used in
    edit mode."
  
  This error persists even when I set the page's Content Permissions to limit access to users in selected roles.
  The error disappears when I wrap the civicrm shortcode within the members_logged_in shortcode:
  [members_logged_in]
  [civicrm component="profile" gid="35" mode="edit" hijack="0"]
  [/members_logged_in]
  
  But then the profile form loses its formatting; it seems like some Javascript/CSS is not loaded on the page when the shortcode is nested.
  Is there a way to make this work correctly? Do I need to switch to Caldera Forms with the Caldera Forms CiviCRM plugin?
  Thanks for your help.
  
  **Tags:** wordpress, profile
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2021-02-01. Score: 2
  
  The solution was to make sure the Civi scripts loaded on the page. [This answer provides guidance](https://civicrm.stackexchange.com/questions/16718/enable-use-of-do-shortcode-when-using-civicrm-and-wordpress-templates) on how to do that.
  
  
  ---
  
  ### Answer by username_1 on 2021-01-29. Score: 0
  
  Did you find a solution? This is still happening with:
  Wordpress version: 5.6
  CiviCRM version: 5.32.2
  I'm having a consulting team investigate, I'll report back if they find a solution.
  UPDATE:
  I found a VERY hacky workaround. I added this block to civicrm.shortcodes.php inside "prerender" function:
            // default regex FAILED. Support nested shortcodes with custom regex.
        if (empty($shortcodes_array)) {
          preg_match_all('/\[civicrm component="(contribution|event|profile|user-dashboard|petition)"( action="[a-z]+"| mode="[a-z]+")?( id="[0-9]")?( gid="[0-9]")?\]/', $post->post_content, $located);
          if (!empty($located) && !empty($located[0])) {
            $shortcodes_array = $located[0];
          }
        }
  
  Here is the entire function with my custom block included:
    public function prerender( $wp ) {
  
  /*
   * At this point, all conditional tags are available
   * @see http://codex.wordpress.org/Conditional_Tags
   */
  
  // Bail if this is a 404
  if ( is_404() ) return;
  
  // A counter's useful
  $shortcodes_present = 0;
  
  /*
   * Let's loop through the results
   * This also has the effect of bypassing the logic in
   * https://github.com/civicrm/civicrm-wordpress/pull/36
   */
  if ( have_posts() ) {
    while ( have_posts() ) : the_post();
  
      global $post;
  
      // Check for existence of shortcode in content
      if ( has_shortcode( $post->post_content, 'civicrm' ) ) {
  
        // Get CiviCRM shortcodes in this post
        $shortcodes_array = $this->get_for_post( $post->post_content );
  
        // default regex FAILED. Support nested shortcodes with custom regex.
        if (empty($shortcodes_array)) {
          preg_match_all('/\[civicrm component="(contribution|event|profile|user-dashboard|petition)"( action="[a-z]+"| mode="[a-z]+")?( id="[0-9]")?( gid="[0-9]")?\]/', $post->post_content, $located);
          if (!empty($located) && !empty($located[0])) {
            $shortcodes_array = $located[0];
          }
        }
  
        // Sanity check
        if ( !empty( $shortcodes_array ) ) {
  
          // Add it to our property
          $this->shortcodes[$post->ID] = $shortcodes_array;
  
          // Bump shortcode counter
          $shortcodes_present += count( $this->shortcodes[$post->ID] );
  
        }
  
      }
  
    endwhile;
  }
  
  // Reset loop
  rewind_posts();
  
  // Did we get any?
  if ( $shortcodes_present ) {
  
    // We need CiviCRM initialised prior to parsing shortcodes
    if (!$this->civi->initialize()) {
      return;
    }
  
    // How should we handle multiple shortcodes?
    if ( $shortcodes_present > 1 ) {
  
      // Add CSS resources for front end
      add_action( 'wp_enqueue_scripts', array( $this->civi, 'front_end_css_load' ), 100 );
  
      // Let's add dummy markup
      foreach( $this->shortcodes AS $post_id => $shortcode_array ) {
  
        // Set flag if there are multple shortcodes in this post
        $multiple = ( count( $shortcode_array ) > 1 ) ? 1 : 0;
  
        foreach( $shortcode_array AS $shortcode ) {
  
          // Mimic invoke in multiple shortcode context
          $this->shortcode_markup[$post_id][] = $this->render_multiple( $post_id, $shortcode, $multiple );
  
        }
  
      }
  
    } else {
  
      // Add core resources for front end
      add_action( 'wp', array( $this->civi, 'front_end_page_load' ), 100 );
  
      /*
       * Since we have only one shortcode, run the_loop again
       * the DB query has already been done, so this has no significant impact
       */
      if ( have_posts() ) {
        while ( have_posts() ) : the_post();
  
          global $post;
  
          // Is this the post?
          if ( ! array_key_exists( $post->ID, $this->shortcodes ) ) {
            continue;
          }
  
          // The shortcode must be the first item in the shortcodes array
          $shortcode = $this->shortcodes[$post->ID][0];
  
          // Check to see if a shortcode component has been repeated?
          $atts = $this->get_atts( $shortcode );
  
          // Test for hijacking
          if ( isset( $atts['hijack'] ) AND $atts['hijack'] == '1' ) {
            add_filter( 'civicrm_context', array( $this, 'get_context' ) );
          }
  
          // Store corresponding markup
          $this->shortcode_markup[$post->ID][] = do_shortcode( $shortcode );
  
          // Test for hijacking
          if ( isset( $atts['hijack'] ) AND $atts['hijack'] == '1' ) {
  
            // Ditch the filter
            remove_filter( 'civicrm_context', array( $this, 'get_context' ) );
  
            // Set title
            global $civicrm_wp_title;
            $post->post_title = $civicrm_wp_title;
  
            // Override page title
            add_filter( 'single_post_title', array( $this->civi, 'single_page_title' ), 50, 2 );
  
            // Overwrite content
            add_filter( 'the_content', array( $this, 'get_content' ) );
  
          }
  
        endwhile;
      }
  
      // Reset loop
      rewind_posts();
  
    }
  
  }
  
  // Flag that we have parsed shortcodes
  $this->shortcodes_parsed = TRUE;
  
  /**
   * Broadcast that shortcodes have been parsed.
   *
   * @since 4.6
   */
  do_action( 'civicrm_shortcodes_parsed' );
  
  }
  Please reply if there's a better way to do this!
  
  
  ---
  
  