Comments (5)
'dlm_options_end' action is pretty straightforward - you just hook in and output your checkbox html. The post ID is passed to the action should you wish to get_post_meta
And for saving its just a case of something like:
add_action( 'dlm_save_meta_boxes', 'your_save_function', 1, 2 );
function your_save_function( $post_id, $post ) {
$checkbox = ( isset( $_POST['checkbox'] ) ) ? 'yes' : 'no';
update_post_meta( $post_id, 'checkbox', $checkbox);
}
from download-monitor.
Thanks for the help. I was able to get my additional postmeta added and saved via -
//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 );
Below is an example of code that I am running in order to get the new meta option I created to work with a user cap, allowing download. For some reason I can only get - Call to a member function is_act_sub() on a non-object in. I have tried using global $download; with no luck.
//new rules using the act_sub post meta check and the active_subscription user role.
function subscription_access( $download, $can_download) {
if ( $download->is_act_sub() && ! current_user_can('active_subscription') )
$can_download = true;
return $can_download;
}
add_filter( 'dlm_can_download', 'subscription_access', 10, 2 );
Any insight? Thank you in advanced.
from download-monitor.
is_act_sub() isn't a method of the download class. You need to use get_post_meta directly.
from download-monitor.
Thanks. I got it. I will post my code in a bit so others can use it.
from download-monitor.
Alright here is the code I used to do the following.
- Add additional meta boxes to download post screen
- Save post meta
- Get post meta value and then use it to rule if a user has permission to download based on custom user roles and capabilities.
Thanks for your help! I will post my code to my repository here Themazign Toolbox
<?php
/*
This file includes the download monitor customizations needed to add additional meta options, save meta options and new rules based on meta and user cap.
*/
//setup globals
global $post, $download;
// start add aditional post meta
//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 );
// end add aditional post meta
//new rules using the act_sub post meta check and the active_subscription user role.
function check_subscription( $can_download, $download ) {
$can_download = false;
if (current_user_can('active_subscriber_cap')){
$active_sub_status = get_post_meta( $download->post->ID , '_act_sub', true );
if ( $active_sub_status = 'yes' )
$can_download = true;
}
elseif (current_user_can('inactive_subscriber_cap')) {
if ( $download->is_members_only() && is_user_logged_in() )
$can_download = true;
}
elseif (current_user_can('free_cap')) {
if ( $download->is_members_only() && is_user_logged_in() )
$can_download = true;
}
return $can_download;
}
add_filter( 'dlm_can_download', 'check_subscription', 10, 2 );
?>
from download-monitor.
Related Issues (20)
- attach a user to the download monitor record
- No version template triggers error
- User reports not showing user name & role
- File Browser not working on installations that return '//' ( double slashed ) paths
- PHP warning on templates that do not use defined Download - page addon for example
- Products update problem
- downloads are not ordered correctly when there are Norwegian characters
- Create a global DLM settings page in multisite environments
- Bundle download HOT 1
- Performance optimizations
- Version links don't work on Versions list template
- have the ‘Members only’ checkbox automatically tick for any file that’s protected from the media library
- Performance issue with large postmeta tables
- Filename filetype problem
- Date Range goes over the Export button - bug on small display
- open_basedir problem when file is remote
- post_status= "publish" on download versions
- group the items by file type
- cannot activate license if the email contains '+' in it
- Shop cart empty
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from download-monitor.