Uživatelské taxonomie, přidávání uživatelských polí k taxonomiím

Custom user taxonomies »

*

To add a custom field to your custom taxonomy, add the following code to your theme's functions.php:

// A callback function to add a custom field to our "presenters" taxonomy
function presenters_taxonomy_custom_fields($tag) {
// Check for existing taxonomy meta for the term you're editing
$t_id = $tag->term_id; // Get the ID of the term you're editing
$term_meta = get_option( "taxonomy_term_$t_id" ); // Do the check
?>
<tr class="form-field">
    <th scope="row" valign="top">
        <label for="presenter_id"><?php _e('WordPress User ID'); ?></label>
    </th>
    <td>
        <input type="text" name="term_meta[presenter_id]" id="term_meta[presenter_id]" size="25" style="width:60%;" value="<?php echo $term_meta['presenter_id'] ? $term_meta['presenter_id'] : ''; ?>"><br />
        <span class="description"><?php _e('The Presenter\'s WordPress User ID'); ?></span>
    </td>
</tr>
<?php
}

Next, we'll create a callback function that we'll use to save our custom fields. Add the following code to your theme's functions.php:

// A callback function to save our extra taxonomy field(s)
function save_taxonomy_custom_fields( $term_id ) {
if ( isset( $_POST['term_meta'] ) ) {
    $t_id = $term_id;
    $term_meta = get_option( "taxonomy_term_$t_id" );
    $cat_keys = array_keys( $_POST['term_meta'] );
    foreach ( $cat_keys as $key ){
        if ( isset( $_POST['term_meta'][$key] ) ){
            $term_meta[$key] = $_POST['term_meta'][$key];
        }
    }
//save the option array
update_option( "taxonomy_term_$t_id", $term_meta );
}
}

Let's associate these callback functions to the "edit" screen for our custom taxonomies. Add the following code to your theme's functions.php:

// Add the fields to the "presenters" taxonomy, using our callback function
add_action( 'presenters_edit_form_fields', 'presenters_taxonomy_custom_fields', 10, 2 );
// Save the changes made on the "presenters" taxonomy, using our callback function
add_action( 'edited_presenters', 'save_taxonomy_custom_fields', 10, 2 );

To access a custom field added to your custom taxonomy using the method noted earlier, add the following code inside your custom taxonomy template (in our case, taxonomy-presenters.php), within the PHP block at the top:

// Get the custom fields based on the $presenter term ID
$presenter_custom_fields = get_option( "taxonomy_term_$presenter->term_id" );
// Return the value for the "presenter_id" custom field
$presenter_data = get_userdata( $presenter_custom_fields[presenter_id] ); // Get their data

To see what data is stored inside the custom fields you created, add the print_r function to your template, then preview it:

<?php
    echo '<pre>';
    print_r( $presenter_custom_fields );
    echo '</pre>';
?>

To keep it dynamic, we are passing in the "presenter_id" field of our $presenter_cus­tom_fields variable. Now, to see what data you have to work with, use print_r again:

<?php
    echo '<pre>';
    print_r( $presenter_data );
    echo '</pre>';
?>

Zdroj: How To Add Custom Fields To Custom Taxonomies »


To add a form field to the Edit Category screen we’ll use the edit_category_for­m_fields action hook available in WordPress:

<?php
add_action ( 'edit_category_form_fields', 'tme_cat_featured');

function tme_cat_featured( $tag ) {

//check for existing featured ID
$cat_featured = get_option( 'category_featured' );
$featured_id = '';
if ( is_array( $cat_featured ) && array_key_exists( $tag->term_id, $cat_featured ) ) {
     $featured_id = $cat_featured[$tag->term_id] ;
}
?>
<tr class="form-field">
    <th scope="row" valign="top"><label for="category_featured"><?php _e('Featured Post ID') ?></label></th>
    <td>
        <input type="text" name="category_featured" id="category_featured" size="3" style="width:5%;" value="<?php echo $featured_id; ?>"><br />
        <span class="description">The post ID that will be the featured post when viewing this category.</span>
    </td>
</tr>
<?php
}
?>

The above code will add a single text field (Featured Post ID) to the Edit Category screen.

