Skip to content

Instantly share code, notes, and snippets.

<?php
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$title = sanitize_text_field( $new_instance['title'] );
if ( ! empty( $title ) )
$instance['title'] = $title;
return $instance;
<?php
function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
?>
<?php echo $args['before_widget']; ?>
<?php if ( $title )
echo $args['before_title'] . $title . $args['after_title']; ?>
<?php
function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
?>
<?php echo $before_widget; ?>
<?php if ( $title )
echo $before_title . $title . $after_title; ?>
Hola, mundo
<?php
class Fictizia_Widget extends WP_Widget {
// El nombre de la clase tiene que coincidir con esta función
function Fictizia_Widget() {
// Argumentos
$args = array( 'classname' => 'fictizia-widget', 'description' => __( 'Fictizia Widget Description', 'fictizia' ) );
<?php
global $wpdb;
$tablename = $wpdb->prefix . 'fictizia_clientes';
$charset_collate = '';
if ( ! empty($wpdb->charset) )
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
if ( ! empty($wpdb->collate) )
$charset_collate .= " COLLATE $wpdb->collate";
<form action="" method="POST">
<table class="form-table">
<tr>
<th scope="row"><?php _e( 'New customer', 'fictizia' ); ?></th>
<td>
<input type="text" name="cliente" value=""/>
</td>
</tr>
</table>
<?php
add_action( 'admin_menu', 'fictizia_add_settings_menu' );
function fictizia_add_settings_menu() {
add_submenu_page( 'fictizia-main', 'Settings', 'Settings', 'manage_options', 'fictizia-settings', 'fictizia_display_settings_menu' );
}
function fictizia_settings_init() {
register_setting( 'OPTIONS_GROUP', 'OPTIONS_GROUP', 'SANITIZE_CALLBACK' );
add_settings_section( 'SECTION_ID', __( 'SECTION_TITLE', 'fictizia' ), 'SECTION_CALLBACK', 'MENU_SLUG' );
<?php
add_action( 'wp_ajax_fictizia_load_posts', 'fictizia_load_posts' );
add_action( 'wp_ajax_nopriv_fictizia_load_posts', 'fictizia_load_posts' );
function fictizia_load_posts() {
$posts = // SELECCIONAMOS LOS POSTS
wp_send_json( $posts );
}
@igmoweb
igmoweb / phpunit.xml
Last active August 29, 2015 14:13
phpunit.xml for multisites
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<php>
<const name="WP_TESTS_MULTISITE" value="1" />
@igmoweb
igmoweb / wp-head-css.php
Last active August 29, 2015 14:14
Use wp_head to dinamically generate CSS
<?php
add_action( 'wp_head', 'dolly_print_styles' );
function dolly_print_styles() {
$options = get_option( 'my-options' );
?>
<style>
.my-class {
background-color:<?php echo $options['background-color']; ?>;
font-size:<?php echo $options['font-size']; ?>px;
}