We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Removing a custom profile field when a weblog entry is deleted

Development and Programming

Manoj Thomas's avatar
Manoj Thomas
185 posts
16 years ago
Manoj Thomas's avatar Manoj Thomas

Hi everyone, I’m writing an extension that creates a custom profile field when a weblog entry is created. I’m able to get this part working, but I also need to have the extension delete the profile field if the entry is deleted - this is the part I’m having trouble with. Can anybody shed some light? I’m trying to use the delete_entries_end hook.

<?php
class Add_community
{
    var $settings        = array();
    var $name            = 'Add_community';
    var $version         = '1.0.0';
    var $description     = 'Adds two new member profile fields for each Community weblog entry';
    var $settings_exist  = 'n';
    var $docs_url        = 'http://www.trademarkmedia.com';
    
    // -------------------------------
    //   Constructor - Extensions use this for settings
    // -------------------------------
    function Add_community($settings='')
    {
        $this->settings = $settings;
    }
    // END
    
    // --------------------------------
    //  Activate Extension
    // --------------------------------
    function activate_extension() {
        global $DB;
    
        $hooks[] = array(
            'extension_id' => '',
            'class'        => "Add_community",
            'method'       => "delete_member_field",
            'hook'         => "delete_entries_end",
            'settings'     => "",
            'priority'     => 10,
            'version'      => $this->version,
            'enabled'      => "y"
        );
        $hooks[] = array(
            'extension_id' => '',
            'class'        => "Add_community",
            'method'       => "add_member_field",
            'hook'         => "submit_new_entry_end",
            'settings'     => "",
            'priority'     => 10,
            'version'      => $this->version,
            'enabled'      => "y"
        );
    
        foreach ($hooks as $hook) {
            $DB->query($DB->insert_string('exp_extensions',    $hook));
        }
    }
    // END
        
    // --------------------------------
    //  Update Extension
    // --------------------------------  
    function update_extension($current='')
    {
        global $DB;
        if ($current == '' OR $current == $this->version)
        {
            return FALSE;
        }
        if ($current < '1.0.1')
        {
            // Update to next version 1.0.1
        }
        if ($current < '1.0.2')
        {
            // Update to next version 1.0.2
        }
        $DB->query("UPDATE exp_extensions 
                SET version = '".$DB->escape_str($this->version)."' 
                        WHERE class = 'Example_extension'");
        }
    // END
    
    // --------------------------------
    //  Disable Extension
    // --------------------------------
    function disable_extension()
    {
        global $DB;
        $DB->query("DELETE FROM exp_extensions WHERE class = 'Example_extension'");
    }
    // END
    
    // --------------------------------
    //  Insert up to two Profile Fields
    // --------------------------------        
    function add_member_field($entry_id, $data, $ping_message)
    {
        global $DSP, $DB, $IN, $EXT;
        if ($data['weblog_id'] == '5') {
            $m_field_name = "community_" . $data['url_title'];
            $m_field_label = "Community: " .$data['title'];                    
            $DB->query("INSERT INTO exp_member_fields (m_field_id, m_field_name, m_field_label, m_field_type, m_field_list_items, m_field_ta_rows, m_field_maxl, m_field_width, m_field_search, m_field_required, m_field_public, m_field_reg, m_field_fmt) VALUES (NULL, '$m_field_name', '$m_field_label', 'text', 'No', '10', '100', '100%', 'y', 'n', 'y', 'n', 'none')");
            $DB->query("ALTER table exp_member_data add column m_field_id_{$DB->insert_id} text NOT NULL");                
        }
    }
    // END
        
    // --------------------------------
    //  Delete Profile Fields
    // --------------------------------        
    function delete_member_field()
    {

    }
    // END        
    }
// END CLASS
?>

Thanks, Manoj

       
wecreateyou's avatar
wecreateyou
86 posts
15 years ago
wecreateyou's avatar wecreateyou

Did you get that figured out? If so can you share the results, I’d like to play around with it.

Thanks

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.