Skip to content

Commit

Permalink
#1289 Hide image into the post option metabox, clean up function.php
Browse files Browse the repository at this point in the history
  • Loading branch information
FitoreGashi committed May 25, 2023
1 parent 4c638d3 commit f958d35
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 58 deletions.
57 changes: 0 additions & 57 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,60 +396,3 @@ function fau_embedded_posts( $query ) {
require_once( get_template_directory() . '/functions/gutenberg.php');






// Move the following block to functions/custom-fields.php please...

/*-----------------------------------------------------------------------------------*/
/*Hide and show feutured image
/*-----------------------------------------------------------------------------------*/
function hide_featured_image_meta_box() {
add_meta_box( 'hide_featured_image', 'Featured Image', 'hide_featured_image_callback', 'post', 'side', 'low' );
}
add_action( 'add_meta_boxes', 'hide_featured_image_meta_box' );
function hide_featured_image_callback( $post ) {
$value = get_post_meta( $post->ID, '_hide_featured_image', true );
echo '<label for="hide-featured-image"><input type="checkbox" id="hide-featured-image" name="hide_featured_image" value="1"' . checked( $value, 1, false ) . '> Hide featured image from this post</label>';
}


function hide_featured_image_save_post( $post_id ) {
if ( isset( $_POST['hide_featured_image'] ) ) {
update_post_meta( $post_id, '_hide_featured_image', 1 );
} else {
delete_post_meta( $post_id, '_hide_featured_image' );
}

// Add the following code to set a cookie with the checkbox value
// setcookie( 'hide_featured_image', isset( $_POST['hide_featured_image'] ), time() + 86400, COOKIEPATH, COOKIE_DOMAIN );

// Rework this please. See: https://github.com/RRZE-Webteam/FAU-Einrichtungen/issues/1288
}
add_action( 'save_post', 'hide_featured_image_save_post' );


/*-----------------------------------------------------------------------------------*/
/* Outside-box image post block
*
* Note: Please move Block Editor stuff to functions/gutenberg.php
*/
/*-----------------------------------------------------------------------------------*/
function fau_custom_image_blocks() {
wp_register_script(
'my-custom-blocks',
get_template_directory_uri() . '/js/fau-costum-image-block.min.js',
array( 'wp-blocks', 'wp-editor' ),
true
);
register_block_type( 'my-blocks/full-width-image', array(
'editor_script' => 'my-custom-blocks',
) );
}
add_action( 'init', 'fau_custom_image_blocks' );


/*-----------------------------------------------------------------------------------*/
/* This is the end of the code as we know it
/*-----------------------------------------------------------------------------------*/
23 changes: 22 additions & 1 deletion functions/custom-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ function fau_metabox_cf_setup() {
add_action('add_meta_boxes_page', 'fau_add_metabox_page');
add_action('add_meta_boxes_post', 'fau_add_metabox_post');


/* Save sidecontent */
add_action('save_post', 'fau_save_metabox_page_untertitel', 10, 2);

Expand Down Expand Up @@ -133,7 +132,19 @@ function fau_add_metabox_post() {
'fau_do_metabox_post_vidpod',
'post', 'side', 'low'
);

// Hide Featured Image meta box
add_meta_box(
'fau_metabox_post_teaser',
esc_html__('Beitragsoptionen', 'fau'),
'fau_do_metabox_post_teaser',
'post', 'normal', 'high'
);
}




/*-----------------------------------------------------------------------------------*/
/* Display Options for posts
/*-----------------------------------------------------------------------------------*/
Expand Down Expand Up @@ -180,6 +191,9 @@ function fau_do_metabox_post_teaser($object, $box) {
$sliderimage = get_post_meta($object->ID, 'fauval_slider_image', true);
fau_form_image('fauval_slider_image', $sliderimage, __('Bühnenbild', 'fau'), __('An dieser Stelle kann optional ein alternatives Bild für die Bühne der Startseite ausgewählt werden, falls das normale Beitragsbild hierzu nicht verwendet werden soll.', 'fau'), 540, 150);
}
$value = get_post_meta($object->ID, '_hide_featured_image', true);

echo '<label for="hide-featured-image"><input type="checkbox" id="hide-featured-image" name="hide_featured_image" value="1"' . checked($value, 1, false) . '> Hide featured image from this post</label>';
}
/*-----------------------------------------------------------------------------------*/
/* Save the meta box's post metadata.
Expand Down Expand Up @@ -239,7 +253,14 @@ function fau_save_post_teaser($post_id, $post) {
} else {
delete_post_meta($post_id, 'fauval_slider_image');
}
if (isset($_POST['hide_featured_image'])) {
update_post_meta($post_id, '_hide_featured_image', 1);
} else {
delete_post_meta($post_id, '_hide_featured_image');
}
}



/* Display Options for pages */
function fau_do_metabox_post_topevent($object, $box) {
Expand Down
25 changes: 25 additions & 0 deletions functions/gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,31 @@ function fau_is_newsletter_plugin_active() {
return false;
}



/*-----------------------------------------------------------------------------------*/
/* Outside-box image post block
/*-----------------------------------------------------------------------------------*/
function fau_custom_image_blocks() {
wp_register_script(
'my-custom-blocks',
get_template_directory_uri() . '/js/fau-costum-image-block.min.js',
array( 'wp-blocks', 'wp-editor' ),
true
);
register_block_type( 'my-blocks/full-width-image', array(
'editor_script' => 'my-custom-blocks',
) );
}
add_action( 'init', 'fau_custom_image_blocks' );


/*-----------------------------------------------------------------------------------*/
/* This is the end of the code as we know it
/*-----------------------------------------------------------------------------------*/



/*-----------------------------------------------------------------------------------*/
/* Defined allowed core block types if theme is used in Gutenberg Block Editor
/*-----------------------------------------------------------------------------------*/
Expand Down

0 comments on commit f958d35

Please sign in to comment.