<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Johan de Bruin &#187; Programar plugins wordpress</title>
	<atom:link href="http://www.johandebruin.com/t/programar-plugins-wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johandebruin.com</link>
	<description>Programación en php, tutorial de api wordpress y posicionamiento en buscadores seo.</description>
	<lastBuildDate>Sun, 05 Feb 2012 15:18:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Añadir opciones a un plugin wordpress</title>
		<link>http://www.johandebruin.com/anadir-opciones-a-un-plugin-wordpress/</link>
		<comments>http://www.johandebruin.com/anadir-opciones-a-un-plugin-wordpress/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 14:18:29 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Añadir opciones wordpress]]></category>
		<category><![CDATA[API wordpress]]></category>
		<category><![CDATA[Opciones wordpress]]></category>
		<category><![CDATA[Plugin wordpress]]></category>
		<category><![CDATA[Programar plugins wordpress]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=480</guid>
		<description><![CDATA[Consta de una variable para establecer un nombre de id para establecer las opciones en la base de datos, añadir la acción al hook del menu al construir el plugin, establecer como aparecerá en la pestaña las opcinones con add_options_page, y el código que mostrará y gestionará las opciones insertadas. Aquí un ejemplo básico de [...]]]></description>
			<content:encoded><![CDATA[<p>Consta de una variable para establecer un nombre de id para establecer las opciones en la base de datos, añadir la acción al hook del menu al construir el plugin, establecer como aparecerá en la pestaña las opcinones con <strong>add_options_page</strong>, y el código que mostrará y gestionará las opciones insertadas. Aquí un ejemplo básico de como quedaría:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> miPlugin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$db_option</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'miPlugin_Options'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> miPlugin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//Línea para incluir el menú</span>
		add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'miMenu'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'admin_menu'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> miMenu<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		add_options_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Opciones del plugin'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Algun id'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'opciones'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> opciones<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_options</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submitted'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		  check_admin_referer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'nonce'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		  <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		  <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		  <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		  update_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db_option</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">// Aquí establecemos algunas variables que usaremos en el form</span>
		<span style="color: #000088;">$action_url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$b</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
       	&lt;form name=&quot;SnazzyArchives&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$action_url</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; method=&quot;post&quot;&gt;
            <span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_nonce_field<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'nonce'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
            &lt;input type=&quot;checkbox&quot; name=&quot;a&quot;  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$a</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> /&gt;&lt;label&gt; Show Posts&lt;/label&gt;  &lt;br /&gt;
            &lt;input type=&quot;checkbox&quot; name=&quot;b&quot;  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$b</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> /&gt;&lt;label&gt; Show Pages&lt;/label&gt;  &lt;br /&gt;
            &lt;div&gt;&lt;input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Update&quot; /&gt;&lt;/div&gt;
       	&lt;/form&gt;
        <span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Solo decir que que las opciones se obtienen con <em>$options = $this->get_options();</em> y se establecen con <em>update_option($this->db_option, $options);</em> Además, <em><?php wp_nonce_field('nonce'); ?></em> sirve como parametro de seguridad para cercionarnos que se está empleando el formulario correcto. Esto luego se comprueba con <em>check_admin_referer(&#8216;nonce&#8217;);</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/anadir-opciones-a-un-plugin-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

