Support » Plugin: Easy Digital Downloads » Removing functions from edd_logs_view_sales action hook

  • Resolved Ahaenor



    i’m having some troubles while removing edd_logs_view_sales() function from “edd_logs_view_sales” action hook.

    My goal is to use my own code there instead of edd_logs_view_sales(). But my custom function is adding normally, and original function isn’t removed.

    I’ve tried to
    remove_action('edd_logs_view_sales', 'edd_logs_view_sales')
    from init, admin_init or plugins_loaded hooks (with various priorities). But none of this locations don’t even see the function edd_logs_view_sales() – function_exists() returns false everywhere.

    In addition to that, i’m failed to find a do_action('edd_logs_view_sales')
    code in EDD.

    Any help would be appreciated.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Pippin Williamson


    Pippin's Plugins and Plugin Reviewer

    Can you show me the complete code you tried to use?

    Here it is:

    `function myplugin_logs_some_view() {

    $logs_table = new Myplugin_Some_Log_Table();
    remove_action(‘edd_logs_view_sales’, ‘edd_logs_view_sales’);
    add_action(‘edd_logs_view_sales’, ‘myplugin_logs_some_view’);`

    This code attempts to replace EDD_Sales_Log_Table class with my custom class. It must be used exactly in place of original class.

    I’ve done such class replacements already in EDD, and they all worked fine. But none of the classes from *_Log_Table group haven’t.

    Plugin Author Pippin Williamson


    Pippin's Plugins and Plugin Reviewer

    Try putting the remove_action('edd_logs_view_sales', 'edd_logs_view_sales'); line into another function tied to the admin_init hook.

    I’m curious to know why you’re replacing the log tables? Are you making them better? If so I’d love to know in what way 😀

    No, it’s not working too. I’ve tried to hook up to init, admin_init or plugins_loaded, each with priority 1, 10 or 100.

    Interesting thing is that

    has_action('edd_logs_view_sales', 'edd_logs_view_sales');

    returned false in each of this cases. As i’ve said earlier, seems like my plugin code don’t see

    add_action('edd_logs_view_sales', 'edd_logs_view_sales');

    for some reason.

    And all my custom callbacks tied to edd_logs_view_sales is adding and working all properly.

    We began to replace default classes (and many content displaying functions) due to the charity specifics of our project.

    Many times we’d needed to make simple terminological/conceptual changes like “downloads” -> “??”, “Sales” -> “??”, “Earnings” -> “??”, “Buyers” -> “??” etc.

    Sometimes it’s been easy since there is EDD filter hooks just for that purpose (like for “Downloads”), but in many cases we couldn’t do much else than to redefine a large parts of original EDD code with only a few such changes.

    And still, we can’t exclude that soon we’ll need to expand a functionality too, not just some terms, to fit the requests our users, so we’re planning to support this possibility 🙂

    Plugin Author Pippin Williamson


    Pippin's Plugins and Plugin Reviewer

    I’m guessing that your actions are loading too late. Have you tried wrapping them all inside of a function tied to “plugins_loaded”?

    Yes, it’s one of the approaches i’ve tried. My code is something like this:

    function my_callback(){
        // Common log views. This hook is working correctly.
        function my_log_views($views){
            // my code
            return $views;
        add_filter('edd_log_views', 'my_log_views');
        function my_logs_view_custom() {
            $logs_table = new My_Custom_Log_Table();
        // Removing action isn't working for some reason with any of Logs tables hooks:
        remove_action('edd_logs_view_sales', 'edd_logs_view_sales');
        // has_action() returns 0, as if there isn't such function tied to this hook yet
        has_action('edd_logs_view_sales', 'edd_logs_view_sales');
        // Adding action works properly:
        add_action('edd_logs_view_sales', 'my_logs_view_custom');
    add_action('plugins_loaded', 'my_callback');
    Plugin Author Pippin Williamson


    Pippin's Plugins and Plugin Reviewer

    Weird. Try “admin_init” instead of “plugins_loaded”.

    I’ve managed to found the issue.

    init, admin_init or plugins_loaded hooks won’t help, because do_action(‘edd_logs_view_{log type}’) is triggered earlier than them.

    So, to remove or replace any of log views functions, you need to do it right before this do_action(). It’s done in edd_reports_tab_logs() function, tied to a edd_reports_tab_logs hook. I’ve replaced this func, and that has do the trick:

    function my_custom_reports_tab_logs() {
    	require( EDD_PLUGIN_DIR . 'includes/admin/reporting/logs.php' );
    	$current_view = 'file_downloads';
    	$log_views    = edd_log_default_views();
    	if ( isset( $_GET[ 'view' ] ) && array_key_exists( $_GET[ 'view' ], $log_views ) )
    		$current_view = $_GET[ 'view' ];
            remove_action( 'edd_logs_view_' . $current_view );
    	do_action( 'edd_logs_view_' . $current_view );
    remove_action( 'edd_reports_tab_logs', 'edd_reports_tab_logs' );
    add_action( 'edd_reports_tab_logs', 'my_custom_reports_tab_logs' );
    Plugin Author Pippin Williamson


    Pippin's Plugins and Plugin Reviewer

    Aha! Excellent.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Removing functions from edd_logs_view_sales action hook’ is closed to new replies.