Warning: session_start(): Cannot send session cache limiter - wordpress

here is the error i get on my website when trying to process a payment page am not sure what to do i found this code
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/bargainhivee/public_html/wp-includes/wp-db.php:1482) in /home/bargainhivee/public_html/wp-content/plugins/Tevolution/tmplconnector/templatic-connector.php on line 5
this is the line 5
if (!isset($_SESSION)) { session_start(); }
here is the php file templatic-connector.php
<?php
/*
* includes the main files of tevolution default ad-on such as claim ownership,custom taxonomy,csutom fields,etc. and common functions.
*/
if (!isset($_SESSION)) { session_start(); }
require_once(TEMPL_MONETIZE_FOLDER_PATH."/templatic-claim_ownership/install.php" );
require_once(TEMPL_MONETIZE_FOLDER_PATH."/templatic-custom_taxonomy/install.php" );
require_once(TEMPL_MONETIZE_FOLDER_PATH."/templatic-custom_fields/install.php" );
require_once(TEMPL_MONETIZE_FOLDER_PATH."/templatic-monetization/install.php" );
require_once(TEMPL_MONETIZE_FOLDER_PATH."/templatic-ratings/install.php" );
require_once(TEMPL_MONETIZE_FOLDER_PATH."/templatic-registration/install.php" );
require_once (TEMPL_MONETIZE_FOLDER_PATH . "/templatic-widgets/templatic_browse_by_categories_widget.php");
require_once (TEMPL_MONETIZE_FOLDER_PATH . "/templatic-widgets/templatic_advanced_search_widget.php");
require_once (TEMPL_MONETIZE_FOLDER_PATH . "/templatic-widgets/templatic_people_list_widget.php");
require_once (TEMPL_MONETIZE_FOLDER_PATH . "/templatic-widgets/templatic_metakey_search_widget.php");
require_once(TEMPL_MONETIZE_FOLDER_PATH."templatic-generalization/general_functions.php" );
/* Add to favourites for tevolution*/
if(file_exists(TEMPL_MONETIZE_FOLDER_PATH."templatic-generalization/add_to_favourites.php") && (!strstr($_SERVER['REQUEST_URI'],'/wp-admin/') || strstr
($_SERVER['REQUEST_URI'],'/admin-ajax.php') )){
require_once(TEMPL_MONETIZE_FOLDER_PATH."templatic-generalization/add_to_favourites.php" );
}
/*
do action for admin menu
*/
add_action('admin_menu', 'templ_add_admin_menu_'); /* create templatic admin menu */
function templ_add_admin_menu_()
{
do_action('templ_add_admin_menu_');
}
add_action('templ_add_admin_menu_', 'templ_add_mainadmin_menu_', 0);
add_action('templ_add_admin_menu_', 'templ_remove_mainadmin_sub_menu_');
if(!function_exists('templ_remove_mainadmin_sub_menu_')){
function templ_remove_mainadmin_sub_menu_(){
remove_submenu_page('templatic_system_menu', 'templatic_system_menu');
add_submenu_page( 'templatic_system_menu', __('Overview','templatic-admin'), __('Overview','templatic-admin'), 'administrator',
'templatic_system_menu', 'templatic_connector_class' );
}
}
/*
include the main.connector.class.php file
*/
function templatic_connector_class()
{
require_once(TEVOLUTION_PAGE_TEMPLATES_DIR.'classes/main.connector.class.php' );
}
/*
Return the main menu at admin sidebar
*/
function templ_add_mainadmin_menu_()
{
$menu_title = __('Tevolution', 'templatic');
if (function_exists('add_object_page'))
{
if(isset($_REQUEST['page']) && $_REQUEST['page'] == 'templatic_system_menu'){
$icon = TEMPL_PLUGIN_URL.'favicon-active.png';
}else{
$icon = TEMPL_PLUGIN_URL.'favicon-active.png';
}
$hook = add_menu_page("Admin Menu", $menu_title, 'administrator', 'templatic_system_menu', 'dashboard_bundles', '',3); /* title of new
sidebar*/
}else{
add_menu_page("Admin Menu", $menu_title, 'administrator', 'templatic_wp_admin_menu', 'design','');
}
}
/*
return the connection with dashboard wizards(bundle box)
*/
function dashboard_bundles()
{
$Templatic_connector = New Templatic_connector;
require_once(TEVOLUTION_PAGE_TEMPLATES_DIR.'classes/main.connector.class.php' );
if(isset($_REQUEST['tab']) && $_REQUEST['tab'] =='extend') {
$Templatic_connector->templ_extend();
}else if(isset($_REQUEST['tab']) && $_REQUEST['tab'] =='payment-gateways') {
$Templatic_connector->templ_payment_gateway();
}else if((!isset($_REQUEST['tab'])&& #$_REQUEST['tab']=='') || isset($_REQUEST['tab']) && $_REQUEST['tab'] =='overview') {
$Templatic_connector->templ_overview();
$Templatic_connector->templ_dashboard_extends();
}
}
/*
return main CSS of Plugin
*/
add_action('admin_head', 'templ_add_my_stylesheet'); /* include style sheet */
add_action('wp_head', 'templ_add_my_stylesheet',0); /* include style sheet */
function templ_add_my_stylesheet()
{
/* Respects SSL, Style.css is relative to the current file */
wp_enqueue_script('jquery');
$tmpl_is_allow_url_fopen = tmpl_is_allow_url_fopen();
/* Tevolution Plug-in Style Sheet File In Desktop view only */
if (function_exists('tmpl_wp_is_mobile') && !tmpl_wp_is_mobile()) {
/* if "allow_url_fopen" is enabled then apply minifiled css otherwise includse seperately */
if(!$tmpl_is_allow_url_fopen){
wp_enqueue_style('tevolution_style',TEMPL_PLUGIN_URL.'style.css','',false);
}else{
wp_enqueue_style('tevolution_style',TEMPL_PLUGIN_URL.'css.minifier.php','',false);
}
}
if(function_exists('theme_get_settings')){
if(theme_get_settings('supreme_archive_display_excerpt')){
if(function_exists('tevolution_excerpt_length')){
add_filter('excerpt_length', 'tevolution_excerpt_length');
}
if(function_exists('new_excerpt_more')){
add_filter('excerpt_more', 'new_excerpt_more');
}
}
}
}
/* check if "allow_url_fopen" is enabled or not */
function tmpl_is_allow_url_fopen(){
if( ini_get('allow_url_fopen') ) {
return true;
}else{
return false;
}
}
/*
return each add-ons is activated or not
*/
function is_active_addons($key)
{
$act_key = get_option($key);
if ($act_key != '')
{
return true;
}
}
/*
Function will remove the admin dashboard widget
*/
function templ_remove_dashboard_widgets()
{
/* Globalize the metaboxes array, this holds all the widgets for wp-admin*/
global $wp_meta_boxes;
/* Remove the Dashboard quickpress widget*/
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
/* Remove the Dashboard incoming links widget*/
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
/* Remove the Dashboard secondary widget*/
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
}
add_action('wp_dashboard_setup', 'templ_remove_dashboard_widgets');
/* -- coding to add submenu under main menu-- */
add_action('templ_add_admin_menu_', 'templ_add_page_menu');
function templ_add_page_menu()
{
/*tevolution_menu_before_general_settings hook for add additional menu before general settings */
do_action('tevolution_menu_before_general_settings');
$menu_title2 = __('Settings', 'templatic-admin');
add_submenu_page('templatic_system_menu', $menu_title2, $menu_title2,'administrator', 'templatic_settings', 'my_page_templates_function');
/*tevolution_menu_after_general_settings hook for add additional menu after general settings */
do_action('tevolution_menu_after_general_settings');
}
/*
Email, security , and set up steps menu selected
*/
add_action('admin_footer','tevolution_menu_script');
function tevolution_menu_script()
{
?>
<script data-cfasync="false" type="text/javascript" async >
jQuery(document).ready(function(){
if(jQuery('#adminmenu ul.wp-submenu li').hasClass('current'))
{
<?php if(isset($_REQUEST['page']) && $_REQUEST['page']=='templatic_system_menu' && isset($_REQUEST['tab']) && $_REQUEST['tab']=='setup-steps'
):?>
jQuery('#adminmenu ul.wp-submenu li').removeClass('current');
jQuery('#adminmenu ul.wp-submenu li a').removeClass('current');
jQuery('#adminmenu ul.wp-submenu li a[href*="page=templatic_system_menu&tab=setup-steps"]').attr('href', function() {
jQuery('#adminmenu ul.wp-submenu li a[href*="page=templatic_system_menu&tab=setup-steps"]').addClass('current');
jQuery('#adminmenu ul.wp-submenu li a[href*="page=templatic_system_menu&tab=setup-steps"]').parent().addClass('current');
});
<?php endif;?>
}
jQuery('.reset_custom_fields').click( function() {
if(confirm("<?php echo __('All your modifications done with this, will be deleted forever! Still you want to proceed?','templatic-admin');?
>")){
return true;
}else{
return false;
}
});
});
</script>
<?php
}
/* include general_settings.php file */
function my_page_templates_function()
{
include(TEMPL_MONETIZE_FOLDER_PATH.'templatic-generalization/general_settings.php');
}
/*
Redirect on plugin dashboard after activating plugin
*/
add_action('admin_init', 'my_plugin_redirect');
function my_plugin_redirect()
{
global $pagenow;
if (get_option('myplugin_redirect_on_first_activation') == 'true' && $pagenow=='plugins.php' ){
update_option('myplugin_redirect_on_first_activation', 'false');
wp_redirect(MY_PLUGIN_SETTINGS_URL);
}
if (get_option('myplugin_redirect_on_first_activation') == 'true' && $pagenow=='themes.php' ){
update_option('myplugin_redirect_on_first_activation', 'false');
wp_redirect(site_url().'/wp-admin/themes.php');
}
}
/*
* View counter for detail page
*/
function view_counter_single_post($pid){
if($_SERVER['HTTP_REFERER'] == '' || !strstr($_SERVER['HTTP_REFERER'],$_SERVER['REQUEST_URI']))
{
$viewed_count = get_post_meta($pid,'viewed_count',true);
$viewed_count_daily = get_post_meta($pid,'viewed_count_daily',true);
$daily_date = get_post_meta($pid,'daily_date',true);
update_post_meta($pid,'viewed_count',$viewed_count+1);
if(get_post_meta($pid,'daily_date',true) == date('Y-m-d')){
update_post_meta($pid,'viewed_count_daily',$viewed_count_daily+1);
} else {
update_post_meta($pid,'viewed_count_daily','1');
}
update_post_meta($pid,'daily_date',date('Y-m-d'));
}
}
/*
* return the count of post view
*/
if(!function_exists('user_single_post_visit_count')){
function user_single_post_visit_count($pid)
{
if(get_post_meta($pid,'viewed_count',true))
{
return get_post_meta($pid,'viewed_count',true);
}else
{
return '0';
}
}
}
/*
* Function Name:user_single_post_visit_count_daily
* Argument: Post id
*/
if(!function_exists('user_single_post_visit_count_daily')){
function user_single_post_visit_count_daily($pid)
{
if(get_post_meta($pid,'viewed_count_daily',true))
{
return get_post_meta($pid,'viewed_count_daily',true);
}else
{
return '0';
}
}
}
/*
* add view count display after the content
*/
if( !function_exists('view_count')){
function view_count( $content ) {
if ( is_single())
{
global $post;
$sep =" , ";
$custom_content='';
$custom_content.="<p>".__('Visited','templatic')." ".user_single_post_visit_count($post->ID)." ".__('times','templatic');
$custom_content.= $sep.user_single_post_visit_count_daily($post->ID).__(" Visits today",'templatic')."</p>";
$custom_content .= $content;
echo $custom_content;
}
}
}
/*
* show counter and share button after custom fields.
*/
function teamplatic_view_counter()
{
$settings = get_option( "templatic_settings" );
if(isset($settings['templatic_view_counter']) && $settings['templatic_view_counter']=='Yes')
{
global $post;
view_counter_single_post($post->ID);
view_count('');
}
//view_sharing_buttons('');
tevolution_socialmedia_sharelink();
}
/*Remove the the_content filter to add view counter everywhere in single page and add action tmpl_detail_page_custom_fields_collection before the custom
field display*/
add_action('tmpl_detail_page_custom_fields_collection','teamplatic_view_counter',5);
function view_sharing_buttons($content)
{
global $post;
if (is_single() && ($post->post_type!='post' && $post->post_type!='page' && $post->post_type!='product' && $post->post_type!='product_variation'
))
{
$post_img = bdw_get_images_plugin($post->ID,'thumb');
$post_images = $post_img[0];
$title=urlencode($post->post_title);
$url=urlencode(get_permalink($post->ID));
$summary=urlencode(htmlspecialchars($post->post_content));
$image=$post_images;
$settings = get_option( "templatic_settings" );
if($settings['facebook_share_detail_page'] =='yes' || $settings['google_share_detail_page'] == 'yes' || $settings
['twitter_share_detail_page'] == 'yes' || $settings['pintrest_detail_page']=='yes'){
echo '<div class="share_link">';
if($settings['facebook_share_detail_page'] == 'yes')
{
?>
<a onClick="window.open('//www.facebook.com/sharer.php?s=100&p[title]=<?php echo $title;?>&p[summary]=<?php echo
$summary;?>&p[url]=<?php echo $url; ?>&&p[images][0]=<?php echo $image;?>','sharer','toolbar=0,status=0,width=548,height=325');"
href="javascript: void(0)" id="facebook_share_button"><?php _e('Facebook Share.',T_DOMAIN); ?></a>
<?php
}
if($settings['google_share_detail_page'] == 'yes'): ?>
<script data-cfasync="false" type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<div class="g-plus" data-action="share" data-annotation="bubble"></div>
<?php endif;
if($settings['twitter_share_detail_page'] == 'yes'): ?>
<a href="https://twitter.com/share" class="twitter-share-button" data-lang="en" data-text='<?php echo htmlentities
($post->post_content);?>' data-url="<?php echo get_permalink($post->ID); ?>" data-counturl="<?php echo get_permalink($post->ID); ?>"><?php _e
('Tweet',T_DOMAIN); ?></a>
<script data-cfasync="false">!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id))
{js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-
wjs");</script>
<?php endif;
if(#$settings['pintrest_detail_page']=='yes'):?>
<!-- Pinterest -->
<div class="pinterest">
<a href="//pinterest.com/pin/create/button/?url=<?php echo urlencode(get_permalink($post->ID)); ?>&media=<?php echo $image; ?
>&description=<?php the_title(); ?>" ><?php _e('Pin It','templatic');?></a>
<script data-cfasync="false" type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script>
</div>
<?php endif;
echo '</div>';
}
}
return $content;
}
/*
return the currency code
*/
function templatic_get_currency_type()
{
global $wpdb;
$option_value = get_option('currency_code');
if($option_value)
{
return stripslashes($option_value);
}else
{
return 'USD';
}
}
/*
this function returns the currency with position selected in currency settings
*/
function fetch_currency_with_position($amount,$currency = '')
{
$amt_display = '';
if($amount==''){ $amount =0; }
$decimals=get_option('tmpl_price_num_decimals');
$decimals=($decimals!='')?$decimals:2;
if($amount >=0 )
{
if(#$amount !='')
$amount = number_format( (float)($amount),$decimals,'.','');
$currency = get_option('currency_symbol');
$position = get_option('currency_pos');
if($position == '1')
{
$amt_display = $currency.$amount;
}
else if($position == '2')
{
$amt_display = $currency.' '.$amount;
}
else if($position == '3')
{
$amt_display = $amount.$currency;
}
else
{
$amt_display = $amount.' '.$currency;
}
return apply_filters('tmpl_price_format',$amt_display,$amount,$currency);
}
}
/*
this function returns the currency with position selected in currency settings
*/
function fetch_currency_with_symbol($amount,$currency = '')
{
$amt_display = '';
if($amount==''){ $amount =0; }
$decimals=get_option('tmpl_price_num_decimals');
$decimals=($decimals!='')?$decimals:2;
if($amount >=0 )
{
if(#$amount !='')
$amount = $amount;
$currency = get_option('currency_symbol');
$position = get_option('currency_pos');
if($position == '1')
{
$amt_display = $currency.$amount;
}
else if($position == '2')
{
$amt_display = $currency.' '.$amount;
}
else if($position == '3')
{
$amt_display = $amount.$currency;
}
else
{
$amt_display = $amount.' '.$currency;
}
return apply_filters('tmpl_price_format',$amt_display,$amount,$currency);
}
}
/* eof - display currency with position */
/* this function will display the legends descr

Related

Wordpress filter locale and add_action->switch_to_locale

Changing locale via add_action->switch_to_locale works while add_filter doesn't.
add_filter
function change_locale( $locale ) {
if (is_singular()) {
global $post;
if(($post->ID=='1839') || ($post->ID=='577') || ($post->ID=='1346')){
$locale = 'en_US';
}
}
return $locale;
}
add_filter('locale', 'change_locale');
add_action
function change_to_english_local() {
if (is_singular()) {
global $post;
if(($post->ID=='1839') || ($post->ID=='577') || ($post->ID=='1346')){
switch_to_locale('en_US');
}
}
}
add_action( 'wp_enqueue_scripts', 'change_to_english_local');
Why?

how to remove custom post type from wordpress url?

I have a wordpress website which is using the custom template with custom post types like landing and services.
Each post type have a specific slug in the url like this => (http://example.com/landing/landing-page-name)
I want to change this url (http://example.com/landing/landing-page-name) to this url (http://example.com/landing-page-name).
In fact I need to remove the [landing] phrase from the url. The important thing is that the [landing] is a custom post type in my posts table.
I have tested following solutions:
==> I have changed slug to '/' in rewrite property in register_post_type() --> It breaks the all of landings, posts and pages url (404)
==> I added 'with_front' => false to the rewrite property --> nothing changed
==> I tried to do this with RewriteRule in htaccess --> it did not work or give too many redirects error
I could not get a proper result.
Did anyone solve this problem before?
First, you need to filter the permalink for your custom post type so that all published posts don't have the slug in their URLs:
function stackoverflow_remove_cpt_slug( $post_link, $post ) {
if ( 'landing' === $post->post_type && 'publish' === $post->post_status ) {
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
}
return $post_link;
}
add_filter( 'post_type_link', 'stackoverflow_remove_cpt_slug', 10, 2 );
At this point, trying to view the link would result in a 404 (Page Not Found) error. That's because WordPress only knows that Posts and Pages can have URLs like domain.com/post-name/ or domain.com/page-name/. We need to teach it that our custom post type's posts can also have URLs like domain.com/cpt-post-name/.
function stackoverflow_add_cpt_post_names_to_main_query( $query ) {
// Return if this is not the main query.
if ( ! $query->is_main_query() ) {
return;
}
// Return if this query doesn't match our very specific rewrite rule.
if ( ! isset( $query->query['page'] ) || 2 !== count( $query->query ) ) {
return;
}
// Return if we're not querying based on the post name.
if ( empty( $query->query['name'] ) ) {
return;
}
// Add CPT to the list of post types WP will include when it queries based on the post name.
$query->set( 'post_type', array( 'post', 'page', 'landing' ) );
}
add_action( 'pre_get_posts', 'stackoverflow_add_cpt_post_names_to_main_query' );
try this code , 100% working single custom post type and multiple post type.
add this class in functions.php file in our theme , or create separate file and import into functions.php
class remove_cpt_base {
var $plugin_admin_page;
static $instance = null;
static public function init() {
if (self::$instance == null) {
self::$instance = new self();
}
return self::$instance;
}
function __construct() {
add_action('plugins_loaded', array($this, 'plugins_loaded'));
$this->rcptb_selected = get_option('rcptb_selected', array());
$this->rcptb_selected_keys = array_keys($this->rcptb_selected);
add_action('admin_menu', array($this, 'plugin_menu_link'));
add_filter('post_type_link', array($this, 'remove_slug'), 10, 3);
add_action('template_redirect', array($this, 'auto_redirect_old'), 1);
add_action('pre_get_posts', array($this, 'handle_cpts'), 1);
}
function plugins_loaded() {
load_plugin_textdomain('remove_cpt_base', FALSE, basename(dirname(__FILE__)) . '/languages/');
}
function filter_plugin_actions($links, $file) {
$settings_link = '' . __('Settings') . '';
array_unshift($links, $settings_link);
return $links;
}
function plugin_menu_link() {
$this->plugin_admin_page = add_submenu_page(
'options-general.php',
__('Remove CPT base', 'remove_cpt_base'),
__('Remove CPT base', 'remove_cpt_base'),
'manage_options',
basename(__FILE__),
array($this, 'admin_options_page')
);
add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'filter_plugin_actions'), 10, 2);
}
function admin_options_page() {
if (get_current_screen()->id != $this->plugin_admin_page) {
return;
}
global $wp_post_types;?>
<div class="wrap">
<h2><?php _e('Remove base slug from url for these custom post types:', 'remove_cpt_base')?></h2><?php
if (isset($_POST['rcptb_selected_sent'])) {
if (!isset($_POST['rcptb_alternation']) || !is_array($_POST['rcptb_alternation'])) {
$alternation = array();
} else {
$alternation = $_POST['rcptb_alternation'];
}
if (!isset($_POST['rcptb_selected']) || !is_array($_POST['rcptb_selected'])) {
$this->rcptb_selected = array();
} else {
$this->rcptb_selected = $_POST['rcptb_selected'];
}
foreach ($this->rcptb_selected as $post_type => $active) {
$this->rcptb_selected[$post_type] = isset($alternation[$post_type]) ? 1 : 0;
}
$this->rcptb_selected_keys = array_keys($this->rcptb_selected);
update_option('rcptb_selected', $this->rcptb_selected, 'no');
echo '<div class="below-h2 updated"><p>' . __('Settings saved.') . '</p></div>';
flush_rewrite_rules();
}?>
<br>
<form method="POST" action="">
<input type="hidden" name="rcptb_selected_sent" value="1">
<table class="widefat" style="width:auto">
<tbody><?php
foreach ($wp_post_types as $type => $custom_post) {
if ($custom_post->_builtin == false) {?>
<tr>
<td>
<label>
<input type="checkbox" name="rcptb_selected[<?php echo $custom_post->name ?>]" value="1" <?php echo isset($this->rcptb_selected[$custom_post->name]) ? 'checked' : '' ?>>
<?php echo $custom_post->label ?> (<?php echo $custom_post->name ?>)
</label>
</td>
<td>
<label>
<input type="checkbox" name="rcptb_alternation[<?php echo $custom_post->name ?>]" value="1" <?php echo isset($this->rcptb_selected[$custom_post->name]) && $this->rcptb_selected[$custom_post->name] == 1 ? 'checked' : '' ?>>
<?php _e('alternation', 'remove_cpt_base')?>
</label>
</td>
</tr><?php
}
}?>
</tbody>
</table>
<p><?php _e('* if your custom post type children return error 404, then try alternation mode', 'remove_cpt_base')?></p>
<hr>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save')?>">
</p>
</form>
</div><?php
}
function remove_slug($permalink, $post, $leavename) {
global $wp_post_types;
foreach ($wp_post_types as $type => $custom_post) {
if ($custom_post->_builtin == false && $type == $post->post_type && isset($this->rcptb_selected[$custom_post->name])) {
$custom_post->rewrite['slug'] = trim($custom_post->rewrite['slug'], '/');
$permalink = str_replace('/' . $custom_post->rewrite['slug'] . '/', '/', $permalink);
}
}
return $permalink;
}
function get_current_url() {
$REQUEST_URI = strtok($_SERVER['REQUEST_URI'], '?');
$real_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
$real_url .= $_SERVER['SERVER_NAME'] . $REQUEST_URI;
return $real_url;
}
function handle_cpts($query) {
// make sure it's main query on frontend
if (!is_admin() && $query->is_main_query() && !$query->get('queried_object_id')) {
// conditions investigated after many tests
if ($query->is_404() || $query->get('pagename') || $query->get('attachment') || $query->get('name') || $query->get('category_name')) {
// test both site_url and home_url
$web_roots = array();
$web_roots[] = site_url();
if (site_url() != home_url()) {
$web_roots[] = home_url();
}
// polylang fix
if (function_exists('pll_home_url')) {
if (site_url() != pll_home_url()) {
$web_roots[] = pll_home_url();
}
}
foreach ($web_roots as $web_root) {
// get clean current URL path
$path = $this->get_current_url();
$path = str_replace($web_root, '', $path);
// fix missing slash
if (substr($path, 0, 1) != '/') {
$path = '/' . $path;
}
// test for posts
$post_data = get_page_by_path($path, OBJECT, 'post');
if (!($post_data instanceof WP_Post)) {
// test for pages
$post_data = get_page_by_path($path);
if (!is_object($post_data)) {
// test for selected CPTs
$post_data = get_page_by_path($path, OBJECT, $this->rcptb_selected_keys);
if (is_object($post_data)) {
// maybe name with ancestors is needed
$post_name = $post_data->post_name;
if ($this->rcptb_selected[$post_data->post_type] == 1) {
$ancestors = get_post_ancestors($post_data->ID);
foreach ($ancestors as $ancestor) {
$post_name = get_post_field('post_name', $ancestor) . '/' . $post_name;
}
}
// get CPT slug
$query_var = get_post_type_object($post_data->post_type)->query_var;
// alter query
$query->is_404 = 0;
$query->tax_query = NULL;
$query->is_attachment = 0;
$query->is_category = 0;
$query->is_archive = 0;
$query->is_tax = 0;
$query->is_page = 0;
$query->is_single = 1;
$query->is_singular = 1;
$query->set('error', NULL);
unset($query->query['error']);
$query->set('page', '');
$query->query['page'] = '';
$query->set('pagename', NULL);
unset($query->query['pagename']);
$query->set('attachment', NULL);
unset($query->query['attachment']);
$query->set('category_name', NULL);
unset($query->query['category_name']);
$query->set('post_type', $post_data->post_type);
$query->query['post_type'] = $post_data->post_type;
$query->set('name', $post_name);
$query->query['name'] = $post_name;
$query->set($query_var, $post_name);
$query->query[$query_var] = $post_name;
break;
} else {
// deeper matching
global $wp_rewrite;
// test all selected CPTs
foreach ($this->rcptb_selected_keys as $post_type) {
// get CPT slug and its length
$query_var = get_post_type_object($post_type)->query_var;
// test all rewrite rules
foreach ($wp_rewrite->rules as $pattern => $rewrite) {
// test only rules for this CPT
if (strpos($pattern, $query_var) !== false) {
if (strpos($pattern, '(' . $query_var . ')') === false) {
preg_match_all('#' . $pattern . '#', '/' . $query_var . $path, $matches, PREG_SET_ORDER);
} else {
preg_match_all('#' . $pattern . '#', $query_var . $path, $matches, PREG_SET_ORDER);
}
if (count($matches) !== 0 && isset($matches[0])) {
// build URL query array
$rewrite = str_replace('index.php?', '', $rewrite);
parse_str($rewrite, $url_query);
foreach ($url_query as $key => $value) {
$value = (int) str_replace(array('$matches[', ']'), '', $value);
if (isset($matches[0][$value])) {
$value = $matches[0][$value];
$url_query[$key] = $value;
}
}
// test new path for selected CPTs
if (isset($url_query[$query_var])) {
$post_data = get_page_by_path('/' . $url_query[$query_var], OBJECT, $this->rcptb_selected_keys);
if (is_object($post_data)) {
// alter query
$query->is_404 = 0;
$query->tax_query = NULL;
$query->is_attachment = 0;
$query->is_category = 0;
$query->is_archive = 0;
$query->is_tax = 0;
$query->is_page = 0;
$query->is_single = 1;
$query->is_singular = 1;
$query->set('error', NULL);
unset($query->query['error']);
$query->set('page', '');
$query->query['page'] = '';
$query->set('pagename', NULL);
unset($query->query['pagename']);
$query->set('attachment', NULL);
unset($query->query['attachment']);
$query->set('category_name', NULL);
unset($query->query['category_name']);
$query->set('post_type', $post_data->post_type);
$query->query['post_type'] = $post_data->post_type;
$query->set('name', $url_query[$query_var]);
$query->query['name'] = $url_query[$query_var];
// solve custom rewrites, pagination, etc.
foreach ($url_query as $key => $value) {
if ($key != 'post_type' && substr($value, 0, 8) != '$matches') {
$query->set($key, $value);
$query->query[$key] = $value;
}
}
break 3;
}
}
}
}
}
}
}
}
}
}
}
}
}
function auto_redirect_old() {
global $post;
if (!is_preview() && is_single() && is_object($post) && isset($this->rcptb_selected[$post->post_type])) {
$new_url = get_permalink();
$real_url = $this->get_current_url();
if (substr_count($new_url, '/') != substr_count($real_url, '/') && strstr($real_url, $new_url) == false) {
remove_filter('post_type_link', array($this, 'remove_slug'), 10);
$old_url = get_permalink();
add_filter('post_type_link', array($this, 'remove_slug'), 10, 3);
$fixed_url = str_replace($old_url, $new_url, $real_url);
wp_redirect($fixed_url, 301);
}
}
}
}
function rcptb_remove_plugin_options() {
delete_option('rcptb_selected');
}
add_action('init', array('remove_cpt_base', 'init'), 99);
register_activation_hook(__FILE__, 'flush_rewrite_rules');
register_deactivation_hook(__FILE__, 'flush_rewrite_rules');
register_uninstall_hook(__FILE__, 'rcptb_remove_plugin_options');
To the rewrite you just have to change your current slug from ‘cpt-slug’ to ‘/’ and the with-front: ‘false’. And done, you just resave permalinks and the url shouldn’t display the cpt slug anymore.
Having same issue and came across this answer and none of the above mentioned solution works so tried different plugins and the best which worked, removed base slug and solved 404 error try Remove CPT base

Change apperance of login modal form module drupal 7

I installed the modal forms module in drupal 7 (https://drupal.org/project/modal_forms) to create a modal window login form. But now, I'm tryig to change its appereance with css but I don't know how to do it.
Anyone knows how to change for example the appereance of input submit button applying one css class?
This is my code:
function get_output_ajax(){
$output = array();
ctools_add_js('ajax-responder');
$output[] = ctools_modal_command_dismiss(t('Login success'));
if (isset($_GET['destination'])) {
$output[] = ctools_ajax_command_redirect($_GET['destination']);
}
elseif(module_exists('login_destination')) {
$destination = login_destination_get_destination('login');
$output[] = ctools_ajax_command_redirect($destination['path']);
}
else {
$output[] = ctools_ajax_command_reload();
}
return $output;
}
function modal_forms_login($js = NULL) {
// Fall back if $js is not set.
if (!$js) {
return drupal_get_form('user_login');
}
$output = get_output_ajax();
}
}
else{
$output = get_output_ajax();
}
print ajax_render($output);
} global $user;
if ($user->uid == 0) {
$output = ctools_modal_form_wrapper('user_login', $form_state);
if (!empty($form_state['executed'])) {
$output = get_output_ajax();
}
}
else{
$output = get_output_ajax();
}
print ajax_render($output);
}
Thanks in advance.
Here my solution, it works for me:
function modal_forms_login($js = NULL) {
// Fall back if $js is not set.
if (!$js) {
return drupal_get_form('user_login');
}
ctools_include('modal');
ctools_include('ajax');
$form_state = array(
// 'title' => t('Log in'),
'ajax' => TRUE,
);
global $user;
if ($user->uid == 0) {
$output = ctools_modal_form_wrapper('user_login', $form_state);
//Necesario para editar el boton del login
$cadena = $output[0]['output'];
$patrón = '/class="form-submit"/';
$sustitución = 'class="form-submit btn btn-primary"';
$output[0]['output'] = preg_replace($patrón, $sustitución, $cadena);
if (!empty($form_state['executed'])) {
$output = get_output_ajax();
}
}
else{
$output = get_output_ajax();
}
print ajax_render($output);
}

custom_wp_pagenavi works perfectly in all browsers ecxcept Safari

I am using the following code in my WP theme functions.php page and it works perfectly in all browsers but does not always show up in Safari, where it is intermittent.
When it does not show up on the page, it is in the code, if I look at the source code.
function custom_wp_pagenavi($before = '', $after = '', $prelabel = '', $nxtlabel = '', $pages_to_show = 5, $always_show = false) {
global $request, $posts_per_page, $wpdb, $paged;
if(empty($prelabel)) {
$prelabel = '<strong>«</strong>';
}
if(empty($nxtlabel)) {
$nxtlabel = '<strong>»</strong>';
}
$half_pages_to_show = round($pages_to_show/2);
if (!is_single()) {
if(!is_category()) {
preg_match('#FROM\s(.*)\sORDER BY#siU', $request, $matches);
} else {
preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches);
}
$fromwhere = $matches[1];
$numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
$max_page = ceil($numposts /$posts_per_page);
if(empty($paged)) {
$paged = 1;
}
if($max_page > 1 || $always_show) {
echo "$before <div class=\"wp-pagenavi\"><span class=\"pages\">Page $paged of $max_page:</span>";
if ($paged >= ($pages_to_show-1)) {
echo '« First';
}
previous_posts_link($prelabel);
for($i = $paged - $half_pages_to_show; $i <= $paged + $half_pages_to_show; $i++) {
if ($i >= 1 && $i <= $max_page) {
if($i == $paged) {
echo "<strong class='current'>$i</strong>";
} else {
echo ' '.$i.' ';
}
}
}
next_posts_link($nxtlabel, $max_page);
if (($paged+$half_pages_to_show) < ($max_page)) {
echo 'Last »';
}
echo "</div> $after";
}
}
}
<?php if (function_exists('custom_wp_pagenavi')) : ?>
<?php custom_wp_pagenavi(); ?>
Any suggestions would be greatly appreciated.

Wordpress - Create own admin messages for Custom Post Type

I've created a custom post type called routes and I'd like to be able to return error messages to the screen when something goes wrong during a save/update e.g. The type allows for gpx/kml files to be uploaded and checked that the correct type has been posted. At the moment it just returns if it goes wrong - how can I set an error message?
//Return if file type wrong.
if($file_type != 'application/octet-stream' && $file_type != 'application/gpx+xml' ) {
return;
}
try this
example:
add_admin_message('Please enter valid URL for the project link', true);
add_admin_message('Your custom post type was updated');
source:
<?php
/**
* Messages with the default wordpress classes
*/
function showMessage($message, $errormsg = false)
{
if ($errormsg) {
echo '<div id="message" class="error">';
}
else {
echo '<div id="message" class="updated fade">';
}
echo "<p>$message</p></div>";
}
/**
* Display custom messages
*/
function show_admin_messages()
{
if(isset($_COOKIE['wp-admin-messages-normal'])) {
$messages = strtok($_COOKIE['wp-admin-messages-normal'], "##");
while ($messages !== false) {
showMessage($messages, true);
$messages = strtok("##");
}
setcookie('wp-admin-messages-normal', null);
}
if(isset($_COOKIE['wp-admin-messages-error'])) {
$messages = strtok($_COOKIE['wp-admin-messages-error'], "##");
while ($messages !== false) {
showMessage($messages, true);
$messages = strtok("##");
}
setcookie('wp-admin-messages-error', null);
}
}
/**
* Hook into admin notices
*/
add_action('admin_notices', 'show_admin_messages');
/**
* User Wrapper
*/
function add_admin_message($message, $error = false)
{
if(empty($message)) return false;
if($error) {
setcookie('wp-admin-messages-error', $_COOKIE['wp-admin-messages-error'] . '##' . $message, time()+60);
} else {
setcookie('wp-admin-messages-normal', $_COOKIE['wp-admin-messages-normal'] . '##' . $message, time()+60);
}
}

Resources