Annonce

Faites la différence entre le service WordPress.com et l'application libre WordPress.

Mettez-vous à jour ! WordPress 3.3.2 est disponible en français.

Annonce 1 : Le Codex en français a besoin de vous pour avancer !
Annonce 2 : Avant de poster, n'oubliez pas de faire une petite recherche et de lire les règles de ce forum.
Annonce 3 : Lisez notre blog, il regorge de bonnes informations.
Annonce 4 : Rejoignez-nous sur Facebook, Google + et sur Twitter

#1 06-02-2012 20:03:11

bakalegum
Connaisseur WP
Date d'inscription: 04-08-2009
Messages: 19

dupliquer un widget

Bonjour à tous,

je suis sous wordpress 3.3.1 et je cherche a dupliquer un widget, non pas "juste" avoir la possibilté de le mettre deux fois dans la page, mais bien avoir 2 dossier différents dans le dossier plugin.

Il s'agit du plugin suivant :http://wordpress.org/extend/plugins/sidebar-login/

Je me suis dit, je n'ai qu'a copier le dossier sidebar-login en créant alors sidebar-login2 et a renommer tous les sidebar-login en sidebar-login2.. mais ca ne fonctionne pas.
J'ai vraiment passé tout l’après midi sur ce soucis, et je viens vers vous pour savoir si vous voyez quoi faire. voici les 2 fichiers qui me semblent à modifier:


l'objectif avoir dans ma partie widget "sidebar-login" et "siderbar-login2"

le fichier admin.php

Code: html

<?php

add_action( 'admin_init', 'sidebar_login_options_init' );
add_action( 'admin_menu', 'sidebar_login_options_add_page' );

/**
 * Define Options
 */
global $sidebar_login_options;

$sidebar_login_options = (
	array( 
		array(
			'', 
			array(
				array(
					'name' 		=> 'sidebarlogin_heading', 
					'std' 		=> __('Login', 'sblogin'), 
					'label' 	=> __('Logged out heading', 'sblogin'),  
					'desc'		=> __('Heading for the widget when the user is logged out.', 'sblogin')
				),
				array(
					'name' 		=> 'sidebarlogin_welcome_heading', 
					'std' 		=> __('Welcome %username%', 'sblogin'), 
					'label' 	=> __('Logged in heading', 'sblogin'),  
					'desc'		=> __('Heading for the widget when the user is logged in.', 'sblogin')
				),
			)
		),
		array(
			__('Redirects', 'sblogin'), 
			array(
				array(
					'name' 		=> 'sidebarlogin_login_redirect', 
					'std' 		=> '', 
					'label' 	=> __('Login redirect', 'sblogin'),  
					'desc'		=> __('Url to redirect the user to after login. Leave blank to use the current page.', 'sblogin'),
					'placeholder' => 'http://'
				),
				array(
					'name' 		=> 'sidebarlogin_logout_redirect', 
					'std' 		=> '', 
					'label' 	=> __('Logout redirect', 'sblogin'),  
					'desc'		=> __('Url to redirect the user to after logout. Leave blank to use the current page.', 'sblogin'),
					'placeholder' => 'http://'
				),
			)
		),
		array(
			__('Links', 'sblogin'), 
			array(
				array(
					'name' 		=> 'sidebarlogin_register_link', 
					'std' 		=> '1', 
					'label' 	=> __('Show Register Link', 'sblogin'),  
					'desc'		=> sprintf( __('The <a href="%s" target="_blank">\'Anyone can register\'</a> setting must be turned on for this option to work.', 'sblogin'), admin_url('options-general.php')),
					'type' 		=> 'checkbox'
				),
				array(
					'name' 		=> 'sidebarlogin_forgotton_link', 
					'std' 		=> '1', 
					'label' 	=> __('Show Lost Password Link', 'sblogin'),  
					'desc'		=> '',
					'type' 		=> 'checkbox'
				),
				array(
					'name' 		=> 'sidebar_login_avatar', 
					'std' 		=> '1', 
					'label' 	=> __('Show Logged in Avatar', 'sblogin'),  
					'desc'		=> '',
					'type' 		=> 'checkbox'
				),
				array(
					'name' 		=> 'sidebarlogin_logged_in_links', 
					'std' 		=> "<a href=\"".get_bloginfo('wpurl')."/wp-admin/\">".__('Dashboard','sblogin')."</a>\n<a href=\"".get_bloginfo('wpurl')."/wp-admin/profile.php\">".__('Profile','sblogin')."</a>", 
					'label' 	=> __('Logged in links', 'sblogin'),  
					'desc'		=> sprintf( __('One link per line. Note: Logout link will always show regardless. Tip: Add <code>|true</code> after a link to only show it to admin users or alternatively use a <code>|user_capability</code> and the link will only be shown to users with that capability (see <a href=\'http://codex.wordpress.org/Roles_and_Capabilities\' target=\'_blank\'>Roles and Capabilities</a>).<br/> You can also type <code>%%USERNAME%%</code> and <code>%%USERID%%</code> which will be replaced by the user\'s info. Default: <br/>&lt;a href="%s/wp-admin/"&gt;Dashboard&lt;/a&gt;<br/>&lt;a href="%s/wp-admin/profile.php"&gt;Profile&lt;/a&gt;', 'sblogin'), get_bloginfo('wpurl'), get_bloginfo('wpurl') ),
					'type' 		=> 'textarea'
				),
			)
		)
	)
);
	
/**
 * Init plugin options to white list our options
 */
function sidebar_login_options_init() {

	global $sidebar_login_options;

	foreach($sidebar_login_options as $section) {
		foreach($section[1] as $option) {
			if (isset($option['std'])) add_option($option['name'], $option['std']);
			register_setting( 'sidebar-login', $option['name'] );
		}
	}

	
}

/**
 * Load up the menu page
 */
function sidebar_login_options_add_page() {
	add_options_page(__('Sidebar Login','sblogin'), __('Sidebar Login','sblogin'), 'manage_options', 'sidebar-login', 'sidebar_login_options');
}

/**
 * Create the options page
 */
