2017 © Pedro Peláez
 

library custom-field

image

miya/custom-field

  • Wednesday, September 27, 2017
  • by miya0001
  • Repository
  • 1 Watchers
  • 1 Stars
  • 423 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 61 % Grown

The README.md

miya/custom-field

Build Status Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

An abstract class to create a custom field for WordPress., (*2)

Install

$ composer require miya/custom-field

Example

add( 'post' );


class Text_Field extends \Miya\WP\Custom_Field
{
    /**
     * Fires at the `admin_enqueue_scripts` hook.
     *
     * @param string $hook The hook like `post.php` or so.
     * @return none
     */
    public function admin_enqueue_scripts( $hook )
    {
        // If you need a CCS or JS, you can run `wp_enqueue_*()` here.
        // This function will be callded when current screen is the specific post type by `add()`.
    }

    /**
     * Displays the form for the metabox. The nonce will be added automatically.
     *
     * @param object $post The object of the post.
     * @param array $args The argumets passed from `add_meta_box()`.
     * @return none
     */
    public function form( $post, $args )
    {
        ?>
            <input type="text" name="input"
                    value="<?php echo esc_attr( get_post_meta( get_the_ID(), '_input', true ) ); ?>">
        <?php
    }

    /**
     * Save the metadata from the `form()`. The nonce will be verified automatically.
     *
     * @param int $post_id The ID of the post.
     * @return none
     */
    public function save( $post_id )
    {
        update_post_meta( $post_id, '_input', $_POST['input'] );
    }
}

The result is following., (*3)

, (*4)

The Versions

27/09 2017

dev-stable

dev-stable

  Sources   Download

GPL v2

27/09 2017

2.3.0

2.3.0.0

  Sources   Download

GPL v2

27/09 2017

dev-master

9999999-dev

  Sources   Download

GPL v2

07/08 2017

2.2.0

2.2.0.0

  Sources   Download

GPL v2

07/08 2017

2.1.0

2.1.0.0

  Sources   Download

GPL v2

06/08 2017

2.0.0

2.0.0.0

  Sources   Download

GPL v2

06/08 2017

1.4.0

1.4.0.0

  Sources   Download

GPL v2

05/08 2017

1.3.0

1.3.0.0

  Sources   Download

GPL v2

05/08 2017

1.2.0

1.2.0.0

  Sources   Download

GPL v2

05/08 2017

1.0.0

1.0.0.0

  Sources   Download

GPL v2

05/08 2017

1.1.0

1.1.0.0

  Sources   Download

GPL v2