کاتالوگ آنفایو
051-38538006 09355240891

اضافه کردن ویرایشگر TinyMCE برای رده توضیحات

اضافه کردن ویرایشگر TinyMCE برای رده توضیحات
پنج شنبه ۱۶ دی ۹۵

اضافه کردن ویرایشگر TinyMCE برای رده توضیحات

در وردپرس به طور پیش فرض دو راه برای سازماندهی پست های خود وجود دارد شما می توانید آنها را گروه ها و برچسب ها و یا توسط مجموعه ها ایجاد کنید. در هر دو از این طبقه بندی شما می توانید  مثل حلزون حرکت کنید و شرح سفارشی ایجاد کنید. این باعث می شود

مشکل با  قسمت پیش فرض توضیحات وردپرس است که شما از ویرایشگر TinyMCE WYSIWYG استفاده می کنید.

اضافه کردن ویرایشگر TinyMCE در وردپرس

اضافه کردن ویرایشگر TinyMCE

در اینجا مراحل اضافه کردن یک ویرایشگر TinyMCE جدید و حذف جعبه توضیحات قدیمی از جدول را میبینیم،

اضافه کردن TinyMCE به جعبه
برای شروع ابتدا نیاز به اضافه کردن جعبه TinyMCE به جدید ما به این صفحه  با استفاده از تابع wp_editor () داریم.این تابع اجازه می دهد تا ما مقدار پیش فرض، یک نام و تنظیمات متعدد برای ایجاد جعبه TinyMCE را تعیین کنیم.