function sidebar_login_options() {
	global $sidebar_login_options;

	if ( ! isset( $_REQUEST['settings-updated'] ) ) $_REQUEST['settings-updated'] = false;

	?>
	<div class="wrap">
		<?php screen_icon(); echo "<h2>" .__( 'Sidebar Login Options','sblogin') . "</h2>"; ?>
		
		<form method="post" action="options.php">
		
			<?php settings_fields( 'sidebar-login' ); ?>
	
			<?php
			foreach($sidebar_login_options as $section) {
			
				if ($section[0]) echo '<h3 class="title">'.$section[0].'</h3>';
				
				echo '<table class="form-table">';
				
				foreach($section[1] as $option) {
					
					echo '<tr valign="top"><th scope="row">'.$option['label'].'</th><td>';
					
					if (!isset($option['type'])) $option['type'] = '';
					
					switch ($option['type']) {
						
						case "checkbox" :
						
							$value = get_option($option['name']);
							
							?><input id="<?php echo $option['name']; ?>" name="<?php echo $option['name']; ?>" type="checkbox" value="1" <?php checked( '1', $value ); ?> /><?php
						
						break;
						case "textarea" :
							
							$value = get_option($option['name']);
							
							?><textarea id="<?php echo $option['name']; ?>" class="large-text" cols="50" rows="10" name="<?php echo $option['name']; ?>" placeholder="<?php if (isset($option['placeholder'])) echo $option['placeholder']; ?>"><?php echo esc_textarea( $value ); ?></textarea><?php
						
						break;
						default :
							
							$value = get_option($option['name']);
							
							?><input id="<?php echo $option['name']; ?>" class="regular-text" type="text" name="<?php echo $option['name']; ?>" value="<?php esc_attr_e( $value ); ?>" placeholder="<?php if (isset($option['placeholder'])) echo $option['placeholder']; ?>" /><?php
						
						break;
						
					}
					
					if ($option['desc']) echo '<span class="description">'.$option['desc'].'</span>';
					
					echo '</td></tr>';
				}
				
				echo '</table>';
				
			}
			?>

			<p class="submit">
				<input type="submit" class="button-primary" value="<?php _e( 'Save Options', 'sblogin'); ?>" />
			</p>
		</form>
	</div>
	<?php
}

Code: html

<?php
/*
Plugin Name: Sidebar Login
Plugin URI: http://wordpress.org/extend/plugins/sidebar-login/
Description: Easily add an ajax-enhanced login widget to your site's sidebar.
Version: 2.3.4
Author: Mike Jolley
Author URI: http://mikejolley.com
*/

load_plugin_textdomain('sblogin', WP_PLUGIN_URL.'/sidebar-login/langs/', 'sidebar-login/langs/');

if (is_admin()) include( WP_PLUGIN_DIR . '/sidebar-login/admin.php' );

/* Call via function */
function sidebarlogin( $args = '' ) {
	
	if (!is_array($args)) parse_str($args, $args);
	
	$defaults = array(
		'before_widget'=>'',
		'after_widget'=>'',
		'before_title'=>'<h2>',
		'after_title'=>'</h2>'
	);
	$args = array_merge($defaults, $args);
	
	widget_wp_sidebarlogin($args);
}

