Changeset 3213751
- Timestamp:
- 12/27/2024 11:21:37 AM (15 months ago)
- Location:
- travelers-map
- Files:
-
- 2 edited
-
tags/2.3.0/cttm-settings.php (modified) (1 diff)
-
trunk/cttm-settings.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
travelers-map/tags/2.3.0/cttm-settings.php
r3213742 r3213751 111 111 <?php 112 112 } 113 function cttm_create_new_marker($title, $content, $imagename) 114 { 115 //Check if post exist by title and content, so we don't duplicate posts on re-activation of plugin 116 if (post_exists($title, $content) == 0) { 117 $cttm_marker_post = array( 118 'post_title' => $title, 119 'post_content' => $content, 120 'post_type' => "cttm-marker", 121 'post_status' => 'publish' 122 ); 123 //Insert post, return the id of the newly created post. If there is an error, return 0. 124 $cttm_post_id = wp_insert_post($cttm_marker_post); 125 126 //Check if returned id is different from 0. 127 if ($cttm_post_id != 0) { 128 129 //Set file url with $imagename 130 $cttm_file_url = plugin_dir_url(__FILE__) . 'images/' . $imagename; 131 //Download the image from specified URL and attach it to post 132 $cttm_image_id = media_sideload_image($cttm_file_url, $cttm_post_id, null, 'id'); 133 //check if image was downloaded without error 134 if (!is_wp_error($cttm_image_id)) { 135 set_post_thumbnail($cttm_post_id, $cttm_image_id); 136 }else{ 137 //if error with thumbnail (frequently SSL error), remove the marker. 138 wp_delete_post($cttm_post_id, true); 139 } 140 } 141 } 142 } 113 143 114 144 115 add_action('admin_init', 'cttm_admin_init'); 145 116 function cttm_admin_init() 146 117 { 147 cttm_create_new_marker(__('Default - Black', 'travelers-map'), 'black', 'cttm_markers-black.png');148 118 //Register new setting "cttm_options" in database (array). 149 119 register_setting('cttm_options', 'cttm_options', 'cttm_validate_option'); -
travelers-map/trunk/cttm-settings.php
r3213742 r3213751 111 111 <?php 112 112 } 113 function cttm_create_new_marker($title, $content, $imagename) 114 { 115 //Check if post exist by title and content, so we don't duplicate posts on re-activation of plugin 116 if (post_exists($title, $content) == 0) { 117 $cttm_marker_post = array( 118 'post_title' => $title, 119 'post_content' => $content, 120 'post_type' => "cttm-marker", 121 'post_status' => 'publish' 122 ); 123 //Insert post, return the id of the newly created post. If there is an error, return 0. 124 $cttm_post_id = wp_insert_post($cttm_marker_post); 125 126 //Check if returned id is different from 0. 127 if ($cttm_post_id != 0) { 128 129 //Set file url with $imagename 130 $cttm_file_url = plugin_dir_url(__FILE__) . 'images/' . $imagename; 131 //Download the image from specified URL and attach it to post 132 $cttm_image_id = media_sideload_image($cttm_file_url, $cttm_post_id, null, 'id'); 133 //check if image was downloaded without error 134 if (!is_wp_error($cttm_image_id)) { 135 set_post_thumbnail($cttm_post_id, $cttm_image_id); 136 }else{ 137 //if error with thumbnail (frequently SSL error), remove the marker. 138 wp_delete_post($cttm_post_id, true); 139 } 140 } 141 } 142 } 113 143 114 144 115 add_action('admin_init', 'cttm_admin_init'); 145 116 function cttm_admin_init() 146 117 { 147 cttm_create_new_marker(__('Default - Black', 'travelers-map'), 'black', 'cttm_markers-black.png');148 118 //Register new setting "cttm_options" in database (array). 149 119 register_setting('cttm_options', 'cttm_options', 'cttm_validate_option');
Note: See TracChangeset
for help on using the changeset viewer.