Changeset 2542760
- Timestamp:
- 06/04/2021 06:36:42 PM (5 years ago)
- Location:
- social-media-publish/trunk
- Files:
-
- 11 edited
-
README.txt (modified) (2 diffs)
-
admin/css/smp-admin.css (modified) (1 diff)
-
admin/js/facebook.js (modified) (2 diffs)
-
admin/js/smp-gutenberg.js (modified) (2 diffs)
-
admin/menu-tab-settings.php (modified) (1 diff)
-
admin/menu.php (modified) (2 diffs)
-
admin/post-hook.php (modified) (1 diff)
-
includes/facebook.php (modified) (4 diffs)
-
includes/metabox.php (modified) (3 diffs)
-
includes/notices.php (modified) (1 diff)
-
social-media-publish.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
social-media-publish/trunk/README.txt
r2542236 r2542760 2 2 Contributors: bogi1991 3 3 Donate link: https://www.paypal.com/donate?hosted_button_id=X2L4JMQ5C9DYN 4 Tags: social media, automation, instagram, auto post, auto publish5 Requires at least: 3.0.14 Tags: social media, automation, facebook instagram, auto post, auto publish 5 Requires at least: 5.0. 6 6 Tested up to: 5.7.2 7 7 Requires PHP: 7.2 8 Stable tag: 1.0. 08 Stable tag: 1.0.1 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 14 14 == Description == 15 15 16 This Plugin automatizate your Social Media processes, by publishing your posts to Social Media plattforms like Instagram. 17 We are using the open [Facebook API Graph](https://developers.facebook.com/docs) to communicate with Social Media plattforms. 16 This Plugin automatizate your Social Media processes, by publishing your posts to Social Media plattforms. 18 17 19 18 = A quick look into Social Media Publish: = 20 19 21 20 * **Auto Publish** - to Instagram 21 * **Auto Publish** - to Facebook 22 22 * **Reupload** - your post manually 23 23 24 24 25 25 == Changelog == 26 27 = 1.0.1 = 28 * Disable Reupload button during sending process 29 * Facebook auto publish after post 30 * Show tooltip with required permissions 26 31 27 32 = 1.0.0 = -
social-media-publish/trunk/admin/css/smp-admin.css
r2542221 r2542760 10 10 color: #f02929; 11 11 } 12 13 14 /* -------------------------------------------------------------------------- */ 15 /* Tooltip */ 16 /* -------------------------------------------------------------------------- */ 17 18 .smp-tooltip { 19 position: relative; 20 display: inline-block; 21 } 22 23 .smp-tooltip .smp-tooltiptext { 24 visibility: hidden; 25 /* width: 120px; */ 26 top: 100%; 27 left: 50%; 28 margin-left: -60px; /* Use half of the width (120/2 = 60), to center the tooltip */ 29 background-color: black; 30 color: #fff; 31 text-align: center; 32 border-radius: 5px; 33 padding: 3px; 34 35 /* Position the tooltip */ 36 position: absolute; 37 z-index: 1; 38 } 39 40 .smp-tooltip:hover .smp-tooltiptext { 41 visibility: visible; 42 } -
social-media-publish/trunk/admin/js/facebook.js
r2542221 r2542760 1 2 /** 3 * Initialize Facebook SDK 4 * @param {*} clientAppId 5 */ 1 6 function initFacebookSdk(clientAppId) { 2 7 FB.init({ … … 8 13 } 9 14 15 /** 16 * Show Facebook Login Dialog and get long live access token 17 * @param {*} app_id 18 * @param {*} app_secret 19 */ 10 20 function showLoginDialog(app_id, app_secret) { 11 21 FB.login(function (loginResponse) { -
social-media-publish/trunk/admin/js/smp-gutenberg.js
r2542221 r2542760 38 38 } 39 39 40 41 /* -------------------------------------------------------------------------- */ 42 /* Reupload */ 43 /* -------------------------------------------------------------------------- */ 44 45 function reupload(socialMediaName) { 46 // Disable button during send process 47 jQuery(`#${socialMediaName}-reupload`).attr("disabled", true); 48 49 jQuery.ajax({ 50 type: 'POST', 51 url: smp_gutenberg.ajaxurl, 52 data: { 53 action: `smp_${socialMediaName}_reupload`, 54 post_id: smp_gutenberg.post_id 55 }, 56 success: function (data) { 57 data = data.replace("0", ""); 58 showNotice(data); 59 60 // Enable button 61 jQuery(`#${socialMediaName}-reupload`).attr("disabled", false); 62 }, 63 error: function (errorThrown) { 64 var errorMessage = `${errorThrown['status']} ${errorThrown['statusText']}: ${errorThrown['responseText']}`; 65 showNotice(errorMessage, "error"); 66 67 // Enable button 68 jQuery(`#${socialMediaName}-reupload`).attr("disabled", false); 69 } 70 }); 71 } 72 40 73 /* -------------------------------------------------------------------------- */ 41 74 /* Button Action */ … … 44 77 // https://www.user-mind.de/ajax-richtig-in-wordpress-nutzen/ 45 78 jQuery("#instagram-reupload").click(function () { 46 // Send POST Request to call php function 47 jQuery.ajax({ 48 type: 'POST', 49 url: smp_gutenberg.ajaxurl, 50 data: { 51 action: 'smp_instagram_reupload', 52 post_id: smp_gutenberg.post_id 53 }, 54 success: function (data) { 55 data = data.replace("0", ""); 56 showNotice(data); 57 }, 58 error: function (errorThrown) { 59 var errorMessage = `${errorThrown['status']} ${errorThrown['statusText']}: ${errorThrown['responseText']}`; 60 showNotice(errorMessage, "error"); 61 } 62 }); 79 reupload("instagram"); 80 }); 81 82 jQuery("#facebook-reupload").click(function () { 83 reupload("facebook"); 63 84 }); 64 85 }); -
social-media-publish/trunk/admin/menu-tab-settings.php
r2542221 r2542760 24 24 <th scope="row">Instagram</th> 25 25 <td> 26 <label for="woocommerce_cart_redirect_after_add"> 27 <input type="checkbox" name="smp_instagram_auto_publish" value="1" <?php checked( esc_attr( get_option('smp_instagram_auto_publish')), 1 ); ?>> Enable auto publish after post 26 <label> 27 <div class="smp-tooltip"><span class="dashicons dashicons-editor-help"></span> 28 <span class="smp-tooltiptext">Required permissions: ads_management, business_management, instagram_basic, instagram_content_publish, pages_read_engagement</span> 29 </div> 30 31 <input type="checkbox" name="smp_instagram_auto_publish" value="1" 32 <?php checked( esc_attr( get_option('smp_instagram_auto_publish')), 1 ); ?> 33 > Enable auto publish after post 28 34 </label> 29 35 </td> 30 </tr> 36 </tr> 37 38 <tr> 39 <th scope="row">Facebook</th> 40 <td> 41 <label> 42 <div class="smp-tooltip"><span class="dashicons dashicons-editor-help"></span> 43 <span class="smp-tooltiptext">Required permissions: pages_manage_posts, pages_read_engagement</span> 44 </div> 45 46 <input type="checkbox" name="smp_facebook_auto_publish" value="1" 47 <?php checked( esc_attr( get_option('smp_facebook_auto_publish')), 1 ); ?> 48 > Enable auto publish after post 49 </label> 50 </td> 51 </tr> 31 52 </table> 32 53 -
social-media-publish/trunk/admin/menu.php
r2542221 r2542760 61 61 62 62 // Enqueue scripts 63 wp_enqueue_script('smp-admin', plugins_url('/js/smp-admin.js', __FILE__), array()); 63 64 // https://connect.facebook.net/en_US/sdk.js 64 65 wp_enqueue_script('facebook-sdk', plugins_url('/js/facebook-sdk.js', __FILE__), array(), '10.0', true); … … 86 87 register_setting( 'smp-plugin-settings-group', 'smp_fb_app_secret' ); 87 88 register_setting( 'smp-plugin-settings-group', 'smp_instagram_auto_publish' ); 89 register_setting( 'smp-plugin-settings-group', 'smp_facebook_auto_publish' ); 88 90 } 89 91 -
social-media-publish/trunk/admin/post-hook.php
r2542231 r2542760 10 10 // Retrive image thumbnail 11 11 $post_thumbnail_id = get_post_thumbnail_id( $post ); 12 $featured_image_url = wp_get_attachment_image_url( $post_thumbnail_id, 'original' ); 12 $featured_image_url = wp_get_attachment_image_url( $post_thumbnail_id, 'original' ); 13 14 /* -------------------------------------------------------------------------- */ 15 /* INSTAGRAM */ 16 /* -------------------------------------------------------------------------- */ 13 17 14 18 // Get instagram published date 15 19 $instagramPublishedPostMeta = get_post_meta( $post_id, 'smp-ig-published', true ); 16 17 // Featured image exist and instagram auto publish is enabled 18 // Check post already published 19 if( $featured_image_url && 20 esc_attr( get_option('smp_instagram_auto_publish')) && 21 empty( $instagramPublishedPostMeta ) 20 21 if( $featured_image_url && // Featured image exist 22 esc_attr( get_option('smp_instagram_auto_publish')) && // Instagram auto publish is enabled 23 empty( $instagramPublishedPostMeta ) // Post already published 22 24 ) { 23 25 // Set Instagram published flag 24 26 add_post_meta( $post_id, 'smp-ig-published' , date("d.m.Y H:i")); 25 27 smp_post_instagram($post->post_title, $featured_image_url); 28 } 29 30 /* -------------------------------------------------------------------------- */ 31 /* FACEBOOK */ 32 /* -------------------------------------------------------------------------- */ 33 34 $facebookPublishedPostMeta = get_post_meta( $post_id, 'smp-fb-published', true ); 35 36 if ( esc_attr( get_option('smp_facebook_auto_publish')) && empty($facebookPublishedPostMeta) ) { 37 38 smp_publish_facebook( $post->post_title, get_post_permalink( $post) ); 39 40 // Set Facebook published flag 41 add_post_meta( $post_id, 'smp-fb-published' , date("d.m.Y H:i")); 26 42 } 27 43 } -
social-media-publish/trunk/includes/facebook.php
r2542221 r2542760 70 70 ); 71 71 72 if ( is_wp_error( $response ) &&smp_is_facebook_error( $response )) {72 if ( is_wp_error( $response ) || smp_is_facebook_error( $response )) { 73 73 $error_message = $response->get_error_message(); 74 74 error_log('IG CONTAINER ERROR: ' . $error_message); … … 102 102 $jsonResponse = json_decode($response['body']); 103 103 104 $publishId = $jsonResponse->id; 105 error_log('PUBLISH INSTAGRAM ID: ' . $publishId); 106 107 return $publishId; 104 return $jsonResponse->id; 108 105 } 109 106 } … … 111 108 /** 112 109 * Upload instagram photo 110 * https://developers.facebook.com/docs/instagram-api/guides/content-publishing/ 111 * Permissions: ads_management, business_management, instagram_basic, instagram_content_publish, pages_read_engagement 113 112 */ 114 113 function smp_post_instagram($caption, $image_url) { 114 $image_url = 'https://devcraft.de/wp-content/uploads/2020/08/favicon.png'; 115 115 $facebookPageId = smp_get_facebook_page_id(); 116 116 … … 128 128 } 129 129 } 130 131 /** 132 * Publish a link to facebook page 133 * https://developers.facebook.com/docs/pages/publishing/ 134 * Permissions: pages_manage_posts, pages_read_engagement 135 */ 136 function smp_publish_facebook($message, $permalink) { 137 error_log('PERMA' . $permalink); 138 $facebookPageId = smp_get_facebook_page_id(); 139 140 $requestUrl = smp_get_facebook_graph_url() . $facebookPageId . '/feed?message=' . $message 141 . '&link=' . $permalink . '&access_token=' . $_COOKIE['smp_a']; 142 143 $response = wp_safe_remote_post( $requestUrl , array( 144 'method' => 'POST', 145 'timeout' => 45, 146 'redirection' => 5, 147 'httpversion' => '1.0', 148 'blocking' => true, 149 'headers' => array(), 150 'cookies' => array() 151 ) 152 ); 153 154 if ( is_wp_error( $response ) || smp_is_facebook_error( $response )) { 155 $error_message = $response->get_error_message(); 156 error_log('FACEBOOK PUBLISH ERROR: ' . $error_message); 157 } else { 158 // FB response will be page-post-id 159 error_log('PUBLISH FACEBOOK BODY: ' . $response['body']); 160 161 $jsonResponse = json_decode($response['body']); 162 163 // Return page-post-id 164 return $jsonResponse->id; 165 } 166 } 130 167 ?> -
social-media-publish/trunk/includes/metabox.php
r2542221 r2542760 8 8 } 9 9 10 /** 11 * Initialize Meta Box 12 */ 10 13 function smp_init_meta_box(){ 11 14 12 15 if ( get_post_status ( get_the_id() ) == 'publish' ) { 13 $ meta = get_post_meta( get_the_id(), 'smp-ig-published', true );16 $instagramMeta = get_post_meta( get_the_id(), 'smp-ig-published', true ); 14 17 18 if ( !empty($instagramMeta) ) { 15 19 ?> 16 20 <div class="components-panel__row"> 17 <p class="dashicons-before dashicons-instagram text-success">Published: <?php echo $meta ?></p>21 <p class="dashicons-before dashicons-instagram text-success">Published: <?php echo $instagramMeta ?></p> 18 22 <button id="instagram-reupload" class="components-button is-secondary is-small">Reupload</button> 19 23 </div> 20 24 <?php 25 } 26 27 $facebookMeta = get_post_meta( get_the_id(), 'smp-fb-published', true ); 28 if ( !empty($facebookMeta) ) 29 { 30 ?> 31 <div class="components-panel__row"> 32 <p class="dashicons-before dashicons-facebook text-success">Published: <?php echo $facebookMeta ?></p> 33 <button id="facebook-reupload" class="components-button is-secondary is-small">Reupload</button> 34 </div> 35 <?php 36 } 21 37 } else { 22 38 ?> … … 28 44 add_action( 'add_meta_boxes', 'smp_add_meta_box' ); 29 45 46 /** 47 * Reupload post to instagram 48 */ 30 49 function smp_instagram_reupload() { 31 50 $post_id = sanitize_text_field($_POST['post_id']); … … 40 59 smp_post_instagram( $title, $featured_image_url ); 41 60 update_post_meta( $post_id, 'smp-ig-published' , date("d.m.Y H:i")); 61 62 // Show notice on gutenberg screen 42 63 echo $title . ' uploaded to Instagram.'; 43 64 } else { 44 echo 'Whoops... something went wrong'; 65 echo 'No post ID available'; 66 } 67 } 68 69 /** 70 * Reupload to Facebeook 71 */ 72 function smp_facebook_reupload() { 73 $post_id = sanitize_text_field($_POST['post_id']); 74 75 if ( !empty($post_id) ) { 76 $title = get_the_title( $post_id ); 77 $post = get_post( $post_id ); 78 79 smp_publish_facebook( $title, get_post_permalink( $post) ); 80 update_post_meta( $post_id, 'smp-fb-published' , date("d.m.Y H:i")); 81 82 // Show notice on gutenberg screen 83 echo $title . ' uploaded to Instagram.'; 84 } else { 85 echo 'No post ID available'; 45 86 } 46 87 } -
social-media-publish/trunk/includes/notices.php
r2542221 r2542760 17 17 } 18 18 19 function smp_admin_notices() { 20 error_log('ADMIN_NOTICES'); 21 19 function smp_admin_notices() { 22 20 // SESSION 23 21 if ( array_key_exists( 'smp_errors', $_SESSION ) ) { 24 22 25 $type = 'warning';26 23 $message = $_SESSION['smp_errors']; 27 $class = 'notice notice-' . $type . ' is-dismissible';28 24 29 25 smp_show_notification($message); -
social-media-publish/trunk/social-media-publish.php
r2542221 r2542760 4 4 * Plugin URI: http://yourdomain.com 5 5 * Description: Insert a brief description of what your plugin does here. 6 * Version: 1.0. 06 * Version: 1.0.1 7 7 * Author: Bogdan Schreiber 8 8 * Author URI: https://devcraft.de
Note: See TracChangeset
for help on using the changeset viewer.