Delete post actions

parent deaa6c7b
<?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_PostType_Video')) {
class SH_PostType_Video
{
public function __construct()
{
add_action('delete_post', array($this, 'delete_post'), 10, 2);
}
public function delete_post($post_id, $post)
{
// Make sure is the right post_type or exit
if(!is_object($post) || ($post->post_type!='sexhack_video'))
return;
sh_delete_video_from_post($post_id);
}
}
// run
new SH_PostType_Video;
}
?>
...@@ -81,25 +81,35 @@ if(!class_exists('SH_Query')) { ...@@ -81,25 +81,35 @@ if(!class_exists('SH_Query')) {
} }
} }
public static function delete_Video($id, $idtype='')
{
global $wpdb;
if(!is_integer($id))
return;
$idtype=sanitize_idtype($idtype);
if(!$idtype) return false;
$sql = "DELETE FROM {$wpdb->prefix}".SH_PREFIX."videos WHERE {$idtype}=".intval($id);
return $wpdb->query( $sql );
}
public static function get_Video($id, $idtype='') public static function get_Video($id, $idtype='')
{ {
global $wpdb; global $wpdb;
switch($idtype) if(!is_integer($id))
{ return;
case "product":
case "post":
$idtype=$idtype."_id";
break;
default:
$idtype="id";
} $idtype=sanitize_idtype($idtype);
if(!$idtype) return false;
// TODO sanitize query $sql = "SELECT * FROM {$wpdb->prefix}".SH_PREFIX."videos WHERE {$idtype}=".intval($id);
$sql = "SELECT * from {$wpdb->prefix}".SH_PREFIX."videos WHERE {$idtype}=".intval($id);
$dbres = $wpdb->get_results( $sql ); $dbres = $wpdb->get_results( $sql );
if(is_array($dbres) && count($dbres) > 0) if(is_array($dbres) && count($dbres) > 0)
{ {
......
...@@ -32,36 +32,6 @@ function sh_get_template($tmpl, $args=array()) ...@@ -32,36 +32,6 @@ function sh_get_template($tmpl, $args=array())
return false; return false;
} }
function sh_save_video($video)
{
return SH_Query::save_Video($video);
}
function sh_get_videos($vcat=false)
{
return SH_Query::get_Videos($vcat);
}
function sh_get_video($id)
{
return SH_Query::get_Video($id);
}
function sh_get_video_from_post($p)
{
if(is_int($p) && $p > 0) return SH_Query::get_Video($p, 'post');
else if(is_object($p)) return SH_Query::get_Video($p->ID, 'post');
return false;
}
function sh_get_video_from_product($p)
{
if(is_int($p) and $p > 0) return SH_Query::get_Video($p, 'product');
else if(is_object($p)) return SH_Query::get_Video($p->get_id(), 'product');
return false;
}
function sh_get_subscription_plans() function sh_get_subscription_plans()
{ {
return pms_get_subscription_plans(); return pms_get_subscription_plans();
......
...@@ -39,6 +39,24 @@ if(!function_exists('sexhack_log')){ ...@@ -39,6 +39,24 @@ if(!function_exists('sexhack_log')){
} }
function sanitize_idtype($idt=false)
{
if((!$idt) || ($idt=='')) $idt='id';
switch($idt)
{
case 'post':
case 'product':
return $idt."_id";
break;
case 'id':
return $idt;
break;
default:
return false;
}
}
function debug_rewrite_rules($matchonly=false) function debug_rewrite_rules($matchonly=false)
{ {
$matchonly=true; $matchonly=true;
......
...@@ -375,6 +375,8 @@ if(!class_exists('SexHackMe_Plugin')) { ...@@ -375,6 +375,8 @@ if(!class_exists('SexHackMe_Plugin')) {
/* Video */ /* Video */
$this->file_include('includes/class-video.php'); $this->file_include('includes/class-video.php');
$this->file_include('includes/functions-video.php');
$this->file_include('includes/class-post_type-video.php');
/* Video Gallery */ /* Video Gallery */
$this->file_include('includes/class-videogallery.php'); $this->file_include('includes/class-videogallery.php');
...@@ -609,8 +611,8 @@ if(!class_exists('SexHackMe_Plugin')) { ...@@ -609,8 +611,8 @@ if(!class_exists('SexHackMe_Plugin')) {
if( WP_DEBUG === true ){ if( WP_DEBUG === true ){
// only matched? // only matched?
//add_action("the_post", 'wp_SexHackMe\debug_rewrite_rules'); //add_action("the_post", 'wp_SexHackMe\debug_rewrite_rules');
sexhack_log("REQUEST: ".$_SERVER['REQUEST_URI']." QUERY: ".$_SERVER['QUERY_STRING']. "POST:"); //sexhack_log("REQUEST: ".$_SERVER['REQUEST_URI']." QUERY: ".$_SERVER['QUERY_STRING']. "POST:");
sexhack_log($_POST); //sexhack_log($_POST);
} }
......
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