Adding post format support to an elementor site but the dropdown shows only 'standard' - elementor

I'm trying to add post format support to a site using hello theme for Elementor using the following snippet:
array(
'aside',
'gallery',
'link',
'image',
'quote',
'status',
'video',
'audio',
'chat'
)
);
add_post_type_support( 'post', 'post-formats' );
add_post_type_support( 'page', 'post-formats' );
I've tested it on another site built with Oxygen builder and it works fine, but on this site the options don't show in the dropdown (only Standard shows)
I've seen this question - Wordpress Post Format Dropdown Empty
But I do have an index.php file, so that isn't the problem here
Any ideas I could try?

Related

Using two permalink structures for 2 types of posts

I'm new to wordpress and currently facing an issue on permalinks.
For example I have a page for privacy policy and the permalink for that page is like this
https://testsitename.io/privacy
Above page works with the this permalink structure in permalink settings
https://testsitename.io/archives/123
I also integrated a react app to wordpress and, the react app produces a permalink like
https://testsitename.io/crazy_droid
Above page loads with a custom permalink structure of https://testsitename.io/%post_id%
The issue is when i select a permalink structure i can only get one type of page to load. Other page will give a 404 not found error. How can i fix this issue .
NOTE: i'm a newbie to wordpress
UPDATE:
For the react app, url is created through a register_post_type as follows
function custom_post_type()
{
register_post_type(
'expert',[
'public' => true,
'label' => 'Experts',
'rewrite' => array( 'slug' => '/' ),
'supports' => array( 'title','editor','thumbnail' )
]);
}

CSRF issues when integrating TinyMCE image upload with CakePHP 3.8

