Plugin Directory

Changeset 3213751


Ignore:
Timestamp:
12/27/2024 11:21:37 AM (15 months ago)
Author:
socrapop
Message:

2.3.1 with fix

Location:
travelers-map
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • travelers-map/tags/2.3.0/cttm-settings.php

    r3213742 r3213751  
    111111<?php
    112112}
    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
    143114
    144115add_action('admin_init', 'cttm_admin_init');
    145116function cttm_admin_init()
    146117{
    147     cttm_create_new_marker(__('Default - Black', 'travelers-map'), 'black', 'cttm_markers-black.png');
    148118    //Register new setting "cttm_options" in database (array).
    149119    register_setting('cttm_options', 'cttm_options', 'cttm_validate_option');
  • travelers-map/trunk/cttm-settings.php

    r3213742 r3213751  
    111111<?php
    112112}
    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
    143114
    144115add_action('admin_init', 'cttm_admin_init');
    145116function cttm_admin_init()
    146117{
    147     cttm_create_new_marker(__('Default - Black', 'travelers-map'), 'black', 'cttm_markers-black.png');
    148118    //Register new setting "cttm_options" in database (array).
    149119    register_setting('cttm_options', 'cttm_options', 'cttm_validate_option');
Note: See TracChangeset for help on using the changeset viewer.