Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom BP Component is inactive


  • salvatore77
    Participant

    @salvatore77

    I have created my custom component for custom notifications, but id doesn’t work. This is the code:

    <?php
    /**
     * Class to serve notification Calls.
     *
    
     */
    
    	class MyPlugin___Notifications extends BP_Component {
    
    	    protected $component_name = 'MyPlugin__';
    
    		/**
    		 * Constructor.
    		 *
    		 * @since    1.0.0
    		 * @access   public
    		 * @author   Wbcom Designs
    		 */
    		public function __construct() {
    			$this->slug = $this->component_name;
    
    			parent::start(
    			    $this->component_name, esc_html__( 'Custom', 'bp-MyPlugin-Custom' ), dirname( __FILE__ )
    			);
    
    			buddypress()->active_components[ $this->component_name ] = '1';
    			
    		}
    		
    
    		public function setup_globals( $args = array() ) {
    			parent::setup_globals(
    				array(
    					'slug'                  => $this->component_name,
    					'has_directory'         => false,
    					'notification_callback' => 'MyPlugin_custom_format_buddypress_notifications',
    				)
    			);
    		}
    
    		public function setup_actions() {
    			parent::setup_actions();
    		}
    		
    		public function add_MyPlugin_notification_format($action, $item_id, $secondary_item_id, 
    		                                                      $user_id, $format = 'string' ){
    		    global $wpdb;
    		    if ( bp_is_active( 'notifications' ) ) {
    		        if ( 'custom_action' === $action ) {
    		           //there is a php code
    		            return $return;
    		        }
    		    }
    		}
    
    		public function component_name() {
    			return $this->component_name;
    		}
    	}
    
    function init_MyPlugin___notifications_component(){
        buddypress()->MyPlugin___notifications =  new MyPlugin___Notifications();
        buddypress()->MyPlugin___notifications->notification_callback = 'MyPlugin_custom_format_buddypress_notifications';
       
    }
    add_action( 'bp_init', 'init_MyPlugin___notifications_component', 40 );
    
    add_filter( 'bp_notifications_get_notifications_for_user', 'MyPlugin_custom_format_buddypress_notifications', 10, 5 );
    
    function MyPlugin_custom_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
        $return = buddypress()->MyPlugin___notifications->add_MyPlugin_notification_format( $action, $item_id, 
            $secondary_item_id, $total_items, $format);
    }
    
    
  • You must be logged in to reply to this topic.
Skip to toolbar