I'm using CakePHP 3.8 to create a CMS for a website. I need a simple WYSIWYG editor with image upload. I'd previously used CKEditor, but was having problems getting the image upload working, so thought I'd try TinyMCE instead.
So, I downloaded TinyMCE 5 (with all standard plugins), linked it in in the head section of my page, and created a form with a TinyMCE textarea like this:
<fieldset>
<legend>New Page</legend>
<?php
echo $this->Flash->render();
echo $this->Form->create($newpage);
echo $this->Form->control('title');
echo $this->Form->control('content',
array('label' => 'Page Content',
'type' => 'textarea',
'id' => 'editor_area'));
echo $this->Form->button('Save');
echo $this->Form->end();
?>
</fieldset>
<script>
tinymce.init({
selector:'#editor_area',
height: 500,
menubar: false,
images_upload_url: '<?php echo IMG_UPLOAD_URL ?>',
toolbar: [
'undo redo | cut copy paste | styleselect | bold italic underline removeformat | alignleft aligncenter alignright | charmap | bullist numlist | link image'
],
plugins: ['advlist lists link autolink image charmap imagetools code']
});
</script>
This works fine, text area appears with the editor etc. The upload url in images_upload_url points to the following UploadsController.php (I've left out the details for brevity; can add them in if needed):
<?php
namespace App\Controller\Admin;
use App\Controller\AppController;
class UploadsController extends AppController
{
public function uploadImage() {
$result = array();
$result['success'] = 'success';
// Process file upload
return $this->response->withType('application/json')
->withStringBody(json_encode($result));
}
}
When I upload an image, I get the following error in the console:
Failed to load resource: the server responded with a status of 403 (Forbidden)
The output from CakePHP shows the error:
Error: CSRF token mismatch.
The debugger shows that the POST includes the following:
Cookie: CAKEPHP=dvsktjv7vp8la5nv7dv19634d1; csrfToken=53e5718e13a1e963d51f9c93c48471a478b35c02b565d6f0699cd2a335775c2b17986cfc2cc587ff7343a6573e3eb2e498a9cb962397599c023417d1dfa9506c; ckCsrfToken=7l2PEC0g06819qQcLwdX5ul7E7jNRa3r61jENt2x
I'm not sure where to go from here.
(Or if there's a more straightforward way to include a free/inexpensive WYSIWYG editor with a decent image/file uploader, I'm open to suggestions! It's a website for a school, so budget is very small and can't be a monthly cost.)
The cookie data is only one part of the CSRF protection mechanism, the client needs to send the CSRF token in either the request data or the X-CSRF-Token header too.
I'm not overly familiar with TinyMCE image uploads, but looking at the docs, you'll probably need a custom upload handler, where you can add additional data, the CSRF token that is.
Taking the example from the TinyMCE docs, the handler could look something like this, where the CSRF token is appended to the form data:
images_upload_handler: function (blobInfo, success, failure) {
var xhr, formData;
xhr = new XMLHttpRequest();
xhr.withCredentials = false;
xhr.open('POST', <?= json_encode(IMG_UPLOAD_URL) ?>);
xhr.onload = function() {
var json;
if (xhr.status != 200) {
failure('HTTP Error: ' + xhr.status);
return;
}
json = JSON.parse(xhr.responseText);
if (!json || typeof json.location != 'string') {
failure('Invalid JSON: ' + xhr.responseText);
return;
}
success(json.location);
};
formData = new FormData();
formData.append('file', blobInfo.blob(), blobInfo.filename());
// append CSRF token in the form data
formData.append('_csrfToken', <?= json_encode($this->request->getParam('_csrfToken')) ?>);
xhr.send(formData);
}
Also according to the docs the response JSON must contain a property named location that contains the web path to the uploaded file, that might be in the code that you've left out, mentioning it just in case.
See also
TinyMCE Docs > Introduction & getting started > Uploading images and files
TinyMCE Docs > Configuration reference > Image & file upload options > images_upload_handler
Cookbook > Security > Cross Site Request Forgery (CSRF) Middleware

Display custom post type in author archive thanks to elementor

I'm using Elementor Pro and its "Hello Theme" to build my website. I registered a CPT "movie" in fucntions.php.
Now, I would like to display the archive from this new CPT on my author page but that doesn't seem to work : Elementor says it doesn't find any archive.
I tried adding this piece of code :
add_action( 'pre_get_posts', 'post_types_author_archives' );
function post_types_author_archives( $query ) {
if ( $query->is_author ) {
$query->set( 'post_type', array( 'post', 'movie' ) );
remove_action( 'pre_get_posts', 'post_types_author_archives' );
}`
Unfortunately, it didn't work neither...

How to use Auth component of Cakephp 3 in Event

I'm using CakePHP 3.2 and proffer plugin for image uploading.
I want to rewrite the default path of proffer plugin to upload image and change image name before save.
As per the documentation of proffer from github. I have created an event in /src/Event
Now I want to rename the file like
$this->Auth->user('id').'-'.$row('id').date('dmyhis').ext
this is what I have done
$newFilename = $this->Auth->user('id').'-'.$event->subject()->get('id') . '_' . Inflector::slug($event->subject()->get('name')) . date('ymdhis') . $ext;
But this is giving error that Auth can not be used here. Is there any way to use Auth Component outside controller ?
You can access the logged in user id by loading the session.
use Cake\Network\Session;
$session = new Session();
$userData = $session->read('Auth.User.id');
Use this as a reference: Reading & Writing Session Data
With cake 3.x and after, you should using this:
$this->request->session()->read('Auth');
When debug it
debug( $this->request->session()->read('Auth') );
[
'id' => (int) 2,
'username' => 'admin',
'nice_name' => 'Tommy Do',
'first_name' => 'Huy',
'last_name' => 'Đỗ',
...//and more info in UserTable
]
And access to each element.
$this->request->session()->read('Auth.nice_name');
Print:
Tommy Do
Hope it will help you :D

CakePHP 2.6 DebugKit not loading properly

So I recently tried to install DebugKit for cakephp 2.6 and run into an interesting propblem. I have loaded the plugin in bootstrap.php. I have debug set to 1 in core.php. I have the component loaded in AppController.php. And I have removed the sql_dump from default.ctp. When I load my app I don't see the cake logo in the upper right corner and I get a message that prints at the bottom of the page that says.
There are no active panels. You must enable a panel to see its output.
Any help is greatly appreciated.
Code in files as requested:
bootstrap.php
CakePlugin::load( [ 'DebugKit', 'BoostCake', 'Search' ] );
core.php
Configure::write('debug', 1);
AppController.php
public $helpers = [
'DebugKit.Toolbar',
'Session',
'Html',
'Form',
'Paginator' => [ 'className' => 'BoostCake.BoostCakePaginator' ],
]
I saw my problem as soon as I posted my code.
I declared the Debugkit.Toolbar in the helpers array not the components array so now I have
$components = [ 'DebugKit.Toolbar' ];
And everything works just fine. Thank you to everyone who posted

Resources