custom field – How to make a complete Meta Box part of a complete Post Type?

I receive the code complete, but I don’t know how to make the Post Type loads the MetaBox when creating a new Post, here is the Post Type:

if ( ! function_exists('cpt_campaign_details') ) {

// Register Custom Post Type
function cpt_campaign_details() {

    $labels = array(
        'name'                  => _x( 'Campaign Details', 'Post Type General Name', 'text_domain' ),
        'singular_name'         => _x( 'Campaign Detail', 'Post Type Singular Name', 'text_domain' ),
        'menu_name'             => __( 'Campaign Details', 'text_domain' ),
        'name_admin_bar'        => __( 'Campaign Detail Post', 'text_domain' ),
        'archives'              => __( 'Campaign Details Archives', 'text_domain' ),
        'attributes'            => __( 'Campaign Detail Attributes', 'text_domain' ),
        'parent_item_colon'     => __( 'Parent Campaign Detail:', 'text_domain' ),
        'all_items'             => __( 'All Campaign Details', 'text_domain' ),
        'add_new_item'          => __( 'Add New Campaign Detail', 'text_domain' ),
        'add_new'               => __( 'Add New', 'text_domain' ),
        'new_item'              => __( 'New Campaign Detail', 'text_domain' ),
        'edit_item'             => __( 'Edit Campaign Detail', 'text_domain' ),
        'update_item'           => __( 'Update Campaign Detail', 'text_domain' ),
        'view_item'             => __( 'View Campaign Detail', 'text_domain' ),
        'view_items'            => __( 'View Campaign Detail', 'text_domain' ),
        'search_items'          => __( 'Search Campaign Details', 'text_domain' ),
        'not_found'             => __( 'Not found', 'text_domain' ),
        'not_found_in_trash'    => __( 'Not found in Trash', 'text_domain' ),
        'featured_image'        => __( 'Featured Image', 'text_domain' ),
        'set_featured_image'    => __( 'Set featured image', 'text_domain' ),
        'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
        'use_featured_image'    => __( 'Use as featured image', 'text_domain' ),
        'insert_into_item'      => __( 'Insert into Campaign Detail', 'text_domain' ),
        'uploaded_to_this_item' => __( 'Uploaded to this Campaign Detail', 'text_domain' ),
        'items_list'            => __( 'Campaign Details list', 'text_domain' ),
        'items_list_navigation' => __( 'Campaign Details list navigation', 'text_domain' ),
        'filter_items_list'     => __( 'Filter Campaign Details list', 'text_domain' ),
    );
    $args = array(
        'label'                 => __( 'Campaign Detail', 'text_domain' ),
        'description'           => __( 'This post is used to manage all Campaign details', 'text_domain' ),
        'labels'                => $labels,
        'supports'              => array( 'title', 'thumbnail', 'page-attributes' ),
        'taxonomies'            => array( 'category', 'post_tag' ),
        'hierarchical'          => true,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        'menu_icon'             => 'dashicons-megaphone',
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => true,
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'capability_type'       => 'page',
    );
    register_post_type( 'campaign_details', $args );

}
add_action( 'init', 'cpt_campaign_details', 0 );

}

And here is the Meta Box:

class CampDeta_Resu {

    public function __construct() {

        if ( is_admin() ) {
            add_action( 'load-post.php',     array( $this, 'init_metabox' ) );
            add_action( 'load-post-new.php', array( $this, 'init_metabox' ) );
        }

    }

    public function init_metabox() {

        add_action( 'add_meta_boxes',        array( $this, 'add_metabox' )         );
        add_action( 'save_post',             array( $this, 'save_metabox' ), 10, 2 );

    }

    public function add_metabox() {

        add_meta_box(
            'CampDeta_Resu',
            __( 'Campaign Details Results', 'text_domain' ),
            array( $this, 'render_metabox' ),
            'post',
            'normal',
            'default'
        );

    }

