Skip to content

Commit

Permalink
Merge pull request #1757 from publishpress/update/#1743-Allow-users-t…
Browse files Browse the repository at this point in the history
…o-chose-the-publish-date-in-the-New-Post-box

update/#1743-Allow-users-to-chose-the-publish-date-in-the-New-Post-box
  • Loading branch information
olatechpro authored Sep 9, 2024
2 parents 200dfd8 + a870d95 commit c6f621c
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 2 deletions.
96 changes: 96 additions & 0 deletions common/php/class-module.php
Original file line number Diff line number Diff line change
Expand Up @@ -1178,5 +1178,101 @@ public function get_author_markup($post, $can_edit_post) {
}
}

public function get_publish_date_markup() {
ob_start();
?>
<div class="misc-pub-section curtime misc-pub-curtime">
<fieldset id="timestampdiv">
<?php $this->touch_time(); ?>
</fieldset>
</div>
<?php
$publish_date_markup = ob_get_clean();
return $publish_date_markup;
}

public function touch_time( $tab_index = 0, $multi = 0 ) {
global $wp_locale;

$tab_index_attribute = '';
if ( (int) $tab_index > 0 ) {
$tab_index_attribute = " tabindex=\"$tab_index\"";
}

$jj = current_time( 'd' );
$mm = current_time( 'm' );
$aa = current_time( 'Y' );
$hh = current_time( 'H' );
$mn = current_time( 'i' );
$ss = current_time( 's' );

$cur_jj = current_time( 'd' );
$cur_mm = current_time( 'm' );
$cur_aa = current_time( 'Y' );
$cur_hh = current_time( 'H' );
$cur_mn = current_time( 'i' );

$month = '<label><span class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
__( 'Month' ) .
'</span><select class="form-required" ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n";
for ( $i = 1; $i < 13; $i = $i + 1 ) {
$monthnum = zeroise( $i, 2 );
$monthtext = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) );
$month .= "\t\t\t" . '<option value="' . $monthnum . '" data-text="' . $monthtext . '" ' . selected( $monthnum, $mm, false ) . '>';
/* translators: 1: Month number (01, 02, etc.), 2: Month abbreviation. */
$month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $monthtext ) . "</option>\n";
}
$month .= '</select></label>';

$day = '<label><span class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
__( 'Day' ) .
'</span><input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" class="form-required" /></label>';
$year = '<label><span class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
__( 'Year' ) .
'</span><input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" class="form-required" /></label>';
$hour = '<label><span class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
__( 'Hour' ) .
'</span><input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" class="form-required" /></label>';
$minute = '<label><span class="screen-reader-text">' .
/* translators: Hidden accessibility text. */
__( 'Minute' ) .
'</span><input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" class="form-required" /></label>';

echo '<div class="timestamp-wrap">';
/* translators: 1: Month, 2: Day, 3: Year, 4: Hour, 5: Minute. */
printf( __( '%1$s %2$s, %3$s at %4$s:%5$s' ), $month, $day, $year, $hour, $minute );

echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';

if ( $multi ) {
return;
}

echo "\n\n";

$map = array(
'mm' => array( $mm, $cur_mm ),
'jj' => array( $jj, $cur_jj ),
'aa' => array( $aa, $cur_aa ),
'hh' => array( $hh, $cur_hh ),
'mn' => array( $mn, $cur_mn ),
);

foreach ( $map as $timeunit => $value ) {
list( $unit, $curr ) = $value;

echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $unit . '" />' . "\n";
$cur_timeunit = 'cur_' . $timeunit;
echo '<input type="hidden" id="' . $cur_timeunit . '" name="' . $cur_timeunit . '" value="' . $curr . '" />' . "\n";
}
?>
<?php
}


}
}
31 changes: 31 additions & 0 deletions modules/content-board/content-board.php
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,31 @@ public function update_content_board_form_action() {
'post_status' => $status
];

