i am newbie to wordpress theme development...
i know to create theme options in wordpress themes but now i want to use WYSIWYG Editor of wordpress, the wp_editor(), i have read some tuts on this but i can't make it...
here is my code:
add_settings_field('tinytxt', 'WYSIWYG: ', array($this, 'tinytxt'), 'oditer_theme_options', 'jd_theme_options_main_section');
public function tinytxt() {
wp_editor("{$this->options['tinytxt']}", 'tinytxtboom');
}
And how to retrieve the saved content from the database, i know to use get_option()...
thanks in advance...
You need to give your WordPress editor a name for the input, so that it can save the value.
wp_editor( $this->options['tinytxt'], 'tinytxtboom', array(
'textarea_name' => 'jd_theme_options[tinytxt]'
) );
This will give the hidden textarea wp_editor uses a name for the form submission. jd_theme_options matches the second argument to register_setting, and tinytxt is the option key you want to save the value under.
I think that's all you need. Comment if you have trouble. I'll be back tomorrow to check.
You could also try getting it to work with just a simple textarea, then try to get the wp_editor working.
Related
My problem:
I have replaced the color input in the customizer with an input that supports the alpha channel. The sanitization function from Wordpress is only for hex colors but I get rgba() colors. I wrote a sanitization function that works perfectly for any new control I add to the customizer but if I replace an existing one and change the sanitize_callback parameter of the corresponding setting to my own function ($wp_customize->get_setting("background_color")->sanitize_callback = "slug_sanitize_color";) Wordpress still uses its standard sanitize_hex_color. The output of var_dump($wp_customize->get_setting("background_color")->sanitize_callback); is string(19) "slug_sanitize_color" so I guess it should work. If more code is needed I can provide it.
My question:
What do I have to do to make Wordpress use my sanitization function for a preexisting control instead of the one Wordpress ships with?
Addition: It all happens inside a function hooked to customize_register
I found the solution myself.
If you want to change the sanitize_callback, sanitize_js_callback or validate_callback you have to manually unregister the old callback function (remove_filter("customize_sanitize_{$settingid}",$wp_customize->get_setting($settingid)->sanitize_callback);), then change the value for the object ($wp_customize->get_setting($settingid)->sanitize_callback = "my_custom_filter_function";) and finally register the new filter function (add_filter("customize_sanitize_{$settingid}",my_custom_filter_function,10,2);).
On my forum (made in WordPress) I let users add copy to clipboard buttons so they can make code easier to copy. I am using a plugin for this meaning that when you are posting something on the forum and type this then it will make a copy to clipboard button:
[pw-clippy caption="Copy"]Text to Copy goes here[/pw-clippy]
I don't really like users having to use the name of the plugin 'pw-clippy' when making these buttons so I am wondering if I can shorten it so instead you type something like:
[copytoclip caption="Copy"]Text to Copy goes here[/copytoclip]
or this would also be fine:
[copytoclip]Text to Copy goes here[/copytoclip]
This may have an easy solution but I am fairly new to WordPress and would like to learn more.
Thanks for any help.
Note: I am not sure if it is called shortcode but any knowledge on it would be appreciated :D
Untested but here goes:
function copytoclip_shortcode( $atts, $content = null ){
return do_shortcode('[pw-clippy caption="Copy"]' . $content . '[/pw-clippy]');
}
add_shortcode( 'copytoclip', 'copytoclip_shortcode' );
Add this to functions.php, or even better as a standalone plugin file in your wp-content/plugins/ directory.
I am trying to write a plugin for wordpress. I have a problem i can't solve.
Inside plugin i habe added a shortcode that show a form.
function showForm() {
echo '<form method="post" action="www.example.com/myDestinationPage">';
[...]
}
add_shortcode( 'ShowFormSC' , 'showForm' );
After that, in a page, i added the shortcode and it works perfectly. ;-)
Now the problem: how can i read POST data in myDestinationPage (another wordpress page)?
In Php would be very simple ... but in wordpress I do not know how to do.
Second problem: myDestinationPage must be a real wordpress page with another shortcode inside, or can be defined as a "virtual" page inside my plugin?
Thank you for your help!
Best Regards,
Simone
www.example.com/myDestinationPage needs to be edited to recieve the post data, just as in any other php script, wordpress or not. If 'myDestinationPage' resolves to dynamic wordpress content, then you are in muddy waters.
Let's say, myDestinationPage is a wordpress Post. That "page" doesn't exist as a file, it comes directly from the database.
You could write a shortcode which handles this though:
add_shortcode('post_parser', 'postParser');
. . .
function postParser() {
filter_input(INPUT_POST, 'my_post_value');
//do something
}
Then, you just add the '[post_parser]' shortcode to the myDestinatioPage Post. (You mentioned it's a wordpress page, but page & post are both WP_Post objects.)
Another option is to put your post processing code in the post.php (or whichever template myDestinationPage is).
1st answer: you can directly use $_POST in wordpress like in php.
2nd answer: Yes you can. If you want to use pages in your plugin, use plugins_url() to generate the path for form action.
https://codex.wordpress.org/Function_Reference/plugins_url
How can I place a default text (hashtag) in the Custom Message?
The textarea is (located in line 643) under jetpack/modules/publicize/ui.php
I tried to put the text in front of $title in various ways, like:
<?php echo "#myhashtag $title"; ?>
or
<?php echo '#myhashtag '.$title; ?>
but it just echoes the text, not the $title.
Any ideas will be greatly appreciated.
You can use the approach of this Wordpress plugin i made (Publicize With Hashtags), which does exactly that. It basically use and action trigger bound to the 'save_post' native event.
If you want to develop your own one you can have a look at my Source Code on the project's GitHub page or in this installation & usage guide I wrote about it.
You can add a filter, like so, to your theme's functions.php or a site-specific plugin:
add_filter( 'wpas_default_prefix', 'add_default_publicize_hashtag_prefix', 10, 4 );
function add_default_publicize_hashtag_prefix() {
$default_tags = '#yourhastaghere ';
return $default_tags;
}
This will add your default hashtag before your title without you needing to hack the WordPress core.
jetpack/modules/publicize/ui.php itself states in its comments:
/**
* Only user facing pieces of Publicize are found here.
*/
You added your hashtag in the textarea which allows admins to enter a custom message (click edit and it will slide down with your hashtag).
As #Yazmin mentioned, the best way to permanently edit the message is using a filter. The filters available are wpas_default_prefix, wpas_default_message, and wpas_default_suffix.
Personally, I had no success using these filters and I'm interested in a working solution to this issue myself.
By default a CCK form creation has a title of the form
Create [Your Content Type Name Here]
I want to change mine to
Register for Such and Such
It was suggested that I could use string-override, but I can't find the string to replace. I've also tried writing code to form_alter, but can't seem to figure out how to get the "title" to change.
Ideas?
There are two possibilities, either you can use the theming laying and set $title variable used in the page templage. You can do this with a preprocess function like lazy suggests.
The other options which I prefer would be to use the drupal_set_title(), this would need to go in a module. I haven't tried this, but I would think that you could use this in your hook_form_alter() implementation. That way you could control which titles get changed pretty easily.
Hook form_alter doesn't affect the title, but you can use a preprocess function:
Try this code to start:
function MYMODULENAME_preprocess(&$variables) {
$variables['title'] = 'test title';
}