<pre class=" language-php"><code class=" language-php"><span class="token function">add_filter</span><span class="token punctuation">(</span><span class="token string">'edit_category_form_fields'</span><span class="token punctuation">,</span> <span class="token string">'cat_description'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">function</span> <span class="token function">cat_description</span><span class="token punctuation">(</span><span class="token variable">$tag</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token delimiter">?></span>
        <span class="token markup"><span class="token tag"><span class="token punctuation"><</span>table <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>form-table<span class="token punctuation">"</span></span><span class="token punctuation">></span></span></span>
            <span class="token markup"><span class="token tag"><span class="token punctuation"><</span>tr <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>form-field<span class="token punctuation">"</span></span><span class="token punctuation">></span></span></span>
                <span class="token markup"><span class="token tag"><span class="token punctuation"><</span>th <span class="token attr-name">scope</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>row<span class="token punctuation">"</span></span> <span class="token attr-name">valign</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>top<span class="token punctuation">"</span></span><span class="token punctuation">></span></span></span><span class="token markup"><span class="token tag"><span class="token punctuation"><</span>label <span class="token attr-name">for</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>description<span class="token punctuation">"</span></span><span class="token punctuation">></span></span></span><span class="token php"><span class="token delimiter"><?php</span> <span class="token function">_ex</span><span class="token punctuation">(</span><span class="token string">'Description'</span><span class="token punctuation">,</span> <span class="token string">'Taxonomy Description'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token delimiter">?></span></span><span class="token markup"><span class="token tag"><span class="token punctuation"></</span>label<span class="token punctuation">></span></span></span><span class="token markup"><span class="token tag"><span class="token punctuation"></</span>th<span class="token punctuation">></span></span></span>
                <span class="token markup"><span class="token tag"><span class="token punctuation"><</span>td<span class="token punctuation">></span></span></span>
                <span class="token php"><span class="token delimiter"><?php</span>
                    <span class="token variable">$settings</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span><span class="token string">'wpautop'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token string">'media_buttons'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token string">'quicktags'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token string">'textarea_rows'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token string">'15'</span><span class="token punctuation">,</span> <span class="token string">'textarea_name'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token string">'description'</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token function">wp_editor</span><span class="token punctuation">(</span><span class="token function">wp_kses_post</span><span class="token punctuation">(</span><span class="token variable">$tag</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">description</span> <span class="token punctuation">,</span> <span class="token constant">ENT_QUOTES</span><span class="token punctuation">,</span> <span class="token string">'UTF-8'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">'cat_description'</span><span class="token punctuation">,</span> <span class="token variable">$settings</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token delimiter">?></span></span>
                <span class="token markup"><span class="token tag"><span class="token punctuation"><</span>br <span class="token punctuation">/></span></span></span>
                <span class="token markup"><span class="token tag"><span class="token punctuation"><</span>span <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>description<span class="token punctuation">"</span></span><span class="token punctuation">></span></span></span><span class="token php"><span class="token delimiter"><?php</span> <span class="token function">_e</span><span class="token punctuation">(</span><span class="token string">'The description is not prominent by default; however, some themes may show it.'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token delimiter">?></span></span><span class="token markup"><span class="token tag"><span class="token punctuation"></</span>span<span class="token punctuation">></span></span></span>
                <span class="token markup"><span class="token tag"><span class="token punctuation"></</span>td<span class="token punctuation">></span></span></span>
            <span class="token markup"><span class="token tag"><span class="token punctuation"></</span>tr<span class="token punctuation">></span></span></span>
        <span class="token markup"><span class="token tag"><span class="token punctuation"></</span>table<span class="token punctuation">></span></span></span>
    <span class="token delimiter"><?php</span>
<span class="token punctuation">}
</span></code>

شما میتوانید توضیحات در سمت سرور از طریق یک فیلتر را حذف کنید ما نیاز به حذف جعبه توضیحات با استفاده از روش حذف () jQuery و استفاده از عمل admin_head برای اضافه کردن این جاوا اسکریپت به تگ head HTML به حذف جعبه توضیحات داریم.

<pre class=" language-php"><code class=" language-php"><span class="token function">add_action</span><span class="token punctuation">(</span><span class="token string">'admin_head'</span><span class="token punctuation">,</span> <span class="token string">'remove_default_category_description'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">function</span> <span class="token function">remove_default_category_description</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token keyword">global</span> <span class="token variable">$current_screen</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token variable">$current_screen</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">id</span> <span class="token operator">==</span> <span class="token string">'edit-category'</span> <span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
    <span class="token delimiter">?></span>
        <span class="token markup"><span class="token tag"><span class="token punctuation"><</span>script <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text/javascript<span class="token punctuation">"</span></span><span class="token punctuation">></span></span></span>
        <span class="token function">jQuery</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span>$<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            $<span class="token punctuation">(</span><span class="token string">'textarea#description'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">closest</span><span class="token punctuation">(</span><span class="token string">'tr.form-field'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token markup"><span class="token tag"><span class="token punctuation"></</span>script<span class="token punctuation">></span></span></span>
    <span class="token delimiter"><?php</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}
</span></code>

حذف فیلتر HTML 
به طور پیش فرض وردپرس مطمئن خواهد شد که این مطلب  از طریق wp_filter_kses و فیلترهای wp_kses_data تخمین زده شده است

 

</pre>
<pre class=" language-php"><code class=" language-php"><span class="token comment" spellcheck="true">// remove the html filtering</span>
<span class="token function">remove_filter</span><span class="token punctuation">(</span> <span class="token string">'pre_term_description'</span><span class="token punctuation">,</span> <span class="token string">'wp_filter_kses'</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">remove_filter</span><span class="token punctuation">(</span> <span class="token string">'term_description'</span><span class="token punctuation">,</span> <span class="token string">'wp_kses_data'</span> <span class="token punctuation">)</span><span class="token punctuation">;
</span></code>

 کد کامل پلاگین

شما نیاز به اضافه کردن ویرایشگر TinyMCE به دسته منطقه توضیحات در کد بالا دارید، در زیر کد کامل پلاگین آمده است:

<pre class=" language-php"><code class=" language-php"><span class="token comment" spellcheck="true">/*
Plugin Name: Tinymce Category Description
Description: Adds a tinymce editor to the category description box
Author: Paulund
Author URI: http://www.paulund.co.uk
Version: 1.0
License: GPL2
*/</span>

<span class="token comment" spellcheck="true">/*

    Copyright (C) Year  Author  Email

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as
    published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/</span>

<span class="token comment" spellcheck="true">// remove the html filtering</span>
<span class="token function">remove_filter</span><span class="token punctuation">(</span> <span class="token string">'pre_term_description'</span><span class="token punctuation">,</span> <span class="token string">'wp_filter_kses'</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">remove_filter</span><span class="token punctuation">(</span> <span class="token string">'term_description'</span><span class="token punctuation">,</span> <span class="token string">'wp_kses_data'</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token function">add_filter</span><span class="token punctuation">(</span><span class="token string">'edit_category_form_fields'</span><span class="token punctuation">,</span> <span class="token string">'cat_description'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">function</span> <span class="token function">cat_description</span><span class="token punctuation">(</span><span class="token variable">$tag</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token delimiter">?></span>
        <span class="token markup"><span class="token tag"><span class="token punctuation"><</span>table <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>form-table<span class="token punctuation">"</span></span><span class="token punctuation">></span></span></span>
            <span class="token markup"><span class="token tag"><span class="token punctuation"><</span>tr <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>form-field<span class="token punctuation">"</span></span><span class="token punctuation">></span></span></span>
                <span class="token markup"><span class="token tag"><span class="token punctuation"><</span>th <span class="token attr-name">scope</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>row<span class="token punctuation">"</span></span> <span class="token attr-name">valign</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>top<span class="token punctuation">"</span></span><span class="token punctuation">></span></span></span><span class="token markup"><span class="token tag"><span class="token punctuation"><</span>label <span class="token attr-name">for</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>description<span class="token punctuation">"</span></span><span class="token punctuation">></span></span></span><span class="token php"><span class="token delimiter"><?php</span> <span class="token function">_ex</span><span class="token punctuation">(</span><span class="token string">'Description'</span><span class="token punctuation">,</span> <span class="token string">'Taxonomy Description'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token delimiter">?></span></span><span class="token markup"><span class="token tag"><span class="token punctuation"></</span>label<span class="token punctuation">></span></span></span><span class="token markup"><span class="token tag"><span class="token punctuation"></</span>th<span class="token punctuation">></span></span></span>
                <span class="token markup"><span class="token tag"><span class="token punctuation"><</span>td<span class="token punctuation">></span></span></span>
                <span class="token php"><span class="token delimiter"><?php</span>
                    <span class="token variable">$settings</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span><span class="token string">'wpautop'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token string">'media_buttons'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token string">'quicktags'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token string">'textarea_rows'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token string">'15'</span><span class="token punctuation">,</span> <span class="token string">'textarea_name'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token string">'description'</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token function">wp_editor</span><span class="token punctuation">(</span><span class="token function">wp_kses_post</span><span class="token punctuation">(</span><span class="token variable">$tag</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">description</span> <span class="token punctuation">,</span> <span class="token constant">ENT_QUOTES</span><span class="token punctuation">,</span> <span class="token string">'UTF-8'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">'cat_description'</span><span class="token punctuation">,</span> <span class="token variable">$settings</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token delimiter">?></span></span>
                <span class="token markup"><span class="token tag"><span class="token punctuation"><</span>br <span class="token punctuation">/></span></span></span>
                <span class="token markup"><span class="token tag"><span class="token punctuation"><</span>span <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>description<span class="token punctuation">"</span></span><span class="token punctuation">></span></span></span><span class="token php"><span class="token delimiter"><?php</span> <span class="token function">_e</span><span class="token punctuation">(</span><span class="token string">'The description is not prominent by default; however, some themes may show it.'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token delimiter">?></span></span><span class="token markup"><span class="token tag"><span class="token punctuation"></</span>span<span class="token punctuation">></span></span></span>
                <span class="token markup"><span class="token tag"><span class="token punctuation"></</span>td<span class="token punctuation">></span></span></span>
            <span class="token markup"><span class="token tag"><span class="token punctuation"></</span>tr<span class="token punctuation">></span></span></span>
        <span class="token markup"><span class="token tag"><span class="token punctuation"></</span>table<span class="token punctuation">></span></span></span>
    <span class="token php"><span class="token delimiter"><?php</span>
<span class="token punctuation">}</span>

<span class="token function">add_action</span><span class="token punctuation">(</span><span class="token string">'admin_head'</span><span class="token punctuation">,</span> <span class="token string">'remove_default_category_description'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">function</span> <span class="token function">remove_default_category_description</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token keyword">global</span> <span class="token variable">$current_screen</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token variable">$current_screen</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">id</span> <span class="token operator">==</span> <span class="token string">'edit-category'</span> <span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
    <span class="token delimiter">?></span></span>
        <span class="token markup"><span class="token tag"><span class="token punctuation"><</span>script <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>text/javascript<span class="token punctuation">"</span></span><span class="token punctuation">></span></span></span>
        <span class="token function">jQuery</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span>$<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            $<span class="token punctuation">(</span><span class="token string">'textarea#description'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">closest</span><span class="token punctuation">(</span><span class="token string">'tr.form-field'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token markup"><span class="token tag"><span class="token punctuation"></</span>script<span class="token punctuation">></span></span></span>
    <span class="token php"><span class="token delimiter"><?php</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token delimiter">?>
</span></span></code>

امیدواریم این مقاله به شما در اضافه کردن ویرایشگر TinyMCE برای رده توضیحات کمک کرده باشد.برای مشاهده مقالات بیشتر درباره ی طراحی قالب وردپرس به http://www.on5.ir مراجعه نمایید.

آنفایو مرجع مقالات تخصصی طراحی قالب وردپرس

 

 

ادامه مطلب

هاست پرسرعت سرور ایران

مشاهده پلن‌ها
آنفایو

استعلام قیمت بصورت آنلاین

تلگرام