title: Modify Existing Class Method / Function in a WordPress plugin
body: <p>Want to change a simple string in a function within a class. More specifically, I just want to change the "%s" in the last function to a hard-coded URL like "<a href="https://whatever.com" rel="nofollow">https://whatever.com</a>".</p>
  
  <hr>
  
  
  
  <pre><code>class WPJMCL_Claim_Free {
  
      public function __construct() {
          add_action( 'template_redirect', array( $this, 'create_claim' ) );
          add_action( 'template_redirect', array( $this, 'display_guest_notice' ) ); // I WANT TO CHANGE THIS ONE
      }
  
      public function create_claim() {
          // CODE I DON'T CARE ABOUT
      }
  
  
      public function display_guest_notice() {
          if ( ! isset( $_GET[ 'action' ] ) || 'claim_as_guest' != $_GET[ 'action' ] ) {
              return;
          }
  
          if ( ! isset( $_GET[ 'listing_id' ] ) ) {
              return;
          }
  
          $listing_id = absint( $_GET[ 'listing_id' ] );
  
          // Add a notice if the theme is using WC
          if ( defined( 'WC_VERSION' ) ) {
              wc_add_notice( sprintf( __( 'Please &lt;a href="%s"&gt;log in&lt;/a&gt; to claim this listing.', 'wp-job-manager-claim-listing' ), wp_login_url( get_permalink( $listing_id ) ) ) );
          }
  
          do_action( 'wpjmcl_guest_claim_redirect', $listing_id );
      }
  
  }
  </code></pre>
  
  
  
  <hr>
  
  <p>I've tried extending the class as a separate plugin.php file, but the output I want happens twice, once as the original class output and another with mine.</p>
  
  <p>My extension:</p>
  
  
  
  <pre><code>add_action('init', 'claim_redirect_mods_loader', 0);
  
  function claim_redirect_mods_loader() {
  
  if( class_exists( 'WPJMCL_Claim_Free' )){
  
      class my_WPJMCL_Claim_Free extends WPJMCL_Claim_Free {
  
          public function __construct() {
              add_action( 'template_redirect', array( $this, 'display_guest_notice' ) );
          }
  
          public function display_guest_notice() {
              if ( ! isset( $_GET[ 'action' ] ) || 'claim_as_guest' != $_GET[ 'action' ] ) {
                  return;
              }
  
              if ( ! isset( $_GET[ 'listing_id' ] ) ) {
                  return;
              }
  
              $listing_id = absint( $_GET[ 'listing_id' ] );
  
              // Add a notice if the theme is using WC
              if ( defined( 'WC_VERSION' ) ) {
                  wc_add_notice( sprintf( __( 'Please &lt;a href="https://directory.supportpay.com/my-account/"&gt;log in or register&lt;/a&gt; to claim this listing.', 'wp-job-manager-claim-listing' ), wp_login_url( get_permalink( $listing_id ) ) ) );
              }
              do_action( 'wpjmcl_guest_claim_redirect', $listing_id );
          }
  
      } // End Class
  
      new my_WPJMCL_Claim_Free();
  
  } // End if
  
  }
  </code></pre>
  
  
  
  <hr>
  
  <p>Instead of extending the class, figured I'd just modify the original function within the original class but not sure if my filter is syntactically correct (in my functions.php file):</p>
  
  
  
  <pre><code>global $WPJMCL_Claim_Free;
  
  function my_display_guest_notice(){
  
    if ( ! isset( $_GET[ 'action' ] ) || 'claim_as_guest' != $_GET[ 'action' ] ) {
              return;
    }
  
    if ( ! isset( $_GET[ 'listing_id' ] ) ) {
        return;
    }
  
    $listing_id = absint( $_GET[ 'listing_id' ] );
  
    // Add a notice if the theme is using WC
    if ( defined( 'WC_VERSION' ) ) {
        wc_add_notice( sprintf( __( 'Please &lt;a href="https://directory.supportpay.com/my-account/"&gt;log in or register&lt;/a&gt; to claim this listing.', 'wp-job-manager-claim-listing' ), wp_login_url( get_permalink( $listing_id ) ) ) );
    }
  
    do_action( 'wpjmcl_guest_claim_redirect', $listing_id );  
  }
  
  add_filter('display_guest_notice', array( $WPJMCL_Claim_Free, 'my_display_guest_notice'), 999 );
  </code></pre>
  
  
  
  <hr>
  
  <p>Should I be overwriting the original function and/or is my approach correct?</p>