creating admin structure, classes for widgets, post types and more

parent cc2f9052
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
*
* This file is part of SexHackMe Wordpress Plugin.
*
* SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* SexHackMe Wordpress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
namespace wp_SexHackMe;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
function advert_adminpage()
{
sh_get_template('admin/advert.php');
}
function settings_advert_section()
{
echo "<h2>SexHackMe Advertising Settings</h2>";
}
?>
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
*
* This file is part of SexHackMe Wordpress Plugin.
*
* SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* SexHackMe Wordpress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
namespace wp_SexHackMe;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
function sexhackme_settings_section() {
echo "<h3></h3>";
}
?>
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
*
* This file is part of SexHackMe Wordpress Plugin.
*
* SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* SexHackMe Wordpress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
namespace wp_SexHackMe;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
function wcpms_adminpage()
{
sh_get_template('admin/wcpms.php');
}
function settings_wcpms_section()
{
echo "<h2>SexHackMe PMS - WooCommerce integration Settings</h2>";
}
function settings_wcpms_section_email()
{
echo "<h2>WooCommerce Checkout Email endpoint</h2>";
}
?>
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
*
* This file is part of SexHackMe Wordpress Plugin.
*
* SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* SexHackMe Wordpress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
namespace wp_SexHackMe;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if(!class_exists('SH_Admin')) {
class SH_Admin
{
public static function init()
{
add_settings_section('sexhackme-settings', ' ', 'wp_SexHackMe\sexhackme_settings_section', 'sexhackme-settings');
// Add WC-PMS_Integration settings
if( file_exists(SH_PLUGIN_DIR_PATH . 'includes/admin/functions-wcpms.php') )
{
include_once SH_PLUGIN_DIR_PATH . 'includes/admin/functions-wcpms.php';
$plans = sh_get_subscription_plans();
add_settings_section('sexhackme-wcpms-settings', ' ', 'wp_SexHackMe\settings_wcpms_section', 'sexhackme-wcpms-settings');
register_setting('sexhackme-wcpms-settings', 'sexhack-wcpms-checkout');
foreach($plans as $plan)
{
if($plan->price > 0)
{
register_setting('sexhackme-wcpms-settings', 'sexhack-wcpms-'.strval($plan->id));
}
}
add_settings_section('sexhackme-wcpms-settings', ' ', 'wp_SexHackMe\settings_wcpms_section_email', 'sexhackme-wcpms-settings-email');
register_setting('sexhackme-wcpms-settings', 'sexhack_registration_mail_endpoint');
}
// Add Advertising settings
if( file_exists(SH_PLUGIN_DIR_PATH . 'includes/admin/functions-advert.php') )
{
include_once SH_PLUGIN_DIR_PATH . 'includes/admin/functions-advert.php';
add_settings_section('sexhackme-advert-settings', ' ', 'wp_SexHackMe\settings_advert_section', 'sexhackme-advert-settings');
register_setting('sexhackme-advert-settings', 'sexadv_video_top');
register_setting('sexhackme-advert-settings', 'sexadv_video_bot');
}
}
public static function menu()
{
//add_menu_page('SexHackMe Settings', 'SexHackMe', 'manage_options', 'sexhackme-settings',
// array($this, 'admin_page'), SH_PLUGIN_DIR_URL .'img/admin_icon.png', 31);
// Add The main page again cause with multiple subpages apparently we need to do it.
add_submenu_page( 'sexhackme-settings', 'SexHackMe Settings', 'Modules',
'manage_options', 'sexhackme-settings');
// Add page WC-PMS_Integration
if( file_exists(SH_PLUGIN_DIR_PATH . 'includes/admin/functions-wcpms.php') )
{
add_submenu_page( 'sexhackme-settings', // root slug
'WC-PMS Integration', // title
'WC-PMS Integration', // title
'manage_options', // capabilities
'pmswc-integration', // slug
'wp_SexHackMe\wcpms_adminpage'); // callback
}
// Add Advertising settings
if( file_exists(SH_PLUGIN_DIR_PATH . 'includes/admin/functions-advert.php') )
{
add_submenu_page( 'sexhackme-settings', // root slug
'Advertising', // title
'Advertising', // title
'manage_options', // capabilities
'advert', // slug
'wp_SexHackMe\advert_adminpage'); // callback
}
}
}
}
?>
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
*
* This file is part of SexHackMe Wordpress Plugin.
*
* SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* SexHackMe Wordpress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
namespace wp_SexHackMe;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if(!class_exists('SH_PostTypes')) {
class SH_PostTypes
{
public static function init()
{
// Advertising
register_post_type('sexhackadv', array(
'label' => 'Advertising','description' => '',
'public' => true,
'show_ui' => true,
'show_in_menu' => true, // Visibility in admin menu.
'menu_position' => 32,
'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', 'wp_SexHackMe\advert_add_id_column', 5 );
add_action( 'manage_sexhackadv_posts_custom_column', 'wp_SexHackMe\advert_id_column_content', 5, 2 );
}
}
}
?>
......@@ -38,6 +38,7 @@ if(!class_exists('SH_Shortcodes')) {
'sh_videohls' => __CLASS__ . '::video_hls',
'xfbp' => __CLASS__ . '::xframe_bypass',
'sexhacklive' => __CLASS__ . '::sexhacklive',
'sexadv' => __CLASS__ . '::adv_shortcode',
);
foreach( $shortcodes as $shortcode_tag => $shortcode_func ) {
......@@ -85,6 +86,33 @@ if(!class_exists('SH_Shortcodes')) {
}
public static function adv_shortcode($attr, $cont)
{
global $post;
extract( shortcode_atts(array(
"adv" => false,
), $attr));
if(!user_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;
}
}
}
......
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
*
* This file is part of SexHackMe Wordpress Plugin.
*
* SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* SexHackMe Wordpress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
namespace wp_SexHackMe;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if(!class_exists('SexhackAddUnlockLogin')) {
class SexhackAddUnlockLogin
{
public function __construct()
{
add_filter("login_form_bottom", array($this, "add_to_login"), 10, 2);
add_action("woocommerce_after_order_notes", array($this, "add_to_checkout"));
add_filter("pms_register_shortcode_content", array($this, "add_to_register"), 10, 2);
add_filter("unlock_authenticate_user", array($this, "fix_unlock_user"), 11, 1);
sexhack_log('SexhackAddUnlockLogin() Instanced');
}
public function get_proto(){
return get_proto();
}
public function fix_unlock_user($user)
{
global $sexhack_pms;
if(is_object($user) && is_valid_eth_address($user->user_login))
{
if(!($sexhack_pms->is_member($user->ID)) && !($sexhack_pms->is_premium($user->ID)))
{
$subscription_plan = $sexhack_pms->get_default_plan();
if($subscription_plan)
{
$data = array(
'user_id' => $user->ID,
'subscription_plan_id' => $subscription_plan->id,
'start_date' => date( 'Y-m-d H:i:s' ),
'expiration_date' => $subscription_plan->get_expiration_date(),
'status' => 'active',
);
$member_subscription = new \PMS_Member_Subscription();
$inserted = $member_subscription->insert( $data );
}
}
}
return $user;
}
public function unlock_get_login_url($redirect_url=false) {
$UNLOCK_BASE_URL = 'https://app.unlock-protocol.com/checkout';
$rurl=apply_filters( 'unlock_protocol_get_redirect_uri', wp_login_url());
if($redirect_url) {
$rurl=$redirect_url;
}
$login_url = add_query_arg(
array(
'client_id' => apply_filters( 'unlock_protocol_get_client_id', wp_parse_url( home_url(), PHP_URL_HOST ) ),
'redirect_uri' => $rurl,
'state' => wp_create_nonce( 'unlock_login_state' ),
),
$UNLOCK_BASE_URL
);
return apply_filters( 'unlock_protocol_get_login_url', $login_url );
}
public function unlock_button($string, $args, $redirect_url)
{
$html="";
if(!is_user_logged_in()) {
$html="<hr><div style='text-align: center; width:100%;'><p>OR</p></div><hr>";
$html.="<br><div style='text-align:left;width:100%;'<p><button onclick=\"window.location.href='".$this->unlock_get_login_url($redirect_url);
$html.="'\" type='button'>Login with Crypto Wallet</button></p></div>";
}
return $string.$html;
}
// XXX Those 3 functions, hard-coded uri's that are dependent on a shortcode? that's sounds a bad idea, we
// should make them a configurable option
public function add_to_register($string, $args){
return $this->unlock_button($string, $args, get_proto().wp_parse_url( home_url(), PHP_URL_HOST )."/register");
}
public function add_to_login($string, $args){
return $this->unlock_button($string, $args, get_proto().wp_parse_url( home_url(), PHP_URL_HOST ));
}
public function add_to_checkout(){
echo $this->unlock_button('', $args, get_proto().wp_parse_url( home_url(), PHP_URL_HOST )."/checkout");
}
}
// Instance Unlock Login support class
new SexhackAddUnlockLogin;
}
?>
......@@ -21,9 +21,13 @@
namespace wp_SexHackMe;
if(!class_exists('SexhackAdvert')) {
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
class sexhackadv_widget extends \WP_Widget {
if(!class_exists('SH_ADVWidget')) {
class SH_ADVWidget extends \WP_Widget
{
function __construct()
{
parent::__construct(
......@@ -75,108 +79,15 @@ if(!class_exists('SexhackAdvert')) {
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()
public static function register()
{
add_shortcode("sexadv", array($this, "adv_shortcode"));
add_action('init', array($this, "register_sexhackadv_post_type"));
sexhack_log('SexhackAdvert() Instanced');
register_widget('wp_SexHackMe\SH_ADVWidget');
}
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;
}
}
add_action( 'widgets_init', array('wp_SexHackMe\SH_ADVWidget', 'register' ));
}
$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')
)
);
?>
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
*
* This file is part of SexHackMe Wordpress Plugin.
*
* SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* SexHackMe Wordpress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
namespace wp_SexHackMe;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
/* Class to add Video to product page instead of image */
if(!class_exists('SexhackWoocommerceProductVideos')) {
class SexhackWoocommerceProductVideos
{
public function __construct()
{
sexhack_log('SexhackWoocommerceProductVideos() Instanced');
add_action( 'woocommerce_before_single_product', array($this, 'video_remove_default_woocommerce_image' ));
add_filter( 'query_vars', array($this, 'themeslug_query_vars' ));
}
public function themeslug_query_vars( $qvars ) {
$qvars[] = 'sexhack_forcevideo';
return $qvars;
}
public function video_remove_default_woocommerce_image() {
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
add_action( 'woocommerce_before_single_product_summary', array($this, 'woocommerce_show_product_images_videos'), 30 );
}
public function woocommerce_show_product_images_videos() {
// Get video and display
$prod = wc_get_product(get_the_ID());
// verify GET vars
$bypass = get_query_var('sexhack_forcevideo', false);
// Possible displays
$disps = array('video', 'gif', 'image');
// By default fallback to:
$display='image';
// detect attributes
$video = $prod->get_attribute('video_preview');
$gif = $prod->get_attribute('gif_preview');
if(in_array($bypass, $disps)) $display=$bypass;
else if($video) $display="video";
else if($gif) $display="gif";
switch($display) {
case "video":
// Sanitize video URL
$video = esc_url( $video );
// Display video
echo '<div class="images"><div class="responsive-video-wrap"><h3>Video Preview</h3>';
echo '<video src='."'$video'".' controls autoplay muted playsinline loop></video></div></div>';
break;
case "gif":
// sanitize URL
$gif = esc_url( $gif );
// Display GIF
echo '<div class="images"><img src="'.$gif.'" /></div>';
break;
case "image":
// No video defined so get thumbnail
wc_get_template( 'single-product/product-image.php' );
break;
}
}
}
// Instance Product Video Support class
new SexhackWoocommerceProductVideos;
}
/* Class to change woocommerce account form fields */
if(!class_exists('WoocommerceAccountRemoveNameSurname')) {
class WoocommerceAccountRemoveNameSurname
{
public function __construct()
{
add_filter('woocommerce_save_account_details_required_fields', array($this, 'ts_hide_first_last_name'));
add_action( 'woocommerce_edit_account_form_start', array($this, 'add_username_to_edit_account_form'));
sexhack_log('WoocommerceAccountRemoveNameSurname() Instanced');
}
// Add the custom field "username"
public function add_username_to_edit_account_form()
{
$user = wp_get_current_user();
?>
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
<label for="username"><?php _e( 'Username', 'woocommerce' ); ?> (Cannot be changed!) </label>
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="username" id="username"
value="<?php echo esc_attr( $user->user_login ); ?>" disabled />
</p>
<?php
}
public function ts_hide_first_last_name($required_fields)
{
unset($required_fields["account_first_name"]);
unset($required_fields["account_last_name"]);
unset($required_fields["account_display_name"]);
return $required_fields;
}
}
// Start changing the woocommerce account form
new WoocommerceAccountRemoveNameSurname;
}
if(!class_exists('WoocommerceEmailCheckout')) {
class WoocommerceEmailCheckout
{
public function __construct()
{
sexhack_log('WoocommerceEmailCheckout() Instanced');
add_filter( 'woocommerce_checkout_fields' , array($this,'simplify_checkout_virtual') );
add_filter( 'woocommerce_login_redirect', array($this, 'fix_woocommerce_user'), 99, 2);
}
public function simplify_checkout_virtual( $fields ) {
$only_virtual = true;
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
// Check if there are non-virtual products
if ( ! $cart_item['data']->is_virtual() ) $only_virtual = false;
}
if( $only_virtual ) {
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_phone']);
unset($fields['billing']['billing_first_name']);
unset($fields['billing']['billing_last_name']);
add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );
}
return $fields;
}
// Fix the user plan if none by add the default (usually free) one
public function fix_woocommerce_user($redirect, $user)
{
if(is_object($user) && is_checkout())
{
sh_fix_user_with_no_plan($user->ID);
}
return $redirect;
}
}
// Start the Woocommerce Email only on Checkout field
new WoocommerceEmailCheckout;
}
if(!class_exists('SH_WooCommerce_Registration_Integration')) {
class SH_WooCommerce_Registration_Integration
{
public function __construct()
{
//$this->addcart = false;
sexhack_log('SH_WooCommerce_Registration_Integration() Instanced');
// Register new endpoint (URL) for My Account page
add_action( 'init', array($this, 'add_subscriptions_endpoint'), 300 );
// Add new QUERY vars
add_filter( 'query_vars', array($this, 'subscriptions_query_vars'), 0 );
// Insert the new endpoint into the My Account menu
add_filter( 'woocommerce_account_menu_items', array($this, 'add_subscriptions_link_my_account') );
/* Add content to the new tab
* NOTE: add_action must follow 'woocommerce_account_{your-endpoint-slug}_endpoint' format */
add_action( 'woocommerce_account_subscriptions_endpoint', array($this, 'subscriptions_content'), 50, 6 );
/* Inject random generate pass as we don't send it from the registration form */
add_action( 'init', array($this, 'gen_random_pwd'), 5); // This need to happen before PMS detect the form at "10" sequence firing
// Sending email with link to set user password
add_action("sh_register_form_after_create_user", array($this, "send_register_email_reset_password") );
// Manage manual payments for Paid Member Subscriptions plugin
// ( expecially for new users and change of subscription plan )
add_filter('sh_get_redirect_url', array($this, 'redirect_after_manual_payment') );
}
// redirect
public function redirect_after_manual_payment($url)
{
$subscription_plan = sh_get_subscription_plan( absint($_POST['subscription_plans']));
if( !isset( $subscription_plan->id ) || $subscription_plan->price == 0 )
return $url;
else
{
$prodid = get_option('sexhack-wcpms-'.strval($subscription_plan->id), false);
$product = false;
if($prodid) $product = wc_get_product($prodid);
if(($product) && ($product->get_regular_price()==$subscription_plan->price)) $wcprods = array($product);
else $wcprods = get_wc_subscription_products_priced($subscription_plan->price, $subscription_plan->id);
if(count($wcprods) > 0)
{
return wc_get_checkout_url()."?add-to-cart=".$wcprods[0]->get_id()."&quantity=1";
}
return $url; //home_url('/payment-info');
}
}
// Register new endpoint (URL) for My Account page
// Note: Re-save Permalinks or it will give 404 error
function add_subscriptions_endpoint()
{
global $wp_rewrite;
sexhack_log("SUBSCRIPTION ENDPOINT ADDED");
add_rewrite_endpoint( 'subscriptions', EP_ROOT | EP_PAGES );
$rules = $wp_rewrite->wp_rewrite_rules();
if(!array_key_exists('(.?.+?)/subscriptions(/(.*))?/?$', $rules))
{
sexhack_log("SUBSCRIPTION RULESS NEEDS REWRITE");
update_option('need_rewrite_flush', 1);
}
}
// Add new QUERY vars
public function subscriptions_query_vars( $vars )
{
$vars[] = 'subscriptions';
return $vars;
}
// Insert the new endpoint into the My Account menu
public function add_subscriptions_link_my_account( $items )
{
$items['subscriptions'] = 'Subscriptions';
return $items;
}
// Add content to the new tab
public function subscriptions_content()
{
sh_account_subscription_content();
}
public function send_register_email_reset_password($user_data)
{
$mailpage = get_option('sexhack_registration_mail_endpoint', false);
if($mailpage) {
$page = get_page($mailpage);
$mailpage = $page->post_name;
}
send_changepwd_mail($user_data["user_login"], $mailpage);
}
public function gen_random_pwd()
{
sh_genpass_register_form();
}
}
// Initilize
new SH_WooCommerce_Registration_Integration;
}
?>
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
*
* This file is part of SexHackMe Wordpress Plugin.
*
* SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* SexHackMe Wordpress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
namespace wp_SexHackMe;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
function advert_add_id_column($columns)
{
$columns['revealid_id'] = 'ID';
$columns['revealid_short'] = 'shortcode';
return $columns;
}
function advert_id_column_content( $column, $id ) {
if( 'revealid_id' == $column ) {
echo $id;
}
if( 'revealid_short' == $column ) {
echo "[sexadv adv=$id]";
}
}
?>
......@@ -108,6 +108,7 @@ function user_has_premium_access($uid='')
{
global $sexhack_pms;
if(!isset($sexhack_pms)) return false;
return $sexhack_pms->is_premium($uid) AND is_user_logged_in();
}
......@@ -115,6 +116,7 @@ function user_is_premium($uid='')
{
global $sexhack_pms;
if(!isset($sexhack_pms)) return false;
return $sexhack_pms->is_premium($uid);
}
......@@ -122,6 +124,7 @@ function user_has_member_access($uid='')
{
global $sexhack_pms;
if(!isset($sexhack_pms)) return false;
if($uid) return $sexhack_pms->is_member($uid) OR $sexhack_pms->is_premium($uid);
return is_user_logged_in();
......@@ -131,6 +134,7 @@ function user_is_member($uid='')
{
global $sexhack_pms;
if(!isset($sexhack_pms)) return false;
return $sexhack_pms->is_member($uid);
}
......
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
*
* This file is part of SexHackMe Wordpress Plugin.
*
* SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* SexHackMe Wordpress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
namespace wp_SexHackMe;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
add_action('pms_register_form_after_create_user', 'pms_register_form_after_create_user');
function pms_register_form_after_create_user()
{
do_action('sh_register_form_after_create_user');
}
// XXX In the docs of PMS they indicate to use add_action but they use a filter... uhmmm
//add_action('pms_get_redirect_url', 'pms_get_redirect_url');
add_filter('pms_get_redirect_url', 'pms_get_redirect_url', 100, 2);
function pms_get_redirect_url($url, $location=false)
{
if( !isset( $_POST['pay_gate'] ) || $_POST['pay_gate'] != 'manual' )
return $url;
return apply_filter('sh_get_redirect_url', $url, $location);
}
?>
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
*
* This file is part of SexHackMe Wordpress Plugin.
*
* SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* SexHackMe Wordpress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
namespace wp_SexHackMe;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
// XXX Add Pagination
function get_wc_products_by_meta($spid=false, $metakey='_pms_woo_subscription_id')
{
if($spid) $meta = array(
'key' => $metakey,
'value' => $spid,
'compare' => '=',
);
else $meta = array(
'key' => $metakey,
'compare' => 'like',
);
$args = array(
'posts_per_page' => 100,
'post_type' => 'product',
'post_status' => 'publish',
'meta_key' => $metakey,
'meta_query' => array($meta),
);
$query = new \WP_Query( $args );
return $query;
}
// XXX Add Pagination
function get_wc_subscription_products_priced($price, $pid=false)
{
$res = array();
// XXX CACHE THIS!
$pages = get_wc_products_by_meta($pid);
if ( $pages->have_posts() )
{
foreach($pages->posts as $post)
{
$product = wc_get_product($post->ID);
if(is_object($product) && (strval($price) == strval($product->get_regular_price())))
{
$res[] = $product;
}
}
}
return $res;
}
?>
......@@ -217,9 +217,16 @@ if(!class_exists('SexHackMe_Plugin')) {
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/functions-core.php' ) )
include_once SH_PLUGIN_DIR_PATH . 'includes/functions-core.php';
/* Custom Post Types declarations */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-post_types.php') )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-post_types.php';
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-admin.php' ) )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-admin.php';
/* Hooks compatibility/translation */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/functions-hooks.php') )
include_once SH_PLUGIN_DIR_PATH . 'include/functions-hooks.php';
include_once SH_PLUGIN_DIR_PATH . 'includes/functions-hooks.php';
/* Cryptocurrencies utils */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/functions-crypto.php' ) )
......@@ -233,6 +240,10 @@ if(!class_exists('SexHackMe_Plugin')) {
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-video-players.php' ) )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-video-players.php';
/* Advertising support */
if(file_exists( SH_PLUGIN_DIR_PATH . 'includes/functions-advert.php' ) )
include_once SH_PLUGIN_DIR_PATH . 'includes/functions-advert.php';
/* Cam4 and Chaturbate support */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-livecam-site-support.php') )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-livecam-site-support.php';
......@@ -257,7 +268,9 @@ if(!class_exists('SexHackMe_Plugin')) {
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-shortcodes.php' ) )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-shortcodes.php';
/* Widgets */
if( file_exists( SH_PLUGIN_DIR_PATH . 'includes/class-widgets.php' ) )
include_once SH_PLUGIN_DIR_PATH . 'includes/class-widgets.php';
/* Hook to include needed files */
do_action( 'pms_include_files' );
......@@ -318,6 +331,9 @@ if(!class_exists('SexHackMe_Plugin')) {
//if( is_admin() )
// add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
// Initialize Custom post_types
add_action( 'init', array( 'wp_SexHackMe\SH_PostTypes', 'init') );
// Initialize shortcodes
add_action( 'init', array( 'wp_SexHackMe\SH_Shortcodes', 'init' ) );
//add_action( 'init', array( $this, 'init_dependencies' ), 1 );
......@@ -520,6 +536,10 @@ if(!class_exists('SexHackMe_Plugin')) {
}
}
}
SH_Admin::init();
}
public function admin_menu()
......@@ -527,8 +547,9 @@ if(!class_exists('SexHackMe_Plugin')) {
add_menu_page('SexHackMe Settings', 'SexHackMe', 'manage_options', 'sexhackme-settings',
array($this, 'admin_page'), SH_PLUGIN_DIR_URL .'img/admin_icon.png', 31);
add_submenu_page( 'sexhackme-settings', 'SexHackMe Settings', 'Modules',
'manage_options', 'sexhackme-settings');
SH_Admin::menu();
foreach($this->SECTIONS as $section) {
if(get_option( $section['name'])=="1")
......@@ -552,8 +573,7 @@ if(!class_exists('SexHackMe_Plugin')) {
public function admin_page()
{
if(file_exists( SH_PLUGIN_DIR_PATH . 'templates/admin/sexhackme.php'))
include_once( SH_PLUGIN_DIR_PATH . 'templates/admin/sexhackme.php');
sh_get_template('admin/sexhackme.php', array('sections' => $this->SECTIONS));
}
}
......
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
*
* This file is part of SexHackMe Wordpress Plugin.
*
* SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* SexHackMe Wordpress Plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
?>
<div class="wrap">
<?php do_settings_sections( 'sexhackme-advert-settings' ); ?>
<form method="post" action="/wp-admin/options.php">
<?php settings_fields( 'sexhackme-advert-settings' ); ?>
<table class="form-table">
<tr align="top">
<td>
<select id="sexadv_video_top" name="sexadv_video_top" class="widefat">
<option value="-1">Choose...</option>
<?php
$opt=get_option("sexadv_video_top");
foreach( get_posts(array('post_type' => 'sexhackadv', 'parent' => 0)) 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 ADV for top Videogallery</p>
<select id="sexadv_video_bot" name="sexadv_video_bot" class="widefat">
<option value="-1">Choose...</option>
<?php
$opt=get_option("sexadv_video_bot");
foreach( get_posts(array('post_type' => 'sexhackadv', 'parent' => 0)) 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 ADV for bottom Videogallery</p>
</td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
......@@ -21,6 +21,8 @@
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
?>
<div class="wrap">
<h2>SexHackMe Plugin Settings</h2>
......@@ -28,7 +30,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
<?php settings_fields( 'sexhackme-settings' ); ?>
<?php do_settings_sections( 'sexhackme-settings' ); ?>
<table class="form-table">
<?php foreach($this->SECTIONS as $section) { ?>
<?php foreach($sections as $section) { ?>
<tr align="top">
<th scope="row"><?php echo $section['description'];?></th>
<td>
......
<?php
<?php
/**
* Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
* License: GNU/GPL version 3.0
......@@ -19,25 +19,10 @@
* along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
*/
namespace wp_SexHackMe;
if(!class_exists('SH_WooCommerce_Registration_Integration')) {
class SH_WooCommerce_Registration_Integration2
{
public function gen_random_pwd()
{
sh_genpass_register_form();
}
}
}
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
function wcpms_adminpage()
{
$plans = sh_get_subscription_plans();
sexhack_log($plans);
$plans = wp_SexHackMe\sh_get_subscription_plans();
?>
<div class="wrap">
......@@ -57,12 +42,11 @@ function wcpms_adminpage()
<select id="sexhack-wcpms-<?php echo $plan->id;?>" name="sexhack-wcpms-<?php echo $plan->id; ?>" class="widefat">
<?php
$opt = get_option('sexhack-wcpms-'.strval($plan->id));
foreach(get_wc_subscription_products_priced($plan->price, $plan->id) as $prod)
foreach(wp_SexHackMe\get_wc_subscription_products_priced($plan->price, $plan->id) as $prod)
{
?>
<option value='<?php echo $prod->id; ?>' <?php if($opt == $prod->id) echo "selected"; ?> >
<?php echo $prod->get_title() ?> (<?php echo $prod->id; ?>)
<option value='<?php echo $prod->get_id(); ?>' <?php if($opt == $prod->get_id()) echo "selected"; ?> >
<?php echo $prod->get_title() ?> (<?php echo $prod->get_id(); ?>)
</option>
<?php
......@@ -76,48 +60,25 @@ function wcpms_adminpage()
}
?>
</table>
<?php do_settings_sections( 'sexhackme-wcpms-settings-email' ); ?>
<table class="form-table">
<tr align="top">
<td>
<select id="sexhack_registration_mail_endpoint" name="sexhack_registration_mail_endpoint" class="widefat">
<option value="-1">Choose...</option>
<?php
$opt=get_option("sexhack_registration_mail_endpoint");
foreach( get_posts(array('post_type' => 'page', 'parent' => 0)) 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 email checkout registration redirect page</p>
</td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}
function settings_wcpms_section()
{
echo "<h2>SexHackMe PMS - WooCommerce integration Settings</h2>";
}
function wcpms_initialize_options()
{
$plans = pms_get_subscription_plans();
add_settings_section('sexhackme-wcpms-settings', ' ', 'wp_SexHackMe\settings_wcpms_section', 'sexhackme-wcpms-settings');
register_setting('sexhackme-wcpms-settings', 'sexhack-wcpms-checkout');
foreach($plans as $plan)
{
if($plan->price > 0)
{
register_setting('sexhackme-wcpms-settings', 'sexhack-wcpms-'.strval($plan->id));
}
}
}
add_action('admin_init', 'wp_SexHackMe\wcpms_initialize_options');
$SEXHACK_SECTION = array(
'class' => 'SH_WooCommerce_Registration_Integration2',
'description' => 'Integrate woocommerce account page and sexhack modified registration form on pms to send password change link by email',
'name' => 'sexhackme_pmswooregistration',
'require-page' => array(
array('post_type' => 'page', 'title' => 'Set password mail page', 'option' => 'sexhack_registration_mail_endpoint')
),
'adminmenu' => array(
array('title' => 'WC-PMS Integration',
'slug' => 'wcpms-integration',
'callback' => 'wp_SexHackMe\wcpms_adminpage')
),
'slugs' => array('account', 'register', 'login', 'password-reset')
);
?>
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