Now we need to save the input to our option array. To capture the ID when a category is updated we’ll use the edited_category action hook like so:

<?php
add_action ( 'edited_category', 'tme_save_featured');

function tme_save_featured( $term_id ) {
if ( isset( $_POST['category_featured'] ) ) {

    //load existing category featured option
    $current_featured = get_option( 'category_featured' );

    //set featured post ID to proper category ID in options array
    $current_featured[$term_id] = intval( $_POST['category_featured'] );

    //save the option array
     update_option( 'category_featured', $current_featured );
    }
}
?>

As you can see we are saving the Category ID and Featured Post ID as a single associative array option value in WordPress named category_featured. As you add Featured Post ID values to each of your categories they will be added to this array and saved in WordPress.

Save Taxonomy Meta Data as an Options Array in WordPress »


How to Add Custom Meta Fields to Custom Taxonomies in WordPress »

Adding Custom Meta Fields to Taxonomies »

How To Add Custom Fields To Custom Taxonomies»

WordPress: Adding custom fields to taxonomies »

WordPress Taxonomies Extra Fields the easy way »

Hooking WordPress Taxonomy Changes With The Plugins API »

Extending WordPress Taxonomies »

Vypnutí XML-RPC

XML-RPC is a Remote Procedure Call (RPC) protocol which uses XML to encode its calls and HTTP as a transport mechanism. XML-RPC is used to do something remotely to your blog such as posting, viewing comments, etc.
By default, WordPress enables XML-RPC automatically!

Disable XML-RPC Pingback
https://wordpress.org/…pc-pingback/

This is more friendly than disabling totally XML-RPC, that it's needed by some plugins and apps (I.e. Mobile apps or some Jetpack's modules).

Vypnutí pingbacků ve functions.php (totéž jako výše uvedený plugin)

function remove_xmlrpc_pingback_ping( $methods ) {
   unset( $methods['pingback.ping'] );
   return $methods;
}
add_filter( 'xmlrpc_methods', 'remove_xmlrpc_pingback_ping' );

How to disable XML-RPC manually:

  1. turn off XML-RPC in functions.php
add_filter('xmlrpc_enabled', '__return_false');
  1. hide xmlrpc.php in HTTP response headers in functions.php
function disable_x_pingback($headers)
{
  unset( $headers['X-Pingback'] );
  return $headers;
}
add_filter('wp_headers', 'disable_x_pingback');
  1. deny request to xmlrpc.php in .htaccess
<IfModule mod_alias.c>
RedirectMatch 403 /xmlrpc.php
</IfModule>

or

<Files xmlrpc.php>
Order Deny,Allow
Deny from all
</Files>

Zdroj »

Přidání nového příspěvku programátorsky

/*
A function used to programmatically create a post in WordPress.
@returns -1 if the post was never created, -2 if a post with the same title exists, or the ID of the post if successful.
*/

function programmatically_create_post($user_id) {
        // Initialize the page ID to -1. This indicates no action has been taken.
        $post_id = -1;

        // Setup the title of the post
        $title = 'My New Post'

        // If the page doesn't already exist, then create it
        if( null == get_page_by_title($title)) {
                // Set the post ID so that we know the post was created successfully
                $new_post = array(
                'post_title' => $title,
                'post_name' => my-new-post,
                'post_content' => 'Lorem ipsum dolor sit amet...',
                'post_status' => 'publish',
                'post_date' => date('j.n.Y H:i:s'),
                'post_author' => $user_id,
                'post_type' => 'post',
                'post_category' => array(0),
                'comment_status'  => 'closed',
                'ping_status'   => 'closed',
                );
                $post_id = wp_insert_post($new_post);
        // Otherwise, we'll stop
        } else {
                // Arbitrarily use -2 to indicate that the page with the title already exists
                $post_id = -2;
        } // end if
} // end programmatically_create_post

Programmatically Create a Post in WordPress »
How to Create a Post in WordPress Programmatically » to Create a Post in WordPress Programmatically

To lze využít např. pro automatické vytvoření příspěvku z uživatelského profilu při jeho ukládání přes user_register hook:

add_action('user_register','programmatically_create_post');