    public function render_metabox( $post ) {

        // Retrieve an existing value from the database.
        $cade_re_results_numbers = get_post_meta( $post->ID, 'cade_re_results_numbers', true );
        $cade_re_results_legend = get_post_meta( $post->ID, 'cade_re_results_legend', true );

        // Set default values.
        if( empty( $cade_re_results_numbers ) ) $cade_re_results_numbers = '';
        if( empty( $cade_re_results_legend ) ) $cade_re_results_legend = '';

        // Form fields.
        echo '<table class="form-table">';

        echo '  <tr>';
        echo '      <th><label for="cade_re_results_numbers" class="cade_re_results_numbers_label">' . __( 'Number', 'text_domain' ) . '</label></th>';
        echo '      <td>';
        echo '          <input type="text" id="cade_re_results_numbers" name="cade_re_results_numbers" class="cade_re_results_numbers_field" placeholder="' . esc_attr__( '', 'text_domain' ) . '" value="' . esc_attr( $cade_re_results_numbers ) . '">';
        echo '          <p class="description">' . __( 'This is the number that will appear over the legend. Example: 5.4M | 8.4M+ | 5x', 'text_domain' ) . '</p>';
        echo '      </td>';
        echo '  </tr>';

        echo '  <tr>';
        echo '      <th><label for="cade_re_results_legend" class="cade_re_results_legend_label">' . __( 'Legend', 'text_domain' ) . '</label></th>';
        echo '      <td>';
        echo '          <input type="text" id="cade_re_results_legend" name="cade_re_results_legend" class="cade_re_results_legend_field" placeholder="' . esc_attr__( '', 'text_domain' ) . '" value="' . esc_attr( $cade_re_results_legend ) . '">';
        echo '          <p class="description">' . __( 'This text will go below the number and will define what the number means. Example: Total print reach | Visits | Engagement growth', 'text_domain' ) . '</p>';
        echo '      </td>';
        echo '  </tr>';

        echo '</table>';

    }

    public function save_metabox( $post_id, $post ) {

        // Sanitize user input.
        $cade_re_new_results_numbers = isset( $_POST( 'cade_re_results_numbers' ) ) ? sanitize_text_field( $_POST( 'cade_re_results_numbers' ) ) : '';
        $cade_re_new_results_legend = isset( $_POST( 'cade_re_results_legend' ) ) ? sanitize_text_field( $_POST( 'cade_re_results_legend' ) ) : '';

        // Update the meta field in the database.
        update_post_meta( $post_id, 'cade_re_results_numbers', $cade_re_new_results_numbers );
        update_post_meta( $post_id, 'cade_re_results_legend', $cade_re_new_results_legend );

    }

}

new CampDeta_Resu;

I googled “add a created metabox to a post type” and a lot of things like that and there is a lot of tutorials but unfortunately I can’t make it work.

permissions – POST Product Image w/ REST API Exception

I have Magento running in a Bitnami Docker container, and
trying to upload an image for a product using the REST API causes an exception.

I initially suspected a permissions error, so the following subdirectories of the Magento installation are CHMOD 777:

Please note I’ve removed the base64 encoded image data from the code snippet below in order to keep this post short and readable.

Not sure what else to look for – a config option maybe?.
Any pointers in the right direction appreciated.

Data I’m sending to server:

{
    "entry": {
        "content": {
            "base64_encoded_data": ***(IMAGE DATA SUPPLIED HERE, NOT SHOWN)***,
            "name": "Mizuno-2.jpg",
            "type": "image/jpeg"
        },
        "disabled": false,
        "file": "Mizuno-2.jpg",
        "id": 0,
        "label": "Mizuno 2",
        "media_type": "image",
        "position": 1,
        "types": (
            "image"
        )
    }
}

REST API Error:

2021-07-26:23:25:27,818 DEBUG    (connectionpool.py:0452) http://localhost:8080 "POST /rest/V1/products/Mizuno-2/media HTTP/1.1" 500 104
<Response (500)>
{
    "message": "Internal Error. Details are available in Magento log file. Report ID: webapi-60ff4467c74b8"
}

Server Log Exception Message:

(2021-07-26 23:25:27) main.CRITICAL: Report ID: webapi-60ff4467c74b8; Message: Notice: file_get_contents(): file created in the system's temporary directory in /bitnami/magento/vendor/laminas/laminas-http/src/PhpEnvironment/Request.php on line 96 {"exception":"(object) (Exception(code: 0): Report ID: webapi-60ff4467c74b8; Message: Notice: file_get_contents(): file created in the system's temporary directory in /bitnami/magento/vendor/laminas/laminas-http/src/PhpEnvironment/Request.php on line 96 at /bitnami/magento/vendor/magento/framework/Webapi/ErrorProcessor.php:208, Exception(code: 0): Notice: file_get_contents(): file created in the system's temporary directory in /bitnami/magento/vendor/laminas/laminas-http/src/PhpEnvironment/Request.php on line 96 at /bitnami/magento/vendor/magento/framework/App/ErrorHandler.php:61)"} ()

