updated plugin Connect Matomo version 1.1.5

This commit is contained in:
2026-06-03 21:28:54 +00:00
committed by Gitium
parent 6e8ffa6f66
commit 1f3438440f
78 changed files with 13800 additions and 5314 deletions

View File

@ -1,63 +1,74 @@
<?php
namespace WP_Piwik\Template;
namespace WP_Piwik\Template;
class MetaBoxCustomVars extends \WP_Piwik\Template {
public function addMetabox() {
add_meta_box(
'wp-piwik_post_customvars',
__('Piwik Custom Variables', 'wp-piwik'),
array(&$this, 'showCustomvars'),
array('post', 'page', 'custom_post_type'),
'side',
'default'
);
}
class MetaBoxCustomVars extends \WP_Piwik\Template {
public function showCustomvars($objPost, $objBox ) {
wp_nonce_field(basename( __FILE__ ), 'wp-piwik_post_customvars_nonce'); ?>
public function addMetabox() {
add_meta_box(
'wp-piwik_post_customvars',
__( 'Piwik Custom Variables', 'wp-piwik' ),
array( &$this, 'showCustomvars' ),
array( 'post', 'page', 'custom_post_type' ),
'side',
'default'
);
}
public function showCustomvars( $obj_post, $obj_box ) {
wp_nonce_field( basename( __FILE__ ), 'wp-piwik_post_customvars_nonce' ); ?>
<table>
<tr><th></th><th><?php _e('Name', 'wp-piwik'); ?></th><th><?php _e('Value', 'wp-piwik'); ?></th></tr>
<?php for($i = 1; $i <= 5; $i++) { ?>
<tr>
<th><label for="wp-piwik_customvar1"><?php echo $i; ?>: </label></th>
<td><input class="widefat" type="text" name="wp-piwik_custom_cat<?php echo $i; ?>" value="<?php echo esc_attr(get_post_meta($objPost->ID, 'wp-piwik_custom_cat'.$i, true ) ); ?>" size="200" /></td>
<td><input class="widefat" type="text" name="wp-piwik_custom_val<?php echo $i; ?>" value="<?php echo esc_attr(get_post_meta($objPost->ID, 'wp-piwik_custom_val'.$i, true ) ); ?>" size="200" /></td>
</tr>
<?php } ?>
</table>
<p><?php _e('Set custom variables for a page view', 'wp-piwik'); ?>. (<a href="http://piwik.org/docs/custom-variables/"><?php _e('More information', 'wp-piwik'); ?></a>.)</p>
<?php
<tr><th></th><th><?php esc_html_e( 'Name', 'wp-piwik' ); ?></th><th><?php esc_html_e( 'Value', 'wp-piwik' ); ?></th></tr>
<?php for ( $i = 1; $i <= 5; $i++ ) { ?>
<tr>
<th><label for="wp-piwik_customvar1"><?php echo esc_attr( $i ); // @phpstan-ignore-line ?>: </label></th>
<td><input class="widefat" type="text" name="wp-piwik_custom_cat<?php echo esc_attr( $i ); // @phpstan-ignore-line ?>" value="<?php echo esc_attr( get_post_meta( $obj_post->ID, 'wp-piwik_custom_cat' . $i, true ) ); ?>" size="200" /></td>
<td><input class="widefat" type="text" name="wp-piwik_custom_val<?php echo esc_attr( $i ); // @phpstan-ignore-line ?>" value="<?php echo esc_attr( get_post_meta( $obj_post->ID, 'wp-piwik_custom_val' . $i, true ) ); ?>" size="200" /></td>
</tr>
<?php } ?>
</table>
<p><?php esc_html_e( 'Set custom variables for a page view', 'wp-piwik' ); ?>. (<a href="http://piwik.org/docs/custom-variables/"><?php esc_html_e( 'More information', 'wp-piwik' ); ?></a>.)</p>
<?php
}
public function saveCustomVars( $int_id, $obj_post ) {
// Verify the nonce before proceeding.
$nonce = isset( $_POST['wp-piwik_post_customvars_nonce'] )
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
? wp_unslash( $_POST['wp-piwik_post_customvars_nonce'] )
: '';
if (
empty( $nonce )
|| ! wp_verify_nonce( $nonce, basename( __FILE__ ) )
) {
return $int_id;
}
public function saveCustomVars($intID, $objPost) {
// Verify the nonce before proceeding.
if (!isset( $_POST['wp-piwik_post_customvars_nonce'] ) || !wp_verify_nonce( $_POST['wp-piwik_post_customvars_nonce'], basename( __FILE__ ) ) )
return $intID;
// Get post type object
$objPostType = get_post_type_object($objPost->post_type);
// Check if the current user has permission to edit the post.
if (!current_user_can($objPostType->cap->edit_post, $intID))
return $intID;
$aryNames = array('cat', 'val');
for ($i = 1; $i <= 5; $i++)
for ($j = 0; $j <= 1; $j++) {
// Get data
$strMetaVal = (isset($_POST['wp-piwik_custom_'.$aryNames[$j].$i])?htmlentities($_POST['wp-piwik_custom_'.$aryNames[$j].$i]):'');
// Create key
$strMetaKey = 'wp-piwik_custom_'.$aryNames[$j].$i;
// Get the meta value of the custom field key
$strCurVal = get_post_meta($intID, $strMetaKey, true);
// Get post type object
$obj_post_type = get_post_type_object( $obj_post->post_type );
// Check if the current user has permission to edit the post.
if ( ! current_user_can( $obj_post_type->cap->edit_post, $int_id ) ) {
return $int_id;
}
$ary_names = array( 'cat', 'val' );
for ( $i = 1; $i <= 5; $i++ ) {
for ( $j = 0; $j <= 1; $j++ ) {
// Create key
$str_meta_key = 'wp-piwik_custom_' . $ary_names[ $j ] . $i;
// Get data
$str_meta_val = isset( $_POST[ $str_meta_key ] ) ? esc_html( $str_meta_key ) : '';
// Get the meta value of the custom field key
$str_cur_val = get_post_meta( $int_id, $str_meta_key, true );
if ( $str_meta_val && '' === $str_cur_val ) {
// Add meta val:
if ($strMetaVal && '' == $strCurVal)
add_post_meta($intID, $strMetaKey, $strMetaVal, true);
add_post_meta( $int_id, $str_meta_key, $str_meta_val, true );
} elseif ( $str_meta_val && $str_meta_val !== $str_cur_val ) {
// Update meta val:
elseif ($strMetaVal && $strMetaVal != $strCurVal)
update_post_meta($intID, $strMetaKey, $strMetaVal);
update_post_meta( $int_id, $str_meta_key, $str_meta_val );
} elseif ( '' === $str_meta_val && $str_cur_val ) {
// Delete meta val:
elseif (''==$strMetaVal && $strCurVal)
delete_post_meta($intID, $strMetaKey, $strCurVal);
delete_post_meta( $int_id, $str_meta_key, $str_cur_val );
}
}
}
}
}
}
}