7

If you want to rewrite example.com/test123 (a standard WordPress Page) to example.com/test234 (another standard WordPress Page) without having to save the rewrite rules in the database, then one option is using the request filter hook: add_filter( 'request', function ( $query_vars ) { if ( isset( $query_vars['pagename'] ) ) { $slug = $query_vars[...


6

It depends on you where you want to call apply_filters(). It can be right when you defined the $title: $title = apply_filters( 'my_hook', the_title_attribute( 'echo=0' ) ); // set echo to false return $title; Or in the return call: $title = the_title_attribute( 'echo=0' ); // set echo to false return apply_filters( 'my_hook', $title ); Then one can hook ...


6

The root of your problem is not object oriented programming, but a fundamental misunderstanding about how PHP handles requests. If this were a Java or a Node application for example, you would start the application on the server, and it would recieve requests, and respond. It's a continuous active program. As a result, you can store things in memory and ...


5

You can use dangerouslysetinnerhtml, a special HTML attribute in React: dangerouslySetInnerHTML is React’s replacement for using innerHTML in the browser DOM. In general, setting HTML from code is risky because it’s easy to inadvertently expose your users to a cross-site scripting (XSS) attack. So, you can set HTML directly from React, but you ...


4

You forgot to add name ="bizdesc" to your textarea, so this function DrawCallBack($post) { $Record = GetDBRecord(); echo '<textarea id="bizdesc" rows="2" cols="50">'; echo $Record['BizDescp']; echo '</textarea>'; echo '<input type=text id="YourName" name="YourName" value="' .$Record['Name'] .'"/>' } should be function ...


4

Just like with Font Awesome 4, you can enqueue styles in your theme to take effect on the admin pages. This allows you get styles needed for Font Awesome icons to be used. Just update your functions as needed for version 5. Here is an example of how to enqueue Font Awesome styles: function fontawesome_dashboard() { wp_enqueue_style('fontawesome', '...


4

The init hook is too early — WordPress hasn't yet identified the queried object (post, category, etc.); hence the is_page() doesn't work there: add_action('init', 'register_script'); So for conditional tags/functions like is_page(), is_single(), etc. to work (i.e. return the proper result), you should use wp or a later hook: add_action('wp', '...


4

Explanation: The issue you are likely facing is that you are trying to add your ajax actions from within the widget itself that may be instantiated on the elementor/widgets/widgets_registered hook. If so, this is hook elementor/widgets/widgets_registered is too late and do_action( "wp_ajax_{$action}" ) and do_action( "wp_ajax_nopriv_{$action}" ) have ...


3

Gutenberg has been integrated in WordPress 5.0 and now you can check by using use_block_editor_for_post function. if(use_block_editor_for_post($post)){ //Block editor is active for this post. } Alternatively, when creating new post you can use use_block_editor_for_post_type function to check if gutenberg is active for this post type. if(...


3

If you look at the documentation, you can insert title, content, slug, etc. using wp_insert_post then use update_post_meta to assign the template to that post. You can write like this $post_arr = array( 'post_title'=>'My title goes here', 'post_content'=>'This is my long content.', 'post_excerpt' => 'My Excerpt', 'post_status' =>...


3

Yes, it can be done very easily. There is a great tutorial by Misha Rudrastyh on how to add Featured Images to Quick Edit. I recently applied it and can confirm that it works. You will be able to see the featured images in the admin area post lists and easily change them using Quick Edit. It is a very good alternative to using a plugin. Copy and paste the ...


3

I'm not entirely sure what you want to do exactly. But basically you just create one instance and then add functions like public static function FunctionName() to be used anywhere you want after the plugin got activated. To fire your hooks simply use the public function __construct(). Taking the Sample Plugin from below, the FooBar method can be called in ...


3

One way is to use static methods from class itself, as @leymannx explained in his answer. I prefer a little bit different approach, which is a little bit nicer/cleaner (but it's only my opinion, so feel free to argue with that statement). I do it like so: If some function should be available for use in templates, then I register is as a template tag (so I ...


3

I found a workaround, sparked by @tmdesigned's answer, which I'm going to post as an answer. It is not pretty and I don't think it can be the "canonical" answer, but hopefully it helps us get there. So first, I kept the attributes using a source: children: tabs: { type: 'array', source: 'children', selector: 'ul.tabs', default: [] } This meant ...


3

Options store values, and the plugin you're trying to adjust has committed the cardinal sin of storing PHP serialised data in the database, complete with all the security and maintenance problems that come with it. You won't find any WordPress APIs that let you update or add to that serialised value, but you can deserialise it, modify it with standard PHP ...


3

This got me started. Set up the block with create-guten-block Gitub Update block.js to something like: import './style.scss'; import './editor.scss'; var PluginPrePublishPanel = wp.editPost.PluginPrePublishPanel; var registerPlugin = wp.plugins.registerPlugin; function Component() { wp.data.dispatch('core/editor').lockPostSaving() //do stuff ...


3

Experiencing plugin incompatibilies isn't something I can relate to very well as that is something I've only faced a handful of times over the past years. On those few occasions that I've needed to build a site using multiple plugins I've prioritized using plugins from same authors. For example WooCommerce and its official addons. I've found this minimizes ...


3

It's a tough problem, especially with supporting sites long-term. I have a couple rules of thumb when building new sites. 1. Establish your standard plugins Put together a list of standard plugins for functionality you want on every site, ie caching, image optimization, forms, etc. Give these a review to make sure you're comfortable supporting them. ...


3

That's a rather opinion-based issue. But I'd recommend to always assume custom coding. And building your custom code around major well-maintained developer-friendly official plugins. Thing is that when developing bigger projects, I nearly always at a certain point are missing certain things from WordPress' core. Foremost a form API and a permission API. And ...


3

You can use get_current_user_id() to get the ID of the current user, and in your case, you can do so to print the user ID in the JavaScript Li.re() call: <script type="text/javascript"> Li.re( 'ab12','<?php echo get_current_user_id(); ?>' ); </script> And yes, you can include the user ID as part of a shortcode: (note that I omitted the ...


3

As a side note for those interested, you can also pass parameters with your custom theme support. // theme functions.php add_theme_support( 'some_feature', array( 'arg_foo', 'arg_bar' ) ); // plugin.php $feature_args = get_theme_support( 'some_feature' ); var_dump( $feature_args ); // array( // array( // 'arg_foo', // 'arg_bar' // ) // );


3

The data passed by wp_localize_script() is output in a <script> tag in the page HTML. So if you have this: wp_localize_script( 'registered_script', 'serverData', array( 'posts' => $post_array ) ); This will be on the page: <script type="text/javascript"> /* <![CDATA[ */ var serverData = { "posts": [] }; /* ]]> */ </...


3

I'm posting this answer because the accepted answer is slightly misleading, as it implies that you cannot use the trademarked name at all. While not 100% wrong, it's also not 100% right. It is correct that unless you are WooCommerce, you can't call your plugin "WooCommerce Cool Add-on". But you can call it "Cool Add-on for WooCommerce." See "Why can’t I ...


3

The component is still functional, the issue is due to how it was pulled out into its own package. It is no longer uppercase and in order to use it in JSX, you will need to alias it: const { serverSideRender: ServerSideRender } = wp; See this issue for more details.


3

the async property is marked as protected, so that usually signifies that it is related more to your implementation's details rather than functionality. Ideally you would write your tests to test the public methods you have exposed. Testing that the class property you set in the constructor of one class is an instanceof what was initialized doesn't provide ...


2

There's been some significant updates in the WordPress ecosystem since this question was asked, and I would like to clarify something about usage tracking code in plugins and themes on WordPress.org. It's completely OK if you ask permission from users. To offer a free version of my plugin on WordPress.org, I use Freemius, which offers insights and ...


2

If you currently are using shortcodes, then most probably you want to display some dynamic content at the bottom of the post. If so, then there is a hook that will allow you to do that: the_content If you want to modify the content only when single post is displayed, then you can use this code: function my_the_content_filter( $content ) { if ( ...


2

It's almost four years after I asked this question. For anyone reading this now, namespaces are officially supported. From the 5.2 release notes: The minimum supported PHP version is now 5.6.20. As of WordPress 5.2, themes and plugins can safely take advantage of namespaces, anonymous functions, and more!


2

Your code has var getid = $('#my-categorychecklist input:checked').last().val(); see the .last(), that's why you're only getting the last item Also, why do you have the same thing in getid and matchid? You need to store the selected categories in an array and loop through them, try something like: var selected_cats = $('#my-categorychecklist input:...


2

Activation hook is run only after the plugin get activated. So only once and only during that one request. It's meant to allow author of a plugin to perform some actions after the plugin is activated. Actions, that need to be done only once. For example if your plugin uses custom database table - you can use activation hook to create such table. On the ...


Only top voted, non community-wiki answers of a minimum length are eligible