WordPress post using block editor displays error when adding the string “cmd.exe”

Today a member of our content team reported that when they attempted to save a post in block editor mode, they continually received an error.

Updating failed. The response is not a valid JSON response.

After some debugging steps we determined that the string “cmd.exe” was to blame. When that string was present the author always got the above error. But when the string was gone or had a space after the “.”, the post saved and displayed just fine. I recreated it in a brand new post, with only the string “cmd.exe” and confirmed that I got the same error.

enter image description here

When viewing the post in the “code editor” view, this is the contents:

<!-- wp:paragraph -->
<p>cmd.exe</p>
<!-- /wp:paragraph -->

We’re currently running WP 5.7.2 on WP Engine.

Does anyone know why this might be happening? I understand it’s probably a security issue, but this seems quite the ham-fisted approach.

I will do 1000 words article, blog, and content writing for website, social media, and blog post for $5

I will do 1000 words article, blog, and content writing for website, social media, and blog post

Respected Buyers Welcome to my creative writing service.

Struggling to find the precise words to express your idea? Whether it can be a very technical article or even a social media post, I’m here to groom your lettering perfectly.
Writing is my appetite, and I LOVE positioning my imagination and skill to worthy useā€”this is where I genuinely spark!

My name is Miraz, and I will be your trustworthy research associate who will deliver you timely deliveries without compromising quality. As a dedicated content writer, rest guaranteed that my writing is thoroughly researched and well organized.

Furthermore, my widespread exposure to content writing portrays my ability to precise my feelings and express my message through words with my exclusive touch of creative appearance.

My services include:

  • Article writing
  • Blog Writing
  • Website Content writing
  • Copywriting
  • Product Descriptions
  • Social Media content writing
  • Creative writing
  • Essays writing
  • Revise your writing

The creative content will meet all the following specifications.

  • Well Researched content
  • 100% plagiarism-free content
  • Top-Notch grammar
  • Fast Response
  • High quality in terms of creativity and expression
  • Timely Turnaround and deliveries
  • Free and Unlimited revisions, if any
  • 100 percent customer satisfaction

To get started on your work, I will prerequisite the topic you need to research, the number of words required, and the due delivery date.
Let me pen down one for you, and who recognizes, you might fell in affection with my work.
Reach out, and let’s get started!

Best wishes

Thank you!!

.

tinymce – Is there a way to grab the current value of the editor in Gutenburg/Classic WordPress editor? (Not the saved value of the post!)

I’m trying to make my plugin “Gutenburg – compatible”. I have some issues when replacing the editors contents. Before I could just change value by using #content but with Gutenburg there’s obviously a new approach with REST API.

Is there a way to grab the current value of the editor? (Not the saved value of the post!)

I want this because I want to replace values of the core/editor in realtime. It works with the classic editor active but I don’t want to require that.

let old_content = '';
old_content = wp.data.select( 'core/editor' ).getCurrentPost().content;     
//TINYMCE => old_content = $('textarea#content').html();

//Aim is to do a replace like this (and this works but only FIRST time because old_content 
//fetches from server/db instead of the actual editor (If I understand this correctly)

wp.data.dispatch( 'core/block-editor' ).resetBlocks( wp.blocks.parse( new_content ) );
//TINYMCE: $('textarea#content').html( new_content );

—Curious— How to edit the title of an embeded post?

Whenever I paste an internal link, WordPress automatically grabs its page title. How can I edit that? I am not a developer.

enter image description here

[AP] Minimum Characters for Post Count | NullScripts

This addon will stop users post counts from increasing, unless their message length exceeds a number which you can configure in the Admin panel (by default it’s 75).

This can be useful if you hire paid posters or do post exchanges, and don’t want people to cheese their way with low effort posts.

.(tagsToTranslate)null scripts(t)nulled(t)nulled sites(t)nulled forum(t)nulled script(t)nulled scripts(t)nulled script forum(t)best nulled scripts site(t)xenforo nulled(t)xenforo 2 nulled(t)xenforo nulled themes(t)seo xenforo 2(t)xenforo themes(t)seo for xenforo(t)vbulletin nulled(t)vbulletin 5 nulled(t)whmcs nulled(t)hexa whmcs(t)whmcs addons nulled(t)whmcs templates nulled(t)whmcs template nulled(t)whmcs modules nulled(t)whmcs themes nulled(t)cs-cart nulled(t)xfilesharing pro nulled(t)blesta nulled(t)arrowchat nulled(t)multi vendor ecommerce script nulled(t)seo providers(t)adsense alternative

