Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
W
WordPress_SexHackMe_Plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SexHackMe
WordPress_SexHackMe_Plugin
Commits
1d64494d
Commit
1d64494d
authored
Jul 23, 2022
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Video product implemented
parent
06cda840
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
126 additions
and
5 deletions
+126
-5
functions-wcpms.php
includes/admin/functions-wcpms.php
+4
-0
class-admin.php
includes/class-admin.php
+6
-0
class-query.php
includes/class-query.php
+4
-0
class-woocommerce-support.php
includes/class-woocommerce-support.php
+29
-5
functions-woocommerce-support.php
includes/functions-woocommerce-support.php
+57
-0
wcpms.php
templates/admin/wcpms.php
+26
-0
No files found.
includes/admin/functions-wcpms.php
View file @
1d64494d
...
...
@@ -40,5 +40,9 @@ function settings_wcpms_section_email()
echo
"<h2>WooCommerce Checkout Email endpoint</h2>"
;
}
function
settings_wcpms_section_prodcat
()
{
echo
"<h2>WooCommerce auto-roducts for Videos</h2>"
;
}
?>
includes/class-admin.php
View file @
1d64494d
...
...
@@ -50,6 +50,12 @@ if(!class_exists('SH_Admin')) {
}
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_settings_section
(
'sexhackme-wcpms-settings'
,
' '
,
'wp_SexHackMe\settings_wcpms_section_prodcat'
,
'sexhackme-wcpms-settings-prodcat'
);
register_setting
(
'sexhackme-wcpms-settings'
,
'sexhack_wcpms-prodcat'
);
register_setting
(
'sexhackme-wcpms-settings'
,
'sexhack_wcpms-prodvisible'
);
}
// Add Advertising settings
...
...
includes/class-query.php
View file @
1d64494d
...
...
@@ -160,10 +160,14 @@ if(!class_exists('SH_Query')) {
if
(
!
is_integer
(
$id
))
return
;
$video
=
SH_Query
::
get_Video
(
$id
,
$idtype
);
$idtype
=
sanitize_idtype
(
$idtype
);
if
(
!
$idtype
)
return
false
;
do_action
(
'sh_delete_video'
,
$video
);
$sqlarr
=
array
();
$sqlarr
[]
=
"DELETE FROM
{
$wpdb
->
prefix
}
"
.
SH_PREFIX
.
"videotags_assoc WHERE video_id IN (
SELECT id FROM
{
$wpdb
->
prefix
}
"
.
SH_PREFIX
.
"videos
...
...
includes/class-woocommerce-support.php
View file @
1d64494d
...
...
@@ -33,12 +33,18 @@ if(!class_exists("SH_VideoProducts")) {
{
//add_action('sh_save_video_after_query', array($this, 'sync_product_from_video'), 1, 10);
add_filter
(
'video_before_save'
,
array
(
$this
,
'sync_product_from_video'
));
add_action
(
'sh_delete_video'
,
array
(
$this
,
'delete_video_product'
),
1
,
10
);
}
public
function
delete_video_product
(
$video
)
{
if
(
$video
->
product_id
>
0
)
return
sh_wc_deleteProduct
(
$video
->
product_id
,
true
);
return
false
;
}
public
function
sync_product_from_video
(
$video
)
{
sexhack_log
(
"PRODUUUUUUCT"
);
sexhack_log
(
$video
);
$prod
=
false
;
...
...
@@ -66,12 +72,13 @@ if(!class_exists("SH_VideoProducts")) {
// Product status.
if
(
$video
->
status
==
'published'
)
$prod
->
set_status
(
'publish
ed
'
);
$prod
->
set_status
(
'publish'
);
else
$prod
->
set_status
(
'draft'
);
// Not visible in catalog
$prod
->
set_catalog_visibility
(
'hidden'
);
// Catalog visibility
if
(
get_option
(
'sexhack_wcpms-prodvisible'
,
false
))
$prod
->
set_catalog_visibility
(
'visible'
);
else
$prod
->
set_catalog_visibility
(
'hidden'
);
// Set the product as virtual and downloadable
$prod
->
set_virtual
(
true
);
...
...
@@ -131,6 +138,23 @@ if(!class_exists("SH_VideoProducts")) {
$prod
->
set_downloads
(
$wcdowns
);
// Categories. If not configured try to search
// for a category named "Video", if not present
// just take the last one in list, if no categories
// exists just don't set anything and will remain in
// Uncategorized.
$cat_id
=
get_option
(
'sexhack_wcpms-prodcat'
,
false
);
if
(
$cat_id
)
$prod
->
set_category_ids
(
array
(
$cat_id
));
else
{
$cat
=
false
;
foreach
(
get_categories
(
array
(
'taxonomy'
=>
'product_cat'
))
as
$cat
)
{
if
(
$cat
->
name
==
'Video'
)
break
;
}
if
(
$cat
)
$prod
->
set_category_ids
(
array
(
$cat
->
term_id
));
}
$prod
->
save
();
$video
->
product_id
=
$prod
->
get_id
();
...
...
includes/functions-woocommerce-support.php
View file @
1d64494d
...
...
@@ -71,4 +71,61 @@ function get_wc_subscription_products_priced($price, $pid=false)
return
$res
;
}
// Delete a product by id
/*
* Method to delete Woo Product
*
* @param int $id the product ID.
* @param bool $force true to permanently delete product, false to move to trash.
* @return \WP_Error|boolean
*/
function
sh_wc_deleteProduct
(
$id
,
$force
=
FALSE
)
{
$product
=
wc_get_product
(
$id
);
if
(
empty
(
$product
))
return
new
WP_Error
(
999
,
sprintf
(
__
(
'No %s is associated with #%d'
,
'woocommerce'
),
'product'
,
$id
));
// If we're forcing, then delete permanently.
if
(
$force
)
{
if
(
$product
->
is_type
(
'variable'
))
{
foreach
(
$product
->
get_children
()
as
$child_id
)
{
$child
=
wc_get_product
(
$child_id
);
$child
->
delete
(
true
);
}
}
elseif
(
$product
->
is_type
(
'grouped'
))
{
foreach
(
$product
->
get_children
()
as
$child_id
)
{
$child
=
wc_get_product
(
$child_id
);
$child
->
set_parent_id
(
0
);
$child
->
save
();
}
}
$product
->
delete
(
true
);
$result
=
$product
->
get_id
()
>
0
?
false
:
true
;
}
else
{
$product
->
delete
();
$result
=
'trash'
===
$product
->
get_status
();
}
if
(
!
$result
)
{
return
new
WP_Error
(
999
,
sprintf
(
__
(
'This %s cannot be deleted'
,
'woocommerce'
),
'product'
));
}
// Delete parent product transients.
if
(
$parent_id
=
wp_get_post_parent_id
(
$id
))
{
wc_delete_product_transients
(
$parent_id
);
}
return
true
;
}
?>
templates/admin/wcpms.php
View file @
1d64494d
...
...
@@ -78,6 +78,32 @@ $plans = wp_SexHackMe\sh_get_subscription_plans();
</td>
</tr>
</table>
<?php
do_settings_sections
(
'sexhackme-wcpms-settings-prodcat'
);
?>
<table
class=
"form-table"
>
<tr
align=
"top"
>
<td>
<select
id=
"sexhackme_wcpms-prodcat"
name=
"sexhack_wcpms-prodcat"
class=
"widefat"
>
<option
value=
"-1"
>
Choose...
</option>
<?php
$opt
=
get_option
(
"sexhack_wcpms-prodcat"
);
foreach
(
get_categories
(
array
(
'taxonomy'
=>
'product_cat'
))
as
$cat
)
{
echo
'<option value="'
.
esc_attr
(
$cat
->
term_id
)
.
'"'
;
if
(
$opt
==
$cat
->
term_id
)
{
echo
"selected"
;}
echo
'>'
.
esc_html
(
$cat
->
name
)
.
' ( ID: '
.
esc_attr
(
$cat
->
term_id
)
.
')'
.
'</option>'
;
}
?>
</select>
<p
class=
"description"
>
Select default woocommerce product category for auto-product creation
</p>
</td>
</tr>
<tr
align=
"top"
>
<td>
<input
type=
'checkbox'
name=
'sexhack_wcpms-prodvisible'
<?php
if
(
get_option
(
'sexhack_wcpms-prodvisible'
,
false
))
echo
"checked"
?>
/>
<p
class=
"description"
>
Show products auto-created in shop?
</p>
</td>
</tr>
</table>
<?php
submit_button
();
?>
</form>
</div>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment