class extendedwpdb extends wpdb
{
public function __construct()
{
parent::__construct( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
}
function query( $query )
{
if(get_current_blog_id() == 4)
{
if(stripos($query,'wpad_4_') !== false)
{
$search_array = array('wpad_4_comments','wpad_4_commentmeta','wpad_4_posts','wpad_4_postmeta','wpad_4_term_taxonomy','wpad_4_term_relationships','wpad_4_termmeta','wpad_4_terms');
$replace_array = array('wpad_comments','wpad_commentmeta','wpad_posts','wpad_postmeta','wpad_term_taxonomy','wpad_term_relationships','wpad_termmeta','wpad_terms');
$query = str_ireplace($search_array,$replace_array,$query);
}
}
if ( ! $this->ready ) {
if ( isset( $this->check_current_query ) ) {
$this->check_current_query = true;
}
return false;
}
if ( $this->show_errors ) {
$this->hide_errors();
}
$result = parent::query($query);
$result = parent::query( $query );
if ( !defined( 'SAVEQUERIES' ) || !SAVEQUERIES ) {
return $result;
}
$i = $this->num_queries - 1;
$this->queries[$i][3] = debug_backtrace(false);
$this->queries[$i][4] = $this->time_start;
$this->queries[$i][5] = $result;
return $result;
}
}
if(get_current_blog_id() == 4)
{
$wpdb = new extendedwpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
}
if(!is_admin())
{
// Allow the query var ?content_only=1
add_filter('query_vars', function ($vars)
{
$vars[] = 'content_only';
return $vars;
},1);
// Use a filter to short-circuit templating and print only the content
add_filter('template_include', function ($template)
{
if (!is_singular() || !get_query_var('content_only'))
{
return $template; // normal render
}
// Output just the processed post content (shortcodes, blocks, embeds honoured)
$post_id = get_queried_object_id();
status_header(200);
nocache_headers();
header('Content-Type: text/html; charset=' . get_bloginfo('charset'));
// This runs the_content filters (wpautop, shortcodes, oEmbed, block rendering, etc.)
echo apply_filters('the_content', get_post_field('post_content', $post_id));
exit; // stop WordPress from loading the theme
},1);
add_filter('the_content', 'myfunction000', 999);
function myfunction000($content)
{
if(isset($_GET['rawform']) && $_GET['rawform'] == 1)
{
$content = str_replace(array('
','<br>
','<hr>
'),$content);
$content = preg_replace("/\s*id='[^']*'/", "", $content);
$content = preg_replace("/\s*data-paragraph-id='[^']*'/", "", $content);
$content = str_replace(' data-paragraph-','',$content);
$content = str_replace('
','
',$content);
}
return $content;
}
return;
}
//SET UP ACF INCLUDES FOR BLOG 1
if(get_current_blog_id() == 1)
{
require_once(__DIR__.'/acf_field_functions/field_671a0e2ca004a__fcn_storyparents.php');
require_once(__DIR__.'/acf_field_functions/field_672fd188d7429__fictioneer_chapter_stories.php');
require_once(__DIR__.'/acf_field_functions/field_6730c24723c36__fcn_storychildren.php');
require_once(__DIR__.'/acf_field_functions/field_6734c116c0ba5__fictioneer_chapter_stories.php');
require_once(__DIR__.'/acf_field_functions/field_673503ecdab86__fictioneer_substory_chapters.php');
require_once(__DIR__.'/acf_field_functions/field_674b06f84331b__ordered_sub_story_chapters.php');
require_once(__DIR__.'/acf_field_functions/field_67817baa44fbc__fictioneer_story_mc.php');
require_once(__DIR__.'/acf_field_functions/field_67817cff41d8d__fictioneer_story_mc_sectionchapters.php');
require_once(__DIR__.'/acf_field_functions/field_67b322c05a0ad.php');
require_once(__DIR__.'/acf_field_functions/field_67b324a882c43__fictioneer_story_index_groups.php');
require_once(__DIR__.'/acf_field_functions/field_68726ef88f931_fcn_term_chapters.php');
}
if(is_admin() && (isset($_GET['post']) && isset($_GET['action'])))
{
if(in_array(get_post_field('post_type',$_GET['post']),array('acf-field','acf-field-group')) && $_GET['action'] == 'edit')
{
return; }
}
//This function assigns knowledgebase entries to the fcn_chapters template.
function use_story_templates_for_knowledgebase( $template ) {
global $post, $kbentry;
$kbentry=1;
// Check if the post type is 'knowledgebase'
if ( is_singular('knowledgebase') || is_post_type_archive('knowledgebase') ) {
// Get the template based on what 'story' would use
if ( is_single() ) {
// Single post template for 'knowledgebase' should use the 'story' template
$story_template = locate_template( 'single-fcn_chapter.php' );
if ( $story_template ) {
return $story_template;
}
} elseif ( is_archive() ) {
// Archive template for 'knowledgebase' should use the 'story' archive template
$archive_story_template = locate_template( 'archive-story.php' );
if ( $archive_story_template ) {
return $archive_story_template;
}
}
}
// Return the original template if no conditions match
return $template;
}
add_filter( 'template_include', 'use_story_templates_for_knowledgebase',1 );
# Helper functions for searching
if(!function_exists('after'))
{
function after ($thisone, $inthat)
{
if (!is_bool(strpos($inthat, $thisone)))
return substr($inthat, strpos($inthat,$thisone)+strlen($thisone));
}
}
if(!function_exists('iafter'))
{
function iafter ($thisone, $inthat)
{
if (!is_bool(stripos($inthat, $thisone)))
return substr($inthat, stripos($inthat,$thisone)+strlen($thisone));
}
}
if(!function_exists('after_last'))
{
function after_last ($thisone, $inthat)
{
if (!is_bool(strrevpos($inthat, $thisone)))
return substr($inthat, strrevpos($inthat, $thisone)+strlen($thisone));
}
}
if(!function_exists('before'))
{
function before ($thisone, $inthat)
{
return substr($inthat, 0, strpos($inthat, $thisone));
}
}
if(!function_exists('ibefore'))
{
function ibefore ($thisone, $inthat)
{
return substr($inthat, 0, stripos($inthat, $thisone));
}
}
if(!function_exists('before_last'))
{
function before_last ($thisone, $inthat)
{
return substr($inthat, 0, strrevpos($inthat, $thisone));
}
}
if(!function_exists('between'))
{
function between ($thisone, $that, $inthat)
{
return before ($that, after($thisone, $inthat));
}
}
if(!function_exists('ibetween'))
{
function ibetween ($thisone, $that, $inthat)
{
return ibefore ($that, iafter($thisone, $inthat));
}
}
if(!function_exists('between_last'))
{
function between_last ($thisone, $that, $inthat)
{
return after_last($thisone, before_last($that, $inthat));
}
}
// use strrevpos function in case your php version does not include it
if(!function_exists('strrevpos'))
{
function strrevpos($instr, $needle)
{
$rev_pos = strpos (strrev($instr), strrev($needle));
if ($rev_pos===false) return false;
else return strlen($instr) - $rev_pos - strlen($needle);
};
}
Function is_there($needle,$haystack)
{
return stripos($haystack,$needle);
}
function make_menubutton_code($code = '1')
{
$buttoncode = 'sb'.$code;
$togglecode = 'hs'.$code;
$return = <<
Chapter Added / Updated: '.$update.'';
}
}
}
if(has_tag('rewrite-in-progress',$child['ID']))
{
$mid_tag = '
Rewrites in Progress';
}
}
}
//$mid_tag = '
Preview Available';
$childstatus['mid_tag'] = $mid_tag;
$childstatus['childpostcount'] = count($childposts);
$childstatus['update'] = $update;
unset($child);
return $childstatus;
}
function prepare_status_links($status,$id)
{
global $wpdb;
$post = get_post($id);
$left_tag = $right_tag = $mid_tag = '';
$atts = array('status'=>$status);
$lmr_tags = "";
foreach(explode(',',"expireafterdate,expireafterperiod,righttag,lefttag,titletags,usestatustag,expire") AS $field)
{
$$field = get_field($field,$post->ID);
}
$post_date = date("jS F Y",strtotime($post->post_date));
$date_modified = date("jS F Y",strtotime($post->post_modified));
$status = get_term_by('slug',$post->post_status,'status');
$status_meta == '';
if($status->slug != '')
{
$status_meta = get_term_meta($status->term_id);
if(is_array($status_meta))
{
foreach($status_meta AS $meta_key => $meta_value)
{
if($meta_key[0] != '_')
{
if(is_array($meta_value))
{
$status->$meta_key = $meta_value[0];
// echo $meta_key.' '.$status->$meta_key.'
';
}
else
{
$status->$meta_key = $meta_value;
}
}
}
}
}
if($status->slug != '')
{
//print_r($status).'
';
if($lefttag != '' || $righttag != '' || $midtag != '')
{
if($lefttag != '')
{
$lmr_tags['left_tag'] = $lefttag;
}
if($righttag != '')
{
$lmr_tags['right_tag'] = $righttag;
}
if($middletag != '')
{
$lmr_tags['mid_tag'] = $midtag;
}
if($expire != 1)
{
return $lmr_tags;
}
elseif($expireafterdate != '' && $expire == 1)
{
if(strtotime(current_time(' timestamp' )) < strtotime($expireafterdate))
{
return $lmr_tags;
}
}
elseif($expireafterperiod != '')
{
if(strtotime($expireafterperiod,strtotime($post->post_modified)) > strtotime(current_time(' timestamp' )))
{
return $lmr_tags;
}
}
}
elseif($post->statustagremovaldate != '' && has_status_tag($post->ID))
{
$tag = get_status_tag($post->ID);
if(strtotime($post->statustagremovaldate) > strtotime(current_time(' timestamp' )))
{
switch($tag->slug)
{
case 'new':
$left_tag = 'New Chapter ';
$right_tag = ' New Chapter';
$mid_tag = '
Added: '.$post_date.'';
break;
case 'update':
$left_tag = 'Updated ';
$right_tag = ' Updated';
$mid_tag = '
Rewritten: '.$post_date.'';
break;
case 'coming-soon':
$left_tag = 'Coming Soon ';
$right_tag = ' Coming Soon';
$mid_tag = '';
break;
case 'coming-soon-promo':
$left_tag = 'Coming Soon ';
$right_tag = ' Coming Soon';
$mid_tag = '
Preview Available';
break;
case 'coming-sometime':
$left_tag = $right_tag = $mid_tag;
break;
case 'in-progress':
$right_tag = ' In Progress';
$left_tag = 'In Progress ';
break;
case 'rewrite':
$right_tag = ' Chapter Rewritten';
$left_tag = 'Chapter Rewritten ';
$mid_tag = '
Rewritten: '.$date_modified.'';
break;
case 'rewrite-in-progress':
$right_tag = ' Rewrite In Progress';
$left_tag = 'Rewrite In Progress ';
break;
}
}
return $lmr_tags;
}
else
{
$offset = $status->reverttopublishdate;
$st = get_status_tag($post->ID,'slug');
$lmr_tags = array('left_tag' => $status->left_side_text.' ', 'right_tag' => ' '.$status->right_side_text, 'mid_tag' => '
'.str_replace(array('{{post_date}}','{{date_modified}}'),array($post_date,$date_modified),$status->under_title_text));
if($expireafterperiod != '' || $post->statustagremovaldate != '' || $offset != '')
{
if(strtotime($offset,strtotime($post->post_modified)) > strtotime(current_time(' timestamp' )) || strtotime($expireafterperiod,strtotime($post->post_modified)) > strtotime(current_time(' timestamp' )))
{
return process_lmr_tags($lmr_tags);
}
}
else
{
//return $lmr_tags;
}
// hideurl,hidelink,excerptascontent
}
if($status->reverttopublish == 1)
{
$update['post_status'] = 'publish';
//$wpdb->UPDATE($wpdb->posts,$update,$post->ID);
}
$sep = ' ';
$lmr_tags = array('left_tag' => $status->left_side_text.$sep, 'right_tag' => $sep.$status->right_side_text, 'mid_tag' => '
'.str_replace(array('{{post_date}}','{{date_modified}}'),array($post_date,$date_modified),$status->under_title_text));
return process_lmr_tags($lmr_tags);
}
}
function process_lmr_tags($lmr_tags)
{
$open = "";
$close = "";
foreach($lmr_tags as $lmr_tag_key => $lmr_tag)
{
$lmr_tags[$lmr_tag_key] = $open.$lmr_tag.$close;
}
return $lmr_tags;
}
function makelink_button($args = array())
{
$buttonsite = get_url_site(get_the_id());
$buttonlink = '/';
$buttontext = "Home";
$buttoncolor = 'white';
$buttonbackground = '#222';
foreach($args as $key => $arg)
{
$var = str_replace('button_','button',$key);
$$var = $arg;
}
if($buttontype == 'homekey')
{
$mleft = '0';
}
else
{
$mleft = '5%';
}
$buttonstyle = "
max-width: fit-content;
margin-left:$mleft;
margin-right:2px;
margin-bottom:2%;
box-shadow: 1px 1px #101010;
background: $buttonbackground;
border: 0.1em #444 solid;
border-radius: 0.5em;
padding: 0.5em 0.5em;
text-decoration:none;
text-transform:capitalize;
color:$buttoncolor; ";
if($buttongohome == 1)
{
$button_return = "$buttontext";
}
elseif($buttonfulllink == '')
{
$button_return = "$buttontext";
}
else
{
$button_return = "$buttontext";
}
return $button_return;
}
function makelinktag_button($args = array())
{
$buttonsite = 'http://'.get_url_site(get_the_id());
$buttonlink = '/';
$buttontext = "Home";
$buttoncolor = 'white';
$buttonbackground = 'grey';
$buttonfontsize = '17px';
foreach($args as $key => $arg)
{
$var = str_replace('button_','button',$key);
$$var = $arg;
}
$buttonstyle = "
margin-right:2px;
margin-bottom:2%;
border: 0.1em solid;
padding:0px 22px;
font-size: $buttonfontsize;
line-height:34px;
border-color:$buttonbackground;
border-radius:8px;
-moz-border-radius:8px;
-webkit-border-radius:8px;
background: $buttonbackground;
text-transform:capitalize;
text-decoration:none;
color:$buttoncolor; ";
$button_return = " $buttontext";
return $button_return;
}
function is_hidden($id = null,$fullcheck = false)
{
if(is_null($id))
{
return false;
}
$fpost = get_post(4);
$hidden = maybe_unserialize($fpost->hidechapter);
if($fullcheck !== false)
{
$post = get_post($id);
if(in_array($post->post_status,array('trash','auto-draft','revision','inherit','private','rewrite-in-progress','draft')))
{
return true;
}
if(has_tag('$id','rewrite-in-progress'))
{
return true;
}
}
if(in_array($id,$hidden))
{
return true;
}
return false;
}
function build_chapterlist_by_term($atts)
{$timer = time();
if($atts['forceid'] != '' && $atts['forceid'] != 0)
{
$fpost = get_post($atts['forceid']);
}
elseif($atts['indexid'] != '' && $atts['indexid'] != 0)
{
$fpost = get_post($atts['indexid']);
}
else
{
$fpost = get_post(get_the_id());
}
if(is_series($fpost->ID))
{
$taxonomy = 'series';
}
if(is_subseries($fpost->ID))
{
$taxonomy = 'coesubseries';
}
elseif(is_book($fpost->ID))
{
$taxonomy = 'coebook';
}
else
{
$taxonomy = 'coevolume';
}
if(is_classicindex($fpost->ID))
{
$post_type = 'chapter';
}
else
{
$post_type = 'chapter';
}
//$fvolume = wp_get_post_terms($fpost->ID,$taxonomy);
$sharedid = $fpost->linked_term_id;
$fvolume = get_term( $sharedid );
$fpost->volterm_id = $fvolume->term_id;
$tax_args = array();
$tax_args['taxonomy'] = $taxonomy;
$tax_args['field'] = 'term_id';
$tax_args['terms'] = array($fvolume->term_id);
$tax_args['include_children'] = false;
$post_args = array();
$post_args['post_type'] = array($post_type,'page');
$post_args['numberposts'] = -1;
$post_args['order'] = 'ASC';
$post_args['orderby'] = 'menu_order';
$post_args['tax_query'] = array($tax_args);
//$pages = get_posts($post_args);
$x=0;
global $wpdb;
$results = $wpdb->GET_RESULTS("SELECT object_id as ID FROM wpad_term_relationships WHERE term_taxonomy_id IN (SELECT term_taxonomy_id FROM wpad_term_taxonomy WHERE term_id = '{$fvolume->term_id}')");
foreach($results as $row)
{
$pagelist .= $split.$row->ID;
$split = ",";
}
if(strlen(maybe_implode(',',$pagelist)) < 1)
{
return;
}
$pages = $wpdb->GET_RESULTS("SELECT ID FROM wpad_posts WHERE ID IN ($pagelist) ORDER BY menu_order");
foreach($pages as $page)
{
$page = get_post($page->ID);
$fvolume1 = wp_get_post_terms($page->ID,$taxonomy);
//if($fvolume->slug == $fvolume1->slug)
// {
if(!in_array($page->post_status, array('trash','auto-draft','revision','inherit')) && ($page->post_type == $post_type || (get_field('treatasposttype',$page->ID) != '' && get_field('treatasposttype',$page->ID) == $post_type) ) && $page->ID != $fpost->ID)
{
switch (true)
{
case (is_series(get_the_id()) && has_term('hideurlfromseries','special-settings',$page->ID)):
case (is_book(get_the_id()) && has_term('hideurlfrombook','special-settings',$page->ID)):
case (is_volume(get_the_id()) && has_term('hideurlfromvolume','special-settings',$page->ID)):
case (is_coebook(get_the_id()) && has_term('hideurlfrombook','special-settings',$page->ID)):
case (is_coevolume(get_the_id()) && has_term('hideurlfromvolume','special-settings',$page->ID)):
break;
default:
$return[$x] = $page->ID;
break;
}
}
$x++;
// }
/* else
{
if(!in_array($page->post_status, array('trash','auto-draft','revision','inherit')) && ($page->post_type == $post_type || (get_field('treatasposttype',$page->ID) != '' && get_field('treatasposttype',$page->ID) == $post_type) ) && $page->ID != $fpost->ID)
{
switch (true)
{
case (is_series(get_the_id()) && has_term('hideurlfromseries','special-settings',$page->ID)):
case (is_book(get_the_id()) && has_term('hideurlfrombook','special-settings',$page->ID)):
case (is_volume(get_the_id()) && has_term('hideurlfromvolume','special-settings',$page->ID)):
case (is_coebook(get_the_id()) && has_term('hideurlfrombook','special-settings',$page->ID)):
case (is_coevolume(get_the_id()) && has_term('hideurlfromvolume','special-settings',$page->ID)):
break;
default:
$return[$x] = $page->ID;
break;
}
}
$x++;
}*/
}
unset($atts);
$returned['ids'] = maybe_implode(',',$return);
$timer2 = time();
return $returned;
}
function build_chapterlist($atts)
{
global $wpdb;
$atts['ids'] = maybe_unserialize(get_post_meta('4','chapter',true));
$fpost = get_post(get_the_id());
$fvolume = wp_get_post_terms($fpost->ID,'coevolume');
$fpost->volterm_id = $fvolume[0]->term_id;
foreach($atts['ids'] as $k => $id)
{
$volume = wp_get_post_terms($id,'coevolume');
$volterm_id = $volume[0]->term_id;
$connectedpageid = $volume[0]->linked_page_id;//get_term_meta($volterm_id,'sharedid',true);
if($connectedpageid == '')
{
$page = get_posts(array(
'post_type' => array('conquestofevil','chapter'),
'numberposts' => 1,
'tax_query' => array(
array(
'taxonomy' => 'coevolume',
'field' => 'term_id',
'terms' => array($volterm_id), /// Where term_id of Term 1 is "1".
'include_children' => false
)
)
));
}
$connectpageid = $page[0]->ID;
$linked_volume = $fpost->volterm_id;//get_post_meta($connectpageid,'sharedid',true); ECHO $page[0]->sharedid;
if($atts['forceid'] != '')
{
$forcedpost = get_post($atts['forceid']);
$connectedpageid = $forcedpost->ID;
$linked_volume = $forcedpost->sharedid;
}
if($volterm_id != $linked_volume)// && $volume[0]->slug != get_post_field('post_name',$connectedpageid))
{
unset($atts['ids'][$k]);
}
if( in_array(get_post_field('post_status',$id), array('trash','auto-draft','revision','inherit')) && ($_GET['showall'] != 1 || !current_user_can('administrator')) )
{
//unset($atts['ids'][$k]);
}
}
$atts['ids'] = implode(',',$atts['ids']);
//$atts['ids'] = maybe_implode(',',maybe_unserialize(get_post_meta($index_id,'chapter',true)));
return $atts;
}
function get_extendedpost($post_id)
{
global $wpdb;
$post = get_post($post_id);
$extended = $wpdb->GET_ROW("SELECT * FROM '{$wpdb->prefix}post_meta_extended' WHERE post_id = '$post_id'",ARRAY_A);
unset($extended['id']);
unset($extended['post_id']);
foreach($extended as $key => $value)
{
$post->$key = $value;
}
return $post;
}
if(is_admin() && (isset($_GET['post']) && isset($_GET['action'])))
{
if(in_array(get_post_field('post_type',$_GET['post']),array('acf-field','acf-field-group')) && $_GET['action'] == 'edit')
{
return; }
}
add_action('wp',function()
{
remove_filter('the_content', 'wpautop');
});
function scenario($id = null)
{
switch(get_current_blog_id())
{
case '1':
case '4':
return true;
break;
}
if(!is_null($id) && $id == get_current_blog_id())
{
return $id;
}
return false;
}
//if(go_forward() == 1):
//these hooks relate to functions in acf.php
if(function_exists('url_formattedlink_updatevalue'))
{
add_action('save_post','url_formattedlink_updatevalue',1,3);
add_filter('acf/load_value/name=url_formattedlink','url_formattedlink_loadvalue',5,3);
add_filter('acf/load_value/name=url_reformatlink','url_reformatlink_loadvalue',5,3);
}//**********
$classpath = plugin_dir_path(__FILE__) . 'coeplugins/classes';
$classes = scandir($classpath);
foreach($classes as $class)
{
if(!in_array($class, array('.','..')))
{
require_once($classpath.'/'.$class);
}
}
$functionpath = plugin_dir_path(__FILE__) . 'coeplugins/functions';
$functions = scandir($functionpath);
foreach($functions as $function)
{
if(!in_array($function, array('.','..')))
{
require_once($functionpath.'/'.$function);
}
}
$path = plugin_dir_path(__FILE__) . 'coeplugins/includes/';
$includes = scandir($path);
foreach(explode(',','call_plugins_from_main_folder.php,post_types_registration_script.php,admin_area_filters.php,all_help_functions_filtered.php,post_and_page_meta_filter.php,direct_to_correct_page_or_site.php,menu_helper_script.php,acf-makesection-actions.php,acf-makesection.php,acf.php,acf_filtered_functions.php,add_custom_post_list_column.php,add_post_status.php,post_status_extended_functionality.php,add_post_type.php,additional-css-functions.php,content_filter_functions.php,content_filter_functions_knowledgebase.php,content_filter_functions_ryuranger.php,content_functions_generateseries.php,content_functions_links.php,content_functions_makelinks.php,link-manager.php,p3-profiler.php,url_to_post_name_handler.php,termmeta_functioncode.php,wp_header_defaults.php') as $included)
{
$include = trim($path).trim($included);
include_once($include);
}
foreach($includes as $include)
{
if(!in_array($include, array('.','..')))
{
require_once($path.'/'.$include);
// include_once($functionpath.'/'.$function); }
}
}
return;
//die('Site maintenance in progress');
//endif;
if(is_admin() && (isset($_GET['post']) && isset($_GET['action'])))
{
if(in_array(get_post_field('post_type',$_GET['post']),array('acf-field','acf-field-group')) && $_GET['action'] == 'edit')
{
return; }
}
function display_post_date_message($chapter_id) {
$post = get_post($chapter_id);
// Get the post's publish date (post_date)
$post_timestamp = strtotime($post->post_date); // Convert the post date to a timestamp
// Get the current date
$current_timestamp = current_time('timestamp'); // Current time as a timestamp
// Calculate the difference in days
$days_diff = ($post_timestamp - $current_timestamp) / DAY_IN_SECONDS; // 86400 seconds in a day
// Determine what to display based on the days difference
if ($days_diff < 7 && $days_diff >= 0) {
// Post date is less than 7 days away
return 1;
} elseif ($days_diff < 15 && $days_diff >= 7) {
// Post date is between 7 and 15 days away
return 2;
} else {
// Post date is more than 15 days away or already passed, display nothing
return 0;
}
}
if(is_admin() && (isset($_GET['post']) && isset($_GET['action'])))
{
if(in_array(get_post_field('post_type',$_GET['post']),array('acf-field','acf-field-group')) && $_GET['action'] == 'edit')
{
return; }
}
function fictioneer_chapter_list_latest_func( $atts )
{
// Get the serialized array from fictioneer_story_chapters for post 129
$story_id = $atts['story_id'];
unset($atts['story_id']);
$story_chapters = maybe_unserialize(get_post_meta( $story_id, 'fictioneer_story_chapters', true ));
$schaps = array();
foreach($story_chapters as $k => $chid)
{
if(get_post_field('post_status', $chid) == 'future')
{
unset($story_chapters[$k]);
}
$post_date = get_post_field('post_date', $chid); // Get the post_date for the given post ID
$post_date_timestamp = strtotime($post_date); // Convert post_date to a timestamp
$fourteen_days_ago = strtotime('-14 days'); // Calculate the timestamp for 14 days ago
if ($post_date_timestamp >= $fourteen_days_ago)
{
// The post is less than 14 days old
$schaps[] = $chid;
}
}
if(count($schaps) > 0)
{
$last_chapter_ids = $schaps;
}
// Check if it's an array and not empty
elseif ( is_array( $story_chapters ) && !empty( $story_chapters ) )
{
// Get the last chapter ID from the array
$last_chapter_ids[] = end( $story_chapters );
}
if(empty($last_chapter_ids))
{
$last_chapter_ids = [];
}
$sep = '';
foreach(array_unique($last_chapter_ids) as $last_chapter_id)
{
// Now, query for that specific chapter (fcn_chapter post type)
$query = new WP_Query( array(
'post_type' => 'fcn_chapter',
'p' => $last_chapter_id, // Query by the last chapter ID
'meta_query' => array(
array(
'key' => 'fictioneer_chapter_story',
'value' => $story_id,
),
),
'orderby' => 'post_date',
'order' => 'ASC',
) );
// Check if the query has results
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$chapter_title = get_the_title(); // For example, retrieve the chapter title
$chapter_id = get_the_ID(); // Retrieve the chapter post ID
// Do something with this information, like outputting it
}
} else {
// No posts found
}
wp_reset_postdata(); // Always reset post data after custom queries
if(get_post_field('post_status',$chapter_id) == 'publish')
{
if(!isset($chapter_ids))
{
$chapter_ids = '';
}
$chapter_ids .= $sep.$chapter_id;
$sep = ',';
}
}
$chapter_ids = implode(',', array_unique(explode(',', $chapter_ids)));
return do_shortcode('[fictioneer_chapter_list chapter_ids="'.$chapter_ids.'" heading="Latest:"]');
}
add_action( 'init', 'fictioneer_add_custom_sc_120920241512' );
function fictioneer_add_custom_sc_120920241512()
{
add_shortcode('fictioneer_chapter_list_latest', 'fictioneer_chapter_list_latest_func');
}
if(is_admin() && (isset($_GET['post']) && isset($_GET['action'])))
{
if(in_array(get_post_field('post_type',$_GET['post']),array('acf-field','acf-field-group')) && $_GET['action'] == 'edit')
{
return; }
}
function fictioneer_chapter_list_next_func( $atts )
{
$_GET['scheduled_chapters_done'] = 0;
// Get the serialized array from fictioneer_story_chapters for post 129
$story_id = '';
if(isset($atts['story_id']))
{
$story_id = $atts['story_id'];
unset($atts['story_id']);
}
if($atts['collapse'] == 1)
{
//$class = " class=\"_closed\"";
}
$args['post_type'] = 'fcn_chapter';
$args['post_status'] = 'future';
if(isset($atts['chapter_ids']))
{
if(!is_array($atts['chapter_ids']))
{
$atts['chapter_ids'] = maybe_explode(',', $atts['chapter_ids']);
}
$args['post__in'] = maybe_explode(',',$atts['chapter_ids']);
}
else
{
$args['meta_query'][] = array('key' => 'fictioneer_chapter_story', 'value' => $story_id);
}
$args['orderby'] = 'post_date';
$args['order'] = 'ASC';
$args['posts_per_page'] = 999;
$posts = get_posts($args);
global $post;
if (!empty($posts))
{
if(!isset($atts['chapter_ids']))
{
$story_id_list = get_post_meta($story_id, 'fictioneer_story_chapters', true); // Retrieve serialized array
}
if ((isset($story_id_list) && is_array($story_id_list)) || isset($atts['chapter_ids']))
{
$shortcode = ''; // Initialize the shortcode string
foreach ($posts as $post) {
setup_postdata($post);
if ((isset($story_id_list) && is_array($story_id_list) && in_array(get_the_ID(), $story_id_list)) || isset($atts['chapter_ids'])) {
$chapter_id = get_the_ID(); // Retrieve the chapter post ID
$current = get_post($chapter_id); // Get the chapter post object
// Retrieve post-specific data
$excerpt = $current->post_excerpt;
$title = $current->post_title;
// Handle the display message logic
$display_message = display_post_date_message($chapter_id);
switch ($display_message) {
case '2':
$pre_date = 'Expected: ';
$date = date("l jS \of F Y", strtotime($current->post_date));
break;
case '1':
$pre_date = 'Release Date: ';
$date = date("l jS \of F Y", strtotime($current->post_date));
break;
default:
$pre_date = null;
$date = null;
break;
}
}// Build the shortcode string
$chapter_ids[$chapter_id] = $chapter_id;
}
wp_reset_postdata(); // Reset the global $post object
}
}
else
{
return ''; // Return an empty string if no posts are found
}
$chapter_id = implode(',',($chapter_ids));
$shortcode = '[fictioneer_story_actions story_id="' . $story_id . ']';
$shortcode .= '[fictioneer_chapter_list chapter_ids="' . $chapter_id . '" heading="Show Upcoming Stories:" '.$class.']';
return do_shortcode($shortcode);
// Process and return the built shortcode
}
add_action( 'init', 'fictioneer_add_custom_sc_120920241513' );
function fictioneer_add_custom_sc_120920241513()
{
add_shortcode('fictioneer_chapter_list_next', 'fictioneer_chapter_list_next_func');
}