Jak přidat tlačítko do HTML editoru

// Add buttons to html editor
add_action('admin_print_footer_scripts','eg_quicktags');
function eg_quicktags() {
?>
<script type="text/javascript" charset="utf-8">
/* Adding Quicktag buttons to the editor WordPress ver. 3.3 and above
* - Button HTML ID (required)
* - Button display, value="" attribute (required)
* - Opening Tag (required)
* - Closing Tag (required)
* - Access key, accesskey="" attribute for the button (optional)
* - Title, title="" attribute (optional)
* - Priority/position on bar, 1-9 = first, 11-19 = second, 21-29 = third, etc. (optional)
*/
QTags.addButton( 'eg_paragraph', 'p', '<p>', '</p>', 'p' );
QTags.addButton( 'eg_pre', 'pre','<pre lang="php">', '</pre>', 'q' );
</script>
<?php
}

Manipulace s údaji v Contact Form 7 před a po odeslání

WordPress Contact Form 7 Hook Unofficial Developer Documentation and Examples »

Changing Form Data Before it is Saved »

Contact Form 7 - form submit change field value »

How to create a mail counter for Contact Form 7 »

Extending the Contact Form 7 Plugin »

[private]

### příklad použitý na http://u904.cz/mimoradna-nabidka-lifebook-a512/
### pocitadlo objednavek odeslanych z CF7

// Define the key to store in the database
define('CF7_COUNTER', 'cf7-counter');
define('CF7_LASTORD', 'cf7-lastord');
define('POCNAB', '200'); // startovni pocet kusu

### Create the shortcode which will read the value from db option
function cf7db_reader(){
        $val = get_option(CF7_COUNTER, POCNAB);  // kdyz neexistuje option v db, vrati startovni pocet
        return $val;
}
add_shortcode('CF7_show', 'cf7db_reader');


### Action performed BEFORE the mail is sent by CF7
function wpcf7_change_mail($form) {
        $formid = $form->id; // gets current form id
        if ($formid == '384') {
          $wpcf7 = WPCF7_ContactForm::get_current(); // get current FORM instance
                $wpcf7data = WPCF7_Submission::get_instance(); // // get current SUBMISSION instance
                if ($wpcf7data) {
                        $formData = $wpcf7data->get_posted_data();
                }
                // Reading a posted value in the form with PHP
                $poc = $formData['pocet']; // nacte hodnotu z prave odeslaneho formulare
                $val = get_option(CF7_COUNTER, POCNAB); // nacte aktualni hodnotu skladu, kdyz neexistuje option v db, vytvori a naplni ji startovnim poctem objednavku.

                // nahrada dat v mailu
                $mail = $wpcf7->prop('mail');

                if($poc > $val): // objednano vic kusu, nez je na sklade, nahradim REPLACER textem
                        $mail['pocet'] = $val; // snizim objednany pocet
                        // doplnim upozorneni do mailu
                        // Find/replace the "special" tag as defined in your CF7 email body
        $mail['body'] = str_replace('REPLACER', "Jelikož jste objednali větší počet (".$poc." ks), než bylo aktuálně k dispozici skladem (".$val." ks), bude objednaný počet snížen na dostupné množství.\n", $mail['body']);
                else: // odstrani REPLACER string
                        $mail['body'] = str_replace('REPLACER', "", $mail['body']);
                endif;

    // Save the email body
    $wpcf7->set_properties(array("mail" => $mail));

                // return current cf7 instance
    return $wpcf7;
        }
}
add_action('wpcf7_before_send_mail', 'wpcf7_change_mail');


### Action performed WHEN the mail is sent by CF7
function cf7_decrement_order_counter($form){
        $formid = $form->id; // gets current form id
        if ($formid == '384') {
          // $wpcf7 = WPCF7_ContactForm::get_current(); // get current FORM instance
                $wpcf7data = WPCF7_Submission::get_instance(); // // get current SUBMISSION instance
                if ($wpcf7data) {
                        $formData = $wpcf7data->get_posted_data();
                }
    $poc = $formData['pocet']; // nacte hodnotu z prave odeslaneho formulare
    $val = get_option(CF7_COUNTER, POCNAB) - $poc; // kdyz neexistuje option v db, vytvori a naplni ji startovnim poctem snizenym o odeslanou objednavku.
                update_option(CF7_COUNTER, $val); // Update the settings with the new count
                update_option(CF7_LASTORD, $poc); // Update the settings with the new count
        }
}
add_action('wpcf7_mail_sent', 'cf7_decrement_order_counter');


