Skip to content

Commit

Permalink
- Stop automatic re-numbering of posts within the series #376
Browse files Browse the repository at this point in the history
  • Loading branch information
olatechpro committed Jan 25, 2022
1 parent 6cbc0da commit dfda820
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 25 deletions.
39 changes: 25 additions & 14 deletions inc/utility-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,33 @@ function ppseries_settings_template_tabbed_callback(){
//activation functions/codes
function pp_series_upgrade_function()
{

$version = get_option('pp_series_version');

if ( !$version || $version < '2.7.1') {
/**
* add newly introduced manage_publishpress_series for administrator
*#https://github.com/publishpress/publishpress-series/issues/313
**/
// Init roles
if ( function_exists( 'get_role' ) ) {
$role = get_role( 'administrator' );
if ( null !== $role && ! $role->has_cap( 'manage_publishpress_series' ) ) {
$role->add_cap( 'manage_publishpress_series' );
}
}
update_option('pp_series_version', ORG_SERIES_VERSION);
}
if ( !$version || $version < '2.7.1') {
/**
* add newly introduced manage_publishpress_series for administrator
*#https://github.com/publishpress/publishpress-series/issues/313
**/
// Init roles
if ( function_exists( 'get_role' ) ) {
$role = get_role( 'administrator' );
if ( null !== $role && ! $role->has_cap( 'manage_publishpress_series' ) ) {
$role->add_cap( 'manage_publishpress_series' );
}
}
update_option('pp_series_version', ORG_SERIES_VERSION);
}

if (!get_option('pp_series_2_7_5_upgraded')) {
$settings = get_option('org_series_options');
$settings = apply_filters('org_series_settings', $settings);
//add new series settings
$settings['automatic_series_part'] = 1;
update_option('org_series_options', $settings);
update_option('pp_series_2_7_5_upgraded', true);
}


}
}
Expand Down
16 changes: 15 additions & 1 deletion orgSeries-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function orgseries_validate($input) {
$newinput['custom_css'] = ( isset($input['custom_css']) && $input['custom_css'] == 1 ? 1 : 0 );
$newinput['series_css_tougle'] = ( isset($input['series_css_tougle']) ? trim(stripslashes(($input['series_css_tougle'])), 1) : 'default' );
$newinput['kill_on_delete'] = ( isset($input['kill_on_delete']) && $input['kill_on_delete'] == 1 ? 1 : 0 );
$newinput['automatic_series_part'] = ( isset($input['automatic_series_part']) && $input['automatic_series_part'] == 1 ? 1 : 0 );
$newinput['series_toc_url'] = preg_replace('/(^\/)|(\/$)/', '', ($input['series_toc_url']));
$newinput['series_custom_base'] = preg_replace('/(^\/)|(\/$)/', '', ($input['series_custom_base']));

Expand Down Expand Up @@ -223,7 +224,7 @@ function orgseries_options_init() {

function ppseries_filter_admin_settings_tabs($settings_tabs){
$settings_tabs['series_taxonomy_base_settings'] = esc_html__('URLs and Taxonomy', 'organize-series');
$settings_tabs['series_uninstall_settings'] = esc_html__('Uninstall / Reset', 'organize-series');
$settings_tabs['series_uninstall_settings'] = esc_html__('Advanced', 'organize-series');
return $settings_tabs;
}

Expand Down Expand Up @@ -806,6 +807,19 @@ function series_uninstall_core_fieldset() {
?>
<table class="form-table ppseries-settings-table">
<tbody>
<tr valign="top">
<th scope="row"><label for="automatic_series_part">
<?php esc_html_e('Automatic Numbering', 'organize-series'); ?>
</label>
</th>
<td>
<label>
<input name="<?php echo esc_attr($org_name); ?>[automatic_series_part]" id="automatic_series_part" type="checkbox" value="1" <?php checked('1', $org_opt['automatic_series_part']); ?> />
<?php esc_html_e('Enable automatic renumbering of posts in a series.', 'organize-series'); ?>
</label>
</td>
</tr>

<tr valign="top">
<th scope="row"><label for="kill_on_delete">
<?php esc_html_e('Series Settings', 'organize-series'); ?>
Expand Down
4 changes: 3 additions & 1 deletion orgSeries-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ function org_series_install() {
add_option( 'series_icon_url', '' );
add_option( 'series_icon_filetypes', 'jpg gif jpeg png' );

pp_series_upgrade_function();
}

function pp_series_upgrade_version_upgrade() {
Expand Down Expand Up @@ -207,9 +206,11 @@ function orgSeries_roles() {
global $wp_roles;
$roles = array('administrator', 'editor');
$capability = 'manage_series';
$capability_2 = 'manage_publishpress_series';

foreach ($roles as $role) {
$wp_roles->add_cap($role, $capability, true);
$wp_roles->add_cap($role, $capability_2, true);
}
return true;
}
Expand Down Expand Up @@ -273,6 +274,7 @@ function add_settings($reset = false) {
$this->settings = array(
//main settings
'custom_css' => 1,
'automatic_series_part' => 1,
'kill_on_delete' => 0, //determines if all series information (including series-icon tables) will be deleted when the plugin is deleted using the delete link on the plugins page.
'auto_tag_toggle' => 1, //sets the auto-tag insertions for the post-list box for posts that are part of series.
'auto_tag_nav_toggle' => 1, //sets the auto-tag insertions for the series navigation strip.
Expand Down
38 changes: 29 additions & 9 deletions orgSeries-taxonomy.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,11 @@ function series_wp_save_post($post_ID, $post, $update){
function wp_set_post_series( $post, $update, $post_ID = 0, $series_id = array(), $dont_skip = false, $is_published = false) {
$post_series = null;
$post_shorttitle = array();
global $orgseries;

$settings = $orgseries->settings;

$automatic_series_part = isset($settings['automatic_series_part']) ? (int)$settings['automatic_series_part'] : 0;

if ( !is_bool($update) ){
return; //safety check for users on earlier version of WP (so existing series don't get messed up)
Expand Down Expand Up @@ -520,11 +525,16 @@ function wp_set_post_series( $post, $update, $post_ID = 0, $series_id = array(),

if (empty($post_series) || ( count($post_series) == 1 && $post_series[0] == 0 ) ) $post_series = array();


if ( isset($_POST) || isset($_GET)) {
if ( isset($_POST['series_part']) ) $series_part = is_array($_POST['series_part']) ? array_map('sanitize_text_field', $_POST['series_part']) : array(sanitize_text_field($_POST['series_part']));
if ( isset($_GET['series_part']) ) $series_part = is_array($_GET['series_part']) ? array_map('sanitize_text_field', $_GET['series_part']) : array(sanitize_text_field($_GET['series_part']));

if (isset($_POST['series_part'])) {
$series_part = is_array($_POST['series_part']) ? array_map('sanitize_text_field', $_POST['series_part']) : array(sanitize_text_field($_POST['series_part']));
}
if (isset($_GET['series_part'])) {
$series_part = is_array($_GET['series_part']) ? array_map('sanitize_text_field', $_GET['series_part']) : array(sanitize_text_field($_GET['series_part']));
}

//The "short" title of the post that will be displayed in the OrgSeries widget.
if ( isset($_POST['serie_post_shorttitle']) )
$post_shorttitle = sanitize_text_field($_POST['serie_post_shorttitle']);
Expand All @@ -534,7 +544,6 @@ function wp_set_post_series( $post, $update, $post_ID = 0, $series_id = array(),
$post_shorttitle = is_array($post_shorttitle) && isset($post_shorttitle[$st_ser_id]) ? trim($post_shorttitle[$st_ser_id]) : '';
update_post_meta($post->ID, SPOST_SHORTTITLE_KEY, $post_shorttitle);


//if we don't have any changes in the series or series part info (or series post status) then let's get out and save time.
$p_status = $post->post_status;
if ( $p_status != 'draft' && $p_status != 'future' && $p_status != 'pending' ) {
Expand Down Expand Up @@ -579,19 +588,23 @@ function wp_set_post_series( $post, $update, $post_ID = 0, $series_id = array(),

$success = wp_set_object_terms($post_ID, $post_series, ppseries_get_series_slug());

if ( empty($p_ser_edit) ) return; //let's get out we've done everything we need to do.
if (empty($p_ser_edit)) {
return; //let's get out we've done everything we need to do.
}



if ( $success ) {
if ( $p_status != 'draft' && $p_status != 'future' && $p_status != 'pending' ) {
$is_published = TRUE;
}
foreach ( $p_ser_edit as $ser_id ) {
if ( empty($series_part[$ser_id]) ) {
if ( empty($series_part[$ser_id]) && $automatic_series_part > 0 ) {
$s_pt = wp_series_part($post_ID, $ser_id);
if ( !$series_part ) $series_part = 0;
}
//If post is not published its part stays as set by user
elseif ( !$is_published ) {
elseif ( !$is_published || $automatic_series_part === 0 ) {
$s_pt = $series_part[$ser_id];
}
else {
Expand All @@ -603,8 +616,15 @@ function wp_set_post_series( $post, $update, $post_ID = 0, $series_id = array(),
}
$s_pt = $set_spart[$ser_id];
}

set_series_order($ser_id, $post_ID, $s_pt, $is_published);

if ($automatic_series_part > 0)
{
set_series_order($ser_id, $post_ID, $s_pt, $is_published);
}else {
$series_part_key = apply_filters('orgseries_part_key', SERIES_PART_KEY, $ser_id);
delete_post_meta($post_ID, $series_part_key);
add_post_meta($post_ID, $series_part_key, $s_pt);
}
}

return;
Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ Yes, you can In the `organize-series` folder you'll see a file called `seriestoc

== Changelog ==

v2.7.5- [===unreleased===]
* Fixed: Stop automatic re-numbering of posts within the series #376

v2.7.4- 2022-01-20
* Fixed: Series option update message

Expand Down

0 comments on commit dfda820

Please sign in to comment.