// set post date
if ( ! empty( $_POST['mm'] ) ) {
$aa = sanitize_text_field($_POST['aa']);
$mm = sanitize_text_field($_POST['mm']);
$jj = sanitize_text_field($_POST['jj']);
$hh = sanitize_text_field($_POST['hh']);
$mn = sanitize_text_field($_POST['mn']);
$ss = sanitize_text_field($_POST['ss']);
$aa = ( $aa <= 0 ) ? gmdate( 'Y' ) : $aa;
$mm = ( $mm <= 0 ) ? gmdate( 'n' ) : $mm;
$jj = ( $jj > 31 ) ? 31 : $jj;
$jj = ( $jj <= 0 ) ? gmdate( 'j' ) : $jj;
$hh = ( $hh > 23 ) ? $hh - 24 : $hh;
$mn = ( $mn > 59 ) ? $mn - 60 : $mn;
$ss = ( $ss > 59 ) ? $ss - 60 : $ss;


$post_date = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $aa, $mm, $jj, $hh, $mn, $ss );
$valid_date = wp_checkdate( $mm, $jj, $aa, $post_date );
if ($valid_date ) {
$postArgs['post_date'] = $post_date;
$postArgs['post_date_gmt'] = get_gmt_from_date( $post_date );
}
}

$postId = wp_insert_post($postArgs);

if ($postId) {
Expand Down Expand Up @@ -1772,6 +1797,12 @@ public function getPostTypeFields($postType)
'value' => 'draft',
'type' => 'status',
'options' => $this->getUserAuthorizedPostStatusOptions($postType)
],
'pdate' => [
'label' => __('Publish Date', 'publishpress'),
'value' => 'immediately',
'type' => 'pdate',
'html' => $this->get_publish_date_markup()
]
];

Expand Down
7 changes: 6 additions & 1 deletion modules/content-board/lib/content-board.css
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,14 @@
padding-bottom: 5px;
}

.content-board-form-table .misc-pub-section {
padding-left: 0;
padding-right: 0;
}

.content-board-form-table input[type="text"],
.content-board-form-table textarea,
.content-board-form-table select {
.content-board-form-table select:not(#mm) {
width: 250px;
}

Expand Down
31 changes: 31 additions & 0 deletions modules/content-overview/content-overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,31 @@ public function update_content_overview_form_action() {
'post_status' => $status
];

// set post date
if ( ! empty( $_POST['mm'] ) ) {
$aa = sanitize_text_field($_POST['aa']);
$mm = sanitize_text_field($_POST['mm']);
$jj = sanitize_text_field($_POST['jj']);
$hh = sanitize_text_field($_POST['hh']);
$mn = sanitize_text_field($_POST['mn']);
$ss = sanitize_text_field($_POST['ss']);
$aa = ( $aa <= 0 ) ? gmdate( 'Y' ) : $aa;
$mm = ( $mm <= 0 ) ? gmdate( 'n' ) : $mm;
$jj = ( $jj > 31 ) ? 31 : $jj;
$jj = ( $jj <= 0 ) ? gmdate( 'j' ) : $jj;
$hh = ( $hh > 23 ) ? $hh - 24 : $hh;
$mn = ( $mn > 59 ) ? $mn - 60 : $mn;
$ss = ( $ss > 59 ) ? $ss - 60 : $ss;


$post_date = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $aa, $mm, $jj, $hh, $mn, $ss );
$valid_date = wp_checkdate( $mm, $jj, $aa, $post_date );
if ($valid_date ) {
$postArgs['post_date'] = $post_date;
$postArgs['post_date_gmt'] = get_gmt_from_date( $post_date );
}
}

$postId = wp_insert_post($postArgs);

if ($postId) {
Expand Down Expand Up @@ -1709,6 +1734,12 @@ public function getPostTypeFields($postType)
'value' => 'draft',
'type' => 'status',
'options' => $this->getUserAuthorizedPostStatusOptions($postType)
],
'pdate' => [
'label' => __('Publish Date', 'publishpress'),
'value' => 'immediately',
'type' => 'pdate',
'html' => $this->get_publish_date_markup()
]
];

Expand Down
7 changes: 6 additions & 1 deletion modules/content-overview/lib/content-overview.css
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,14 @@ table.content-overview thead td {
padding-bottom: 5px;
}

.content-overview-form-table .misc-pub-section {
padding-left: 0;
padding-right: 0;
}

.content-overview-form-table input[type="text"],
.content-overview-form-table textarea,
.content-overview-form-table select {
.content-overview-form-table select:not(#mm) {
width: 250px;
}

Expand Down

0 comments on commit c6f621c

Please sign in to comment.