Example #1
0
 /**
  * Save the custom Status, used when posting to an Fan Page's Timeline
  *
  * @since 1.0
  * @param int $post_id post identifier
  */
 public static function save($post_id)
 {
     // verify if this is an auto save routine.
     // If it is our form has not been submitted, so we dont want to do anything
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     // verify this came from the our screen and with proper authorization,
     // because save_post can be triggered at other times
     if (!isset($_POST[self::FIELD_MESSAGE]) || empty($_POST[self::NONCE_NAME]) || !wp_verify_nonce($_POST[self::NONCE_NAME], plugin_basename(__FILE__))) {
         return;
     }
     // Check permissions
     $post_type = get_post_type($post_id);
     if (!($post_type && post_type_supports($post_type, 'author'))) {
         return;
     }
     if (!class_exists('Facebook_Social_Publisher')) {
         require_once dirname(__FILE__) . '/social_publisher.php';
     }
     $capability_singular_base = Facebook_Social_Publisher::post_type_capability_base($post_type);
     if (!current_user_can('edit_' . $capability_singular_base, $post_id)) {
         return;
     }
     $message = trim(sanitize_text_field($_POST[self::FIELD_MESSAGE]));
     if ($message) {
         update_post_meta($post_id, self::POST_META_KEY, $message);
     }
 }
 /**
  * Save submitted post after create / update
  *
  * @since 1.1
  * @param int $post_id post identifier
  */
 public static function save($post_id)
 {
     // verify if this is an auto save routine.
     // If it is our form has not been submitted, so we dont want to do anything
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     if (!class_exists('Facebook_User')) {
         require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/facebook-user.php';
     }
     $facebook_user = Facebook_User::get_current_user();
     if (!$facebook_user) {
         return;
     }
     // verify this came from the our screen and with proper authorization,
     // because save_post can be triggered at other times
     if (!isset($_POST[self::FIELD_AUTOCOMPLETE]) || empty($_POST[self::NONCE_NAME]) || !wp_verify_nonce($_POST[self::NONCE_NAME], plugin_basename(__FILE__))) {
         return;
     }
     // Check permissions
     $post_type = get_post_type($post_id);
     if (!($post_type && post_type_supports($post_type, 'author'))) {
         return;
     }
     if (!class_exists('Facebook_Social_Publisher')) {
         require_once dirname(dirname(__FILE__)) . '/social_publisher.php';
     }
     $capability_singular_base = Facebook_Social_Publisher::post_type_capability_base($post_type);
     if (!current_user_can('edit_' . $capability_singular_base, $post_id)) {
         return;
     }
     // process data then save it
     preg_match_all('/\\[(\\d*?)\\|(.*?)\\]/su', $_POST[self::FIELD_AUTOCOMPLETE], $friend_details, PREG_SET_ORDER);
     $friends_details_meta = array();
     foreach ($friend_details as $friend_detail) {
         $friends_details_meta[] = array('id' => $friend_detail[1], 'name' => sanitize_text_field($friend_detail[2]));
     }
     if (!empty($friends_details_meta)) {
         update_post_meta($post_id, self::POST_META_KEY_MENTIONS, $friends_details_meta);
     }
     $message = trim(sanitize_text_field($_POST[self::FIELD_MESSAGE]));
     if ($message) {
         update_post_meta($post_id, self::POST_META_KEY_MESSAGE, $message);
     }
 }