• Resolved jaywok

    (@jaywok)


    Hello. I’m putting together a lightweight analytics plugin and hope to integrate with domain mapping.

    Overall, my goal is to update the analytics platform with the new url automatically when a new primary is set it domain mapping.

    I’m trying to use the ‘dm_handle_action_primary’ hook, but it doesn’t seem to be firing at all, even when adding a new primary domain. As a work around, I’ve tried ‘dm_handle_action_add’. That’s firing correctly, however my attempt to retrieve the primary domain from the database at that time is retrieving the domain which is being replaced as the primary, so it seems to be firing before that gets written to the database.

    Here’s the relevant code:

    function piwik_inline_update_blog($domain)
    {
      //get the primary domain
      global $wpdb;
      $domain = $wpdb-> get_results( "SELECT * FROM {$wpdb->base_prefix}domain_mapping WHERE blog_id = '".get_current_blog_id()."' and active=1");
    
       echo $domain; // outputs the domain being replaced; new is not yet saved to database.
    }
    add_action('dm_handle_actions_primary', 'piwik_inline_update_blog'); // function is never called through this hook
    
    add_action('dm_handle_actions_add', 'piwik_inline_update_blog');

    Do you have any advice on how to better approach this? Any help or advice at all would be greatly appreciated!

    https://ww.wp.xz.cn/plugins/wordpress-mu-domain-mapping/

Viewing 1 replies (of 1 total)
  • Thread Starter jaywok

    (@jaywok)

    Hello. I established that the problem only exists when it is a new domain alias being added with the ‘primary’ checkbox selected.

    I tried submitting a patch but don’t seem to know what I am doing. Let me know how best to relay this information.

    adding a call to do_action on line 356 of domain_mapping.php fixes this.

    case "add":
            		        do_action('dm_handle_actions_add', $domain);
    				if( null == $wpdb->get_row( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain = '$domain'" ) && null == $wpdb->get_row( "SELECT blog_id FROM {$wpdb->dmtable} WHERE domain = '$domain'" ) ) {
                                            if ( $_POST[ 'primary' ] ) {
                                              $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->dmtable} SET active = 0 WHERE blog_id = %d", $wpdb->blogid ) );
                                              do_action('dm_handle_actions_primary', $domain);
                                            }
                                            $wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->dmtable} ( <code>id</code> , <code>blog_id</code> , <code>domain</code> , <code>active</code> ) VALUES ( NULL, %d, %s, %d )", $wpdb->blogid, $domain, $_POST[ 'primary' ] ) );

Viewing 1 replies (of 1 total)

The topic ‘dm_handle_action_primary’ is closed to new replies.