Skip to content

Commit

Permalink
Update post meta metaboxes
Browse files Browse the repository at this point in the history
Pass the ID to the fields class so it's available immediately
  • Loading branch information
robincornett committed May 8, 2019
1 parent 078f28d commit 2f1d17a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
Expand Up @@ -8,6 +8,21 @@
*/
class ScriptlessSocialSharingPostMetaFields {

/**
* The current post ID.
* @var $post_id
*/
private $post_id;

/**
* ScriptlessSocialSharingPostMetaFields constructor.
*
* @param $post_id
*/
public function __construct( $post_id ) {
$this->post_id = $post_id;
}

/**
* Generic field function.
*
Expand Down Expand Up @@ -49,7 +64,7 @@ public function do_image( $id, $label ) {
esc_attr( $id ),
esc_html( $label )
);
$meta = get_post_meta( get_the_ID(), $id, true );
$meta = get_post_meta( $this->post_id, $id, true );
$this->render_image_preview( $label, $meta );
$this->render_buttons( $id, $meta );
}
Expand Down Expand Up @@ -119,7 +134,7 @@ protected function do_textarea( $id, $label ) {
printf(
'<textarea class="large-text" rows="3" id="%1$s" name="%1$s" aria-label="%3$s">%2$s</textarea>',
esc_attr( $id ),
esc_textarea( get_post_meta( get_the_ID(), $id, true ) ),
esc_textarea( get_post_meta( $this->post_id, $id, true ) ),
esc_attr( $label )
);
}
Expand All @@ -131,7 +146,7 @@ protected function do_textarea( $id, $label ) {
* @param $label
*/
protected function do_checkbox( $id, $label ) {
$check = (bool) get_post_meta( get_the_ID(), $id, true );
$check = (bool) get_post_meta( $this->post_id, $id, true );
printf(
'<p><label for="%1$s"><input type="checkbox" id="%1$s" name="%1$s" value="1" %2$s/>%3$s</label>',
esc_attr( $id ),
Expand Down
20 changes: 13 additions & 7 deletions includes/postmeta/class-scriptlesssocialsharing-postmeta.php
Expand Up @@ -59,20 +59,26 @@ public function enqueue() {
if ( ! in_array( $screen->post_type, $this->post_types(), true ) ) {
return;
}
$handle = 'scriptless-upload';
$minify = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_register_script(
'scriptless-upload',
$handle,
plugins_url( "/js/image-upload{$minify}.js", dirname( __FILE__ ) ),
array( 'jquery', 'media-upload', 'thickbox' ),
SCRIPTLESSOCIALSHARING_VERSION,
true
);

wp_enqueue_media();
wp_enqueue_script( 'scriptless-upload' );
wp_localize_script( 'scriptless-upload', 'scriptlessL10n', array(
'text' => __( 'Select Image', 'scriptless-social-sharing' ),
) );
wp_enqueue_script( $handle );
wp_localize_script(
$handle,
'scriptlessL10n',
array(
'text' => __( 'Select Image', 'scriptless-social-sharing' ),
'pinterest' => __( 'Custom Pinterest Image', 'scriptless-social-sharing' ),
)
);
}

/**
Expand All @@ -82,8 +88,8 @@ public function enqueue() {
*/
public function do_metabox( $post ) {
wp_nonce_field( 'scriptlesssocialsharing_post_save', 'scriptlesssocialsharing_post_nonce' );
include_once plugin_dir_path( __FILE__ ) . 'class-scriptlesssocialsharing-postmeta-fields.php';
$fields_class = new ScriptlessSocialSharingPostMetaFields();
include_once 'class-scriptlesssocialsharing-postmeta-fields.php';
$fields_class = new ScriptlessSocialSharingPostMetaFields( $post->ID );
$fields = $this->get_fields();
foreach ( $fields as $field ) {
$fields_class->do_field( $field );
Expand Down

0 comments on commit 2f1d17a

Please sign in to comment.