### zmena poctu objednanych kusu v databazi odeslanych formularu (Contact Form DB)
function change_cfdb_value($formData){
        $formName = 'A514';
        if ($formData && $formName == $formData->title) {
                $poc = $formData->posted_data['pocet'];
                $val = get_option(CF7_COUNTER, POCNAB);
                if($poc > $val): // objednano vic kusu, nez je na sklade
                        $formData->posted_data['dodavka'] = $val;
                else:
                        $formData->posted_data['dodavka'] = $poc;
                endif;
  }
  return $formData;
}
add_filter('cfdb_form_data', 'change_cfdb_value');


### Change content of Ordering Page
function formRemover($content) {
                if(!is_feed() && !is_admin() && is_page(381)) {
        $val = get_option(CF7_COUNTER);
        if($val == 0):
                                $content = str_replace('<h3>Tak neváhejte!</h3>', '<h3>Prodej byl ukončen.</h3>', $content);
        else:
                                $content = str_replace('</ul>', '</ul><h3>Objednávkový formulář</h3><h3></h3>[contact-form-7 404 "Not Found"]', $content);
                        endif;
    }
    return $content;
}
add_filter ('the_content', 'formRemover');


### Change content of Thank You Page
function orderAlert($content) {
                if(!is_feed() && !is_admin() && is_page(385)) {
        $val = get_option(CF7_COUNTER, POCNAB);
        $poc = get_option(CF7_LASTORD, 0);
        $roz = $poc-$val;
        if($val <= 0):
                                $content = str_replace('REPLACER', '<h3>Díky za objednávku.</h3><p>Jelikož jste objednali <b>větší počet</b> kusů, než bylo aktuálně k dispozici skladem, byl Vámi objednaný počet <b>snížen</b>.</p><p>Na adresu, kterou jste uvedli ve formuláři, byl zaslán potvrzující e-mail.</p>', $content);
                                update_option(CF7_COUNTER, 0); // vynulovani pocitadla
                                update_option(CF7_LASTORD, 0); // vynulovani pocitadla
        else:
                                $content = str_replace('REPLACER', '<h3>Díky za objednávku.</h3><p>Na adresu, kterou jste uvedli ve formuláři, byl zaslán potvrzující e-mail.</p>', $content);
                        endif;
    }
    return $content;
}
add_filter ('the_content', 'orderAlert');


### pridani odkazu na blog page k excerptum
function excerpt_read_more_link($output) {
global $post;
return $output . '<a href="'. get_permalink($post->ID) . '"> Více »</a>';
}
add_filter('the_excerpt', 'excerpt_read_more_link');


#############################
#### ve starších verzích CF7
#############################

// Define the key to store in the database
define('CF7_COUNTER', 'cf7-counter');
define('CF7_LASTORD', 'cf7-lastord');
define('POCNAB', '260'); // startovni pocet kusu

### Create the shortcode which will read the value from db option
function cf7db_reader(){
        $val = get_option(CF7_COUNTER, POCNAB);  // kdyz neexistuje option v db, vrati startovni pocet
        return $val;
}
add_shortcode('CF7_show', 'cf7db_reader');


