echo not working in JomSocial plugin - jomsocial

I am making a JomSocial plugin to get name of the user but when I echo the name it is not displaying the name. Here is my code
<?php
defined('_JEXEC') or die('Restricted access');
require_once JPATH_ROOT .'/components/com_community/libraries/core.php';
class plgCommunityName extends JPlugin{
function getUserDetails(){
$cuser = CFactory::getUser();
$name = $cuser->username;
echo $name;
}
}
?>
How can I do this ?

Try to return $name; instead of echo $name;

It should be rather:
$cuser = CFactory::getUser();
$name = $cuser->getDisplayName();
echo $name;

Related

How can I check a user from wp_user table on a custom login page?

I am building a new login page for a user login page, but I am using the wp_user table. When I am trying to user md5() or wp_hash_password() to check user password, it is not working.
My code is as follows:
<?php if(isset($_POST['submit'])){
//print_r($_POST); die();
$user_email=$_POST['email'];
$user_pass=$_POST['pass'];
$encuser_pass = wp_hash_password( $user_pass );
echo $check_user="select * from wp_users WHERE user_login='$user_email'AND user_pass='$encuser_pass)";
//echo $check_user; die;
$run=$wpdb->get_results($check_user, ARRAY_A);
if(count($run))
{
$_SESSION['email']= $user_email;//here session is used and value of $user_email store in $_SESSION.
wp_redirect( get_site_url().'/dashboard/');
exit;
}
else
{
echo "<script>alert('Email or Password is wrong')</script>";
}
}?>
It's not working. What way I need to implement that?
<?php require_once(ABSPATH . 'wp-includes/class-phpass.php');
<?php if(isset($_POST['submit'])){
$user_email=$_POST['email'];
$user_pass=$_POST['pass'];
global $wpdb;
$check_user="select user_pass from wp_users WHERE user_login='$user_email'";
$wp_hasher = new PasswordHash(8, TRUE);
$password_hashed = $wpdb->get_var($check_user);
if($wp_hasher->CheckPassword($user_pass, $password_hashed)) {
echo "YES, Matched";
} else {
echo "No, Wrong Password";
}
}

How to get parent category name form child category id wordpress

I have child category id in wordpress and i want to get parent category name for the same.i just want to fetch the parent category name only...
You can use this kind of function :
function get_category_parent($child_id, $link=false, $nicename=false){
$return = '';
$parent = &get_category($child_id);
if(is_wp_error($parent)) return $parent;
if($nicename){
$name = $parent->slug;
}else{
$name = $parent->cat_name;
}
if($link){
$return .= ''.$name.'';
}else{
$return .= $name;
}
return $return;
}

My wordpress custom widget mess the entire site, one widget work, add more widget and ruin anything

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.

add_filter function in the theme (wordpress)

I have a function for encrypt the content:
function rewrite_text( $article, $case_sensitive=false ) {
$workwith=$article;
*(hide line code for copyright)....(hide line code for copyright)*
$codul='<script type="text/javascript">
document.write(String.fromCharCode('.$numbers.'));
</script>';
$workwith=$codul;
}
return $workwith;
}
add_filter('the_content', 'rewrite_text', 100);
In my wordpress theme (deTube wordpress theme) have a function for show youtube player (in theme_name/functions.php):
function dp_video($post_id, $autoplay = false) {
$file = get_post_meta($post_id, 'dp_video_file', true);
$file = !empty($file) ? explode("\n", $file) : array();
$url = trim(get_post_meta($post_id, 'dp_video_url', true));
$code = trim(get_post_meta($post_id, 'dp_video_code', true));
if(!empty($code)) {
$code = do_shortcode($code);
if(function_exists('jwplayer_tag_callback'))
$code = jwplayer_tag_callback($code);
$code = extend_video_html($code, $autoplay);
echo '<div class="video-wrap">'.$code.'</div>';
} elseif(!empty($url)) {
$youtube_id = getYouTubeIdFromURL($url);
$video = "<div class=\"video-wrap\"><embed src=\"http://www.youtube.com/v/".$youtube_id."?modestbranding=1&version=3&hl=vi_VN&rel=0&autoplay=1&showsearch=0&iv_load_policy=3&theme=light\" type=\"application/x-shockwave-flash\" allowFullScreen=\"true\" allowScriptAccess=\"always\" width=\"100%\" height=\"100%\"/></div>";
echo $video;
I want to encrypt youtube link (youtube player code) by add_filter function dp_video, using:
add_filter('dp_video', 'rewrite_text', 100);
But it's not working!
Can you help me add filter for dp_video function?
Thank you very much!
If you do add_filter('dp_video') there must be an apply_filters('dp_video') somewhere. If you wanna filter $video for example you can change the last line to
echo apply_filters('dp_video', $video);

Error connecting to wordpress blog from Windows Live Writer

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.

Resources