utility.php
2.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* Admin message
*
* @since 1.5.0
*
* @param string $message Message.
* @param string $type Update Type.
*/
function cpac_admin_message( $message = '', $type = 'updated' ) {
$GLOBALS['cpac_messages'][] = '<div class="cpac_message ' . $type . '"><p>' . $message . '</p></div>';
add_action( 'admin_notices', 'cpac_admin_notice' );
add_action( 'network_admin_notices', 'cpac_admin_notice' );
}
/**
* Admin Notice
*
* This uses the standard CSS styling from WordPress, no additional CSS have to be loaded.
*
* @since 1.5.0
*
* @return string Message.
*/
function cpac_admin_notice() {
echo implode( $GLOBALS['cpac_messages'] );
}
/**
* Is doing ajax
*
* @since 2.3.4
*/
function cac_is_doing_ajax() {
if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) {
return false;
}
if ( ( isset( $_POST['action'] ) && 'inline-save' === $_POST['action'] ) ) {
return true;
}
if ( ( isset( $_POST['action'] ) && 'edit-comment' === $_POST['action'] ) ) {
return true;
}
if ( ( isset( $_POST['action'] ) && 'replyto-comment' === $_POST['action'] ) ) {
return true;
}
if ( ( isset( $_POST['plugin_id'] ) && 'cpac' == $_POST['plugin_id'] ) || ( isset( $_GET['plugin_id'] ) && 'cpac' == $_GET['plugin_id'] ) ) {
return true;
}
return false;
}
/**
* Returns true if the installed version of WooCommerce is version X or greater
*
* @since 2.3.4
* @return boolean true if the installed version of WooCommerce is version X or greater
*/
function cpac_is_wc_version_gte( $version = '1.0' ) {
$wc_version = defined( 'WC_VERSION' ) && WC_VERSION ? WC_VERSION : null;
return $wc_version && version_compare( $wc_version, $version, '>=' );
}
function cpac_is_acf_active() {
return class_exists( 'acf', false );
}
function cpac_is_woocommerce_active() {
return class_exists( 'WooCommerce', false );
}
function cpac_is_pro_active() {
return class_exists( 'CAC_Addon_Pro', false );
}