ﺲﻳﺮﺑﺩﺭﻭﻭ ﻲﻓ URL ﻥﺍﻮﻨﻋ ﻦﻣ ﺓﺰﻴﻤﻣ ﺓﺭﻮﺻ ﺔﻓﺎﺿﺇ ﺔﻴﻔﻴﻛ
؟ﻚﻟﺫ ﻞﻌﻔﺗ ﻒﻴﻛ :ﺔﻌﺋﺎﺷ ﺔﻠﻜﺸﻣ ﻪﺟﺍﻮﺗ ﺖﻧﺃﻭ .ﻚﺑ ﺹﺎﺨﻟﺍ WordPress ﺖﻴﺒﺜﺗ ﻪﻴﻠﻋ ﻞﻤﻌﻳ ﻱﺬﻟﺍ
.ﺓﺰﻴﻤﻤﻟﺍ ﺓﺭﻮﺼﻟﺍ ﻊﻣ ﻞﻣﺎﻌﺘﻨﺳ ﻚﻟﺫ ﺪﻌﺑﻭ ،ﺎﻴًﻜﻴﻣﺎﻨﻳﺩ ﺪﻳﺪﺟ ﺭﻮﺸﻨﻣ ءﺎﺸﻧﺈﺑ ﻡﻮﻘﻨﺳ ﻰﻟﻭﻷﺍ ﺓ
ﺎﻴًﻜﻴﻣﺎﻨﻳﺩ ﺭﻮﺸﻨﻣ ءﺎﺸﻧﺇ :1 ﺓﻮﻄﺨﻟﺍ
.ﻱﺪﻳ ﻝﻭﺎﻨﺘﻣ ﻲﻓ ﺲﻴﻟ .ﺪﻳﺪﺟ ﺭﻮﺸﻨﻣ ءﺎﺸﻧﺇ ﻢﺘﻴﺳ ﺔﺤﻔﺼﻟﺍ ﻞﻴﻤﺤﺗ ﻢﺘﻳ ﺓﺮﻣ ﻞﻛ ﻲﻓ ﻪﻧﺈﻓ ﻻﺇﻭ
// Register Post Data
$post = array();
$post['post_status'] = 'publish';
$post['post_type'] = 'post'; // can be a CPT too
$post['post_title'] = 'My New Post';
$post['post_content'] = 'My new post content';
$post['post_author'] = 1;
// Create Post
$post_id = wp_insert_post( $post );.ﺓﺰﻴﻤﻤﻟﺍ ﺓﺭﻮﺼﻟﺍ ﺔﻓﺎﺿﻹ ﺖﻗﻮﻟﺍ ﻥﺎﺣ ﻥﻵﺍ .ﺪﻳﺪﺟ ﺭﻮﺸﻨﻣ ءﺎﺸﻧﺇ ﻰﻟﺇ ﺔﻃﺎﺴﺒﺑ ﺰﻣﺮﻟﺍ ﺍﺬﻫ ﻞﻴﻐ
ﺓﺰﻴﻤﻤﻟﺍ ﺓﺭﻮﺼﻟﺍ ﺔﻓﺎﺿﺇ :2 ﺓﻮﻄﺨﻟﺍ
:WordPress ﻒﺋﺎﻇﻭ ﺾﻌﺑ ﻡﺍﺪﺨﺘﺳﺍ ﺎﻨﻴﻠﻋ ﻦﻴﻌﺘﻳ ،URL ﻥﺍﻮﻨﻋ ﻦﻣ ﺓﺰﻴﻤﻤﻟﺍ ﺓﺭﻮﺼﻟﺍ ﺔﻓﺎﺿﻹ
- wp_upload_dir() : ﻞﻴﻤﺤﺘﻟﺍ ﺞﻣﺎﻧﺮﺑ ﺪﻠﺠﻣ ﺭﺎﺴﻣ ﺩﺍﺩﺮﺘﺳﻻ
- wp_mkdir_p() : ﺕﺎﻧﻭﺫﻷﺍ ﻦﻴﻴﻌﺗﻭ ﺪﻠﺠﻣ ءﺎﺸﻧﻹ
- wp_check_filetype() : ﻖﻓﺮﻤﻟﺍ ﻖﻴﺴﻨﺗ ﻦﻣ ﻖﻘﺤﺘﻠﻟ
- sanitize_file_name() : ﻖﻓﺮﻤﻟﺍ ﻒﻠﻤﻟﺍ ﻢﺳﺍ ﻖﻴﺴﻨﺘﻟ
- wp_insert_attachment() : ﻖﻓﺮﻣ ءﺎﺸﻧﻹ
- wp_generate_attachment_metadata(): ﺕﺎﻘﻓﺮﻤﻟﺍ ﻒﻳﺮﻌﺗ ﺕﺎﻧﺎﻴﺑ ءﺎﺸﻧﻹ
- wp_update_attachment_metadata() : ﺕﺎﻘﻓﺮﻤﻠﻟ ﺔﻴﻔﻳﺮﻌﺘﻟﺍ ﺕﺎﻧﺎﻴﺒﻟﺍ ﺚﻳﺪﺤﺘﻟ
- set_post_thumbnail() : ﺓﺰﻴﻤﻣ ﺓﺭﻮﺸﻨﻣ ﺓﺭﻮﺼﻛ ﻖﻓﺮﻤﻟﺍ ﻦﻴﻴﻌﺘﻟ
.ﻲﺼﻨﻟﺍ ﺞﻣﺎﻧﺮﺒﻟﺍ ﺍﺬﻫ ﻞﻴﻐﺸﺗ ﺪﻨﻋ ﻂﺒﻀﻟﺎﺑ ﺙﺪﺤﻳ ﺎﻣ ﺔﻳﺅﺭ ﻦﻣ ﻦﻜﻤﺘﺗ ﻰﺘﺣ ءﺍﺮﺟﺇ ﻞﻛ ﻰﻠﻋ ﻖﻴ
// Add Featured Image to Post
$image_url = 'http://s.wordpress.org/style/images/wp-header-logo.png'; // Define the image URL here
$image_name = 'wp-header-logo.png';
$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'] . '/' . $filename;
} else {
$file = $upload_dir['basedir'] . '/' . $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 );!ﻖﺋﺎﻗﺩ ﻥﻮﻀﻏ ﻲﻓ ﺎﻫﺅﺎﺸﻧﺇ ﻢﺗ ﻲﺘﻟﺍ ﺓﺪﻳﺪﺠﻟﺍ ﺕﺎﻛﺭﺎﺸﻤﻟﺍ ﺕﺎﺌﻣ ﻰﻠﻋ ﻞﺼﺤﺘﺳ ﻻﺇﻭ ،ﻚﻟﺫ ﻞﺒﻗ ﺔ
!ﻒﻄﺘﻘﻤﻟﺍ ﺍﺬﻫ ﻦﻣ ﻪﺋﺎﺸﻧﺈﺑ ﺖﻤﻗ ﺎﻤﺑ ﺎﻧﺮﺒﺧﺃﻭ ﺎﻘًﻴﻠﻌﺗ ﻙﺮﺗﺍ ﻚﻠﻀﻓ ﻦﻣ ؟ﺍﺪًﻴﻔﻣ ﻒﻄﺘﻘﻤﻟﺍ ﺍﺬﻫ
