I am trying to connect to my wordpress 3.4.1 hosted web blog to Windows Live Writer to make blog posts from WLW instead of web interface provided by wordpress.
However i am getting the errors as shown in screenshot:
Also attached is xmlrpc.php code :
<?php
/**
* XML-RPC protocol support for WordPress
*
* #package WordPress
*/
/**
* Whether this is a XMLRPC Request
*
* #var bool
*/
define('XMLRPC_REQUEST', true);
// Some browser-embedded clients send cookies. We don't want them.
$_COOKIE = array();
// A bug in PHP < 5.2.2 makes $HTTP_RAW_POST_DATA not set by default,
// but we can do it ourself.
if ( !isset( $HTTP_RAW_POST_DATA ) ) {
$HTTP_RAW_POST_DATA = file_get_contents( 'php://input' );
}
// fix for mozBlog and other cases where '<?xml' isn't on the very first line
if ( isset($HTTP_RAW_POST_DATA) )
$HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
/** Include the bootstrap for setting up WordPress environment */
include('./wp-load.php');
if ( isset( $_GET['rsd'] ) ) { // http://archipelago.phrasewise.com/rsd
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
?>
<?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
<rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd">
<service>
<engineName>WordPress</engineName>
<engineLink>http://wordpress.org/</engineLink>
<homePageLink><?php bloginfo_rss('url') ?></homePageLink>
<apis>
<api name="WordPress" blogID="1" preferred="true" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" />
<api name="Movable Type" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" />
<api name="MetaWeblog" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" />
<api name="Blogger" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" />
<api name="Atom" blogID="" preferred="false" apiLink="<?php echo site_url('wp-app.php/service', 'rpc') ?>" />
</apis>
</service>
</rsd>
<?php
exit;
}
include_once(ABSPATH . 'wp-admin/includes/admin.php');
include_once(ABSPATH . WPINC . '/class-IXR.php');
include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php');
// Turn off all warnings and errors.
// error_reporting(0);
/**
* Posts submitted via the xmlrpc interface get that title
* #name post_default_title
* #var string
*/
$post_default_title = "";
/**
* Whether to enable XMLRPC Logging.
*
* #name xmlrpc_logging
* #var int|bool
*/
$xmlrpc_logging = 0;
/**
* logIO() - Writes logging info to a file.
*
* #uses $xmlrpc_logging
* #package WordPress
* #subpackage Logging
*
* #param string $io Whether input or output
* #param string $msg Information describing logging reason.
* #return bool Always return true
*/
function logIO($io,$msg) {
global $xmlrpc_logging;
if ($xmlrpc_logging) {
$fp = fopen("../xmlrpc.log","a+");
$date = gmdate("Y-m-d H:i:s ");
$iot = ($io == "I") ? " Input: " : " Output: ";
fwrite($fp, "\n\n".$date.$iot.$msg);
fclose($fp);
}
return true;
}
if ( isset($HTTP_RAW_POST_DATA) )
logIO("I", $HTTP_RAW_POST_DATA);
// Make sure wp_die output is XML
add_filter( 'wp_die_handler', '_xmlrpc_wp_die_filter' );
// Allow for a plugin to insert a different class to handle requests.
$wp_xmlrpc_server_class = apply_filters('wp_xmlrpc_server_class', 'wp_xmlrpc_server');
$wp_xmlrpc_server = new $wp_xmlrpc_server_class;
// Fire off the request
$wp_xmlrpc_server->serve_request();
?>
Asked the webhost team to re install the xmlrpc on the server and it worked.
Related
Fatal error: Cannot redeclare wp_get_attachment_thumb_file()
(previously declared in
/home/lh1fmg9r4ipw/public_html/wp-includes/post.php:6709) in
/home/lh1fmg9r4ipw/public_html/wp-includes/deprecated.php on line 4327
I upgraded the wordpress version to 6.0.3 and I cannot get the site to work again.
attached is the error messages I see once i go to my site
In my error log I see a lot of
"[29-Jan-2023 19:55:40 UTC] PHP Fatal error: Cannot redeclare
wp_get_attachment_thumb_file() (previously declared in
/home/lh1fmg9r4ipw/public_html/wp-includes/post.php:6709) in
/home/lh1fmg9r4ipw/public_html/wp-includes/deprecated.php on line
4327"
Here is wp-includes/deprecated.php on line> 4327
/**
* Retrieves thumbnail for an attachment.
* Note that this works only for the (very) old image metadata style where 'thumb' was set,
* and the 'sizes' array did not exist. This function returns false for the newer image metadata style
* despite that 'thumbnail' is present in the 'sizes' array.
*
* #since 2.1.0
* #deprecated 6.1.0
*
* #param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`.
* #return string|false Thumbnail file path on success, false on failure.
*/
function wp_get_attachment_thumb_file( $post_id = 0 ) {
_deprecated_function( __FUNCTION__, '6.1.0' );
$post_id = (int) $post_id;
$post = get_post( $post_id );
if ( ! $post ) {
return false;
}
// Use $post->ID rather than $post_id as get_post() may have used the global $post object.
$imagedata = wp_get_attachment_metadata( $post->ID );
if ( ! is_array( $imagedata ) ) {
return false;
}
$file = get_attached_file( $post->ID );
if ( ! empty( $imagedata['thumb'] ) ) {
$thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file );
if ( file_exists( $thumbfile ) ) {
/**
* Filters the attachment thumbnail file path.
*
* #since 2.1.0
*
* #param string $thumbfile File path to the attachment thumbnail.
* #param int $post_id Attachment ID.
*/
return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );
}
}
return false;
}
/**
Well maybe this is common knowledge but I went on the backup version. I replaced the "public_html" with on of the unzipped files in the "application_backups" folder. I will know update all the plugins first, then backup, then try to move to 6.1.1
I'm looking to restrict a page content to a specific role, subscriber, AND redirect all other to the Wordpress registration form.
I've tried to do it, but I was getting an error "content is private" and was getting automatically disconnected.
Could anyone be of assistance?
This is a basic page template using conditional statements to restrict users from viewing specific contents pages. That's probably somewhat what you're looking for, at least you will be close, and you can do some research on your own for the rest. I've commented pretty much everything used. Modify it and have fun.
<?php
if ( ! defined( 'ABSPATH' ) ):
exit;
endif;
/**
* is_user_logged_in
* Determines whether the current visitor is a logged in user.
* #link https://developer.wordpress.org/reference/functions/is_user_logged_in/
*
* wp_get_current_user
* Retrieve the current user object.
* #link https://developer.wordpress.org/reference/functions/wp_get_current_user/
* #link https://wordpress.org/support/article/roles-and-capabilities/
*/
$users = wp_get_current_user();
$roles = array( 'administrator', 'editor', 'author', 'subscriber' );
if ( ! is_user_logged_in() || ! array_intersect( $roles, $users->roles ) ):
/**
* wp_logout
* Log the current user out.
* #link https://developer.wordpress.org/reference/functions/wp_logout/
*/
wp_logout();
/**
* wp_redirect
* Redirects to another page.
* #link https://developer.wordpress.org/reference/functions/wp_redirect/
*
* wp_registration_url
* Returns the URL that allows the user to register on the site.
* #link https://developer.wordpress.org/reference/functions/wp_registration_url/
*/
wp_redirect( esc_url( wp_registration_url() ) );
exit;
endif;
/**
* get_header
* Load header template.
* #link https://developer.wordpress.org/reference/functions/get_header/
*/
get_header();
/**
* The Loop
* #link https://developer.wordpress.org/themes/basics/the-loop/
*/
if( have_posts() ):
while( have_posts() ): the_post();
/**
* get_the_title
* Retrieve post title.
* #link https://developer.wordpress.org/reference/functions/get_the_title/
*
* the_title
* Display or retrieve the current post title with optional markup.
* #link https://developer.wordpress.org/reference/functions/the_title/
*/
if( get_the_title() !== '' ):
esc_attr( the_title() );
endif;
/**
* get_the_content
* Retrieve the post content.
* #link https://developer.wordpress.org/reference/functions/get_the_content/
*
* the_content
* Display the post content.
* #link https://developer.wordpress.org/reference/functions/the_content/
*/
if( get_the_content() !== '' ):
esc_attr( the_content() );
endif;
endwhile;
endif;
/**
* get_footer
* Load footer template.
* #link https://developer.wordpress.org/reference/functions/get_footer/
*/
get_footer(); ?>
Learn more
wp_logout # https://developer.wordpress.org/reference/functions/wp_logout/
wp_redirect # https://developer.wordpress.org/reference/functions/wp_redirect/
wp_registration_url # https://developer.wordpress.org/reference/functions/wp_registration_url/
I am trying to change the title of my detail page to the name of the car.
I have made a plugin that fills the detail page with the car information. But now I can't get the add_filter('wp_title') to work in my plugin.
Here is the code I tried:
function init() {
hooks();
}
add_action('wp', 'init');
function hooks() {
if(get_query_var('car_id') != "") {
add_filter('wp_title', 'addTitle', 100);
add_action('wp_head', 'fillHead');
}
add_shortcode('showCar', 'showCar');
}
function addTitle() {
$api_url_klant = API_URL . '/gettitle/' . get_option("ac") . '/' . get_query_var('car_id');
$title = getJSON($api_url_klant);
return $title['merk'] . " " . $title['model'] . " - " . $title['bedrijf'];
}
The addTitle() function works just fine. It returns the right name. Also the add_action('wp_head') works as well. I only can't get the wp_title filter not to work.
Am I executing this filter at the wrong moment or what am I doing wrong?
If anyone else is having problems with this, it may be due to the Yoast plugin. Use:
add_filter( 'pre_get_document_title', function( $title ){
// Make any changes here
return $title;
}, 999, 1 );
I can't tell from the code you have provided, but are you using:
<title><?php wp_title(); ?></title>
in your <head>, under header.php?
UPDATE
Apparently a change was made to the way titles are handled as of 4.4. Here is a link that explains how to use the new code:
https://www.developersq.com/change-page-post-title-wordpress-4-4/
/*
* Override default post/page title - example
* #param array $title {
* The document title parts.
*
* #type string $title Title of the viewed page.
* #type string $page Optional. Page number if paginated.
* #type string $tagline Optional. Site description when on home page.
* #type string $site Optional. Site title when not on home page.
* }
* #since WordPress 4.4
* #website: www.developersq.com
* #author: Aakash Dodiya
*/
add_filter('document_title_parts', 'dq_override_post_title', 10);
function dq_override_post_title($title){
// change title for singular blog post
if( is_singular( 'post' ) ){
// change title parts here
$title['title'] = 'EXAMPLE';
$title['page'] = '2'; // optional
$title['tagline'] = 'Home Of Genesis Themes'; // optional
$title['site'] = 'DevelopersQ'; //optional
}
return $title;
}
I posted this answer to another question but since it is relevant and more up-to-date, I though it might be useful.
How document title is generated has changed since Wordpress v4.4.0. Now wp_get_document_title dictates how title is generated:
/**
* Displays title tag with content.
*
* #ignore
* #since 4.1.0
* #since 4.4.0 Improved title output replaced `wp_title()`.
* #access private
*/
function _wp_render_title_tag() {
if ( ! current_theme_supports( 'title-tag' ) ) {
return;
}
echo '<title>' . wp_get_document_title() . '</title>' . "\n";
}
Here is the code from v5.4.2. Here are the filters you can use to manipulate title tag:
function wp_get_document_title() {
/**
* Filters the document title before it is generated.
*
* Passing a non-empty value will short-circuit wp_get_document_title(),
* returning that value instead.
*
* #since 4.4.0
*
* #param string $title The document title. Default empty string.
*/
$title = apply_filters( 'pre_get_document_title', '' );
if ( ! empty( $title ) ) {
return $title;
}
// --- snipped ---
/**
* Filters the separator for the document title.
*
* #since 4.4.0
*
* #param string $sep Document title separator. Default '-'.
*/
$sep = apply_filters( 'document_title_separator', '-' );
/**
* Filters the parts of the document title.
*
* #since 4.4.0
*
* #param array $title {
* The document title parts.
*
* #type string $title Title of the viewed page.
* #type string $page Optional. Page number if paginated.
* #type string $tagline Optional. Site description when on home page.
* #type string $site Optional. Site title when not on home page.
* }
*/
$title = apply_filters( 'document_title_parts', $title );
// --- snipped ---
return $title;
}
So here are two ways you can do it.
First one uses pre_get_document_title filter which short-circuits the title generation and hence more performant if you are not going make changes on current title:
function custom_document_title( $title ) {
return 'Here is the new title';
}
add_filter( 'pre_get_document_title', 'custom_document_title', 10 );
Second way uses document_title_separator and document_title_parts hooks for the title and the title seperator that are executed later in the function, after title is generated using functions like single_term_title or post_type_archive_title depending on the page and about to be outputted:
// Custom function should return a string
function custom_seperator( $sep ) {
return '>';
}
add_filter( 'document_title_separator', 'custom_seperator', 10 );
// Custom function should return an array
function custom_html_title( $title ) {
return array(
'title' => 'Custom Title',
'site' => 'Custom Site'
);
}
add_filter( 'document_title_parts', 'custom_html_title', 10 );
I have trawled through each and every solution on the web trying 100s of examples.
In the end... Well Done joemaller As putting this first solved everything!
add_filter('wpseo_title', '__return_empty_string');
The simple answer is using this variable.
document_title_parts();
For example:
add_filter( 'document_title_parts', function( $title ){
// Customize here
return clean( $title );
}, 10 );
Output before:
#Page Title
After Output:
Page Title
Thanks.
i really love wordpress with tons of plugin and theme available out there, i just learn how to write my own custom widget.
my widget is work fine when i include it on my theme function. its show on backend and also on frontend just like another widget.
The only problem i got, when i add/create another widgets, the widgets(all widgets) start act wierd.
when i add the widget(s) to widget area it show the options(form) but then option suddently dissapear.
when i try to refresh the page (widget.php) on admin area the options on that widget appear normal and i can modify the value on that widget and save it just like normal widget.
This behavior affect the other functionality in my admin area such ass add image thumbnail is wierd(i can add thumbnail image, but image not shows on the thumbnail section on editor page.
Also with the other functionality, for example when i add new post it show on blank page when i hit save, also the same condition for adding category, page, menu, or anything that say add new. even on saving my theme options it direct me to blank page after i hit save.
this is the widget code.
<?php
class chalax_try_widget extends WP_Widget {
/**
* Register widget with WordPress.
*/
function __construct() {
parent::__construct(
'chalax_try_widget', // Base ID
__('Chalax try List', 'text_domain'), // Name
array( 'description' => __( 'Widget untuk menampilkan daftar artikel/berita tertentu', 'text_domain' ), ) // Args
);
}
/**
* Front-end display of widget.
*
* #see WP_Widget::widget()
*
* #param array $args Widget arguments.
* #param array $instance Saved values from database.
*/
public function widget( $args, $instance ) {
echo $args['before_widget'];
echo $args['before_title'].$instance['title1'].$args['after_title'];
echo "string";
echo $args['after_widget'];
}
/**
* Back-end widget form.
*
* #see WP_Widget::form()
*
* #param array $instance Previously saved values from database.
*/
public function form( $instance ) {
if (isset($instance['title1'])) {
# code...
$title1=$instance['title1'];
}else{
$title1="jajal";
}
?>
<input id="<?php echo $this->get_field_id( 'title1' ); ?>" name="<?php echo $this->get_field_name( 'title1' ); ?>" value="<?php echo $title1 ;?>">
<?php
}
/**
* Sanitize widget form values as they are saved.
*
* #see WP_Widget::update()
*
* #param array $new_instance Values just sent to be saved.
* #param array $old_instance Previously saved values from database.
*
* #return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title1'] = ( ! empty( $new_instance['title1'] ) ) ? strip_tags( $new_instance['title1'] ) : '';
return $instance;
}
} // class Foo_Widget
?>
the widget is work,
but when i try to add another custome widget, say this..
<?php
class chalax_try_widget extends WP_Widget {
/**
* Register widget with WordPress.
*/
function __construct() {
parent::__construct(
'chalax_try_widget', // Base ID
__('Chalax try List', 'text_domain'), // Name
array( 'description' => __( 'Widget untuk menampilkan daftar artikel/berita tertentu', 'text_domain' ), ) // Args
);
}
/**
* Front-end display of widget.
*
* #see WP_Widget::widget()
*
* #param array $args Widget arguments.
* #param array $instance Saved values from database.
*/
public function widget( $args, $instance ) {
echo $args['before_widget'];
echo $args['before_title'].$instance['title1'].$args['after_title'];
echo "string";
echo $args['after_widget'];
}
/**
* Back-end widget form.
*
* #see WP_Widget::form()
*
* #param array $instance Previously saved values from database.
*/
public function form( $instance ) {
if (isset($instance['title1'])) {
# code...
$title1=$instance['title1'];
}else{
$title1="jajal";
}
?>
<input id="<?php echo $this->get_field_id( 'title1' ); ?>" name="<?php echo $this->get_field_name( 'title1' ); ?>" value="<?php echo $title1 ;?>">
<?php
}
/**
* Sanitize widget form values as they are saved.
*
* #see WP_Widget::update()
*
* #param array $new_instance Values just sent to be saved.
* #param array $old_instance Previously saved values from database.
*
* #return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title1'] = ( ! empty( $new_instance['title1'] ) ) ? strip_tags( $new_instance['title1'] ) : '';
return $instance;
}
} // class Foo_Widget
?>
then the problem comes up..
i follow the tutorial even copy this functions from codex..
You should be getting a php error if you do the above. Basically you are declaring a class with the same name twice (same effect as declaring a function twice) Just rename the 2nd class.
Also you are missing the code to register the widgets, i assume it is there as something is changing. If not, add it in, its in the codex as well.
I have a widget that retrieves and displays the latest comments for a WordPress site. It displays the comment author, Gravatar, comment and date / time.
The function to display the comments is in a class.
The issue that I am having is that whenever i display this widget it messes up or conflicts with the number of comments that are returned for my WordPress theme.
Example. In the widget choose to display 5 comments. On a page on the site I have a post that has 8 comments. When the widget is enabled only 6 of those 8 comments are displayed.
If I disable the widget, all the comments display.
This is the function to display the comments
/**
* Retrieves the latest comments
*
* Shows a list of latest comments ordered by the date added
*
* #param int $limit - The number of posts to display
* #param int $chars - The number of characters to display for the post body
* #param int $size - Size of the comment Gravatar
* #param boolean $displayCommentsIcon - Whether to display the comment Gravatar
*
*/
public function aaw_get_latest_comments($display_comments_icon = true, $comments_icon_size = 50, $comments_amount = 5, $comments_chars = 35, $display_comments_date = true) {
global $comments;
$com_excerpt = '';
$aaw_comments = get_comments(array('number' => $comments_amount, 'status' => 'approve'));
if($aaw_comments){
foreach((array)$aaw_comments as $aaw_comment){
if($comments_chars > 0) {
$com_excerpt = self::aaw_snippet_text($aaw_comment->comment_content, $comments_chars);
}
echo '<li>';
if($display_comments_icon == 'true'){
echo '<a href="'.esc_url(get_comment_link($aaw_comment->comment_ID) ).'" title="'. __('Commented on: ', $this->hook). $aaw_comment->post_title.'">';
echo get_avatar($aaw_comment, $comments_icon_size);
echo '</a>';
}
echo '<div class="aaw_info">';
echo '<a href="'.esc_url(get_comment_link($aaw_comment->comment_ID) ).'" title="'. __('Commented on: ', $this->hook). $aaw_comment->post_title.'">';
echo '<i>'.strip_tags($aaw_comment->comment_author).'</i>: '.strip_tags($com_excerpt).'...';
echo '</a>';
if($display_comments_date == 'true'){
echo '<span class="aaw_meta">'.get_comment_date('j M Y',$aaw_comment->comment_ID).' '.__('at', $this->hook).' '.get_comment_date('g:i a',$aaw_comment->comment_ID).'</span>';
}
echo '</div>';
echo '</li>';
}
} else {
echo '<li>'.__('No comments available', $this->hook).'</li>'."\n";
}
}
This is how I call the function:
<?php $advanced_activity_widget->aaw_get_latest_comments($display_comments_icon == 'true' ? 'true' : 'false', $comments_icon_size, $comments_amount, $comments_chars, $display_comments_date == 'true' ? 'true' : 'false'); ?>
At first I thought is was the Gravatar causing the conflict however I removed it and it didn't make a change.
Any help would be greatly appreciated.
Thanks
EDIT:
It seems to be the get_comment_link() that is causing the problems.
If I remove both instances of that function call the widget and comments display fine.
I have tried: wp_reset_postdata(); wp_reset_query(); rewind_posts(); all to no effect.
Try adding a call to wp_reset_query() after your foreach loop.
http://codex.wordpress.org/Function_Reference/wp_reset_query