Skip to content

Commit

Permalink
Merge branch 'release/1.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ClassyBot committed Jul 13, 2023
2 parents 1ed2982 + a8105c2 commit fe6a548
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 151 deletions.
3 changes: 0 additions & 3 deletions wp-admin/includes/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,6 @@ function wp_ajax_dashboard_widgets() {
case 'dashboard_primary':
wp_dashboard_primary();
break;
case 'dashboard_petitions':
cp_dashboard_petitions();
break;
}
wp_die();
}
Expand Down
2 changes: 1 addition & 1 deletion wp-admin/includes/class-wp-posts-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ public function inline_edit() {

<label>
<span class="title"><?php _e( 'Slug' ); ?></span>
<span class="input-text-wrap"><input type="text" name="post_name" value="" /></span>
<span class="input-text-wrap"><input type="text" name="post_name" value="" autocomplete="off" spellcheck="false" /></span>
</label>

<?php endif; // $bulk ?>
Expand Down
157 changes: 24 additions & 133 deletions wp-admin/includes/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ function wp_dashboard_setup() {
// ClassicPress News
wp_add_dashboard_widget( 'dashboard_primary', __( 'ClassicPress News' ), 'wp_dashboard_events_news' );

// ClassicPress Petitions
wp_add_dashboard_widget( 'dashboard_petitions', __( 'ClassicPress Petitions' ), 'cp_dashboard_petitions' );
// ClassicPress upgrade notice
if ( current_user_can( 'update_core' ) ) {
wp_add_dashboard_widget( 'dashboard_upgrade', __( 'ClassicPress Upgrade' ), 'cp_dashboard_upgrade' );
}

if ( is_network_admin() ) {

Expand Down Expand Up @@ -1442,147 +1444,36 @@ function wp_welcome_panel() {
}

/**
* Callback function for the petitions dashboard widget
*
* @since 1.0.0
*/
function cp_dashboard_petitions() {
$feeds = array(
'trending' => array(
'title' => __( 'Trending' ),
),
'most-wanted' => array(
'title' => __( 'Most Wanted' ),
),
'recent' => array(
'title' => __( 'Recent' ),
),
);

wp_dashboard_cached_rss_widget( 'dashboard_petitions', 'cp_dashboard_petitions_output', $feeds );
}

/**
* Display the ClassicPress petitions feeds.
*
* Query the ClassicPress.net API for data about ClassicPress petitions, and
* echo the results as HTML.
*
* @since 1.0.0
* Display the ClassicPress upgrade widget
* Warns about PHP support ending and will prompt for upgrade once available
*
* @param string $widget_id Widget ID.
* @param array $feeds Array of petition feeds (possible sort orders).
* @since CP-1.6.0
*/
function cp_dashboard_petitions_output( $widget_id, $feeds ) {
$api_url = 'https://api-v1.classicpress.net/features/1.0/';

/**
* Response body should be an object with:
* 'link' - string - Link to the ClassicPress petitions website.
* 'most-wanted' - object - Petitions sorted by number of votes.
* 'trending' - object - Petitions sorted by activity and votes.
* 'recent' - object - Petitions sorted by date created.
* Each of these 'object' keys should have a 'data' property which is an
* array of the top petitions sorted in the order represented by the key.
*/
$response = wp_remote_get( $api_url );
$response_code = wp_remote_retrieve_response_code( $response );

if ( ! is_wp_error( $response ) && 200 !== $response_code ) {
$response = new WP_Error(
'api-error',
/* translators: %d: numeric HTTP status code, e.g. 400, 403, 500, 504, etc. */
sprintf( __( 'Invalid API response code (%d)' ), $response_code )
);
}

if ( ! is_wp_error( $response ) ) {
$response = json_decode( wp_remote_retrieve_body( $response ) );
if ( empty( $response ) || ! is_object( $response ) || ! isset( $response->link ) ) {
$response = new WP_Error(
'api-error',
__( 'Invalid API response (invalid JSON)' )
);
}
}

if ( is_wp_error( $response ) ) {
if ( is_admin() || current_user_can( 'manage_options' ) ) {
echo '<p><strong>' . __( 'Error:' ) . '</strong> ' . $response->get_error_message() . '</p>';
}
return;
}

function cp_dashboard_upgrade() {
$display_version = classicpress_version();
?>
<div class="sub">
<a href="<?php echo esc_url( $response->link ); ?>" target="_blank" class="cp_petitions_link"><?php esc_html_e( 'Your voice counts, create and vote on petitions.' ); ?><span class="screen-reader-text"><?php esc_html_e( '(opens in a new window)' ); ?></span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>
</div>

<ul class="petitions-tabs">

<?php
$keys = array_keys( $feeds );
$active = array_shift( $keys );

foreach ( $feeds as $name => $args ) {
$class = $name === $active ? ' class="active"' : '';
?>
<li<?php echo $class; ?>><a href="#<?php echo esc_attr( $name ); ?>"><?php echo esc_html( $args['title'] ); ?></a></li>
<?php
}
?>

</ul>

<div class="petitions-content">

<div class ="upgrade-widget-content">
<p>
<?php
foreach ( $feeds as $name => $args ) {
echo '<p>' . sprintf( __( 'Thank you for using ClassicPress %s!' ), $display_version ) . '</p>';
echo '<p>' . __( 'We wanted to let you know some important information about ClassicPress.' ) . '</p>';
echo '<p>' . __( 'The major version number (1.x) you are currently using is not being actively developed. Instead we are working hard to bring you a brand new version 2.0.0.' ) . '</p>';
echo '<p>' . sprintf( __( 'Your current version will continue to receive security updates until %s' ), esc_html( date_i18n( get_option( 'date_format' ), 1700956800 ) ) ) . '</p>';
echo '<p>' . sprintf( __( 'This date has been chosen because it is when <a href="%s">support</a> for PHP 8.0 ends. PHP 7.4 is already unsupported and no longer receives security updates.' ), esc_url( 'https://www.php.net/supported-versions.php' ) ) . '</p>';

if ( empty( $response->$name ) ) {
continue;
}
$core_updates = get_core_updates( array( 'dismissed' => true ) );

$data = $response->$name->data;
$class = $name === $active ? 'petitions-pane active' : 'petitions-pane';
$active = $name === array_shift( $keys ) ? ' active' : '';
?>

<div id="<?php echo esc_attr( $name ); ?>" class="<?php echo esc_attr( $class ); ?>">
<table class="cp_petitions">
<thead>
<tr>
<td><?php esc_html_e( 'Votes' ); ?></td>
<td><?php esc_html_e( 'Petitions' ); ?></td>
</tr>
</thead>
if ( ! empty( $core_updates ) && version_compare( $core_updates[0]->current, '2.0.0' ) >= 0 ) {
echo '<p>' . sprintf( __( 'Version 2.0.0 has now been released. <a href="%s">Upgrade</a> as soon as you are ready and read more about the release on our <a href="%s">forum</a>.' ), esc_url( admin_url( 'update-core.php' ) ), esc_url( 'https://forums.classicpress.net/c/announcements/release-notes/48' ) ) . '</p>';
} else {
echo '<p>' . sprintf( __( 'You can continue to use ClassicPress %s at this time. You will be notified when a new version is available that supports future versions of PHP. <a href="%s">Learn more</a> about testing version 2.0.0.' ), $display_version, esc_url( 'https://www.classicpress.net/help-test-classicpress-v2/' ) ) . '</p>';
}

<?php
foreach ( $data as $petition ) {
?>
<tr>
<td class="votes-count"><?php echo esc_html( $petition->votesCount ); ?></td>

<td class="petition">
<a target="_blank" href="<?php echo esc_url( $petition->link ); ?>"><?php echo esc_html( $petition->title ); ?><span class="screen-reader-text"><?php esc_html_e( '(opens in a new window)' ); ?></span></a>
<?php
if ( 'open' === $petition->status ) {
echo esc_html__( ' - ' ) . ' ' . sprintf( __( '%s ago' ), human_time_diff( strtotime( $petition->createdAt ), current_time( 'timestamp' ) ) );
} else {
echo ' - ' . '<span class="' . esc_attr( $petition->status ) . '">' . esc_html( $petition->status ) . '</span>';
}
?>
</td>
</tr>
<?php
}
?>
</table>
echo '<p>' . __( 'Deprecation notice: Version 1.6 is the last version to support PHP 5.6 - 7.3. The minimum required version for 2.0.0 will be PHP 7.4.' ) . '</p>';

</div>
<?php
}
?>
</p>
</div>
<?php
}
16 changes: 16 additions & 0 deletions wp-admin/includes/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,19 @@ function sort_menu( $a, $b ) {
}

$menu = add_menu_classes( $menu );

/**
* Remove the ClassicPress Security Page Menu when it is not used.
*
* The page itself is still accessible if calling the direct URL, or,
* if a plugin uses add_security_page()
*
* The way we unhook the menu is by checking if the $submenu global holds the key `security.php`,
* which is only the case if a plugin added another submenu with `add_security_page` on the `admin_menu` hook.
* Note that plugins COULD also add said menu on `init`, but that is `doing_it_wrong` and will actually produce an erroneus menu sequence, even if it "works"
*
* @since CP-1.6.0
*/
if ( ! isset( $submenu['security.php'] ) ) {
unset( $menu[85] );
}
4 changes: 3 additions & 1 deletion wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,11 @@ function maybe_unserialize( $original ) {
/**
* Check value to find if it was serialized.
*
* If $data is not an string, then returned value will always be false.
* If $data is not a string, then returned value will always be false.
* Serialized data is always a string.
*
* @since WP-2.0.5
* @since WP-6.1.0 Added Enum support.
*
* @param string $data Value to check to see if was serialized.
* @param bool $strict Optional. Whether to be strict about the end of the string. Default true.
Expand Down Expand Up @@ -468,6 +469,7 @@ function is_serialized( $data, $strict = true ) {
// or else fall through
case 'a':
case 'O':
case 'E':
return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data );
case 'b':
case 'i':
Expand Down
20 changes: 10 additions & 10 deletions wp-includes/link-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ function permalink_anchor( $mode = 'id' ) {
*
* @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`.
* @param bool $leavename Optional. Whether to keep post name or page name. Default false.
*
* @return string|false The permalink URL or false if post does not exist.
* @return string|false The permalink URL. False if the post does not exist.
*/
function get_the_permalink( $post = 0, $leavename = false ) {
return get_permalink( $post, $leavename );
Expand All @@ -114,7 +113,7 @@ function get_the_permalink( $post = 0, $leavename = false ) {
*
* @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`.
* @param bool $leavename Optional. Whether to keep post name or page name. Default false.
* @return string|false The permalink URL or false if post does not exist.
* @return string|false The permalink URL. False if the post does not exist.
*/
function get_permalink( $post = 0, $leavename = false ) {
$rewritecode = array(
Expand Down Expand Up @@ -251,21 +250,22 @@ function get_permalink( $post = 0, $leavename = false ) {
* Retrieves the permalink for a post of a custom post type.
*
* @since WP-3.0.0
* @since WP-6.1.0 Returns false if the post does not exist.
*
* @global WP_Rewrite $wp_rewrite
*
* @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`.
* @param bool $leavename Optional, defaults to false. Whether to keep post name. Default false.
* @param bool $sample Optional, defaults to false. Is it a sample permalink. Default false.
* @return string|WP_Error The post permalink.
* @param bool $leavename Optional. Whether to keep post name. Default false.
* @param bool $sample Optional. Is it a sample permalink. Default false.
* @return string|false The post permalink URL. False if the post does not exist.
*/
function get_post_permalink( $id = 0, $leavename = false, $sample = false ) {
global $wp_rewrite;

$post = get_post( $id );

if ( is_wp_error( $post ) ) {
return $post;
if ( ! $post ) {
return false;
}

$post_link = $wp_rewrite->get_extra_permastruct( $post->post_type );
Expand Down Expand Up @@ -3687,8 +3687,8 @@ function get_edit_profile_url( $user_id = 0, $scheme = 'admin' ) {
* @since WP-4.6.0
*
* @param int|WP_Post $post Optional. Post ID or object. Default is global `$post`.
* @return string|false The canonical URL, or false if the post does not exist or has not
* been published yet.
* @return string|false The canonical URL. False if the post does not exist
* or has not been published yet.
*/
function wp_get_canonical_url( $post = null ) {
$post = get_post( $post );
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/pluggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
if ( false !== $bracket_pos ) {
// Text before the bracketed email is the "From" name.
if ( $bracket_pos > 0 ) {
$from_name = substr( $content, 0, $bracket_pos - 1 );
$from_name = substr( $content, 0, $bracket_pos );
$from_name = str_replace( '"', '', $from_name );
$from_name = trim( $from_name );
}
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function classicpress_asset_version( $type = 'script', $handle = null ) {
static $default_version;

if ( empty( $default_version ) ) {
$default_version = 'cp_8a8887e6';
$default_version = 'cp_a76dff86';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @global string $cp_version
*/
$cp_version = '1.5.3';
$cp_version = '1.6.0';

/**
* The WordPress version string
Expand Down

0 comments on commit fe6a548

Please sign in to comment.