### Action performed BEFORE the mail is sent by CF7
function wpcf7_change_mail($formData) {
        $formName = 'A512';
        if ($formData && $formName == $formData->title) {
                // Reading a posted value in the form with PHP
                $poc = $formData->posted_data['pocet']; // nacte hodnotu z prave odeslaneho formulare
                $val = get_option(CF7_COUNTER, POCNAB); // nacte aktualni hodnotu skladu, kdyz neexistuje option v db, vytvori a naplni ji startovnim poctem objednavku.
                $bod = $formData->mail['body'];

                if($poc > $val): // objednano vic kusu, nez je na sklade, nahradim REPLACER textem
                        $formData->posted_data['pocet'] = $val; // snizim objednany pocet
                        // doplnim upozorneni do mailu
                        $bod = str_replace('REPLACER', "Jelikož jste objednali větší počet (".$poc." ks), než bylo aktuálně k dispozici skladem (".$val." ks), byl objednaný počet snížen na dostupné množství.\n", $bod);
                        $formData->mail['body'] = $bod;
                else: // odstrani REPLACER string
                        $bod = str_replace('REPLACER', '', $bod);
                        $formData->mail['body'] = $bod;
                endif;
        }
}
add_action('wpcf7_before_send_mail', 'wpcf7_change_mail');


### Action performed WHEN the mail is sent by CF7
function cf7_decrement_order_counter($formData){
        $formName = 'A512';
        if ($formData && $formName == $formData->title) {
    $poc = $formData->posted_data['pocet']; // nacte hodnotu z prave odeslaneho formulare
    $val = get_option(CF7_COUNTER, POCNAB) - $poc; // kdyz neexistuje option v db, vytvori a naplni ji startovnim poctem snizenym o odeslanou objednavku.
                update_option(CF7_COUNTER, $val); // Update the settings with the new count
                update_option(CF7_LASTORD, $poc); // Update the settings with the new count
        }
}
add_action('wpcf7_mail_sent', 'cf7_decrement_order_counter');


### zmena poctu objednanych kusu v databazi odeslanych formularu (Contact Form DB)
function change_cfdb_value($formData){
        $formName = 'A512';
        if ($formData && $formName == $formData->title) {
                $poc = $formData->posted_data['pocet'];
                $val = get_option(CF7_COUNTER, POCNAB);
                if($poc > $val): // objednano vic kusu, nez je na sklade
                        $formData->posted_data['dodavka'] =     $val;
                else:
                        $formData->posted_data['dodavka'] =     $poc;
                endif;
  }
  return $formData;
}
add_filter('cfdb_form_data', 'change_cfdb_value');


### Change content of Ordering Page
function formRemover($content) {
                if(!is_feed() && !is_admin() && is_page(60)) {
        $val = get_option(CF7_COUNTER);
        if($val == 0):
                                $content = str_replace('<h3>Tak neváhejte!</h3>', '<h3>Prodej byl ukončen.</h3>', $content);
        else:
                                $content = str_replace('</ul>', '</ul><h3>Objednávkový formulář</h3><h3></h3>[contact-form-7 404 "Not Found"]', $content);
                        endif;
    }
    return $content;
}
add_filter ('the_content', 'formRemover');


### Change content of Thank You Page
function orderAlert($content) {
                if(!is_feed() && !is_admin() && is_page(72)) {
        $val = get_option(CF7_COUNTER, POCNAB);
        $poc = get_option(CF7_LASTORD, 0);
        $roz = $poc-$val;
        if($val <= 0):
                                $content = str_replace('REPLACER', '<h3>Díky za objednávku.</h3><p>Jelikož jste objednali <b>větší počet</b> kusů, než bylo aktuálně k dispozici skladem, byl Vámi objednaný počet <b>snížen</b>.</p><p>Na adresu, kterou jste uvedli ve formuláři, byl zaslán potvrzující e-mail.</p>', $content);
                                update_option(CF7_COUNTER, 0); // vynulovani pocitadla
                                update_option(CF7_LASTORD, 0); // vynulovani pocitadla
        else:
                                $content = str_replace('REPLACER', '<h3>Díky za objednávku.</h3><p>Na adresu, kterou jste uvedli ve formuláři, byl zaslán potvrzující e-mail.</p>', $content);
                        endif;
    }
    return $content;
}
add_filter ('the_content', 'orderAlert');

[/private]

Ve verzi CF7 4 a vyšší se způsob přebírání dat z formuláře změnil:

/* WPCF7_ContactForm object no longer has a posted_data property. */
$posted_data = $contact_form->posted_data; // Tohle už nefunguje

/* Use WPCF7_Submission object's get_posted_data() method to get it. */
$submission = WPCF7_Submission::get_instance();

