Categories
Wordpress

How to use media library / uploader in code

How to use WordPress 3.5 Media Uploader in Theme Options

Categories
Wordpress

WordPress settings for custom plugin

Ottopress has a pretty good tutorial for writing a wordpress plugin settings page but its a little confusing if you dont see the software flow

Here is my interpretation

 

 

 

/**
*
* Created by Urbanpixels.com
* Author: Chuck
* Copyright: 8/12]0/12 All Rights Reserved
*
*/
add_action('admin_menu', 'kpi_forum_admin_add_page');
$settings_slug = 'kpi-forum-settings'; // array catcher
$plugin_slug = 'kpi-forum';
$section_slug = 'kpi-forum-section';
add_action('admin_init', 'kpi_forum_admin_init');
function kpi_forum_admin_init(){
global $plugin_slug,$settings_slug,$section_slug;
register_setting( $settings_slug, $settings_slug, 'kpi_forum_validate' );
add_settings_section($section_slug, 'KPI Forum Settings', 'kpi_forum_section_description', $plugin_slug);
add_settings_field('kpi-forum-test-field', 'Test', 'kpi_forum_test_field', $plugin_slug, $section_slug);
add_settings_field('kpi-forum-foo-field', 'Foo', 'kpi_forum_foo_field', $plugin_slug, $section_slug);

}
function kpi_forum_admin_add_page() {
global $plugin_slug;
add_options_page('Custom Plugin Page', 'KPI Forum', 'manage_options', $plugin_slug, 'kpi_forum_form');
}
function kpi_forum_form() {
global $plugin_slug,$settings_slug;
?>
<div>
<h2>KPI Forum Settings</h2>
<form method="post" action="options.php">
<?php
settings_fields( $settings_slug );
do_settings_sections( $plugin_slug );
submit_button();
?>

</form>
</div>
<?php
}

function kpi_forum_section_description() {
?>
Some text describe section one
<?php
}

function kpi_forum_test_field() {
global $settings_slug;
$options = get_option($settings_slug);
?>
<input type="text" name="kpi-forum-settings[test]" value="<?php echo $options['test'];?>"/>
<?php
}
function kpi_forum_foo_field() {
global $settings_slug;
$options = get_option($settings_slug);
?>
<input type="text" name="kpi-forum-settings[foo]" value="<?php echo $options['foo'];?>"/>
<?php
}
function kpi_forum_validate($options) {
return $options;
}

Categories
Wordpress

Custom URL structure in wordpress

http://matty.co.za/2009/11/custom-url-rewrites-in-wordpress/

Read the comments about rewrite. I would put definitely use admin-init and put it inside of the settings page to flush.

Categories
Wordpress

mysql date to php

$date = strtotime( '2009-12-02');
$php_date = date( 'Y-m-d H:i:s', $date );
Categories
Wordpress

Disable Admin Bar

Lots of ways to skin this cat, but this is the easiest for wp 3.3+

in functions.php
show_admin_bar(false);

Categories
Wordpress

Add a theme options page

http://codex.wordpress.org/Function_Reference/add_theme_page

function theme_admin_setup() {

add_theme_page(
__( ‘Theme Options’),   // Name of page
__( ‘Theme Options’),   // Label in menu
‘edit_theme_options’,                    // Capability required
‘theme_options’,                         // Menu slug, used to uniquely identify the page
‘theme_options_page’ // Function that renders the options page
);
}

add_action(‘admin_menu’, ‘theme_admin_setup’); // must be wrapped in admin_menu
function theme_options_page() {

if ($_POST) { .. update .. }

// page for the form

}