-
-
Save DavidPeralvarez/0b3597b46597e7dc8caabc851c6a96d8 to your computer and use it in GitHub Desktop.
Recuperar opciones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Options API | |
Description: Practicando con la API de opciones | |
*/ | |
// Activa el plugin | |
register_activation_hook( __FILE__, 'dp_oa_activate_plugin' ); | |
function dp_oa_activate_plugin(){ | |
// Asignar valores por defecto a las opciones/settings del plugin | |
// Utilizar esta función cuando activemos nuestro plugin | |
add_option( 'dp_oa_age', 18 ); | |
add_option( 'dp_oa_true', 1 ); | |
add_option( 'dp_oa_false', 0 ); | |
// Si existe la opción en la BBDD la actualiza y sino la crea nueva | |
//update_option( 'dp_oa_age', 21 ); | |
// Guardar una array de opciones | |
$options = array( | |
'visits' => 0, | |
'last_ip' => '3.145.4.78', | |
'color' => 'green', | |
'flag' => true | |
); | |
add_option( 'dp_oa_options', $options ); | |
} | |
add_action( 'init', 'dp_oa_visits_counter' ); | |
function dp_oa_visits_counter(){ | |
$age = get_option( 'dp_oa_age' ); | |
var_dump( $age ); | |
var_dump( get_option( 'dp_oa_true' ) ); | |
var_dump( get_option( 'dp_oa_false' ) ); | |
if( get_option( 'opcion_inventada' ) === false ): | |
echo "Esta opción no existe"; | |
else: | |
echo "Esta opción ya existe"; | |
endif; | |
// if( get_option( 'dp_oa_age', 'not_found' ) == 'not_found' ): | |
// echo "Esta opción no existe"; | |
// else: | |
// echo "Esta opción ya existe"; | |
// endif; | |
$options = get_option( 'dp_oa_options' ); | |
$visits = $options['visits']; | |
$last_ip = $options['last_ip']; | |
$color = $options['color']; | |
$flag = $options['flag']; | |
var_dump( $flag ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment