php - Call to undefined method - Download Monitor

admin2025-06-05  1

I have been working on adding some customizations to Download Monitor

So far I have been able to add custom meta check boxes, and save them using the following code.

global $post, $download;

//add additional meta to download monitor post screen.
function add_custom_dm_options( $post ) {
        global $post, $thepostid;
        $thepostid = $post->ID;

        echo '<p class="form-field form-field-checkbox">
            <input type="checkbox" name="_act_sub" id="_act_sub" ' . checked( get_post_meta( $thepostid, '_act_sub', true ), 'yes', false ) . ' />
            <label for="_act_sub">' . __( 'Active Subscriber', 'download_monitor' ) . '</label>
            <span class="description">' . __( 'This download is only for users who belong to the Active Subscriber Role.', 'download_monitor' ) . '</span>
        </p>';

    }
add_action( 'dlm_options_end', 'add_custom_dm_options' );

//save additional meta on download monitor post.
function save_custom_dm_options( $post_id, $post ) {
  $_act_sub = ( isset( $_POST['_act_sub'] ) ) ? 'yes' : 'no';
  update_post_meta( $post_id, '_act_sub', $_act_sub );
}
add_action( 'dlm_save_meta_boxes', 'save_custom_dm_options', 1, 2 );

The next step is to determine if the user is logged in and that the post was saved with _act_sub.

Here is the code I am using:

//new rules using the act_sub post meta check and the active_subscription user role. 
function subscription_access( $post, $download ) {

        if ( $download->is_act_sub() && ! is_user_logged_in() )
            $can_download = true;

        return $can_download;
    }
add_filter( 'dlm_can_download', 'subscription_access', 1, 2 );

This code is all on the same function file so it also uses the globals previously stated.

When I dump the $download variable I get: pastebin

I can use the built in meta key of _members_only just fine but I have not been able to use my custom meta key. I checked the database ad everything is saving properly.

Can anyone help me determine if there is some syntax issues?

Plugin - Download Monitor Custom Plugin - The code above

I have been working on adding some customizations to Download Monitor

So far I have been able to add custom meta check boxes, and save them using the following code.

global $post, $download;

//add additional meta to download monitor post screen.
function add_custom_dm_options( $post ) {
        global $post, $thepostid;
        $thepostid = $post->ID;

        echo '<p class="form-field form-field-checkbox">
            <input type="checkbox" name="_act_sub" id="_act_sub" ' . checked( get_post_meta( $thepostid, '_act_sub', true ), 'yes', false ) . ' />
            <label for="_act_sub">' . __( 'Active Subscriber', 'download_monitor' ) . '</label>
            <span class="description">' . __( 'This download is only for users who belong to the Active Subscriber Role.', 'download_monitor' ) . '</span>
        </p>';

    }
add_action( 'dlm_options_end', 'add_custom_dm_options' );

//save additional meta on download monitor post.
function save_custom_dm_options( $post_id, $post ) {
  $_act_sub = ( isset( $_POST['_act_sub'] ) ) ? 'yes' : 'no';
  update_post_meta( $post_id, '_act_sub', $_act_sub );
}
add_action( 'dlm_save_meta_boxes', 'save_custom_dm_options', 1, 2 );

The next step is to determine if the user is logged in and that the post was saved with _act_sub.

Here is the code I am using:

//new rules using the act_sub post meta check and the active_subscription user role. 
function subscription_access( $post, $download ) {

        if ( $download->is_act_sub() && ! is_user_logged_in() )
            $can_download = true;

        return $can_download;
    }
add_filter( 'dlm_can_download', 'subscription_access', 1, 2 );

This code is all on the same function file so it also uses the globals previously stated.

When I dump the $download variable I get: pastebin

I can use the built in meta key of _members_only just fine but I have not been able to use my custom meta key. I checked the database ad everything is saving properly.

Can anyone help me determine if there is some syntax issues?

Plugin - Download Monitor Custom Plugin - The code above

Share Improve this question asked Aug 12, 2013 at 6:58 SmashBrandoSmashBrando 113 bronze badges 3
  • On a side note, if I run: $metakey = get_post_meta( $post->ID, '_members_only', true ); var_dump($metakey); I get boolean null. But if I substitute it with the post ID I get yes(which is what the value is). It seems I am having trouble getting the post ID properly. – SmashBrando Commented Aug 12, 2013 at 7:29
  • 1 Have you tried asking the support forum? The author might help you himself. – RRikesh Commented Aug 12, 2013 at 8:15
  • Yes but the author doesn't give support in most cases. Generally just fixes bugs. I am awaiting a response but until then, here I am. – SmashBrando Commented Aug 12, 2013 at 15:45
Add a comment  | 

3 Answers 3

Reset to default 0

It appears the issue was mostly with scope. In this case the following was needed to get the post ID:

php $download->post->ID

I then was able to get my meta value by using the following:

php $active_sub_status = get_post_meta( $download->post->ID , '_act_sub', true );

I have asked the author for how I set DM to be accessible by members only, by default. He told me to use apply_filters( 'dlm_can_download', true, $download, $version )

I do not know how to apply this as I am not much of a coder

The way I could get the correct post/download id was with $download->id.

    function check_download_permissions($can_download,$download) {
        $target_post = $download->id; // This is how to get the post id
        if(get_post_meta($target_post, '_act_sub', true) && ! is_user_logged_in()){
            $can_download = true;
        }
        return $can_download;
    }  

    add_filter( 'dlm_can_download', 'check_download_permissions', 10, 2);
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749133754a316647.html

最新回复(0)