This commit is contained in:
2026-04-26 23:47:49 +02:00
parent 1b95f03d1e
commit b073e009d8
5288 changed files with 1112699 additions and 55536 deletions

View File

@@ -7,21 +7,21 @@ if ( ! defined( 'ABSPATH' ) ) {
}
function buildAdminUrl( $page, $tab = '', $action = '', $extra = array() ) {
$args = array( 'page' => $page );
if ( $tab ) {
$args['tab'] = $tab;
}
if ( $action ) {
$args['action'] = $action;
}
$args = array_merge( $args, $extra );
return add_query_arg( $args, admin_url( 'admin.php' ) );
}
function getCurrentAdminPage() {
@@ -47,7 +47,7 @@ function getCurrentAdminAction() {
}
function getAdminPrimaryNavTabs() {
$tabs = array(
'general' => array(
'url' => buildAdminUrl( 'pixelyoursite' ),
@@ -58,23 +58,23 @@ function getAdminPrimaryNavTabs() {
'name' => 'Events',
),
);
if ( isWooCommerceActive() ) {
$tabs['woo'] = array(
'url' => buildAdminUrl( 'pixelyoursite', 'woo' ),
'name' => 'WooCommerce',
);
}
if ( isEddActive() ) {
$tabs['edd'] = array(
'url' => buildAdminUrl( 'pixelyoursite', 'edd' ),
'name' => 'EasyDigitalDownloads',
);
}
if ( isWcfActive() ) {
@@ -90,38 +90,38 @@ function getAdminPrimaryNavTabs() {
'name' => 'Consent',
'class' => 'orange'
);
return $tabs;
}
function getAdminSecondaryNavTabs() {
$tabs = array(
'facebook_settings' => array(
'url' => buildAdminUrl( 'pixelyoursite', 'facebook_settings' ),
'name' => 'Facebook Settings',
'name' => 'Meta Settings',
),
'ga_settings' => array(
'url' => buildAdminUrl( 'pixelyoursite', 'ga_settings' ),
'name' => 'Google Analytics Settings',
),
);
$tabs = apply_filters( 'pys_admin_secondary_nav_tabs', $tabs );
$tabs['superpack_settings'] = array(
'url' => buildAdminUrl( 'pixelyoursite', 'superpack_settings' ),
'name' => 'Super Pack Settings',
);
$tabs['head_footer'] = array(
'url' => buildAdminUrl( 'pixelyoursite', 'head_footer' ),
'name' => 'Head & Footer',
);
return $tabs;
}
function cardCollapseBtn($attr = "") {
@@ -138,17 +138,17 @@ function renderCollapseTargetAttributes( $key, $settings ) {
function manageAdminPermissions() {
global $wp_roles;
$roles = PYS()->getOption( 'admin_permissions', array( 'administrator' ) );
foreach ( $wp_roles->roles as $role => $options ) {
if ( in_array( $role, $roles ) ) {
$wp_roles->add_cap( $role, 'manage_pys' );
} else {
$wp_roles->remove_cap( $role, 'manage_pys' );
}
}
}
@@ -159,7 +159,7 @@ function renderPopoverButton( $popover_id ) {
data-placement="right" data-popover_id="<?php esc_attr_e( $popover_id ); ?>">
<i class="fa fa-info-circle" aria-hidden="true"></i>
</button>
<?php
}
@@ -169,52 +169,52 @@ function renderExternalHelpIcon( $url ) {
<a class="btn btn-link" target="_blank" href="<?php echo esc_url( $url ); ?>">
<i class="fa fa-info-circle" aria-hidden="true"></i>
</a>
<?php
}
function purgeCache() {
if ( function_exists( 'w3tc_pgcache_flush' ) ) { // W3 Total Cache
w3tc_pgcache_flush();
} elseif ( function_exists( 'wp_cache_clean_cache' ) ) { // WP Super Cache
global $file_prefix, $supercachedir;
if ( empty( $supercachedir ) && function_exists( 'get_supercache_dir' ) ) {
$supercachedir = get_supercache_dir();
}
wp_cache_clean_cache( $file_prefix );
} elseif ( class_exists( 'WpeCommon' ) ) {
if ( method_exists( 'WpeCommon', 'purge_memcached' ) ) {
\WpeCommon::purge_memcached();
}
// if ( method_exists( 'WpeCommon', 'clear_maxcdn_cache' ) ) {
// \WpeCommon::clear_maxcdn_cache();
// }
if ( method_exists( 'WpeCommon', 'purge_varnish_cache' ) ) {
\WpeCommon::purge_varnish_cache();
}
} elseif ( method_exists( 'WpFastestCache', 'deleteCache' ) ) {
global $wp_fastest_cache;
if ( ! empty( $wp_fastest_cache ) ) {
$wp_fastest_cache->deleteCache();
}
} elseif ( function_exists( 'sg_cachepress_purge_cache' ) ) {
sg_cachepress_purge_cache();
}
}
function adminIncompatibleVersionNotice( $pluginName, $minVersion ) {
@@ -225,20 +225,20 @@ function adminIncompatibleVersionNotice( $pluginName, $minVersion ) {
least <?php esc_html_e( $pluginName ); ?> <?php echo $minVersion; ?>. Please, update to
latest version.</p>
</div>
<?php
}
function adminRenderNotices() {
if ( ! current_user_can( 'manage_pys' ) ) {
return;
}
/**
* Expiration notices
*/
$now = time();
$apiTokens = Facebook()->getOption('server_access_api_token');
if(Facebook()->enabled() && !$apiTokens)
@@ -259,7 +259,7 @@ function adminRenderNotices() {
adminIncompatibleVersionNotice( 'PixelYourSite Pinterest Add-On', PYS_FREE_PINTEREST_MIN_VERSION );
} elseif ( isPinterestActive() ) {
$expire_at = Pinterest()->getOption( 'license_expires' );
if ( $expire_at && $now > $expire_at ) {
adminRenderLicenseExpirationNotice( Pinterest() );
}
@@ -278,26 +278,26 @@ function adminRenderNotices() {
/**
* Pixel ID notices
*/
$facebook_pixel_id = Facebook()->getPixelIDs() ;
if ( Facebook()->enabled() && empty( $facebook_pixel_id ) ) {
$no_facebook_pixels = true;
} else {
$no_facebook_pixels = false;
}
$ga_tracking_id = GA()->getPixelIDs() ;
if ( GA()->enabled() && empty( $ga_tracking_id ) ) {
$no_ga_pixels = true;
} else {
$no_ga_pixels = false;
}
$pinterest_pixel_id = Pinterest()->getOption( 'pixel_id' );
$pinterest_license_status = Pinterest()->getOption( 'license_status' );
if ( isPinterestActive() && Pinterest()->enabled()
&& ! empty( $pinterest_license_status ) // license active or was active before
&& empty( $pinterest_pixel_id ) ) {
@@ -305,48 +305,48 @@ function adminRenderNotices() {
} else {
$no_pinterest_pixels = false;
}
if ( isPinterestActive() ) {
if ( $no_facebook_pixels && $no_ga_pixels && $no_pinterest_pixels ) {
adminRenderNoPixelsNotice();
} else {
if ( $no_facebook_pixels ) {
adminRenderNoPixelNotice( Facebook() );
}
if ( $no_ga_pixels ) {
adminRenderNoPixelNotice( GA() );
}
if ( $no_pinterest_pixels ) {
adminRenderNoPixelNotice( Pinterest() );
}
}
// show notice if licence was never activated
if (Pinterest()->enabled() && empty($pinterest_license_status)) {
adminRenderActivatePinterestLicence();
}
} else {
if ( $no_facebook_pixels && $no_ga_pixels ) {
adminRenderNoPixelsNotice();
} else {
if ( $no_facebook_pixels ) {
adminRenderNoPixelNotice( Facebook() );
}
if ( $no_ga_pixels ) {
adminRenderNoPixelNotice( GA() );
}
}
}
if ( isBingActive() ) {
@@ -359,7 +359,7 @@ function adminRenderNotices() {
}
}
/**
* GDPR
*/
@@ -372,33 +372,33 @@ function adminRenderNotices() {
* @param Plugin|Settings $plugin
*/
function adminRenderLicenseExpirationNotice( $plugin ) {
if ( 'pixelyoursite' == getCurrentAdminPage() ) {
return; // do not show notice on plugin pages
}
$slug = $plugin->getSlug();
$user_id = get_current_user_id();
// show only if never dismissed or dismissed more than a week ago
$meta_key = 'pys_' . $slug . '_expiration_notice_dismissed_at';
$dismissed_at = get_user_meta( $user_id, $meta_key );
if ( $dismissed_at ) {
if ( is_array( $dismissed_at ) ) {
$dismissed_at = reset( $dismissed_at );
}
$week_ago = time() - WEEK_IN_SECONDS;
if ( $week_ago < $dismissed_at ) {
return;
}
}
$license_key = $plugin->getOption( 'license_key' );
?>
<div class="notice notice-error is-dismissible pys_<?php esc_attr_e( $slug ); ?>_expiration_notice">
@@ -425,26 +425,26 @@ function adminRenderLicenseExpirationNotice( $plugin ) {
})
</script>
<?php
}
add_action( 'wp_ajax_pys_notice_dismiss', 'PixelYourSite\adminNoticeDismissHandler' );
function adminNoticeDismissHandler() {
if ( empty( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'pys_notice_dismiss' ) ) {
return;
}
if ( empty( $_REQUEST['user_id'] ) || empty( $_REQUEST['addon_slug'] ) || empty( $_REQUEST['meta_key'] ) ) {
return;
}
// save time when notice was dismissed
$meta_key = 'pys_' . sanitize_text_field( $_REQUEST['addon_slug'] ) . '_' . sanitize_text_field( $_REQUEST['meta_key'] ) . '_dismissed_at';
$userId = sanitize_text_field( $_REQUEST['user_id'] );
update_user_meta($userId, $meta_key, time() );
}
function adminRenderNotCAPI( $plugin ) {
@@ -556,20 +556,20 @@ function adminRenderActivateBingLicence() {
}
function adminRenderNoPixelsNotice() {
if ( 'pixelyoursite' == getCurrentAdminPage() ) {
return; // do not show notice on plugin pages
}
$user_id = get_current_user_id();
// do not show dismissed notice
$meta_key = 'pys_core_no_pixels_dismissed_at';
$dismissed_at = get_user_meta( $user_id, $meta_key );
if ( $dismissed_at ) {
return;
}
?>
<div class="notice notice-warning is-dismissible pys_core_no_pixels_notice">
@@ -594,7 +594,7 @@ function adminRenderNoPixelsNotice() {
})
</script>
<?php
}
@@ -602,21 +602,21 @@ function adminRenderNoPixelsNotice() {
* @param Plugin|Settings $plugin
*/
function adminRenderNoPixelNotice( $plugin ) {
if ( 'pixelyoursite' == getCurrentAdminPage() ) {
return; // do not show notice on plugin pages
}
$slug = $plugin->getSlug();
$user_id = get_current_user_id();
// do not show dismissed notice
$meta_key = 'pys_' . $slug . '_no_pixel_dismissed_at';
$dismissed_at = get_user_meta( $user_id, $meta_key );
if ( $dismissed_at ) {
return;
}
?>
<div class="notice notice-warning is-dismissible pys_<?php esc_attr_e( $slug ); ?>_no_pixel_notice">
@@ -624,7 +624,7 @@ function adminRenderNoPixelNotice( $plugin ) {
<p>Add your Meta Pixel (formerly Facebook Pixel) ID and start tracking everything with PixelYourSite. <a
href="<?php echo esc_url( buildAdminUrl( 'pixelyoursite' ) ); ?>">Click Here</a></p>
<?php elseif ( $slug == 'ga' && ( isWooCommerceActive() || isEddActive() ) ) : ?>
<p>Add your Google Analytics tracking ID inside PixelYourSite and start tracking everything. Enhanced
@@ -632,19 +632,19 @@ function adminRenderNoPixelNotice( $plugin ) {
href="<?php echo esc_url( buildAdminUrl( 'pixelyoursite' ) ); ?>">Click Here</a></p>
<p>(If you use another Google Analytics plugin, disable it in order to avoid conflicts)</p>
<?php elseif ( $slug == 'ga' && ! isWooCommerceActive() && ! isEddActive() ) : ?>
<p>Add your Google Analytics ID inside PixelYourSite and start tracking everything. <a
href="<?php echo esc_url( buildAdminUrl( 'pixelyoursite' ) ); ?>">Click Here</a></p>
<p>(If you use another Google Analytics plugin, disable it in order to avoid conflicts)</p>
<?php elseif ( $slug == 'pinterest' ) : ?>
<p>Add your Pinterest pixel ID and start tracking everything with PixelYourSite. <a
href="<?php echo esc_url( buildAdminUrl( 'pixelyoursite' ) ); ?>">Click Here</a></p>
<?php endif; ?>
</div>
@@ -664,7 +664,7 @@ function adminRenderNoPixelNotice( $plugin ) {
})
</script>
<?php
}
@@ -672,15 +672,22 @@ function renderDummyTextInput( $placeholder = '' ) {
?>
<input type="text" disabled="disabled" placeholder="<?php esc_html_e( $placeholder ); ?>" class="form-control">
<?php
}
function renderDummyTextAreaInput( $placeholder = '' ) {
?>
<textarea type="text" disabled="disabled" placeholder="<?php esc_html_e( $placeholder ); ?>" class="form-control">
</textarea>
<?php
}
function renderDummyNumberInput($default = 0) {
?>
<input type="number" disabled="disabled" min="0" max="100" class="form-control" value="<?=$default?>">
<?php
}
@@ -692,7 +699,7 @@ function renderDummySwitcher($isEnable = false) {
<input type="checkbox" value="1" <?=$attr?> disabled="disabled" class="custom-switch-input">
<label class="custom-switch-btn"></label>
</div>
<?php
}
@@ -710,7 +717,7 @@ function renderDummyCheckbox( $label, $with_pro_badge = false ) {
} ?>
</span>
</label>
<?php
}
@@ -723,7 +730,7 @@ function renderDummyRadioInput( $label, $checked = false ) {
<span class="custom-control-indicator"></span>
<span class="custom-control-description"><?php echo wp_kses_post( $label ); ?></span>
</label>
<?php
}
@@ -731,7 +738,7 @@ function renderDummyTagsFields( $tags = array() ) {
?>
<select class="form-control pys-tags-pysselect2" disabled="disabled" style="width: 100%;" multiple>
<?php foreach ( $tags as $tag ) : ?>
<option value="<?php echo esc_attr( $tag ); ?>" selected>
<?php echo esc_attr( $tag ); ?>
@@ -739,20 +746,20 @@ function renderDummyTagsFields( $tags = array() ) {
<?php endforeach; ?>
</select>
<?php
}
function renderDummySelectInput( $value, $full_width = false ) {
$attr_width = $full_width ? 'width: 100%;' : '';
?>
<select class="form-control form-control-sm" disabled="disabled" autocomplete="off" style="<?php esc_attr_e( $attr_width ); ?>">
<option value="" disabled selected><?php esc_html_e( $value ); ?></option>
</select>
<?php
}
@@ -778,13 +785,13 @@ function renderDummyGoogleAdsConversionLabelInputs() {
}
function renderProBadge( $url = null,$label = "Pro Feature" ) {
if ( ! $url ) {
$url = 'https://www.pixelyoursite.com/';
}
$url = untrailingslashit( $url ) . '/?utm_source=pys-free-plugin&utm_medium=pro-badge&utm_campaign=pro-feature';
echo '&nbsp;<a href="' . esc_url( $url ) . '" target="_blank" class="badge badge-pill badge-pro">'.$label.' <i class="fa fa-external-link" aria-hidden="true"></i></a>';
}
@@ -860,4 +867,4 @@ function addMetaTagFields($pixel,$url) { ?>
</script>
</div>
</div>
<?php }
<?php }