php – Add Featured Image to Existing Post

I have already created thousands of product as posts (CSV Import). They have a custom post type. Now, I would like to assign featured image to each existing post programmatically (without manually entering each post and setting the featured images more than 3,000 times).

Additional info:

  • Import plugin have not worked out, so I cannot attach the images using CSV import.
  • I use a custom field called ‘ean’ with each prduct, and it is standing as the unique serial number. It is an interger, for example: “5999626322456”. The same interger is standing for name of the image (i.e. 5999626322456.jpg).

What code do you recommend to use? I tried these two (among many), but they do not work. What do I do wrong?

function set_post_thumbnail( $post, $thumbnail_id ) {
    $post    = get_post( $post );
    $ean_url = rwmb_get_value( 'ean' );
    $kep_url = $ean_url . '.jpg';
    $thumbnail_id = attachment_url_to_postid( $kep_url );
    if ( $post && $thumbnail_id && get_post( $thumbnail_id ) ) {
        if ( wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) ) {
            return update_post_meta( $post->ID, '_thumbnail_id', $thumbnail_id );
        } else {
            return delete_post_meta( $post->ID, '_thumbnail_id' );
        }
    }
    return false;
}

// Add Featured Image to Post

$ean_url          = rwmb_get_value( 'ean' );
$image_url        = '/wp-content/uploads/' . $ean_url . '.jpg'; // Define the image URL here
$image_name       = $ean_url . '.jpg';
$upload_dir       = wp_upload_dir(); // Set upload folder
$image_data       = file_get_contents($image_url); // Get image data
$unique_file_name = wp_unique_filename( $upload_dir('path'), $image_name ); // Generate unique name
$filename         = basename( $unique_file_name ); // Create image file name

// Check folder permission and define file location
if( wp_mkdir_p( $upload_dir('path') ) ) {
    $file = $upload_dir('path') . "https://wordpress.stackexchange.com/" . $filename;
} else {
    $file = $upload_dir('basedir') . "https://wordpress.stackexchange.com/" . $filename;
}

// Create the image  file on the server
file_put_contents( $file, $image_data );

// Check image file type
$wp_filetype = wp_check_filetype( $filename, null );

// Set attachment data
$attachment = array(
    'post_mime_type' => $wp_filetype('type'),
    'post_title'     => sanitize_file_name( $filename ),
    'post_content'   => '',
    'post_status'    => 'inherit'
);

// Create the attachment
$attach_id = wp_insert_attachment( $attachment, $file, $post_id );

// Include image.php
require_once(ABSPATH . 'wp-admin/includes/image.php');

// Define attachment metadata
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );

// Assign metadata to attachment
wp_update_attachment_metadata( $attach_id, $attach_data );

// And finally assign featured image to post
set_post_thumbnail( $post_id, $attach_id );

[OzzModz] Link To Moderator That Last Edited The Post

Admin submitted a new resource:

[OzzModz] Link To Moderator That Last Edited The Post – Link to the moderator who edited the post

Small addon that changes the text " Last edited by a moderator: 34 minutes ago" into a link that leads to the profile of the moderator that last edited the post.

Read more about this resource…

.

editor – Edit Post with a parameter in URL

I was thinking in a way to make the editors have a quick way to access the current post editor.

I know we can manage this by showing a Link and make some conditionals to show to some users and login in users, but it would be cool to have something like this.

I thought first in something like:

add_action('init', 'edit_post_please');
function edit_post_please()
{
    if (is_user_logged_in() && current_user_can( 'edit_posts' )) {
        $protocol = ((!empty($_SERVER('HTTPS')) && $_SERVER('HTTPS') != 'off') || $_SERVER('SERVER_PORT') == 443) ? "https://" : "http://";
        $url = $protocol . $_SERVER('HTTP_HOST') . $_SERVER('REQUEST_URI');
    
        $id = url_to_postid($url);


        $parts = explode("/", $url);
        $editor = end($parts);
        $editor_link = get_edit_post_link($id);

        if ($editor == '?editor') {
            wp_redirect($editor_link);
            exit;
        }
    }
}

I haven’t think about the security issues or anything else this code does’t seem to work at all, I mean it redirects well to Dashboard but not to post I would like to edit.

$editor_link have the correct edit url, but seems that this could be a restriction of WP?