if ( $submission ) {
    $posted_data = $submission->get_posted_data();
}

WordPress návody přímo v administraci

LifeGuard+
http://wplifeguard.com/…uard-plugin/

The LifeGuard+ Assistant plugin puts WordPress video tutorials right into a WordPress Dashboard. Gone are the days where WordPress developers have to teach each new client how to use WordPress. Now all that needs to be done is install LifeGuard+ Assistant on all new client WordPress projects, and they can learn how to use WordPress by watching our thorough WordPress tutorials!

76 užitečných tipů

  • WordPress Shortcodes
  • WordPress Permalinks Outside of the Loop
  • Custom Message to Returning Visitors
  • Recently Updated Posts and Pages
  • Custom Content to Search Engine Visitors
  • Last Modified Time and Date for Posts
  • Display Total Number of Trackbacks and Pingbacks
  • Display Recently Registered Users
  • List all of Your Site’s Posts
  • List WordPress User Information
  • Display List of Scheduled Posts
  • Display Private Posts to Logged-in Users
  • Display Posts from Exactly One Year Ago
  • Custom CSS Styles for Recent Posts
  • New WordPress-2.7 Comments Loop
  • Backwards-Compatible Comment Templates
  • Disable WordPress Post Revisions
  • Limit WordPress Post Revisions
  • Remove WordPress Post Revisions from the Database
  • Reduce Comment Spam by Blocking No-Referrer Requests
  • Prevent Google Analytics from Tracking Admin Pages
  • Meta Descriptions without a Plugin
  • Differentiate Between Posts Depending on Presence of Excerpt
  • Modify the wp_options Table via the WordPress Admin
  • Alternate Comment Styles
  • Automatically Remove Code Mistakes in Posts
  • Automatically Disable Comments and Trackbacks in Old Posts
  • Access Post Data Outside the Loop
  • Display Posts for a Specified Time Period
  • Unique Single Post Templates for Different Categories
  • Display Performance Statistics for WordPress Pages
  • Custom Post Thumbnails in Two Steps
  • Highlight Author Comments
  • Easy Random Posts
  • Display Dates for Groups of Posts
  • Display a Sticky Post in the Sidebar
  • Display Latest Comments without a Plugin
  • Display Most Commented Posts without a Plugin
  • Change Permalinks from Date-Based to Post-Date Only
  • Test for Sub-Pages
  • Multiple Widgetizable Sidebars
  • Remove Fancy Quotes from Comments
  • Display a List of All Untagged Posts
  • Easy Display of Custom Headers, Footers, and Sidebars
  • A Better Way for Users to Logout
  • Display a Custom Message on a Specific Date
  • Display Three Columns of Posts
  • Disable WordPress Search Functionality
  • Display Posts with Specific Custom Fields
  • How to Number Your Comments, Pingbacks, & Trackbacks in 2.7+
  • How to Number Your Comments Using the Classic Loop
  • Invite Readers to Comment via Feed
  • Display the Total Number of Users for Your Blog
  • Automatically Insert Content into Your WordPress Post Editor
  • How to Prevent Duplicate Content
  • Conditionally Display Full Posts or Excerpts
  • Display Related Posts without a Plugin
  • Drop-Dead Easy Styles for Author Comments
  • Display Posts Upcoming Scheduled Posts
  • Display Automatic TinyURLs for Your Posts
  • Implement a Site-Maintenance Page for Your Blog
  • Display the First Image from Each of Your Posts
  • Display Most Popular Posts without a Plugin
  • Automatically Highlight Search Terms
  • Automatically Disable Widgets
  • Display All Images from Your Post Content
  • Display Category List in Two Columns
  • Show Ads or Other Content Only in the First Three Posts
  • A Better Way to Display Recent Comments without a Plugin
  • Selectively Disable Automatic Post Formatting
  • Browser Detection via WordPress’ body_class Function
  • Get Post or Page Contents as a PHP Variable
  • Simple Example of How to Use WordPress Cron
  • Add More Default Avatar Choices to the WordPress Admin
  • Add a Private Page to Your Navigation Menu
  • How to Add Additional Links to wp_list_pages

Stupid WordPress Tricks »