Add adv support, fix member plans order

parent e0a7c43e
<?php
namespace wp_SexHackMe;
if(!class_exists('SexhackAdvert')) {
class sexhackadv_widget extends \WP_Widget {
function __construct()
{
parent::__construct(
// Base ID of your widget
'sexhackadv_widget',
// Widget name will appear in UI
__('SexHack ADV', 'sexhack_widget_domain'),
// Widget description
array( 'description' => __( 'Adverstising widget for SexHackMe', 'sexhack_widget_domain' ), )
);
}
public function widget( $args, $instance )
{
global $post;
echo $args['before_widget'];
$id=$instance['advid'];
if ( ! empty($id))
echo $args['before_advid'] . do_shortcode('[sexadv adv='.$id.']'). $args['after_advid'];
echo $args['after_widget'];
}
public function form( $instance )
{
if ( isset( $instance[ 'advid' ] ) )
{
$advid = $instance[ 'advid' ];
}
else {
$advid = __( 'ADVert ID', 'sexhack_widget_domain' );
}
// Widget admin form
?>
<p>
<label for="<?php echo $this->get_field_id( 'advid' ); ?>"><?php _e( 'ID Advert:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'advid' ); ?>" name="<?php echo $this->get_field_name( 'advid' ); ?>" type="text" value="<?php echo esc_attr( $advid ); ?>" />
</p>
<?php
}
// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance )
{
$instance = array();
$instance['advid'] = ( ! empty( $new_instance['advid'] ) ) ? strip_tags( $new_instance['advid'] ) : '';
return $instance;
}
}
// Register and load the widget
function adv_load_widget() {
register_widget( 'wp_SexHackMe\sexhackadv_widget' );
}
add_action( 'widgets_init', 'wp_SexHackMe\adv_load_widget' );
class SexhackAdvert
{
public function __construct()
{
add_shortcode("sexadv", array($this, "adv_shortcode"));
add_action('init', array($this, "register_sexhackadv_post_type"));
sexhack_log('SexhackAdvert() Instanced');
}
public function revealid_add_id_column($columns)
{
$columns['revealid_id'] = 'ID';
$columns['revealid_short'] = 'shortcode';
return $columns;
}
public function revealid_id_column_content( $column, $id ) {
if( 'revealid_id' == $column ) {
echo $id;
}
if( 'revealid_short' == $column ) {
echo "[sexadv adv=$id]";
}
}
public function register_sexhackadv_post_type()
{
register_post_type('sexhackadv', array(
'label' => 'Advertising','description' => '',
'public' => true,
'show_ui' => true,
'show_in_menu' => true, // Visibility in admin menu.
'menu_position' => 151,
'capability_type' => 'post',
'hierarchical' => false,
'publicly_queryable' => true,
'rewrite' => false,
'query_var' => true,
'has_archive' => true,
'supports' => array('title','editor','page-attributes', 'shortcode'),
'taxonomies' => array(),
// there are a lot more available arguments, but the above is plenty for now
));
add_filter( 'manage_sexhackadv_posts_columns', array($this, 'revealid_add_id_column'), 5 );
add_action( 'manage_sexhackadv_posts_custom_column', array($this, 'revealid_id_column_content'), 5, 2 );
}
public function adv_shortcode($attr, $cont)
{
global $post;
global $sexhack_pms;
extract( shortcode_atts(array(
"adv" => false,
), $attr));
if(isset($sexhack_pms) && !$sexhack_pms->is_premium())
{
if($attr['adv'])
{
$post = get_post(intval($attr['adv']));
if(($post) && ($post->post_type == 'sexhackadv'))
{
$html = $post->post_content;
wp_reset_postdata();
return $html;
}
}
wp_reset_postdata();
//return 'Error in retrieving sexhackadv post. Wrong ID?';
}
return;
}
}
}
$SEXHACK_SECTION = array(
'class' => 'SexhackAdvert',
'description' => 'Advertising support for SexHackMe',
'name' => 'sexhackme_advertising',
//'require-page' => 'sexhackadv'
'require-page' => array(array('post_type' => 'sexhackadv', 'title' => 'Top Banner Video Page', 'option' => 'sexadv_video_top'),
array('post_type' => 'sexhackadv', 'title' => 'Bottom Banner Video Page', 'option' => 'sexadv_video_bot')
)
);
?>
......@@ -40,7 +40,19 @@ if(!class_exists('PmsWoocommerceRegistrationIntegration')) {
// Sending email with link to set user password
add_action("pms_register_form_after_create_user", array($this, "send_register_email_reset_password") );
// Reorder membership subscription in registration page
//add_action( 'pre_get_posts', array($this, 'sexhack_reorder_membership'), 1 );
}
/*
public function sexhack_reorder_membership($query) {
if ( ! is_admin() && in_array ( $query->get('post_type'), array('pms-subscriptions') ) ) {
$query->set( 'order' , 'asc' );
$query->set( 'orderby', 'price');
}
}
*/
// Register new endpoint (URL) for My Account page
// Note: Re-save Permalinks or it will give 404 error
......
......@@ -156,15 +156,23 @@ if(!class_exists('SexHackMe')) {
register_setting('sexhackme-settings', $section['name']);
if(array_key_exists('require-page', $section) && ($section['require-page']))
{
if(is_array($section['require-page'])) {
foreach($section['require-page'] as $pagereq) {
if(array_key_exists('post_type', $pagereq)) {
if(array_key_exists('option', $pagereq)) register_setting('sexhackme-settings', $pagereq['option']);
}
}
} else {
register_setting('sexhackme-settings', $section['name']."-page");
}
}
}
}
public function admin_menu()
{
add_menu_page('SexHackMe Settings', 'SexHackMe', 'manage_options', 'sexhackme-settings',
array($this, 'admin_page'), plugin_dir_url(__FILE__) .'/img/admin_icon.png');
array($this, 'admin_page'), plugin_dir_url(__FILE__) .'/img/admin_icon.png', 150);
}
public function admin_page()
......@@ -185,19 +193,47 @@ if(!class_exists('SexHackMe')) {
<td>
<input type="checkbox" name="<?php echo $section['name'];?>" value="1" <?php echo $this->checkbox(get_option( $section['name'] )); ?>/>
<br>
<?php if(array_key_exists('require-page', $section) && ($section['require-page']))
{ ?>
<select id="<?php echo $section['name'];?>-page" name="<?php echo $section['name'];?>-page" class="widefat">
<?php
if(array_key_exists('require-page', $section) && ($section['require-page']))
{
$reqps = array();
if(is_string($section['require-page']))
{
$reqtitle="Select the base plugin module page";
$reqpages=get_posts(array('post_type' => $section['require-page'], 'parent' => 0));
$reqps[] = array('title' => $reqtitle, 'pages' => $reqpages, 'option' => $section['name']."-page");
} elseif(is_array($section['require-page'])) {
$i=0;
foreach($section['require-page'] as $rpage) {
if(array_key_exists('post_type', $rpage)) {
$reqpsa = array('title' => 'Select Page', 'option' => $section['name']."-page$i",
'pages' => get_posts(array('post_type' => $rpage['post_type'], 'parent' => 0)));
if(array_key_exists('option', $rpage)) $reqpsa['option'] = $rpage['option'];
if(array_key_exists('title', $rpage)) $reqpsa['title'] = $rpage['title'];
$reqps[] = $reqpsa;
}
$i++;
}
} else {
$reqtitle="Select the base plugin module page";
$reqpages=get_pages();
$reqps[] = array('title' => $reqtitle, 'pages' => $reqpages, 'option' => $section['name']."-page");
}
foreach($reqps as $reqarr) {
?>
<select id="<?php echo $reqarr['option'];?>" name="<?php echo $reqarr['option']; ?>" class="widefat">
<option value="-1"><?php esc_html_e( 'Choose...', 'paid-member-subscriptions' ) ?></option>
<?php
$opt=get_option( $section['name']."-page");
foreach( get_pages() as $page ) {
$opt=get_option($reqarr['option']);
foreach( $reqarr['pages'] as $page ) {
echo '<option value="' . esc_attr( $page->ID ) . '"';
if ($opt == $page->ID) { echo "selected";}
echo '>' . esc_html( $page->post_title ) . ' ( ID: ' . esc_attr( $page->ID ) . ')' . '</option>';
} ?>
</select>
<p class="description">Select the base plugin module page</p>
<p class="description"><?php echo $reqarr['title']; ?></p>
<?php } ?>
<?php } ?>
</td>
</tr>
......
......@@ -28,6 +28,8 @@ get_header(); ?>
while ( have_posts() ) :
the_post();
echo do_shortcode("[sexadv adv=".get_option('sexadv_video_top')."]");
$prod = wc_get_product(get_the_ID());
$hls = $prod->get_attribute("hls_public");
$hls_member = $prod->get_attribute("hls_members");
......@@ -115,8 +117,8 @@ get_header(); ?>
?>
<h3><a href="<?php echo get_the_permalink(); ?>">Download the full lenght hi-res version of this video</a><h3>
<br><hr>
<?php
<?php
echo do_shortcode("[sexadv adv=".get_option('sexadv_video_bot')."]");
endwhile;
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment