Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules
File: stats.php
<?php esc_html_e( 'Configure', 'jetpack' ); ?>
[500] Fix | Delete
</a>
[501] Fix | Delete
<?php
[502] Fix | Delete
endif;
[503] Fix | Delete
[504] Fix | Delete
?>
[505] Fix | Delete
</h2>
[506] Fix | Delete
</div>
[507] Fix | Delete
<div class="wrap">
[508] Fix | Delete
<div class="stats-odyssey-notice stats-odyssey-notice--content__highlighted">
[509] Fix | Delete
<div class="stats-odyssey-notice--content">
[510] Fix | Delete
<h2 class="stats-odyssey-notice--content-header"><?php esc_html_e( 'Deprecated Jetpack Stats Experience', 'jetpack' ); ?></h2>
[511] Fix | Delete
<p class="stats-odyssey-notice--content-text"><?php esc_html_e( 'The old Jetpack Stats has been deprecated. Please click the button to enable the new experience.', 'jetpack' ); ?></p>
[512] Fix | Delete
<div class="stats-odyssey-notice--action-bar">
[513] Fix | Delete
<button class="dops-button stats-odyssey-notice--primary-button">
[514] Fix | Delete
<a class="is-primary-link" href="<?php echo esc_url( $redirect_url ); ?>"><?php esc_html_e( 'Switch to new Stats', 'jetpack' ); ?></a>
[515] Fix | Delete
</button>
[516] Fix | Delete
<a class="is-secondary-link" href="<?php echo esc_url( $learn_url ); ?>" rel="noopener noreferrer" target="_blank"><?php esc_html_e( 'Learn about Stats', 'jetpack' ); ?> <svg xmlns="http://www.w3.org/2000/svg" style="vertical-align: middle;" viewBox="0 0 24 24" width="16" height="16" aria-hidden="true" focusable="false"><path d="M18.2 17c0 .7-.6 1.2-1.2 1.2H7c-.7 0-1.2-.6-1.2-1.2V7c0-.7.6-1.2 1.2-1.2h3.2V4.2H7C5.5 4.2 4.2 5.5 4.2 7v10c0 1.5 1.2 2.8 2.8 2.8h10c1.5 0 2.8-1.2 2.8-2.8v-3.6h-1.5V17zM14.9 3v1.5h3.7l-6.4 6.4 1.1 1.1 6.4-6.4v3.7h1.5V3h-6.3z"></path></svg></a>
[517] Fix | Delete
</div>
[518] Fix | Delete
</div>
[519] Fix | Delete
<div class="stats-odyssey-notice--image-container"></div>
[520] Fix | Delete
</div>
[521] Fix | Delete
</div>
[522] Fix | Delete
<p></p>
[523] Fix | Delete
</div>
[524] Fix | Delete
<?php
[525] Fix | Delete
return;
[526] Fix | Delete
}
[527] Fix | Delete
[528] Fix | Delete
$day = isset( $_GET['day'] ) && preg_match( '/^\d{4}-\d{2}-\d{2}$/', $_GET['day'] ) ? $_GET['day'] : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput
[529] Fix | Delete
$q = array(
[530] Fix | Delete
'noheader' => 'true',
[531] Fix | Delete
'proxy' => '',
[532] Fix | Delete
'page' => 'stats',
[533] Fix | Delete
'day' => $day,
[534] Fix | Delete
'blog' => $blog_id,
[535] Fix | Delete
'charset' => get_option( 'blog_charset' ),
[536] Fix | Delete
'color' => get_user_option( 'admin_color' ),
[537] Fix | Delete
'ssl' => is_ssl(),
[538] Fix | Delete
'j' => sprintf( '%s:%s', JETPACK__API_VERSION, JETPACK__VERSION ),
[539] Fix | Delete
);
[540] Fix | Delete
if ( get_locale() !== 'en_US' ) {
[541] Fix | Delete
$q['jp_lang'] = get_locale();
[542] Fix | Delete
}
[543] Fix | Delete
// Only show the main chart, without extra header data, or metaboxes.
[544] Fix | Delete
$q['main_chart_only'] = $main_chart_only;
[545] Fix | Delete
$args = array(
[546] Fix | Delete
'view' => array( 'referrers', 'postviews', 'searchterms', 'clicks', 'post', 'table' ),
[547] Fix | Delete
'numdays' => 'int',
[548] Fix | Delete
'day' => 'date',
[549] Fix | Delete
'unit' => array( '1', '7', '31', 'human' ),
[550] Fix | Delete
'humanize' => array( 'true' ),
[551] Fix | Delete
'num' => 'int',
[552] Fix | Delete
'summarize' => null,
[553] Fix | Delete
'post' => 'int',
[554] Fix | Delete
'width' => 'int',
[555] Fix | Delete
'height' => 'int',
[556] Fix | Delete
'data' => 'data',
[557] Fix | Delete
'blog_subscribers' => 'int',
[558] Fix | Delete
'comment_subscribers' => null,
[559] Fix | Delete
'type' => array( 'wpcom', 'email', 'pending' ),
[560] Fix | Delete
'pagenum' => 'int',
[561] Fix | Delete
'masterbar' => null,
[562] Fix | Delete
);
[563] Fix | Delete
foreach ( $args as $var => $vals ) {
[564] Fix | Delete
if ( ! isset( $_REQUEST[ $var ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
[565] Fix | Delete
continue;
[566] Fix | Delete
}
[567] Fix | Delete
$val = wp_unslash( $_REQUEST[ $var ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
[568] Fix | Delete
if ( is_array( $vals ) ) {
[569] Fix | Delete
if ( in_array( $val, $vals, true ) ) {
[570] Fix | Delete
$q[ $var ] = $val;
[571] Fix | Delete
}
[572] Fix | Delete
} elseif ( 'int' === $vals ) {
[573] Fix | Delete
$q[ $var ] = (int) $val;
[574] Fix | Delete
} elseif ( 'date' === $vals ) {
[575] Fix | Delete
if ( preg_match( '/^\d{4}-\d{2}-\d{2}$/', $val ) ) {
[576] Fix | Delete
$q[ $var ] = $val;
[577] Fix | Delete
}
[578] Fix | Delete
} elseif ( null === $vals ) {
[579] Fix | Delete
$q[ $var ] = '';
[580] Fix | Delete
} elseif ( 'data' === $vals ) {
[581] Fix | Delete
if ( str_starts_with( $val, 'index.php' ) ) {
[582] Fix | Delete
$q[ $var ] = $val;
[583] Fix | Delete
}
[584] Fix | Delete
}
[585] Fix | Delete
}
[586] Fix | Delete
[587] Fix | Delete
$url = 'https://' . STATS_DASHBOARD_SERVER . '/wp-admin/index.php';
[588] Fix | Delete
if ( isset( $_GET['chart'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
[589] Fix | Delete
if ( preg_match( '/^[a-z0-9-]+$/', $_GET['chart'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput
[590] Fix | Delete
$chart = sanitize_title( $_GET['chart'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput
[591] Fix | Delete
$url = 'https://' . STATS_DASHBOARD_SERVER . "/wp-includes/charts/{$chart}.php";
[592] Fix | Delete
}
[593] Fix | Delete
}
[594] Fix | Delete
[595] Fix | Delete
$url = add_query_arg( $q, $url );
[596] Fix | Delete
$method = 'GET';
[597] Fix | Delete
$timeout = 90;
[598] Fix | Delete
$user_id = 0; // Means use the blog token.
[599] Fix | Delete
[600] Fix | Delete
$get = Client::remote_request( compact( 'url', 'method', 'timeout', 'user_id' ) );
[601] Fix | Delete
$get_code = wp_remote_retrieve_response_code( $get );
[602] Fix | Delete
if ( is_wp_error( $get ) || $get_code === '' || ( 2 !== (int) ( $get_code / 100 ) && 304 !== $get_code ) || empty( $get['body'] ) ) {
[603] Fix | Delete
stats_print_wp_remote_error( $get, $url );
[604] Fix | Delete
} elseif ( ! empty( $get['headers']['content-type'] ) ) {
[605] Fix | Delete
$type = $get['headers']['content-type'];
[606] Fix | Delete
if ( str_starts_with( $type, 'image' ) ) {
[607] Fix | Delete
$img = $get['body'];
[608] Fix | Delete
header( 'Content-Type: ' . $type );
[609] Fix | Delete
header( 'Content-Length: ' . strlen( $img ) );
[610] Fix | Delete
echo $img; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[611] Fix | Delete
die( 0 );
[612] Fix | Delete
}
[613] Fix | Delete
}
[614] Fix | Delete
[615] Fix | Delete
if ( isset( $_GET['page'] ) && 'stats' === $_GET['page'] && ! isset( $_GET['chart'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
[616] Fix | Delete
$tracking = new Tracking();
[617] Fix | Delete
$tracking->record_user_event( 'wpa_page_view', array( 'path' => 'old_stats' ) );
[618] Fix | Delete
}
[619] Fix | Delete
[620] Fix | Delete
if ( isset( $_GET['noheader'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
[621] Fix | Delete
die( 0 );
[622] Fix | Delete
}
[623] Fix | Delete
}
[624] Fix | Delete
[625] Fix | Delete
/**
[626] Fix | Delete
* Stats Convert Image URLs.
[627] Fix | Delete
*
[628] Fix | Delete
* @access public
[629] Fix | Delete
* @param mixed $html HTML.
[630] Fix | Delete
* @return string
[631] Fix | Delete
*/
[632] Fix | Delete
function stats_convert_image_urls( $html ) {
[633] Fix | Delete
$url = set_url_scheme( 'https://' . STATS_DASHBOARD_SERVER );
[634] Fix | Delete
$html = preg_replace( '|(["\'])(/i/stats.+)\\1|', '$1' . $url . '$2$1', $html );
[635] Fix | Delete
return $html;
[636] Fix | Delete
}
[637] Fix | Delete
[638] Fix | Delete
/**
[639] Fix | Delete
* Callback for preg_replace_callback used in stats_convert_chart_urls()
[640] Fix | Delete
*
[641] Fix | Delete
* @since 5.6.0
[642] Fix | Delete
*
[643] Fix | Delete
* @param array $matches The matches resulting from the preg_replace_callback call.
[644] Fix | Delete
* @return string The admin url for the chart.
[645] Fix | Delete
*/
[646] Fix | Delete
function jetpack_stats_convert_chart_urls_callback( $matches ) {
[647] Fix | Delete
// If there is a query string, change the beginning '?' to a '&' so it fits into the middle of this query string.
[648] Fix | Delete
return 'admin.php?page=stats&noheader&chart=' . $matches[1] . str_replace( '?', '&', $matches[2] );
[649] Fix | Delete
}
[650] Fix | Delete
[651] Fix | Delete
/**
[652] Fix | Delete
* Stats Convert Chart URLs.
[653] Fix | Delete
*
[654] Fix | Delete
* @access public
[655] Fix | Delete
* @param mixed $html HTML.
[656] Fix | Delete
* @return string
[657] Fix | Delete
*/
[658] Fix | Delete
function stats_convert_chart_urls( $html ) {
[659] Fix | Delete
$html = preg_replace_callback(
[660] Fix | Delete
'|https?://[-.a-z0-9]+/wp-includes/charts/([-.a-z0-9]+).php(\??)|',
[661] Fix | Delete
'jetpack_stats_convert_chart_urls_callback',
[662] Fix | Delete
$html
[663] Fix | Delete
);
[664] Fix | Delete
return $html;
[665] Fix | Delete
}
[666] Fix | Delete
[667] Fix | Delete
/**
[668] Fix | Delete
* Stats Convert Post Title HTML
[669] Fix | Delete
*
[670] Fix | Delete
* @access public
[671] Fix | Delete
* @param mixed $html HTML.
[672] Fix | Delete
* @return string
[673] Fix | Delete
*/
[674] Fix | Delete
function stats_convert_post_titles( $html ) {
[675] Fix | Delete
global $stats_posts;
[676] Fix | Delete
$pattern = "<span class='post-(\d+)-link'>.*?</span>";
[677] Fix | Delete
if ( ! preg_match_all( "!$pattern!", $html, $matches ) ) {
[678] Fix | Delete
return $html;
[679] Fix | Delete
}
[680] Fix | Delete
$posts = get_posts(
[681] Fix | Delete
array(
[682] Fix | Delete
'include' => implode( ',', $matches[1] ),
[683] Fix | Delete
'post_type' => 'any',
[684] Fix | Delete
'post_status' => 'any',
[685] Fix | Delete
'numberposts' => -1,
[686] Fix | Delete
'suppress_filters' => false,
[687] Fix | Delete
)
[688] Fix | Delete
);
[689] Fix | Delete
foreach ( $posts as $post ) {
[690] Fix | Delete
$stats_posts[ $post->ID ] = $post;
[691] Fix | Delete
}
[692] Fix | Delete
$html = preg_replace_callback( "!$pattern!", 'stats_convert_post_title', $html );
[693] Fix | Delete
return $html;
[694] Fix | Delete
}
[695] Fix | Delete
[696] Fix | Delete
/**
[697] Fix | Delete
* Stats Convert Post Title Matches.
[698] Fix | Delete
*
[699] Fix | Delete
* @access public
[700] Fix | Delete
* @param mixed $matches Matches.
[701] Fix | Delete
* @return string
[702] Fix | Delete
*/
[703] Fix | Delete
function stats_convert_post_title( $matches ) {
[704] Fix | Delete
global $stats_posts;
[705] Fix | Delete
$post_id = $matches[1];
[706] Fix | Delete
if ( isset( $stats_posts[ $post_id ] ) ) {
[707] Fix | Delete
return '<a href="' . get_permalink( $post_id ) . '" target="_blank">' . get_the_title( $post_id ) . '</a>';
[708] Fix | Delete
}
[709] Fix | Delete
return $matches[0];
[710] Fix | Delete
}
[711] Fix | Delete
[712] Fix | Delete
/**
[713] Fix | Delete
* CSS to hide the tracking pixel smiley.
[714] Fix | Delete
* It is now hidden for everyone (used to be visible if you had set the hide_smile option).
[715] Fix | Delete
*
[716] Fix | Delete
* @access public
[717] Fix | Delete
* @return void
[718] Fix | Delete
*/
[719] Fix | Delete
function stats_hide_smile_css() {
[720] Fix | Delete
?>
[721] Fix | Delete
<style>img#wpstats{display:none}</style>
[722] Fix | Delete
<?php
[723] Fix | Delete
}
[724] Fix | Delete
[725] Fix | Delete
/**
[726] Fix | Delete
* Stats Admin Bar Head.
[727] Fix | Delete
*
[728] Fix | Delete
* @access public
[729] Fix | Delete
* @return void
[730] Fix | Delete
*/
[731] Fix | Delete
function stats_admin_bar_head() {
[732] Fix | Delete
// Let's not show the stats admin bar to users who are not logged in.
[733] Fix | Delete
if ( ! is_user_logged_in() ) {
[734] Fix | Delete
return;
[735] Fix | Delete
}
[736] Fix | Delete
[737] Fix | Delete
if ( ! Stats_Options::get_option( 'admin_bar' ) ) {
[738] Fix | Delete
return;
[739] Fix | Delete
}
[740] Fix | Delete
[741] Fix | Delete
if ( ! current_user_can( 'view_stats' ) ) {
[742] Fix | Delete
return;
[743] Fix | Delete
}
[744] Fix | Delete
[745] Fix | Delete
if ( ! is_admin_bar_showing() ) {
[746] Fix | Delete
return;
[747] Fix | Delete
}
[748] Fix | Delete
[749] Fix | Delete
add_action( 'admin_bar_menu', 'stats_admin_bar_menu', 100 );
[750] Fix | Delete
?>
[751] Fix | Delete
[752] Fix | Delete
<style data-ampdevmode type='text/css'>
[753] Fix | Delete
#wpadminbar .quicklinks li#wp-admin-bar-stats {
[754] Fix | Delete
height: 32px;
[755] Fix | Delete
}
[756] Fix | Delete
#wpadminbar .quicklinks li#wp-admin-bar-stats a {
[757] Fix | Delete
height: 32px;
[758] Fix | Delete
padding: 0;
[759] Fix | Delete
}
[760] Fix | Delete
#wpadminbar .quicklinks li#wp-admin-bar-stats a div {
[761] Fix | Delete
height: 32px;
[762] Fix | Delete
width: 95px;
[763] Fix | Delete
overflow: hidden;
[764] Fix | Delete
margin: 0 10px;
[765] Fix | Delete
}
[766] Fix | Delete
#wpadminbar .quicklinks li#wp-admin-bar-stats a:hover div {
[767] Fix | Delete
width: auto;
[768] Fix | Delete
margin: 0 8px 0 10px;
[769] Fix | Delete
}
[770] Fix | Delete
#wpadminbar .quicklinks li#wp-admin-bar-stats a img {
[771] Fix | Delete
height: 24px;
[772] Fix | Delete
margin: 4px 0;
[773] Fix | Delete
max-width: none;
[774] Fix | Delete
border: none;
[775] Fix | Delete
}
[776] Fix | Delete
</style>
[777] Fix | Delete
<?php
[778] Fix | Delete
}
[779] Fix | Delete
[780] Fix | Delete
/**
[781] Fix | Delete
* Gets the image source of the given stats chart.
[782] Fix | Delete
*
[783] Fix | Delete
* @param string $chart Name of the chart.
[784] Fix | Delete
* @param array $args Extra list of argument to use in the image source.
[785] Fix | Delete
* @return string An image source.
[786] Fix | Delete
*/
[787] Fix | Delete
function stats_get_image_chart_src( $chart, $args = array() ) {
[788] Fix | Delete
$url = add_query_arg( 'page', 'stats', admin_url( 'admin.php' ) );
[789] Fix | Delete
[790] Fix | Delete
return add_query_arg(
[791] Fix | Delete
array_merge(
[792] Fix | Delete
array(
[793] Fix | Delete
'noheader' => '',
[794] Fix | Delete
'proxy' => '',
[795] Fix | Delete
'chart' => $chart,
[796] Fix | Delete
),
[797] Fix | Delete
$args
[798] Fix | Delete
),
[799] Fix | Delete
$url
[800] Fix | Delete
);
[801] Fix | Delete
}
[802] Fix | Delete
[803] Fix | Delete
/**
[804] Fix | Delete
* Stats AdminBar.
[805] Fix | Delete
*
[806] Fix | Delete
* @access public
[807] Fix | Delete
* @param mixed $wp_admin_bar WPAdminBar.
[808] Fix | Delete
* @return void
[809] Fix | Delete
*/
[810] Fix | Delete
function stats_admin_bar_menu( &$wp_admin_bar ) {
[811] Fix | Delete
$img_src = esc_attr( stats_get_image_chart_src( 'admin-bar-hours-scale' ) );
[812] Fix | Delete
$img_src_2x = esc_attr( stats_get_image_chart_src( 'admin-bar-hours-scale-2x' ) );
[813] Fix | Delete
$alt = esc_attr( __( 'Stats', 'jetpack' ) );
[814] Fix | Delete
$title = esc_attr( __( 'Views over 48 hours. Click for more Jetpack Stats.', 'jetpack' ) );
[815] Fix | Delete
[816] Fix | Delete
$menu = array(
[817] Fix | Delete
'id' => 'stats',
[818] Fix | Delete
'href' => add_query_arg( 'page', 'stats', admin_url( 'admin.php' ) ), // no menu_page_url() blog-side.
[819] Fix | Delete
'title' => "<div><img fetchpriority='low' loading='lazy' decoding='async' src='$img_src' srcset='$img_src 1x, $img_src_2x 2x' width='112' height='24' alt='$alt' title='$title'></div>",
[820] Fix | Delete
);
[821] Fix | Delete
[822] Fix | Delete
$wp_admin_bar->add_menu( $menu );
[823] Fix | Delete
}
[824] Fix | Delete
[825] Fix | Delete
/**
[826] Fix | Delete
* Stats Get Blog.
[827] Fix | Delete
*
[828] Fix | Delete
* @deprecated 11.5
[829] Fix | Delete
*
[830] Fix | Delete
* @access public
[831] Fix | Delete
* @return string
[832] Fix | Delete
*/
[833] Fix | Delete
function stats_get_blog() {
[834] Fix | Delete
_deprecated_function( __METHOD__, 'jetpack-11.5' );
[835] Fix | Delete
return Stats_XMLRPC::init()->get_blog();
[836] Fix | Delete
}
[837] Fix | Delete
[838] Fix | Delete
/**
[839] Fix | Delete
* Stats Dashboard Widget Options.
[840] Fix | Delete
*
[841] Fix | Delete
* TODO: This should be moved into class-jetpack-stats-dashboard-widget.php.
[842] Fix | Delete
*
[843] Fix | Delete
* @access public
[844] Fix | Delete
* @return array
[845] Fix | Delete
*/
[846] Fix | Delete
function stats_dashboard_widget_options() {
[847] Fix | Delete
$defaults = array(
[848] Fix | Delete
'chart' => 1,
[849] Fix | Delete
'top' => 1,
[850] Fix | Delete
'search' => 7,
[851] Fix | Delete
);
[852] Fix | Delete
$options = get_option( 'stats_dashboard_widget' );
[853] Fix | Delete
if ( ( ! $options ) || ! is_array( $options ) ) {
[854] Fix | Delete
$options = array();
[855] Fix | Delete
}
[856] Fix | Delete
[857] Fix | Delete
// Ignore obsolete option values.
[858] Fix | Delete
$intervals = array( 1, 7, 31, 90, 365 );
[859] Fix | Delete
foreach ( array( 'top', 'search' ) as $key ) {
[860] Fix | Delete
if ( isset( $options[ $key ] ) && ! in_array( (int) $options[ $key ], $intervals, true ) ) {
[861] Fix | Delete
unset( $options[ $key ] );
[862] Fix | Delete
}
[863] Fix | Delete
}
[864] Fix | Delete
[865] Fix | Delete
return array_merge( $defaults, $options );
[866] Fix | Delete
}
[867] Fix | Delete
[868] Fix | Delete
/**
[869] Fix | Delete
* Stats Dashboard Widget Control.
[870] Fix | Delete
*
[871] Fix | Delete
* TODO: This should be moved into class-jetpack-stats-dashboard-widget.php.
[872] Fix | Delete
*
[873] Fix | Delete
* @access public
[874] Fix | Delete
* @return void
[875] Fix | Delete
*/
[876] Fix | Delete
function stats_dashboard_widget_control() {
[877] Fix | Delete
stats_dashboard_widget_controls_handle_submission();
[878] Fix | Delete
$periods = array(
[879] Fix | Delete
'1' => __( 'day', 'jetpack' ),
[880] Fix | Delete
'7' => __( 'week', 'jetpack' ),
[881] Fix | Delete
'31' => __( 'month', 'jetpack' ),
[882] Fix | Delete
);
[883] Fix | Delete
$intervals = array(
[884] Fix | Delete
'1' => __( 'the past day', 'jetpack' ),
[885] Fix | Delete
'7' => __( 'the past week', 'jetpack' ),
[886] Fix | Delete
'31' => __( 'the past month', 'jetpack' ),
[887] Fix | Delete
'90' => __( 'the past quarter', 'jetpack' ),
[888] Fix | Delete
'365' => __( 'the past year', 'jetpack' ),
[889] Fix | Delete
);
[890] Fix | Delete
stats_dashboard_widget_controls_html( $intervals, $periods, stats_dashboard_widget_options() );
[891] Fix | Delete
}
[892] Fix | Delete
[893] Fix | Delete
/**
[894] Fix | Delete
* Handle widget controls form submission.
[895] Fix | Delete
*
[896] Fix | Delete
* TODO: This should be moved into class-jetpack-stats-dashboard-widget.php.
[897] Fix | Delete
*
[898] Fix | Delete
* @access public
[899] Fix | Delete
* @return void
[900] Fix | Delete
*/
[901] Fix | Delete
function stats_dashboard_widget_controls_handle_submission() {
[902] Fix | Delete
$options = stats_dashboard_widget_options();
[903] Fix | Delete
$defaults = array(
[904] Fix | Delete
'top' => 1,
[905] Fix | Delete
'search' => 7,
[906] Fix | Delete
);
[907] Fix | Delete
[908] Fix | Delete
// Check if the correct form was submitted.
[909] Fix | Delete
if ( isset( $_POST['stats_id'] ) && 'dashboard_stats' === $_POST['stats_id'] ) {
[910] Fix | Delete
// Perform nonce verification.
[911] Fix | Delete
if (
[912] Fix | Delete
isset( $_POST['dashboard-widget-nonce'] ) &&
[913] Fix | Delete
wp_verify_nonce( filter_var( wp_unslash( $_POST['dashboard-widget-nonce'] ) ), 'edit-dashboard-widget_dashboard_stats' )
[914] Fix | Delete
) {
[915] Fix | Delete
// Update options.
[916] Fix | Delete
$options['chart'] = isset( $_POST['chart'] ) ? (int) $_POST['chart'] : 1;
[917] Fix | Delete
foreach ( array( 'top', 'search' ) as $key ) {
[918] Fix | Delete
$options[ $key ] = isset( $_POST[ $key ] ) ? (int) $_POST[ $key ] : $defaults[ $key ];
[919] Fix | Delete
}
[920] Fix | Delete
update_option( 'stats_dashboard_widget', $options );
[921] Fix | Delete
}
[922] Fix | Delete
}
[923] Fix | Delete
}
[924] Fix | Delete
[925] Fix | Delete
/**
[926] Fix | Delete
* Output HTML for widget controls.
[927] Fix | Delete
*
[928] Fix | Delete
* @param array $intervals Array of intervals.
[929] Fix | Delete
* @param array $periods Array of periods.
[930] Fix | Delete
* @param array $options Array of options.
[931] Fix | Delete
*
[932] Fix | Delete
* TODO: This should be moved into class-jetpack-stats-dashboard-widget.php.
[933] Fix | Delete
*
[934] Fix | Delete
* @access public
[935] Fix | Delete
* @return void
[936] Fix | Delete
*/
[937] Fix | Delete
function stats_dashboard_widget_controls_html( $intervals, $periods, $options ) {
[938] Fix | Delete
?>
[939] Fix | Delete
<p>
[940] Fix | Delete
<label for="chart"><?php esc_html_e( 'Chart stats by', 'jetpack' ); ?></label>
[941] Fix | Delete
<select id="chart" name="chart">
[942] Fix | Delete
<?php
[943] Fix | Delete
foreach ( $periods as $val => $label ) {
[944] Fix | Delete
?>
[945] Fix | Delete
<option value="<?php echo esc_attr( $val ); ?>"<?php selected( $val, $options['chart'] ); ?>><?php echo esc_html( $label ); ?></option>
[946] Fix | Delete
<?php
[947] Fix | Delete
}
[948] Fix | Delete
?>
[949] Fix | Delete
</select>.
[950] Fix | Delete
</p>
[951] Fix | Delete
[952] Fix | Delete
<p>
[953] Fix | Delete
<label for="top"><?php esc_html_e( 'Show top posts over', 'jetpack' ); ?></label>
[954] Fix | Delete
<select id="top" name="top">
[955] Fix | Delete
<?php
[956] Fix | Delete
foreach ( $intervals as $val => $label ) {
[957] Fix | Delete
?>
[958] Fix | Delete
<option value="<?php echo esc_attr( $val ); ?>"<?php selected( $val, $options['top'] ); ?>><?php echo esc_html( $label ); ?></option>
[959] Fix | Delete
<?php
[960] Fix | Delete
}
[961] Fix | Delete
?>
[962] Fix | Delete
</select>.
[963] Fix | Delete
</p>
[964] Fix | Delete
[965] Fix | Delete
<p>
[966] Fix | Delete
<label for="search"><?php esc_html_e( 'Show top search terms over', 'jetpack' ); ?></label>
[967] Fix | Delete
<select id="search" name="search">
[968] Fix | Delete
<?php
[969] Fix | Delete
foreach ( $intervals as $val => $label ) {
[970] Fix | Delete
?>
[971] Fix | Delete
<option value="<?php echo esc_attr( $val ); ?>"<?php selected( $val, $options['search'] ); ?>><?php echo esc_html( $label ); ?></option>
[972] Fix | Delete
<?php
[973] Fix | Delete
}
[974] Fix | Delete
?>
[975] Fix | Delete
</select>.
[976] Fix | Delete
</p>
[977] Fix | Delete
<?php
[978] Fix | Delete
}
[979] Fix | Delete
[980] Fix | Delete
/**
[981] Fix | Delete
* Jetpack Stats Dashboard Widget.
[982] Fix | Delete
*
[983] Fix | Delete
* TODO: This should be moved into class-jetpack-stats-dashboard-widget.php.
[984] Fix | Delete
*
[985] Fix | Delete
* @access public
[986] Fix | Delete
* @return void
[987] Fix | Delete
*/
[988] Fix | Delete
function stats_jetpack_dashboard_widget() {
[989] Fix | Delete
?>
[990] Fix | Delete
<form id="stats_dashboard_widget_control" action="<?php echo esc_url( admin_url() ); ?>" method="post">
[991] Fix | Delete
<?php stats_dashboard_widget_control(); ?>
[992] Fix | Delete
<?php wp_nonce_field( 'edit-dashboard-widget_dashboard_stats', 'dashboard-widget-nonce' ); ?>
[993] Fix | Delete
<input type="hidden" name="stats_id" value="dashboard_stats" />
[994] Fix | Delete
<?php submit_button( __( 'Submit', 'jetpack' ) ); ?>
[995] Fix | Delete
</form>
[996] Fix | Delete
<button type="button" class="handlediv js-toggle-stats_dashboard_widget_control" aria-expanded="true">
[997] Fix | Delete
<span class="screen-reader-text"><?php esc_html_e( 'Configure', 'jetpack' ); ?></span>
[998] Fix | Delete
<span class="toggle-indicator" aria-hidden="true"></span>
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function