/* The widget */
function widget_wp_sidebarlogin($args) {
	global $user_ID, $current_user;
	
	/* To add more extend i.e when terms came from themes - suggested by dev.xiligroup.com */
	$defaults = array(
		'thelogin'=>'',
		'thewelcome'=>'',
		'theusername'=>__('Username:','sblogin'),
		'thepassword'=>__('Password:','sblogin'),
		'theremember'=>__('Remember me','sblogin'),
		'theregister'=>__("INSCRIVEZ-VOUS \n creez vote bateau maintenant",'sblogin'),
		'thepasslostandfound'=>__('Password Lost and Found','sblogin'),
		'thelostpass'=>	__('Lost your password?','sblogin'),
		'thelogout'=> __('Logout','sblogin')
	);
	
	$args = array_merge($defaults, $args);
	extract($args);		
	
	get_currentuserinfo();

	if ($user_ID != '') {
	
		// User is logged in

		echo $before_widget ;
		
	

		
		

		
		
		?>
				
<TABLE BORDER="0" style="width: 1024px; height:116px;">
		
<TR><TD style="width: 40%; text-align: left;">

<div id="affichagecommentaire" style="cursor: pointer; float: right;  ">
<P style="text-align:center; margin-bottom: 0px;"><a id="roll2" href="http://ns300444.ovh.net/~bateau/?page_id=49">

<img width="116" height="408" src="http://ns300444.ovh.net/~bateau/img/bouton4.png">

</a></p>
</div>
</TD><TD style="width: 20%; text-align: left;" >


<P style="text-align:center;margin-bottom: 0px;"><img style="height:111px" src="http://ns300444.ovh.net/~bateau/img/logo.png"></P>



</TD>

<TD style="width: 40%; text-align: left;" >






<div id="connect" style="float: right; background-image: url('http://ns300444.ovh.net/~bateau/img/bouton6.png'); height: 116px; background-repeat: no-repeat;">






<TABLE border="0" style="margin-top: 12px;">
<TR><TD style="text-align: center; height: 5px;" COLSPAN=2>




<?php
		global $current_user;
  		get_currentuserinfo();
		
		if (empty($thewelcome)) $thewelcome = str_replace('%username%',ucwords($current_user->display_name),get_option('sidebarlogin_welcome_heading'));
		
		echo  $thewelcome;

?>


</TD></TR>


<TR><TD style="text-align: center; height: 21px;" COLSPAN=2>







</TD></TR>


<TR><TD style="text-align: center; color: white; padding-left: 10px; padding-right: 10px; width: 186px;">
<a href="http://ns300444.ovh.net/~bateau/?page_id=51">G&eacute;rer votre compte</a>
</TD><TD style="text-align: center; color: white; padding-left: 10px; padding-right: 10px; width: 186px;">
<a href="http://ns300444.ovh.net/~bateau/?page_id=73">&Eacute;diter vos informations</a>

</TD></TR>
<TR><TD style="text-align:center; color:white">

<a href="http://ns300444.ovh.net/~bateau/?page_id=49">Acc&eacute;der au logiciel</a>

</TD><TD style="text-align: center; color: white; padding-top: 5px;">

<?php
$redir = trim(stripslashes(get_option('sidebarlogin_logout_redirect')));
		if (!$redir || empty($redir)) $redir = sidebar_login_current_url('nologout');
		echo '<a href="'.wp_logout_url($redir).'">'.$thelogout.'</a>';
		?>

</TD></TR>


</TABLE>

</div>
	
			
			
			
		







			
			



</TD></TR>






</TABLE>
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		<?php
		
		
		
		
		
		
	} else {
	
		// User is NOT logged in!!!
		
		if (empty($thelogin)) $thelogin = get_option('sidebarlogin_heading');
		
		echo $before_widget . $before_title .'<span>'. $thelogin .'</span>' . $after_title;

		global $login_errors;

		if ( is_wp_error($login_errors) && $login_errors->get_error_code() ) {
			
			foreach ($login_errors->get_error_messages() as $error) {
				$error = apply_filters('sidebar_login_error', $error);
				echo '<div class="login_error">' . $error . "</div>\n";
				break;
			}
				
		}
		
		// Get redirect URL
		$redirect_to = trim(stripslashes(get_option('sidebarlogin_login_redirect')));
		
		if (empty($redirect_to)) :
			if (isset($_REQUEST['redirect_to'])) 
				$redirect_to = $_REQUEST['redirect_to'];
			else
				$redirect_to = sidebar_login_current_url('nologout');
		endif;
		
		if ( force_ssl_admin() ) $redirect_to = str_replace( 'http:', 'https:', $redirect_to );
		
			$links2 = '';	
	
		
		
			$links = '';	
		if (get_option('users_can_register') && get_option('sidebarlogin_register_link')=='1') { 

			if (!is_multisite()) {
				
				$links .= '<li><a href="'.get_bloginfo('wpurl').'/wp-login.php?action=register" rel="nofollow">'.$theregister.'</a></li>';

			} else {
				
				$links .= '<li><a href="'.get_bloginfo('wpurl').'/wp-signup.php" rel="nofollow">'.$theregister.'</a></li>';

			}
		}


		 
		
		
		
		
		
		
		
		// login form
		if (force_ssl_login() || force_ssl_admin()) $sidebarlogin_post_url = str_replace('http://', 'https://', sidebar_login_current_url()); else $sidebarlogin_post_url = sidebar_login_current_url();
		?>
		<form style="height: 116px;" method="post" action="<?php echo $sidebarlogin_post_url; ?>">
		<TABLE BORDER="0" style="width: 1024px; height:116px;">		
<TR><TD style="width: 40%; text-align: left;">
<div id="affichagecommentaire" style="cursor: pointer; float: right;  ">
<P style="text-align:center; margin-bottom: 0px;"><a id="roll" href="http://ns300444.ovh.net/~bateau/wp-login.php?action=register">
<img width="116" height="408" src="http://ns300444.ovh.net/~bateau/img/bouton2.png">
</a></p>
</div>
</TD><TD style="width: 20%; text-align: left;" >
<P style="text-align:center;margin-bottom: 0px;"><img style="height:111px" src="http://ns300444.ovh.net/~bateau/img/logo.png"></P>
</TD>
<TD style="width: 40%; text-align: left;" >
<div id="connect" style="float: right; background-image: url('http://ns300444.ovh.net/~bateau/img/bouton.png'); height: 116px; background-repeat: no-repeat;">
<TABLE border="0" style="margin-top: 31px;">
<TR><TD style="text-align: center; height: 5px;" COLSPAN=2></TD></TR>
<TR><TD style="text-align: center; color: white; padding-left: 10px; padding-right: 10px;">
Nom d'utilisateur :
<input name="log" style="width:180px; height: 25px;" value="<?php if (isset($_POST['log'])) echo esc_attr(stripslashes($_POST['log'])); ?>" class="text" id="user_login" type="text" />
</TD><TD style="text-align: center; color: white; padding-left: 10px; padding-right: 10px;">
Mot de passe :
<a href="http://ns300444.ovh.net/~bateau/wp-login.php?action=lostpassword">
perdu?
</a>
<input name="pwd" style="width:180px; height: 25px;" class="text" id="user_pass" type="password" />
</TD></TR>
<TR><TD style="text-align:center; color:white">
<input name="rememberme" class="checkbox" id="rememberme" value="forever" type="checkbox" /> 
Se souvenir de moi
</TD><TD style="text-align: center; color: white; padding-top: 5px;">	
				<input type="submit" name="wp-submit" id="wp-submit" value="<?php _e('Se connecter &raquo;', 'sblogin'); ?>" />
				<input type="hidden" name="redirect_to" class="redirect_to" value="<?php echo $redirect_to; ?>" />
				<input type="hidden" name="sidebarlogin_posted" value="1" />
				<input type="hidden" name="testcookie" value="1" />	
</TD></TR>
</TABLE></div>
</TD></TR>
</TABLE></form>
		<?php 			
		// Output other links

	}		
		
	// echo widget closing tag
	echo $after_widget;
}

