[DevOps] WP 플러그인/테마 Title * Options Secret Author * Password * Content Visual Text <span style="font-family: arial, helvetica, sans-serif;"><br><br><br><br><hr style="border-top: dotted 1px;" />Parent Title : <b>Re(0): 플러그인 코드 작성방법 (AI)</b><br>Author : 박창희(한국)<br>Created Date : 24-10-11 17:31 / Last Updated Date : 24-10-11 18:55<br><hr style="border-top: dotted 1px;" /><span style="font-family: arial, helvetica, sans-serif;">2024-10-11(금) 플러그인에서 Javascript / PHP 간에 기본 데이터 교환 흐름도 </span> 1) wp-content/plugins/my-tinymce-button-plugin.php로 부터 작성 2) wp-content/plugins/js/my-tinymce-button-script.js에 javascript 코드는 작성하고 서버 쪽 값이 필요할 경우, ajax를 통해서 함수 또는 파일에 값 작성 3) wp-content/themes/function.php에 해당함수를 넣거나, theme 별도 파일에 만들어서 new_function.php 파일을 만들어서 function을 생성한 후 응답결과 가져오기. [[전체 모식도 예시 : 플러그인 이름 - my-tinymce-button-plugin.php 라고 가정시]] Source:http://fdcs.delphizon.com/wp-content/uploads/2024/10/플러그인_테마_데이터구성도.xlsx <span style="font-family: arial, helvetica, sans-serif;"><img class="alignnone wp-image-3112 size-large" src="http://fdcs.delphizon.com/wp-content/uploads/2024/10/image-6-1024x811.png" alt="" width="1024" height="811" /> </span> <hr /> <div class="mwai-reply mwai-user"> <div class="mwai-name-text">Question : wordpress make plugin add tinymce button and call function.php function and response</div> </div> <div> Sure, I'd be happy to help you with that! To create a WordPress plugin that adds a TinyMCE button and calls a function in your <code>functions.php</code> file, you'll need to follow these steps: <ol start="1"> <li>Create a new folder in the <code>wp-content/plugins/</code> directory of your WordPress installation. Name it something relevant to your plugin, for example, <code>my-tinymce-button-plugin</code>.</li> <li>Inside the plugin folder, create a PHP file (e.g., <code>my-tinymce-button-plugin.php</code>) and add the necessary plugin header information at the top of the file:</li> </ol> <pre><code class="lang-php hljs language-php"><span class="hljs-meta"><?php</span> <span class="hljs-comment">/* Plugin Name: My TinyMCE Button Plugin Description: Adds a custom TinyMCE button to the editor. Version: 1.0 Author: Your Name */</span> <span class="hljs-comment">// Plugin code will go here</span></code></pre> <ol start="3"> <li>Add the code to enqueue your JavaScript file with the TinyMCE button functionality. You can do this by hooking into the <code>admin_enqueue_scripts</code> action in WordPress:</li> </ol> <pre><code class="lang-php hljs language-php"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">my_enqueue_tinymce_button_script</span>() </span>{ <span class="hljs-title function_ invoke__">wp_enqueue_script</span>(<span class="hljs-string">'my-tinymce-button-script'</span>, <span class="hljs-title function_ invoke__">plugin_dir_url</span>(<span class="hljs-keyword">__FILE__</span>) . <span class="hljs-string">'js/my-tinymce-button-script.js'</span>, <span class="hljs-keyword">array</span>(<span class="hljs-string">'jquery'</span>), <span class="hljs-literal">null</span>, <span class="hljs-literal">true</span>); } <span class="hljs-title function_ invoke__">add_action</span>(<span class="hljs-string">'admin_enqueue_scripts'</span>, <span class="hljs-string">'my_enqueue_tinymce_button_script'</span>);</code></pre> <ol start="4"> <li>Now create the JavaScript file (<code>my-tinymce-button-script.js</code>) inside a <code>js</code> folder in your plugin directory. This file should contain the code to add your custom TinyMCE button:</li> </ol> <pre><code class="lang-javascript hljs language-javascript">(<span class="hljs-keyword">function</span>() { tinymce.<span class="hljs-property">PluginManager</span>.<span class="hljs-title function_">add</span>(<span class="hljs-string">'my_tinymce_button'</span>, <span class="hljs-keyword">function</span>(<span class="hljs-params">editor, url</span>) { editor.<span class="hljs-title function_">addButton</span>(<span class="hljs-string">'my_tinymce_button'</span>, { <span class="hljs-attr">text</span>: <span class="hljs-string">'My Button'</span>, <span class="hljs-attr">icon</span>: <span class="hljs-literal">false</span>, <span class="hljs-attr">onclick</span>: <span class="hljs-keyword">function</span>() { <span class="hljs-comment">// Call the function in functions.php </span> <span class="hljs-comment">// You can use ajax to send a request to your server and get the response jQuery.<span class="hljs-title function_">post</span>(ajaxurl, { <span class="hljs-attr">action</span>: <span class="hljs-string">'my_custom_tinymce_button_action'</span> }, <span class="hljs-keyword">function</span>(<span class="hljs-params">response</span>) { <span class="hljs-title function_">alert</span>(<span class="hljs-string">'Response: '</span> + response); });</span> } }); }); })();</code></pre> <ol start="5"> <li>In your <code>functions.php</code> file, create the function that will be called when the TinyMCE button is clicked:</li> </ol> <pre><code class="lang-php hljs language-php"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">my_custom_tinymce_button_action</span>() </span>{ <span class="hljs-comment">// Your custom functionality here </span> <span class="hljs-keyword">echo</span> <span class="hljs-string">'Response from the custom function!'</span>; <span class="hljs-title function_ invoke__">wp_die</span>(); } <span class="hljs-title function_ invoke__">add_action</span>(<span class="hljs-string">'wp_ajax_my_custom_tinymce_button_action'</span>, <span class="hljs-string">'my_custom_tinymce_button_action'</span>);</code><code class="lang-javascript hljs language-javascript"></code></pre> That's it! You now have a WordPress plugin that adds a custom TinyMCE button and calls a function in your <code>functions.php</code> file with a response. Let me know if you need further assistance or clarification! </div> <hr style="border-top: dotted 1px;" /> Parent Title : <b>플러그인 코드 작성방법 (AI)</b> Author : changhee1220 Created Date : 23-08-26 22:31 / Last Updated Date : 23-08-26 22:31 <hr style="border-top: dotted 1px;" /> <img src="http://fdcs.iptime.org/wp-content/uploads/kboard_attached/6/202308/64e9fec64e1c74471479.png" alt="" /> <br> Photos KBoard Add Media Thumbnail WP Search Public Only title (secret document) Exclusion Back Save