/* Init widget/styles/scripts */
function widget_wp_sidebarlogin_init() {
	
	$plugin_url = (is_ssl()) ? str_replace('http://','https://', WP_PLUGIN_URL) : WP_PLUGIN_URL;
	
	// CSS
	$sidebar_login_css = $plugin_url . '/sidebar-login/style.css';
    wp_register_style('wp_sidebarlogin_css_styles', $sidebar_login_css);
    wp_enqueue_style('wp_sidebarlogin_css_styles');
    
	// Scripts
	$block_ui = $plugin_url . '/sidebar-login/js/blockui.js';
	$sidebar_login_script = $plugin_url . '/sidebar-login/js/sidebar-login.js';
	
	wp_register_script('blockui', $block_ui, array('jquery'), '1.0' );
	wp_register_script('sidebar-login', $sidebar_login_script, array('jquery', 'blockui'), '1.0' );
	wp_enqueue_script('jquery');
	wp_enqueue_script('blockui');
	wp_enqueue_script('sidebar-login');
	
	// Pass variables to script
	$sidebar_login_params = array(
		'ajax_url' 				=> (is_ssl()) ? str_replace('http:', 'https:', admin_url('admin-ajax.php')) : str_replace('https:', 'http:', admin_url('admin-ajax.php')),
		'login_nonce' 			=> wp_create_nonce("sidebar-login-action")
	);
	wp_localize_script( 'sidebar-login', 'sidebar_login_params', $sidebar_login_params );
	
	// Register widget
	class SidebarLoginMultiWidget extends WP_Widget {
	    function SidebarLoginMultiWidget() {  
	        $widget_ops = array('description' => __( 'Sidebar Login.','sblogin') );
			$this->WP_Widget('wp_sidebarlogin', __('Sidebar Login','sblogin'), $widget_ops);  
	    }
	    function widget($args, $instance) {    
	        
	        widget_wp_sidebarlogin($args);
	
	    }
	} 
	register_widget('SidebarLoginMultiWidget');
	
}
add_action('init', 'widget_wp_sidebarlogin_init', 1);

/* Login Action */
function widget_wp_sidebarlogin_check() {

	if (isset($_POST['sidebarlogin_posted'])) {
		
		global $login_errors;
		
		// Get redirect URL
		$redirect_to = trim(stripslashes(get_option('sidebarlogin_login_redirect')));
		
		if (empty($redirect_to)) :
			if (isset($_REQUEST['redirect_to'])) 
				$redirect_to = $_REQUEST['redirect_to'];
			else
				$redirect_to = sidebar_login_current_url('nologout');
		endif;

		// Check for Secure Cookie
		$secure_cookie = '';
		
		// If the user wants ssl but the session is not ssl, force a secure cookie.
		if ( !empty($_POST['log']) && !force_ssl_admin() ) {
			$user_name = sanitize_user($_POST['log']);
			if ( $user = get_userdatabylogin($user_name) ) {
				if ( get_user_option('use_ssl', $user->ID) ) {
					$secure_cookie = true;
					force_ssl_admin(true);
				}
			}
		}
		
		if ( force_ssl_admin() ) $secure_cookie = true;
		if ( $secure_cookie=='' && force_ssl_login() ) $secure_cookie = false;

		// Login
		$user = wp_signon('', $secure_cookie);

		// Redirect filter
		if ( $secure_cookie && strstr($redirect_to, 'wp-admin') ) $redirect_to = str_replace('http:', 'https:', $redirect_to);
		
		// Check the username
		if ( !$_POST['log'] ) :
			$user = new WP_Error();
			$user->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.', 'sblogin'));
		elseif ( !$_POST['pwd'] ) :
			$user = new WP_Error();
			$user->add('empty_username', __('<strong>ERROR</strong>: Please enter your password.', 'sblogin'));
		endif;
		
		// Redirect if successful
		if ( !is_wp_error($user) ) :
			wp_safe_redirect( apply_filters('login_redirect', $redirect_to, isset( $redirect_to ) ? $redirect_to : '', $user) );
			exit;
		endif;
		
		$login_errors = $user;
			
	}
}
add_action('init', 'widget_wp_sidebarlogin_check', 0);


/**
 * Process ajax login
 */
add_action('wp_ajax_sidebar_login_process', 'sidebar_login_ajax_process');
add_action('wp_ajax_nopriv_sidebar_login_process', 'sidebar_login_ajax_process');

function sidebar_login_ajax_process() {

	check_ajax_referer( 'sidebar-login-action', 'security' );
	
	// Get post data
	$creds = array();
	$creds['user_login'] 	= esc_attr($_POST['user_login']);
	$creds['user_password'] = esc_attr($_POST['user_password']);
	$creds['remember'] 		= esc_attr($_POST['remember']);
	$redirect_to 			= esc_attr($_POST['redirect_to']);
	
	// Check for Secure Cookie
	$secure_cookie = '';
	
	// If the user wants ssl but the session is not ssl, force a secure cookie.
	if ( !empty($_POST['log']) && !force_ssl_admin() ) {
		$user_name = sanitize_user($_POST['log']);
		if ( $user = get_userdatabylogin($user_name) ) {
			if ( get_user_option('use_ssl', $user->ID) ) {
				$secure_cookie = true;
				force_ssl_admin(true);
			}
		}
	}
	
	if ( force_ssl_admin() ) $secure_cookie = true;
	if ( $secure_cookie=='' && force_ssl_login() ) $secure_cookie = false;

	// Login
	$user = wp_signon($creds, $secure_cookie);
	
	// Redirect filter
	if ( $secure_cookie && strstr($redirect_to, 'wp-admin') ) $redirect_to = str_replace('http:', 'https:', $redirect_to);

	// Result
	$result = array();
	
	if ( !is_wp_error($user) ) :
		$result['success'] = 1;
		$result['redirect'] = $redirect_to;
	else :
		$result['success'] = 0;
		foreach ($user->errors as $error) {
			$result['error'] = $error[0];
			break;
		}
	endif;
	
	echo json_encode($result);

	die();
}


/* Get Current URL */
if ( !function_exists('sidebar_login_current_url') ) {
	function sidebar_login_current_url( $url = '' ) {
	
		$pageURL  = 'http://';
		$pageURL .= $_SERVER['HTTP_HOST'];
		$pageURL .= $_SERVER['REQUEST_URI'];
		if ( force_ssl_admin() ) $pageURL = str_replace( 'http:', 'https:', $pageURL );
	
		if ($url != "nologout") {
			if (!strpos($pageURL,'_login=')) {
				$rand_string = md5(uniqid(rand(), true));
				$rand_string = substr($rand_string, 0, 10);
				$pageURL = add_query_arg('_login', $rand_string, $pageURL);
			}	
		}
		
		return $pageURL;
	}
}

Hors ligne

 

#2 07-02-2012 12:02:01

bakalegum
Connaisseur WP
Date d'inscription: 04-08-2009
Messages: 19

Re: dupliquer un widget

Voici ce que je modifie si je veux creer un novua widget sidebar-loginX

MAis bien sur ca ne march epas ( j 'ai bien modifié les chemins et noms des fichiers)

Code: html

<?php
/*
Plugin Name: Sidebar Login
Plugin URI: http://wordpress.org/extend/plugins/sidebar-loginX/
Description: Easily add an ajax-enhanced login widget to your site's sidebar.
Version: 2.3.4
Author: Mike Jolley
Author URI: http://mikejolley.com
*/

load_plugin_textdomain('sblogin', WP_PLUGIN_URL.'/sidebar-loginX/langs/', 'sidebar-loginX/langs/');

if (is_admin()) include( WP_PLUGIN_DIR . '/sidebar-loginX/admin.php' );

/* Call via function */
function sidebarloginX( $args = '' ) {
	
	if (!is_array($args)) parse_str($args, $args);
	
	$defaults = array(
		'before_widget'=>'',
		'after_widget'=>'',
		'before_title'=>'<h2>',
		'after_title'=>'</h2>'
	);
	$args = array_merge($defaults, $args);
	
	widget_wp_sidebarloginX($args);
}

/* The widget */
function widget_wp_sidebarloginX($args) {
	global $user_ID, $current_user;
	
	/* To add more extend i.e when terms came from themes - suggested by dev.xiligroup.com */
	$defaults = array(
		'thelogin'=>'',
		'thewelcome'=>'',
		'theusername'=>__('Username:','sblogin'),
		'thepassword'=>__('Password:','sblogin'),
		'theremember'=>__('Remember me','sblogin'),
		'theregister'=>__('Register','sblogin'),
		'thepasslostandfound'=>__('Password Lost and Found','sblogin'),
		'thelostpass'=>	__('Lost your password?','sblogin'),
		'thelogout'=> __('Logout','sblogin')
	);
	
	$args = array_merge($defaults, $args);
	extract($args);		
	
	get_currentuserinfo();

	if ($user_ID != '') {
	
		// User is logged in
		global $current_user;
  		get_currentuserinfo();
		
		if (empty($thewelcome)) $thewelcome = str_replace('%username%',ucwords($current_user->display_name),get_option('sidebarloginX_welcome_heading'));
		
		echo $before_widget . $before_title .$thewelcome. $after_title;
		
		if (get_option('sidebar_loginX_avatar')=='1') echo '<div class="avatar_container">'.get_avatar($user_ID, $size = '38').'</div>';
		
		echo '<ul class="pagenav">';
		
		if(isset($current_user->user_level) && $current_user->user_level) $level = $current_user->user_level;
				
		$links = do_shortcode(trim(get_option('sidebarloginX_logged_in_links')));
		
		$links = explode("\n", $links);
		if (sizeof($links)>0)
		foreach ($links as $l) {
			$l = trim($l);
			if (!empty($l)) {
				$link = explode('|',$l);
				if (isset($link[1])) {
					$cap = strtolower(trim($link[1]));
					if ($cap=='true') {
						if (!current_user_can( 'manage_options' )) continue;
					} else {
						if (!current_user_can( $cap )) continue;
					}
				}
				// Parse %USERNAME%
				$link[0] = str_replace('%USERNAME%',sanitize_title($current_user->user_login),$link[0]);
				$link[0] = str_replace('%username%',sanitize_title($current_user->user_login),$link[0]);
				// Parse %USERID%
				$link[0] = str_replace('%USERID%',$current_user->ID,$link[0]);
				$link[0] = str_replace('%userid%',$current_user->ID,$link[0]);
				echo '<li class="page_item">'.$link[0].'</li>';
			}
		}
		
		$redir = trim(stripslashes(get_option('sidebarloginX_logout_redirect')));
		if (!$redir || empty($redir)) $redir = sidebar_loginX_current_url('nologout');
		
		echo '<li class="page_item"><a href="'.wp_logout_url($redir).'">'.$thelogout.'</a></li></ul>';
		
	} else {
	
		// User is NOT logged in!!!
		
		if (empty($thelogin)) $thelogin = get_option('sidebarloginX_heading');
		
		echo $before_widget . $before_title .'<span>'. $thelogin .'</span>' . $after_title;

		global $login_errors;

		if ( is_wp_error($login_errors) && $login_errors->get_error_code() ) {
			
			foreach ($login_errors->get_error_messages() as $error) {
				$error = apply_filters('sidebar_loginX_error', $error);
				echo '<div class="login_error">' . $error . "</div>\n";
				break;
			}
				
		}
		
		// Get redirect URL
		$redirect_to = trim(stripslashes(get_option('sidebarloginX_login_redirect')));
		
		if (empty($redirect_to)) :
			if (isset($_REQUEST['redirect_to'])) 
				$redirect_to = $_REQUEST['redirect_to'];
			else
				$redirect_to = sidebar_loginX_current_url('nologout');
		endif;
		
		if ( force_ssl_admin() ) $redirect_to = str_replace( 'http:', 'https:', $redirect_to );
		
		// login form
		if (force_ssl_login() || force_ssl_admin()) $sidebarloginX_post_url = str_replace('http://', 'https://', sidebar_loginX_current_url()); else $sidebarloginX_post_url = sidebar_loginX_current_url();
		?>
		<form method="post" action="<?php echo $sidebarloginX_post_url; ?>">
		
			<p><label for="user_login"><?php echo $theusername; ?></label> <input name="log" value="<?php if (isset($_POST['log'])) echo esc_attr(stripslashes($_POST['log'])); ?>" class="text" id="user_login" type="text" /></p>
			<p><label for="user_pass"><?php echo $thepassword; ?></label> <input name="pwd" class="text" id="user_pass" type="password" /></p>			
	
			<?php
				// OpenID Plugin (http://wordpress.org/extend/plugins/openid/) Integration
				if (function_exists('openid_wp_login_form')) :
					echo '
						<hr id="openid_split" />
						<p>
							<label for="openid_field">' . __('Or login using an <a href="http://openid.net/what/" title="Learn about OpenID">OpenID</a>', 'sblogin') . '</label>
							<input type="text" name="openid_identifier" id="openid_field" class="input mid" value="" /></label>
						</p>
					';		
				endif;
			?>
			
			<p class="rememberme"><input name="rememberme" class="checkbox" id="rememberme" value="forever" type="checkbox" /> <label for="rememberme"><?php echo $theremember; ?></label></p>
			
			<p class="submit">
				<input type="submit" name="wp-submit" id="wp-submit" value="<?php _e('Login &raquo;', 'sblogin'); ?>" />
				<input type="hidden" name="redirect_to" class="redirect_to" value="<?php echo $redirect_to; ?>" />
				<input type="hidden" name="sidebarloginX_posted" value="1" />
				<input type="hidden" name="testcookie" value="1" />
			</p>
			
			<?php if (function_exists('fbc_init_auth')) do_action('fbc_display_login_button'); // Facebook Plugin ?>
		
		</form>
		<?php 			
		// Output other links
		$links = '';	
		if (get_option('users_can_register') && get_option('sidebarloginX_register_link')=='1') { 

			if (!is_multisite()) {
				
				$links .= '<li><a href="'.get_bloginfo('wpurl').'/wp-login.php?action=register" rel="nofollow">'.$theregister.'</a></li>';

			} else {
				
				$links .= '<li><a href="'.get_bloginfo('wpurl').'/wp-signup.php" rel="nofollow">'.$theregister.'</a></li>';

			}
		}
		if (get_option('sidebarloginX_forgotton_link')=='1') : 
			
			$links .= '<li><a href="'.wp_lostpassword_url().'" rel="nofollow">'. $thelostpass .'</a></li>';

		endif; 
		if ($links) echo '<ul class="sidebarloginX_otherlinks">'.$links.'</ul>';	
	}		
		
	// echo widget closing tag
	echo $after_widget;
}

/* Init widget/styles/scripts */
function widget_wp_sidebarloginX_init() {
	
	$plugin_url = (is_ssl()) ? str_replace('http://','https://', WP_PLUGIN_URL) : WP_PLUGIN_URL;
	
	// CSS
	$sidebar_loginX_css = $plugin_url . '/sidebar-loginX/style.css';
    wp_register_style('wp_sidebarloginX_css_styles', $sidebar_loginX_css);
    wp_enqueue_style('wp_sidebarloginX_css_styles');
    
	// Scripts
	$block_ui = $plugin_url . '/sidebar-loginX/js/blockui.js';
	$sidebar_loginX_script = $plugin_url . '/sidebar-loginX/js/sidebar-loginX.js';
	
	wp_register_script('blockui', $block_ui, array('jquery'), '1.0' );
	wp_register_script('sidebar-loginX', $sidebar_loginX_script, array('jquery', 'blockui'), '1.0' );
	wp_enqueue_script('jquery');
	wp_enqueue_script('blockui');
	wp_enqueue_script('sidebar-loginX');
	
	// Pass variables to script
	$sidebar_loginX_params = array(
		'ajax_url' 				=> (is_ssl()) ? str_replace('http:', 'https:', admin_url('admin-ajax.php')) : str_replace('https:', 'http:', admin_url('admin-ajax.php')),
		'login_nonce' 			=> wp_create_nonce("sidebar-loginX-action")
	);
	wp_localize_script( 'sidebar-loginX', 'sidebar_loginX_params', $sidebar_loginX_params );
	
	// Register widget
	class sidebarloginXMultiWidget extends WP_Widget {
	    function sidebarloginXMultiWidget() {  
	        $widget_ops = array('description' => __( 'Sidebar LoginX.','sblogin') );
			$this->WP_Widget('wp_sidebarloginX', __('Sidebar LoginX','sblogin'), $widget_ops);  
	    }
	    function widget($args, $instance) {    
	        
	        widget_wp_sidebarloginX($args);
	
	    }
	} 
	register_widget('sidebarloginXMultiWidget');
	
}
add_action('init', 'widget_wp_sidebarloginX_init', 1);

/* Login Action */
function widget_wp_sidebarloginX_check() {

	if (isset($_POST['sidebarloginX_posted'])) {
		
		global $login_errors;
		
		// Get redirect URL
		$redirect_to = trim(stripslashes(get_option('sidebarloginX_login_redirect')));
		
		if (empty($redirect_to)) :
			if (isset($_REQUEST['redirect_to'])) 
				$redirect_to = $_REQUEST['redirect_to'];
			else
				$redirect_to = sidebar_loginX_current_url('nologout');
		endif;

		// Check for Secure Cookie
		$secure_cookie = '';
		
		// If the user wants ssl but the session is not ssl, force a secure cookie.
		if ( !empty($_POST['log']) && !force_ssl_admin() ) {
			$user_name = sanitize_user($_POST['log']);
			if ( $user = get_userdatabylogin($user_name) ) {
				if ( get_user_option('use_ssl', $user->ID) ) {
					$secure_cookie = true;
					force_ssl_admin(true);
				}
			}
		}
		
		if ( force_ssl_admin() ) $secure_cookie = true;
		if ( $secure_cookie=='' && force_ssl_login() ) $secure_cookie = false;

		// Login
		$user = wp_signon('', $secure_cookie);

		// Redirect filter
		if ( $secure_cookie && strstr($redirect_to, 'wp-admin') ) $redirect_to = str_replace('http:', 'https:', $redirect_to);
		
		// Check the username
		if ( !$_POST['log'] ) :
			$user = new WP_Error();
			$user->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.', 'sblogin'));
		elseif ( !$_POST['pwd'] ) :
			$user = new WP_Error();
			$user->add('empty_username', __('<strong>ERROR</strong>: Please enter your password.', 'sblogin'));
		endif;
		
		// Redirect if successful
		if ( !is_wp_error($user) ) :
			wp_safe_redirect( apply_filters('login_redirect', $redirect_to, isset( $redirect_to ) ? $redirect_to : '', $user) );
			exit;
		endif;
		
		$login_errors = $user;
			
	}
}
add_action('init', 'widget_wp_sidebarloginX_check', 0);


/**
 * Process ajax login
 */
add_action('wp_ajax_sidebar_loginX_process', 'sidebar_loginX_ajax_process');
add_action('wp_ajax_nopriv_sidebar_loginX_process', 'sidebar_loginX_ajax_process');

function sidebar_loginX_ajax_process() {

	check_ajax_referer( 'sidebar-loginX-action', 'security' );
	
	// Get post data
	$creds = array();
	$creds['user_login'] 	= esc_attr($_POST['user_login']);
	$creds['user_password'] = esc_attr($_POST['user_password']);
	$creds['remember'] 		= esc_attr($_POST['remember']);
	$redirect_to 			= esc_attr($_POST['redirect_to']);
	
	// Check for Secure Cookie
	$secure_cookie = '';
	
	// If the user wants ssl but the session is not ssl, force a secure cookie.
	if ( !empty($_POST['log']) && !force_ssl_admin() ) {
		$user_name = sanitize_user($_POST['log']);
		if ( $user = get_userdatabylogin($user_name) ) {
			if ( get_user_option('use_ssl', $user->ID) ) {
				$secure_cookie = true;
				force_ssl_admin(true);
			}
		}
	}
	
	if ( force_ssl_admin() ) $secure_cookie = true;
	if ( $secure_cookie=='' && force_ssl_login() ) $secure_cookie = false;

	// Login
	$user = wp_signon($creds, $secure_cookie);
	
	// Redirect filter
	if ( $secure_cookie && strstr($redirect_to, 'wp-admin') ) $redirect_to = str_replace('http:', 'https:', $redirect_to);

	// Result
	$result = array();
	
	if ( !is_wp_error($user) ) :
		$result['success'] = 1;
		$result['redirect'] = $redirect_to;
	else :
		$result['success'] = 0;
		foreach ($user->errors as $error) {
			$result['error'] = $error[0];
			break;
		}
	endif;
	
	echo json_encode($result);

	die();
}


/* Get Current URL */
if ( !function_exists('sidebar_loginX_current_url') ) {
	function sidebar_loginX_current_url( $url = '' ) {
	
		$pageURL  = 'http://';
		$pageURL .= $_SERVER['HTTP_HOST'];
		$pageURL .= $_SERVER['REQUEST_URI'];
		if ( force_ssl_admin() ) $pageURL = str_replace( 'http:', 'https:', $pageURL );
	
		if ($url != "nologout") {
			if (!strpos($pageURL,'_login=')) {
				$rand_string = md5(uniqid(rand(), true));
				$rand_string = substr($rand_string, 0, 10);
				$pageURL = add_query_arg('_login', $rand_string, $pageURL);
			}	
		}
		
		return $pageURL;
	}
}

Code: html

<?php

add_action( 'admin_init', 'sidebar_loginX_options_init' );
add_action( 'admin_menu', 'sidebar_loginX_options_add_page' );

/**
 * Define Options
 */
global $sidebar_loginX_options;

$sidebar_loginX_options = (
	array( 
		array(
			'', 
			array(
				array(
					'name' 		=> 'sidebarloginX_heading', 
					'std' 		=> __('Login', 'sblogin'), 
					'label' 	=> __('Logged out heading', 'sblogin'),  
					'desc'		=> __('Heading for the widget when the user is logged out.', 'sblogin')
				),
				array(
					'name' 		=> 'sidebarloginX_welcome_heading', 
					'std' 		=> __('Welcome %username%', 'sblogin'), 
					'label' 	=> __('Logged in heading', 'sblogin'),  
					'desc'		=> __('Heading for the widget when the user is logged in.', 'sblogin')
				),
			)
		),
		array(
			__('Redirects', 'sblogin'), 
			array(
				array(
					'name' 		=> 'sidebarloginX_login_redirect', 
					'std' 		=> '', 
					'label' 	=> __('Login redirect', 'sblogin'),  
					'desc'		=> __('Url to redirect the user to after login. Leave blank to use the current page.', 'sblogin'),
					'placeholder' => 'http://'
				),
				array(
					'name' 		=> 'sidebarloginX_logout_redirect', 
					'std' 		=> '', 
					'label' 	=> __('Logout redirect', 'sblogin'),  
					'desc'		=> __('Url to redirect the user to after logout. Leave blank to use the current page.', 'sblogin'),
					'placeholder' => 'http://'
				),
			)
		),
		array(
			__('Links', 'sblogin'), 
			array(
				array(
					'name' 		=> 'sidebarloginX_register_link', 
					'std' 		=> '1', 
					'label' 	=> __('Show Register Link', 'sblogin'),  
					'desc'		=> sprintf( __('The <a href="%s" target="_blank">\'Anyone can register\'</a> setting must be turned on for this option to work.', 'sblogin'), admin_url('options-general.php')),
					'type' 		=> 'checkbox'
				),
				array(
					'name' 		=> 'sidebarloginX_forgotton_link', 
					'std' 		=> '1', 
					'label' 	=> __('Show Lost Password Link', 'sblogin'),  
					'desc'		=> '',
					'type' 		=> 'checkbox'
				),
				array(
					'name' 		=> 'sidebar_loginX_avatar', 
					'std' 		=> '1', 
					'label' 	=> __('Show Logged in Avatar', 'sblogin'),  
					'desc'		=> '',
					'type' 		=> 'checkbox'
				),
				array(
					'name' 		=> 'sidebarloginX_logged_in_links', 
					'std' 		=> "<a href=\"".get_bloginfo('wpurl')."/wp-admin/\">".__('Dashboard','sblogin')."</a>\n<a href=\"".get_bloginfo('wpurl')."/wp-admin/profile.php\">".__('Profile','sblogin')."</a>", 
					'label' 	=> __('Logged in links', 'sblogin'),  
					'desc'		=> sprintf( __('One link per line. Note: Logout link will always show regardless. Tip: Add <code>|true</code> after a link to only show it to admin users or alternatively use a <code>|user_capability</code> and the link will only be shown to users with that capability (see <a href=\'http://codex.wordpress.org/Roles_and_Capabilities\' target=\'_blank\'>Roles and Capabilities</a>).<br/> You can also type <code>%%USERNAME%%</code> and <code>%%USERID%%</code> which will be replaced by the user\'s info. Default: <br/>&lt;a href="%s/wp-admin/"&gt;Dashboard&lt;/a&gt;<br/>&lt;a href="%s/wp-admin/profile.php"&gt;Profile&lt;/a&gt;', 'sblogin'), get_bloginfo('wpurl'), get_bloginfo('wpurl') ),
					'type' 		=> 'textarea'
				),
			)
		)
	)
);
	
/**
 * Init plugin options to white list our options
 */
function sidebar_loginX_options_init() {

	global $sidebar_loginX_options;

	foreach($sidebar_loginX_options as $section) {
		foreach($section[1] as $option) {
			if (isset($option['std'])) add_option($option['name'], $option['std']);
			register_setting( 'sidebar-loginX', $option['name'] );
		}
	}

	
}

/**
 * Load up the menu page
 */
function sidebar_loginX_options_add_page() {
	add_options_page(__('Sidebar LoginX','sblogin'), __('Sidebar LoginX','sblogin'), 'manage_options', 'sidebar-loginX', 'sidebar_loginX_options');
}

/**
 * Create the options page
 */
function sidebar_loginX_options() {
	global $sidebar_loginX_options;

	if ( ! isset( $_REQUEST['settings-updated'] ) ) $_REQUEST['settings-updated'] = false;

	?>
	<div class="wrap">
		<?php screen_icon(); echo "<h2>" .__( 'Sidebar LoginX Options','sblogin') . "</h2>"; ?>
		
		<form method="post" action="options.php">
		
			<?php settings_fields( 'sidebar-loginX' ); ?>
	
			<?php
			foreach($sidebar_loginX_options as $section) {
			
				if ($section[0]) echo '<h3 class="title">'.$section[0].'</h3>';
				
				echo '<table class="form-table">';
				
				foreach($section[1] as $option) {
					
					echo '<tr valign="top"><th scope="row">'.$option['label'].'</th><td>';
					
					if (!isset($option['type'])) $option['type'] = '';
					
					switch ($option['type']) {
						
						case "checkbox" :
						
							$value = get_option($option['name']);
							
							?><input id="<?php echo $option['name']; ?>" name="<?php echo $option['name']; ?>" type="checkbox" value="1" <?php checked( '1', $value ); ?> /><?php
						
						break;
						case "textarea" :
							
							$value = get_option($option['name']);
							
							?><textarea id="<?php echo $option['name']; ?>" class="large-text" cols="50" rows="10" name="<?php echo $option['name']; ?>" placeholder="<?php if (isset($option['placeholder'])) echo $option['placeholder']; ?>"><?php echo esc_textarea( $value ); ?></textarea><?php
						
						break;
						default :
							
							$value = get_option($option['name']);
							
							?><input id="<?php echo $option['name']; ?>" class="regular-text" type="text" name="<?php echo $option['name']; ?>" value="<?php esc_attr_e( $value ); ?>" placeholder="<?php if (isset($option['placeholder'])) echo $option['placeholder']; ?>" /><?php
						
						break;
						
					}
					
					if ($option['desc']) echo '<span class="description">'.$option['desc'].'</span>';
					
					echo '</td></tr>';
				}
				
				echo '</table>';
				
			}
			?>

			<p class="submit">
				<input type="submit" class="button-primary" value="<?php _e( 'Save Options', 'sblogin'); ?>" />
			</p>
		</form>
	</div>
	<?php
}

Hors ligne

 

#3 07-02-2012 12:17:34

Guy
Blogueur
Date d'inscription: 07-04-2011
Messages: 6772

Re: dupliquer un widget

Il y a pas mal de choses à modifier, le nom des fonctions et/ou classes qui peuvent être dupliquées, les chemins d’accès, les données postées avec l'url, les identifiants de plugins et widgets, cela dans tous les fichiers du plugin.

C'est un travail méticuleux de comparaison et de compréhension du fonctionnement du plugin. Il y a des implications un peu partout, dans la base de données, dans la partie admin, dans le front end, ce n'est pas un mince travail, et je ne sais pas si tu trouveras quelqu'un pour l'effectuer bénévolement ici, attends plutôt des aides sur des points ponctuels que tu auras identifié.

Hors ligne

 

#4 07-02-2012 12:20:03

bakalegum
Connaisseur WP
Date d'inscription: 04-08-2009
Messages: 19

Re: dupliquer un widget

Merci guy,

J'ai pris consience  de ca. du coup, plutot que de retatonner 1 demi journée, je regarde des tutos de creation de widget. pour tout bien comprendre, voir le recoder directement avec mes propres nom de fonctions.

Hors ligne

 

#5 07-02-2012 12:24:52

bakalegum
Connaisseur WP
Date d'inscription: 04-08-2009
Messages: 19

Re: dupliquer un widget

roalala qu'est ce que je peux etre con.
en fait depsui el début, je regarde si en modifiant les fichiers le widget apparait comme par magie dans les widget disponible.. mais sans activer l'extension!!!

tout ce temps perdu pour rien, du coup car marche très bien, peut etre quelque conflit de nom a gerer mais au moins ca marche!!!!!

shame on me.

Hors ligne

 

#6 07-02-2012 12:27:27

Guy
Blogueur
Date d'inscription: 07-04-2011
Messages: 6772

Re: dupliquer un widget

lol , et oui des fois... smile

Hors ligne

 

#7 07-02-2012 12:31:55

bakalegum
Connaisseur WP
Date d'inscription: 04-08-2009
Messages: 19

Re: dupliquer un widget

Comment on indique résolu sur ce forum, je ne peux pas éditer mon titre...
Si un admin passe par la resolu

Dernière modification par bakalegum (07-02-2012 12:32:15)

Hors ligne

 

Pied de page des forums

Propulsé par PunBB 1.2.23
© Copyright 2005-2006 WordPress France

[ Generated in 0.035 seconds, 14 queries executed ]